def update(self): if self.right > games.screen.width or self.left < 0: self.dx = -self.dx if self.top > games.screen.height: self.player_score.value += 1 self.bottom = games.screen.height/2 if self.bottom <= 0: self.comp_score.value += 1 self.top = games.screen.height/2 if (self.player_score.value or self.comp_score.value) == 7: self.destroy() if self.player_score.value < self.comp_score.value: game_over = games.Message(value = 'Player 1 wins!', size = 40, color = color.blue, x = 420, y = 100, lifetime = 250, after_death = games.screen.quit) elif self.comp_score.value < self.player_score.value: game_over = games.Message(value = 'Computer wins!', size = 40, color = color.blue, x = 420, y = 100, lifetime = 250, after_death = games.screen.quit) games.screen.add(game_over)
def main(): # background wall_image = games.load_image("field_background.bmp", transparent=False) games.screen.background = wall_image # when game starts, play sound yahoo_sound = games.load_sound("yahoo.wav") yahoo_sound.play() # begin message start_message = games.Message(value="Kill 20 ducks!", size=90, color=color.blue, x=games.screen.width / 2, y=games.screen.height / 2, lifetime=games.screen.fps) games.screen.add(start_message) directions_spacebar = games.Message(value="Spacebar to shoot!", size=25, color=color.green, is_collideable=False, x=games.screen.width / 4, y=games.screen.height - 20, lifetime=500) games.screen.add(directions_spacebar) directions_turning = games.Message(value="Turn with <- and -> arrow keys!", size=25, color=color.green, is_collideable=False, x=games.screen.width - 225, y=games.screen.height - 20, lifetime=500) games.screen.add(directions_turning) # create 4 ducks for i in range(2): x = random.randrange(games.screen.width) y = random.randrange(400) size = random.choice( [Duck.Duck1, Duck.Duck2, Duck.Duck3, Duck.Shadow_duck]) new_duck = Duck(x=x, y=y, size=size) games.screen.add(new_duck) # add the gun the_gun = Gun(x=games.screen.width / 2, y=games.screen.height) games.screen.add(the_gun) games.mouse.is_visible = False games.screen.event_grab = True games.screen.mainloop()
def update(self): if self.y == (games.screen.height - 140): games.screen.background = games.load_image('img/background_2.jpg', transparent=False) if self.y == (games.screen.height - 200): games.screen.background = games.load_image('img/background_3.jpg', transparent=False) if self.y == (games.screen.height - 260): games.screen.background = games.load_image('img/background_4.jpg', transparent=False) if self.y == (games.screen.height - 340): games.screen.background = games.load_image('img/background_5.jpg', transparent=False) if self.y == (games.screen.height - 420): games.screen.background = games.load_image('img/background_6.jpg', transparent=False) if self.y <= 70: self.timestop = datetime.datetime.now() time = (self.timestop - self.timestart).seconds timetext = 'Ваш результат: ' + str(time) + 'секунд' if time <= 12: text = 'Вы - Мавка' elif 12 < time <= 25: text = 'Вы - Лукаш' else: text = 'Вы - Килина' message_end_1 = games.Message(value='Конец игры', size=50, color=color.brown, x=games.screen.width / 2, y=games.screen.height / 4, lifetime=2 * games.screen.fps, after_death=games.screen.quit) message_end_2 = games.Message(value=timetext, size=50, color=color.brown, x=games.screen.width / 2, y=games.screen.height / 3, lifetime=2 * games.screen.fps, after_death=games.screen.quit) message_end_3 = games.Message(value=text, size=50, color=color.brown, x=games.screen.width / 2, y=games.screen.height * 5 / 12, lifetime=2 * games.screen.fps, after_death=games.screen.quit) games.screen.add(message_end_1) games.screen.add(message_end_2) games.screen.add(message_end_3)
def update(self): #end game and display message if bottom of screen touched. if self.bottom > games.screen.height: self.destroy() end = games.Message("Game Over", size=100, color=color.red, x=games.screen.width / 2, y=games.screen.height / 2, lifetime=250, after_death=games.screen.quit) games.screen.add(end) for Pannel in self.overlapping_sprites: self.score.value += 1 self.score.right = games.screen.width - 10 #determines if the ball will move right or left and #applies a random number to the x and y velocity if games.keyboard.is_pressed(games.K_a): self.dx = random.randint(-4, -1) elif games.keyboard.is_pressed(games.K_d): self.dx = random.randint(1, 4) else: self.dx = self.dx self.dy = random.randint(-5, -1) #collision logic for sprite bouncing of walls and pannel. if self.top < 0: self.dy = -self.dy elif self.left < 0: self.dx = -self.dx elif self.right > games.screen.width: self.dx = -self.dx
def advance(self): """Переводит игру на уровнеь выше""" self.level += 1 # зарезервированное пространство вокруг корабля BUFFER = 150 #создание новых астероидов for i in range(self.level): x_min = random.randrange(BUFFER) y_min = BUFFER - x_min x_distance = random.randrange(x_min, games.screen.width - x_min) y_distance = random.randrange(y_min, games.screen.height - y_min) x = self.ship.x + x_distance y = self.ship.y + y_distance x %= games.screen.width y %= games.screen.height new_asteroid = Asteroid(game=self, x=x, y=y, size=Asteroid.LARGE) games.screen.add(new_asteroid) #отображение номера уровня level_message = games.Message(value="Level " + str(self.level), size=40, color=color.yellow, x=games.screen.width / 2, y=games.screen.width / 10, lifetime=3 * games.screen.fps, is_collideable=False) games.screen.add(level_message) #звуковой эффект перехода (кроме 1 уровня) if self.level > 1: self.sound.play()
def check_catch(self): for pizza in self.overlapping_sprites: self.score.value += 10 self.score.right = games.screen.width - 10 pizza.handle_caught() if self.score.value in range(100, 1000, 100): pizza.speed_up() self.alert() if self.score.value == 10: print('speed', self.chef.dx) print('odds change', self.chef.odds_change) self.chef.speed_change() self.alert() print(self.chef.dx) print(self.chef.odds_change) if self.score.value in range(500, 1500, 200): self.bottom -= 20 self.alert() if self.score.value == 600: self.chef.add_chef() self.alert() if self.score.value == 800: win_message = games.Message(value="You won!", size=90, color=color.red, x=games.screen.width / 2, y=games.screen.height / 2, lifetime=5 * games.screen.fps, after_death=games.screen.quit) games.screen.add(win_message) self.chef.stop()
def update(self): """ Move the bullet """ # add 50 points if you hit a duck with a bullet if self.overlapping_sprites: self.score.value += 1 for sprite in self.overlapping_sprites: sprite.die() self.die() # if 20 ducks have been killed, you win if self.score.value == 20: end_message = games.Message(value="Good job!", size=90, color=color.blue, x=games.screen.width / 2, y=games.screen.height / 2, lifetime=3 * games.screen.fps, after_death=games.screen.quit) games.screen.add(end_message) # if lifetime is up, destroy the bullet self.lifetime -= 1 if self.lifetime == 0: self.destroy()
def advance(self): """ Переводит игру на очередной уровень. """ self.level += 1 # зарезервированное пространство вокруг корабля BUFFER = 150 # создание новых астероидов for i in range(self.level): # вычислим x и y, чтобы от корабля они отстояли минимум на BUFFER пикселов # сначала выберем минимельные отступы по горизонтали и вертикали x_min = random.randrange(BUFFER) y_min = BUFFER - x_min # исходя из этих минимумов, сгенерируем расстояния от корабля по горизонтали и вертикали x_distance = random.randrange(x_min, games.screen.width - x_min) y_distance = random.randrange(y_min, games.screen.height - y_min) # исходя из этих расстояний вычислим экранные координаты x = self.ship.x + x_distance y = self.ship.y + y_distance # если необходимо, вернем объект внутрь окна x %= games.screen.width y %= games.screen.height # создадим астероид new_asteroid = Asteroid(game=self, x=x, y=y, size=Asteroid.LARGE) games.screen.add(new_asteroid) # отображение номера уровня level_message = games.Message(value="Уровень " + str(self.level), size=40, color=color.yellow, x=games.screen.width / 2, y=games.screen.width / 10, lifetime=3 * games.screen.fps, is_collideable=False) games.screen.add(level_message) # звуковой эффект перехода (кроме 1-го уровня) if self.level > 1: self.sound.play()
def rejection(self): rejection_message = games.Message(value = "You cannot build that", size = 70, x = games.mouse.get_x(), y = games.mouse.get_y(), is_collideable = False, lifetime = 1 * games.screen.fps, color = color.red) games.screen.add(rejection_message)
def end_game(self): #End The Game! end_message=games.Message(value='Game Over!', size=90,\ color=color.black, x=games.screen.width/2, y=games.screen.height/2, lifetime=5*games.screen.fps, after_death=games.screen.quit) games.screen.add(end_message)
def die(self): #game over if Ship.lives == 0: explosionSound.play() new_explosion = Explosion(x=self.x, y=self.y) games.screen.add(new_explosion) self.destroy() end_game = games.Message(value="Game Over", size=90, color=color.red, x=games.screen.width / 2, y=games.screen.height / 2, lifetime=5 * games.screen.fps, after_death=games.screen.quit) games.screen.add(end_game) #remove a life and create an explosion else: Ship.hit = 10 Ship.lives -= 1 self.livesShow.value -= 1 explosionSound.play() new_explosion = Explosion(x=self.x, y=self.y) games.screen.add(new_explosion) self.destroy() if self.x < 40: self.x += 40 else: self.x -= 40 ship = Ship(x=self.x, y=500) games.screen.add(ship)
def update(self): """ wykonuje się co klatkę """ self.switch() #naciśnięcie enter rozpoczyna grę if self.state == Director.MENU: if games.keyboard.is_pressed(games.K_RETURN): self.state = Director.PLAY Alien.count = 0 self.game.loaded = 0 self.win = 0 self.alien_count = 0 if self.state == Director.PLAY: #dodanie zestawu naprawczego self.add_repair_kit() self.add_alien() if self.alien_count == Director.MAX_ALIEN and self.win == 0: if Alien.count == 0: self.win = 1 games.screen.clear() win_message = games.Message(value = "You won!", size = 100, color = color.white, x = games.screen.width/2, y = games.screen.height/2, lifetime = games.screen.fps*4, after_death = self.game.show_menu, is_collideable = False) games.screen.add(win_message)
def check_status(self): if Master.new_butts == Button.new_butts and Button.choice > 0: level_message = games.Message(value="Level " + str(int(Game.level) - 1), size=60, color=color.yellow, x=games.screen.width / 2, y=50, lifetime=5 * games.screen.fps, is_collideable=False) games.screen.add(level_message) if self.delay_two <= 0: self.game.score.value += 10 Game.level += 1 self.delay_two = 200 self.delay = 100 Game.color = 1 Master.new_butts = [False, False, False, False, False] Button.new_butts = [False, False, False, False, False] Button.choice = 0 self.game.play() elif self.delay_two > 0: self.delay_two -= 1
def die(self): """ Destroy player's ship, display game over message and quit""" self.destroy() game_over = games.Message(value="GAME OVER", size=60, color=color.red,\ x=WIDTH/2, y=HEIGHT/2, lifetime=180, \ after_death=games.screen.quit) games.screen.add(game_over)
def advance(self): self.level += 1 BUFFER = 150 for i in range(self.level): x_min = random.randrange(BUFFER) y_min = BUFFER - x_min x_distance = random.randrange(x_min, games.screen.width - x_min) y_distance = random.randrange(y_min, games.screen.height - y_min) x = self.ship.x + x_distance y = self.ship.y + y_distance x %= games.screen.width y %= games.screen.height new_asteroid = Asteroid(game=self, x=x, y=y, size=Asteroid.LARGE) games.screen.add(new_asteroid) level_message = games.Message(value="Poziom " + str(self.level), size=40, color=color.yellow, x=games.screen.width / 2, y=games.screen.height / 2, lifetime=3 * games.screen.fps, is_collideable=False) games.screen.add(level_message) if self.level > 1: self.sound.play()
def end_game(self): """ End the game. """ end_message = games.Message(value = "Game Over", size = 90, color = color.red, x = games.screen.width/2, y = games.screen.height/2, lifetime = 5 * games.screen.fps, after_death = games.screen.quit) games.screen.add(end_message)
def wyswietlKomunikat(cls): cls.wiadomosc = games.Message('Czarny analizuje ruch', 70, color.blue, x=games.screen.width / 2, y=games.screen.height / 4, lifetime=(20 * games.screen.fps)) games.screen.add(cls.wiadomosc)
def difficult(self): """Correct difficult in game""" # level 1, increase speed falling rocks if self.score.value == 750: lvl_1_msg = games.Message(value='Rocks fall faster!', size=90, color=color.black, x=games.screen.width / 2, y=games.screen.height / 2, lifetime=0.5 * games.screen.fps) games.screen.add(lvl_1_msg) Rock.speed = 6 # level 2, increase speed falling rocks if self.score.value == 500: lvl_1_msg = games.Message(value='Rocks fall still faster!!', size=90, color=color.black, x=games.screen.width / 2, y=games.screen.height / 2, lifetime=0.5 * games.screen.fps) games.screen.add(lvl_1_msg) Rock.speed = 9 # level 3, increase speed falling rocks if self.score.value == 250: lvl_1_msg = games.Message(value='Carefully!!!', size=90, color=color.black, x=games.screen.width / 2, y=games.screen.height / 2, lifetime=0.5 * games.screen.fps) games.screen.add(lvl_1_msg) Rock.speed = 12 # 0 points = victory if self.score.value == 0: victory_message = games.Message( value='You elude from all rocks! You save himself !', size=40, color=color.purple, x=games.screen.width / 2, y=games.screen.height / 2, lifetime=2 * games.screen.fps, after_death=games.screen.quit) games.screen.add(victory_message) for obj in games.screen._objects: if obj.dy: obj.destroy()
def alert(self): level_up_message = games.Message(value="Speed Up!", size=90, color=color.black, x=games.screen.width / 2, y=games.screen.height / 2, lifetime=3 * games.screen.fps) games.screen.add(level_up_message)
def message(self): ball_message = games.Message(value="Innings", size=50, color=color.green, right=games.screen.width / 2 - 25, y=games.screen.height / 6, lifetime=3 * games.screen.fps) games.screen.add(ball_message)
def main(): # create window #games.init(screen_width = 640, screen_height = 480, fps =50) #Moved to global as a workaround. #Load background #still has problem if we give absolute path, i.e."C:\lkjlfs\dfdsfs" wall_image = games.load_image("CIMG2622.JPG", transparent=False) games.screen.background = wall_image # Add on 3 pizzas for 3 girls p_image = games.load_image("pizza.bmp") #Now calling derived class Pizza to make them bounce via over-ride update method. pizza_x = random.randrange(games.screen.width) #New for 2.0 pizza_y = random.randrange(games.screen.height) pizza1 = Pizza(image=p_image, x=pizza_x, y=pizza_y, dx=1, dy=-1) #New for 2.0 pizza2 = Pizza(image=p_image, x=pizza_x, y=pizza_y, dx=-1, dy=-1) pizza3 = Pizza(image=p_image, x=pizza_x, y=pizza_y, dx=-1, dy=1) pizza4 = Pizza(image=p_image, x=pizza_x, y=pizza_y, dx=1, dy=1) games.screen.add(pizza1) games.screen.add(pizza2) games.screen.add(pizza3) games.screen.add(pizza4) #Load music file playing as background games.music.load("theme.mid") loop = 9999 games.music.play(loop) #Create Pan sprite and add to screen. pan_image = games.load_image("pan.bmp") pan = Pan() #Mod for Rev 2.0 games.screen.add(pan) #Display "Dinner Time" as Message demo eatMessage = games.Message( value="Touch Score Board to Quit!", size=40, color=color.red, x=games.screen.width / 2, y=games.screen.height / 2, lifetime=50, #after_death = games.screen.mainloop ) #games.screen.add(eatMessage) #Setting mouse pinter not visible games.mouse.is_visible = False #Grab all graphic events games.screen.event_grab = True #Display window on screen games.screen.mainloop()
def end_game(): end_msg = games.Message(value='Вы проиграли!', size=90, color=color.red, x=games.screen.width / 2, y=games.screen.height / 2, lifetime=3 * games.screen.fps, after_death=games.screen.quit) games.screen.add(end_msg)
def end_game(self): end_message = games.Message(value="Koniec Gry!", size=130, color=color.yellow, x=games.screen.width / 2, y=games.screen.height / 2, lifetime=3 * games.screen.fps, after_death=games.screen.quit) games.screen.add(end_message)
def end_game(self): end_message = games.Message(value=self.message, size=90, color=color.red, x=games.screen.width / 2, y=games.screen.height / 2, lifetime=1 * games.screen.fps, after_death=games.screen.quit) games.screen.add(end_message)
def end_game(self): end_message = games.Message(value="Koniec gry", size=90, color=color.black, x=games.screen.width / 2, y=games.screen.height / 2, lifetime=5 * games.screen.fps, after_death=games.screen.quit) games.screen.add(end_message)
def end_game(self): end_message = games.Message(value='GAME OVER', size=150, color=color.pink, x=320, y=240, lifetime=250, after_death=games.screen.quit) games.screen.add(end_message)
def end_game(self): self.game_over = games.Message(x=games.screen.width / 2, y=games.screen.width / 4, size=150, color=(192, 192, 192), lifetime=2 * games.screen.fps, after_death=self.save_score, value="||GameOver||", is_collideable=False) games.screen.add(self.game_over)
def end(self): end_message = games.Message(value="Koniec gry", size=90, color=color.red, x=games.screen.width / 2, y=games.screen.height / 2, lifetime=5 * games.screen.fps, after_death=games.screen.quit, is_collideable=False) games.screen.add(end_message)
def end_game(self): """ Завершает игру. """ end_message = games.Message(value='Game over', size=90, color=color.red, x=WIDTH / 2, y=HEIGHT / 2, lifetime=5 * games.screen.fps, after_death=games.screen.quit) games.screen.add(end_message)
def end(self): end_message = games.Message(value='Game Over', size=100, color=color.pink, x=games.screen.width / 2, y=games.screen.height / 2, lifetime=100 * games.screen.fps, after_death=games.screen.quit, is_collideable=False) games.screen.add(end_message)