예제 #1
0
파일: pysnake.py 프로젝트: dbrizov/PySnake
 def tick(self, deltaTime):
     Entity.tick(self, deltaTime)
     self._passedDistance += self._speed * deltaTime
     if (self._passedDistance > 1.0):
         self._passedDistance -= 1.0
         self.move_Internal()
         self.hangleCollisions_Internal()
예제 #2
0
파일: player.py 프로젝트: ehouse/Bunbunmaru
	def __init__( self, lives, score, bulletMan, maxSpeed, sprite, viewBox, bulletSprite, bulletBox ):
		# position vars
		self.SPAWN_X = 300
		self.SPAWN_Y = 600
		self.xpos = self.SPAWN_X
		self.ypos = self.SPAWN_Y
		Entity.__init__( self, 400 , 300, sprite, Rect( self.xpos - 10,
							self.ypos - 10, self.xpos + 54, self.ypos + 54 ) )

		# movement vars
		self._maxSpeed = maxSpeed
		self._focusedSpeed = maxSpeed /  2.0
		self._xSpeed = 0
		self._ySpeed = 0

		# Game vars
		self.lives = lives
		self.score = score
		self.invincible = False
		self._invincibilityTime = 5000
		self._bulletMan = bulletMan
		self._FIRE_COOL_MAX = 10
		self._fireCoolDown = 0

		# sprite vars
		self._itemBox = Rect( self.xpos, self.ypos, self.xpos + 64,
									self.ypos + 64 )
		self._viewBox = viewBox
		self._bulletSprite = bulletSprite
		self._bulletBox = bulletBox
예제 #3
0
    def __init__(self, pos=(0, 0), zoom=0.25):
        #possible inheritance fail
        Vec2.__init__(self, pos[0], pos[1])
        Entity.__init__(self)

        self.zoom = zoom
        self.shift = Vec2(0, 0)
예제 #4
0
파일: pysnake.py 프로젝트: dbrizov/PySnake
 def init(self):
     Entity.init(self)
     for row in range(self._rows):
         for col in range(self._cols):
             cellType = self._cellMatrix[row][col]
             cellEntity = EntitySpawner.spawnEntity(CellEntity, self, Vector2(row, col), cellType)
             cellEntity.getTransform().position = Vector2(col * CELL_SIZE.x, row * CELL_SIZE.y)
             self._cells.append(cellEntity)
예제 #5
0
파일: pysnake.py 프로젝트: dbrizov/PySnake
    def init(self):
        Entity.init(self)
        self._renderComponent = self.addComponent(
            SnakeRenderComponent(Screen.getSize(), CELL_SIZE, CELL_BORDER_WIDTH, Color.RED, Color.BLACK))

        self._inputComponent = self.addComponent(InputComponent())
        self._inputComponent.bindAction("left", InputEvent.EVENT_TYPE_PRESSED, lambda: self.changeDirection(DIRECTION_LEFT))
        self._inputComponent.bindAction("right", InputEvent.EVENT_TYPE_PRESSED, lambda: self.changeDirection(DIRECTION_RIGHT))
        self._inputComponent.bindAction("up", InputEvent.EVENT_TYPE_PRESSED, lambda: self.changeDirection(DIRECTION_UP))
        self._inputComponent.bindAction("down", InputEvent.EVENT_TYPE_PRESSED, lambda: self.changeDirection(DIRECTION_DOWN))
예제 #6
0
파일: pysnake.py 프로젝트: dbrizov/PySnake
    def __init__(self, board, speed, initialSize, initialHeadPos, initialDir, priority=0, initialComponents=None):
        Entity.__init__(self, priority, initialComponents)
        self._board = board
        self._headPos = initialHeadPos
        self._dir = initialDir
        self._deque = deque()
        for i in range(initialSize):
            self._deque.appendleft(initialHeadPos - initialDir * i)

        self._speed = speed
        self._passedDistance = 0.0
        self._dirQueue = deque()
        self._ateFood = False
        self.onFoodEaten = EventHook()
        self.onDeath = EventHook()
예제 #7
0
파일: enemy.py 프로젝트: ehouse/Bunbunmaru
	def __init__( self, xpos, ypos, speed, hp, sprite, hitbox ):
		Entity.__init__( self, xpos, ypos, sprite, hitbox )
		# movement vars
		self._speedx = 0
		self._speedy = 0
		self._curAngle = 270
		#self._maxspeed = speed
		self._maxspeed = 2

		# game vars
		self.destroyed = False
		self.hit = False
		self.hp = hp
		self.heat = 0
		self._actcode = 0

		self._hitbox.move_ip( xpos, ypos )
