Example #1
0
 def __init__(self, x, y):
     self.entity = e.entity(x, y, 32, 32, 'player')
     self.movingRight = False
     self.movingLeft = False
     self.momentum = 0
     self.airTimer = 0
     self.movement = [0, 0]
     self.platformCollision = False
     self.onPlatform = False
     self.through = False
     self.levelOver = False
 def create_enemies():
     a = 5
     for i in range(a):
         enemies.append([
             0, 2,
             e.entity(
                 random.randint(-200, 900) - 300, 150, 13, 13, 'enemy')
         ])
         if enemies[0][2] in range((player.x - 30), (player.x + 30)):
             enemies.pop(-1)
             a += 1
def load_level(number):
    f = open('data/levels/level_' + str(number) + '.txt', 'r')
    dat = f.read()
    f.close()
    tile_map = json.loads(dat)
    max_height = -99999
    min_height = 99999
    spawnpoint = [0, 0]
    remove_list = []
    final_tile_map = {}
    entities = []
    total_cores = 0
    limits = [99999, -99999]
    for tile in tile_map:
        min_height = min(min_height, tile_map[tile][1][1])
        max_height = max(max_height, tile_map[tile][1][1])
        limits[0] = min(limits[0], tile_map[tile][1][0])
        limits[1] = max(limits[1], tile_map[tile][1][0])
    for tile in tile_map:
        tile_map[tile][1][1] -= min_height
        final_tile_map[xy2str(tile_map[tile][1])] = tile_map[tile].copy()
    for tile in final_tile_map:
        if final_tile_map[tile][0] == 16:
            spawnpoint = [
                final_tile_map[tile][1][0] * 16,
                final_tile_map[tile][1][1] * 16 - 32 +
                (max_height - min_height + 1) * 50
            ]
            remove_list.append(tile)
        elif (final_tile_map[tile][0] >= 14) and (final_tile_map[tile][0] <
                                                  16):
            remove_list.append(tile)
            entity_dat = [
                e.entity(
                    final_tile_map[tile][1][0] * 16 +
                    entity_info[final_tile_map[tile][0]][3],
                    final_tile_map[tile][1][1] * 16 +
                    entity_info[final_tile_map[tile][0]][4],
                    entity_info[final_tile_map[tile][0]][0],
                    entity_info[final_tile_map[tile][0]][1],
                    entity_info[final_tile_map[tile][0]][2]), False
            ]
            if final_tile_map[tile][0] == 15:
                entity_dat += [0, 0]
            if final_tile_map[tile][0] == 14:
                total_cores += 1
            entities.append(entity_dat)
    for tile in remove_list:
        del final_tile_map[tile]

    limits = [limits[0] * 16, limits[1] * 16]
    return final_tile_map, entities, max_height - min_height + 1, spawnpoint, total_cores, limits
Example #4
0
 def __init__(self, screen, clock, smallFont, largeFont, background):
     self.clock = clock
     self.screen = screen
     self.smallFont = smallFont
     self.largeFont = largeFont
     self.showFPS = True
     self.fullscreen = False
     self.background = e.entity(0, 0, 640, 480, background)
     self.button = pygame.image.load(
         'data/images/button01.png').convert_alpha()
     self.selectedButton = pygame.image.load(
         'data/images/buttonPressed01.png').convert_alpha()
     self.unavailableButton = pygame.image.load(
         'data/images/unavailableButton.png').convert_alpha()
     self.unavailableSelected = pygame.image.load(
         'data/images/unavailableSelected.png').convert_alpha()
Example #5
0
def Restart_L():  # Not working
    dead = True
    text.show_text('click to restart', 150 - int(get_text_width('click to restart', 1) / 2), 97, 1, 9999, font,
                   main_display)
    if click:
        dead = False
        temp = str(level)
        tile_map, entities, map_height, spawnpoint, total_cores, limits = load_level(temp)
        player = e.entity(spawnpoint[0] + 4, spawnpoint[1] - 17, 8, 15, 'player')
        player.set_offset([-3, -2])
        level_time = 0
        bullets = []
        flashes = []
        explosion_particles = []
        particles = []
        circle_effects = []
        scroll_target = [player.get_center()[0], player.get_center()[1]]
        scroll = scroll_target.copy()
        true_scroll = scroll.copy()
        bar_height = 100
        moved = False
        player_velocity = [0, 0]
