Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 19th, 2012  |  syntax: Python  |  size: 1.20 KB  |  hits: 20  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.         isOnTop = False
  2.         isOnBottom = False
  3.         isOnLeft = False
  4.         isOnRight = False
  5.         moving = False
  6.         global playerX, playerY, playerRect, gravity, xVel, yVel, movDir, friction, jumped, platforms
  7.        
  8.         for x in platforms:
  9.                 if playerRect.colliderect(x):
  10.                
  11.                         if playerRect.top < x.top:
  12.                                 playerY = x.top - 19
  13.                                 isOnTop = True
  14.                                
  15.                         elif playerRect.top > x.top:
  16.                                 playerY = x.bottom
  17.                                 isOnBottom = True
  18.                                
  19.                         if playerRect.right > x.right:
  20.                                 playerX = x.left - 19
  21.                                 isOnLeft = True
  22.                                
  23.                         elif playerRect.left < x.right:
  24.                                 playerX = x.right + 1
  25.                                 isOnRight = True
  26.                                
  27.                                
  28.         if isOnTop == True:
  29.                 yVel = 0
  30.         if isOnTop == False:
  31.                 if yVel < 17:
  32.                         yVel += gravity        
  33.         if movDir == 1:
  34.                 if isOnLeft == False:
  35.                         if xVel < 10:
  36.                                 xVel += 0.5
  37.                                 moving = True
  38.         elif movDir == -1:
  39.                         if isOnRight == False:
  40.                                 if xVel > -10:
  41.                                         xVel -= 0.5
  42.                                         moving = True
  43.                
  44.         elif moving == False:
  45.                 if       xVel == 0:
  46.                         pass
  47.                 elif xVel > -0.1 and xVel < 0.1:
  48.                         xVel = 0
  49.                 elif xVel > 0:
  50.                         xVel -= friction
  51.                 elif xVel < 0:
  52.                         xVel += friction
  53.                        
  54.        
  55.         playerX += xVel
  56.         playerY += yVel
  57.         playerRect = pygame.Rect((playerX, playerY), (cubeImg.get_width(), cubeImg.get_height()))