Is the game 2D or 3D? What perspective are you using? Do players only move
one tile at a time or are free-roaming? These sorts of questions effect the
kind of collision calculations used. Assuming for the moment you mean a 2D
game, simple collision detection involves checking the distance between two
objects and moving them appart if they over lap. For example:
#player position
player_x = 100
player_y = 100
#player width/height
player_wh = 32
#block position
block_x = 80
block_y = 80
#block width/height
block_wh = 32
#collision check
if ((player_x < block_x + block_wh and player_x + player_wh > block_x)
and (player_y < block_y + block_wh and player_y + player_wh > block_y)):
print 'collision'
#if player is to the right of block, move more right
if player_x > block_x:
player_x += 1
print 'pushed right'
#if player is to the left of block, move more left
elif player_x < block_x:
player_x -= 1
print 'pushed left'
#if player is higher than block, move more up
if player_y > block_y:
player_y += 1
print 'pushed up'
#if player is below the block, move more down
elif player_y < block_y:
player_y -= 1
print 'pushed down'
else:
print 'no collision'
--
You received this message because you are subscribed to the Google Groups
"pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.