示例#1
0
文件: player.py 项目: b4naser/Amnesty
    def __init__(self):
        self.inventory = Inventory()

        self.image = SpriteSheet("media/char.png").get_sprite(0, 0, 32, 48)
        self.rect = self.image.get_rect()

        # Used to delay moving player till the collision will be checked
        # TODO: Change vector to class
        self.vector = {"x": 0, "y": 0}

        self.x = 200
        self.y = 200

        # FIXME: Connected with fixme from platform.py
        # If you consider it's stupid know that when you player he is on different position
        # till he will be updated and collide with newly created items
        self.rect.x = self.y
        self.rect.y = self.x

        # Actual sprite position
        self.sprite_col = 0
        self.sprite_row = 0

        # Used to draw sprite at certain frames
        self.frame = 0

        # Save attacking state:
        self.attacking = False
        self.attacking_time = 0
示例#2
0
文件: client.py 项目: armandmgt/zappy
 def look(self):
     self.write('Look')
     data = parse_response_array(self.responses.get())
     self.player.vision = []
     for s in data:
         vision = Inventory([0] * len(_ITEMS))
         segment = s.strip().split(' ')
         for key in segment:
             if find(vision.keys(), key=lambda x: x == key) is not None:
                 vision[key] += 1
         self.player.vision.append(vision)
示例#3
0
    def init_player(race, prof, name):
        consts = Constants.consts
        race_dict = consts[race]
        prof_dict = consts[prof]
        hp = race_dict['hp'] + prof_dict['hp_bonus']
        defense = race_dict['defense'] + prof_dict['def_bonus']
        power = race_dict['power'] + prof_dict['power_bonus']
        xp = 0
        armor = 0
        mana = race_dict['mana'] + prof_dict['mana_bonus']
        magic = race_dict['magic'] + prof_dict['magic_bonus']
        fighting = race_dict['fighting'] + prof_dict['fighting_bonus']
        shielding = race_dict['shielding'] + prof_dict['shielding_bonus']
        conjuring = race_dict['conjuring'] + prof_dict['conjuring_bonus']
        archery = race_dict['archery'] + prof_dict['archery_bonus']
        transmutations = race_dict['transmutations'] + prof_dict['transmutations_bonus']
        hexes = race_dict['hexes'] + prof_dict['hexes_bonus']
        speed = race_dict['speed']
        mana_regen = race_dict['mana_regen']

        fighter_component = Fighter(hp, defense, power, xp, armor, mana, magic,
                                    death_function=DeathFunctions.player_death,
                                    fighting=fighting, shielding=shielding, conjuring=conjuring,
                                    archery=archery, transmutations=transmutations, hexes=hexes,
                                    speed=speed, mana_regen=mana_regen)
        fighter_component.stealthiness = race_dict['stealthiness']

        inv_component = Inventory()

        player = Entity(0, 0, consts['player_tile'], name, libtcod.white, blocks=True, fighter=fighter_component,
                        race=race, prof=prof, inventory=inv_component)
        player.level = 1
        player.isplayer = True
        return player
示例#4
0
 def __init__(self,
              score: float = 0,
              origin: int = 0,
              level: int = 0,
              inventory: Inventory = Inventory()):
     self.score = score
     self.origin = origin
     self.level = level
     self.inventory = inventory
示例#5
0
 def resources_score(self, inventory: Inventory) -> int:
     my_needed_resources = _RESOURCES_NEEDED[self.client.player.level - 1]
     for (key, value) in my_needed_resources.items():
         new_value = value - self.client.player.inventory[key]
         my_needed_resources[key] = 0 if new_value < 0 else new_value
     resource_scores = []
     for (key, available) in inventory.items():
         missing_resource = my_needed_resources[key] - available
         if missing_resource < 0:
             missing_resource = 0
         resource_scores.append(missing_resource)
     return 1 / sum(resource_scores) if sum(resource_scores) else 1
示例#6
0
class Player:
	level = 1
	position: Vec2d = Vec2d(0, 0)
	orientation = 0
	inventory = Inventory()
	vision = []

	def __init__(self, pid: int, pos: Vec2d or None):
		self.id = pid
		self.position = pos if not None else Vec2d(0, 0)
		for x in range(4):
			self.vision.append(Inventory())

	def to_str(self) -> str:
		return f'{self.level};{self.inventory}'
示例#7
0
    def __init__(self, hwnd, coordinates):

        print("DEBUG: setting up runescape client instance")

        self.hwnd = hwnd
        self.coordinates = coordinates

        self.exchange = exchange.Exchange(self.coordinates)
        self.is_member = config.membership

        if os.path.exists("./data/dynamic_coordinates.json"):

            file = open('./data/dynamic_coordinates.json', 'r')
            coords = json.load(file)

            self.inventory = Inventory(
                utils.dynamic_coordinate_converter(self.coordinates,
                                                   coords['inventory_window'],
                                                   '+'))
        self.inventory.inventory_list[0].set(items.Item('coins'),
                                             self.find_coins())
        print("DEBUG: Coins in inventory",
              self.inventory.inventory_list[0].amount)
示例#8
0
    def update(self, time_delta, objects, enemies=None):
        p_s = pygame.mixer.Sound('sounds/foot.ogg')
        p_s.set_volume(0.1)
        self.last_damage += 1
        if self.direction == 0:
            self.set_sprite(Player.player_sprite_right[0])
        else:
            self.set_sprite(Player.player_sprite_left[0])
        keys = pygame.key.get_pressed()
        old_x = self.get_x()
        old_y = self.get_y()
        horizontal_direction = 0
        if keys[K_d]:
            self.direction = 0
            horizontal_direction += 1
            self.set_sprite(Player.player_sprite_right[self.index // 10])
            self.index += 1
            if self.index > 20:
                self.index = 0
        if keys[K_a]:
            self.direction = 1
            horizontal_direction -= 1
            self.set_sprite(Player.player_sprite_left[self.index // 10])
            self.index += 1
            if self.index > 20:
                self.index = 0

        self.set_x(self._x + self.speed *
                   (time_delta / 1000) * horizontal_direction)

        for obj in pygame.sprite.spritecollide(self, objects, dokill=False):
            inventory = Inventory.get_instance()
            if obj.type == 'rocket':
                self.hp = -1
            elif obj.type == 'rock':
                if not obj.push(
                        self.speed *
                    (time_delta / 1000) * horizontal_direction, 0, objects):
                    self.set_x(old_x)
                    break
            elif obj.type == 'rainbow1':
                if not obj.push(
                        self.speed *
                    (time_delta / 1000) * horizontal_direction, 0, objects):
                    self.set_x(old_x)
                    break
            elif obj.type == 'rainbow2':
                if not obj.push(
                        self.speed *
                    (time_delta / 1000) * horizontal_direction, 0, objects):
                    self.set_x(old_x)
                    break
            elif obj.type == 'key':
                item = Item(
                    "key_{}".format(obj.part), "key_{}".format(obj.part),
                    pygame.image.load('img/key_{}.png'.format(obj.part)), 0, 0)
                inventory.add_item(item)
                if inventory.check_engine():
                    pass
                obj.cary = True
                if obj.part in (1, 2):
                    inventory.unitKey()
                obj.kill()
            elif obj.type == 'door' and inventory.checkKey():
                obj.sound = obj.sound.play()
                obj.kill()
            elif obj.type == 'item':
                inventory.add_item(obj)
                obj.kill()
            elif obj.type in ('ghost', 'monster', 'saw'):
                self.take_damage()
            elif not obj.type == "background" and obj.type != 'button':
                self.set_x(old_x)
                break

        vertical_direction = 0

        if keys[K_s]:
            vertical_direction -= 1
            if self.direction == 0:
                self.set_sprite(Player.player_sprite_right[self.index // 10])
                self.index += 1
                if self.index > 20:
                    self.index = 0
            if self.direction == 1:
                self.set_sprite(Player.player_sprite_left[self.index // 10])
                self.index += 1
                if self.index > 20:
                    self.index = 0
        if keys[K_w]:
            vertical_direction += 1
            old_y = self.get_y()
            if self.direction == 0:
                self.set_sprite(Player.player_sprite_right[self.index // 10])
                self.index += 1
                if self.index > 20:
                    self.index = 0
            if self.direction == 1:
                self.set_sprite(Player.player_sprite_left[self.index // 10])
                self.index += 1
                if self.index > 20:
                    self.index = 0
        self.set_y(self._y - self.speed *
                   (time_delta / 1000) * vertical_direction)

        inventory = Inventory.get_instance()
        for obj in pygame.sprite.spritecollide(self, objects, dokill=False):
            if obj.type == 'rocket':
                self.hp = -1
            elif obj.type == 'rock':
                if not obj.push(
                        0,
                        self.speed *
                    (time_delta / 1000) * -vertical_direction, objects):
                    self.set_y(old_y)
                    break
            elif obj.type == 'rainbow1':
                if not obj.push(
                        0,
                        self.speed *
                    (time_delta / 1000) * -vertical_direction, objects):
                    self.set_y(old_y)
                    break
            elif obj.type == 'rainbow2':
                if not obj.push(
                        0,
                        self.speed *
                    (time_delta / 1000) * -vertical_direction, objects):
                    self.set_y(old_y)
            elif obj.type == 'key':
                item = Item(
                    "key_{}".format(obj.part), "key_{}".format(obj.part),
                    pygame.image.load('img/key_{}.png'.format(obj.part)), 0, 0)
                inventory.add_item(item)
                if inventory.check_engine():
                    pass

                obj.cary = True
                inventory.unitKey()
                obj.kill()
            elif obj.type == 'item':
                inventory.add_item(obj)
                obj.kill()

            elif obj.type == 'door' and inventory.checkKey():
                obj.sound = obj.sound.play()
                obj.kill()

            elif obj.type in ('ghost', 'monster', 'saw'):
                self.take_damage()
            elif not obj.type == "background" and obj.type != 'button':
                self.set_y(old_y)
                break

        if enemies is not None:
            for obj in pygame.sprite.spritecollide(self, enemies,
                                                   dokill=False):
                if obj.type == 'arrow':
                    if obj.horizontal_direction != 0 or obj.vertical_direction != 0:
                        self.take_damage()
                    item = Item("arrow", "arrow",
                                pygame.image.load('img/strzala_prawo.png'), 0,
                                0)
                    inventory.add_item(item)
                    obj.cary = True
                    obj.kill()
示例#9
0
import random

from classes.game import Character
from classes.magic import Spell
from classes.inventory import Inventory

# Spells
iceBolt = Spell("Ice bolt", 12, 40, "Ice")
fireBolt = Spell("Fire bolt", 5, 15, "Fire")
earthBolt = Spell("Earth bolt", 26, 57, "Earth")
windBolt = Spell("Wind bolt", 1, 10, "Wind")
heal = Spell("Lesser Heal", 2, 10, "White")

# Items
smallPotion = Inventory("Small Potion", "potion", "Heals you for 25hp", 25)
potion = Inventory("Potion", "potion", "Heals you for 100hp", 100)
bomb = Inventory("Bomb", "attack", "Attacks enemy for 350hp", 200)

# Characters
hero = Character(500, 120, 50, 30, [iceBolt, fireBolt, earthBolt, windBolt, heal], [smallPotion, potion, bomb])
enemy = Character(450, 100, 20, 30, [windBolt, earthBolt], [smallPotion, bomb, potion])

running = True

while running:

    # ___PLAYER ACTION____
    print("+==================+")
    hero.chooseAction()
    select = input("Choose action:")
    index = int(select) - 1
示例#10
0
	def __init__(self, pid: int, pos: Vec2d or None):
		self.id = pid
		self.position = pos if not None else Vec2d(0, 0)
		for x in range(4):
			self.vision.append(Inventory())
示例#11
0
def game(screen):
    """Load levels"""
    global welcome, lost, game_sound

    game_state = GameState.get_instance()
    inventory = Inventory.get_instance()
    inventory_board = pygame.Surface(screen.get_size())

    item = Item("arrow", "arrow", pygame.image.load('img/strzala_prawo.png'), 0, 0)
    item2 = Item("arrow", "arrow", pygame.image.load('img/strzala_prawo.png'), 0, 0)
    item3 = Item("arrow", "arrow", pygame.image.load('img/strzala_prawo.png'), 0, 0)
    Inventory.get_instance().add_item(item)
    Inventory.get_instance().add_item(item2)
    Inventory.get_instance().add_item(item3)

    game_state.reset()

    room_manager.set_lvl(lvl)

    """Sound"""

    game_menu.sound.stop()
    if (room_manager.get_lvl() == 1):
        print('test')
        game_sound = pygame.mixer.Sound('sounds/LOCHY-theme.ogg')
        game_sound.play(-1)
        game_sound.set_volume(0.15)


    board = pygame.Surface((640, 640))


    run = True
    counter = 0
    while run:
        counter += 1
        board, welcome_2 = calculate_scale(screen.get_size(), board, welcome, force=True)
        board.blit(welcome_2, (0, 0))
        screen.fill((0, 0, 0))
        screen.blit(board, ((screen.get_size()[0] - board.get_size()[0])/2, 0))
        pygame.display.flip()
        for event in pygame.event.get():
            if event.type == pygame.KEYDOWN and counter > 300:
                run = False


    player = Player.get_instance()
    player.set_x(128)
    player.set_y(128)

    show_s = True

    resett = True

    while(not game_state.exit):
        objects_list = room_manager.get_objects()
        old_room_obj = room(screen, board, objects_list, inventory, inventory_board)
        player = Player.get_instance()
        if player.get_y() < 0:
            room_manager.move_up()
        elif player.get_y() + player._height > 16 * 16:
            room_manager.move_down()
        elif player.get_x() < 0:
            room_manager.move_left()
        elif player.get_x() + player._width > 16 * 16:
            room_manager.move_right()
        if old_room_obj is not None:
            play_room_animation(old_room_obj, room_manager.get_objects(), board, inventory, inventory_board)
        GameObject.clear_objects_list()
        if game_state.next_lvl:
            game_state.next_lvl = False
            room_manager.set_lvl(room_manager.get_lvl() + 1)

        if (room_manager.get_lvl() == 2 and resett):
            resett = False
            game_sound.stop()
            game_sound = pygame.mixer.Sound('sounds/hepi-theme-final.ogg')
            game_sound.play(-1)
            game_sound.set_volume(0.95)

        run = True
        counter = 0
        while run and show_s and room_manager.get_lvl() == 2:
            counter += 1
            board, lost3 = calculate_scale(screen.get_size(), board, lost2, force=True)
            board.blit(lost3, (0, 0))
            screen.fill((0, 0, 0))
            screen.blit(board, ((screen.get_size()[0] - board.get_size()[0])/2, 0))
            pygame.display.flip()
            for event in pygame.event.get():
                if event.type == pygame.KEYDOWN and counter > 300:
                    run = False
                    show_s = False

    run = True
    counter = 0
    while run:
        counter += 1
        if Player.get_instance().hp == 0:
            board, lost_2 = calculate_scale(screen.get_size(), board, lost, force=True)
        else:
            board, lost_2 = calculate_scale(screen.get_size(), board, win, force=True)
        board.blit(lost_2, (0, 0))
        screen.fill((0, 0, 0))
        screen.blit(board, ((screen.get_size()[0] - board.get_size()[0])/2, 0))
        pygame.display.flip()
        for event in pygame.event.get():
            if event.type == pygame.QUIT and counter > 300:
                run = False
            if event.type == pygame.KEYDOWN and counter > 300:
                run = False
    exit(0)
示例#12
0
def room(screen, board, objects_list: list, inventory: Inventory, inventory_board) -> pygame.sprite.Group:

    global hearth, empty_heart, hearths_board, game_sound

    game_s = GameState.get_instance()
    game_s = game_s.sound

    if game_s != None:
        game_sound.stop()
        game_sound = game_s
        game_sound.play()


    objects = pygame.sprite.Group()
    monsters = pygame.sprite.Group()
    enemies = pygame.sprite.Group()
    teleports = pygame.sprite.Group()
    floor = None
    if RoomManager.get_instance().get_lvl() == 1:
        floor = pygame.image.load('img/no_floor.png')
    else:
        floor = pygame.image.load('img/no_floor.png')

    for o in objects_list:
        if not isinstance(o, Teleport) and not isinstance(o, Monster):
            objects.add(o)
        elif isinstance(o, Monster):
            monsters.add(o)
        elif not o.cary:
            teleports.add(o)
        elif o.cary:
            pass

    for obj in objects:
        if obj.type in ('ghost', 'rock', 'rainbow1', 'rainbow2', 'saw'):
            enemies.add(obj)

    for o in monsters:
        enemies.add(o)

    clock = pygame.time.Clock()
    game_state = GameState.get_instance()

    player = Player.get_instance()
    player_group = pygame.sprite.Group()
    player_group.add(player)

    inventory_g = pygame.sprite.Group()
    inventory_bar = pygame.sprite.Group()
    inventory.rescale()
    inventory_bar.add(inventory)

    # Make sure if scale of the board is correct
    board, floor = calculate_scale(screen.get_size(), board, floor, force=True)

    all_objects = pygame.sprite.Group()
    for obj in objects:
        all_objects.add(obj)
    for obj in monsters:
        all_objects.add(obj)

    running = True
    while running:
    
        for i in game_state.resp:
            enemies.add(i)
            all_objects.add(i)
            game_state.resp.remove(i)

        hearths_board.fill((0, 0, 0))
        inventory_g = pygame.sprite.Group()
        for o in inventory.get_items():
            o.rescale()
            inventory_g.add(o)

        for i in range(3):
            if i < player.hp:
                hearths_board.blit(hearth, (16*i * game_state.get_board_scale(), 0))
            else:
                hearths_board.blit(empty_heart, (16*i * game_state.get_board_scale(), 0))

        time_delta = clock.tick(120)
        # RGB from 0 to 255
        screen.fill((0, 0, 0))
        inventory_board.fill((0, 0, 0))

        board.fill((0, 255, 0))
        if floor:
            board.blit(floor, (0, 0))

        objects.update(time_delta)
        teleports.update(time_delta)
        monsters.update(time_delta, objects)
        player.update(time_delta, all_objects, enemies)
        enemies.update(time_delta, all_objects)

        objects.draw(board)
        enemies.draw(board)
        teleports.draw(board)
        player_group.draw(board)
        monsters.draw(board)

        inventory_bar.draw(inventory_board)
        inventory_g.draw(inventory_board)

        screen.blit(inventory_board, (0, 0))
        screen.blit(hearths_board, (0, screen.get_size()[1]-16 * GameState.get_instance().get_board_scale()))
        screen.blit(board, ((screen.get_size()[0] - board.get_size()[0])/2, 0))
        pygame.display.flip()
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False
                game_state.exit = True
                exit(0)
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    running = False
                    game_state.exit = True
                    exit(0)

                arrow = None
                if event.key == pygame.K_UP:
                    arrow = Arrow.shoot_arrow(0, -1)
                elif event.key == pygame.K_DOWN:
                    arrow = Arrow.shoot_arrow(0, 1)
                elif event.key == pygame.K_LEFT:
                    arrow = Arrow.shoot_arrow(-1, 0)
                elif event.key == pygame.K_RIGHT:
                    arrow = Arrow.shoot_arrow(1, 0)

                if arrow is not None:
                    enemies.add(arrow)
            elif event.type == pygame.VIDEORESIZE:
                width, height = event.size
                if width < 300:
                    width = 300
                    pygame.display.set_mode((width, height), pygame.RESIZABLE)
                if height < 300:
                    height = 300
                    pygame.display.set_mode((width, height), pygame.RESIZABLE)
                board, floor = calculate_scale(event.size, board, floor)
            elif event.type == pygame.KEYUP and event.key == pygame.K_e:
                if inventory.has_potion():
                    player.hp = player.hp + 1
                    inventory.dec_potion()

        if player.check_if_hit_border():
            for t in teleports:
                objects.add(t)
            Saw.stop_saws()
            return objects
        if pygame.sprite.spritecollideany(player, teleports):
            Saw.stop_saws()
            game_state.next_lvl = True
            running = False
        if player.hp == 0 or player.hp == -1:
            game_sound.stop()
            lost_s.play()
            Saw.stop_saws()
            running = False
            game_state.exit = True
示例#13
0
def play_room_animation(old_objects, new_objects, board, inventory: Inventory, inventory_board):
    global hearth, empty_heart, hearths_board
    speed = 150
    player = Player.get_instance()
    horizontal = True
    direction = -1
    if player.get_x() < 0:
        horizontal = True
        direction = 1
    elif player.get_y() < 0:
        horizontal = False
        direction = 1
    elif player.get_y() + player._height > 16 * 16:
        horizontal = False
        direction = -1

    if horizontal:
        for x in new_objects:
            if not x.cary:
                x.set_x(x.get_x() - 16 * 16 * direction)
    if not horizontal:
        for x in new_objects:
            if not x.cary:
                x.set_y(x.get_y() - 16 * 16 * direction)

    objects_list = new_objects
    new_objects = pygame.sprite.Group()
    inventory_g = pygame.sprite.Group()
    inventory_bar = pygame.sprite.Group()

    for o in objects_list:
        if not o.cary:
            new_objects.add(o)


    player_group = pygame.sprite.Group()
    player_group.add(player)
    inventory.rescale()
    inventory_bar.add(inventory)

    clock = pygame.time.Clock()
    game_state = GameState.get_instance()
    if RoomManager.get_instance().get_lvl() == 1:
        floor = pygame.image.load('img/no_floor.png')
    else:
        floor = pygame.image.load('img/no_floor.png')
    board, floor = calculate_scale(screen.get_size(), board, floor, force=True)
    move = 0

    while True:

        for o in inventory.get_items():
            o.rescale()
            inventory_g.add(o)

        inventory_board.fill((0, 0, 0))
        hearths_board.fill((0, 0, 0))
        for i in range(3):
            if i < player.hp:
                hearths_board.blit(hearth, (16*i * game_state.get_board_scale(), 0))
            else:
                hearths_board.blit(empty_heart, (16*i * game_state.get_board_scale(), 0))


        inventory_board.fill((0, 0, 0))
        inventory_bar.draw(inventory_board)
        inventory_g.draw(inventory_board)

        time_delta = clock.tick(120)
        move += speed * (time_delta/1000) * game_state.get_board_scale()
        screen.fill((0, 0, 0))

        board.fill((0, 255, 0))
        if floor:
            if horizontal:
                board.blit(floor, (move*2 * direction, 0))
                board.blit(floor, (move*2 * direction - (direction * 256 * GameState.get_instance().get_board_scale()), 0))
            else:
                board.blit(floor, (0, -move*2 * -direction))
                board.blit(floor, (0, -move*2 * -direction - (direction * 256 * GameState.get_instance().get_board_scale())))
        new_objects.draw(board)
        old_objects.draw(board)
        player_group.draw(board)
        screen.blit(inventory_board, (0, 0))
        screen.blit(hearths_board, (0, screen.get_size()[1]-16 * GameState.get_instance().get_board_scale()))
        screen.blit(board, ((screen.get_size()[0] - board.get_size()[0])/2, 0))
        pygame.display.flip()

        if horizontal:
            for x in old_objects:
                if not x.cary:
                    x.set_x(x.get_x() + speed * (time_delta/1000) * game_state.get_board_scale() * direction)
            for x in new_objects:
                if not x.cary:
                    x.set_x(x.get_x() + speed * (time_delta/1000) * game_state.get_board_scale() * direction)
            player.set_x(player.get_x() + speed * (time_delta/1000) * game_state.get_board_scale()/(17.3/16) * direction)
        else:
            for x in old_objects:
                if not x.cary:
                    x.set_y(x.get_y() + speed * (time_delta/1000) * game_state.get_board_scale() * direction)
            for x in new_objects:
                if not x.cary:
                    x.set_y(x.get_y() + speed * (time_delta/1000) * game_state.get_board_scale() * direction)
            player.set_y(player.get_y() + speed * (time_delta/1000) * game_state.get_board_scale()/(17.3/16) * direction)

        if move >= 16 * 16:
            if horizontal:
                player.set_x(player.get_x() - direction)
            else:
                player.set_y(player.get_y() - direction)
            return
示例#14
0
from classes.inventory import Inventory
from constants import game_settings as gs
from constants import voice_settings as vs
from constants import speech_settings as ss
from constants import entity_settings as es
from functions import load
import pygame as pg
from classes import player, objects
from classes import mapping
from functions import speech

inventory = Inventory(player, 10, 5, 2)

playerList = ("Adam", "Alex", "Amelia", "Bob", "Bouncer", "Conference_man",
              "Conference_woman", "Dan", "Edward", "Halloween_Kid_1",
              "kid_Abby", "kid_Oscar", "Lucy", "Molly", "Old_man_Josh",
              "Old_woman_Jenny", "Pier", "Rob", "Roki", "Samuel",
              "Santa_claus")
clickArrow = False
compteur = 0


def win_init():
    pg.display.set_caption("HETIC LIFE")  #window title
    # Game Icon (HETIC LOGO)
    pg.display.set_icon(pg.image.load("img/game_icon.png"))
    gs.win = pg.display.set_mode((gs.WIDTH, gs.HEIGHT))
    pg.mouse.set_cursor(*pg.cursors.diamond)
    gs.run = True
    gs.clock = pg.time.Clock()
    init_game()
示例#15
0
文件: player.py 项目: b4naser/Amnesty
class Player(object):
    def __init__(self):
        self.inventory = Inventory()

        self.image = SpriteSheet("media/char.png").get_sprite(0, 0, 32, 48)
        self.rect = self.image.get_rect()

        # Used to delay moving player till the collision will be checked
        # TODO: Change vector to class
        self.vector = {"x": 0, "y": 0}

        self.x = 200
        self.y = 200

        # FIXME: Connected with fixme from platform.py
        # If you consider it's stupid know that when you player he is on different position
        # till he will be updated and collide with newly created items
        self.rect.x = self.y
        self.rect.y = self.x

        # Actual sprite position
        self.sprite_col = 0
        self.sprite_row = 0

        # Used to draw sprite at certain frames
        self.frame = 0

        # Save attacking state:
        self.attacking = False
        self.attacking_time = 0

    def update(self):
        self.image = SpriteSheet("media/char.png").get_sprite(
            self.sprite_col * 32, self.sprite_row * 48, 32, 48)
        self.rect.x = self.x + Cam.x
        self.rect.y = self.y + Cam.y

        if self.attacking:
            self.attacking_time += 1

        if self.attacking_time > 5:
            self.attacking = False
            self.attacking_time = 0

    def move_left(self):
        if not self.sprite_row == 1:
            self.frame = 0

        if self.frame % 5 == 0:
            self.sprite_col += 1
            self.sprite_row = 1
            if self.sprite_col > 3:
                self.sprite_col = 0

            self.frame = 1

        self.frame += 1

        self.vector["x"] -= 6

    def move_right(self):
        if not self.sprite_row == 2:
            self.frame = 0

        if self.frame % 4 == 0:
            self.sprite_col += 1
            self.sprite_row = 2
            if self.sprite_col > 3:
                self.sprite_col = 0

            self.frame = 1

        self.frame += 1

        self.vector["x"] += 6

    def move_top(self):
        if not self.sprite_row == 3:
            self.frame = 0

        if self.frame % 4 == 0:
            self.sprite_col += 1
            self.sprite_row = 3
            if self.sprite_col > 3:
                self.sprite_col = 0

            self.frame = 1

        self.frame += 1

        self.vector["y"] -= 6

    def move_down(self):
        if not self.sprite_row == 0:
            self.frame = 0

        if self.frame % 4 == 0:
            self.sprite_col += 1
            self.sprite_row = 0
            if self.sprite_col > 3:
                self.sprite_col = 0

            self.frame = 1

        self.frame += 1

        self.vector["y"] += 6

    def attack(self):
        if self.inventory.get_equipped_weapon():
            self.attacking = True
            Music.player_attack()
示例#16
0
    def get_objects(self) -> list:
        game_state = GameState.get_instance()
        """Return all objects in current room"""
        if self.rooms[self._y][self._x] is None:
            self.load_room(self._x, self._y)
        # TODO: refactor :)
        objects = []
        for y, row in enumerate(self.rooms[self._y][self._x]):
            for x, tile in enumerate(row):
                if tile == '#':
                    objects.append(Wall(x * 16, y * 16))
                elif tile == '$':
                    objects.append(Teleport(x * 16, y * 16))
                elif tile == '{':
                    objects.append(Door(x * 16, y * 16))
                elif tile == '}':
                    objects.append(Door(x * 16, y * 16, 'right'))
                elif tile == ']':
                    objects.append(Door(x * 16, y * 16, 'up'))
                elif tile == '[':
                    objects.append(Door(x * 16, y * 16, 'down'))
                elif tile == 'r':

                    objects.append(Rock(x * 16 + 1, y * 16 + 1))
                elif tile == 'k':
                    inventory = Inventory.get_instance()
                    if not inventory.checkKey():
                        objects.append(Key(x * 16, y * 16, 1))
                elif tile == 'l':
                    objects.append(Key(x * 16, y * 16, 2))
                elif tile == 'g':
                    objects.append(Ghost(x * 16, y * 16))
                elif tile == 'b':
                    objects.append(Button(x * 16, y * 16))
                elif tile == 't':
                    objects.append(Trellis(x * 16, y * 16))

                elif tile == 'e':
                    objects.append(
                        Wall(
                            x * 16, y * 16,
                            pygame.image.load('img/dungeon_wall_broken.png').
                            convert_alpha()))
                elif tile == 'j':
                    objects.append(
                        Wall(
                            x * 16, y * 16,
                            pygame.image.load('img/dungeon_spiders_web.png').
                            convert_alpha()))
                elif tile == 'a':
                    objects.append(
                        Wall(
                            x * 16, y * 16,
                            pygame.image.load(
                                'img/dungeon_bones.png').convert_alpha()))
                elif tile == 'c':
                    objects.append(
                        Wall(
                            x * 16, y * 16,
                            pygame.image.load(
                                'img/dungeon_skull.png').convert_alpha()))
                elif tile == 'h':
                    objects.append(
                        Background(
                            x * 16, y * 16,
                            pygame.image.load(
                                'img/candy_rainbow_wall.png').convert_alpha()))
                elif tile == 'm':
                    objects.append(
                        Wall(
                            x * 16, y * 16,
                            pygame.image.load(
                                'img/candy_wall.png').convert_alpha()))
                elif tile == 'd':
                    objects.append(
                        Monster(x * 16, y * 16, 20, 'sounds/demon.ogg',
                                'img/demon_0.png', 'demon', 5))

                elif tile == 'n':
                    objects.append(
                        Monster(x * 16, y * 16, 15, 'sounds/demon.ogg',
                                'img/candy_mob_0.png', 'candy_mob', 0))

                elif tile == 'o':
                    objects.append(
                        Monster(x * 16, y * 16, 20, 'sounds/demon.ogg',
                                'img/rainbow_mob_0.png', 'rainbow_mob', 2))
                elif tile == 'z':
                    objects.append(
                        Background(
                            x * 16, y * 16,
                            pygame.image.load('img/dungeon_background2.png').
                            convert_alpha()))
                elif tile == 'p':
                    objects.append(
                        Trellis(
                            x * 16, y * 16,
                            pygame.image.load(
                                'img/krata2.png').convert_alpha()))
                elif tile == 'q':
                    objects.append(
                        Background(
                            x * 16, y * 16,
                            pygame.image.load('img/candy_rainbow_wall2.png').
                            convert_alpha()))
                elif tile == 'x':
                    objects.append(Rainbow_1(x * 16, y * 16))
                elif tile == '&':
                    objects.append(Rainbow_2(x * 16, y * 16))
                elif tile == 's':
                    objects.append(Key(x * 16, y * 16, 3))
                elif tile == 'u':
                    objects.append(Key(x * 16, y * 16, 4))
                elif tile == '+':
                    objects.append(Button_rainbow1(x * 16, y * 16))

                elif tile == '-':
                    objects.append(Button_rainbow2(x * 16, y * 16))

                elif tile == 'f':
                    objects.append(Background(x * 16, y * 16))
                elif tile == 'v':
                    objects.append(Saw(x * 16, y * 16))
                    objects.append(
                        Background(
                            x * 16, y * 16,
                            pygame.image.load(
                                'img/saw_track.png').convert_alpha()))
                elif tile == '|':
                    objects.append(Saw(x * 16, y * 16, False))
                    objects.append(
                        Background(
                            x * 16, y * 16,
                            pygame.image.load(
                                'img/saw_track_v.png').convert_alpha()))
                elif tile == '=':
                    objects.append(
                        Item(
                            "hp_potion", "hp_potion",
                            pygame.image.load(
                                'img/hp_potion.png').convert_alpha(), x * 16,
                            y * 16))
                elif tile == 'y':
                    objects.append(
                        Monster(x * 16, y * 16, 12, 'sounds/demon.ogg',
                                'img/dr_pehape_0.png', 'dr_pehape', 0, 4,
                                False))
                    game_state.sound = pygame.mixer.Sound('sounds/boss_t.ogg')
                elif tile == '*':
                    objects.append(
                        Background(
                            x * 16, y * 16,
                            pygame.image.load(
                                'img/saw_track.png').convert_alpha()))
                elif tile == '@':
                    objects.append(
                        Background(
                            x * 16, y * 16,
                            pygame.image.load(
                                'img/saw_track_v.png').convert_alpha()))
                elif tile == '`':
                    objects.append(Resp(x * 16, y * 16))
                elif tile == ',':
                    objects.append(
                        Wall(
                            x * 16, y * 16,
                            pygame.image.load(
                                'img/rocket_piece1.png').convert_alpha(),
                            "rocket"))
                elif tile == '<':
                    objects.append(
                        Wall(
                            x * 16, y * 16,
                            pygame.image.load(
                                'img/rocket_piece2.png').convert_alpha(),
                            "rocket"))
                elif tile == '.':
                    objects.append(
                        Wall(
                            x * 16, y * 16,
                            pygame.image.load(
                                'img/rocket_piece3.png').convert_alpha(),
                            "rocket"))
                elif tile == '>':
                    objects.append(
                        Wall(
                            x * 16, y * 16,
                            pygame.image.load(
                                'img/rocket_piece4.png').convert_alpha(),
                            "rocket"))
                elif tile == ';':
                    objects.append(
                        Wall(
                            x * 16, y * 16,
                            pygame.image.load(
                                'img/rocket_piece5.png').convert_alpha(),
                            "rocket"))
                elif tile == ':':
                    objects.append(
                        Wall(
                            x * 16, y * 16,
                            pygame.image.load(
                                'img/rocket_piece6.png').convert_alpha(),
                            "rocket"))
                elif tile == '?':
                    objects.append(Trellis_rainbow1(x * 16, y * 16))
                elif tile == '/':
                    objects.append(Trellis_rainbow2(x * 16, y * 16))

        return objects
示例#17
0
import json
from random import randint

from numpy.core.umath import sign

from classes.client import Client, clamp
from classes.inventory import Inventory
from common.listtools import find, index
from common.vec import Vec2d

_RESOURCES_NEEDED = [
    Inventory([0, 1, 0, 0, 0, 0, 0, 1]),
    Inventory([0, 1, 1, 1, 0, 0, 0, 2]),
    Inventory([0, 2, 0, 1, 0, 2, 0, 2]),
    Inventory([0, 1, 1, 2, 0, 1, 0, 4]),
    Inventory([0, 1, 2, 1, 3, 0, 0, 4]),
    Inventory([0, 1, 2, 3, 0, 1, 0, 6]),
    Inventory([0, 2, 2, 2, 2, 2, 1, 6])
]


class PlayerDesc:
    score: float
    origin: int
    level: int
    inventory: Inventory

    def __init__(self,
                 score: float = 0,
                 origin: int = 0,
                 level: int = 0,