hey, i have to make a 2.5d platformer for school and am using the game creators tutorial out of their magazine issue 62. im trying to implement sparkies collision to the cubes that make up the platforms in the ascii map. im having trouble understanding some of the code. if anyone could give me heads up on how to setup collision for the objects that would be great or explain what this line of code means.
curobj= ((y*(map_x+1))+x)+1000
the rest of the code is
set display mode 1280,1024,32
sync on
sync rate 50
autocam off
set dir ".."
autocam off
global curobj=100
type maptype
col as byte
block as integer
id as integer
state as byte
marker$ as string
endtype
global map_x=50
global map_y=80
global plx#
global ply#
global plf#
global pli#
global oplx#
global oply#
global plxs#
global plys#
`global pdir#
`global pdir
global retx
global rety
global retx#
global rety#
dim char_col(2,2)
dim map(map_x,map_y) as maptype
load image "C:\Users\Owner\Downloads\New folder (3)\Platformer Tutorial\Media\Backdrops\desert mountains.png",10
`Block 1, Brick
make object cube 31,5.0 : hide object 31
`Block 2, Jewel
load object "C:\Users\Owner\Downloads\New folder (3)\Platformer Tutorial\Media\Meshes\jewel.x",32 : hide object 32
`Block = 12
global map_tran$=" *"
`global jewel_count
`global jewel_score
`jewel_count=0
`jewel_score=0
gosub set_testmap
gosub build_map
`set camera range 20.0,1000.0
color backdrop rgb(128,128,255)
fog distance 1000
fog on
fog color rgb(128,128,255)
`Make backdrop plains
for n=0 to 4
make object plain 20+n,146*7,87*5
position object 20+n,map_x*2.5,n*50.0-rnd(32),300+(n*50)
texture object 20+n,10
scroll object texture 20+n,rnd(100)/100.0,0.0
set object transparency 20+n,2
set object texture 20+n,0,0
set object fog 20+n,1
next n
load object "C:\Users\Owner\Downloads\New folder (3)\Platformer Tutorial\Media\Characters\schlump.x",5 : loop object 5
SC_setupObject 5, 0, 0
do
`64-400
`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 camy#<64 then camy#=64
`if camy#>400 then camy#=400
position light 0,16.5*5.0,camy#+200.0,-153.0
position camera plx#, ply#, - 100
rotate camera 0,0,0
update_player()
`update_pickups()
text 0,0,"Jewels: "+str$(jewel_score)+"\"+str$(jewel_count)
sync
loop
`-------------------------------------------------------------------------------------
set_testmap:
` 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,"* o***********************o *")
map_set(18,"* *")
map_set(19,"* *")
map_set(20,"*****o o*****")
map_set(21,"* *")
map_set(22,"* *")
map_set(23,"* *")
map_set(24,"*********o o*********")
map_set(25,"* *")
map_set(26,"* *")
map_set(27,"* *")
map_set(28,"*************o o*************")
map_set(29,"* *")
map_set(30,"* *")
map_set(31,"* *")
map_set(32,"* ************* *")
map_set(33,"* *oo oo* *")
map_set(34,"* *** *** *")
map_set(35,"* * * *")
map_set(36,"* * * *")
map_set(37,"* **** **** *")
map_set(38,"* * * *")
map_set(39,"* *")
map_set(40,"* *")
map_set(41,"**** ****")
map_set(42,"* * * *")
map_set(43,"* * * *")
map_set(44,"* oo * oo * oo *")
map_set(45,"* * * *")
map_set(46,"***** * ********* *")
map_set(47,"* * * *")
map_set(48,"* oo * oo * oo *")
map_set(49,"* * * *")
map_set(50,"* ********* * *****")
map_set(51,"* * * *")
map_set(52,"* oo * oo * *")
map_set(53,"* * * *")
map_set(54,"***** * ********* *")
map_set(55,"* * * *")
map_set(56,"* * oo * oo *")
map_set(57,"* * * *")
map_set(58,"* ********* * *****")
map_set(59,"* * * *")
map_set(60,"* * * *")
map_set(61,"* * * *")
map_set(62,"* **** * ***** **** *")
map_set(63,"* *ooo ooo* *")
map_set(64,"* * * *")
map_set(65,"* * * *")
map_set(66,"* **** ********* **** *")
map_set(67,"* o o o o o o o *")
map_set(68,"* *")
map_set(69,"* *")
map_set(70,"* ********* ********* *")
map_set(71,"* o o *")
map_set(72,"* *")
map_set(73,"* S *")
map_set(74,"* ttttttttt *")
map_set(75,"* o o o o *")
map_set(76,"* o o o *")
map_set(77,"* *")
map_set(78,"* *")
map_set(79,"* *")
map_set(80,"**************************************************************************")
return
`-------------------------------------------------------------------------------------
build_map:
for y=0 to map_y
for x=0 to map_x
curobj=((y*(map_x+1))+x)+1000
if object exist(curobj)=1 then delete object curobj
xx#=(x*5.0)+ 2.5
yy#=(y*5.0)+2.5
zz#=0.0
if map(x,y).block=1 `Brick
map(x,y).id=curobj
clone object curobj,31
SC_setupObject curobj, 1, 2
SC_allowObjectScaling curobj
scale object curobj,100,100,200-rnd(50)
SC_updateobject curobj
`r=rnd(255) : g=rnd(255) : b=rnd(255)
`color object curobj,rgb(r,g,b)
`set object emissive curobj,rgb(r/2,g/2,b/2)
position object curobj,xx#,yy#,zz#
endif
remstart
if map(x,y).block=2 `Jewel
inc jewel_count,1
map(x,y).id=curobj
map(x,y).state=0
clone object curobj,32
r=rnd(255) : g=rnd(255) : b=rnd(255)
`color object curobj,rgb(r,g,b)
set object emissive curobj,rgb(r/2,g/2,b/2)
ghost object on curobj
position object curobj,xx#,yy#,zz#
endif
remend
next x
next y
return
`-------------------------------------------------------------------------------------
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" `Start marker
plx#=(x*5.0)
ply#=(y*5.0)
endif
for n=1 to len(map_tran$)
if mid$(map_tran$,n)=pm$ then map(x,y).block=n-1
next n
map(x,y).marker$=pm$
next p
endfunction
`-------------------------------------------------------------------------------------
function update_player()
oplx#=plx#
oply#=ply#
`Left and Right movement control
mv=0
if leftkey()=1 `then mv=-1
DEC plxs#, 0.4
rotate object 5, 0, 90, 0
ENDIF
if rightkey()=1 `then mv=1
INC plxs#, 0.4
rotate object 5, 0, -90, 0
ENDIF
`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.2
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
remstart
`Update animation
if plf#<49
`Static or moving
if mv=0
plf#=10.0+(sin(timer()/10.0)*7.0)
else
if plf#<19 then plf#=19 : pli#=1.0
inc plf#,abs(plxs#*2.0)
if plf#>44 then dec plf#,20.0
endif
else `Jumping
inc plf#,0.5
if plf#>51 then plf#=51
endif
remend
`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#
`collision-------------------------------------------------------------------------------------------------------
colb=character_col(plx#,ply#,3.0,6.5)
if colb=1
if character_col(plx#,oply#,3.0,6.5)=1 then plx#=oplx#
if character_col(oplx#,ply#,3.0,6.5)=1
ply#=oply#
if plys#<0 then plys#=plys#*0.5 else plys#=0
if plf#>50 then plf#=0.0
pli#=2.0
endif
if character_col(plx#,ply#,3.0,6.5)=1 `Safety measure, avoid sticking
plx#=oplx# : plxs#=0.0
ply#=oply# : plys#=0.0
endif
endif
if upkey()=1 and character_col(plx#,ply#-1.5,3.0,6.5)=1
plys#=3.5
`plf#=20
`pli#=3.0
endif
`--------------------------------------------------------------------------------------------------------------
`Update player direction Left:Pdir=-1, Right:Pdir=1
remstart
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 animation smoothing
dec pli#,0.1 : if pli#<0 then pli#=0 else set object interpolation 5,pli#
remend
`Update player position etc
position object 5,plx#,ply#,0 : `rotate object 5,0,pdir#*-90.0,0
`set object frame 5,plf#
endfunction
`-------------------------------------------------------------------------------------
remstart
function update_pickups()
ang#=timer()/3.0
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,ang#+(map_x*10.0),0
endif
next x
next y
endfunction
remend
`-------------------------------------------------------------------------------------
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
remstart
`diamiond collection
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
endif
endif
remend
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