def __init__(self, idx_x, idx_y, display): super().__init__(idx_x, idx_y, display) self.is_passable = True self.is_bullet_passable = True possible_sprites = [ "terrain_road_1", "terrain_road_2", "terrain_road_3", ] sprite_name = random.choice(possible_sprites) self.sprite = SpriteDatabase.get_sprite(sprite_name) pass
def __init__(self, idx_x, idx_y, display): self.idx_x = idx_x self.idx_y = idx_y self.display = display self.is_solid = False self.is_destroyable = False self.is_passable = False self.is_bullet_passable = False self.SIZE_X = 50 self.SIZE_Y = 50 self.pos_x = idx_x * self.SIZE_X self.pos_y = idx_y * self.SIZE_Y self.type = MapTileType.GRASS self.is_tank_track_up = False self.is_tank_track_left = False self.is_tank_track_right = False self.is_tank_track_down = False self.tank_track_up_sprite = SpriteDatabase.get_sprite("tank_track_up") self.tank_track_down_sprite = SpriteDatabase.get_sprite( "tank_track_down") self.tank_track_left_sprite = SpriteDatabase.get_sprite( "tank_track_left") self.tank_track_right_sprite = SpriteDatabase.get_sprite( "tank_track_right")
def __init__(self, idx_x, idx_y, display): super().__init__(idx_x, idx_y, display) self.is_passable = False self.is_bullet_passable = False self.sprites = [] possible_sprites_group = [ ["terrain_building_1", "terrain_building_2", "terrain_building_3"], ["terrain_building_4", "terrain_building_5", "terrain_building_6"], ["terrain_building_7", "terrain_building_8", "terrain_building_9"], ] sprites_group = random.choice(possible_sprites_group) for sprite_name in sprites_group: self.sprites.append(SpriteDatabase.get_sprite(sprite_name)) self.sprite_idx = 0 pass
def __init__(self, display, tile_size, bullets_manager): # Pixel position self.pos_x = 0 self.pos_y = 0 # Tile position self.tile_x = 0 self.tile_y = 0 # Destination tile position self.destination_tile_x = 0 self.destination_tile_y = 0 # Tank state self.state = TankState.IDLE self.move_speed = 2 self.display = display self.size_x = tile_size self.size_y = tile_size # Tank direction self.direction = TankDirection.UP # Tank group, bullets can hit only tanks with another group self.damage_group = 0 self.health = 100.0 self.bullets_manager = bullets_manager self.state_changed_callback = None self.sprites = {} self.sprites['moving_up_sprite'] = SpriteDatabase.get_sprite( 'enemy_tank_1_moving_up') self.sprites['moving_up_sprite'].loop = True self.sprites['moving_up_sprite'].play() self.sprites['moving_down_sprite'] = SpriteDatabase.get_sprite( 'enemy_tank_1_moving_down') self.sprites['moving_down_sprite'].loop = True self.sprites['moving_down_sprite'].play() self.sprites['moving_left_sprite'] = SpriteDatabase.get_sprite( 'enemy_tank_1_moving_left') self.sprites['moving_left_sprite'].loop = True self.sprites['moving_left_sprite'].play() self.sprites['moving_right_sprite'] = SpriteDatabase.get_sprite( 'enemy_tank_1_moving_right') self.sprites['moving_right_sprite'].loop = True self.sprites['moving_right_sprite'].play() self.sprites['up_sprite'] = SpriteDatabase.get_sprite( 'enemy_tank_1_up') self.sprites['down_sprite'] = SpriteDatabase.get_sprite( 'enemy_tank_1_down') self.sprites['left_sprite'] = SpriteDatabase.get_sprite( 'enemy_tank_1_left') self.sprites['right_sprite'] = SpriteDatabase.get_sprite( 'enemy_tank_1_right') self.sprites['gun_up'] = SpriteDatabase.get_sprite( 'enemy_tank_1_gun_up') self.sprites['gun_down'] = SpriteDatabase.get_sprite( 'enemy_tank_1_gun_down') self.sprites['gun_left'] = SpriteDatabase.get_sprite( 'enemy_tank_1_gun_left') self.sprites['gun_right'] = SpriteDatabase.get_sprite( 'enemy_tank_1_gun_right')
if game_logic_running: player_tank_logic.process_input(event) GAME_DELTA = 1 / GAME_FPS if game_logic_running: player_tank_logic.update(GAME_DELTA) tank_group.update(GAME_DELTA) bullets_manager.update(GAME_DELTA) bullets_manager.check_player_collision(player_tank_logic) ParticlesGenerator.update(GAME_DELTA) pygame.display.update() # Draw things gameMap.draw() tank_group.draw() bullets_manager.draw() player_tank_logic.tank.draw() ParticlesGenerator.draw() if player_tank_logic.tank.health < 0: game_over_sprite = SpriteDatabase.get_sprite("game_over") game_over_sprite.draw(display, 50, 100) game_logic_running = False pass clock.tick(GAME_FPS) pygame.quit()
def __init__(self, idx_x, idx_y, display): super().__init__(idx_x, idx_y, display) self.is_passable = True self.is_bullet_passable = True self.sprite = SpriteDatabase.get_sprite("terrain_asphalt") pass