Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Sliding Collisions for a Zombie Game

Author
Message
bobbyhill
19
Years of Service
User Offline
Joined: 6th Apr 2005
Location:
Posted: 1st May 2005 02:19
Hi,

I read as much as I could about collisions but still confused! Please help I'm still learning.
I'm trying to make a simple zombie game by combining the tutorial that comes with DBPro (the fps example with the floating aliens) and the sliding collision code by Aura (http://forum.thegamecreators.com/?m=forum_view&t=36053&b=6). I can't figure out how to get the same collision code to work for my zombies, they just pass through my buildings in the x level I made. I want them to come at me, but when they collide with object in my level I want them to slide and go around the object and keep coming at me. I commented out my attempts in the code as you'll see...

Thanks in advance,

Bobby
HowDo
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 1st May 2005 22:01
your source bounced! try again.

In Space No One can Hear You Scream! (When your comm Line is cut?)
bobbyhill
19
Years of Service
User Offline
Joined: 6th Apr 2005
Location:
Posted: 2nd May 2005 03:13
here it is again...

bobby
Lame Brain
19
Years of Service
User Offline
Joined: 28th Apr 2005
Location: Portland, OR
Posted: 2nd May 2005 04:48
Try using the Code button(above) instead of the code box (below).

to use it, just press it once, and it will add a box that says "{code}"
then you paste your program in and press it again and it will say "{/code}" (although its in sqaure brakets instead of squggly ones.)

Another hair-brained idear from... LAME BRAIN!
bobbyhill
19
Years of Service
User Offline
Joined: 6th Apr 2005
Location:
Posted: 2nd May 2005 22:50
one more time...set display mode 800,600,32
sync on : sync rate 100
autocam off
Set camera range 1,25000
hide mouse
set normalization on
backdrop on : color backdrop 0 `RGB(130,130,130)

rem Make normal light
set ambient light 60
rem Make shadow light
make light 1
position light 1,250,100,250
color light 1,150,150,150
set light range 1,10000
fog on : fog distance 2500 : fog color RGB(0,0,0)

remstart
rem test light
make light 2
position light 2,0,-5,100
color light 2,250,160,0
set light range 2,4000
`make object cube 44,165
`position object 44,0,-5,100
remend

rem inilalize player origin
X#=0
Z#=-500
Y#=0

rem Select font
set text font "arial" : set text size 16
set text to bold : set text transparent

rem Loading prompt
sync : center text screen width()/2,screen height()/2,"LOADING" : sync

rem Load all media for game
gosub _load_game

rem Setup all objects for game
gosub _setup_game

Rem Main Game loop
Do

rem Control game elements
gosub GravityPlayer
` gosub SlidingCollisionEnemy
` gosub GravityEnemy
gosub hitroof
gosub _control_player
gosub _control_gunandbullet
gosub _control_enemies

set cursor 10,10
print screen fps()

oldcAY# = cAY#
oldcAX# = cAX#

cAY# = WrapValue(cAY#+MousemoveX()*0.2)
cAX# = WrapValue(cAX#+MousemoveY()*0.2)
caZ# = Camera angle Z()

Rem input for the players wall collision
if KEYSTATE(17)
XTest# = Newxvalue(X#,cAY#,speed)
ZTest# = Newzvalue(Z#,cAY#,speed)
gosub SlidingCollisionPlayer

else
if KEYSTATE(31)
XTest# = Newxvalue(X#,Wrapvalue(cAY#-180),speed)
ZTest# = Newzvalue(Z#,Wrapvalue(cAY#-180),speed)
gosub SlidingCollisionPlayer
Endif
Endif

if KEYSTATE(30)
XTest# = Newxvalue(X#,Wrapvalue(cAY#-90),speed)
ZTest# = Newzvalue(Z#,Wrapvalue(cAY#-90),speed)
gosub SlidingCollisionPlayer
else
if KEYSTATE(32)
XTest# = Newxvalue(X#,Wrapvalue(cAY#+90),speed)
ZTest# = Newzvalue(Z#,Wrapvalue(cAY#+90),speed)
gosub SlidingCollisionPlayer
Endif
Endif

Rem Rotate camera with mouse movement
YRotate camera CurveAngle(cAY#,oldcAY#,24)
XRotate camera CurveAngle(cAX#,oldcAX#,24)

rem position camera at the position of the players sliding sphere
Position Camera X#-25,Object position y(player)+20,Z#


`jump
if spacekey()=1
position object player,Object position x(player),Object position y(player)+height,Object position z(player)
height=height-1
else
height=20
endif
if height=<0
height=0
endif