Example #6
0
def load_level(number):
    # TODO: Fix levels to read ints and not strings
    # TODO: Inspect why players can access hidden level x without moving it into levels
    pathNameTest = "data/levels/"
    onlyfiles = next(os.walk(pathNameTest))[2]  # dir is your directory path as string
    # print(len(onlyfiles))
    # num=str(number)
    levelTemp = "1"

    if (number != ""):
        level = number + ".txt"

    else:
        level = levelTemp + ".txt"

    outfile = os.path.join('data/levels/', level)
    if os.path.exists(os.path.dirname(outfile)):
        f = open(outfile, 'r')
    else:
        raise FileNotFoundError(
            errno.ENOENT, os.strerror(errno.ENOENT), outfile)
        return
    dat = f.read()
    f.close()
    tile_map = json.loads(dat)
    max_height = -99999
    min_height = 99999
    spawnpoint = [0, 0]
    remove_list = []
    final_tile_map = {}
    entities = []
    total_cores = 0
    limits = [99999, -99999]
    for tile in tile_map:
        min_height = min(min_height, tile_map[tile][1][1])
        max_height = max(max_height, tile_map[tile][1][1])
        limits[0] = min(limits[0], tile_map[tile][1][0])
        limits[1] = max(limits[1], tile_map[tile][1][0])
    for tile in tile_map:
        tile_map[tile][1][1] -= min_height
        final_tile_map[xy2str(tile_map[tile][1])] = tile_map[tile].copy()
    for tile in final_tile_map:
        if final_tile_map[tile][0] == 16:
            spawnpoint = [final_tile_map[tile][1][0] * 16,
                          final_tile_map[tile][1][1] * 16 - 32 + (max_height - min_height + 1) * 50]
            remove_list.append(tile)
        elif (final_tile_map[tile][0] >= 14) and (final_tile_map[tile][0] < 16):
            remove_list.append(tile)
            entity_dat = [e.entity(final_tile_map[tile][1][0] * 16 + entity_info[final_tile_map[tile][0]][3],
                                   final_tile_map[tile][1][1] * 16 + entity_info[final_tile_map[tile][0]][4],
                                   entity_info[final_tile_map[tile][0]][0], entity_info[final_tile_map[tile][0]][1],
                                   entity_info[final_tile_map[tile][0]][2]), False]
            if final_tile_map[tile][0] == 15:
                entity_dat += [0, 0]
            if final_tile_map[tile][0] == 14:
                total_cores += 1
            entities.append(entity_dat)
    for tile in remove_list:
        del final_tile_map[tile]

    limits = [limits[0] * 16, limits[1] * 16]
    return final_tile_map, entities, max_height - min_height + 1, spawnpoint, total_cores, limits
Example #7
0
if len(argv) > 2:
    levelTemp = argv[2]
    if levelTemp.isnumeric():
        level = int(levelTemp)

try:
    tile_map, entities, map_height, spawnpoint, total_cores, limits = load_level(levelTemp)
except FileNotFoundError:
    tile_map, entities, map_height, spawnpoint, total_cores, limits = load_level("1")

current_fps = 0
dt = 0  # delta time
last_frame = pygame.time.get_ticks()
game_speed = 1
frozen = False
player = e.entity(spawnpoint[0] + 4, spawnpoint[1] - 17, 8, 15, 'player')
player.set_offset([-3, -2])
player_grav = 0
jumps = 2
player_speed = 2
air_timer = 0
last_movement = [0, 0]
shoot_timer = 0
dead = False
total_time = 0
level_time = 0
win = 0
moved = False
player_velocity = [0, 0]
bullets = []
explosion_particles = []
tile_index = {1: grass_img, 2: dirt_img, 3: plant_img}

jump_sound = pygame.mixer.Sound('data/audio/jump.wav')
grass_sounds = [
    pygame.mixer.Sound('data/audio/grass_0.wav'),
    pygame.mixer.Sound('data/audio/grass_1.wav')
]
grass_sounds[0].set_volume(0.2)
grass_sounds[1].set_volume(0.2)

pygame.mixer.music.load('data/audio/music.wav')
pygame.mixer.music.play(-1)

grass_sound_timer = 0

player = e.entity(100, 100, 5, 13, 'player')

background_objects = [[0.25, [120, 10, 70, 400]], [0.25, [280, 30, 40, 400]],
                      [0.5, [30, 40, 40, 400]], [0.5, [130, 90, 100, 400]],
                      [0.5, [300, 80, 120, 400]]]

while True:  # game loop
    display.fill((146, 244, 255))  # clear screen by filling it with blue

    if grass_sound_timer > 0:
        grass_sound_timer -= 1

    true_scroll[0] += (player.x - true_scroll[0] - 152) / 20
    true_scroll[1] += (player.y - true_scroll[1] - 106) / 20
    scroll = true_scroll.copy()
    scroll[0] = int(scroll[0])
def game():
    display = pygame.Surface(
        (300, 200))  # used as the surface for rendering, which is scaled

    player_health = 6
    stab = False  # used for player attacking
    cant_attack = False  # if player attacking or not used in later calculations
    hit = False  # bool for if been hit recently or not
    when_hit = 0.0  # float for timing how long player cant be hurt for
    moving_right = False
    moving_left = False
    vertical_momentum = 0
    air_timer = 0  # used to make sure player isnt jumping whilst already in the air

    true_scroll = [0, 0]  # camera scrolling

    CHUNK_SIZE = 8  # each chunk is 8 by 8

    def generate_chunk(x, y):
        chunk_data = []
        for y_pos in range(CHUNK_SIZE):  # 0 - 7 (not including 8)
            for x_pos in range(CHUNK_SIZE):  # 0 -7 (not including 8)
                target_x = x * CHUNK_SIZE + x_pos  # x * 8 (size of each chunk) + exact x_position inside of chunk
                target_y = y * CHUNK_SIZE + y_pos  # y * 8 (size of each chunk) + exact y_position inside of chunk
                tile_type = 0  # defaulting 0 which is empty
                if target_y == 6 and target_x in range(
                        1, 4):  # setting conditions for tiles to spawn
                    tile_type = 1  # grass (platform)
                if target_y == 7 and target_x in range(11, 16):
                    tile_type = 1  # grass (platform)
                if target_y in range(4, 10) and target_x == 7:
                    tile_type = 2  # dirt (wall)
                if target_y > 10:
                    tile_type = 2  # dirt
                elif target_y == 10:
                    tile_type = 1  # grass
                elif target_y == 9:
                    if random.randint(1, 5) == 1:
                        if tile_type == 0:
                            tile_type = 3  # plant 1/5 chance
                if tile_type != 0:
                    chunk_data.append(
                        [[target_x, target_y],
                         tile_type])  # returning list of x,y and block type
        return chunk_data

    class jumper_obj():
        def __init__(self, loc):
            self.loc = loc

        def render(
            self, surf, scroll
        ):  # rendering in the jumper based off its location and screens scroll
            surf.blit(jumper_img,
                      (self.loc[0] - scroll[0], self.loc[1] - scroll[1]))

        def get_rect(self):  # getting rectangles x, y and width and height
            return pygame.Rect(self.loc[0], self.loc[1], 8, 9)

        def collision_test(self, rect):  # adding collisions
            jumper_rect = self.get_rect()
            return jumper_rect.colliderect(rect)

    # loading animations from engine.py
    e.load_animations('data/images/entities/')

    game_map = {
    }  # starts empty gets used with generate chunks to generate the world
    # loading all the images
    grass_img = pygame.image.load('data/images/grass.png')
    dirt_img = pygame.image.load('data/images/dirt.png')
    plant_img = pygame.image.load('data/images/plant.png').convert()
    plant_img.set_colorkey((255, 255, 255))
    heart_img_full = pygame.image.load('data/images/heart.png').convert()
    heart_img_full.set_colorkey((255, 255, 255))
    heart_img_half = pygame.image.load('data/images/half_heart.png').convert()
    heart_img_half.set_colorkey((255, 255, 255))
    heart_img_empty = pygame.image.load(
        'data/images/empty_heart.png').convert()
    heart_img_empty.set_colorkey((255, 255, 255))

    jumper_img = pygame.image.load('data/images/jumper.png').convert()
    jumper_img.set_colorkey((255, 255, 255))
    # for generating the chunks line 87 generate chunk function
    tile_index = {1: grass_img, 2: dirt_img, 3: plant_img}
    # audio setup
    jump_sound = pygame.mixer.Sound('data/audio/jump.wav')
    jump_sound.set_volume(0.2)
    grass_sounds = [
        pygame.mixer.Sound('data/audio/grass_0.wav'),
        pygame.mixer.Sound('data/audio/grass_1.wav')
    ]
    grass_sounds[0].set_volume(0.2)
    grass_sounds[1].set_volume(0.2)
    pop_sound = pygame.mixer.Sound('data/audio/pop.wav')
    pop_sound.set_volume(0.3)
    # music setup
    pygame.mixer.music.load('data/audio/music.wav')
    pygame.mixer.music.set_volume(0.4)
    pygame.mixer.music.play(-1)
    music_play = True
    grass_sound_timer = 0  # timer defaulted at 0 for when grass sounds get played

    player = e.entity(60, 70, 7, 14, 'player')  # create and spawn player in
    # create and spawn player sword in as object locked to player for determining
    # hitbox when attacking
    sword = pygame.Rect((player.x - 5), player.y, 17, 6)

    enemies = []

    # creating 5 random enemies in random locations
    def create_enemies():
        a = 5
        for i in range(a):
            enemies.append([
                0, 2,
                e.entity(
                    random.randint(-200, 900) - 300, 150, 13, 13, 'enemy')
            ])
            if enemies[0][2] in range((player.x - 30), (player.x + 30)):
                enemies.pop(-1)
                a += 1

        # setting background objects for parrallax effect

    background_objects = [[4, [120, 10, 70, 400]], [4, [280, 30, 40, 400]],
                          [2, [30, 40, 40, 400]], [2, [130, 90, 100, 400]],
                          [2, [300, 80, 120, 400]]]

    jumper_objects = []
    # randomly creates a jumper obj which bounces the character high
    for i in range(5):
        jumper_objects.append(jumper_obj((random.randint(0, 600) - 300, 150)))

    while True:  # game loop
        display.fill((146, 244, 255))  # clear screen by filling it with blue
        sword.x = int(player.x -
                      5)  # setting sword to always be where the player is
        sword.y = int(
            player.y)  # setting sword to always be where the player is

        # spawns enemies as they die
        if enemies.__len__() <= 4:
            create_enemies()

        if grass_sound_timer > 0:
            grass_sound_timer -= 1
            # scroll is following the player and /20 is giving it a slow follow rather than locked on
        true_scroll[0] += (player.x - true_scroll[0] - 152) / 20
        true_scroll[1] += (player.y - true_scroll[1] - 106) / 20
        scroll = true_scroll.copy()
        scroll[0] = int(scroll[0])
        scroll[1] = int(scroll[1])

        # parrallax effect where differrent objects in background moves at different speeds
        pygame.draw.rect(display, (7, 80, 75), pygame.Rect(0, 120, 300, 80))
        for background_object in background_objects:
            obj_rect = pygame.Rect(
                background_object[1][0] -
                int(scroll[0] / background_object[0]),
                background_object[1][1] -
                int(scroll[1] / background_object[0]), background_object[1][2],
                background_object[1][3])

            if background_object[0] == 2:
                pygame.draw.rect(display, (14, 222, 150), obj_rect)
            else:
                pygame.draw.rect(display, (9, 91, 85), obj_rect)

        tile_rects = []
        # tile rendering around player based off generate chunk function
        for y in range(4):
            for x in range(4):
                target_x = x - 1 + int(round(
                    scroll[0] / (CHUNK_SIZE * 16)))  # returning x coordinate
                target_y = y - 1 + int(round(
                    scroll[1] / (CHUNK_SIZE * 16)))  # returning y coordinate
                target_chunk = str(target_x) + ';' + str(
                    target_y)  # putting the two together
                if target_chunk not in game_map:  # if not created yet create it
                    game_map[target_chunk] = generate_chunk(target_x, target_y)
                for tile in game_map[
                        target_chunk]:  # display objects as long as they exist on the screen
                    display.blit(tile_index[tile[1]],
                                 (tile[0][0] * 16 - scroll[0],
                                  tile[0][1] * 16 - scroll[1]))
                    if tile[1] in [1, 2]:
                        tile_rects.append(
                            pygame.Rect(tile[0][0] * 16, tile[0][1] * 16, 16,
                                        16))

            # set momentum for player based on key presses
        player_movement = [0, 0]
        if moving_right == True:
            player_movement[0] += 2
        if moving_left == True:
            player_movement[0] -= 2
        player_movement[1] += vertical_momentum
        vertical_momentum += 0.2
        if vertical_momentum > 3:
            vertical_momentum = 3

            # setting animations based on players movements
        if player_movement[0] == 0 and stab is False:
            player.set_action('idle')
        if player_movement[0] > 0 and stab is False:
            player.set_flip(False)
            player.set_action('run')
        if player_movement[0] < 0 and stab is False:
            player.set_flip(True)
            player.set_action('run')
        if player_movement[0] == 0 and stab is True:
            player.set_action('stab')
        if player_movement[0] > 0 and stab is True:
            player.set_flip(False)
            player.set_action('stab_run')
        if player_movement[0] < 0 and stab is True:
            player.set_flip(True)
            player.set_action('stab_run')

        collision_types = player.move(player_movement, tile_rects)

        if collision_types['bottom'] == True:  # if collided with ground
            air_timer = 0  # reset jump
            vertical_momentum = 0  # remove vertical momentum
            if player_movement[0] != 0:  # if moving on ground play grass sounds
                if grass_sound_timer == 0:
                    grass_sound_timer = 30
                    random.choice(grass_sounds).play()
        else:
            air_timer += 1  # otherwise air timer +1 so you cant jump in the air somehow

        player.change_frame(
            1)  # how much to change animation frames by per frame
        player.display(
            display, scroll
        )  # calls display function to show character on screen and scroll camera

        for jumper in jumper_objects:
            jumper.render(
                display,
                scroll)  # spawns in jumper objects that bounce players
            if jumper.collision_test(player.obj.rect):
                vertical_momentum = -6

        display_r = pygame.Rect(scroll[0], scroll[1], 300,
                                200)  # setting current camera co-ordinates

        for number, enemy in enumerate(
                enemies):  # for each enemy we spawn into a list
            if display_r.colliderect(
                    enemy[2].obj.rect):  # if they are in camera
                enemy[0] += 0.2
                if enemy[0] > 3:  # setting vertical movement capped at 3
                    enemy[0] = 3
                enemy_movement = [0, enemy[0]]
                if player.x > enemy[
                        2].x + 3:  # setting horizontal movement relative to player
                    enemy_movement[0] = 1
                if player.x < enemy[
                        2].x - 3:  # setting horizontal movement relative to player
                    enemy_movement[0] = -1
                enemy[2].move(enemy_movement, tile_rects)  # movement function
                if collision_types[
                        'bottom'] == True:  # if touching ground stop falling
                    enemy[0] = 0

            enemy[2].display(display, scroll)
            if player.obj.rect.colliderect(enemy[2].obj.rect):
                if enemy_movement[0] > 0:  # moving right
                    player_movement[0] += 15  # knock player left
                elif enemy_movement[0] < 0:  # moving left
                    player_movement[0] -= 15  # knock player right
                vertical_momentum = -3  # always knock player up
                player.move(player_movement, tile_rects)

                if hit == False:  # if player gets hit
                    player_health -= 1
                    hit = True  # setting hit to true so player cant be hit again for a short while
                    when_hit = time.time()
            if (time.time() - when_hit) >= 1:
                hit = False  # invulnerable for 1 second
            if hit == False and (time.time() -
                                 when_hit) >= 10 and player_health < 6:
                player_health = 6  # temporary regen if not hurt for 10 secs

            if stab == True:  # if player is attacking
                if cant_attack == False:  # if player is able to attack
                    cant_attack = True  # make it so they can't attack while attacking / for a short duration
                    time_attack = time.time()  # grab time they attacked
                if sword.colliderect(enemy[2].obj.rect
                                     ):  # if they hit something with attack
                    enemy[1] -= 1
                    # knockback enemies if hit depending on location
                    if enemy[2].x < player.x:
                        enemy_movement[0] = -10
                    elif enemy[2].x > player.x:
                        enemy_movement[0] = 10
                    enemy[2].move(
                        enemy_movement,
                        tile_rects)  # movement function for kncokback effect
                    stab = False  # so enemy wont keep taking ticks of damage if still in range of "sword"
                    print("bam")
                    if enemy[1] == 0:  # if enemy dead
                        enemies.pop(number)  # remove from enemies list
                        pop_sound.play()  # play sound
                        if player_health < 6:  # if player wounded, 33% chance to heal
                            a = random.randrange(1, 4)
                            if a == 1:
                                player_health += 1

            if cant_attack == True:  # resets cant_attack every .4 secs - prevents spam attacking
                if (time.time() - time_attack) >= 0.4:
                    stab = False
                    cant_attack = False

        for event in pygame.event.get():  # event loop
            if event.type == QUIT:
                pygame.quit()
                sys.exit()
            if event.type == KEYDOWN:
                if event.key == K_m:
                    if music_play == True:
                        pygame.mixer.music.fadeout(1000)
                        music_play = False
                    elif music_play == False:
                        pygame.mixer.music.play(-1)
                        music_play = True
                if event.key == K_RIGHT:
                    moving_right = True
                if event.key == K_LEFT:
                    moving_left = True
                if event.key == K_UP:
                    if air_timer < 6:
                        jump_sound.play()
                        vertical_momentum = -5
                if event.key == K_k:  # test button fornow
                    if cant_attack == False:
                        stab = True
            if event.type == KEYUP:
                if event.key == K_RIGHT:
                    moving_right = False
                if event.key == K_LEFT:
                    moving_left = False

        heart_full_scaled = pygame.transform.scale(heart_img_full, (20, 20))
        heart_half_scaled = pygame.transform.scale(heart_img_half, (20, 20))
        heart_empty_scaled = pygame.transform.scale(heart_img_empty, (20, 20))
        display.blit(heart_empty_scaled, (5, 5))
        display.blit(heart_empty_scaled, (30, 5))
        display.blit(heart_empty_scaled, (55, 5))

        hearts = player_health / 2  # all of the hearts related items below are setting up images based off health
        if hearts == 0:
            pygame.mixer.music.fadeout(1000)
            game_over()
        elif hearts == 0.5:
            display.blit(heart_half_scaled, (5, 5))
        elif hearts == 1:
            display.blit(heart_full_scaled, (5, 5))
        elif hearts == 1.5:
            display.blit(heart_full_scaled, (5, 5))
            display.blit(heart_half_scaled, (30, 5))
        elif hearts == 2:
            display.blit(heart_full_scaled, (5, 5))
            display.blit(heart_full_scaled, (30, 5))
        elif hearts == 2.5:
            display.blit(heart_full_scaled, (5, 5))
            display.blit(heart_full_scaled, (30, 5))
            display.blit(heart_half_scaled, (55, 5))
        elif hearts == 3:
            display.blit(heart_full_scaled, (5, 5))
            display.blit(heart_full_scaled, (30, 5))
            display.blit(heart_full_scaled, (55, 5))

        screen.blit(pygame.transform.scale(display, WINDOW_SIZE), (0, 0))
        pygame.display.update()
        clock.tick(60)
Example #10
0
 def __init__(self, x, y):
     self.x = x
     self.y = y
     self.collider = pygame.Rect((self.x, self.y, 16, 16))
     self.type = "key"
     self.img = e.entity(x, y, 16, 16, self.type)
dirt_img = pygame.image.load('data/images/dirt.png')
plant_img = pygame.image.load('data/images/plant.png').convert()
plant_img.set_colorkey((255, 255, 255))

jumper_img = pygame.image.load('data/images/jumper.png').convert()
jumper_img.set_colorkey((255, 255, 255))

tile_index = {1: grass_img, 2: dirt_img, 3: plant_img}

################## ENEMY TEST CODE #######################

enemies = []

for i in range(5):
    enemies.append(
        [0, e.entity(random.randint(0, 600) - 300, 80, 13, 13, 'enemy')])

global animation_frames
animation_frames = {}


def load_animation(path, frame_durations):
    global animation_frames
    animation_name = path.split('/')[-1]
    animation_frame_data = []
    n = 0
    for frame in frame_durations:
        animation_frame_id = animation_name + '_' + str(n)
        img_loc = path + '/' + animation_frame_id + '.png'
        # enemy_animations/idle/idle_0.png
        animation_image = pygame.image.load(img_loc).convert()
Example #12
0
tile_index = {1: grass_img, 2: dirt_img, 3: plant_img}

