class Player(pygame.Rect): """Handles player input, logic, and display""" def __init__(self, surface): """Constructor""" super(Player, self).__init__(PLAYER_X, PLAYER_Y, PLAYER_WID, PLAYER_HT) self.surface = surface self.bullet_manager = BulletManager() self.gun = Gun(self, surface) self.sword = Sword(self) self.speed = 10 self.ammo = 6 self.status = 'GROUND' self.facing = 'RSTOP' self.current_weapon = 'GUN' self.lives = 3 self.hit = [0, 0] self.jump_offset = 200 def move(self, levelloader): """Handles x movement and collisions""" self.hit = levelloader.check_collisions(self, False) if self.facing == 'LEFT': if self.x > PLAYER_WID: self.x -= PLAYER_SPEED if self.facing == 'RIGHT': if self.x < SCREEN_WIDTH/2: self.x += PLAYER_SPEED elif self.x >= SCREEN_WIDTH/2 and not levelloader.end_of_level: levelloader.shift(self.speed) else: self.x += PLAYER_SPEED def update_jump(self): """Updates game based on player input""" if self.status == 'RISE' and self.y > PLAYER_JUMP_HT-self.jump_offset: self.y -= PLAYER_GRAVITY elif self.status == 'FALL' and self.y < SCREEN_HEIGHT-PLAYER_HT-GROUND_HEIGHT and self.status != 'GROUND': self.y += PLAYER_GRAVITY else: self.status = 'GROUND' def die(self): """Handles player death""" player_death_sound.play() self.lives -= 1 self.x = PLAYER_X self.y = PLAYER_Y def update(self): if self.current_weapon == 'GUN': self.gun.draw() elif self.current_weapon == 'SWORD': self.sword.update() pygame.draw.rect(self.surface, LIGHT_GREY, self.sword, 0)
class Player(pygame.Rect): """Handles player input, logic, and display""" def __init__(self, surface): """Constructor""" super(Player, self).__init__(PLAYER_X, PLAYER_Y, PLAYER_WID, PLAYER_HT) self.surface = surface self.bullet_manager = BulletManager() self.gun = Gun(self, surface) self.sword = Sword(self) self.speed = 10 self.ammo = 6 self.status = 'GROUND' self.facing = 'RSTOP' self.current_weapon = 'GUN' self.lives = 3 self.hit = [0, 0] self.jump_offset = 200 def move(self, levelloader): """Handles x movement and collisions""" self.hit = levelloader.check_collisions(self, False) if self.facing == 'LEFT': if self.x > PLAYER_WID: self.x -= PLAYER_SPEED if self.facing == 'RIGHT': if self.x < SCREEN_WIDTH / 2: self.x += PLAYER_SPEED elif self.x >= SCREEN_WIDTH / 2 and not levelloader.end_of_level: levelloader.shift(self.speed) else: self.x += PLAYER_SPEED def update_jump(self): """Updates game based on player input""" if self.status == 'RISE' and self.y > PLAYER_JUMP_HT - self.jump_offset: self.y -= PLAYER_GRAVITY elif self.status == 'FALL' and self.y < SCREEN_HEIGHT - PLAYER_HT - GROUND_HEIGHT and self.status != 'GROUND': self.y += PLAYER_GRAVITY else: self.status = 'GROUND' def die(self): """Handles player death""" player_death_sound.play() self.lives -= 1 self.x = PLAYER_X self.y = PLAYER_Y def update(self): if self.current_weapon == 'GUN': self.gun.draw() elif self.current_weapon == 'SWORD': self.sword.update() pygame.draw.rect(self.surface, LIGHT_GREY, self.sword, 0)
def shoot(self, option=None): if option == None and not self.shooting and not self.reloading: if self.gun == "pistol": if self.pistolAmmo > 0: self.pistolAmmo -= 1 self.currentAmmo = self.pistolAmmo self.shootDelay = 1 self.shooting = True return PistolBullet(self.rect.center, self.angle) elif self.gun == "uzi": if self.uziAmmo > 0: self.uziAmmo -= 1 self.currentAmmo = self.uziAmmo self.shootDelay = 1 self.shooting = True return UziBullet(self.rect.center, self.angle) elif self.gun == "shotgun": if self.shotgunAmmo > 0: self.shotgunAmmo -= 1 self.currentAmmo = self.shotgunAmmo self.shootDelay = 1 self.shooting = True return ShotgunBullet(self.rect.center, self.angle) elif self.gun == "sword": if self.swordAmmo > 0: self.swordAmmo -= 1 self.currentAmmo = self.swordAmmo self.shootDelay = 1 self.shooting = True return Sword(self.rect.center, self.angle)
def __init__(self, surface): """Constructor""" super(Player, self).__init__(PLAYER_X, PLAYER_Y, PLAYER_WID, PLAYER_HT) self.surface = surface self.bullet_manager = BulletManager() self.gun = Gun(self, surface) self.sword = Sword(self) self.speed = 10 self.ammo = 6 self.status = 'GROUND' self.facing = 'RSTOP' self.current_weapon = 'GUN' self.lives = 3 self.hit = [0, 0] self.jump_offset = 200
def __init__(self, x, y): """Constructor""" super(Enemy, self).__init__(x, y, 20, 40) self.facing = 'LEFT' self.health = 2 self.sword = Sword(self) self.seed1 = randrange(11, 33) self.seed2 = randrange(11, 33) self.stab = True
class Store(object): # If you define a variable in the scope of a class: # This is a class variable and you can access it like # Store.items => [Tonic, Sword] items = [Tonic(), Sword(), SuperTonic(), EvadeTonic()] def do_shopping(self, hero): while True: print("=====================") print("Welcome to the store!") print("=====================") print("You have {} coins.".format(hero.coins)) print("What do you want to do?") count = 1 for item in self.items: print("{}. buy {} ({})".format(count, item.name, item.cost)) count += 1 print("10. leave") keyinput = int(input("> ")) if keyinput == 10: break else: hero.buy(self.items[keyinput - 1])
def run_game(): # Get access to our game settings settings = Settings() # initialize game pygame.init() screen = pygame.display.set_mode( (settings.screen_width, settings.screen_height), 0, 32) clock = pygame.time.Clock() scoreboard = Scoreboard(screen, settings) play_button = Button( screen, settings.screen_width / 2 - settings.button_width / 2, settings.screen_height / 2 - settings.button_height / 2, settings, "Start Balloon Ninja") game_over_button = Button( screen, play_button.x_position, play_button.y_position - 2 * settings.button_height, settings, "Game Over") instructions = Instructions(screen, settings) # Create a list to hold our balloons, and our kittens balloons = [] #kittens = [] # Create our dagger sword = Sword(screen, settings.scoreboard_height) # Create our game engine, with access to appropriate game parameters: engine = Engine(screen, settings, scoreboard, balloons, sword) # main event loop while True: rcreen, center = ball.getit(settings.screen_width, settings.screen_height) img = pygame.transform.flip( pygame.transform.rotate(pygame.surfarray.make_surface((rcreen)), 270), True, False) time_passed = clock.tick(50) if center is None or center[0] is None: mousex, mousey = pygame.mouse.get_pos()[0], pygame.mouse.get_pos( )[1] else: mousex, mousey = center mouse_x, mouse_y = pygame.mouse.get_pos()[0], pygame.mouse.get_pos()[1] engine.check_events(play_button, mouse_x, mouse_y) # Redraw the empty screen before redrawing any game objects screen.blit(img, (0, 0)) if settings.game_active: # Update the sword's position and check for popped or disappeared balloons engine.update_sword(mousex, mousey) engine.check_balloons(time_passed, mousex, mousey) # If all balloons have disappeared, either through popping or rising, # release a new batch of balloons. if len(balloons) == 0: # If we are not just starting a game, increase the balloon speed and points per balloon, # and increment batches_finished if scoreboard.balloons_popped > 0: # Increase the balloon speed, and other factors, for each new batch of balloons. settings.balloon_speed *= settings.speed_increase_factor settings.kitten_ratio *= settings.speed_increase_factor settings.points_per_balloon = int( round(settings.points_per_balloon * settings.speed_increase_factor)) scoreboard.batches_finished += 1 # If player has completed required batches, increase batch_size if scoreboard.batches_finished % settings.batches_needed == 0 and scoreboard.batches_finished > 0: settings.batch_size += 1 engine.release_batch() else: # Game is not active, so... # Show play button play_button.blitme() # Show instructions for first few games. if settings.games_played < 3: instructions.blitme() # If a game has just ended, show Game Over button if settings.games_played > 0: game_over_button.blitme() # Display updated scoreboard scoreboard.blitme() # Show the redrawn screen pygame.display.flip()
def LoadGame(self, Surface, music, Things_To_Dump, died=False): self.CreateGame(music) self.Location = Things_To_Dump[0] if self.Location == 'Campo': self.tilemap = self.Campo elif self.Location == 'Dungeon': self.tilemap = self.Dungeon else: self.tilemap = self.Caverna self.player.kill() self.player.add([self.tilemap.SpritesToChoose]) #Agora vamos atualizar as informações do tilemap onde o player se encontra #Primeiro as informações do Player self.player.direction = Things_To_Dump[2][0] self.player.number_of_sprite = Things_To_Dump[2][1] self.player.collisionRect = Things_To_Dump[2][2] self.player.placedPositions = Things_To_Dump[2][3] self.player.Justdied = Things_To_Dump[2][4] self.player.vida = Things_To_Dump[2][5] self.player.vx = Things_To_Dump[2][6] self.player.vy = Things_To_Dump[2][7] self.player.cooldown = Things_To_Dump[2][8] self.player.imunity = Things_To_Dump[2][9] self.player.alive = Things_To_Dump[2][10] self.player.atking = Things_To_Dump[2][11] self.player.digging = Things_To_Dump[2][12] self.player.digged = Things_To_Dump[2][13] self.player.first_pressed = Things_To_Dump[2][14] self.player.pressed = Things_To_Dump[2][15] self.player.cont = Things_To_Dump[2][16] self.player.cont2 = Things_To_Dump[2][17] self.player.numbX = Things_To_Dump[2][18] self.player.numbY = Things_To_Dump[2][19] self.player.item = Things_To_Dump[2][20] self.player.Undelivered = Things_To_Dump[2][21] if self.player.atking: self.player.spritesheet = self.player.atkSheet elif self.player.digging: self.player.spritesheet = self.player.PaSheet elif self.player.vx != 0 or self.player.vy != 0: self.player.spritesheet = self.player.MoveSheet else: self.player.spritesheet = self.player.StopSheet #Construimos as Espadas do jogo for SwordInfo in Things_To_Dump[3]: sword = Sword(self.images['Sword'], (self.player.rect.x - 16, self.player.rect.y - 20), 'Sword', self.player.direction, (self.tilemap.SpritesToChoose, self.tilemap.Swords)) sword.number_of_sprite = SwordInfo[0] sword.image = sword.spritesheet[sword.direction][ sword.number_of_sprite] sword.cont = SwordInfo[1] sword.rect = SwordInfo[2] #Construimos os inimigos do jogo for EnemieInfo in Things_To_Dump[4]: if 'Lesma' == EnemieInfo[0]: inimigo = Lesma( self.tilemap.images['Lesma'], (0, 0), 'Lesma', (self.tilemap.SpritesToChoose, self.tilemap.Enemies)) elif 'Bitch' == EnemieInfo[0]: inimigo = Bitch( self.tilemap.images['Bitch'], (0, 0), 'Bitch', (self.tilemap.SpritesToChoose, self.tilemap.Enemies)) elif 'Planta' == EnemieInfo[0]: inimigo = Planta( self.tilemap.images['Planta'], (0, 0), 'Planta', (self.tilemap.SpritesToChoose, self.tilemap.Enemies)) elif 'Sniper' == EnemieInfo[0]: inimigo = Sniper( self.tilemap.images['Sniper'], (0, 0), 'Sniper', (self.tilemap.SpritesToChoose, self.tilemap.Enemies)) else: inimigo = Zumbi( self.tilemap.images['Zumbi'], (0, 0), 'Zumbi', (self.tilemap.SpritesToChoose, self.tilemap.Enemies)) inimigo.burn = EnemieInfo[1] inimigo.collisionRect = EnemieInfo[2] inimigo.direction = EnemieInfo[3] inimigo.number_of_sprite = EnemieInfo[4] inimigo.vida = EnemieInfo[5] inimigo.cooldown = EnemieInfo[6] inimigo.Max = EnemieInfo[7] inimigo.vy = EnemieInfo[8] inimigo.vx = EnemieInfo[9] inimigo.alive = EnemieInfo[10] inimigo.cont = EnemieInfo[11] inimigo.numbX = EnemieInfo[12] inimigo.numbY = EnemieInfo[13] inimigo.atking = EnemieInfo[14] inimigo.originalPosition = EnemieInfo[15] if not inimigo.alive: if inimigo.burn: inimigo.image = inimigo.cinzas else: inimigo.image = inimigo.deadImage #Construcao de Bombas for BombaInfo in Things_To_Dump[5]: Bomba = Pilastra( self.images['Bomba'], 'Bomba', (0, 0), (self.tilemap.SpritesToChoose, self.tilemap.Bombas)) Bomba.cont = BombaInfo[0] Bomba.number_of_sprite = BombaInfo[1] Bomba.rect = BombaInfo[2] #Construcao de Explosoes for ExploInfo in Things_To_Dump[6]: Explosion = Explosion( self.images['Explosion'], (0, 0), 'Explosion', 0, (self.tilemap.Bombas, self.tilemap.SpritesToChoose)) Explosion.cont = ExploInfo[0] Explosion.number_of_sprite = ExploInfo[1] Explosion.rect = ExploInfo[2] #Contrucao de Animacoes for AniInfo in Things_To_Dump[7]: Animation = DeathAnimation(self.images[AniInfo[0]], (0, 0), AniInfo[0], [self.tilemap.SpritesToChoose]) Animation.rect = AniInfo[1] Animation.image = AniInfo[2] Animation.number_of_sprite = AniInfo[3] Animation.cont = AniInfo[4] #Construcao de Atks for ATKinfo in Things_To_Dump[8]: if ATKinfo[0] == 'AtkZumbi': ATK = ZumbiAtk(self.tilemap.images['Zumbi']['Atk'], (0, 0), ATKinfo[4], ATKinfo[0], [self.tilemap.SpritesToChoose], [ enemy for enemy in self.tilemap.Enemies if enemy.nome == 'Zumbi' ][0]) else: if 'Sniper' in ATKinfo[0]: ATK = Atk(self.tilemap.images['Sniper']['Atk'], (0, 0), ATKinfo[4], ATKinfo[0], ATKinfo[1], [self.tilemap.SpritesToChoose]) else: ATK = Atk(self.tilemap.images['Planta']['Atk'], (0, 0), ATKinfo[4], ATKinfo[0], ATKinfo[1], [self.tilemap.SpritesToChoose]) ATK.number_of_sprite = ATKinfo[2] ATK.alive = ATKinfo[3] ATK.rect = ATKinfo[5] ATK.Max = ATKinfo[6] ATK.cont = ATKinfo[7] #Colocando o menu de Itens self.ItemMenu.Itens = Things_To_Dump[9].Itens self.ItemMenu.selected = Things_To_Dump[9].selected self.ItemMenu.using = Things_To_Dump[9].using self.ItemMenu.menu = Things_To_Dump[9].menu self.ItemMenu.Fala = Things_To_Dump[9].Fala self.Campo.AdjustTileHoleAndRachadura(Things_To_Dump[1][0], self) self.Campo.AdjustJewels(Things_To_Dump[1][0], self) self.Caverna.AdjustTileHoleAndRachadura(Things_To_Dump[1][1], self) self.Caverna.AdjustJewels(Things_To_Dump[1][1], self) self.Dungeon.AdjustTileHoleAndRachadura(Things_To_Dump[1][2], self) self.Dungeon.AdjustJewels(Things_To_Dump[1][2], self) #Verificamos o numero de joias devolvidas self.Delivered = Things_To_Dump[10] #E por ultimo vemos se ja dialogamos com o sr moshiro ou nao self.Campo.Moshiro.first = Things_To_Dump[11] self.tilemap.set_focus(self.player.collisionRect.centerx, self.player.collisionRect.centery) if not died: self.Escroto.SaveGame(self, 'CheckPoint.save', 0, 2, 0) if self.musicPlaying: self.tilemap.InicializeSounds() self.tilemap.SetSound(self) self.SaveTilemaps() #self.ItemMenu.Itens['Safira']['Possui'] = True #self.ItemMenu.Itens['Safira']['Delivered'] = True #self.Delivered += 1 self.ResizeScreen(Surface.get_width(), Surface.get_height()) self.main(Surface)
def game(level_folder, lives): global cameraX, cameraY global current_level pygame.init() screen = pygame.display.set_mode(DISPLAY, pygame.FULLSCREEN) #Създаване на прозореца, задаване на fullscreen pygame.display.set_caption("Robopartans: The Game V1.2") #Задаване на име на прозореца timer = pygame.time.Clock() #Инициализация на таймера pygame.mouse.set_visible(0) #Мишката не се вижда р рамките на прозореца up = left = right = running = False #Всички функции за движение са неактивни directory = 'files/Levels/'+level_folder bg = Surface((32,32)) #Създаване на фона entities = pygame.sprite.Group() player = Player(40, 40, directory, lives) #Създаване на играча от класа Player platforms = [] #Инициализация на списък, в който ще се съхраняват всички активни платформи enemy = [] #Инициализация на списък, в който ще се съхраняват всики противници на играча gears = [] x = y = 0 path_to_map = 'files/Levels/'+level_folder+'/map.txt' f_level = open(path_to_map) level_color = f_level.readline() level = f_level.readlines() f_level.close() level_color = re.sub(r'\n', '', level_color) level_color = re.sub(r'\r', '', level_color) lives_image = pygame.image.load(directory+"/live.png") #Задаване на картинка, която ще илюстрира животите на играча lives_image = pygame.transform.scale(lives_image, (32, 32)) bg.fill(Color(level_color)) #Цвят на фона for row in level: #Всички моделирани елементи се добавят в списъка с активните платформи for col in row: if col == "S": s = Score_line(x, y, directory) platforms.append(s) entities.add(s) if col == "p": p = Platforms(x, y, 108, 32,directory+"/beam_5.png") platforms.append(p) entities.add(p) if col == "P": P = Platforms(x, y, 251, 32,directory+"/beam_11.png") platforms.append(P) entities.add(P) if col == "G": g = Ground(x, y, directory) platforms.append(g) entities.add(g) if col == "T": t = Target(x, y) gears.append(t) entities.add(t) player.gears_count += 1 if col == "B": b = Bad_Platform(x, y) platforms.append(b) entities.add(b) if col == "L": l = Live(x, y, directory) platforms.append(l) entities.add(l) if col == "V": v = Shield(x, y, directory) platforms.append(v) entities.add(v) if col == "I": i = Sword(x, y, directory) platforms.append(i) entities.add(i) if col == "E": e = Enemy(x, y, directory) enemy.append(e) entities.add(e) x += 32 y += 32 x = 0 y = 0 total_level_width = (len(level[0])-2)*32 total_level_height = len(level)*32 camera = Camera(total_level_width, total_level_height) entities.add(player) font = pygame.font.Font('files/Fonts/Adventure Subtitles.ttf',20) #Форматиране на текста в score line-а while 1: timer.tick(60) #Пояснителен текст lives_text = font.render("LIVES:", 1,(255,255,255)) for e in pygame.event.get(): #Проверка за натиснати бутони if e.type == QUIT: raise SystemExit, "QUIT" if e.type == KEYDOWN and e.key == K_ESCAPE: menu_game() if e.type == KEYDOWN and e.key == K_SPACE: up = True if e.type == KEYDOWN and e.key == K_LEFT: left = True if e.type == KEYDOWN and e.key == K_RIGHT: right = True if e.type == KEYUP and e.key == K_SPACE: up = False if e.type == KEYUP and e.key == K_RIGHT: right = False if e.type == KEYUP and e.key == K_LEFT: left = False # Извеждане на фона for y in range(32): for x in range(64): screen.blit(bg, (x*32 , y*32)) #Текст, който показва прогреса по събиране на точки и броя скокове, които са направени # Ъпдейтване на играча и извеждане на всичко останало for i in enemy: i.update(True, platforms, total_level_height) player.update(up, left, right, running, platforms, enemy, gears, total_level_height) for e in entities: screen.blit(e.image, camera.apply(e)) camera.update(player, WIN_WIDTH, WIN_HEIGHT) screen.blit(lives_text, (900 , 4)) for i in range(player.lives): screen.blit(lives_image, ((1100 - i*35), 0)) #Текст, който показва прогреса по събиране на точки и броя скокове, които са направени scoretext = font.render("Score:"+str(player.score)+"/"+str(player.gears_count*16)+" Jumps:"+str(player.jumps), 1,(255,255,255)) screen.blit(scoretext, (10 , 4)) #Проверка дали играта е свършила if player.score == player.gears_count*16: #Ако са събрани всички зъбни колела, изведи съобщение и се върни в началното меню font_end = pygame.font.Font('files/Fonts/Adventure Subtitles.ttf',30) end_text_first_line = font_end.render("Congratulations! ", 1,(255,0,0)) end_text_second_line = font_end.render("You collected maximum points! ", 1,(255,0,0)) screen.blit(end_text_first_line, (500 , 350)) screen.blit(end_text_second_line, (430 , 380)) screen.blit(scoretext, (10 , 4)) pygame.display.update() pygame.time.delay(2000) pygame.event.wait() current_level+=1 game('Level_'+str(current_level), player.lives) if player.lives == 0: #Ако играча е загубил всичките си животи, изведи съобщение и се върни в началното меню font_end = pygame.font.Font('files/Fonts/Adventure Subtitles.ttf',30) end_text_first_line = font_end.render("Game Over! ", 1,(255,0,0)) end_text_second_line = font_end.render("You died!", 1,(255,0,0)) screen.blit(end_text_first_line, (500 , 350)) screen.blit(end_text_second_line, (515 , 380)) pygame.display.update() pygame.time.delay(2000) pygame.event.wait() menu_game() pygame.display.update()
def test_le1(self): sword1 = Sword("Меч1", 50, 1) sword2 = Sword("Меч2", 40, 1) self.assertFalse(sword1.__le__(sword2))
def test_attack(self): sword = Sword("Меч", 50, 1) self.assertEqual(sword.damage, 50)
def test_le2(self): sword1 = Sword("Меч1", 50, 1) sword2 = Sword("Меч2", 40, 1) self.assertTrue(sword2.__le__(sword1))
dif = 2 godCode = [pygame.K_UP, pygame.K_UP, pygame.K_DOWN, pygame.K_LEFT, pygame.K_RIGHT, pygame.K_RIGHT, pygame.K_s, pygame.K_t, pygame.K_a, pygame.K_r, pygame.K_t] codeCount = 0 canScrollUp = False canScrollDown = False godmode = False typed = False hurt = Player_Effects(["rcs/imgs/player/hurt.png"], [0,0], screenSize, 10) map = Level("map1", screenSize) boss = Boss(['rcs/imgs/bosses/boss.png'], [0,0], screenSize, 10) boss.place([300,500]) sword = Sword(screenSize) counter = Counter([45,25], screenSize) healthbar_imgs = [] for i in range(100, 0, -5): healthbar_imgs += ["rcs/imgs/stats_bar/health_bar_" + str(i) + "%.png"] healthbar = Screen(healthbar_imgs, [0, 0], screenSize) healthbar.place([645,13]) energybar_background = Screen(["rcs/imgs/stats_bar/energy_bar_background.png"], [0,0], screenSize) energybar_background.place([640, 25]) energybar_imgs = ["rcs/imgs/stats_bar/nothing.png"] for i in range(5, 105, 5): energybar_imgs += ["rcs/imgs/stats_bar/energy_bar_" + str(i) + "%.png"]
def run_game(): # access to settings #width,height=800,600 settings =Settings() #initialize game pygame.init() sound= 'resources/back_sound.mp3' pygame.mixer.init() pygame.mixer.music.load(sound) pygame.mixer.music.play(-1) pygame.event.wait() screen=pygame.display.set_mode((settings.width,settings.height),0,32) pygame.display.set_caption("PopBob") clock =pygame.time.Clock() scoreboard = Scoreboard(screen, settings) play_button = Button(screen, settings.width/2-settings.button_width/2, settings.height/2-settings.button_height/2, settings, "Play") game_over_button = Button(screen,play_button.x_position, play_button.y_position-2*settings.button_height, settings, "Game Over") #balloons=[Balloon(screen, settings.balloon_speed)] # scoreboard_height=50 # game play params #balloon_speed= 0.1 #points_per_hit=10 instructions = Instructions(screen, settings) #scoreboard=Scoreboard(screen, settings.scoreboard_height) balloons = [] fish = [] #spawn_balloon(screen, settings, balloons) # balloons=[Balloon(screen, settings.balloon_speed)] sword=Sword(screen, settings.scoreboard_height) #new_balloon=Balloon(screen) #bg_image=pygame.image.load('resources/back_pop_ga.jpg') engine = Engine(screen, settings, scoreboard, balloons, fish, sword) while 1: time_passed = clock.tick(50) mouse_x,mouse_y = pygame.mouse.get_pos()[0],pygame.mouse.get_pos()[1] engine.check_events(play_button, mouse_x, mouse_y) print (pygame.mouse.get_pos()) screen.blit(settings.bg_image,(0,0)) if settings.game_active: engine.update_sword(mouse_x, mouse_y) engine.check_balloons(time_passed) engine.check_fishes(time_passed) if len(balloons)==0: if scoreboard.balloons_popped >0: settings.balloon_speed *= settings.speed_increase_factor settings.fish_ratio *= settings.speed_increase_factor settings.points_per_hit = int(round(settings.points_per_hit * settings.speed_increase_factor)) scoreboard.batches_finished +=1 if scoreboard.batches_finished % settings.batches_needed == 0 and scoreboard.batches_finished>0: settings.batch_size+=1 engine.release_batch() else : play_button.blitme() if settings.games_played < 3 : instructions.blitme() if settings.games_played >0: game_over_button.blitme() #displaying the scoreboard scoreboard.blitme() pygame.display.flip()
def LoadGame(self, Surface, music, Things_To_Dump, died = False): self.CreateGame(music) self.Location = Things_To_Dump[0] if self.Location == 'Campo': self.tilemap = self.Campo elif self.Location == 'Dungeon': self.tilemap = self.Dungeon else: self.tilemap = self.Caverna self.player.kill() self.player.add([self.tilemap.SpritesToChoose]) #Agora vamos atualizar as informações do tilemap onde o player se encontra #Primeiro as informações do Player self.player.direction = Things_To_Dump[2][0] self.player.number_of_sprite= Things_To_Dump[2][1] self.player.collisionRect = Things_To_Dump[2][2] self.player.placedPositions = Things_To_Dump[2][3] self.player.Justdied = Things_To_Dump[2][4] self.player.vida = Things_To_Dump[2][5] self.player.vx = Things_To_Dump[2][6] self.player.vy = Things_To_Dump[2][7] self.player.cooldown = Things_To_Dump[2][8] self.player.imunity = Things_To_Dump[2][9] self.player.alive = Things_To_Dump[2][10] self.player.atking = Things_To_Dump[2][11] self.player.digging = Things_To_Dump[2][12] self.player.digged = Things_To_Dump[2][13] self.player.first_pressed = Things_To_Dump[2][14] self.player.pressed = Things_To_Dump[2][15] self.player.cont = Things_To_Dump[2][16] self.player.cont2 = Things_To_Dump[2][17] self.player.numbX = Things_To_Dump[2][18] self.player.numbY = Things_To_Dump[2][19] self.player.item = Things_To_Dump[2][20] self.player.Undelivered = Things_To_Dump[2][21] if self.player.atking: self.player.spritesheet = self.player.atkSheet elif self.player.digging: self.player.spritesheet = self.player.PaSheet elif self.player.vx != 0 or self.player.vy != 0: self.player.spritesheet = self.player.MoveSheet else: self.player.spritesheet = self.player.StopSheet #Construimos as Espadas do jogo for SwordInfo in Things_To_Dump[3]: sword = Sword(self.images['Sword'], (self.player.rect.x - 16, self.player.rect.y - 20), 'Sword', self.player.direction, (self.tilemap.SpritesToChoose, self.tilemap.Swords)) sword.number_of_sprite = SwordInfo[0] sword.image = sword.spritesheet[sword.direction][sword.number_of_sprite] sword.cont = SwordInfo[1] sword.rect = SwordInfo[2] #Construimos os inimigos do jogo for EnemieInfo in Things_To_Dump[4]: if 'Lesma' == EnemieInfo[0]: inimigo = Lesma(self.tilemap.images['Lesma'], (0,0), 'Lesma', (self.tilemap.SpritesToChoose, self.tilemap.Enemies)) elif 'Bitch' == EnemieInfo[0]: inimigo = Bitch(self.tilemap.images['Bitch'], (0,0), 'Bitch', (self.tilemap.SpritesToChoose, self.tilemap.Enemies)) elif 'Planta' == EnemieInfo[0]: inimigo = Planta(self.tilemap.images['Planta'], (0,0), 'Planta', (self.tilemap.SpritesToChoose, self.tilemap.Enemies)) elif 'Sniper' == EnemieInfo[0]: inimigo = Sniper(self.tilemap.images['Sniper'], (0,0), 'Sniper', (self.tilemap.SpritesToChoose, self.tilemap.Enemies)) else: inimigo = Zumbi(self.tilemap.images['Zumbi'], (0,0), 'Zumbi', (self.tilemap.SpritesToChoose, self.tilemap.Enemies)) inimigo.burn = EnemieInfo[1] inimigo.collisionRect = EnemieInfo[2] inimigo.direction = EnemieInfo[3] inimigo.number_of_sprite = EnemieInfo[4] inimigo.vida = EnemieInfo[5] inimigo.cooldown = EnemieInfo[6] inimigo.Max = EnemieInfo[7] inimigo.vy = EnemieInfo[8] inimigo.vx = EnemieInfo[9] inimigo.alive = EnemieInfo[10] inimigo.cont = EnemieInfo[11] inimigo.numbX = EnemieInfo[12] inimigo.numbY = EnemieInfo[13] inimigo.atking = EnemieInfo[14] inimigo.originalPosition = EnemieInfo[15] if not inimigo.alive: if inimigo.burn: inimigo.image = inimigo.cinzas else: inimigo.image = inimigo.deadImage #Construcao de Bombas for BombaInfo in Things_To_Dump[5]: Bomba = Pilastra(self.images['Bomba'], 'Bomba', (0,0), (self.tilemap.SpritesToChoose, self.tilemap.Bombas)) Bomba.cont = BombaInfo[0] Bomba.number_of_sprite = BombaInfo[1] Bomba.rect = BombaInfo[2] #Construcao de Explosoes for ExploInfo in Things_To_Dump[6]: Explosion = Explosion(self.images['Explosion'], (0,0), 'Explosion', 0, (self.tilemap.Bombas, self.tilemap.SpritesToChoose)) Explosion.cont = ExploInfo[0] Explosion.number_of_sprite = ExploInfo[1] Explosion.rect = ExploInfo[2] #Contrucao de Animacoes for AniInfo in Things_To_Dump[7]: Animation = DeathAnimation(self.images[AniInfo[0]], (0,0), AniInfo[0], [self.tilemap.SpritesToChoose]) Animation.rect = AniInfo[1] Animation.image = AniInfo[2] Animation.number_of_sprite = AniInfo[3] Animation.cont = AniInfo[4] #Construcao de Atks for ATKinfo in Things_To_Dump[8]: if ATKinfo[0] == 'AtkZumbi': ATK = ZumbiAtk(self.tilemap.images['Zumbi']['Atk'], (0,0), ATKinfo[4], ATKinfo[0], [self.tilemap.SpritesToChoose], [enemy for enemy in self.tilemap.Enemies if enemy.nome == 'Zumbi'][0]) else: if 'Sniper' in ATKinfo[0]: ATK = Atk(self.tilemap.images['Sniper']['Atk'], (0,0), ATKinfo[4], ATKinfo[0], ATKinfo[1], [self.tilemap.SpritesToChoose]) else: ATK = Atk(self.tilemap.images['Planta']['Atk'], (0,0), ATKinfo[4], ATKinfo[0], ATKinfo[1], [self.tilemap.SpritesToChoose]) ATK.number_of_sprite = ATKinfo[2] ATK.alive = ATKinfo[3] ATK.rect = ATKinfo[5] ATK.Max = ATKinfo[6] ATK.cont = ATKinfo[7] #Colocando o menu de Itens self.ItemMenu.Itens = Things_To_Dump[9].Itens self.ItemMenu.selected = Things_To_Dump[9].selected self.ItemMenu.using = Things_To_Dump[9].using self.ItemMenu.menu = Things_To_Dump[9].menu self.ItemMenu.Fala = Things_To_Dump[9].Fala self.Campo.AdjustTileHoleAndRachadura(Things_To_Dump[1][0], self) self.Campo.AdjustJewels(Things_To_Dump[1][0], self) self.Caverna.AdjustTileHoleAndRachadura(Things_To_Dump[1][1], self) self.Caverna.AdjustJewels(Things_To_Dump[1][1], self) self.Dungeon.AdjustTileHoleAndRachadura(Things_To_Dump[1][2], self) self.Dungeon.AdjustJewels(Things_To_Dump[1][2], self) #Verificamos o numero de joias devolvidas self.Delivered = Things_To_Dump[10] #E por ultimo vemos se ja dialogamos com o sr moshiro ou nao self.Campo.Moshiro.first = Things_To_Dump[11] self.tilemap.set_focus(self.player.collisionRect.centerx, self.player.collisionRect.centery) if not died: self.Escroto.SaveGame(self,'CheckPoint.save', 0, 2,0) if self.musicPlaying: self.tilemap.InicializeSounds() self.tilemap.SetSound(self) self.SaveTilemaps() #self.ItemMenu.Itens['Safira']['Possui'] = True #self.ItemMenu.Itens['Safira']['Delivered'] = True #self.Delivered += 1 self.ResizeScreen(Surface.get_width(), Surface.get_height()) self.main(Surface)