MCPcopy Index your code
hub / github.com/geekcomputers/Python / update

Method update

Street_Fighter/src/fighter.py:132–175  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

130
131 # handle animation updates
132 def update(self):
133 # check what action the player is performing
134 if self.health <= 0:
135 self.health = 0
136 self.alive = False
137 self.update_action(6) # 6:death
138 elif self.hit:
139 self.update_action(5) # 5:hit
140 elif self.attacking:
141 if self.attack_type == 1:
142 self.update_action(3) # 3:attack1
143 elif self.attack_type == 2:
144 self.update_action(4) # 4:attack2
145 elif self.jump:
146 self.update_action(2) # 2:jump
147 elif self.running:
148 self.update_action(1) # 1:run
149 else:
150 self.update_action(0) # 0:idle
151
152 animation_cooldown = 50
153 # update image
154 self.image = self.animation_list[self.action][self.frame_index]
155 # check if enough time has passed since the last update
156 if pygame.time.get_ticks() - self.update_time > animation_cooldown:
157 self.frame_index += 1
158 self.update_time = pygame.time.get_ticks()
159 # check if the animation has finished
160 if self.frame_index >= len(self.animation_list[self.action]):
161 # if the player is dead then end the animation
162 if not self.alive:
163 self.frame_index = len(self.animation_list[self.action]) - 1
164 else:
165 self.frame_index = 0
166 # check if an attack was executed
167 if self.action == 3 or self.action == 4:
168 self.attacking = False
169 self.attack_cooldown = 20
170 # check if damage was taken
171 if self.action == 5:
172 self.hit = False
173 # if the player was in the middle of an attack, then the attack is stopped
174 self.attacking = False
175 self.attack_cooldown = 20
176
177 def attack(self, target):
178 if self.attack_cooldown == 0:

Callers 7

victory_screenFunction · 0.45
main_menuFunction · 0.45
scores_screenFunction · 0.45
countdownFunction · 0.45
game_loopFunction · 0.45
create_wallMethod · 0.45
game_loopFunction · 0.45

Calls 1

update_actionMethod · 0.95

Tested by

no test coverage detected