
Untitled
By: a guest on
May 19th, 2012 | syntax:
Python | size: 1.20 KB | hits: 20 | expires: Never
isOnTop = False
isOnBottom = False
isOnLeft = False
isOnRight = False
moving = False
global playerX, playerY, playerRect, gravity, xVel, yVel, movDir, friction, jumped, platforms
for x in platforms:
if playerRect.colliderect(x):
if playerRect.top < x.top:
playerY = x.top - 19
isOnTop = True
elif playerRect.top > x.top:
playerY = x.bottom
isOnBottom = True
if playerRect.right > x.right:
playerX = x.left - 19
isOnLeft = True
elif playerRect.left < x.right:
playerX = x.right + 1
isOnRight = True
if isOnTop == True:
yVel = 0
if isOnTop == False:
if yVel < 17:
yVel += gravity
if movDir == 1:
if isOnLeft == False:
if xVel < 10:
xVel += 0.5
moving = True
elif movDir == -1:
if isOnRight == False:
if xVel > -10:
xVel -= 0.5
moving = True
elif moving == False:
if xVel == 0:
pass
elif xVel > -0.1 and xVel < 0.1:
xVel = 0
elif xVel > 0:
xVel -= friction
elif xVel < 0:
xVel += friction
playerX += xVel
playerY += yVel
playerRect = pygame.Rect((playerX, playerY), (cubeImg.get_width(), cubeImg.get_height()))