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 / Help Newbie tile collision problem

Author
Message
Sladeh_boi
12
Years of Service
User Offline
Joined: 18th Jul 2012
Location:
Posted: 16th Aug 2012 20:30
Hi everyone this is my first post.

I am using a tile map to create a simple platformer. My problem is i cant seem to get the collision to recognize the "E" of the tile map. of end zone of the game. I simply want to end the game when the player collides with the "E" block in my tile map.

Any suggestions would be greatly appreciated as i'm quite stuck on this one.

Thanks Rich


`Fog
fog on
fog distance 1000
fog color rgb(125,125,240)
`------------------
`Backdrop plains
`------------------
for n=0 to 4
make object plain n+20,146*7,87*5
position object n+20,map_x*2.5,n*50.0-rnd(32),300+(n*50)
texture object n+20,11
scroll object texture n+20,rnd(100)/100.0,0.0
set object transparency n+20,2
set object texture n+20,0,0
set object fog n+20,1
next n
`----------------
`----------------
`MAIN LOOP
`----------------
`----------------
DO


if abs(camy#-ply#)>20.0
if camy#>ply# then dec camy#,0.5 : if camy#<ply# then camy#=ply#
if camy#<ply# then inc camy#,0.5 : if camy#>ply# then camy#=ply#
endif

if abs(camx#-plx#)>20.0
if camx#>plx# then dec camx#,0.5 : if camx#<plx# then camx#=plx#
if camx#<plx# then inc camx#,0.5 : if camx#>plx# then camx#=plx#
endif

if camy#<64 then camy#=64
if camx#>400 then camy#=400
if camx#<64 then camx#=64
if camx#>400 then camx#=400
position light 0,camx#,camy#+200.0,-153.0
position camera camx#,camy#,-110.0
rotate camera 0,0,0

Game_end=player()
if Game_end=1
cls
center text 640,512,"EnD"
wait key
endif

pickup()

text 0,0,str$(jewel_score)+"/"+str$(jewel_count)
text 0,20,str$(map(plx,ply).block)



sync
loop
`-----------------
`-----------------
`SUB ROUTINES
`-----------------
`-----------------
level:
` 000000000011111111112222222222333
` ## 012345678901234567890123456789012
map_set(00,"EEEEEEEEEEEEEEEEEEEEEEE ")
map_set(01,"************************************* *****")
map_set(02,"* ******")
map_set(03,"* ** *")
map_set(04,"* ** *")
map_set(05,"* ** *")
map_set(06,"* ** *")
map_set(07,"* ** *")
map_set(08,"* ** *")
map_set(09,"* ooo** *")
map_set(10,"* ooo** *")
map_set(11,"* ooo** *")
map_set(12,"* ********* *")
map_set(13,"* ** *")
map_set(14,"* **ooo *")
map_set(15,"* **ooo *")
map_set(16,"* **ooo *")
map_set(17,"* *********************** *")
map_set(18,"* *")
map_set(19,"* *")
map_set(20,"* *")
map_set(21,"* ******* ******")
map_set(22,"* *")
map_set(23,"* *")
map_set(24,"* S *")
map_set(25,"**************************************************")

return
`----------------
`----------------
build_map:

`For loop
for y=0 to map_y
for x=0 to map_x

`Qube def
qube=((y*(map_x+1))+x)+1000

`Delete previous level
if object exist(qube)=1 then delete object qube

`Set block cords
xx#=(x*5.0)+2.5
yy#=(y*5.0)+2.5
zz#=0.0

`Check for standard block and create
if map(x,y).block=1
map(x,y).id=qube
clone object qube,31
scale object qube,100,100,200
r=rnd(255):g=rnd(255):b=rnd(255)
color object qube,rgb(r,g,b)
set object emissive qube,rgb(r/2,g/2,b/2)
position object qube,xx#,yy#,zz#
endif

`Check for pickup and create
if map(x,y).block=2
map(x,y).id=qube
map(x,y).state=0
inc jewel_count
clone object qube,32
ghost object on qube
position object qube,xx#,yy#,zz#
endif

if map(x,y).block=3
map(x,y).id=qube
clone object qube,34
scale object qube,100,200,200
position object qube,xx#,yy#,zz#
endif

next x
next y

return
`----------------
`----------------
Camera:

OldCamAngleY# = CameraAngleY#
OldCamAngleX# = CameraAngleX#
CameraAngleY# = WrapValue(CameraAngleY#+MousemoveX()*0.08)
CameraAngleX# = WrapValue(CameraAngleX#+MousemoveY()*0.08)

If Leftkey()=1
XTest# = Newxvalue(X#,Wrapvalue(CameraAngley#-90),10)
ZTest# = Newzvalue(Z#,Wrapvalue(CameraAngley#-90),10)
ytest#=newyvalue(y#,wrapvalue(cameraanglex#),10)
x#=xtest#
z#=ztest#
y#=ytest#


endif

If Rightkey()=1
XTest# = Newxvalue(X#,Wrapvalue(CameraAngley#+90),10)
ZTest# = Newzvalue(Z#,Wrapvalue(CameraAngleY#+90),10)
ytest#=newyvalue(y#,wrapvalue(cameraanglex#),10)
X#=xtest#
Z#=ztest#
y#=ytest#

Endif

