class Player(object): def __init__(self, name, init_x, init_y, image, stats, equipment, inventory, skills): self.utils = Utils() self.name = name self.x = init_x self.y = init_y self.sprite = Sprite((self.x * self.utils.MAP_TILE_WIDTH, self.y * self.utils.MAP_TILE_HEIGHT), image, self.name) self.stats = stats self.equipment = equipment self.inventory = inventory self.skills = skills def gain_stat(self, stat, gain): if stat in self.stats: self.stats[stat] += gain def equip(self, equipment): self.equipment[equipment.equip_type] = equipment equipment.is_equipped = True def unequip(self, equip_slot): self.equipment[equip_slot].is_equipped = False self.equipment.pop(equip_slot) def add_item(self, item): self.inventory.update(item) def remove_item(self, item): self.inventory.pop(item) def add_skill(self, skill): self.skills.update(skill) def remove_skill(self, skill): self.skills.pop(skill) def move(self, dx, dy): self.x += dx self.y += dy self.sprite.move(dx * self.utils.MAP_TILE_WIDTH, dy * self.utils.MAP_TILE_HEIGHT)
class Monster(object): def __init__(self, name, init_x, init_y, image, stats, other): self.utils = Utils() self.name = name self.x = init_x self.y = init_y self.sprite = Sprite((self.x * self.utils.MAP_TILE_WIDTH, self.y * self.utils.MAP_TILE_HEIGHT), image, self.name) self.stats = stats self.exp_given = other['exp'] self.difficulty = other['difficulty'] def move(self, dx, dy): self.x += dx self.y += dy self.sprite.move(dx * self.utils.MAP_TILE_WIDTH, dy * self.utils.MAP_TILE_HEIGHT) def set_pos(self, abs_pos): self.x = abs_pos[0] self.y = abs_pos[1] self.sprite.move(abs_pos[0] * self.utils.MAP_TILE_WIDTH, abs_pos[1] * self.utils.MAP_TILE_HEIGHT)
if event.type == QUIT: running = False break elif event.type == KEYDOWN: if event.key == K_UP: up = True elif event.type == KEYUP: if event.key == K_UP: up = False screen.blit(background, (0, 0)) if (not dead): player.move(player_speed, up=up) player.render(screen, not up) for pipe in pipes: x, y = player.get_pos() x1, y1 = pipe.get_pos() if (player.get_collision(pipe)): die() elif (x > x1 and x < x1 + pipe.get_width() and timer > 40): score += 1 timer = 0 elif (x > x1 and x < x1 + pipe.get_width() and timer <= 40):
running = False break elif event.type == KEYDOWN: if event.key == K_UP: up = True elif event.type == KEYUP: if event.key == K_UP: up = False screen.blit(background, (0,0) ) if (not dead): player.move(player_speed, up = up) player.render(screen, not up) for pipe in pipes: x, y = player.get_pos() x1,y1= pipe.get_pos() if (player.get_collision(pipe)): die() elif (x > x1 and x < x1+pipe.get_width() and timer > 40): score += 1 timer = 0