jump_sound = pygame.mixer.Sound('data/audio/jump.wav')
grass_sounds = [
    pygame.mixer.Sound('data/audio/grass_0.wav'),
    pygame.mixer.Sound('data/audio/grass_1.wav')
]
grass_sounds[0].set_volume(0.2)
grass_sounds[1].set_volume(0.2)

pygame.mixer.music.load('data/audio/music.wav')
pygame.mixer.music.play(-1)

grass_sound_timer = 0

player = e.entity(100, 100, 5, 13, 'player')

enemies = []

for i in range(5):
    enemies.append(
        [0, e.entity(random.randint(0, 600) - 300, 80, 13, 13, 'enemy')])

background_objects = [[0.25, [120, 10, 70, 400]], [0.25, [280, 30, 40, 400]],
                      [0.5, [30, 40, 40, 400]], [0.5, [130, 90, 100, 400]],
                      [0.5, [300, 80, 120, 400]]]

jumper_objects = []

for i in range(5):
    jumper_objects.append(jumper_obj((random.randint(0, 600) - 300, 80)))
Example #13
0
tile_index = {1:grass_img,
              2:dirt_img,
              3:plant_img
              }

jump_sound = pygame.mixer.Sound('data/audio/jump.wav')
grass_sounds = [pygame.mixer.Sound('data/audio/grass_0.wav'),pygame.mixer.Sound('data/audio/grass_1.wav')]
grass_sounds[0].set_volume(0.2)
grass_sounds[1].set_volume(0.2)

