def _initialize_sprites(self): """Alustaa pelikentän tausta-, seinä- ja teksti-spritet.""" height = 22 width = 18 for row in range(height): for col in range(width): x_coordinate = col * 25 y_coordinate = row * 25 if (0 < row < 21 and 0 < col < 11) or (0 < row < 6 and 11 < col < 17): self._backgrounds.add( Background(x_coordinate, y_coordinate)) else: self._obstacles.add(Wall(x_coordinate, y_coordinate)) score_text = Text("score", 300, 200, 30) level_text = Text("level", 300, 275, 30) self.all_sprites.add(self._backgrounds, self._obstacles, self._score, self._level, self.start_game_button, score_text, level_text)
def setBackground(x, y): backgrounds.append(Background()) backgrounds[len(backgrounds) - 1].set_dimensions(1280, 720) backgrounds[len(backgrounds) - 1].y_pos = y backgrounds[len(backgrounds) - 1].x_pos = x
def level_4(test, win, character, energy_time1, energy_time2): for i in range(26): # set floors if i > 3 and i < 22: setPlatform(i * 50, 670, 1, 1) else: setPlatform(i * 50, 670, 1, 0) for i in range(18): if i > 0 and i < 17: setPlatform(200 + i * 50, 620, 1, 1) else: setPlatform(200 + i * 50, 620, 1, 0) for i in range(16): if i > 1 and i < 14: setPlatform(250 + i * 50, 570, 1, 1) else: setPlatform(250 + i * 50, 570, 1, 0) for i in range(12): if i > 0 and i < 11: setPlatform(350 + i * 50, 520, 1, 1) else: setPlatform(350 + i * 50, 520, 1, 0) for i in range(10): if i > 1 and i < 8: setPlatform(400 + i * 50, 470, 1, 1) else: setPlatform(400 + i * 50, 470, 1, 0) for i in range(6): if i > 0 and i < 5: setPlatform(500 + i * 50, 420, 1, 1) else: setPlatform(500 + i * 50, 420, 1, 0) setPlatform(550, 370, 3, 0) setPlatform(700, 370, 1, 1) setPlatform(100, 400, 3, 0) setVirus(200, 570) setVirus(500, 370) setSink(640, 320) setPlatform(700, 320, 1, 0) # border for i in range(12): setWall(0, 720 - 100 - 50 * i) setWall(1230, 720 - 100 - 50 * i) setDisinfect(110, 355) setDoors(60, 570) setDoors(1140, 570) # fill level surface level = pygame.Surface((1280, 720)) # 960, 640 count = 0 background = Background() background.set_dimensions(1280, 720) level.blit(background.image_cave, (0, 0)) setBackground(0, 0) for i in range(len(floors)): level.blit(floors[i].image_wall_darker, (floors[i].x_pos, floors[i].y_pos)) for i in range(len(platforms)): if platformImages[i] == 1: level.blit(platforms[i].image_soil, (platforms[i].x_pos, platforms[i].y_pos)) else: level.blit(platforms[i].image_grass, (platforms[i].x_pos, platforms[i].y_pos)) for i in range(len(sinks)): level.blit(sinks[i].image_sink, (sinks[i].x_pos, sinks[i].y_pos)) for i in range(len(disinfectants)): level.blit(disinfectants[i].image_disinfectant, (disinfectants[i].x_pos, disinfectants[i].y_pos)) for i in range(len(boxes)): level.blit(boxes[i].image_box, (boxes[i].x_pos, boxes[i].y_pos)) level.blit(doors[0].door_entrance, (doors[0].x_pos, doors[0].y_pos)) level.blit(doors[1].door_exit, (doors[1].x_pos, doors[1].y_pos)) # ---for testing only if test: window_x_size = 1280 window_y_size = 720 pygame.init() win = pygame.display.set_mode((window_x_size, window_y_size)) pygame.display.set_caption("Testing environment.") count = 0 while True: pygame.time.delay(40) win.fill((0, 0, 0)) win.blit(level, (0 - (count * 5), 0)) # count += 1 pygame.display.update() pygame.quit() # if not for testing return level surface else: return start_level_4(win, character, energy_time1, energy_time2)
from sprites.Player import Player from sprites.enemy import Controller import sprites.bullet as bullets from sprites.background import Background pygame.init() loader.load() pygame.display.set_mode(global_vars.SCREEN_SIZE) pygame.display.set_caption("Hell Of Bullets") player = Player() controller = Controller() clk = pygame.time.Clock() bg = Background() WHITE = (255,255,255) running=True while running: deltaT = clk.tick(60)/1000 events.process_events() if events.QUIT: running = False # Fizyka player.update(deltaT) controller.update(deltaT)
def level_3(test, win, character, energy_time1, energy_time2): for i in range(26): # set floors if i == 12 or i == 21: setPlatform(i * 50, 670, 1, 1) else: setPlatform(i * 50, 670, 1, 0) # border for i in range(12): setWall(0, 720 - 100 - 50 * i) setWall(1230, 720 - 100 - 50 * i) # set middle wall for i in range(10): setPlatform(600, 620 - 50 * i, 1, 1) setPlatform(350, 120, 3, 0) setPlatform(500, 120, 1, 1) setPlatform(550, 120, 2, 0) # set door wall for i in range(6): if i == 5: setPlatform(1050, 620 - 50 * i, 1, 0) else: setPlatform(1050, 620 - 50 * i, 1, 1) setPlatform(70, 470, 3, 0) setPlatform(550, 530, 1, 0) setPlatform(320, 370, 4, 0) setPlatform(120, 220, 2, 0) setPlatform(720, 550, 5, 0) setPlatform(500, 70, 1, 0) setVirus(250, 620) setVirus(410, 70) setVirus(670, 620) setVirus(950, 620) setVirus(750, 500) setGloves(350, 620) setGloves(1000, 620) setSink(550, 70) setBox(450, 620) setBox(410, 320) setBox(820, 500) setDoors(60, 570) setDoors(1140, 570) # fill level surface level = pygame.Surface((1280, 720)) # 960, 640 count = 0 background = Background() background.set_dimensions(1280, 720) level.blit(background.image_cave, (0, 0)) setBackground(0, 0) for i in range(len(floors)): level.blit(floors[i].image_wall_darker, (floors[i].x_pos, floors[i].y_pos)) for i in range(len(platforms)): if (i > 25 and i < 36) or i == 39 or i == 12 or (i > 41 and i < 47) or i == 21: level.blit(platforms[i].image_soil, (platforms[i].x_pos, platforms[i].y_pos)) continue level.blit(platforms[i].image_grass, (platforms[i].x_pos, platforms[i].y_pos)) for i in range(len(sinks)): level.blit(sinks[i].image_sink, (sinks[i].x_pos, sinks[i].y_pos)) for i in range(len(disinfectants)): level.blit(disinfectants[i].image_disinfectant, (disinfectants[i].x_pos, disinfectants[i].y_pos)) for i in range(len(boxes)): level.blit(boxes[i].image_box, (boxes[i].x_pos, boxes[i].y_pos)) level.blit(doors[0].door_entrance, (doors[0].x_pos, doors[0].y_pos)) level.blit(doors[1].door_exit, (doors[1].x_pos, doors[1].y_pos)) # ---for testing only if test: window_x_size = 1280 window_y_size = 720 pygame.init() win = pygame.display.set_mode((window_x_size, window_y_size)) pygame.display.set_caption("Testing environment.") count = 0 while True: pygame.time.delay(40) win.fill((0, 0, 0)) win.blit(level, (0 - (count * 5), 0)) # count += 1 pygame.display.update() pygame.quit() # if not for testing return level surface else: return start_level_3(win, character, energy_time1, energy_time2)
def level_5(test, win, character, energy_time1, energy_time2): for i in range(103): # set floors if (i > 22 and i < 25) or i == 60: setPlatform(i * 50, 670, 1, 1) else: setPlatform(i * 50, 670, 1, 0) setPlatform(250, 520, 4, 0) setBox(280, 470) setPlatform(170, 300, 2, 0) setDisinfect(170, 250) setPlatform(650, 470, 3, 0) setPlatform(950, 370, 10, 0) setPlatform(1000, 420, 8, 1) setPlatform(1100, 470, 4, 1) setPlatform(1150, 520, 2, 1) setPlatform(1150, 570, 2, 1) setPlatform(1150, 620, 2, 1) setVirus(250, 620) setVirus(265, 620) setVirus(280, 620) setVirus(295, 620) setVirus(310, 620) setBox(1140, 320) setSink(1250, 620) setPlatform(1600, 200, 1, 0) setDisinfect(1600, 150) for i in range(4): setPlatform(1800 + i * 70, 50 + 150 * i, 7, 0) if i != 0: setBox(1870 + i * 80, 150 * i) setBox(2030 + i * 80, 150 * i) for y in range(3): setBox(1870 + i * 250, 620) setPlatform(2500, 350, 4, 0) setBox(2550, 300) for i in range(9): setPlatform(3000, 620 - i * 50, 1, 1) setPlatform(2900, 170, 8, 0) setBox(3050, 120) setPlatform(3050, 350, 5, 0) setSink(3050, 300) for i in range(11): if i == 0: setPlatform(3500, 10, 1, 0) setPlatform(4100, 170, 1, 0) else: setPlatform(3500, 10 + i * 50, 1, 1) setPlatform(4100, 170 + i * 50, 1, 1) setPlatform(3550, 510, 9, 0) setPlatform(3550, 150, 9, 0) setPlatform(3700, 350, 8, 0) setPlatform(3450, 280, 1, 0) setSink(3550, 100) setBox(3950, 620) setBox(3800, 300) # border for i in range(12): setWall(0, 720 - 100 - 50 * i) setWall(1230 + 1280 * 2 + 640, 720 - 100 - 50 * i) setDoors(60, 570) setDoors(1140 + 1280 * 2 + 640, 570) # fill level surface level = pygame.Surface((1280 * 3 + 640, 720)) # 960, 640 count = 0 background = Background() background.set_dimensions(1280, 720) level.blit(background.image_cave, (0, 0)) level.blit(background.image_cave, (1280, 0)) level.blit(background.image_cave, (1280 * 2, 0)) level.blit(background.image_cave, (1280 * 3, 0)) for i in range(len(floors)): level.blit(floors[i].image_wall_darker, (floors[i].x_pos, floors[i].y_pos)) for i in range(len(platforms)): if platformImages[i] == 1: level.blit(platforms[i].image_soil, (platforms[i].x_pos, platforms[i].y_pos)) else: level.blit(platforms[i].image_grass, (platforms[i].x_pos, platforms[i].y_pos)) for i in range(len(sinks)): level.blit(sinks[i].image_sink, (sinks[i].x_pos, sinks[i].y_pos)) for i in range(len(disinfectants)): level.blit(disinfectants[i].image_disinfectant, (disinfectants[i].x_pos, disinfectants[i].y_pos)) for i in range(len(boxes)): level.blit(boxes[i].image_box, (boxes[i].x_pos, boxes[i].y_pos)) level.blit(doors[0].door_entrance, (doors[0].x_pos, doors[0].y_pos)) level.blit(doors[1].door_exit, (doors[1].x_pos, doors[1].y_pos)) # ---for testing only if test: window_x_size = 1280 window_y_size = 720 pygame.init() win = pygame.display.set_mode((window_x_size, window_y_size)) pygame.display.set_caption("Testing environment.") count = 0 while True: pygame.time.delay(6) win.fill((0, 0, 0)) win.blit(level, (0 - (count * 5), 0)) count += 1 pygame.display.update() pygame.quit() # if not for testing return level surface else: return start_level_5(win, character, energy_time1, energy_time2)
def load_data(self): self.dir = path.dirname(__file__) self.img_dir = path.join(self.dir, "img") self.background = Background(path.join(self.img_dir, "bg.jpg"), [0, 0]) self.background.image = pg.transform.scale(self.background.image, (WIDTH, HEIGHT))
from config import FPS_CLOCK, FPS, displaysurface, hit_cooldown, enemy_stun_cooldown 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()
def level_2(test): for i in range(26): #set floors if (i > 5 and i < 14): setPlatform(i * 50, 670, 1, 1) else: setPlatform(i * 50, 670, 1, 0) #border for i in range(12): setWall(0, 720 - 100 - 50 * i) setWall(1230, 720 - 100 - 50 * i) setPlatform(680, 420, 2, 0) setPlatform(200, 300, 6, 0) setPlatform(200, 250, 1, 1) setBox(340, 570) setBox(930, 620) setPlatform(300, 620, 8, 0) setSink(250, 250) #setMask(310, 70) #setDisinfect(180, 405) setDoors(60, 570) setDoors(1140, 570) #fill level surface level = pygame.Surface((1280, 720)) #960, 640 count = 0 background = Background() background.set_dimensions(1280, 720) level.blit(background.image_cave, (0, 0)) setBackground(0, 0) for i in range(len(floors)): level.blit(floors[i].image_wall_darker, (floors[i].x_pos, floors[i].y_pos)) for i in range(len(platforms)): if platformImages[i] == 1: level.blit(platforms[i].image_soil, (platforms[i].x_pos, platforms[i].y_pos)) else: level.blit(platforms[i].image_grass, (platforms[i].x_pos, platforms[i].y_pos)) for i in range(len(sinks)): level.blit(sinks[i].image_sink, (sinks[i].x_pos, sinks[i].y_pos)) for i in range(len(disinfectants)): level.blit(disinfectants[i].image_disinfectant, (disinfectants[i].x_pos, disinfectants[i].y_pos)) for i in range(len(boxes)): level.blit(boxes[i].image_box, (boxes[i].x_pos, boxes[i].y_pos)) level.blit(doors[0].image_entrance, (doors[0].x_pos, doors[0].y_pos)) level.blit(doors[1].image_exit, (doors[1].x_pos, doors[1].y_pos)) #---for testing only if test: window_x_size = 1280 window_y_size = 720 pygame.init() win = pygame.display.set_mode((window_x_size, window_y_size)) pygame.display.set_caption("Testing environment.") count = 0 while True: pygame.time.delay(40) win.fill((0, 0, 0)) win.blit(level, (0 - (count * 5), 0)) #count += 1 pygame.display.update() pygame.quit() #if not for testing return level surface else: start_level_2()