`crouch
if controlkey()=1
crouch=crouch+5
else
crouch=crouch-5
endif

if crouch=>50
crouch=50
endif

if crouch=<0
crouch=0
endif

`walk
if KEYSTATE(42) or controlkey()=1
speed=10
else
speed=20
endif

remstart
`goto gravity
gosub GravityPlayer
gosub SlidingCollisionEnemy
gosub GravityEnemy
gosub hitroof
remend

Sync
rem End loop
loop

rem End program
end

Rem Heres the magic
SlidingCollisionPlayer:
position object player,XTest#,Object position y(player),Z#
if object collision(world,player) = 0 then X# = XTest#
position object player,X#,Object position y(player),ZTest#
if object collision(world,player) = 0 then Z# = ZTest#
return

remstart
SlidingCollisionEnemy:
position object ene,XTest#,Object position y(ene),Z#
if object collision(world,ene) = 0 then X# = XTest#
position object ene,X#,Object position y(ene),ZTest#
if object collision(world,ene) = 0 then Z# = ZTest#
return
remend

GravityPlayer:
rem gravity
position object playerGrav,X#,Object position y(player)-63+crouch,Z#
if Object collision(world,playerGrav)>0
ondeck=1
else
ondeck=0
if player_speedz1=>0
player_speedz1=0
endif
player_speedz1=player_speedz1-1
position object player,Object position x(player),Object position y(player)+player_speedz1,Object position z(player)
endif

position object playerGrav,X#,Object position y(player)-64+crouch,Z#
if Object collision(world,playerGrav)>0
if player_speedz1=<-0
player_speedz1=0
endif
player_speedz1=player_speedz1+1
position object player,Object position x(player),Object position y(player)+player_speedz1,Object position z(player)
endif

if player_speedz1=>50
player_speedz1=50
endif

if player_speedz1=<-50
player_speedz1=-50
endif
return

remstart
GravityEnemy:
rem gravity
position object eneGrav,X#,Object position y(ene)-63+crouch,Z#
if Object collision(world,eneGrav)>0
ondeck=1
else
ondeck=0
if player_speedz1=>0
player_speedz1=0
endif
player_speedz1=player_speedz1-1
position object ene,Object position x(ene),Object position y(ene)+player_speedz1,Object position z(ene)
endif

position object eneGrav,X#,Object position y(ene)-64+crouch,Z#
if Object collision(world,eneGrav)>0
if player_speedz1=<-0
player_speedz1=0
endif
player_speedz1=player_speedz1+1
position object ene,Object position x(ene),Object position y(ene)+player_speedz1,Object position z(ene)
endif

if player_speedz1=>50
player_speedz1=50
endif

if player_speedz1=<-50
player_speedz1=-50
endif
return
remend

hitroof:
position object playerGrav,X#,Object position y(player)+50,Z#
if Object collision(world,playerGrav)>0
height=0
if player_speedz1=>0
player_speedz1=0
endif
endif
return

_control_player:
remstart
rem Control player direction
rotate camera camera angle x(0)+(mousemovey()/2.0),camera angle y(0)+(mousemovex()/2.0),0

rem Control player movement
cx#=camera angle x(0) : cy#=camera angle y(0)
if upkey()=1 then xrotate camera 0,0 : move camera 0,0.2 : xrotate camera 0,cx#
if downkey()=1 then xrotate camera 0,0 : move camera 0,-0.2 : xrotate camera 0,cx#
if leftkey()=1 then yrotate camera 0,cy#-90 : move camera 0.2 : yrotate camera 0,cy#
if rightkey()=1 then yrotate camera 0,cy#+90 : move camera 0.2 : yrotate camera 0,cy#
if wrapvalue(camera angle x(0))>40 and wrapvalue(camera angle x(0))<180 then xrotate camera 0,40
if wrapvalue(camera angle x(0))>180 and wrapvalue(camera angle x(0))<280 then xrotate camera 0,280

rem Apply simple gravity to player
position camera camera position x(),camera position y()-0.1,camera position z()

rem Player is always focal point of sky
position object SkyObj,camera position x(),camera position y(),camera position z()
remend

rem Position listener at player for 3D sound
position listener camera position x(),camera position y(),camera position z()
rotate listener camera angle x(),camera angle y(),camera angle z()

rem In case of restart
if restart=1
restart=0
` set bsp collision off 1
rotate camera 0,0,0
position camera 0,0,-500
` set bsp camera collision 1,0,0.75,0
endif

return

_control_gunandbullet:

rem Control gun firing
if mouseclick()=1 and bullet=-50
bullet=100
play sound GunSnd
position object BulletObj,camera position x(0),camera position y(0),camera position z(0)
rotate object BulletObj,camera angle x(0),camera angle y(0),0
` set bsp object collision 2,BulletObj,0.1,1
move object BulletObj,0.2
rem *ADDCODE* TUT9B
endif

