forked from williamfiset/Survival
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Survivor.py
123 lines (79 loc) · 2.9 KB
/
Survivor.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
"""
The Survivor file contorls the survivor and his or her movement and actions.
"""
import pygame
from tile import Tile
from character import Character, Direction
__author__ = 'William Fiset'
class Survivor(Character):
_velocity = 8
GUN_IMAGES = [pygame.image.load('images/weapon/pistol.png'),
pygame.image.load('images/weapon/shotgun.png'),
pygame.image.load('images/weapon/automatic.png')]
START_HEALTH = 1000
def __init__(self, x, y):
self.health = Survivor.START_HEALTH
self.current = 0 # 0 -> pistol, 1 -> shotgun, 2 -> automatic
self.direction = Direction.WEST
self.img = pygame.image.load('images/survivor/survivor_w.png')
Character.__init__(self, x, y)
def get_bullet_type(self):
if self.current == 0:
return 'pistol'
elif self.current == 1:
return 'shotgun'
elif self.current == 2:
return 'automatic'
# movement determines if the player should move, and what direction to move in
def movement(self):
if self.isMoving(): # Target is set
x_destination = self.x - self.dx
y_destination = self.y - self.dy
if x_destination < 0: # --->
self.x += Survivor._velocity
elif x_destination > 0: # <----
self.x -= Survivor._velocity
if y_destination > 0: # up
self.y -= Survivor._velocity
elif y_destination < 0: # dopwn
self.y += Survivor._velocity
if x_destination == 0 and y_destination == 0:
self.dx, self.dy = 0, 0
def draw(self, screen):
screen.blit(self.img, (self.x, self.y))
h = self.width / 2
img = Survivor.GUN_IMAGES[self.current]
if self.direction == Direction.WEST:
screen.blit(img, (self.x, self.y + h))
elif self.direction == Direction.EAST:
img = pygame.transform.flip(img, True, False)
screen.blit(img, (self.x + h, self.y + h))
elif self.direction == Direction.SOUTH:
img = pygame.transform.rotate(img, 90) # CCW
screen.blit(img, (self.x + h, self.y + h))
elif self.direction == Direction.NORTH:
south = pygame.transform.rotate(img, 90)
img = pygame.transform.flip(south, False, True)
screen.blit(img, (self.x + h, self.y - h))
"""
changes player direction
"""
def rotate(self, direction):
path = 'images/survivor/survivor_'
png = '.png'
if direction == Direction.NORTH:
if self.direction != Direction.NORTH:
self.direction = Direction.NORTH
self.img = pygame.image.load(path + self.direction + png)
if direction == Direction.SOUTH:
if self.direction != Direction.SOUTH:
self.direction = Direction.SOUTH
self.img = pygame.image.load(path + self.direction + png)
if direction == Direction.EAST:
if self.direction != Direction.EAST:
self.direction = Direction.EAST
self.img = pygame.image.load(path + self.direction + png)
if direction == Direction.WEST:
if self.direction != Direction.WEST:
self.direction = Direction.WEST
self.img = pygame.image.load(path + self.direction + png)