Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class players():
- def __init__(self, x, y, width, height):
- self.x = x
- self.y = y
- self.width = width
- self.height = height
- self.speed = 5
- self.playerJumps = False
- self.jumpHeight = 10
- self.left = False
- self.right = False
- self.walkCount = 10
- self.standing = True
- class enemy():
- def __init__(self, x, y, color, radius, end):
- self.x = x
- self.y = y
- self.color = color
- self.radius = radius
- self.end = end
- self.path = [self.x, self.end]
- self.walkCount = 0
- self.vel = 3
- #Remember to change and fix the draw function once I've got the sprites
- def draw(self, gameWindow):
- self.move()
- if self.walkCount + 1 <= 33:
- self.walkCount = 0
- if self.vel > 0:
- pygame.draw.circle(gameWindow, self.color, (self.x, self.y), self.radius, 0)
- self.walkCount += 1
- else:
- pygame.draw.circle(gameWindow, self.color, (self.x, self.y), self.radius, 0)
- self.walkCount += 1
- #The function is supposed to move the enemy by comparing their coordinates with the limits passed to the variable "self.path"
- def move(self):
- if self.vel > 0:
- if self.x + self.vel < self.path[1]:
- self.x += self.vel
- else:
- self.vel = self.vel * -1
- self.walkCount = 0
- else:
- if self.x - self.vel > self.path[0]:
- self.x += self.vel
- else:
- self.vel = self.vel * -1
- self.walkCount = 0
- def displayUpdate():
- global colorDict
- gameWindow.fill(colorDict["blue"])
- pygame.draw.rect(gameWindow, colorDict["red"], (player.x, player.y, player.width, player.height))
- monster.draw(gameWindow)
- for bullet in bullets:
- bullet.draw(gameWindow)
- pygame.display.update()
- player = players(50, displayHeight - 70, 40, 60)
- monster = enemy(200, 400, colorDict["green"], 25, displayWidth//2)
- bullets = []
- if (keys[pygame.K_a] or keys[pygame.K_LEFT]) and player.x > player.speed:
- player.x -= player.speed
- player.left = True
- player.right = False
- player.standing = False
- elif (keys[pygame.K_d] or keys[pygame.K_RIGHT]) and player.x < 600 - player.speed - player.width:
- player.x += player.speed
- player.left = False
- player.right = True
- player.standing = False
- else:
- player.frameCount = 0
- player.standing = True
- if not(player.playerJumps):
- if keys[pygame.K_w] or keys[pygame.K_UP]:
- player.playerJumps = True
- player.left = False
- player.right = False
- else:
- if player.jumpHeight >= -10:
- negNo = 1
- if player.jumpHeight < 0:
- negNo = -1
- player.y -= (player.jumpHeight ** 2) * 0.5 * negNo
- player.jumpHeight -= 1
- else:
- player.playerJumps = False
- player.jumpHeight = 10
- displayUpdate()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement