forums

TNT Basic Forums > Programming Q&A
Trouble w/Tile Collision
< Last Thread     Next Thread >
Author
Thread        Post A Reply

08-07-2003 02:18

Posted by:
GameDev

Click Here to Email GameDev   Find more posts by GameDev

I am making a platform game where I use two maps, one for background, one for the level itself. When I run this code, however, my sprite stays idle without being on a tile in my second map. How can I fix this?
--------------------------------------
'SCREEN SIZE INTS
Global Int screenx=1152 'Screen Width
Global Int screeny=870 'Screen Height

'STARTING
Hide Mouse
Fade Down
graphics mode hardware screenx,screeny
VBL Sync On
set framerate 30

'GLOBAL INTS
'This is where all the global intergers besides the screen size will be stored
Global int tilesize=128 'The default tile size is 128x128
global int tmapw=20 'The default backgroung map width in tiles is 100
global int tmaph=20 'The default background map height in tiles is 75
global int btmapw=40
global int btmaph=80
global int pmapw=tilesize*tmapw 'The map width in pixels is the tilesize times the number of tiles wide
global int pmaph=tilesize*tmaph 'The map height in pixels is the tilesize times the number of tiles high
global int playerx=screenx/2
global int playery=screeny/2
global int rotation=0
global int xview=screenx
global int yview=screeny
global int velocity
global int acl=3
global int maxs=20
global int tile=0
global int ontile=0
Open Canvas 1,pmapw,pmaph
open viewport 1,0,0 to xview,yview

load images 128
load sounds 128
load map 128

'PLAYER SPRITE
'This is where the player sprite is created


Canvas 1
Draw map section 0,0 to tmapw,tmaph,0 to 0,0
load map 129
Draw map section 0,0 to btmapw,btmaph,0 to 0,0

sprite 0,playerx,playery,000

draw frame
fade up

while not mouse button
set sprite rotation 0,rotation

ontile=0
velocity=velocity
TileCheckProc()
if left
velocity=velocity-acl
spchecknProc()
end if

if right
velocity=velocity+acl
spcheckpProc()
end if

if ontile=0 then playery=playery-1

playerx+playerx+velocity
rotation=rotation+velocity
xview=xview+velocity

draw frame
set viewport offset 1,xview,yview
wend
procedure moveleftProc()
velocity=velocity-acl
end proc

procedure moverightProc()
velocity=velocity+acl
end proc

procedure spcheckpProc()
if velocity>maxs
velocity=maxs
end if
end proc

procedure spchecknProc()
if velocity<-maxs
velocity=-maxs
end if
end proc

Procedure TileCheckProc()
tile=Map Tile (playerx,playery,0)
if tile>0
ontile=1
end if
end proc

08-07-2003 14:24

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

>
tile=Map Tile (playerx,playery,0)
>
map tile uses tile choords, not pixel choords. You may want tro use this:

tile=Map Tile (playerx/tile width,playery/tile height,0)

08-11-2003 18:22

Posted by:
GameDev

Click Here to Email GameDev   Find more posts by GameDev

It still doesn't work. The sprite stays still :(

08-12-2003 14:16

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

The sprite stays still when it hits something?

08-12-2003 15:54

Posted by:
GameDev

Click Here to Email GameDev   Find more posts by GameDev

No, the sprite stays at the starting position, I even tried changing the code to playery=playery-1 and it didn't move vertically :(

08-12-2003 16:13

Posted by:
GameDev

Click Here to Email GameDev   Find more posts by GameDev

UPDATE:
I now revised my code to look like this:
-------------------------------------
'SCREEN SIZE INTS
Global Int screenx=1152 'Screen Width
Global Int screeny=870 'Screen Height

'STARTING
Hide Mouse
Fade Down
graphics mode hardware screenx,screeny
VBL Sync On
set framerate 30

'GLOBAL INTS
'This is where all the global intergers besides the screen size will be stored
Global int tilesize1=128 'The default tile size for map 1 is 128x128
global int tilew2=64
global int tileh2=32
global int tmapw=20 'The default backgroung map width in tiles is 100
global int tmaph=20 'The default background map height in tiles is 75
global int btmapw=40
global int btmaph=80
global int pmapw=tilesize1*tmapw 'The map width in pixels is the tilesize times the number of tiles wide
global int pmaph=tilesize1*tmaph 'The map height in pixels is the tilesize times the number of tiles high
global int playerx=screenx/2
global int playery=screeny/2
global int rotation=0
global int xview=screenx
global int yview=screeny
global int velocity
global int acl=3
global int maxs=20
global int tile=0
global int ontile=0
Open Canvas 1,pmapw,pmaph
open viewport 1,0,0 to xview,yview

load images 128
load sounds 128
load map 128

'PLAYER SPRITE
'This is where the player sprite is created


Canvas 1
Draw map section 0,0 to tmapw,tmaph,0 to 0,0
load map 129
Draw map section 0,0 to btmapw,btmaph,0 to 0,0

sprite 0,playerx,playery,000

draw frame
fade up

while not mouse button
set sprite rotation 0,rotation

ontile=0
velocity=velocity
TileCheckProc()
if left
velocity=velocity-acl
spchecknProc()
end if

if right
velocity=velocity+acl
spcheckpProc()
end if

if ontile=0
playery=playery-1
yview=yview-1
end if
playerx=playerx+velocity
rotation=rotation+velocity
xview=xview+velocity

draw frame

set viewport offset 1,xview,yview


wend
procedure moveleftProc()
velocity=velocity-acl
end proc

procedure moverightProc()
velocity=velocity+acl
end proc

procedure spcheckpProc()
if velocity>maxs
velocity=maxs
end if
end proc

procedure spchecknProc()
if velocity<-maxs
velocity=-maxs
end if
end proc

Procedure TileCheckProc()
tile=Map Tile (playerx/tilew2,playery/tileh2,0)
if tile>0
ontile=1
end if
end proc
--------------------------------------
Now the sprite falls of the map instantly while the viewport moves UP pixel by pixel

09-20-2003 23:23

Posted by:
GameDev

Click Here to Email GameDev   Find more posts by GameDev

I just got a chance to look back at my code this weekend, and I made a stupid mistake.

if ontile=0
playery=playery-1
yview=yview-1
end if

should be

if ontile=0
playery=playery+1
yview=yview+1
end if

I also added this line just to see if it would make any difference

if ontile=1
playery=playery
yview=yview
end if


However, the tile collision still isn't working. I would GREATLY appreciate whatever help you can give me regaurding this. Thank you :)

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.