 TNT Basic Forums > Bugs! Another Sprite Bug < Last Thread     Next Thread >
Author
 Thread  02-26-2006 17:23

Posted by:
Jacob

Location:
San Francisco, CA

This is my code for my sprite collisions:

procedure blockWithTiles(float x, float y, float x2, float y2, int image, int bank)
set default image bank bank : canvas 1
blockedT=-1
blockedD=-1
blockedL=-1
blockedR=-1
int tx, ty, iw=image width(image), ih=image height(image), d=1, fromWhat, toWhat
float x3=x, y3=y
if y2>y then d=-1
if y2<y then d=1
if d=-1 : fromWhat=floor(y/tilesize+ih/tilesize)-1 : toWhat=floor(y/tilesize) : end if
if d=1 : fromWhat=floor(y/tilesize)-1 : toWhat=floor(y/tilesize+ih/tilesize) : end if
for tx=floor(x/tilesize) to floor(x/tilesize+iw/tilesize)
for ty=fromWhat to toWhat step d
if tx>-1 and tx<levelLength+1 and ty>-1 and ty<18
int t=tileType[1, tx, ty]
if t>0 and tileAction[t]=0
set image bank 100, bank : sprite 100, x, y, image
set image bank 101, 153 : sprite 101, tx*tileSize, ty*tileSize, t
int ok=1
sprite 100,x,y2-2 : if sprite col(100,101)>0 then ok=0
sprite 100,x,y2-1 : if sprite col(100,101)>0 then ok=0
if ok=0 : if x2>x then blockedL=tileAction[t] : if x2<x then blockedR=tileAction[t] : x=x2 : end if
sprite 100,x,y : if sprite col(100,101)>0 : if y2>y then blockedT=tileAction[t] : if y2<y then blockedD=tileAction[t] : y=y2 : end if
repeat
sprite 100,x,y : if sprite col(100,101)>0 : y=y-1 : else : break : end if
forever
end if
end if
next
next
newX=x
newY=y
sprite 100, 0, 4000
sprite 101, 0, 4000
End Proc
Procedure up

This code does nothing at all.
But, if I comment out the two lines that move the sprites to 4000 in the y direction it works fine.

Now this shouldn't do anything because I do that after it collides the sprites. 02-26-2006 19:26

Posted by:
allnodcoms

Location:
hertfordshire (England)

You're an 'end if' missing...

...amongst other things. I reformatted the code in Hieroglyph and you're an 'end if' missing, so the basic logic is out, causing unexpected errors (26 of them in fact).

It was a lot easier to spot the error when the code was formatted with single line statements and indented conditionals, three 'if' statements on a single line is possibly a bit enthusiastic?

Without the rest of the code it's a bit difficult to see what's really going on, there's no 'draw frame' in there for example, and I can't test to completion as I don't know what's going on in the rest of program.
Try reformatting the code, add another end if and see if this solves the problem.

Danny (nods) 02-26-2006 19:52

Posted by:
Jacob

Location:
San Francisco, CA

I don't see a missing End If anywhere...

Here, I've got rid of the single-line stuff:

procedure blockWithTiles(float x, float y, float x2, float y2, int image, int bank)
set default image bank bank : canvas 1
blockedT=-1
blockedD=-1
blockedL=-1
blockedR=-1
int tx, ty, iw=image width(image), ih=image height(image), fromWhat, toWhat
float x3=x, y3=y
if y2>y : fromWhat=ceil(y/tilesize+ih/tilesize) : toWhat=floor(y/tilesize) : end if
if y2<y : fromWhat=floor(y/tilesize) : toWhat=ceil(y/tilesize+ih/tilesize) : end if
for tx=floor(x/tilesize) to floor(x/tilesize+iw/tilesize)
for ty=fromWhat to toWhat step (toWhat-fromWhat)/abs(toWhat-fromWhat)
if tx>-1 and tx<levelLength+1 and ty>-1 and ty<18
int t=tileType[1, tx, ty]
if t>0 and tileAction[t]=0
set image bank 100, bank : sprite 100, x, y, image
set image bank 101, 153 : sprite 101, tx*tileSize, ty*tileSize, t
int ok=1
sprite 100,x,y2-2 : if sprite col(100,101)>0 then ok=0
sprite 100,x,y2-1 : if sprite col(100,101)>0 then ok=0
if ok=0
if x2>x then blockedL=tileAction[t]
if x2<x then blockedR=tileAction[t]
x=x2
end if
sprite 100,x,y
if sprite col(100,101)>0
if y2>y then blockedT=tileAction[t]
if y2<y then blockedD=tileAction[t]
y=y2
end if
repeat
sprite 100,x,y
if sprite col(100,101)>0
y=y-1
else
break
end if
forever
end if
end if
next
next
newX=x
newY=y
sprite 100, 0, 4000
' sprite 101, 0, 4000
End Proc

This code works without the y for sprite 101 being set to 4000.

P. S. Too bad we can't have tabs in these forums. :(

 All times are GMT Forum Jump: Please select one: Games In Progress Programming Q&A Beyond Basic Feedback Game-In-60 Tutorials Q&A Bugs! TNT Basic - The Open Source Edition < Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite