Beispiel #1
0
    def __init__(self, screen, joysticks):
        Level.__init__(self, screen, joysticks)

        self.background_colour = (51, 43, 0)

        self.room_items = []

        # - Set up maze, objects 32x32 - #
        room_objects = [
            'DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD',
            'DBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBD',
            'DB                                              BD',
            'DB                                              BD',
            'DB                                              BD',
            'DB                                              BD',
            'DB                        B                     BD',
            'DB       B  BBBBBBBB      B                     BD',
            'DB       B         B      B                     BD',
            'DB       B         B      B                     BD',
            'DB       B         B      B                     BD',
            'DB       BBBBBBB   B      B                     BD',
            'DB                                              BD',
            'DB                                              BD',
            'DB           BBBBBB  BBBBBBB                    BD',
            'DB           B             B                    BD',
            'DB           B       P     B                    BD',
            'DB           B             B                    BD',
            'DB           B             B                    BD',
            'DB           BBBBBBBBBBBB  B                    BD',
            'DB                             BBBBB   BBBBBB   BD',
            'DB                                              BD',
            'DB       BB   BBBBBBBBBBB                       BD',
            'DB       B              B   BBBBBBBBBBBBBBBBB   BD',
            'DB       B              B   B                   BD',
            'DB       B    BBBBBBB   B                       BD',
            'DB       B   BBBBB     BBBBBBBBBBBBBBBBBBBBB    BD',
            'DB       B   B                             B    BD',
            'DB       B   B                             B    BD',
            'DBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB  BBBBBBD',
            'DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDGGDDDDDDD'
        ]

        for i, row in enumerate(room_objects):
            for j, obj in enumerate(row):
                if obj == 'B':
                    new_block = Block(self, j * 32 - 200, i * 32 - 200)
                    self.add_room_object(new_block)
                    self.room_items.append(new_block)
                elif obj == 'P':
                    self.add_room_object(
                        Player(self, j * 32 - 200, i * 32 - 200))
                elif obj == 'G':
                    new_goal = Goal(self, j * 32 - 200, i * 32 - 200)
                    self.add_room_object(new_goal)
                    self.room_items.append(new_goal)
                elif obj == 'D':
                    new_dirt = Dirt(self, j * 32 - 200, i * 32 - 200)
                    self.add_room_object(new_dirt)
                    self.room_items.append(new_dirt)
Beispiel #2
0
    def __init__(self, screen, joysticks):
        Level.__init__(self, screen, joysticks)

        # - Set Background image - #
        self.set_background_image("wood_background.jpg")

        # - Preload images from disk - #
        img_grnd_flat = self.load_image('Grass_Tile_Flat.png')
        img_grnd_left = self.load_image('Grass_Tile_Corner_Edge_l.png')
        img_grnd_right = self.load_image('Grass_Tile_Corner_Edge_r.png')
        img_grnd_under = self.load_image('Grass_Tile_lower.png')

        # - Set up maze, objects 32x32 25x17 - #
        room_objects = [
            'lmmmmmmmmmmmmmmmmmmmmmmmr', 'ug_________________M____u',
            'u_______________________u', 'umrG ___________________u',
            'u_______________________u', 'u_lmmr_lmmmmmr______lr__u',
            'u_____________lmmmr_____u', 'u______________________lu',
            'u__________M____________u', 'u__________________Glmmmu',
            'u_____M________lr_______u', 'u_________lmmr___lr_____u',
            'u_______________________u', 'ummmr__lr_______________u',
            'u________lmmmr__________u', 'up______________________u',
            'ummmmmmmmmmmmmmmmmmmmmmmu'
        ]

        for i, row in enumerate(room_objects):
            for j, obj in enumerate(row):
                if obj == 'm':
                    self.add_room_object(
                        Block(self, j * 32, i * 32, img_grnd_flat))
                elif obj == 'l':
                    self.add_room_object(
                        Block(self, j * 32, i * 32, img_grnd_left))
                elif obj == 'r':
                    self.add_room_object(
                        Block(self, j * 32, i * 32, img_grnd_right))
                elif obj == 'u':
                    self.add_room_object(
                        Block(self, j * 32, i * 32, img_grnd_under))
                elif obj == 'p':
                    self.add_room_object(Player(self, j * 32, i * 32))
                elif obj == 'g':
                    self.add_room_object(Goal(self, j * 32, i * 32))
                elif obj == 'G':
                    self.add_room_object(Monster2(self, j * 32, i * 32))
                elif obj == 'M':
                    self.add_room_object(Monster(self, j * 32, i * 32))

        # - Add Banner for game info (lives) 800x56 - #
        self.add_room_object(Banner(self, 0, 544))

        # - Add Text - #
        self.score_text = TextObject(self, 20, 560,
                                     'Lives: %i' % Globals.LIVES)
        self.score_text.depth = 1000
        self.score_text.colour = (255, 255, 255)
        self.score_text.update_text()
        self.add_room_object(self.score_text)
Beispiel #3
0
    def __init__(self, screen, joysticks):
        Level.__init__(self, screen, joysticks)

        # - Set Background image - #
        self.set_background_image("background.jpg")

        # - Home location for the player - #
        self.home_x = 11 * 32
        self.home_y = 7 * 32

        # - Set up maze, objects 32x32 25x17 - #
        room_objects = [
            'bbbbbbbbbbbbbbbbbbbbbbbbb', 'b___________m___________b',
            'b___bbbbb_d_bbbbbbbb__bdb', 'b___b___bb_bbb_____b___bb',
            'b___b____b__b___b___b___b', 'b___bb___b__b___bbb__b__b',
            'b____b___bp_b______b___mb', 'b____b___b__bbbb__b_____b',
            'b____bbbbb_m___b__b_____b', 'b____m________b__bbbbbbbb',
            'b____bbbb____b__b_______b', 'bbbbb_______b_b__b__bb__b',
            'b_____bbbbb_b_b__b__bb__b', 'b_________b___b_____bb__b',
            'bbbbbbbbbbbbbdbb__bbbb__b', 'b______g_______b_bb_____b',
            'bbbbbbbbbbbbbbbbbbbbbbbbb'
        ]

        for i, row in enumerate(room_objects):
            for j, obj in enumerate(row):
                if obj == 'b':
                    self.add_room_object(Block(self, j * 32, i * 32))
                elif obj == 'd':
                    self.add_room_object(BlockDoor(self, j * 32, i * 32))
                elif obj == 'p':
                    self.add_room_object(Player(self, j * 32, i * 32))
                elif obj == 'g':
                    self.add_room_object(Goal(self, j * 32, i * 32))
                elif obj == 'm':
                    self.add_room_object(Monster(self, j * 32, i * 32))

        # - Add Banner for game info (lives) 800x56 - #
        self.add_room_object(Banner(self, 0, 544))

        # - Add Text - #
        self.score_text = TextObject(self, 20, 560,
                                     'Lives: %i' % Globals.LIVES)
        self.score_text.depth = 1000
        self.score_text.colour = (255, 255, 255)
        self.score_text.update_text()
        self.add_room_object(self.score_text)
Beispiel #4
0
    def __init__(self, DoRestart=True, Tick=60):
        self.Window = Window('Game', 800, 600)
        self.ModLoader = Loader()

        self.Player = Player(0, 0, 50, 50)
        self.Enemies = Collection(Enemy)
        self.Bombs = Collection(Bomb)
        self.Objects = []

        self.Screen = None
        self.Run = True
        self.DoRestart = DoRestart
        self.Tick = Tick

        self.Extensions = []
        self.Plugins = []
        self.CallableEvents = [
            'EventInit'
            'EventStart', 'EventEnd', 'EventCollision', 'EventGameOver',
            'EventRestart', 'EventFrame', 'EventFixedFrame'
        ]

        self.Notifications = {}
        self.Messages = {'GameOver': 'You Died!'}
Beispiel #5
0
from Objects import Block, BLOCK_SIZE, SuperBattery, NormalBattery, Portal, BacteriumNormal, BacteriumMutant, \
    Spike, PlusHealth, PlusJump, PlusSpeed, DarkBall, Player, Bullet, Canon
from Miscellaneous import Coord
# from main import  width, height
import pygame

MORTY = Player('morty', Coord(100, 0, 0), [8, 0], 30, 10, 2, 2, 50)
size = width, height = 1480, 700
pygame.init()
'''
    LEVEL 1 Objects
'''
LEVELS = []

LEVEL_1_FLOOR = []
LEVEL_1_BLOCKS = []
LEVEL_1_OBJECTS = []
x = 0
while x < width:
    LEVEL_1_FLOOR.append(Block(Coord(x, height - BLOCK_SIZE, 0), "ground"))
    x += BLOCK_SIZE
# LEVEL_1_BLOCKS.append(Block(Coord(500, 0, 0), 'brick'))
LEVEL_1_BLOCKS.append(Block(Coord(100, 100, 0), 'brick'))
LEVEL_1_BLOCKS.append(Block(Coord(150, 150, 0), 'brick'))
LEVEL_1_BLOCKS.append(Block(Coord(200, 200, 0), 'brick'))
LEVEL_1_BLOCKS.append(Block(Coord(300, 250, 0), 'brick'))
LEVEL_1_BLOCKS.append(Block(Coord(400, 300, 0), 'brick'))
LEVEL_1_BLOCKS.append(Block(Coord(500, 400, 0), 'brick'))
LEVEL_1_BLOCKS.append(Block(Coord(600, 500, 0), 'brick'))
LEVEL_1_BLOCKS.append(Block(Coord(700, 600, 0), 'brick'))
LEVEL_1_BLOCKS.append(Block(Coord(700, 630, 0), 'brick'))
Beispiel #6
0
    pygame.font.init()
    path = "./fonts/FluoGums.ttf"
    size = 17
    fuente = pygame.font.Font(path, size)
    fuente2 = pygame.font.Font(path, 40)
    #Grupos
    todos = pygame.sprite.Group()
    Players = pygame.sprite.Group()
    Enemys = pygame.sprite.Group()
    Bullets = pygame.sprite.Group()
    Lifes = pygame.sprite.Group()
    Bosses = pygame.sprite.Group()
    Naves = pygame.sprite.Group()

    Luke2 = Player(21, 150)
    Players.add(Luke2)
    todos.add(Luke2)

    Luke = Player(21, 300)
    Players.add(Luke)
    todos.add(Luke)
    #1850X 225Y

    time = 50
    Life1 = Life(20, 450)
    Lifes.add(Life1)
    todos.add(Life1)

    Life2 = Life(400, 450)
    Lifes.add(Life2)
Beispiel #7
0
# Initialize PyGame Music
pg.mixer.init()

pg.mixer.music.load(SPACE_SHOOTER_GAME_MUSIC_PATH)
pg.mixer.music.play(loops=-1)

# Screen setup
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
screen = pg.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
screen.fill(pg.color.THECOLORS['black'])

background_img = get_background_image()

player = Player(SCREEN_WIDTH, SCREEN_HEIGHT)
all_sprites = pg.sprite.Group()
all_player_lasers = pg.sprite.Group()
all_enemy_ships = pg.sprite.Group()
all_enemy_lasers = pg.sprite.Group()
all_meteors = pg.sprite.Group()

clock = pg.time.Clock()

ADD_ENEMY_LASER_EVENT = pg.USEREVENT + 1
pg.time.set_timer(ADD_ENEMY_LASER_EVENT, 1000)

ADD_SMALL_METEOR_EVENT = pg.USEREVENT + 2
pg.time.set_timer(ADD_SMALL_METEOR_EVENT, 2000)

ADD_LARGE_METEOR_EVENT = pg.USEREVENT + 3
Beispiel #8
0
                if (collisionState.Left or collisionState.Right):
                    continue

                if (objs[firstObject].y > objs[secondObject].y
                        and objs[secondObject].y <
                        objs[secondObject].y + objs[secondObject].height):
                    collisionState.Top = True
                elif (objs[firstObject].y + objs[firstObject].height >
                      objs[secondObject].y
                      and objs[firstObject].y + objs[firstObject].height <
                      objs[secondObject].y + objs[secondObject].height):
                    collisionState.Bottom = True

                # We must not be colliding on the top or bottom
                if (collisionState.Top or collisionState.Bottom):
                    continue

                objs[firstObject].Collides(objs[secondObject], collisionState)

    def GetGameState(self):
        return self.__previousState

    def Quit(self):
        pygame.quit()
        quit()


game = Game()
game.AddGameObjects(
    Player.PlayerS((0, 0), (0, 0), (16, 16), Player.PlayerStats(100, 0)))
game.Start()
Beispiel #9
0
        screen.blit(background.image, background.rect)


