Exemplo n.º 1
0
    def players_sprite_init(self):
        self.playlist = arcade.SpriteList()

        self.player1 = Player(3, 4, self.health)
        self.playlist.append(self.player1)

        self.player2 = Player(5, 3, self.health)
        self.playlist.append(self.player2)
Exemplo n.º 2
0
 def data_process(self, line, y):
     for x in range(len(line)):
         if line[x] == rep["player"]: self.player = Player(x=x, y=y)
         if line[x] == rep["door"]: self.doors.append(Door(x=x, y=y))
         if line[x] == rep["box"]: self.boxes.append(Box(x=x, y=y))
         if line[x] == rep["wall"]: self.walls.append(Wall(x=x, y=y))
         if line[x] == rep["ground"]: self.grounds.append(Ground(x=x, y=y))
Exemplo n.º 3
0
    def __init__(self, level_file, level_width, level_height):
        '''
        Constructor
        '''
        self.platform_list = []
        self.player = None
        self.mobile_sprites = []

        with open(level_file) as file:
            self._level = file.readlines()

        self._width_scale = level_width / _get_longest_line_len(self._level)
        self._height_scale = level_height / len(self._level)

        for line_num in range(len(self._level)):
            for col_num in range(len(self._level[line_num])):
                if self._level[line_num][col_num] == "P":
                    self._add_platform(line_num, col_num)

                elif self._level[line_num][col_num] == "p":
                    x = col_num * self._width_scale
                    y = line_num * self._height_scale
                    self.player = Player(x, y)

                elif self._level[line_num][col_num] == "O":
                    self._add_power_up(line_num, col_num, PowerUpColors.ORANGE)

                elif self._level[line_num][col_num] == "s":
                    self._add_enemy(line_num, col_num, SimpleEnemy)
Exemplo n.º 4
0
 def new_game(self):
     self.all_sprites = pg.sprite.LayeredUpdates()
     self.enemys = pg.sprite.Group()
     self.players = pg.sprite.Group()
     self.buffs = pg.sprite.Group()
     self.player = Player(self)
     self.run()
Exemplo n.º 5
0
    def start(self):
        pg.display.set_caption("Demo")

        self.player = Player(self, 16 * self.tile_size, 8 * self.tile_size)
        self.camera.set_focus(self.player)

        self.kill_depth = max([p.rect.bottom
                               for p in self.static_bodies]) + 200
        print(self.kill_depth)
Exemplo n.º 6
0
    def start(self, origin):
        self.__init__(self.game)
        pg.display.set_caption("Combat Test")

        self.player = Player(self, self.screen.get_width() // 2, 600)
        self.camera.set_focus(self.player)

        for edge in self.edges:
            edge.player = self.player
        for sprite in self.rigid_bodies:
            if isinstance(sprite, Mob):
                sprite.set_target(self.player)
Exemplo n.º 7
0
    def load(self):
        self.all_sprites = pg.sprite.Group()
        self.solid = pg.sprite.Group()
        self.items_on_floor = pg.sprite.Group()
        self.doors = pg.sprite.Group()

        assets_folder = path.join(getcwd(), 'assets')
        self.map = Map(path.join(assets_folder, 'maps/map1.json'))

        self.spritesheet = Spritesheet(
            path.join(assets_folder, 'spritesheet.png'), 32)
        wall_img = self.spritesheet.get_image_at_col_row(0, 0)
        apple_img = self.spritesheet.get_image_alpha_at_col_row(1, 0)
        keycard_img = self.spritesheet.get_image_alpha_at_col_row(0, 3)
        self.background_surface = pg.Surface(
            (self.map.width * TILE_SIZE, self.map.height * TILE_SIZE))

        self.visibility_data = [[True] * self.map.height
                                for i in range(self.map.width)]
        self.fov_data = [[True] * self.map.height
                         for i in range(self.map.width)]

        for node in self.map.objects:
            x, y = node['x'], node['y']
            if node["name"] == 'WALL':
                #self.collisions.append(pg.Rect(x, y, TILE_SIZE, TILE_SIZE))  # TODO big rectangles
                wall = Wall(self, x, y, wall_img)
                if not LIMIT_FOV_FOR_STATIC_SPRITES:
                    wall.remove(self.all_sprites)  # skip drawing
                    self.background_surface.blit(
                        wall_img, (x * TILE_SIZE, y * TILE_SIZE))
                self.visibility_data[x][y] = False
            elif node["name"] == 'PLAYER':
                self.player = Player(self, x, y)
            elif node["name"] == 'APPLE':
                item = Item(self, x, y, apple_img)
                item.pickable = Pickable(item, 'apple', False, 1, False)
            elif node["name"] == 'KEYCARD':  # key card
                item = Item(self, x, y, keycard_img)
                item.pickable = Pickable(item, 'keycard', False, 1, False)
            elif node["name"] == "DOOR":
                Door(self, x, y, node["dir"])
                self.visibility_data[x][
                    y] = False  # TODO opened doors visibility

        for trigger in self.map.triggers:
            TextTrigger(
                self,
                pg.Rect(trigger["x"], trigger["y"], trigger["width"],
                        trigger["height"]), trigger["text"])

        self.camera = Camera(self.map.width_screen, self.map.height_screen)
Exemplo n.º 8
0
    def new(self):
        """Create new game
        """

        self.all_sprites = pg.sprite.Group()  # 4
        self.score = 0  # 5
        self.pipes = pg.sprite.Group()  # 6
        self.player = Player()  # 7
        self.all_sprites.add(self.player)
        pipe = PipePair()
        self.all_sprites.add(pipe)
        self.pipes.add(pipe)
        self.last_pipe = pg.time.get_ticks()  # 8
        self.run()
Exemplo n.º 9
0
    def reset(self):
        if self.players_list:
            for player in self.players_list:
                if not player.visible:
                    continue
                if not self.points[player.tank_id]:
                    self.points[player.tank_id] = 1
                else:
                    self.points[player.tank_id] += 1

        # Load level
        self.level = Level()

        self.players_list = pygame.sprite.Group()
        self.walls_list = pygame.sprite.Group()
        self.path_list = pygame.sprite.Group()
        self.bullets_list = pygame.sprite.Group()
        self.power_up_list = pygame.sprite.Group()
        sprite_groups = {
            'players_list': self.players_list,
            'walls_list': self.walls_list,
            'path_list': self.path_list,
            'bullets_list': self.bullets_list,
            'power_up_list': self.power_up_list
        }

        self.walls_list.add(self.level.walls)
        # Players
        free_spot = self.level.get_free_spot(False)
        if free_spot:
            self.player1 = Player("red", *free_spot, sprite_groups, 0, "Mads")
            self.players_list.add(self.player1)
        free_spot = self.level.get_free_spot(False)
        if free_spot:
            self.player2 = Player("blue", *free_spot, sprite_groups, 1,
                                  "Kasper")
            self.players_list.add(self.player2)
Exemplo n.º 10
0
    def start(self):
        pg.display.set_caption("Demo")

        for i in range(10):
            Platform(self, i * 2000 + 550, 350, 2000, 32)
        Platform(self, 400, 200, 32, 500)
        Platform(self, 500, 200, 32, 500)

        a = Platform(self, 300, 100, 32, 32)
        b = Platform(self, 300, 132, 32, 32)
        c = Platform(self, 332, 132, 32, 32)
        d = Platform(self, 332, 100, 32, 32)
        e = a.compress_with(b, True, True)[0]
        f = c.compress_with(d, True, True)[0]
        e.compress_with(f, True, True)

        self.player = Player(self, 450, 0)
        self.camera_focus = self.player
Exemplo n.º 11
0
    def start(self, _):
        pg.display.set_caption("Combat Test")

        self.player = Player(self, self.screen.get_width() // 2, 300)

        for i in range(2):
            m = Mob(self, 2 * self.screen.get_width() // 3, 300 + i * 20)
            m.set_target(self.player)

            m = Mob(self, self.screen.get_width() // 3, 300 + i * 20)
            m.set_target(self.player)

            m = Mob(self, self.screen.get_width() * 1.5, 600 + i * 20)
            m.set_target(self.player)

        self.camera.set_focus(self.player)

        for edge in self.edges:
            edge.player = self.player
Exemplo n.º 12
0
 def new(self):
     self.score = 0
     self.level = 0
     self.pre_wave_begin = None
     self.sprites = pg.sprite.Group()  # all sprites
     self.player = pg.sprite.GroupSingle()
     self.mobs = MobGroup(self)  # spritegroup sub class
     self.bunkers = pg.sprite.Group()
     self.bullets = pg.sprite.Group()  # all bullets
     self.player_bullets = pg.sprite.Group()
     self.mob_bullets = pg.sprite.Group()
     Player(self)
     # spawn bunkers
     for i in range(4):
         spacing = WIDTH / 5
         offset = (WIDTH - (BUNKER_WIDTH * 4 +
                            (spacing - BUNKER_WIDTH) * 3)) / 2
         Bunker(self, i * spacing + offset, BUNKER_Y)
     self.run()
Exemplo n.º 13
0
    def new(self):
        # start a new game
        self.score = 0
        self.all_sprites = pg.sprite.Group()
        self.enemies = pg.sprite.Group()
        self.projectiles = pg.sprite.Group()
        self.allies = pg.sprite.Group()
        self.player = Player(self)
        self.alliesCreated = 0

        self.backgroundImg = pygame.image.load(path.join(IMG_DIR, 'background.png')).convert()
        self.gameoverImg = pygame.image.load(path.join(IMG_DIR, 'gameover.png')).convert()
        self.backgroundRect = self.backgroundImg.get_rect()

        #Create the enemies
        for i in range(ENEMIES):
            m = Enemy(self)
            self.all_sprites.add(m)
            self.enemies.add(m)

        self.run()
Exemplo n.º 14
0
    def load(self, map_name):
        """
        Loads new map with the given name
        :param map_name: map to be loaded
        :return: nothing
        """
        assets_folder = path.join(getcwd(), 'assets')
        self.__map__ = Map(path.join(assets_folder, 'maps/' + map_name + '.json'))

        self.spritesheet = Spritesheet(path.join(assets_folder, 'spritesheet.png'), 32)
        wall_img = self.spritesheet.get_image_at_row_col(0, 0)
        apple_img = self.spritesheet.get_image_alpha_at_row_col(1, 0)

        self.__visibility_data__ = [[True] * self.__map__.height for i in range(self.__map__.width)]
        self.__fov_data__ = [[True] * self.__map__.height for i in range(self.__map__.width)]

        for node in self.__map__.objects:
            x, y = node['x'], node['y']
            if node["name"] == 'WALL':
                Wall(self, x, y, wall_img)
                self.__visibility_data__[x][y] = False
            elif node["name"] == 'PLAYER':
                self.player = Player(self, x, y)
            elif node["name"] == 'APPLE':
                item = Item(self, x, y, apple_img)
                item.pickable = Pickable(item, 'apple', False, 1, False)
            elif node["name"] == "DOOR":
                Door(self, x, y, node["dir"])
                self.__visibility_data__[x][y] = False  # TODO opened doors visibility

        for trigger in self.__map__.triggers:
            TextTrigger(self,
                        pg.Rect(trigger["x"], trigger["y"], trigger["width"], trigger["height"]),
                        trigger["text"])

        self.__camera__ = Camera(self.__map__.width_screen, self.__map__.height_screen)
Exemplo n.º 15
0
Arquivo: map.py Projeto: chynes2/dnd
    def __init__(self, game, map_name):
        self.game = game
        self.npcs = set()

        game_folder = os.path.dirname('..')
        image_folder = os.path.join(game_folder, 'images', 'maps')
        with open(os.path.join(image_folder, map_name)) as f:
            map = f.readlines()
        for y, tiles in enumerate(map):
            for x, tile in enumerate(tiles):
                if tile == '1':
                    Wall(game, x, y)
                elif tile == 'P':
                    self.game.p1 = Player(self.game, x * tile_size,
                                          y * tile_size)
                    self.game.p1.rect.x += (tile_size -
                                            self.game.p1.rect.width) / 2
                elif tile == 'N':
                    self.npcs.add(NPC(self.game, x * tile_size, y * tile_size))

        self.tilewidth = len(map[0].strip())
        self.tileheight = len(map)
        self.width = self.tilewidth * tile_size
        self.height = self.tileheight * tile_size
Exemplo n.º 16
0
def main():
    """this function is called when the program starts.
       it initializes everything it needs, then runs in
       a loop until the function returns."""

    # Initialize Everything
    pg.mixer.init()
    pg.init()
    screen = pg.display.set_mode((screen_width, screen_height))
    pg.display.set_caption("Bullet Helln't")
    pg.mouse.set_visible(0)

    # Create The Background
    bg = pg.image.load("art/background/background.png")
    bg_offset = 0

    # Display The Background
    screen.blit(bg, (0, 0))
    # pg.display.flip()

    #
    pg.mixer.music.load('sound/music.wav')
    pg.mixer_music.play(-1)

    # Prepare Game Objects
    clock = pg.time.Clock()
    potion_list = []
    player = Player(screen_width, screen_height, potion_list)
    hud = HUD(player)
    inv = Inventory(player)

    invisible_top_wall = Wall(0, -35, screen_width, 10)
    invisible_bottom_wall = Wall(0, screen_height + 25, screen_width, 10)
    invisible_left_wall = Wall(-35, 0, 10, screen_height)
    invisible_right_wall = Wall(screen_width + 25, 0, 10, screen_height)
    top_wall = Wall(0, 0, screen_width, 10)
    bottom_wall = Wall(0, screen_height - 10, screen_width, 10)
    left_wall = Wall(0, 0, 10, screen_height)
    right_wall = Wall(screen_width - 10, 0, 10, screen_height)
    walls = pg.sprite.RenderPlain(top_wall, bottom_wall, left_wall, right_wall)
    collision_walls = pg.sprite.RenderPlain(invisible_top_wall,
                                            invisible_bottom_wall,
                                            invisible_left_wall,
                                            invisible_right_wall)
    allsprites = pg.sprite.RenderPlain(player, walls, collision_walls, hud,
                                       inv)
    player.walls = collision_walls.sprites()

    bullet_list = []

    enemy_list = []
    for enemy in enemy_list:
        allsprites.add(enemy)

    # Tracker
    item_count = defaultdict(lambda: 0)

    # Tracker specifically for special potion; and whether player holds it
    bomb_inuse = False
    bomb_counter = 0
    bomb_delay = 330

    # Shows the introduction screen
    story = "THE STORY SO FAR:"
    story2 = "In a world filled with swords, you are a superhero with a bow."
    story3 = "Swing your bow, kill enemies and eliminate swords."
    story4 = "Pick up health and a special potion along the way to make swords disappear!"
    story5 = "<TAB> to begin."

    start_game = False
    while not start_game:
        font = pygame.font.SysFont("Arial", 24)
        text = font.render(story, 1, (0, 0, 0))
        text2 = font.render(story2, 1, (0, 0, 0))
        text3 = font.render(story3, 1, (0, 0, 0))
        text4 = font.render(story4, 1, (0, 0, 0))
        text5 = font.render(story5, 1, (0, 0, 0))

        text_pos = text.get_rect(centerx=screen.get_width() / 2, centery=100)
        text_pos2 = text2.get_rect(centerx=screen.get_width() / 2, centery=200)
        text_pos3 = text3.get_rect(centerx=screen.get_width() / 2, centery=300)
        text_pos4 = text4.get_rect(centerx=screen.get_width() / 2, centery=400)
        text_pos5 = text5.get_rect(centerx=screen.get_width() / 2, centery=500)

        screen.blit(text, text_pos)
        screen.blit(text2, text_pos2)
        screen.blit(text3, text_pos3)
        screen.blit(text4, text_pos4)
        screen.blit(text5, text_pos5)

        pg.display.flip()

        for event in pg.event.get():
            if event.type == pg.QUIT:
                quit()
            if event.type == pg.KEYDOWN and event.key == pg.K_TAB:
                start_game = True
            else:
                continue

    # Main Loop
    going = True
    while going:
        # print(item_count[Enemy], item_count[Enemy2], item_count[Potion])

        # draw two backgrounds, slowly moving down
        screen.blit(bg, (0, bg_offset))
        screen.blit(bg, (0, bg_offset - screen_height))
        if bg_offset < screen_height:
            bg_offset += 1
        else:  # once offset goes off the screen, reset it
            bg_offset = 0

        for event in pg.event.get():
            if event.type == pg.QUIT:
                going = False

            # player attack
            if event.type == pg.KEYDOWN and event.key == pg.K_SPACE:
                player.start_attack()

            # player bomb
            if player.bomb_ready and event.type == pg.KEYDOWN and event.key == pg.K_c:
                pg.mixer.Sound('sound/tactical-nuke.wav').play()
                bomb_inuse = True
                player.bomb_ready = False

        if bomb_inuse:
            if bomb_counter < bomb_delay:
                bomb_counter += 1
            else:
                player.bomb_count = 0
                print("BOOM")
                bomb_inuse = False
                bomb_counter = 0

                # remove all bullets
                for bullet in bullet_list:
                    bullet.kill()
                bullet_list.clear()
                allsprites.remove(bullet_list)

                # remove all enemies?
                for enemy in enemy_list:
                    enemy.kill()
                enemy_list.clear()
                allsprites.remove(enemy_list)
                item_count[Enemy] = 0
                item_count[Enemy2] = 0

        if random.random() < chance_spawn(item_count[Potion]):
            potion = Potion(screen_width, screen_height)
            potion_list.append(potion)
            allsprites.add(potion)
            item_count[Potion] = item_count[Potion] + 1

        if random.random() < chance_spawn(item_count[Enemy]):
            enemy = Enemy(screen_width, screen_height)
            enemy_list.append(enemy)
            allsprites.add(enemy)
            item_count[Enemy] = item_count[Enemy] + 1

        if item_count[Enemy2] <= 5 and random.random() < chance_spawn(
                item_count[Enemy2]):
            enemy = Enemy2(screen_width, screen_height)
            enemy_list.append(enemy)
            allsprites.add(enemy)
            item_count[Enemy2] = item_count[Enemy2] + 1

        # a special potion; if you need to collect 4, may as well have them spawn randomly
        if random.random() < 0.003:
            potion = Potion2(screen_width, screen_height)
            potion_list.append(potion)
            allsprites.add(potion)

        # update player (movement, attack frame, health)
        if not player.update():
            end_screen(screen, bg, player)

        if clock.get_time() % 5:
            for enemy in enemy_list:
                if player.attack and player.attack_box.colliderect(
                        enemy.hurtbox):
                    enemy.kill_enemy(player)
                    enemy_list.remove(enemy)

                    if isinstance(enemy, Enemy):
                        item_count[Enemy] = item_count[Enemy] - 1
                    elif isinstance(enemy, Enemy2):
                        item_count[Enemy2] = item_count[Enemy2] - 1
                    allsprites.remove(
                        enemy
                    )  # TODO: Make enemies stay a while before being removed

                if player.hurtbox.colliderect(enemy.hurtbox):
                    if player.damage_cooldown == 0:
                        player.get_hurt()

                # remove if off screen; after calling 'implode' first on Enemy though
                if enemy.rect.y + 50 > screen_height:
                    if isinstance(enemy, Enemy):
                        bullets = enemy.implode(player.rect.x, screen_height)
                        for bullet in bullets:
                            bullet_list.append(bullet)
                            allsprites.add(bullet)

                    if isinstance(enemy, Enemy):
                        item_count[Enemy] = item_count[Enemy] - 1
                    elif isinstance(enemy, Enemy2):
                        item_count[Enemy2] = item_count[Enemy2] - 1

                    allsprites.remove(enemy)
                    enemy_list.remove(enemy)
                    enemy.kill()

                # get each enemy to go through a 'shoot' cycle; returns None if no bullet generated
                # bullet = None
                # if isinstance(enemy, Enemy):
                bullet = enemy.shoot(player.rect.x, player.rect.y)
                # elif isinstance(enemy, Enemy2):
                #     bullet = enemy.shoot(player.h)
                if bullet:
                    bullet_list.append(bullet)
                    allsprites.add(bullet)

            for bullet in bullet_list:
                remove = False
                # bigger hitbox collides with player attack
                if player.attack and player.attack_box.colliderect(
                        bullet.rect):
                    remove = True
                # smaller hitbox collides with player
                elif player.hurtbox.colliderect(bullet.hurtbox):
                    if player.damage_cooldown == 0:
                        player.get_hurt()
                    remove = True
                # off screen; add 20 to coordinates to centre it (knife is 40x40 px)
                elif bullet.rect.x + 20 < 10 or bullet.rect.x + 20 > screen_width - 10 \
                        or bullet.rect.y + 20 < 10 or bullet.rect.y + 20 > screen_height - 10:
                    remove = True

                # cheeky bodge: homing
                if isinstance(bullet, Knife2):
                    xdist = abs(player.rect.x - bullet.rect.x)
                    if bullet.rect.x + 40 < player.rect.x + 50 - 20:
                        bullet.true_x += bullet.xspeed * xdist
                    elif bullet.rect.x + 40 > player.rect.x + 50 + 20:
                        bullet.true_x -= bullet.xspeed * xdist

                if remove:
                    bullet_list.remove(bullet)
                    allsprites.remove(bullet)
                    bullet.kill()

            # remove potions going off screen
            for potion in potion_list:
                if potion.rect.y > screen_height - 30:
                    if isinstance(potion, Potion2):
                        potion2_present = False
                    allsprites.remove(potion)
                    item_count[Potion] = item_count[Potion] - 1
                    potion_list.remove(potion)
                    potion.kill()

        # draw
        allsprites.update()

        # Draw Everything
        allsprites.draw(screen)
        # text_surface = score_text.generate_surface('Health: ')
        # screen.blit(text_surface,
        #             (screen_width - text_surface.get_width() - 100, screen_height - text_surface.get_height() - 45))
        pg.display.flip()

        clock.tick(60)

    pg.quit()
Exemplo n.º 17
0
            print(data[1].x)

            if not data:
                print("Disconnected")
                break
            else:
                players[data[0]].disconnected = False
                reply = players

                # print("Received: ", data)
                # print("Sending : ", reply)

            conn.sendall(pickle.dumps(reply))
        except:
            break

    print("Lost connection")
    players[data[0]].disconnected = True
    conn.close()


currentPlayer = 0
while True:
    conn, addr = s.accept()
    print("conn")
    print("Connected to:", addr)
    players.append(
        Player(randint(50, 400), randint(50, 400), 50, 50, (255, 0, 0)))

    start_new_thread(threaded_client, (conn, currentPlayer))
    currentPlayer += 1
Exemplo n.º 18
0
from sprites.background import Background
from sprites.ground import Ground
from sprites.player import Player
from sprites.enemies.slime import Slime
from sprites.attacks.slime_attack import SlimeAttack
from stage import stages

pygame.init()

pygame.display.set_caption("Test Game")
stage = stages[0]

background = Background(stage["background"])
ground = Ground(stage["ground"])
player = Player()
slime = Slime()
slime_atk = SlimeAttack()
enemy_group = pygame.sprite.Group()
enemy_group.add(slime)
player_group = pygame.sprite.Group()
player_group.add(player)

hits = pygame.sprite.spritecollide(player, enemy_group, False)

while True:
    keys = pygame.key.get_pressed()
    player.gravity_check()

    for event in pygame.event.get():
        if event.type == QUIT:
Exemplo n.º 19
0
 def create_player(self, x, y):
     '''
     Creates a sprite object of type Player
     '''
     return Player(x, y)
Exemplo n.º 20
0
# player positions
PLAYER1_X = FIELD_X + 20
PLAYER2_X = FIELD_X + FIELD_WIDTH - 20

# initializing pygame & creating window
pygame.init()
screen = pygame.display.set_mode((display_width, display_height))
background = pygame.Surface(screen.get_size())
pygame.display.set_caption('Pynnis')
clock = pygame.time.Clock()

# sprites
all_sprites = pygame.sprite.Group()
field = Field(FIELD_X, FIELD_Y, FIELD_WIDTH, FIELD_HEIGHT, green)
player1 = Player(PLAYER1_X, field.rect, red, pygame.K_a, pygame.K_s)
player2 = Player(PLAYER2_X, field.rect, red, pygame.K_k, pygame.K_l)
ball = Ball(field.rect, yellow)
score = Score(FIELD_X + FIELD_WIDTH / 2 - 100, 5, 200, 50, 32, white, black)

all_sprites.add(field)
all_sprites.add(player1)
all_sprites.add(player2)
all_sprites.add(ball)
all_sprites.add(score)

quitted = False
# Creating game loop
while not quitted:
    # Speed of game loop defined by frames/second
    clock.tick(frames_per_second)