예제 #8
0
 def add_entity(self):
     entity_name = str(self.entity_name_field.text())
     new_entity = Entity(entity_name)
     new_entity_wrapper = Component(new_entity, entity_name)
     widget_component = WidgetItemComponent(entity_name, new_entity_wrapper)
     self.entity_list_view.addItem(widget_component)
     self.context['entities'][entity_name] = dict()
     self.context['entities'][entity_name]['entity'] = new_entity
     self.context['entities'][entity_name]['components'] = defaultdict(list)
예제 #9
0
파일: pysnake.py 프로젝트: dbrizov/PySnake
    def init(self):
        Entity.init(self)
        self._inputComponent = self.addComponent(InputComponent())
        self._inputComponent.bindAction("submit", InputEvent.EVENT_TYPE_PRESSED, self.restart)
        self._inputComponent.bindAction("cancel", InputEvent.EVENT_TYPE_PRESSED, self.quit)
        self._inputComponent.bindAction("pause", InputEvent.EVENT_TYPE_PRESSED, self.togglePaused)

        self._backgroundEntity = EntitySpawner.spawnEntity(Entity)
        self._backgroundEntity.addComponent(RectRenderComponent(Screen.getSize(), Screen.getSize(), Color.BLACK))

        self._boardEntity = EntitySpawner.spawnEntity(BoardEntity, CELL_MATRIX)

        self._snakeEntity = EntitySpawner.spawnEntity(SnakeEntity, self._boardEntity, 5, 3, Vector2(3, 3), DIRECTION_RIGHT)
        self._snakeEntity.onFoodEaten += lambda: self.spawnFood()
        self._snakeEntity.onFoodEaten += lambda: self.setScore(self._score + 1)
        self._snakeEntity.onFoodEaten += lambda: self.increaseSnakeSpeed()
        self._snakeEntity.onDeath += lambda: self.setGameOver(True)
        self.spawnFood()

        self._pausedTextEntity = self.createTextEntity("PAUSED")
        pausedTextRectSize = self._pausedTextEntity.getComponent(TextRenderComponent).getRectSize()
        boardRectSize = Vector2(self._boardEntity.getCols() * CELL_SIZE.x, self._boardEntity.getRows() * CELL_SIZE.y)
        self._pausedTextEntity.getTransform().position = Vector2((boardRectSize.x - pausedTextRectSize.x) // 2,
                                                                 (boardRectSize.y - pausedTextRectSize.y) // 2)

        self._gameOverTextEntity = self.createTextEntity("GAME OVER")
        gameOverTextRectSize = self._gameOverTextEntity.getComponent(TextRenderComponent).getRectSize()
        self._gameOverTextEntity.getTransform().position = Vector2((boardRectSize.x - gameOverTextRectSize.x) // 2,
                                                                   (boardRectSize.y - gameOverTextRectSize.y) // 2)

        self._scoreTextEntity = self.createTextEntity("SCORE:0")
        self._scoreTextEntity.getTransform().position = Vector2(0, boardRectSize.y)

        self._score = 0
        self._gameOver = False
        self.setGameOver(self._gameOver)
        self._paused = True
        self.setPaused(self._paused)
예제 #10
0
    def __init__(self):
        self.map_width = 80
        self.map_height = 45
        self.game_map = GameMap(self.map_width, self.map_height)

        self.player = Hero(int(self.map_width / 2), int(self.map_height / 2),
                           '@', 'player')
        self.entities = [self.player]
        self.entities.append(
            Entity(int(self.map_width / 2 - 5), int(self.map_height / 2), '@',
                   'npc'))
        self.current_entity = 0

        self.energy_threshold = 5
예제 #11
0
def get_game_variables(constant_variables):
    fighter_component = Fighter(hp=100,
                                armor_class=3,
                                strength=10,
                                intelligence=10)
    inventory_component = Inventory(26)
    grimoire_component = Grimoire(5)
    equipment_component = Equipment()
    player = Entity(0,
                    0,
                    '@',
                    libtcod.red,
                    'Player',
                    blocks=True,
                    render_order=RenderOrder.ACTOR,
                    fighter=fighter_component,
                    inventory=inventory_component,
                    grimoire=grimoire_component,
                    equipment=equipment_component)
    spell = Spell(name='Fireball',
                  cast_function=fireball,
                  damage=10,
                  targeting=True,
                  targeting_message=Message('click to target'),
                  radius=3,
                  cost=10)
    player.grimoire.add_spell(spell)
    entities = [player]

    # Initializes map
    game_map = Map(constant_variables['map_width'],
                   constant_variables['map_height'])
    game_map.make_BSP_map(player, entities, constant_variables['map_width'],
                          constant_variables['map_height'])
    # Initializes other game variables
    game_state = GameStates.PLAYERS_TURN
    message_log = MessageLog(constant_variables['message_x'],
                             constant_variables['message_width'],
                             constant_variables['message_height'])

    return player, entities, game_map, game_state, message_log
예제 #12
0
파일: pysnake.py 프로젝트: dbrizov/PySnake
 def init(self):
     Entity.init(self)
     if (self._type == CELL_TYPE_EMPTY):
         self.addComponent(CellRenderComponent(CELL_SIZE, CELL_SIZE, CELL_BORDER_WIDTH, Color(25, 25, 25), Color.BLACK))
     if (self._type == CELL_TYPE_BLOCK):
         self.addComponent(CellRenderComponent(CELL_SIZE, CELL_SIZE, CELL_BORDER_WIDTH, Color.BLUE, Color.BLACK))
예제 #13
0
파일: pysnake.py 프로젝트: dbrizov/PySnake
 def __init__(self, board, pos, priority=0, initialComponents=None):
     Entity.__init__(self, priority, initialComponents)
     self._board = board
     self._pos = pos
     self.setPos(self._pos)
     self._board.getCell(self._pos.x, self._pos.y).food = self
예제 #14
0
    def create_BSP_rooms(self, player, tree, entities):
        """Creates rooms from BSP leafs"""
        room_centers = []
        for node in tree.pre_order():
            # random height and width for rooms
            rand_width = randint(node.x + 4, (node.x + node.width - 1))
            rand_height = randint(node.y + 4, (node.y + node.height - 1))

            node.width = rand_width
            node.height = rand_height

            if not node.children:
                # creates rooms
                # adds center of node to be used for hallway mining
                center_x = int((rand_width + node.x) / 2)
                center_y = int((rand_height + node.y) / 2)
                room_centers.append([center_x, center_y])
                for x in range(node.x, node.width):
                    for y in range(node.y, node.height):
                        #if self.node_area_check(rand_height, rand_width, 10):  #Check if this is needed after we get the random room sizes working
                        self.tiles[x][y].block_sight = False
                        self.tiles[x][y].blocked = False

        for i in range(len(room_centers)):
            if i == 0:
                player.x, player.y = room_centers[i]
                # Spawning flavor text obelisk next to player
                obelisk_fight_comp = Fighter(hp=9999, armor_class=9999)
                start_obelisk = Entity(player.x - 1,
                                       player.y,
                                       ')',
                                       libtcod.gold,
                                       'Obelisk of the Start',
                                       blocks=True,
                                       render_order=RenderOrder.ACTOR,
                                       fighter=obelisk_fight_comp,
                                       ai=WordBlock())
                entities.append(start_obelisk)

            # Spawns stairs in a random room center
            s = randint(1, len(room_centers))
            if s == i:
                s_center_x, s_center_y = room_centers[s]
                stairs_component = Stairs(self.dungeon_level + 1)
                down_stairs = Entity(s_center_x,
                                     s_center_y,
                                     '>',
                                     libtcod.red,
                                     'Stairs',
                                     render_order=RenderOrder.STAIRS,
                                     stairs=stairs_component)
                entities.append(down_stairs)

            x1, y1 = room_centers[i - 1]
            x2, y2 = room_centers[i]

            # Makes rooms visible and walk through able
            for x in range(min(x1, x2), max(x1, x2) + 1):
                self.tiles[x][y1].block_sight = False
                self.tiles[x][y1].blocked = False
            for y in range(min(y1, y2), max(y1, y2) + 1):
                self.tiles[max(x1, x2)][y].block_sight = False
                self.tiles[max(x1, x2)][y].blocked = False
예제 #15
0
    def place_bsp_entities(self, node, entities):
        """Handles monster gen"""
        max_monsters_per_room = from_dungeon_level([[5, 1], [7, 4], [9, 6]],
                                                   self.dungeon_level)
        max_items_per_room = from_dungeon_level([[1, 1], [2, 4]],
                                                self.dungeon_level)
        number_of_monsters = randint(
            0, max_monsters_per_room)  # Gets rand num of spoopy monsters
        max_objects_per_room = from_dungeon_level([[1, 1]], self.dungeon_level)
        number_of_objects = randint(0, max_objects_per_room)

        # Tables for spawn chances
        monster_chances = {
            'ashlee':
            from_dungeon_level([[1, 1]], self.dungeon_level),
            'orc':
            from_dungeon_level([[15, 1], [35, 3], [65, 5]],
                               self.dungeon_level),
            'goblin':
            from_dungeon_level([[60, 1], [40, 3], [20, 5]],
                               self.dungeon_level),
            'troll':
            from_dungeon_level([[30, 3], [40, 5]], self.dungeon_level)
        }

        item_chances = {
            'healing_potion': from_dungeon_level([[25, 1]],
                                                 self.dungeon_level),
            #'lighting_scroll': from_dungeon_level([[25, 3]], self.dungeon_level),
            #'fireball_scroll': from_dungeon_level([[25, 2]], self.dungeon_level),
            'wand': from_dungeon_level([[20, 1]], self.dungeon_level),
            'wooden_club': from_dungeon_level([[20, 1]], self.dungeon_level),
            'simple_robes': from_dungeon_level([[90, 1]], self.dungeon_level),
            'vine_mail': from_dungeon_level([[90, 1]], self.dungeon_level)
        }

        object_chances = {
            'grimoire': from_dungeon_level([[10, 4]], self.dungeon_level),
            'word_chunk': from_dungeon_level([[5, 1]], self.dungeon_level)
        }

        for i in range(number_of_objects):
            # Choose random location in the room
            x = randint(node.x + 1, node.width - 1)
            y = randint(node.y + 1, node.height - 1)

            if not any([
                    entity
                    for entity in entities if entity.x == x and entity.y == y
            ]):
                # Choose objects randomly
                object_choice = random_choice_from_dict(object_chances)
                if object_choice == 'word_chunk':
                    obelisk_fight_comp = Fighter(hp=9999, armor_class=9999)
                    world_object = Entity(x,
                                          y,
                                          ')',
                                          libtcod.gold,
                                          'Obelisk',
                                          blocks=True,
                                          render_order=RenderOrder.ACTOR,
                                          fighter=obelisk_fight_comp,
                                          ai=WordBlock())

                if object_choice == 'grimoire':
                    world_obj_comp = Item(use_function=spell_tome)
                    world_object = Entity(x,
                                          y,
                                          '$',
                                          libtcod.dark_flame,
                                          'spell_tome',
                                          render_order=RenderOrder.ITEM,
                                          item=world_obj_comp,
                                          interactable=True)

                try:
                    entities.append(world_object)
                except UnboundLocalError:
                    pass

        for i in range(number_of_monsters):
            # Choose random location in the room
            x = randint(node.x + 1, node.width - 1)
            y = randint(node.y + 1, node.height - 1)

            if not any([
                    entity
                    for entity in entities if entity.x == x and entity.y == y
            ]):
                # Choose monsters randomly
                monster_choice = random_choice_from_dict(monster_chances)

                if monster_choice == 'ashlee':
                    monster_fight_comp = Fighter(hp=10,
                                                 armor_class=7,
                                                 strength=12)
                    monster = Entity(x,
                                     y,
                                     'A',
                                     libtcod.purple,
                                     "Ashlee",
                                     blocks=True,
                                     fighter=monster_fight_comp,
                                     render_order=RenderOrder.ACTOR,
                                     ai=BasicMonster())

                elif monster_choice == 'orc':
                    monster_fight_comp = Fighter(hp=15,
                                                 armor_class=6,
                                                 strength=10)
                    monster = Entity(x,
                                     y,
                                     'O',
                                     libtcod.darkest_green,
                                     "Orc",
                                     blocks=True,
                                     fighter=monster_fight_comp,
                                     render_order=RenderOrder.ACTOR,
                                     ai=BasicMonster())

                elif monster_choice == 'goblin':
                    monster_fight_comp = Fighter(hp=7,
                                                 armor_class=4,
                                                 strength=4)
                    monster = Entity(x,
                                     y,
                                     'G',
                                     libtcod.dark_green,
                                     "Goblin",
                                     blocks=True,
                                     fighter=monster_fight_comp,
                                     render_order=RenderOrder.ACTOR,
                                     ai=BasicMonster())

                elif monster_choice == 'troll':
                    monster_fight_comp = Fighter(hp=20,
                                                 armor_class=8,
                                                 strength=16)
                    monster = Entity(x,
                                     y,
                                     'T',
                                     libtcod.dark_green,
                                     "Troll",
                                     blocks=True,
                                     fighter=monster_fight_comp,
                                     render_order=RenderOrder.ACTOR,
                                     ai=BasicMonster())

                try:
                    entities.append(monster)
                except UnboundLocalError:
                    pass

        # Handles item gen
        number_of_items = randint(0, max_items_per_room)

        for i in range(number_of_items):
            x = randint(node.x + 1, node.width - 1)
            y = randint(node.y + 1, node.height - 1)

            if not any([
                    entity
                    for entity in entities if entity.x == x and entity.y == y
            ]):
                item_choice = random_choice_from_dict(item_chances)
                if item_choice == 'healing_potion':
                    item_component = Item(use_function=heal, amount=15)
                    item = Entity(x,
                                  y,
                                  '!',
                                  libtcod.violet,
                                  'Healing Potion',
                                  render_order=RenderOrder.ITEM,
                                  item=item_component)

                elif item_choice == 'wooden_club':
                    equippable_component = Equippable(EquipmentSlots.MAIN_HAND,
                                                      strength_bonus=3)
                    item = Entity(x,
                                  y,
                                  '\\',
                                  libtcod.brass,
                                  'Wooden Club',
                                  render_order=RenderOrder.ITEM,
                                  equippable=equippable_component)
                elif item_choice == 'wand':
                    equippable_component = Equippable(EquipmentSlots.MAIN_HAND,
                                                      intelligence_bonus=3)
                    item = Entity(x,
                                  y,
                                  '/',
                                  libtcod.red,
                                  'Wand',
                                  equippable=equippable_component)

                elif item_choice == 'simple_robes':
                    equippable_component = Equippable(EquipmentSlots.BODY,
                                                      intelligence_bonus=3,
                                                      armor_bonus=1)
                    item = Entity(x,
                                  y,
                                  '#',
                                  libtcod.purple,
                                  'Simple Robes',
                                  equippable=equippable_component)

                elif item_choice == 'vine_mail':
                    equippable_component = Equippable(EquipmentSlots.BODY,
                                                      strength_bonus=3,
                                                      armor_bonus=3)
                    item = Entity(x,
                                  y,
                                  '#',
                                  libtcod.dark_green,
                                  'Vine Mail',
                                  render_order=RenderOrder.ITEM,
                                  equippable=equippable_component)

                try:
                    entities.append(item)
                except UnboundLocalError:
                    pass
예제 #16
0
파일: pysnake.py 프로젝트: dbrizov/PySnake
 def init(self):
     Entity.init(self)
     self._renderComponent = self.addComponent(
         CellRenderComponent(CELL_SIZE, CELL_SIZE, CELL_BORDER_WIDTH, Color.GREEN, Color.BLACK))
예제 #17
0
 def testCreateGoblin(self):
     e = Entity(EntityLibrary().getEntity('goblin'), 'The Force')
     self.assertTrue(e.getMaxHP() >= 2 and e.getMaxHP() <= 12)
예제 #18
0
파일: pysnake.py 프로젝트: dbrizov/PySnake
 def __init__(self, board, pos, type, priority=0, initialComponents=None):
     Entity.__init__(self, priority, initialComponents)
     self._board = weakref.ref(board)
     self._pos = pos
     self._type = type
     self.food = None
예제 #19
0
파일: bullet.py 프로젝트: ehouse/Bunbunmaru
	def __init__ ( self, xpos, ypos, speed, damageValue, sprite, hitbox ):
		Entity.__init__( self, xpos, ypos, sprite, hitbox )
		self._speed = speed
		self.damageValue = damageValue
		self.destroyed = False
예제 #20
0
파일: pysnake.py 프로젝트: dbrizov/PySnake
 def __init__(self, cellMatrix, priority=0, initialComponents=None):
     Entity.__init__(self, priority, initialComponents)
     self._cellMatrix = cellMatrix
     self._rows = len(self._cellMatrix)
     self._cols = len(self._cellMatrix[0])
     self._cells = list()