if __name__ == "__main__":
    # Init all pygame modules
    pygame.init()
    # size of the window
    size = width, height = 1080, 655
    speed = [1, 0]
    black = 0, 0, 0
    floor = []
    blocks = []
    # background = pygame.image.load('sprites/scenes/scene_02.jpg').convert_alpha()
    screen = pygame.display.set_mode(size)
    background = Background('sprites/scenes/scene_02.jpg', [0, 0])
    player_morty = Player("rick", Coord(100, 0, 0), [8, 0], 30, 10, 2, 2, 50)
    print(player_morty.bounding)
    x = 0
    player_morty.detect__vertical_collisions(floor + blocks)

    while x < width:
        floor.append(Block(Coord(x, height - BLOCK_SIZE, 0), "ground"))
        x += BLOCK_SIZE

    blocks.append(Block(Coord(500, 0, 0), 'brick'))
    blocks.append(Block(Coord(100, 100, 0), 'brick'))
    blocks.append(Block(Coord(150, 150, 0), 'brick'))
    blocks.append(Block(Coord(200, 200, 0), 'brick'))
    blocks.append(Block(Coord(300, 250, 0), 'brick'))
    blocks.append(Block(Coord(400, 300, 0), 'brick'))
    blocks.append(Block(Coord(500, 400, 0), 'brick'))
Beispiel #10
0
 def createPlayer(self, socketsInfo):
     posX, posY = self.generatePlayersPosition()
     self.playerList.append(
         Player.Player(socketsInfo, self.playersRepresentation.pop(0), posX,
                       posY))
Beispiel #11
0
    keys = []
    # background = pygame.image.load('sprites/scenes/scene_02.jpg').convert_alpha()
    screen = pygame.display.set_mode(size)
    # icon
    icon = pygame.image.load('icon.png')
    pygame.display.set_icon(icon)
    background = Background('sprites/scenes/scene_02.jpg', [0, 0])
    ''' PYGAME '''

    ''' PLAYER '''
    if len(argv) == 1:
        name = 'morty'
    else:
        name = argv[1]
    if name == 'morty':
        player = Player('morty', Coord(100, 0, 0), [8, 0], 50, 10, 2, 2, 50)
    else:
        player = Player(name,
                        Coord(100, 0, 0), [8, 0], 50, 10, 2, 2, 50)
    player.energy = 8
    player.lifes = MAX_LIFES
    ''' PLAYER '''

    ''' LABAEL '''
    myfont = pygame.font.SysFont("monospace bold", 40)
    # render text
    label = myfont.render("Level 1", 1, (0, 0, 0))
    ''' LABAEL '''

    ''' RUNING LEVELS'''
    i = 0
Beispiel #12
0
def start_game():
    # Initialize PyGame
    pg.init()

    # Initialize PyGame Music
    pg.mixer.init()

    pg.mixer.music.load(SPACE_SHOOTER_GAME_MUSIC_PATH)
    pg.mixer.music.play(loops=-1)

    # Screen setup
    SCREEN_WIDTH = 800
    SCREEN_HEIGHT = 600
    screen = pg.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
    screen.fill(pg.color.THECOLORS['black'])

    background_img = get_background_image()

    player = Player(SCREEN_WIDTH, SCREEN_HEIGHT)
    all_sprites = pg.sprite.Group()
    all_player_lasers = pg.sprite.Group()
    all_enemy_ships = pg.sprite.Group()
    all_enemy_lasers = pg.sprite.Group()
    all_meteors = pg.sprite.Group()

    clock = pg.time.Clock()

    ADD_ENEMY_LASER_EVENT = pg.USEREVENT + 1
    pg.time.set_timer(ADD_ENEMY_LASER_EVENT, 1000)

    ADD_SMALL_METEOR_EVENT = pg.USEREVENT + 2
    pg.time.set_timer(ADD_SMALL_METEOR_EVENT, 2000)

    ADD_LARGE_METEOR_EVENT = pg.USEREVENT + 3
    pg.time.set_timer(ADD_LARGE_METEOR_EVENT, 3000)

    ADD_ENEMY_SHIP_EVENT = pg.USEREVENT + 4
    pg.time.set_timer(ADD_ENEMY_SHIP_EVENT, 3000)

    ADD_ENEMY_UFO_EVENT = pg.USEREVENT + 5
    pg.time.set_timer(ADD_ENEMY_UFO_EVENT, 60000)

    game_life = pg.image.load(LIFE_IMG).convert()
    game_life.set_colorkey(pg.color.THECOLORS['black'], RLEACCEL)

    player_life = 3

    score = Score(SCREEN_WIDTH)

    running = True
    while running:

        if player_life == 0:
            running = False

        for event in pg.event.get():
            if event.type == KEYDOWN:
                if event.key == K_ESCAPE:
                    running = False
            elif event.type == QUIT:
                running = False
            elif event.type == ADD_SMALL_METEOR_EVENT:
                x = random.randint(0, SCREEN_WIDTH)
                y = -30
                small_meteor = SmallMeteor(x, y)
                all_meteors.add(small_meteor)
                all_sprites.add(small_meteor)
            elif event.type == ADD_LARGE_METEOR_EVENT:
                x = random.randint(0, SCREEN_WIDTH)
                y = -30
                large_meteor = LargeMeteor(x, y)
                all_meteors.add(large_meteor)
                all_sprites.add(large_meteor)
            elif event.type == ADD_ENEMY_SHIP_EVENT:
                x = random.randint(0, SCREEN_WIDTH)
                y = -30
                enemy_ship = EnemyShip(x, y)
                all_enemy_ships.add(enemy_ship)
                all_sprites.add(enemy_ship)
            elif event.type == ADD_ENEMY_UFO_EVENT:
                x = -30
                y = random.randint(0, ceil(SCREEN_HEIGHT / 2))
                enemy_ufo = EnemyUFO(x, y)
                all_enemy_ships.add(enemy_ufo)
                all_sprites.add(enemy_ufo)
            elif event.type == ADD_ENEMY_LASER_EVENT:
                for enemy_ship in all_enemy_ships:
                    if not enemy_ship.enemy_fired:
                        enemy_laser = EnemyLaser(enemy_ship.x, enemy_ship.y)
                        all_enemy_lasers.add(enemy_laser)
                        all_sprites.add(enemy_laser)
                        shooting_sound.play()

        pressed_keys = pg.key.get_pressed()

        no_of_objects_in_row = ceil(SCREEN_WIDTH / background_img.get_width())
        no_of_objects_in_column = ceil(SCREEN_HEIGHT /
                                       background_img.get_height())

        for i in range(no_of_objects_in_row):
            for j in range(no_of_objects_in_column):
                rect = background_img.get_rect()
                rect.topleft = (i * background_img.get_width(),
                                j * background_img.get_height())
                screen.blit(background_img, rect)

        screen.blit(background_img, background_img.get_rect())

        screen.blit(player.surf, player.rect)

        if pressed_keys[K_SPACE]:
            if not player.player_fired:
                shooting_sound.play()
                laser = PlayerLaser(player.x, player.rect.top)
                all_player_lasers.add(laser)
                all_sprites.add(laser)
                player.player_fire()

        for sprite in all_sprites:
            sprite.update()
            screen.blit(sprite.surf, sprite.rect)

        score.update()
        player.update(pressed_keys)

        for player_laser in all_player_lasers:
            meteor_hit = pg.sprite.spritecollideany(player_laser, all_meteors)
            ship_hit = pg.sprite.spritecollideany(player_laser,
                                                  all_enemy_ships)
            if meteor_hit is not None:
                meteor_hit.kill()
                player_laser.kill()
                explosion_sound.play()
                if type(meteor_hit) == SmallMeteor:
                    score.add_to_score(100)
                else:
                    score.add_to_score(50)
            if ship_hit is not None:
                ship_hit.kill()
                player_laser.kill()
                explosion_sound.play()
                if type(ship_hit) == EnemyUFO:
                    score.add_to_score(1000)
                    player_life += 1
                else:
                    score.add_to_score(150)

        if pg.sprite.spritecollideany(
                player, all_meteors) or pg.sprite.spritecollideany(
                    player, all_enemy_ships) or pg.sprite.spritecollideany(
                        player, all_enemy_lasers):
            player.kill()
            explosion_sound.play()
            time.sleep(1)
            for sprite in all_sprites:
                sprite.kill()
            player_life -= 1

        for i in range(player_life):
            screen.blit(
                game_life,
                game_life.get_rect(center=(i * game_life.get_width() +
                                           game_life.get_width(),
                                           game_life.get_height())))

        screen.blit(score.score_text, score.rect)

        pg.display.flip()

        clock.tick(30)