This commit is contained in:
Frank DeMarco 2017-12-20 18:56:58 -05:00
parent 59ebe2745d
commit cb3d4ffc6a
1 changed files with 114 additions and 41 deletions

155
NS.py
View File

@ -43,6 +43,7 @@ class SoundEffect(GameChild, Sound):
class NS(Game, Animation):
NW, NE, SE, SW = range(4)
N, E, S, W, NE, NW = range(6)
FRONT_WIDTH = 230
BACK_WIDTH = 500
LENGTH = 150
@ -58,12 +59,7 @@ class NS(Game, Animation):
ds = self.get_display_surface()
self.background = Surface(ds.get_size())
self.background.fill((0, 0, 0))
self.lights = [
Light(self, "cyan", self.NW),
Light(self, "magenta", self.NE),
Light(self, "yellow", self.SE),
Light(self, "white", self.SW)
]
self.platform = Platform(self)
self.chemtrails = Chemtrails(self)
self.boss = Boss(self)
self.last_press = get_ticks()
@ -71,27 +67,28 @@ class NS(Game, Animation):
self.reset()
def reset(self):
self.suppressing_input = False
self.suppress_restart = False
self.game_over = False
self.boss.reset()
self.chemtrails.reset()
for light in self.lights:
light.reset()
self.platform.reset()
def respond(self, event):
if event.type in (KEYDOWN, KEYUP):
if not self.suppressing_input and event.type in (KEYDOWN, KEYUP):
# if self.last_press <= get_ticks() - int(self.get_configuration("input", "buffer")):
pressed = True if event.type == KEYDOWN else False
if (event.key in (K_UP, K_o)):
self.lights[0].pressed = pressed
lights = self.platform.lights
if event.key in (K_UP, K_o):
lights[0].pressed = pressed
if self.game_over and not self.suppress_restart:
self.reset()
elif (event.key in (K_RIGHT, K_p)):
self.lights[1].pressed = pressed
elif (event.key in (K_DOWN, K_SEMICOLON)):
self.lights[2].pressed = pressed
elif (event.key in (K_LEFT, K_l)):
self.lights[3].pressed = pressed
elif event.key in (K_RIGHT, K_p):
lights[1].pressed = pressed
elif event.key in (K_DOWN, K_SEMICOLON):
lights[2].pressed = pressed
elif event.key in (K_LEFT, K_l):
lights[3].pressed = pressed
self.last_press = get_ticks()
else:
if self.get_delegate().compare(event, "reset-game"):
@ -126,8 +123,7 @@ class NS(Game, Animation):
Animation.update(self)
self.get_display_surface().blit(self.background, (0, 0))
self.boss.update()
for light in self.lights:
light.update()
self.platform.update()
self.chemtrails.update()
if self.game_over:
self.message.update()
@ -135,6 +131,87 @@ class NS(Game, Animation):
self.restart_message.update()
class Title(GameChild):
def __init__(self, parent):
GameChild.__init__(self, parent)
def reset(self):
self.activate()
def activate(self):
self.active = True
def deactivate(self):
self.active = False
def update(self):
if self.active:
pass
class Introduction(Animation):
def __init__(self, parent):
Animation.__init__(self, parent)
def reset(self):
self.deactivate()
def deactivate(self):
self.active = False
def activate(self):
self.active = True
def update(self):
if self.active:
Animation.update(self)
class Wipe(Animation):
def __init__(self, parent):
Animation.__init__(self, parent)
def reset(self):
self.deactivate()
def deactivate(self):
self.active = False
def activate(self):
self.active = True
def update(self):
if self.active:
Animation.update(self)
class Platform(GameChild):
def __init__(self, parent):
GameChild.__init__(self, parent)
self.lights = [
Light(self, "cyan", NS.NW),
Light(self, "magenta", NS.NE),
Light(self, "yellow", NS.SE),
Light(self, "white", NS.SW)
]
def reset(self):
for light in self.lights:
light.reset()
def get_pressed(self):
return [light.position for light in self.lights if light.pressed]
def update(self):
for light in self.lights:
light.update()
class Light(Animation):
def __init__(self, parent, color, position):
@ -167,6 +244,7 @@ class Light(Animation):
def reset(self):
self.hidden = False
self.halt(self.blink)
self.reset_timer()
def blink(self):
self.hidden = not self.hidden
@ -186,13 +264,13 @@ class Light(Animation):
def in_orientation(self, orientation):
if self.position == NS.NW:
return orientation in (Sword.N, Sword.NW, Sword.W)
return orientation in (NS.N, NS.NW, NS.W)
elif self.position == NS.NE:
return orientation in (Sword.N, Sword.NE, Sword.E)
return orientation in (NS.N, NS.NE, NS.E)
elif self.position == NS.SE:
return orientation in (Sword.NW, Sword.E, Sword.S)
return orientation in (NS.NW, NS.E, NS.S)
elif self.position == NS.SW:
return orientation in (Sword.S, Sword.NE, Sword.W)
return orientation in (NS.S, NS.NE, NS.W)
class Chemtrails(GameChild):
@ -241,48 +319,45 @@ class Chemtrails(GameChild):
if self.queue_index == len(queue):
self.timer_remaining = self.TIME_LIMIT
self.get_game().boss.combo()
for light in self.get_game().lights:
light.reset()
light.reset_timer()
self.get_game().platform.reset()
def orient(self):
ds = self.get_display_surface()
lights = self.parent.lights
pressed = [light.position for light in self.parent.lights if light.pressed]
pressed = self.get_game().platform.get_pressed()
if NS.NW in pressed and NS.NE in pressed:
rect = self.image.get_rect()
rect.center = ds.get_width() / 2, NS.FRONT - 30
ds.blit(self.image, rect.topleft)
self.orientation = Sword.N
self.orientation = NS.N
elif NS.NE in pressed and NS.SE in pressed:
image = rotate(self.image, 270)
rect = image.get_rect()
rect.center = ds.get_width() / 2 + NS.FRONT_WIDTH / 2, NS.FRONT + NS.LENGTH * NS.STEP + 10
ds.blit(image, rect.topleft)
self.orientation = Sword.E
self.orientation = NS.E
elif NS.SE in pressed and NS.SW in pressed:
rect = self.image.get_rect()
rect.center = ds.get_width() / 2, NS.FRONT + NS.LENGTH - NS.LENGTH * NS.STEP - 20
ds.blit(self.image, rect.topleft)
self.orientation = Sword.S
self.orientation = NS.S
elif NS.SW in pressed and NS.NW in pressed:
image = rotate(self.image, 270)
rect = image.get_rect()
rect.center = ds.get_width() / 2 - NS.FRONT_WIDTH / 2 + 70, NS.FRONT + NS.LENGTH * NS.STEP + 10
ds.blit(image, rect.topleft)
self.orientation = Sword.W
self.orientation = NS.W
elif NS.NW in pressed and NS.SE in pressed:
image = rotate(self.image, 315)
rect = image.get_rect()
rect.center = ds.get_width() / 2 + 45, NS.FRONT + NS.LENGTH * NS.STEP - 40
ds.blit(image, rect.topleft)
self.orientation = Sword.NW
self.orientation = NS.NW
elif NS.NE in pressed and NS.SW in pressed:
image = rotate(self.image, 45)
rect = image.get_rect()
rect.center = ds.get_width() / 2 - 30, NS.FRONT + NS.LENGTH * NS.STEP - 50
ds.blit(image, rect.topleft)
self.orientation = Sword.NE
self.orientation = NS.NE
else:
self.orientation = None
@ -374,8 +449,6 @@ class Boss(RainbowSprite):
class Sword(Sprite):
N, E, S, W, NE, NW = range(6)
def __init__(self, parent):
Sprite.__init__(self, parent)
image = load(self.get_resource("Sword.png")).convert_alpha()
@ -399,22 +472,22 @@ class Sword(Sprite):
self.unhide()
position = self.parent.unbrandished.pop(0)
dsr = self.get_display_surface().get_rect()
if position in (self.W, self.E):
if position in (NS.W, NS.E):
self.set_frameset("vertical")
self.location.centery = dsr.centery - 100
if position == self.W:
if position == NS.W:
self.location.centerx = dsr.centerx - 100
else:
self.location.centerx = dsr.centerx + 100
elif position in (self.N, self.S):
elif position in (NS.N, NS.S):
self.set_frameset("horizontal")
self.location.centerx = dsr.centerx
if position == self.N:
if position == NS.N:
self.location.centery = dsr.centery - 200
else:
self.location.centery = dsr.centery
else:
if position == self.NW:
if position == NS.NW:
self.set_frameset("ldiagonal")
else:
self.set_frameset("rdiagonal")