Skip to content

Instantly share code, notes, and snippets.

@qoh
Created April 19, 2013 19:56
Show Gist options
  • Save qoh/5422803 to your computer and use it in GitHub Desktop.
Save qoh/5422803 to your computer and use it in GitHub Desktop.
class Game(object):
def __init__(self):
self.time = 0.0
self.director = Director(self)
self.players = []
for i in range(4):
self.players.append(Player(self))
def on_damaged(self, x, y):
if not (x.friendly and y.friendly):
if x.friendly:
x.increase_intensity(0.025)
if y.friendly:
y.increase_intensity(0.025)
self.director.last_combat_time = self.time
class Player(object):
friendly = True
def __init__(self, game):
self.game = game
self.intensity = 0
def increase_intesity(self, amount):
self.intensity = max(0, min(1, self.intensity + amount))
BUILD_UP = 0
SUSTAIN_PEAK = 1
PEAK_FADE = 2
RELAX = 3
STATE_MODULO = 4
class Director(object):
intensity_peak = 0.75
combat_duration = 3
def __init__(self, game):
self.game = game
self.state = BUILD_UP
self.last_combat_time = -self.combat_duration
def next_state(self):
self.state += 1
self.state %= STATE_MODULO
@property
def in_combat(self):
delay = self.game.time - self.last_combat_time
return delay < self.combat_duration
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment