Add fancy losing screen and keybinding for new game
This commit is contained in:
parent
aafa943a53
commit
3e25eb424c
|
@ -1 +1 @@
|
||||||
include README.rst LICENSE
|
include README.rst LICENSE screenshot.png
|
||||||
|
|
|
@ -35,6 +35,12 @@ The installation procedure should be as simply as follow:
|
||||||
Control
|
Control
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
F2
|
||||||
|
New game.
|
||||||
|
|
||||||
|
Escape, ``p``
|
||||||
|
Pause.
|
||||||
|
|
||||||
Up, ``w``
|
Up, ``w``
|
||||||
Move up.
|
Move up.
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ class Hero:
|
||||||
self.R = int((w * h / sin(pi*2/3) / 624) ** 0.5)
|
self.R = int((w * h / sin(pi*2/3) / 624) ** 0.5)
|
||||||
|
|
||||||
self.next_strike = 0
|
self.next_strike = 0
|
||||||
self.slashing = self.firing = False
|
self.slashing = self.firing = self.dead = False
|
||||||
self.spin_speed = fps / HERO_HP
|
self.spin_speed = fps / HERO_HP
|
||||||
self.spin_queue = self.wound = 0.0
|
self.spin_queue = self.wound = 0.0
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ class Hero:
|
||||||
old_speed, time = self.spin_speed, pygame.time.get_ticks()
|
old_speed, time = self.spin_speed, pygame.time.get_ticks()
|
||||||
self.spin_speed = fps / (HERO_HP-self.wound**0.5)
|
self.spin_speed = fps / (HERO_HP-self.wound**0.5)
|
||||||
self.spin_queue *= self.spin_speed / old_speed
|
self.spin_queue *= self.spin_speed / old_speed
|
||||||
self.wound -= HEAL_SPEED / self.spin_speed / HERO_HP
|
if not self.dead: self.wound -= HEAL_SPEED / self.spin_speed / HERO_HP
|
||||||
if self.wound < 0: self.wound = 0.0
|
if self.wound < 0: self.wound = 0.0
|
||||||
|
|
||||||
if self.slashing and time >= self.next_strike:
|
if self.slashing and time >= self.next_strike:
|
||||||
|
@ -63,7 +63,15 @@ class Hero:
|
||||||
self.angle = atan2(y - self.y, x - self.x)
|
self.angle = atan2(y - self.y, x - self.x)
|
||||||
self.spin_queue = 0.0
|
self.spin_queue = 0.0
|
||||||
trigon = regpoly(3, self.R, self.angle, self.x, self.y)
|
trigon = regpoly(3, self.R, self.angle, self.x, self.y)
|
||||||
|
try:
|
||||||
fill_aapolygon(self.surface, trigon, self.color[int(self.wound)])
|
fill_aapolygon(self.surface, trigon, self.color[int(self.wound)])
|
||||||
|
except IndexError: # When the hero is wounded over his HP
|
||||||
|
self.wound = HERO_HP
|
||||||
|
|
||||||
|
def die(self):
|
||||||
|
"""Handle the hero's death."""
|
||||||
|
self.dead = True
|
||||||
|
self.slashing = self.firing = False
|
||||||
|
|
||||||
def resize(self):
|
def resize(self):
|
||||||
"""Resize the hero."""
|
"""Resize the hero."""
|
||||||
|
@ -87,16 +95,6 @@ class Enemy:
|
||||||
self.spin_speed = fps / ENEMY_HP
|
self.spin_speed = fps / ENEMY_HP
|
||||||
self.spin_queue = self.wound = 0.0
|
self.spin_queue = self.wound = 0.0
|
||||||
|
|
||||||
def firable(self):
|
|
||||||
"""Return True if the enemies should shoot the hero,
|
|
||||||
False otherwise.
|
|
||||||
"""
|
|
||||||
if not self.awake or self.spin_queue or self.offsetx or self.offsety:
|
|
||||||
return False
|
|
||||||
else:
|
|
||||||
self.next_move = pygame.time.get_ticks() + ATTACK_SPEED
|
|
||||||
return True
|
|
||||||
|
|
||||||
def pos(self, distance, middlex, middley):
|
def pos(self, distance, middlex, middley):
|
||||||
"""Return coordinate of the center of the enemy."""
|
"""Return coordinate of the center of the enemy."""
|
||||||
x, y = pos(self.x, self.y, distance, middlex, middley)
|
x, y = pos(self.x, self.y, distance, middlex, middley)
|
||||||
|
@ -152,6 +150,16 @@ class Enemy:
|
||||||
color = self.color[int(self.wound)] if self.awake else FG_COLOR
|
color = self.color[int(self.wound)] if self.awake else FG_COLOR
|
||||||
fill_aapolygon(self.surface, square, color)
|
fill_aapolygon(self.surface, square, color)
|
||||||
|
|
||||||
|
def firable(self):
|
||||||
|
"""Return True if the enemies should shoot the hero,
|
||||||
|
False otherwise.
|
||||||
|
"""
|
||||||
|
if (not self.awake or self.spin_queue or self.offsetx or self.offsety
|
||||||
|
or (self.x, self.y) in SURROUND_HERO):
|
||||||
|
return False
|
||||||
|
self.next_move = pygame.time.get_ticks() + ATTACK_SPEED
|
||||||
|
return True
|
||||||
|
|
||||||
def die(self):
|
def die(self):
|
||||||
"""Kill the enemy."""
|
"""Handle the enemy's death."""
|
||||||
self.maze[self.x][self.y] = EMPTY if self.awake else WALL
|
self.maze[self.x][self.y] = EMPTY if self.awake else WALL
|
||||||
|
|
|
@ -44,6 +44,8 @@ BULLET_LIFETIME = 1000 # ms
|
||||||
|
|
||||||
EMPTY, WALL, HERO, ENEMY = range(4)
|
EMPTY, WALL, HERO, ENEMY = range(4)
|
||||||
ADJACENT_GRIDS = (1, 0), (0, 1), (-1, 0), (0, -1)
|
ADJACENT_GRIDS = (1, 0), (0, 1), (-1, 0), (0, -1)
|
||||||
|
SURROUND_HERO = set((MIDDLE + x, MIDDLE + y) for x, y in
|
||||||
|
ADJACENT_GRIDS + ((1, 1), (-1, 1), (-1, -1), (1, -1)))
|
||||||
|
|
||||||
TANGO = {'Butter': ((252, 233, 79), (237, 212, 0), (196, 160, 0)),
|
TANGO = {'Butter': ((252, 233, 79), (237, 212, 0), (196, 160, 0)),
|
||||||
'Orange': ((252, 175, 62), (245, 121, 0), (206, 92, 0)),
|
'Orange': ((252, 175, 62), (245, 121, 0), (206, 92, 0)),
|
||||||
|
|
|
@ -38,8 +38,14 @@ def main():
|
||||||
for event in events:
|
for event in events:
|
||||||
if event.type == QUIT:
|
if event.type == QUIT:
|
||||||
going = False
|
going = False
|
||||||
|
elif event.type == VIDEORESIZE:
|
||||||
|
maze.resize(event.w, event.h)
|
||||||
elif event.type == KEYDOWN:
|
elif event.type == KEYDOWN:
|
||||||
if event.key in (K_ESCAPE, K_p):
|
if event.key == K_F2: # new game
|
||||||
|
maze.__init__((maze.w, maze.h), fps)
|
||||||
|
elif maze.hero.dead:
|
||||||
|
continue
|
||||||
|
elif event.key in (K_ESCAPE, K_p):
|
||||||
maze.paused ^= True
|
maze.paused ^= True
|
||||||
elif event.key in (K_UP, K_w):
|
elif event.key in (K_UP, K_w):
|
||||||
maze.move(up=-1)
|
maze.move(up=-1)
|
||||||
|
@ -51,6 +57,8 @@ def main():
|
||||||
maze.move(right=-1)
|
maze.move(right=-1)
|
||||||
elif event.key == K_RETURN:
|
elif event.key == K_RETURN:
|
||||||
maze.hero.slashing = True
|
maze.hero.slashing = True
|
||||||
|
elif maze.hero.dead:
|
||||||
|
continue
|
||||||
elif event.type == KEYUP:
|
elif event.type == KEYUP:
|
||||||
if event.key in (K_UP, K_w):
|
if event.key in (K_UP, K_w):
|
||||||
maze.move(up=1)
|
maze.move(up=1)
|
||||||
|
@ -72,8 +80,6 @@ def main():
|
||||||
maze.hero.firing = False
|
maze.hero.firing = False
|
||||||
elif event.button == 3:
|
elif event.button == 3:
|
||||||
maze.hero.slashing = False
|
maze.hero.slashing = False
|
||||||
elif event.type == VIDEORESIZE:
|
|
||||||
maze.resize(event.w, event.h)
|
|
||||||
if len(flash_time) > 5:
|
if len(flash_time) > 5:
|
||||||
new_fps = 5000.0 / (flash_time[-1] - flash_time[0])
|
new_fps = 5000.0 / (flash_time[-1] - flash_time[0])
|
||||||
flash_time.popleft()
|
flash_time.popleft()
|
||||||
|
|
|
@ -262,11 +262,11 @@ class Maze:
|
||||||
for bullet in self.bullets: bullet.place(dx, dy, self.step)
|
for bullet in self.bullets: bullet.place(dx, dy, self.step)
|
||||||
|
|
||||||
self.draw()
|
self.draw()
|
||||||
self.slash()
|
|
||||||
self.track_bullets()
|
|
||||||
for enemy in self.enemies:
|
for enemy in self.enemies:
|
||||||
enemy.update(fps, self.distance, self.middlex, self.middley)
|
enemy.update(fps, self.distance, self.middlex, self.middley)
|
||||||
self.hero.update(fps)
|
self.hero.update(fps)
|
||||||
|
self.slash()
|
||||||
|
self.track_bullets()
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
pygame.display.set_caption('Brutal Maze - Score: {}'.format(
|
pygame.display.set_caption('Brutal Maze - Score: {}'.format(
|
||||||
int(self.score - INIT_SCORE)))
|
int(self.score - INIT_SCORE)))
|
||||||
|
@ -299,5 +299,5 @@ class Maze:
|
||||||
|
|
||||||
def lose(self):
|
def lose(self):
|
||||||
"""Handle loses."""
|
"""Handle loses."""
|
||||||
print('Your score is: {}'.format(int(self.score - INIT_SCORE)))
|
self.hero.die()
|
||||||
quit()
|
self.up = self.left = self.down = self.right = 0
|
||||||
|
|
Loading…
Reference in New Issue