-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHero.py
195 lines (173 loc) · 5.79 KB
/
Hero.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
import pygame, sys
from Person import *
# Colors
BLUE = (0, 0, 255)
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
RED = (255, 0, 0)
class Weapon(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.pos = (0,0)
# Create an image of the block, and fill it with a color.
# This could also be an image loaded from the disk.
#self.image = pygame.Surface([8, 50])
self.image = pygame.image.load("sword.png")
#self.sideImage = pygame.Surface([50,8])
#self.topImage = pygame.Surface([8,50])
self.topImage = pygame.image.load("swordUp.png")
self.botImage = pygame.image.load("swordDown.png")
self.RsideImage = pygame.image.load("swordRight.png")
self.LsideImage = pygame.image.load("swordLeft.png")
#self.image.fill(RED)
self.health = 10
# Fetch the rectangle object that has the dimensions of the image
# Update the position of this object by setting the values of rect.x and rect.y
self.rect = self.image.get_rect()
self.rect.topleft = self.pos
def setPositionVertical(self, pos, direction):
if direction == 1:
self.image = self.topImage
self.rect = self.image.get_rect()
pos[1] -= 50
else:
self.image = self.botImage
self.rect = self.image.get_rect()
self.rect.topleft = tuple(pos)
def setPositionHorizontal(self, pos, direction):
if direction == 4:
self.image = self.LsideImage
self.rect = self.LsideImage.get_rect()
pos[0] -= 50
#pos[1] -= 8
else:
self.image = self.RsideImage
self.rect = self.RsideImage.get_rect()
self.rect.topleft = tuple(pos)
class Hero(Person):
def __init__(self,width,height,pos):
self.level = None
self.words = []
self.dialogueNumber = 0
self.combine = {}
# Call the parent class (Sprite) constructor
pygame.sprite.Sprite.__init__(self)
# Create an image of the block, and fill it with a color.
# This could also be an image loaded from the disk.
self.image = pygame.image.load('hero_front.png').convert_alpha()
self.imagesL = [pygame.image.load('hero_left.png'), pygame.image.load('hero_left_L.png'), pygame.image.load('hero_left_R.png')]
self.imagesR = [pygame.image.load('hero_right.png'), pygame.image.load('hero_right_L.png'), pygame.image.load('hero_right_R.png')]
self.imagesU = [pygame.image.load('hero_up.png'), pygame.image.load('hero_up_L.png'), pygame.image.load('hero_up_R.png')]
self.imagesD = [pygame.image.load('hero_down.png'), pygame.image.load('hero_down_L.png'), pygame.image.load('hero_down_R.png')]
self.imageLeft = 0
self.imageRight = 0
self.imageDown = 0
self.imageUp = 0
# Fetch the rectangle object that has the dimensions of the image
# Update the position of this object by setting the values of rect.x and rect.y
self.rect = self.image.get_rect()
self.rect.topleft = pos
self.athensPoints = 0
self.spartaPoints = 0
self.delphiPoints = 0
self.health = 3
direction = 1
weaponSide = pygame.Surface([50,8])
weaponSide.fill(RED)
weapon = Weapon()
seenScene = {}
def setLevel(self, level):
self.level = level
def resetImage(self, direction):
if direction == "left":
self.imageRight = 0
self.imageDown = 0
self.imageUp = 0
elif direction == "right":
self.imageLeft = 0
self.imageDown = 0
self.imageUp = 0
elif direction == "down":
self.imageRight = 0
self.imageLeft = 0
self.imageUp = 0
elif direction == "up":
self.imageRight = 0
self.imageDown = 0
self.imageLeft = 0
def moveImage(self, direction):
self.resetImage(direction)
if direction == "left":
self.imageLeft += 1
if self.imageLeft > 2:
self.imageLeft = 0
self.image = self.imagesL[self.imageLeft]
elif direction == "right":
self.imageRight += 1
if self.imageRight > 2:
self.imageRight = 0
self.image = self.imagesR[self.imageRight]
elif direction == "down":
self.imageDown += 1
if self.imageDown > 2:
self.imageDown = 0
self.image = self.imagesD[self.imageDown]
elif direction == "up":
self.imageUp += 1
if self.imageUp > 2:
self.imageUp = 0
self.image = self.imagesU[self.imageUp]
def checkScene(self, scene):
seenScene[scene] = True
def setSurface(self, surface):
self.surface = surface
def askDecision(self, surface, textSurface, choices, current):
pass
def getTextBox(self, surface):
pass
def checkHero(self):
if self.spartaPoints >= 3 and self.athensPoints >=3 and self.delphiPoints >= 3:
self.level.reaction("Hydra")
def increasePoints(self, city, number):
if self.spartaPoints >= 3 and self.athensPoints >=3 and self.delphiPoints >= 3:
self.level.reaction("Hydra")
if city == "sparta":
self.spartaPoints += number
if self.spartaPoints <= -5:
return "Spartan-5"
elif self.spartaPoints >= 5:
return "Spartan5"
else:
return "Normal"
elif city == "athens":
self.athensPoints += number
if self.athensPoints <= -5:
return "Athen-5"
elif self.athensPoints >= 5:
return "Athen5"
else:
return "Normal"
elif city == "delphi":
self.delphiPoints += number
if self.delphiPoints <= -5:
return "Delphi-5"
elif self.delphiPoints >= 5:
return "Delphi5"
else:
return "Normal"
def getAction(self):
if(self.direction == 1):
self.weapon.setPositionVertical([self.rect.x, self.rect.y + 8], self.direction)
self.surface.blit(self.weapon.image, self.weapon.rect)
elif(self.direction == 2):
self.weapon.setPositionHorizontal([self.rect.x + 20, self.rect.y + 8], self.direction)
self.surface.blit(self.weapon.image, self.weapon.rect)
elif(self.direction == 3):
self.weapon.setPositionVertical([self.rect.x, self.rect.y + 20], self.direction)
self.surface.blit(self.weapon.image, self.weapon.rect)
elif(self.direction == 4):
self.weapon.setPositionHorizontal([self.rect.x + 8, self.rect.y + 8], self.direction)
self.surface.blit(self.weapon.image, self.weapon.rect)
else:
return None
return self.weapon