rem Control life of bullet
if bullet>0

rem If bullet collides with BSP world
if bsp collision hit(2)=1 or bulletimpact=1
rem End bullet on wall
position sound ImpactSnd,object position x(BulletObj), object position y(BulletObj), object position z(BulletObj)
play sound ImpactSnd
bulletimpact=0
bullet=0
else
rem Move bullet
dec bullet
move object BulletObj,0.5
endif

rem *ADDCODE* TUT9C

rem Bullet dies
if bullet=0
rem *ADDCODE* TUT9D
set bsp collision off 2
endif

else
rem Gun recharge phase
if bullet>-50 then dec bullet
endif

return

_control_enemies:

rem Variable for finding closest enemy
cdist#=9999.99

rem Handle enemies within world
for ene=EneObj to EneObj+4

rem If enemy alive
if object visible(ene)=1

rem Kill this enemy
killenemy=0

remstart
rem Move enemy on a slow curve for appearance of intelegence
if object angle z(ene)=0
yrotate object ene,wrapvalue(object angle y(ene)+2)
endif
if object angle z(ene)=1
yrotate object ene,wrapvalue(object angle y(ene)-2)
endif
if object angle z(ene)=2
move object ene,1.0
else
remend
move object ene,5.5
` endif

rem Switch direction of curve based on a random value
` if rnd(200)=1 then zrotate object ene,rnd(1)


remstart
rem Handle gravity for enemy
position object ene,object position x(ene),object position y(ene)-0.01,object position z(ene)
remend

rem Work out angle and distance between enemy and player
dx#=camera position x(0)-object position x(ene)
dy#=camera position y(0)-object position y(ene)
dz#=camera position z(0)-object position z(ene)
dist#=abs(sqrt(abs(dx#*dx#)+abs(dy#*dy#)+abs(dz#*dz#)))
viewa#=wrapvalue(atanfull(dx#,dz#))
obja#=wrapvalue(object angle y(ene))
if viewa#>180 then viewa#=viewa#-360
if obja#>180 then obja#=obja#-360

