Beispiel #1
0
 def update(self,t):
     Fighter.update(self,t)
     """
     if self.anime is 'jump':
         if self.state.done:
             self.change('stay',t)
             self.force((0,0))
     """
     if self.anime is 'punk':
         if self.state.done:
             self.change('stay',t)
             self.force((0,0))
Beispiel #2
0
    def __init__(self):
        # Initialization
        libtcodpy.console_set_custom_font('src/arial10x10.png', libtcodpy.FONT_TYPE_GREYSCALE | libtcodpy.FONT_LAYOUT_TCOD)
        libtcodpy.console_init_root(settings.SCREEN_WIDTH, settings.SCREEN_HEIGHT, 'ROGuelike TUTorial', False)
        libtcodpy.sys_set_fps(settings.LIMIT_FPS)
        self.con = libtcodpy.console_new(settings.SCREEN_WIDTH, settings.SCREEN_HEIGHT)

        self.game_map = GameMap(self.con)
        player_x, player_y = self.game_map.get_staring_position()
        # game objects
        self.player = Player(
            'Player',
            self.con,
            player_x, player_y, '@',
            fighter=Fighter(hp=15, defense=5, power=5, death_function=player_death))

        npc_x, npc_y = self.game_map.get_ending_position()
        self.npc = Npc('Trader', self.con, npc_x, npc_y, '@')
        self.objects = [self.npc, self.player]

        self.npcs = [self.npc]
        for monster in self.game_map.place_monsters():
            self.objects.append(monster)

            if hasattr(monster, 'is_selfmoving') and monster.is_selfmoving:
                self.npcs.append(monster)

        self.game_state = 'playing'
        self.player_action = None
Beispiel #3
0
    def place_monsters(self):
        for room in self._rooms:
            #choose random number of monsters
            num_monsters = libtcodpy.random_get_int(0, 0,
                                                    settings.MAX_ROOM_MONSTERS)

            for i in range(num_monsters):
                #choose random spot for this monster
                x = libtcodpy.random_get_int(0, room.x1, room.x2)
                y = libtcodpy.random_get_int(0, room.y1, room.y2)

                if libtcodpy.random_get_int(
                        0, 0, 100) < 80:  #80% chance of getting an orc
                    #create an orc
                    monster = Orc('Uguk',
                                  self.con,
                                  x,
                                  y,
                                  'o',
                                  fighter=Fighter(
                                      hp=10,
                                      defense=0,
                                      power=3,
                                      death_function=monster_death),
                                  ai=SelfMovingBasicMonster())
                else:
                    #create a troll
                    monster = Troll('Ogg',
                                    self.con,
                                    x,
                                    y,
                                    'T',
                                    fighter=Fighter(
                                        hp=20,
                                        defense=5,
                                        power=7,
                                        death_function=monster_death),
                                    ai=ImmovableBasicMonster())

                yield monster
Beispiel #4
0
def gen_monster_troll(coords):

    x, y = coords

    fighter_comp = Fighter(hp=16,
                           defense=1,
                           power=4,
                           death_function=gf.monster_death)

    ai_comp = BasicMonster()

    monster = GameObject(g.settings,
                         "Troll",
                         x,
                         y,
                         color=colors.darker_green,
                         blocks=True,
                         fighter=fighter_comp,
                         ai=ai_comp,
                         img=r.troll)

    return monster
Beispiel #5
0
def gen_monster_zombie(coords):

    x, y = coords

    fighter_comp = Fighter(hp=10,
                           defense=0,
                           power=3,
                           death_function=gf.monster_death)

    ai_comp = BasicMonster()

    monster = GameObject(g.settings,
                         "Zombie",
                         x,
                         y,
                         color=colors.darker_violet,
                         blocks=True,
                         fighter=fighter_comp,
                         ai=ai_comp,
                         img=r.zombie)

    return monster
Beispiel #6
0
 def __init__(self,location):
     Fighter.__init__(self,999,location,) 
     self._animation = 'stay'
     for key, val in HULK_IMAGE_DATA.items():
         self.animations[key] = Animation(**val)
