[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[pygame] My solid tile detection doesn't work
- To: pygame-users@xxxxxxxx
- Subject: [pygame] My solid tile detection doesn't work
- From: "Adeola Bannis" <thecodemaiden@xxxxxxxxx>
- Date: Sat, 22 Jul 2006 12:05:04 -0400
- Delivered-to: archiver@seul.org
- Delivered-to: pygame-users-outgoing@seul.org
- Delivered-to: pygame-users@seul.org
- Delivery-date: Sat, 22 Jul 2006 12:05:14 -0400
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=Fo0ywTAzW73vTsskA6t8ORByRndF51zLwtxbhzfNsAI5iMc4tMoYhyAEYGqIGH8nPfo+jaeodIsHFTdIgs82q5mDG18EskoQnJuHoZ8Ftvc/030525x4k5olFhmsgYa2tsCUY+7t1JNLtegtRjsMY47wEwEE2nIXb+FgBjZVh4A=
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
In my little RPG engine-like thing that no one tested, *wink wink*, I
tried implementing solid tiles. My algorithm doesn't work, and I don't
know why.
This is the code I use to place tiles onscreen, only the important
half of the function:
---code---
for y in range(starty, endy):
for x in range(startx, endx):
tilepos = y*(self.mapw) + x; #The position in our array of tiles
showx = x - startx; showy = y - starty #Adjust the position of map
by blitting it to the top
truex = (showx*tilesize-xoff); truey = (showy*tilesize-yoff)
#print endy
tilenum = self.tiles[tilepos]
self.put_tile(tilenum,(truex,truey), screen)
---code---
and this is the code I used to look for a solid tile:
---code---
player_x, player_y = player_pos
p_tilex = player_x//tilesize; p_tiley = player_y//tilesize
n_tilex = n_tiley = 0
if direction == 'left':
n_tilex = (player_x - speed)// tilesize
if direction == 'right':
n_tilex = (player_x + speed)//tilesize
if direction == 'up':
n_tiley = (player_y - speed)//tilesize
if direction == 'down':
n_tiley = (player_y + speed)//tilesize
if (n_tiley == p_tiley) and (n_tilex == p_tilex):
return False
if (p_tilex != n_tilex): # we are moving to a new tile horizontally
n_tilepos = p_tiley*self.mapw + n_tilex # the position in our array of tiles
if (p_tiley != n_tiley): #we are moving to a new tile vertically
n_tilepos = n_tiley*self.mapw + p_tilex # the position in our array of tiles
tilenum = self.tiles[n_tilepos]; print tilenum
return (tilenum in self.solid)
---code---
I didn't want to put all that in... what I basically wanted to point
out was that I was getting the tile number the exact same way I did
when I was drawing the map. Yet I usually get a completely different
tile to the one the player is walking into. Can anybody help me out
here?
Adeola