def appStarted(self): #Initialize the level self.margin = 50 self.extra = 200 self.rows = (self.height - 2 * self.margin) // Square.width self.cols = (self.width + self.extra - 2 * self.margin) // Square.width self.endPiece = Square(self.cols - 1, self.rows // 2, self) self.obstacles = self.generateObstacles() self.startWall = Wall(-100, 0) self.endWall = Wall(self.width + self.extra + 10, 0) #Initialize the player and enemies x0, y0, x1, y1 = self.getCellBounds(self.rows // 2, 0) self.player = Player(1000, (x0 + x1) // 2, (y0 + y1) // 2, self) self.scrollX = 0 self.scrollMargin = 50 self.enemies = self.generateEnemies() self.paused = False self.canDrawBullet = False
def main(): pygame.init() pygame.display.set_caption("RPG - Louvain-la-Neuve") screen = pygame.display.set_mode((960, 640)) grid_width = 30 grid_height = 20 clock = pygame.time.Clock() grid = Grid("level.map", screen, (grid_width, grid_height), (0, 0)) player = Player("res/trainer_running.png", (10, 10), grid, 1) screen.blit(grid.background, grid.view_coord) player.blit(screen, 1) pygame.display.flip() current_direction = [0, 0, 0, 0] old_current_direction = current_direction.copy() grid_offset_x = grid.view_coord[0] % (screen.get_rect().width / grid_width) grid_offset_y = grid.view_coord[1] % (screen.get_rect().height / grid_height) #load button and getting his collide zone bouton = pygame.image.load("images/sound_icon.png") bouton_rect = bouton.get_rect() #sound played sound_played = True #load music pygame.mixer.init() pygame.mixer.music.load("sound/lln_sound.wav") pygame.mixer.music.play(-1, 0.0) running = True while running: screen.blit(grid.background, grid.view_coord) player.blit(screen, player.movement(old_current_direction)) bouton = pygame.transform.scale(bouton, (32, 32)) screen.blit(bouton, (0, 0)) pygame.display.flip() clock.tick(60) print(grid.view_coord) grid_offset_x = grid.view_coord[0] % (screen.get_rect().width / grid_width) grid_offset_y = grid.view_coord[1] % (screen.get_rect().height / grid_height) for event in pygame.event.get(): if event.type == pygame.QUIT: running = False updateDirection(event, current_direction) if grid_offset_y + grid_offset_x == 0: grid.view_coord = updateViewCoordinates(grid.view_coord, current_direction, player) old_current_direction = current_direction.copy() #player.updatePos() else: grid.view_coord = updateViewCoordinates(grid.view_coord, old_current_direction, player) ## Si le focus est sur la fenêtre. if pygame.mouse.get_focused(): ## Trouve position de la souris x, y = pygame.mouse.get_pos() ## S'il y a collision: collide = bouton_rect.collidepoint(x, y) ## Détecte les clique de souris. pressed = pygame.mouse.get_pressed() if pressed[0] and collide: # 0=gauche, 1=milieu, 2=droite if sound_played: bouton = pygame.image.load("images/no_sound_icon.png") pygame.mixer.music.stop() sound_played = False else: bouton = pygame.image.load("images/sound_icon.png") pygame.mixer.music.play(-1, 0.0) sound_played = True
def start(self, display): self.display = display n = self.randResp() self.player = Player(n[0] * PLATFORM_WIDTH, n[1] * PLATFORM_HEIGHT) self.entities.add(self.player)
pygame.draw.rect(surface, pygame.Color(115, 74, 1, 255), (80, 752 // 2 - 200, 40, 230)) pygame.draw.circle(surface, pygame.Color(2, 132, 32, 255), (100, 752 // 2 - 200), 90) run = True #кадрики для неподвижног состояния idleRight = load_image('0_Golem_Idle_000.png', 'images//PNG Sequences_golem1//Idle_//') idleLeft = pygame.transform.flip(idleRight, True, False) #когда покраснел idleRightRed = load_image('0_Golem_Idle_000.png', 'images//PNG Sequences_golem1//Idle_Red//') idleLeftRed = pygame.transform.flip(idleRightRed, True, False) man1 = Player(200, 610, idleLeft, idleRight, idleLeftRed, idleRightRed, player_group) #кадрики для бега и удара man1.load_images('0_Golem_Running_0', 'images//PNG Sequences_golem1//Running_', '.png', 12, man1.RightRunFrames, man1.LeftRunFrames) man1.load_images('0_Golem_Slashing_0', 'images//PNG Sequences_golem1//Slashing_', '.png', 12, man1.RightSlashingFrames, man1.LeftSlashingFrames) #аналогично для id2 idleRight = load_image('0_Golem_Idle_000.png', 'images//PNG Sequences_golem3//Idle_//') idleLeft = pygame.transform.flip(idleRight, True, False) man2 = Player(600, 610, idleLeft, idleRight, None, None, player_group) man2.load_images('0_Golem_Running_0', 'images//PNG Sequences_golem3//Running_', '.png', 12, man2.RightRunFrames, man2.LeftRunFrames) man2.load_images('0_Golem_Slashing_0', 'images//PNG Sequences_golem3//Slashing_', '.png', 12,