pygame.mixer.music.load('data/audio/music.wav')
pygame.mixer.music.play(-1)

grass_sound_timer = 0

player = e.entity(100,100, player_width, player_height,'player')

# player_img.get_width(),player_img.get_height()

enemies = []

for i in range (5):
    # enemies.append(0,e.entity(random.randint(0, 600) - 300, 80, 32, 32, 'enemy'))
    enemies.append([0,e.entity(random.randint(0,600)-300,80,32,32,'enemy')])




background_objects = [[0.25,[120,10,70,400]],[0.25,[280,30,40,400]],[0.5,[30,40,40,400]],[0.5,[130,90,100,400]],[0.5,[300,80,120,400]]]

jumper_objects = []
Example #14
0
 def __init__(self, screen, x, y, xSize, ySize, type):
     self.entity = e.entity(x, y, xSize, ySize, type)
     self.screen = screen
     self.type = type
Example #15
0
os.environ['SDL_VIDEO_WINDOW_POS'] = "%d,%d" % (0, 0) #     set position of the window to right corner of the screen
pygame.init()

level_width = 64
level_height = 36

screen_res = [e.Monitor.current_w, e.Monitor.current_h]
scaling = int((screen_res[0] / level_width) / 16)
w = 800
h = 600
window = pygame.display.set_mode((w, h), pygame.RESIZABLE)