Rem Control input for camera
If Upkey()=1
xtest#=newxvalue(x#,wrapvalue(cameraAngleY#),10)
ztest#=newzvalue(z#,wrapvalue(cameraAngleY#),10)
ytest#=newyvalue(y#,wrapvalue(cameraangleX#),10)
x#=xtest#
z#=ztest#
y#=ytest#

Endif

if downkey()=1
xtest#=newxvalue(x#,wrapvalue(cameraAngleY#-180),10)
ztest#=newzvalue(z#,wrapvalue(cameraAngleY#-180),10)
ytest#=newyvalue(y#,wrapvalue(cameraAngleX#-180),10)
x#=xtest#
z#=ztest#
y#=ytest#

Endif

Yrotate camera CurveAngle(CameraAngleY#,OldCamAngleY#,24)
Xrotate camera CurveAngle(CameraAngleX#,OldCamAngleX#,24)

position camera X#,Y#,Z#

return

`--------------------------------------------------------


`----------------
`----------------
`FUNCTIONS
`----------------
`----------------
function map_set(y,marker$)

y=map_y-y

for p=1 to map_x+1
pm$=mid$(marker$,p)

x=p-1

if pm$="S"
plx#=(x*5.0)
ply#=(y*5.0)
endif


for n=1 to len(block$)
if mid$(block$,n)=pm$ then map(x,y).block=n-1
next n

map(x,y).marker$=pm$

next p

endfunction
`----------------
`----------------
function player()

oplx#=plx#
oply#=ply#

`Left and Right movement control
mv=0
if leftkey()=1 then mv=-1
if rightkey()=1 then mv=1

`Adjust player speeds
if mv=-1 then dec plxs#,0.4
if mv=1 then inc plxs#,0.4
if mv=0 then plxs#=plxs#/1.4
if mv=0 and plxs#>-0.05 and plxs#<0.05 then plxs#=0.0

`Limit player speed
if plxs#<-1.0 then plxs#=-1.0
if plxs#>1.0 then plxs#=1.0

`Update player position
inc ply#,plys#
inc plx#,plxs#
`Increase player drop rate
dec plys#,0.2
if plys#<-2.5 then plys#=-2.5


`USAGE:x#,y#,Radius#,Height#
colb=character_col(plx#,ply#,5.0,5.0)

if colb=2 then finish=1

if colb=1
if character_col(plx#,oply#,5.0,5.0)=1 then plx#=oplx#
if character_col(oplx#,ply#,5.0,5.0)=1
ply#=oply#
if plys#<0 then plys#=plys#*0.5 else plys#=0
endif
if character_col(plx#,ply#,5.0,5.0)=1 `Safety measure, avoid sticking
plx#=oplx# : plxs#=0.0
ply#=oply# : plys#=0.0
endif
endif

`jump
if spacekey()=1 and character_col(plx#,ply#-0.5,5.0,5.0)=1
plys#=3.5
endif

`Update player direction Leftdir=-1, Rightdir=1
if plxs#>0.2 and pdir<1 then pdir=1
if plxs#<-0.2 and pdir>-1 then pdir=-1
if pdir<0 then dec pdir#,0.3
if pdir>0 then inc pdir#,0.3

`Limit Pdir
if pdir#>1.0 then pdir#=1.0
if pdir#<-1.0 then pdir#=-1.0


`Update player position etc
position object 33,plx#+2.5,ply#+2.5,0
endfunction finish

`-------------------------------------------------------------------------
`-------------------------------------------------------------------------

function character_col(x#,y#,r#,h#)

col=0
charcol=0

for yy=0 to 2
for xx=0 to 2

xx#=0.0
if xx=2 then xx#=r#
if xx=0 then xx#=0.0-r#

yy#=h#/2.0
if yy=0 then yy#=h#
if yy=2 then yy#=0

col=map_block(x#+xx#,y#+yy#)
if col=1 then charcol=1

if col=2
if map(retx,rety).state=0
inc jewel_score,1
obj=map(retx,rety).id
map(retx,rety).state=1
map(x,y).block=0
hide object obj

if col=2 then charcol=2
endif
endif



char_col(xx,yy)=col

next xx
next yy

endfunction charcol

`--------------------------------------------------------------------------
`--------------------------------------------------------------------------

function map_block(x#,y#)

x=int(x#/5.0)
y=int(y#/5.0)

if x<0 then x=0
if x>map_x then x=map_x
if y<0 then y=0
if y>map_y then y=map_y

retx=x
rety=y

col=map(x,y).block

endfunction col

`---------------------------------------------------------------------------
`---------------------------------------------------------------------------

function pickup()

spin#=timer()

for y=0 to map_y
for x=0 to map_x

if map(x,y).block=2
rotate object map(x,y).id,0,spin#+500,0
endif
next x
next y

endfunction

Meep
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 17th Aug 2012 14:33 Edited at: 17th Aug 2012 14:34
Hi Rich,

Firstly, you'll need to provide all of the code including the definition 'map(x,y)' and the type used for it.

Secondly, you can (highly recommended) place your code in between the code tags [ code] code here [ /code] (without the spaces in the tags) which allows for collapsing and uncollapsing your code (makes the post smaller).

Lastly, I didn't see any collision commmands in there so you either haven't implemented them yet, they are in another piece of code or you're simply comparing coordinates (I'm assuming the latter).

Once you provide those things we can take a closer look.

Login to post a reply

Server time is: 2024-11-23 17:57:41
Your offset time is: 2024-11-23 17:57:41