def __init__(self): State.__init__(self, "Game") self.characterPosition = Vector(5, 7) self.character_colors = [RED, BLUE, WHITE, ORANGE, PURPLE] self.background_color = BLACK self.wall_color = Color.multiply(GREEN, 0.5) self.map = [] self.offset = 0.0 self.initial_scroll_speed = self.scroll_speed = 0.5 self.scroll_speed_increment = 0.1 self.sharpness = 1.1 self.ship_steer_speed = 0.1 self.ship = Ship(Vector(6, 1), self.character_colors[0], Color.multiply(self.character_colors[0], 0.8)) self.simulationPause = False self.sprites = [] for y in range(PIXEL_DIM_Y * 2 + 1): self.map.append(self.generate_map_slice())
def update(self, dt): State.update(self, dt) if time.time() > self.started + 3000: self.ended = True else: self.sprite.update(dt)
def __init__(self): State.__init__(self, "Game") self.characterPosition = Vector(5, 7) self.character_colors = [RED, BLUE, WHITE, ORANGE, PURPLE] self.background_color = BLACK self.wall_color = Color.multiply(GREEN, 0.5) self.map = [] self.offset = 0.0 self.initial_scroll_speed = self.scroll_speed = 0.5 self.scroll_speed_increment = 0.1 self.sharpness = 1.1 self.ship_steer_speed = 0.1 self.ship = Ship(Vector(6, 1), self.character_colors[0], Color.multiply(self.character_colors[0], 0.8)) self.simulationPause = False self.sprites = [] for y in range(PIXEL_DIM_Y*2 + 1): self.map.append(self.generate_map_slice())
def update(self, dt): State.update(self, dt) self.lastJump += dt if self.lastJump > 2: self.point = Vector.random([PIXEL_DIM_X-1, PIXEL_DIM_Y-1]) self.lastJump = 0 if self.explosion: self.explosion.update(dt) for character in self.characters: character.update(dt) if character.position.toInt() == self.point.toInt(): character.score += 1 character.animation.duration = 1.0/character.score self.point = Vector.random([PIXEL_DIM_X-1, PIXEL_DIM_Y-1]) if character.score > 5: character.score = 0 character.animation.duration = 1.0 self.explosion = Explosion(character.position)
def update(self, dt): State.update(self, dt) self.lastJump += dt if self.lastJump > 2: self.point = Vector.random([PIXEL_DIM_X - 1, PIXEL_DIM_Y - 1]) self.lastJump = 0 if self.explosion: self.explosion.update(dt) for character in self.characters: character.update(dt) if character.position.toInt() == self.point.toInt(): character.score += 1 character.animation.duration = 1.0 / character.score self.point = Vector.random([PIXEL_DIM_X - 1, PIXEL_DIM_Y - 1]) if character.score > 5: character.score = 0 character.animation.duration = 1.0 self.explosion = Explosion(character.position)
def __init__(self): State.__init__(self, "Main") w = PIXEL_DIM_X - 1 h = PIXEL_DIM_Y - 1 self.characters = [ AnimatedGameObject(Vector(0, 0), RED), AnimatedGameObject(Vector(w, 0), BLUE), AnimatedGameObject(Vector(0, h), GREEN), AnimatedGameObject(Vector(w, h), YELLOW) ]
def draw(self, rgb): State.draw(self, rgb) for character in self.characters: character.draw(rgb) if self.explosion: self.explosion.draw(rgb) if self.explosion.ended: self.explosion = None if self.point: rgb.setPixel(self.point, TURQUE)
def draw(self, rgb): State.draw(self, rgb) for y in range(PIXEL_DIM_Y): left, right = self.map[y][0], self.map[y][1] for lx in range(left): pixel = Vector(lx, y) rgb.setPixel(pixel, self.wall_color) for rx in range(right): pixel = Vector(PIXEL_DIM_X - 1 - rx, y) rgb.setPixel(pixel, self.wall_color) self.ship.draw(rgb) for sprite in self.sprites: sprite.draw(rgb)
def update(self, dt): State.update(self, dt) self.offset += self.scroll_speed * dt self.scroll_speed += self.scroll_speed_increment * dt if self.offset >= 1.0: while self.offset >= 1.0: self.offset -= 1.0 self.check_collision() del self.map[0] self.map.append(self.generate_map_slice()) self.ship.update(dt) self.ship.animation.duration = 1.0 / self.scroll_speed self.sprites = [sprite for sprite in self.sprites if not sprite.ended] for sprite in self.sprites: sprite.update(dt)
def update(self, dt): State.update(self, dt) self.offset += self.scroll_speed * dt self.scroll_speed += self.scroll_speed_increment * dt if self.offset >= 1.0: while self.offset >= 1.0: self.offset -= 1.0 self.check_collision() del self.map[0] self.map.append(self.generate_map_slice()) self.ship.update(dt) self.ship.animation.duration = 1.0/self.scroll_speed self.sprites = [sprite for sprite in self.sprites if not sprite.ended] for sprite in self.sprites: sprite.update(dt)
def __init__(self): State.__init__(self, "Main") w = PIXEL_DIM_X - 1 h = PIXEL_DIM_Y - 1 self.point = Vector(6, 4) self.characters = [ AnimatedGameObject(Vector(0, 0), RED, BLUE), AnimatedGameObject(Vector(w, 0), BLUE, RED), AnimatedGameObject(Vector(0, h), GREEN, BLUE), AnimatedGameObject(Vector(w, h), YELLOW, BLUE) ] self.explosion = None for character in self.characters: character.score = 0 self.lastJump = 0
def update(self, dt): State.update(self, dt) for character in self.characters: character.update(dt)
def draw(self, rgb): State.draw(self, rgb) self.sprite.draw(rgb)
def onClampedAxisChanged(self, player, x, y): State.onClampedAxisChanged(self, player, x, y) self.ship.position.x += x
def __init__(self): State.__init__(self, "GameOver") self.started = time.time() self.sprite = FullscreenSprite(RED)
def onButtonChanged(self, player, a_button, b_button, previous_a_button, previous_b_button): State.onButtonChanged(self, player, a_button, b_button, previous_a_button, previous_b_button)
def onEnter(self, old_state): State.onEnter(self, old_state) print old_state self.reset()
def draw(self, rgb): State.draw(self, rgb) for character in self.characters: character.draw(rgb)
def onAxisChanged(self, player, x, y, px, py): State.onAxisChanged(self, player, x, y, px, py) self.characters[player].velocity = Vector(x, y) self.game.playSound('tock')