gravity = 0

e.load_animations("data/graphics/")
player = e.entity(0, 0, 16, 16, "player")
player.scale_size(scaling)
moving_left = False
moving_right = False

while True:
    window.fill(e.purple)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()
        if event.type == pygame.VIDEORESIZE:
            window = pygame.display.set_mode((event.w, event.h), pygame.RESIZABLE)

        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_ESCAPE:
                markers.append(['left', [x, y], 0])
            if color == (255, 127, 39):
                markers.append(['right', [x, y], 0])
            if color == (34, 177, 76):
                markers.append(['up', [x, y], 0])
            if color == (0, 162, 232):
                markers.append(['down', [x, y], 0])
    return tiles, markers


# Setup ------------------------------------------------------ #

tiles, markers = load_map('map')
markers.append(['end', [12 * 21 - 10, 18]])

player = e.entity(25, 57 * 18, 6, 11, 'player')
player.set_offset([-1, -1])
player_grav = 0
ground_timer = 0

jumps = 1

scroll = [player.x - WINDOWWIDTH / 2, player.y - WINDOWHEIGHT / 2]

game_timer = 0

last_save = [25, 57 * 18 + 7]

circle_center = [
    player.get_center()[0] - scroll[0],
    player.get_center()[1] - scroll[1]
Example #17
0
 def __init__(self, x, y):
     super().__init__(x, y)
     self.type = "spike"
     self.img = e.entity(x,y, 16, 8, "spike")
Example #18
0
tile_index = {1: grass_img, 2: dirt_img, 3: plant_img}

jump_sound = pygame.mixer.Sound('data/audio/jump.wav')
grass_sounds = [
    pygame.mixer.Sound('data/audio/grass_0.wav'),
    pygame.mixer.Sound('data/audio/grass_1.wav')
]
grass_sounds[0].set_volume(0.2)
grass_sounds[1].set_volume(0.2)

pygame.mixer.music.load('data/audio/music.wav')
pygame.mixer.music.play(-1)

grass_sound_timer = 0

player = e.entity(100, 100, player_width, player_height, 'player')

# player_img.get_width(),player_img.get_height()

# enemy/idle/ 1 loop

enemies = []

for i in range(5):
    # enemies.append(0,e.entity(random.randint(0, 600) - 300, 80, 32, 32, 'enemy'))
    enemies.append(
        [0, e.entity(random.randint(0, 600) - 300, 80, 13, 13, 'enemy')])

background_objects = [[0.25, [120, 10, 70, 400]], [0.25, [280, 30, 40, 400]],
                      [0.5, [30, 40, 40, 400]], [0.5, [130, 90, 100, 400]],
                      [0.5, [300, 80, 120, 400]]]
Example #19
0
tile_index = {1:grass_img,
              2:dirt_img,
              3:plant_img
              }

jump_sound = pygame.mixer.Sound('data/audio/jump.wav')
grass_sounds = [pygame.mixer.Sound('data/audio/grass_0.wav'),pygame.mixer.Sound('data/audio/grass_1.wav')]
grass_sounds[0].set_volume(0.2)
grass_sounds[1].set_volume(0.2)

pygame.mixer.music.load('data/audio/music.wav')
pygame.mixer.music.play(-1)

grass_sound_timer = 0

player = e.entity(100,100, player_width, player_height,'player')

# player_img.get_width(),player_img.get_height()


background_objects = [[0.25,[120,10,70,400]],[0.25,[280,30,40,400]],[0.5,[30,40,40,400]],[0.5,[130,90,100,400]],[0.5,[300,80,120,400]]]

jumper_objects = []

for i in range(5):
    jumper_objects.append(jumper_obj((random.randint(0, 600) - 500, 304)))

while True: # game loop
    display.fill((146,244,255)) # clear screen by filling it with blue

    if grass_sound_timer > 0:
    limits = [limits[0] * 16, limits[1] * 16]
    return final_tile_map, entities, max_height - min_height + 1, spawnpoint, total_cores, limits


top_tile_list = [9, 10, 11, 12, 13]

level = 1
tile_map, entities, map_height, spawnpoint, total_cores, limits = load_level(
    level)

current_fps = 0
dt = 0  # delta time
last_frame = pygame.time.get_ticks()
game_speed = 1

player = e.entity(spawnpoint[0] + 4, spawnpoint[1] - 17, 8, 15, 'player')
player.set_offset([-3, -2])
player_grav = 0
jumps = 2
player_speed = 2
air_timer = 0
last_movement = [0, 0]
shoot_timer = 0
dead = False
total_time = 0
level_time = 0
win = 0
moved = False
player_velocity = [0, 0]

bullets = []