Skip to content
This repository has been archived by the owner on Nov 30, 2020. It is now read-only.

Commit

Permalink
Enable manual slashing by moving mouse
Browse files Browse the repository at this point in the history
  • Loading branch information
McSinyx committed Mar 1, 2018
1 parent 79ae3ed commit 6f9eb44
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
27 changes: 20 additions & 7 deletions brutalmaze/characters.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __init__(self, surface, fps, maze_size):
self.surface = surface
w, h = maze_size
self.x, self.y = w >> 1, h >> 1
self.angle, self.color = pi / 4, TANGO['Aluminium']
self.angle, self.color = -pi * 3 / 4, TANGO['Aluminium']
self.R = (w * h / sin(pi*2/3) / 624) ** 0.5

self.next_heal = self.next_beat = self.next_strike = 0
Expand All @@ -82,27 +82,40 @@ def update(self, fps):
play(self.sfx_heart)
self.next_beat = time + MIN_BEAT*(2 - self.wound/HERO_HP)

full_spin = pi * 2 / self.get_sides()
if self.slashing and time >= self.next_strike:
self.next_strike = time + ATTACK_SPEED
self.spin_queue = randsign() * self.spin_speed
self.angle -= sign(self.spin_queue) * full_spin
if abs(self.spin_queue) > 0.5:
self.angle += sign(self.spin_queue) * pi / 2 / self.spin_speed
self.angle += sign(self.spin_queue) * full_spin / self.spin_speed
self.spin_queue -= sign(self.spin_queue)
else:
self.spin_queue = 0.0

def get_sides(self):
"""Return the number of sides the hero has. While the hero is
generally a trigon, Agent Orange may turn him into a square.
"""
return 3 if get_ticks() >= self.next_heal else 4

def update_angle(self, angle):
"""Turn to the given angle if the hero is not busy slashing."""
if abs(self.spin_queue) <= 0.5:
self.spin_queue = 0.0
self.angle = angle
if abs(self.spin_queue) > 0.5: return
delta = (angle - self.angle + pi) % (pi * 2) - pi
unit = pi * 2 / self.get_sides() / self.spin_speed
if abs(delta) < unit:
self.angle, self.spin_queue = angle, 0.0
else:
self.spin_queue = delta / unit

def get_color(self):
"""Return current color of the hero."""
return self.color[int(self.wound)]

def draw(self):
"""Draw the hero."""
sides = 3 if get_ticks() >= self.next_heal else 4
trigon = regpoly(sides, self.R, self.angle, self.x, self.y)
trigon = regpoly(self.get_sides(), self.R, self.angle, self.x, self.y)
fill_aapolygon(self.surface, trigon, self.get_color())

def resize(self, maze_size):
Expand Down
2 changes: 1 addition & 1 deletion brutalmaze/maze.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,6 @@ def reinit(self):
self.add_enemy()

self.next_move = self.next_slashfx = 0
self.hero.next_heal = self.hero.next_beat = self.hero.next_strike = 0
self.hero.next_heal = self.hero.next_strike = 0
self.hero.slashing = self.hero.firing = self.hero.dead = False
self.hero.spin_queue = self.hero.wound = 0.0

0 comments on commit 6f9eb44

Please sign in to comment.