Advertisement
Guest User

Untitled

a guest
Dec 12th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.22 KB | None | 0 0
  1.  
  2. class players():
  3.     def __init__(self, x, y, width, height):
  4.         self.x = x
  5.         self.y = y
  6.         self.width = width
  7.         self.height = height
  8.         self.speed = 5
  9.         self.playerJumps = False
  10.         self.jumpHeight = 10
  11.         self.left = False
  12.         self.right = False
  13.         self.walkCount = 10
  14.         self.standing = True
  15. class enemy():
  16.     def __init__(self, x, y, color, radius, end):
  17.         self.x = x
  18.         self.y = y
  19.         self.color = color
  20.         self.radius = radius
  21.         self.end = end
  22.         self.path = [self.x, self.end]
  23.         self.walkCount = 0
  24.         self.vel = 3
  25.  
  26. #Remember to change and fix the draw function once I've got the sprites
  27.     def draw(self, gameWindow):      
  28.         self.move()
  29.         if self.walkCount + 1 <= 33:
  30.             self.walkCount = 0
  31.         if self.vel > 0:
  32.             pygame.draw.circle(gameWindow, self.color, (self.x, self.y), self.radius, 0)
  33.             self.walkCount += 1
  34.         else:
  35.             pygame.draw.circle(gameWindow, self.color, (self.x, self.y), self.radius, 0)
  36.             self.walkCount += 1
  37.  
  38. #The function is supposed to move the enemy by comparing their coordinates with the limits passed to the variable "self.path"
  39.     def move(self):
  40.         if self.vel > 0:
  41.             if self.x + self.vel < self.path[1]:
  42.                 self.x += self.vel
  43.             else:
  44.                 self.vel = self.vel * -1
  45.                 self.walkCount = 0
  46.         else:
  47.             if self.x - self.vel > self.path[0]:
  48.                 self.x += self.vel
  49.             else:
  50.                 self.vel = self.vel * -1
  51.                 self.walkCount = 0
  52. def displayUpdate():
  53.     global colorDict
  54.     gameWindow.fill(colorDict["blue"])
  55.     pygame.draw.rect(gameWindow, colorDict["red"], (player.x, player.y, player.width, player.height))
  56.     monster.draw(gameWindow)
  57.     for bullet in bullets:
  58.         bullet.draw(gameWindow)
  59.     pygame.display.update()
  60.  
  61. player = players(50, displayHeight - 70, 40, 60)
  62. monster = enemy(200, 400, colorDict["green"], 25, displayWidth//2)
  63. bullets = []
  64. if (keys[pygame.K_a] or keys[pygame.K_LEFT]) and player.x > player.speed:
  65.             player.x -= player.speed
  66.             player.left = True
  67.             player.right = False
  68.             player.standing = False
  69.  
  70.         elif (keys[pygame.K_d] or keys[pygame.K_RIGHT]) and player.x < 600 - player.speed - player.width:
  71.             player.x += player.speed
  72.             player.left = False
  73.             player.right = True
  74.             player.standing = False
  75.         else:
  76.             player.frameCount = 0
  77.             player.standing = True
  78.  
  79.  
  80.         if not(player.playerJumps):
  81.             if keys[pygame.K_w] or keys[pygame.K_UP]:
  82.                 player.playerJumps = True
  83.                 player.left = False
  84.                 player.right = False
  85.  
  86.         else:
  87.             if player.jumpHeight >= -10:
  88.                 negNo = 1
  89.                 if player.jumpHeight < 0:
  90.                     negNo = -1
  91.                 player.y -= (player.jumpHeight ** 2) * 0.5 * negNo
  92.                 player.jumpHeight -= 1
  93.             else:
  94.                 player.playerJumps = False
  95.                 player.jumpHeight = 10
  96.         displayUpdate()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement