-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcharacter.py
37 lines (26 loc) · 1.03 KB
/
character.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import pygame
class Character:
"""A class that creates a character"""
def __init__(self, game):
self.settings = game.settings
self.screen = game.screen
self.screen_rect = self.screen.get_rect()
self.image = pygame.image.load('img/fanteria.gif').convert()
self.rect = self.image.get_rect()
self.rect.midleft = self.screen_rect.midleft
self.x = float(self.rect.x)
self.y = float(self.rect.y)
self.moving_up = False
self.moving_down = False
def blitme(self):
"""Method for bliting"""
self.update()
self.screen.blit(self.image, self.rect)
def update(self):
"""Method to update the character's location based on keys pressed"""
if self.moving_up == True and self.rect.top > 0:
self.y -= self.settings.CHAR_SPEED
if self.moving_down == True and self.rect.bottom < self.screen_rect.bottom:
self.y += self.settings.CHAR_SPEED
self.rect.x = self.x
self.rect.y = self.y