import pickle import pygame import os from pygame import mixer from os import path pygame.font.init() pygame.mixer.init() # Version----------------- Version = "1.0" # SetupWindow----------------- HEIGHT, WIDTH = 800, 800 WIN = pygame.display.set_mode((HEIGHT, WIDTH)) pygame.display.set_caption("Game") display = pygame.Surface((HEIGHT, WIDTH)) characterHeight = 90 characterWidth = 100 Block_width = 40 Block_heigh = 40 tile_size = 50 run = True clock = pygame.time.Clock() FPS = 60 player_rect = pygame.Rect((80, 100), (80, 90)) lvl = 1 maxlevels = 20 # BackgroundMusic----------------- def backgroundmusic(): mixer.music.load("music/popsmoke.mp3") mixer.music.set_volume(0.008) mixer.music.play(-1) # SFX----------------- jump_s = pygame.mixer.Sound('music/jump.sound.mp3') jump_s.set_volume(0.4) shoot_s = pygame.mixer.Sound('music/shoot.sound.mp3') shoot_s.set_volume(0.3) # Background"0" Background = pygame.image.load(os.path.join("assets/imgs", "BC3.png")) # ImageUpload----------------- """ WalkingList = [pygame.transform.scale(pygame.image.load(os.path.join("Walking", "Satyr_01_Walking_000.png")), (characterHeight, characterWidth)), pygame.transform.scale(pygame.image.load(os.path.join("Walking", "Satyr_01_Walking_001.png")), (characterHeight, characterWidth)), pygame.transform.scale(pygame.image.load(os.path.join("Walking", "Satyr_01_Walking_002.png")), (characterHeight, characterWidth)), pygame.transform.scale(pygame.image.load(os.path.join("Walking", "Satyr_01_Walking_003.png")), (characterHeight, characterWidth)), pygame.transform.scale(pygame.image.load(os.path.join("Walking", "Satyr_01_Walking_004.png")), (characterHeight, characterWidth)), pygame.transform.scale(pygame.image.load(os.path.join("Walking", "Satyr_01_Walking_005.png")), (characterHeight, characterWidth)), pygame.transform.scale(pygame.image.load(os.path.join("Walking", "Satyr_01_Walking_006.png")), (characterHeight, characterWidth)), pygame.transform.scale(pygame.image.load(os.path.join("Walking", "Satyr_01_Walking_007.png")), (characterHeight, characterWidth)), pygame.transform.scale(pygame.image.load(os.path.join("Walking", "Satyr_01_Walking_008.png")), (characterHeight, characterWidth)), pygame.transform.scale(pygame.image.load(os.path.join("Walking", "Satyr_01_Walking_009.png")), (characterHeight, characterWidth)), pygame.transform.scale(pygame.image.load(os.path.join("Walking", "Satyr_01_Walking_010.png")), (characterHeight, characterWidth)), pygame.transform.scale(pygame.image.load(os.path.join("Walking", "Satyr_01_Walking_011.png")), (characterHeight, characterWidth)), pygame.transform.scale(pygame.image.load(os.path.join("Walking", "Satyr_01_Walking_012.png")), (characterHeight, characterWidth)), pygame.transform.scale(pygame.image.load(os.path.join("Walking", "Satyr_01_Walking_013.png")), (characterHeight, characterWidth)), pygame.transform.scale(pygame.image.load(os.path.join("Walking", "Satyr_01_Walking_014.png")), (characterHeight, characterWidth)), pygame.transform.scale(pygame.image.load(os.path.join("Walking", "Satyr_01_Walking_015.png")), (characterHeight, characterWidth)), pygame.transform.scale(pygame.image.load(os.path.join("Walking", "Satyr_01_Walking_016.png")), (characterHeight, characterWidth)), pygame.transform.scale(pygame.image.load(os.path.join("Walking", "Satyr_01_Walking_017.png")), (characterHeight, characterWidth)), ] IdleList = [pygame.transform.scale(pygame.image.load(os.path.join("Idle", "Satyr_01_Idle_000.png")), (characterHeight, characterWidth)), pygame.transform.scale(pygame.image.load(os.path.join("Idle", "Satyr_01_Idle_001.png")), (characterHeight, characterWidth)), pygame.transform.scale(pygame.image.load(os.path.join("Idle", "Satyr_01_Idle_002.png")), (characterHeight, characterWidth)), pygame.transform.scale(pygame.image.load(os.path.join("Idle", "Satyr_01_Idle_003.png")), (characterHeight, characterWidth)), pygame.transform.scale(pygame.image.load(os.path.join("Idle", "Satyr_01_Idle_004.png")), (characterHeight, characterWidth)), pygame.transform.scale(pygame.image.load(os.path.join("Idle", "Satyr_01_Idle_005.png")), (characterHeight, characterWidth)), pygame.transform.scale(pygame.image.load(os.path.join("Idle", "Satyr_01_Idle_006.png")), (characterHeight, characterWidth)), pygame.transform.scale(pygame.image.load(os.path.join("Idle", "Satyr_01_Idle_007.png")), (characterHeight, characterWidth)), pygame.transform.scale(pygame.image.load(os.path.join("Idle", "Satyr_01_Idle_008.png")), (characterHeight, characterWidth)), pygame.transform.scale(pygame.image.load(os.path.join("Idle", "Satyr_01_Idle_009.png")), (characterHeight, characterWidth)), pygame.transform.scale(pygame.image.load(os.path.join("Idle", "Satyr_01_Idle_010.png")), (characterHeight, characterWidth)), pygame.transform.scale(pygame.image.load(os.path.join("Idle", "Satyr_01_Idle_011.png")), (characterHeight, characterWidth)), ] JumpList = [pygame.transform.scale(pygame.image.load(os.path.join("Jump Loop", "Satyr_01_Jump Loop_000.png")), (characterHeight, characterWidth)), pygame.transform.scale(pygame.image.load(os.path.join("Jump Loop", "Satyr_01_Jump Loop_001.png")), (characterHeight, characterWidth)), pygame.transform.scale(pygame.image.load(os.path.join("Jump Loop", "Satyr_01_Jump Loop_002.png")), (characterHeight, characterWidth)), pygame.transform.scale(pygame.image.load(os.path.join("Jump Loop", "Satyr_01_Jump Loop_003.png")), (characterHeight, characterWidth)), pygame.transform.scale(pygame.image.load(os.path.join("Jump Loop", "Satyr_01_Jump Loop_004.png")), (characterHeight, characterWidth)), pygame.transform.scale(pygame.image.load(os.path.join("Jump Loop", "Satyr_01_Jump Loop_005.png")), (characterHeight, characterWidth)), ] IdleBlinkList = [pygame.transform.scale(pygame.image.load(os.path.join("Idle Blink", "Satyr_01_Idle Blinking_000.png")), (characterHeight, characterWidth)), pygame.transform.scale(pygame.image.load(os.path.join("Idle Blink", "Satyr_01_Idle Blinking_001.png")), (characterHeight, characterWidth)), pygame.transform.scale(pygame.image.load(os.path.join("Idle Blink", "Satyr_01_Idle Blinking_002.png")), (characterHeight, characterWidth)), pygame.transform.scale(pygame.image.load(os.path.join("Idle Blink", "Satyr_01_Idle Blinking_003.png")), (characterHeight, characterWidth)), pygame.transform.scale(pygame.image.load(os.path.join("Idle Blink", "Satyr_01_Idle Blinking_004.png")), (characterHeight, characterWidth)), pygame.transform.scale(pygame.image.load(os.path.join("Idle Blink", "Satyr_01_Idle Blinking_005.png")), (characterHeight, characterWidth)), pygame.transform.scale(pygame.image.load(os.path.join("Idle Blink", "Satyr_01_Idle Blinking_006.png")), (characterHeight, characterWidth)), pygame.transform.scale(pygame.image.load(os.path.join("Idle Blink", "Satyr_01_Idle Blinking_007.png")), (characterHeight, characterWidth)), pygame.transform.scale(pygame.image.load(os.path.join("Idle Blink", "Satyr_01_Idle Blinking_008.png")), (characterHeight, characterWidth)), pygame.transform.scale(pygame.image.load(os.path.join("Idle Blink", "Satyr_01_Idle Blinking_009.png")), (characterHeight, characterWidth)), pygame.transform.scale(pygame.image.load(os.path.join("Idle Blink", "Satyr_01_Idle Blinking_010.png")), (characterHeight, characterWidth)), pygame.transform.scale(pygame.image.load(os.path.join("Idle Blink", "Satyr_01_Idle Blinking_011.png")), (characterHeight, characterWidth))] """ def reset_level(lvl): player.reset(100, HEIGHT - 130) blob_group.empty() tele_group.empty() # load in level data and create world if path.exists(f'level{lvl}_data'): pickle_in = open(f'level{lvl}_data', 'rb') world_data = pickle.load(pickle_in) world = World(world_data) return world class World(): def __init__(self, data): self.tile_list = [] # load images grass_img = pygame.transform.scale(pygame.image.load(os.path.join("tiles/1 Tiles/2.png")), (Block_heigh, Block_width)) dirt_img = pygame.transform.scale(pygame.image.load(os.path.join("tiles/1 Tiles/1.png")), (Block_heigh, Block_width)) row_count = 0 for row in data: col_count = 0 for tile in row: if tile == 1: img = pygame.transform.scale(grass_img, (Block_width, Block_width)) img_rect = img.get_rect() img_rect.x = col_count * Block_width img_rect.y = row_count * Block_width tile = (img, img_rect) self.tile_list.append(tile) if tile == 0: img = pygame.transform.scale(dirt_img, (Block_width, Block_width)) img_rect = img.get_rect() img_rect.x = col_count * Block_width img_rect.y = row_count * Block_width tile = (img, img_rect) self.tile_list.append(tile) if tile == 2: blob = Enemy(col_count * Block_width, row_count * Block_width - 15) blob_group.add(blob) if tile == 3: tele = Teleport(col_count * Block_width, row_count * Block_width - 15) tele_group.add(tele) col_count += 1 row_count += 1 def draw(self): for tile in self.tile_list: WIN.blit(tile[0], tile[1]) Tree = pygame.transform.scale(pygame.image.load(os.path.join("Willows", "3.png")), (350, 300)) WIN.blit(Tree, (450, 420)) Tombstone = pygame.transform.scale(pygame.image.load(os.path.join("Stones", "1.png")), (80, 70)) WIN.blit(Tombstone, (470, 650)) class Player(pygame.sprite.Sprite): def __init__(self, x, y, health=100): self.images_right = [] self.images_left = [] self.inx = 0 self.counter = 0 for num in range(0, 18): img_right = pygame.image.load(f"Player/Walking/Satyr_01_Walking_{num}.png") img_right = pygame.transform.scale(img_right, (characterWidth, characterHeight)) img_left = pygame.transform.flip(img_right, True, False) self.images_right.append(img_right) self.images_left.append(img_left) self.image = self.images_right[self.inx] self.rect = self.image.get_rect() self.rect.x = x + 40 self.rect.y = y self.rect.width = 40 self.rect.height = 60 self.height = self.image.get_height() self.width = self.image.get_width() self.palyer_img = None self.direction = 0 self.char_vel = 0 self.jumped = False self.jumpingcounter = 0 Tombstone = pygame.transform.scale(pygame.image.load(os.path.join("Stones", "1.png")), (80, 70)) WIN.blit(Tombstone, (470, 650)) self.Tombstone = Tombstone.get_rect() self.jump_s = pygame.mixer.Sound('music/jump.sound.mp3') self.jump_s.set_volume(0.4) self.collect_crystal_sound = pygame.mixer.Sound('music/coinsound.mp3') self.collect_crystal_sound.set_volume(0.1) self.crystalcounter = 0 def update(self): hx = 0 hy = 0 walk_cooldown = 1 # jumping&Moving&Gravity # 1.0-Jumping keys = pygame.key.get_pressed() if keys[pygame.K_SPACE] and self.jumped == False: self.char_vel = -15 self.jumpingcounter += 1 self.jumped = True self.jump_s.play() if keys[pygame.K_SPACE] == False: self.jumped = False # 1.1-Moving if keys[pygame.K_a]: hx -= 5 self.counter += 1 self.direction = -1 if keys[pygame.K_d]: hx += 5 self.counter += 1 self.direction = 1 if keys[pygame.K_a] == False and keys[pygame.K_d] == False: self.counter = 0 self.inx = 0 self.image = self.images_right[self.inx] # Animation if self.counter > walk_cooldown: self.counter = 0 self.inx += 1 if self.inx >= len(self.images_right): self.inx = 0 if self.direction == 1: self.image = self.images_right[self.inx] if self.direction == -1: self.image = self.images_left[self.inx] # 1.2-Gravity self.char_vel += 1 if self.char_vel > 7: self.char_vel = 7 hy += self.char_vel # Collisions for tile in world.tile_list: if tile[1].colliderect(self.rect.x + hx, self.rect.y, self.rect.width, self.rect.height): hx = 0 if tile[1].colliderect(self.rect.x, self.rect.y + hy, self.rect.width, self.rect.height): if self.char_vel < 0: hy = tile[1].bottom - self.rect.top self.char_vel = 0 elif self.char_vel >= 0: hy = tile[1].top - self.rect.bottom self.char_vel = 0 # collisons with Crystals if pygame.sprite.spritecollide(self, blob_group, True): print("Stretli sa") self.collect_crystal_sound.play() self.crystalcounter += 1 return self.crystalcounter # collisons with Teleport if pygame.sprite.spritecollide(self, tele_group, False): game_over = 1 print("teleport") self.rect.x += hx self.rect.y += hy if self.rect.bottom > HEIGHT: self.rect.bottom = HEIGHT hy = 0 if self.crystalcounter == 5: tele_group.draw(WIN) tele_group.update() imgsrect = self.image.get_rect() imgsrect.x = self.rect.x - 34 imgsrect.y = self.rect.y - 10 WIN.blit(self.image, imgsrect) class Lava(pygame.sprite.Sprite): def __init__(self, x, y): pygame.sprite.Sprite.__init__(self) self.image = pygame.transform.scale(pygame.image.load(os.path.join("lava", "lava_tile1.png")), (Block_heigh, Block_width)) self.rect = self.image.get_rect() self.rect.x = x self.rect.y = y self.move_lava = -5 def update(self): self.rect.y += self.move_lava """ def draw(self): WIN.blit(self.image, (450, 420)) """ class Enemy(pygame.sprite.Sprite): def __init__(self, x, y, ): pygame.sprite.Sprite.__init__(self) self.image = pygame.transform.scale(pygame.image.load(os.path.join("tiles/1 Tiles/3.png")), (Block_heigh, Block_width)) self.rect = self.image.get_rect() self.rect.x = x self.rect.y = y self.move = -1 self.move_counter = 0 def update(self): self.rect.y += self.move self.move_counter += 1 if self.move_counter > 15: self.move *= -1 self.move_counter = 0 class Teleport(pygame.sprite.Sprite): def __init__(self, x, y, ): pygame.sprite.Sprite.__init__(self) self.image = pygame.transform.scale(pygame.image.load(os.path.join("tiles/1 Tiles/4.png")), (Block_heigh, Block_width)) self.rect = self.image.get_rect() self.rect.x = x self.rect.y = y self.moveteleport = -1 self.move_counter_teleport = 0 def update(self): self.rect.y += self.moveteleport self.move_counter_teleport += 1 if self.move_counter_teleport > 15: self.moveteleport *= -1 self.move_counter_teleport = 0 # main----------------- backgroundmusic() shoot_s.play() player = Player(400, HEIGHT - 40) blob_group = pygame.sprite.Group() tele_group = pygame.sprite.Group() pickle_in = open(f"level{lvl}_data", "rb") world_data = pickle.load(pickle_in) world = World(world_data) while run: world.draw() clock.tick(FPS) player.update() pygame.display.update() WIN.blit(Background, (0, 0)) """ Lava.draw() """ """ Lava.update() """ blob_group.draw(WIN) blob_group.update() game_over = player.update(game_over) if game_over == 1: lvl += 1 if lvl <= maxlevels: world_data = [] world = reset_level(lvl) game_over = 0 else: pass for event in pygame.event.get(): if event.type == pygame.QUIT: run = False
Stars
0
Forks
0
Watchers
0
Open Issues
0
Overall repository health assessment
No language data available
No package.json found
This might not be a Node.js project
1
commits