def on_enter(self, previous_scene): super(BattleScene, self).on_enter(previous_scene) self.player = get_shared_values().player self.enemy = get_shared_values().orderly self.previous_scene = previous_scene self.state = player_move_select_state self.player_selected_item = 0 self.enemy_selected_item = 0 self.message = "" # self.player.items = get_shared_values().items # self.player.health = get_shared_values().health # self.max_health = get_shared_values().max_health # self.player.type = get_shared_values().type # self.image = get_shared_values().image # self.player_image = pygame.image.load("assets/characters/astronaut_small2.png") # self.enemy_image = pygame.image.load("assets/characters/doctor_woman.png") self.blue_move = pygame.image.load( "assets/battle-background-images/blue-rect.png") self.red_move = pygame.image.load( "assets/battle-background-images/red-rect.png") self.green_move = pygame.image.load( "assets/battle-background-images/green-rect.png") self.black_move = pygame.image.load( "assets/battle-background-images/black-rect.png") self.message_box = pygame.image.load( "assets/battle-background-images/message-box.png") self.border = pygame.image.load( "assets/battle-background-images/border.png") self.render_queue = RenderQueue() # self.test_anim = Animation(True, pygame.image.load("assets/characters/spedec-2/spedec-man-walk-2-sheet.png"), 180) # remove this # enemy_items = [ # ItemGenerator().getItem(), # ItemGenerator().getItem(), # ItemGenerator().getItem(), # ItemGenerator().getItem(), # ] # enemy_items = ItemGenerator().getItems(4) # self.enemy = Orderly("Bob", "assets/characters/doctor_woman.png", 1000, physical_type, enemy_items) self.move_font = pygame.font.Font("assets/Courgette-Regular.ttf", 24) self.movement_path = None
def drawInterface(self): margin = 8 healthPercent = get_shared_values().player.health / get_shared_values( ).player.max_health draw_health_bar(self.rq, margin, margin, healthPercent, SCREEN_WIDTH / 2 - 2 * margin, 16) weapons = get_shared_values().player.items item_spacing = ((SCREEN_WIDTH / 2) - (4 * THUMB_SIZE)) / 5 x = SCREEN_WIDTH / 2 for i in weapons: x += item_spacing self.rq.add((x, margin), i.thumb) x += THUMB_SIZE
def spawn(self): if self.entitytype not in Spawner.entities: print("Can't spawn entitytype '%s'" % self.entitytype) return edefs = Spawner.entities[self.entitytype] if self.filter is not None: edefs = [ e for e in edefs if 'filter' in e and e['filter'] == self.filter ] if self.entitytype == 'player': entitydata = [ d for d in edefs if d['name'] == get_shared_values().player.name ][0] else: entitydata = random.choice(edefs) width = entitydata['width'] * BLOCKS_PER_M height = entitydata['height'] * BLOCKS_PER_M # Spawn above the bottom of the current block b = self.y + 0.99 m = self.x + 0.5 x = m - width / 2.0 y = b - height entity = LevelEntity(x, y, self.entitytype, entitydata) # TODO: Assign a proper controller if self.type == 'goright': entity.go_r = 1 elif self.type == 'goleft': entity.go_l = 1 self.level.addEntity(entity)
def __init__(self): self.rq = RenderQueue() LevelObjectPattern.init() Spawner.init() self.itemgen = ItemGenerator() get_shared_values().player = Player("spedecWoman") self.resetLevel()
def handle_collisions(self): """ Checks collisions and applies rules based on that """ colliding = self.level.collidingEntities(self.spedec.le) matches = { t: [e for e in colliding if e.archetype == t] for t in ['health', 'orderly', 'weapon'] } # Process health items first for health in matches['health']: get_shared_values().player.adjust_health( health.definition['amount']) self.level.dropEntity(health) # Process weapon pickups if self.spedec.get_item and matches['weapon']: weapon = matches['weapon'][0] self.level.dropEntity(weapon) game_item = self.itemgen.getItemByName(weapon.definition['name']) itemDropped = get_shared_values().player.add_item(game_item) if itemDropped: weaponName = itemDropped.name weapons = Spawner.entities['weapon'] definitions = [d for d in weapons if d['name'] == weaponName] if definitions: x, y = (self.spedec.le.centre, self.spedec.le.middle) entity = LevelEntity(x, y, 'weapon', definitions[0]) self.level.addEntity(entity) else: print("Can't drop item '%s'!" % weaponName) # Only process the first orderly to collide with if matches['orderly']: orderly = matches['orderly'][0] get_shared_values().orderly = Orderly(orderly.definition['name']) self.level.dropEntity(orderly) self.application.change_scene(get_battle_scene())
def __init__(self, name): sanity = round(10 * get_shared_values().distance_through_level) _json = json.load(open('entities.json')) for thing in _json["orderly"]: if thing["name"] == name: orderly_json = thing self.name = name self.health = orderly_json["health"] self.max_health = orderly_json["health"] self.type = orderly_json["type"] self.image_path = orderly_json["image"] self.image = pygame.image.load("assets/" + self.image_path) # image_width = self.image.get_width() image_height = self.image.get_height() desired_height = 250 ratio = desired_height / image_height self.image = pygame.transform.smoothscale( self.image, (int(self.image.get_width() * ratio), int(self.image.get_height() * ratio))) self.image_width = self.image.get_width() self.image_height = self.image.get_height() approperate_items = [] for item in _json["weapon"]: if item["sanity"] > (sanity - 2) and item["sanity"] < (sanity + 2): approperate_items.append(item["name"]) self.items = [] if len(approperate_items) < 4: for approperate_item in approperate_items: self.items.append( ItemGenerator().getItemByName(approperate_item)) else: random.shuffle(approperate_items) for approperate_item in approperate_items[:4]: self.items.append( ItemGenerator().getItemByName(approperate_item))
def update(self, dt): keys = pygame.key.get_pressed() self.spedec.setInputs(keys) # Go back to last lamppost if we run out of health if get_shared_values().player.health <= 0: # TODO: reset this scene to the last lamppost self.application.change_scene(get_game_over_scene()) # TODO: Win if we get to the end of the level # if self.spedec.??x position?? > ??level width??: # self.application.change_scene(get_win_scene()) self.handle_collisions() self.level.setScreenRect(self.camera_left, self.camera_top, self.camera_right, self.camera_bottom) self.level.update(dt / 1000.0) self.spedec.afterUpdate() if not self.spedec.dead: self.aimCamera(self.spedec.le.centre, self.spedec.le.middle) else: self.resetLevel()
def leave_scene(self): get_shared_values().health = self.player.health get_shared_values().enemy = None self.application.change_scene(self.previous_scene)
self.player.items) if event.key == pygame.K_RETURN or event.key == pygame.K_SPACE: self.state = player_attack_animation_state elif self.state == player_message_state: if event.type == pygame.KEYDOWN: if event.key == pygame.K_RETURN or event.key == pygame.K_SPACE: self.state = enemy_move_select_state elif self.state == enemy_message_state: if event.type == pygame.KEYDOWN: if event.key == pygame.K_RETURN or event.key == pygame.K_SPACE: self.state = player_move_select_state if __name__ == '__main__': app = ezpygame.Application(title='The Game', resolution=(SCREEN_WIDTH, SCREEN_HEIGHT), update_rate=FPS) get_shared_values().orderly = Orderly("doctor woman") get_shared_values().player = Player("spedecWoman") app.run(BattleScene())
def resetLevel(self): self.level = Level.load(get_shared_values().levelfile) self.spedec = SpedEcController(self.level.getSpedEcEntity()) self.aimCamera(self.spedec.le.centre, self.spedec.le.middle) self.death = 0