Beispiel #7
0
def run_game():
    #Initialize game and create a screen object.
    pygame.init()
    settings = Settings()
    g.settings = Settings()

    g.settings_g = Settings()

    pygame.display.set_caption(settings.title)

    # Initialize Map
    grid = Grid(settings)
    g.tiles = Group()

    # Map Matrix initialisieren und Tiles hinzufügen
    tiles_init(settings, g.tiles)

    #Player
    fighter_comp = Fighter(hp=30,
                           defense=2,
                           power=5,
                           death_function=gf.player_death)
    g.player = GameObject(settings,
                          "player",
                          1,
                          1,
                          colors.gold,
                          img=r.player,
                          blocks=True,
                          fighter=fighter_comp)

    # Create Random Map
    make_map()

    # Initialize GUI and Inventory
    g.gui_elements = GUI(settings)
    g.inventory_menu = InventoryMenu(settings)

    #Print Welcome Message
    print_message("Welcome to the BEIDL", colors.black, colors.dark_red)

    #Initialize groups
    g.monster_group = Group()
    g.item_group = Group()
    g.dead_group = Group()
    g.inventory = Group()
    g.graphics_group = Group()
    """F**K AROUND"""
    #vvvvvvvvvvv#

    for i in range(10):
        testi_place_objects('item')

    for i in range(50):
        testi_place_objects('enemy')

    # """Test: Dummy Walls"""
    # g.map_matrix[4][5].blocked = True
    # g.map_matrix[4][5].block_sight = True
    # g.map_matrix[4][6].blocked = True
    # g.map_matrix[4][6].block_sight = True
    #
    # g.map_matrix[15][21].blocked = True
    # g.map_matrix[15][21].block_sight = True
    # g.map_matrix[16][21].blocked = True
    # g.map_matrix[16][21].block_sight = True

    #^^^^^^^^^#
    """F**K AROUND"""

    # Start the main loop for the game.
    while True:
        """MENU"""
        # Menu Screen
        #while settings.game_state == "menu":
        #gf.check_events_menu(settings, all_groups)
        #gf.update_screen_menu(settings, all_groups)
        """GAME"""
        #while g.game_state == "playing":
        while True:

            g.clock.tick(FPS)
            # ticks = pygame.time.get_ticks()

            gf.update_screen(settings)

            # Check game_state for Contol Setup
            # TODO game state control handling like this?
            if g.game_state == 'inventory':
                player_action = gf.controls_inventory(settings)
            else:
                player_action = gf.controls(settings, g.player)

            # Let Enemys take turns
            if g.game_state == 'playing' and player_action != "noturn":
                for obj in g.monster_group:
                    if obj.ai:
                        obj.ai.take_turn()

            # TODO Turn for using inventory item, redundant, use in game state?
            if player_action == "turn":
                for obj in g.monster_group:
                    if obj.ai:
                        obj.ai.take_turn()
Beispiel #8
0
def main():
    if not pygame.font:
        print('Warning, fonts disabled')
        return
    if not pygame.mixer:
        print('Warning, sound disabled')

    pygame.font.init()
    music = pygame.mixer.music

    if config.music:
        try:
            music.load(os.path.join('data', 'music.ogg'))
        except:
            print('No music')
            config.music = False

    pygame.init()
    screen = pygame.display.set_mode(config.size)
    pygame.display.set_caption('SpaceFight')
    pygame.mouse.set_visible(0)

    background = pygame.image.load(
        os.path.join('data', 'background.png')).convert()

    screen.blit(background, (0, 0))
    pygame.display.flip()

    clock = pygame.time.Clock()
    lastCast = pygame.time.get_ticks()
    lastPowerUp = pygame.time.get_ticks()
    enemies = pygame.sprite.RenderPlain(Ufo())
    fighter = Fighter(enemies)
    fighterGroup = pygame.sprite.RenderPlain(fighter)
    powerups = pygame.sprite.RenderPlain(choice(config.powerups)(fighter))

    if config.music:
        music.set_volume(0.8)
        music.play(-1)

    while 1:
        clock.tick(50)

        for event in pygame.event.get():
            if event.type == QUIT:
                return
            elif event.type == KEYDOWN:
                if event.key == K_ESCAPE or event.key == K_q:
                    return
                #######################################################
                #                         DEBUG                       #
                #######################################################
                elif event.key == K_s:
                    enemies.add(Ufo())
                    lastCast = pygame.time.get_ticks()
                elif event.key == K_p:
                    powerups.add(choice(config.powerups)(fighter))
                    lastPowerUp = pygame.time.get_ticks()
                #######################################################
                elif event.key == K_SPACE:
                    fighter.shotType = fighter.shootRocket
                    fighter.shooting = True
                elif event.key == K_c:
                    fighter.shotType = fighter.shootSuperChicken
                    fighter.shooting = True
                elif event.key == K_UP or event.key == K_l:
                    fighter.shotType = fighter.shootLaser
                    fighter.shooting = True
                elif event.key == K_RIGHT:
                    fighter.dx = min(fighter.speed, fighter.maxspeed)
                elif event.key == K_LEFT:
                    fighter.dx = -min(fighter.speed, fighter.maxspeed)
                elif event.key == K_f:
                    pygame.display.toggle_fullscreen()
            elif event.type == KEYUP:
                if event.key == K_RIGHT and fighter.dx > 0:
                    fighter.dx = 0
                elif event.key == K_LEFT and fighter.dx < 0:
                    fighter.dx = 0
                elif event.key == K_SPACE and fighter.shotType == fighter.shootRocket:
                    fighter.shooting = False
                elif (event.key == K_UP or event.key == K_l) and fighter.shotType == fighter.shootLaser:
                    fighter.shooting = False
                elif event.key == K_c and fighter.shotType == fighter.shootSuperChicken:
                    fighter.shooting = False


        if pygame.time.get_ticks() - lastCast >= config.levels[stats.level['level']]['spawnSpeed'] and stats.level['spawned'] < config.levels[stats.level['level']]['spawns']:
            enemies.add(Ufo())
            lastCast = pygame.time.get_ticks()
            stats.level['spawned'] += 1

        if pygame.time.get_ticks() - lastPowerUp >= config.levels[stats.level['level']]['powerUpSpeed']:
            powerups.add(choice(config.powerups)(fighter))
            lastPowerUp = pygame.time.get_ticks()

        if stats.level['spawned'] == config.levels[stats.level['level']]['spawns']:
            # spawn endboss
            pass


        screen.blit(background, (0, 0))
        stats.update()
        fighterGroup.update()
        fighterGroup.draw(screen)
        powerups.update()
        powerups.draw(screen)
        enemies.update()
        enemies.draw(screen)
        pygame.display.flip()