rem If enemy 'facing player' and 'on similar height' and 'close', zoom in
if abs(viewa#-obja#)<360.0 and abs(dy#)<500.0 and dist#<5000.0
if object angle z(ene)<>2 then play sound EnemygunSnd
rotate object ene,0,viewa#,2
set object speed ene,200
else
set object speed ene,100
endif

rem If enemy gets too close to player, player dies
if dist#<30.0
play sound DieSnd
for x=0 to 100
point camera object position x(ene), object position y(ene)+(x/20.0), object position z(ene)
sync
next x
restart=1
killenemy=1
endif

rem If enemy and bullet in same space, enemy dies
if bullet>0
if object collision(BulletObj,ene)>0
play sound EnemydieSnd
play object ene,26,26+50
set object speed ene,100
bulletimpact=1
endif
endif

rem Closest enemy emits the enemy sound
if dist#<cdist#
cdist#=dist#
position sound EnemySnd,object position x(ene), object position y(ene), object position z(ene)
position sound EnemygunSnd,object position x(ene), object position y(ene), object position z(ene)
position sound EnemydieSnd,object position x(ene), object position y(ene), object position z(ene)
endif

rem Hide enemy when die animation over
if object frame(ene)>26+25 and object visible(ene)=1
killenemy=1
endif

if killenemy=1
set bsp collision off 3+(ene-EneObj)
hide object ene : dec aliensleft
killenemy=0
endif

rem If enemy alive ENDIF
endif

next ene

return

_control_stats:
rem *ADDCODE* TUT9A
return

_setup_game:

rem Setup gun for player
lock object on GunObj
scale object GunObj,2,2,4
rotate object GunObj,180,0,180
position object GunObj,0.5,-1,2
disable object zdepth GunObj

rem Create object for bullet
BulletObj=3 : make object cube BulletObj,0.1

remstart
rem Create simple sprite based crosshair
sprite 1,400-16,300-16,CrossHairImg
set sprite 1,0,1
remend

rem Place enemies throughout world and set BSP collision for them
aliensleft=0
restore EnemyPosData
for ene=EneObj to EneObj+4
read ex#,ey#,ez#
position object ene,ex#,ey#,ez#
` set bsp object collision 3+(ene-EneObj),ene,0.75,0
yrotate object ene,180 : fix object pivot ene
inc aliensleft
next ene

remstart
rem Start the enemy presence sound
loop sound EnemySnd
scale listener 0.1
remend

rem Trigger player initialisation
restart=1

return

_load_game:

rem Load world
world=7
load object "models\scene.x",world
position object world,0,-73,0
scale object world,100,100,100
set object texture world,0,1
Set object collision to polygons world
SET OBJECT TRANSPARENCY world,2
`set object fog 7,1
`play object 7,39,79

rem make players wall collision
player=10
make object cube player,70
Set object collision to polygons player
hide object player

rem create player ground collision
playerGrav=4
make object cube playerGrav,65
set object collision to polygons playerGrav
hide object playerGrav

player_speedz1=0


rem Load model for gun
GunObj=2 : load object "models\gun\gun.x",GunObj

rem Load models for enemies
EneObj=11
for ene=EneObj to EneObj+4
load object "models\enemy\simpleguy.x",ene
` append object "models\enemy\H-Alien Psionic-Die.x", ene, total object frames(ene)+1
scale object ene,100,100,100
set object collision to boxes ene
` loop object ene,0,25
next ene

rem Load all sounds
GunSnd=1 : load sound "sounds\gun.wav",GunSnd
ImpactSnd=2 : load 3dsound "sounds\impact.wav",ImpactSnd
DieSnd=3 : load sound "sounds\die.wav",DieSnd
EnemySnd=11 : load 3dsound "sounds\enemy.wav",EnemySnd
EnemygunSnd=12 : load 3dsound "sounds\enemygun.wav",EnemygunSnd
EnemydieSnd=13 : load 3dsound "sounds\enemydie.wav",EnemydieSnd

rem Load music (WAV best for looping)
MusicSnd=101 : load sound "sounds\ingame.wav",MusicSnd
loop sound MusicSnd : set sound volume MusicSnd,80

rem Load images
` FireImg=1 : load image "images\fire.bmp",FireImg
` CrossHairImg=2 : load image "images\crosshair.bmp",CrossHairImg

return

rem Enemy position data within level
EnemyPosData:
data -1190.27,-30,-2.78
data -2160.54,-30,19.18
data 3120.0,-30,25.0
data -1120.0,-30,25.0
data 1120,-30,10.0

Login to post a reply

Server time is: 2024-09-23 19:30:54
Your offset time is: 2024-09-23 19:30:54