Quote: "when a bullet is made it has the identity 'bullet'"
Yes I think that the problem... "bullet" is the next lowest free object number, and it increases everytime a bullet is made so my "move object bullet,bulletspeed#" only applies to the last bullet made... Any ideas how I should fix that?
This is my first game where my gun actually shoots an object...
Incase this helps, this is my code:
Rem Project: SideScroller
Rem Created: 7/26/2009 4:28:45 PM
Rem ***** Main Source File *****
`Video setup:
Sync On : Sync Rate 60
Sync : Position mouse 0,300
Autocam off
`Variables
`Object Numbers
player# = 1
ground# = 2
gun# = 3
bullet# = 4
target# = 5
gun_limb# = 6
`Sound Numbers
Shoot# = 1
Empty# = 2
reload# = 3
JetSound# = 4
`Gravity/Movement
gravity# = -5
max_gravity# = -16
Momentum# = 0.0
force# = 0
Right# = 180
`JetPack
JetStrenght# = 12
JFuel# = 125
MinFuel# = 2
max_fuel# = JFuel#
Refill_speed# = 10
`Gun Shooting
Ammo# = 30
Reloaded# = Ammo#
Shoot_Speed# = 75
Empty_Speed# = 85
Reload_Speed# = 125
bulletspeed# = 20
bulletmove# = 0
`Other Variables
p_cam# = 0
`Subroutines
Gosub LoadMedia
Gosub MakeLevel
Gosub Player
Do `Main loop
Gosub Col_Controls
Gosub Camera
Gosub HUD
Gosub GameOver
Gosub Shoot
Gosub BulletLife
Sync
Loop
Camera:
`Sets up the Camera
Position camera p_cam#, ox#,oy#,1000
Rotate Camera p_cam#, 180,0,180
Return
Player:
`Make player
Make Object Box Player#, 15,80,25
`Gun
Make Object Box Gun#, 30,10.8,10.6 : Hide object Gun#
Make mesh from object 2, Gun# : Add limb Player#, 1, 2
Offset limb Player#,1, -25,16.5,16.5
Rotate Limb player#,1, 0,0,0
SC_SetupObject Player#,0,0
Return
Col_Controls:
fac# = camera angle y(p_cam#) `Camera facing
`Gun limb position
lX = Limb position X(player#,1)
lY = Limb position Y(player#,1)
lZ = Limb position Z(player#,1)
`Old object positions (for collisions)
ox# = object position x(player#)
oy# = object position y(player#)
oz# = object position z(player#)
`Gravity (must be placed after old positions are saved!)
Move object up player#,gravity# `Gravity on player!
Rem --Controls--
`General movement: Actually makes the player move
if force# > 0
move object left player#, force#,
endif
if force# < 0
Move object right player#, force#,
endif
`Right----------------
If keystate(32) and force# > -5 `Right - D; Increases the force to move right
dec force#, .5
yrotate object player#, fac#+0
`force# = force#-force#-force#
endif
If keystate(32) = false and force# <.1 `Right; If you're not pressing "D" slow the player down until force#=0
inc force#, .5
endif
`Left-----------------
If keystate(30) and force# < 5 `Left - A; Increases the force to move left
inc force#, .5
yrotate object player#, fac#+180
endif
If keystate(30) = false and force# >0 `Left; If you're not pressing "A" lower the force down until force#=0
dec force#, .5
endif
Rem -- Flying & Gravity --
Collide# = SC_getCollisionDistance ()
If keystate(42) and jfuel# > 1 `If flying, decrease fuel (Spacekey)
Dec JFuel#,MinFuel#
endif
If keystate(42) and gravity# <8 and jfuel# > MinFuel# `Actually makes player fly (decreased gravity)
inc gravity#, .25
endif
If keystate(42) = false and JFuel# < max_fuel# and inctimer <= timer() `Increases fuel up to 75 by 1
inctimer = timer() + refill_speed#
inc JFuel#,1
endif
If keystate(42) = false and gravity# > max_gravity# `If you're not pressing shift then add more gravity
dec gravity#, .2
endif
If jfuel# < MinFuel# and gravity > max_gravity# `No fuel: add more gravity
dec gravity#, .2
endif
If gravity# < max_gravity# `Forces Max Gravity
gravity# = max_gravity#
endif
If collide# < 2 and gravity# < -2
Gravity# = -2
endif
If keystate(42) and jfuel# > minfuel# and soundtime <= timer()
soundtime = timer() + 1030
play sound JetSound#
endif
If keystate(42) = false or jfuel# <= minfuel#
stop sound JetSound#
soundtime = timer() = 0
endif
`New object positions (for collisions)
x# = object position x(player#)
y# = object position y(player#)
z# = object position z(player#)
`Sliding Collisions Function
SlidingCollision(OX#,OY#,OZ#,X#,Y#,Z#,36,player#,ground#)
Return
HUD:
Grav# = Gravity#
`JET PACK:
Set text font "arial" : set text size 16
Set cursor 555,410
Print "Jet Fuel: ", jfuel#
`AMMO:
Set cursor 10,410
Print "Ammo: ", Ammo#
`LIFE:
Set cursor 10,390
Print "Life: ", fac#
`Stats:
Set cursor 10,90
Print "Move: ", force#, `Prints current force
Set cursor 10,70
Print "Gravity: ", gravity#, `Prints current gravity
Set cursor 10,50
Print "Collision: ", Collide# `Prints if a collision is detected
Set Cursor 10,30
Print "Object Position Z: ", oz#
Set Cursor 10,10
Print "Player Y Angle: ", playerY#
GameOver:
If Object position y(player#) < -500 `If you fall off the map the game is ended
` EndGame()
Endif
Return
Shoot:
`Full ammo, then shoot
If keystate(57) and keystate(19)=false and ammo# > 0 and shoottimer <= timer() `Full ammo, then shoot
Shoottimer = timer() + Shoot_Speed#
play sound shoot# `Plays gun sound
dec ammo#, 1 `Decreases the ammo by 1
Gosub Bullet
endif
`No ammo, gun_click
If keystate(57) and empty <=timer() and ammo# < 1
Empty = timer() + Empty_Speed#
Play sound empty#
endif
`If spacebar is not press and ammo < 30 Reload
If keystate(19) and ammo# < 30 and keystate(57)=false `Reloading
shoottimer = timer() + Reload_Speed#
Play Sound reload#
Ammo# = Reloaded#
endif
Return
Bullet:
PlayerY# = Object angle y (player#)
Bullet = FreeObject() `Gets lowest free object number
Make object cube Bullet,5 `Makes the bullet
Position object Bullet,lx,ly,lz `Positions bullet
rotate object Bullet, 0,PlayerY#-90,0 `Rotates bullet
bulletmove# = 1 `Move bullet
Move Object bullet,bulletspeed#
Return
BulletLife:
If Bulletmove# = 1 then move object bullet,bulletspeed# `Moves bullet if alive
Return
Rem *** Include File: source\media.dba ***
Rem Created: 7/28/2009 2:25:16 PM
Rem Included in Project: ...\Dark Basic Professional\Projects\SideScroller\SideScroller.dbpro
`Loads/makes all the media
Makelevel:
`Makes/Loads the level
Load object "Bin\maps\map1.dbo", Ground#
Position Object Ground#, 0,-25,0
SC_SetupObject Ground#,0,0
Return
LoadMedia:
`Sounds
Load Sound "Bin\Sounds\shoot.wav", Shoot#
Load Sound "Bin\Sounds\empty_gun.wav", Empty#
Load Sound "Bin\Sounds\reload.wav", Reload#
Load Sound "Bin\Sounds\jetpack.wav", JetSound#
Return
Rem *** Include File: source\functions.dba ***
Rem Created: 7/29/2009 2:37:48 PM
Rem Included in Project: ...\Dark Basic Professional\Projects\SideScroller\SideScroller.dbpro
Rem Functions :-: (Must be at end of code)
Function SlidingCollision(X1#,Y1#,Z1#,X2#,Y2#,Z2#,Radius#,Dyn,Obj)
C = sc_SphereSlide(Obj,X1#,Y1#,Z1#,X2#,Y2#,Z2#,Radius#,0)
If C > 0
cx# = sc_getCollisionSlideX()
cy# = sc_getCollisionSlideY()
`cz# = sc_getCollisionSlideZ() `We don't want sliding collisions for the z axis because this is a side scroller
Position Object Dyn, cx#, cy#, cz#
Endif
EndFunction
Delete Memblock 1 `Force-Calls Memory Block plugin
Function FreeObject()
Repeat
inc i
if object exist(i)=0 then found#=1
until found#
EndFunction i
Function Gun_Shoot()
Obj = FreeObject()
Make object cube Obj,1
Position object Obj, lx,ly,lz
Endfunction
Thanks a lot!!
ßõw§€r¥¤