def title(keys): global credit_count, play_count, option_count, sound_level pygame.mixer.music.set_volume(sound_level) if pygame.K_q in keys: quit() camera.clear("red") camera.draw(titlebackground) camera.draw(char2) camera.draw(char4) camera.draw(char5) camera.draw(char6) camera.draw(char7) camera.draw(char3) if pygame.K_p in keys: global_stage.level += 1 if pygame.K_o in keys: option_count += 1 if pygame.K_c in keys: credit_count += 1 if pygame.K_ESCAPE in keys: gamebox.stop_loop() if credit_count != 0: tick_creds(keys) if option_count != 0: tick_options(keys) if global_stage.level == 1: musicplayer1 = music1.play(-1) gamebox.timer_loop(30, game_final_1.tick) elif global_stage.level == 2: music1.stop() musicplayer2 = music2.play(-1) gamebox.timer_loop(30, sponge_run.sponge_run_function) if play_count == 0 and credit_count == 0 and option_count == 0: camera.display()
def title(keys): global credit_count, play_count, option_count, sound_level pygame.mixer.music.set_volume(sound_level) if pygame.K_q in keys: quit() camera.clear("red") camera.draw(titlebackground) camera.draw(char2) camera.draw(char4) camera.draw(char5) camera.draw(char6) camera.draw(char7) camera.draw(char3) if pygame.K_p in keys: global_stage.level += 1 if pygame.K_o in keys: option_count += 1 if pygame.K_c in keys: credit_count += 1 if credit_count != 0: tick_creds(keys) if option_count != 0: tick_options(keys) if global_stage.level == 1: musicplayer1 = music1.play(-1) gamebox.timer_loop(30, level_one.tick) elif global_stage.level == 2: music1.stop() musicplayer2 = music2.play(-1) gamebox.timer_loop(30, level_two.sponge_run_function) if play_count == 0 and credit_count == 0 and option_count == 0: camera.display()
def start(keys): camera.clear("skyblue") camera.draw(gamebox.from_text(500,500,"Our Game", "Futura",20,"black")) camera.draw(gamebox.from_text(500,600,"Press SPACE to start", "Futura",20,'black')) camera.display() if pygame.K_SPACE in keys: gamebox.timer_loop(ticks_per_second, tick)
def intro(keys): global time, score, minutes, agreed if agreed == True: # keep this line the last one in your program gamebox.timer_loop(ticks_per_second, tick) else: camera.clear("black") message = gamebox.from_text (250, 250, "PRESS SPACE TO START", "arial", 34, "red") camera.draw(message) if pygame.K_s in keys: agreed = True camera.display()
def intro(keys): global start if start == True: gamebox.timer_loop(ticks_per_second, tick) else: ## DEFINING BACKGROUND OF GAME START background = gamebox.from_image(400, 300, "startingbackground.jpg") ## SCALING BACKGROUND FOR BETTER FIT background.scale_by(0.65) ## CREATING INSTRUCTIONS TO INFORM PLAYER(S) instructions = gamebox.from_text(400, 125, "PRESS SPACE TO START", "TIMES", 24, "white") howtoplay = gamebox.from_text(400, 410, "HOW TO PLAY", 'TIMES', 18, 'white') player1instructions = gamebox.from_text( 400, 430, "PLAYER 1 - UP, DOWN, LEFT, RIGHT", 'TIMES', 12, 'white') player2instructions = gamebox.from_text(400, 450, "PLAYER 2 - W, A, S, D", 'TIMES', 12, 'white') generalinstructions = gamebox.from_text( 400, 470, "TRAP YOUR OPPONENT IN YOUR PATH", 'TIMES', 12, 'white') generalinstructions1 = gamebox.from_text( 400, 490, "AND GATHER COINS TO GET POINTS", 'TIMES', 12, 'white') generalinstructions2 = gamebox.from_text(400, 510, "FIRST TO 10 POINTS WINS!", 'TIMES', 12, 'white') names = gamebox.from_text( 600, 590, "Connor Park (CJP7ZG) & John Cragun (JEC2GW)", 'TIMES', 15, 'white') instructionshighlight = gamebox.from_color(400, 125, "red", 350, 50) howtoplayhighlight = gamebox.from_color(400, 460, "red", 350, 125) nameshighlight = gamebox.from_color(600, 590, "red", 385, 20) ## DRAWING INSTRUCTIONS FOR GAME camera.draw(background) camera.draw(instructionshighlight) camera.draw(howtoplayhighlight) camera.draw(nameshighlight) camera.draw(instructions) camera.draw(howtoplay) camera.draw(player1instructions) camera.draw(player2instructions) camera.draw(generalinstructions) camera.draw(generalinstructions1) camera.draw(generalinstructions2) camera.draw(names) ## DEFINING USER INPUT TO START GAME if pygame.K_SPACE in keys: start = True backgroundsound.stop() camera.display()
def down(self): self.b.speed = 0, self.scale / 8 self.look = (0, 1) if self.ok: tmp = gamebox.timer_loop(60, self._tick, 16) self.ok &= tmp self.moves += 1 return self.ok
def right(self): self.b.speed = self.scale / 8, 0 self.look = (1, 0) if self.ok: tmp = gamebox.timer_loop(60, self._tick, 16) self.ok &= tmp self.moves += 1 return self.ok
def start_frame(): pygame.init() start_img = pygame.image.load("start_screen.png") text1 = my_font.render("Welcome To The Hungry Snake Game!", True, (0, 200, 0)) text2 = my_font.render("Press Any Key to Start", True, (0, 200, 0)) while True: event = pygame.event.wait() if event.type == pygame.QUIT: return if event.type == pygame.KEYDOWN: break init_screen.fill(white) init_screen.blit(start_img, [400, 300]) init_screen.blit(text1, [50, 200]) init_screen.blit(text2, [50, 250]) pygame.display.flip() gamebox.timer_loop(30, tick) # start the actual game
def check_down(self): if not self.ok: return False self.looks += 1 self.b.speed = 0, 0 if self.look != (0, 1): self.look = (0, 1) self.ok &= gamebox.timer_loop(60, self._tick, 8) return (self.b.x // (self.scale * 2), self.b.y // (self.scale * 2) + 1) in self.open
def check_left(self): if not self.ok: return False self.looks += 1 self.b.speed = 0, 0 if self.look != (-1, 0): self.look = (-1, 0) self.ok &= gamebox.timer_loop(60, self._tick, 8) return (self.b.x // (self.scale * 2) - 1, self.b.y // (self.scale * 2)) in self.open
def restart(keys): ''' This function is executed whenever the player hits a wall or hits an enemy -- it's basically a "reset". :param keys: :return: ''' global time global level global points if pygame.K_SPACE in keys: gamebox.unpause() points = points - 10 if points < 0: camera.clear('black') camera.draw( gamebox.from_text(camera.left + 400, 200, 'You Lose!', 50, 'white')) camera.draw( gamebox.from_text(camera.left + 400, 300, 'Quit and reopen the game to play again', 50, 'white')) elif level == 1: player_sprite[0].x = 320 player_sprite[0].y = 550 gamebox.timer_loop(60, tick) elif level == 2: player_sprite[1].x = 0 player_sprite[1].y = 420 enemy_sprite2[0].x = 400 enemy_sprite2[0].y = 420 enemy_sprite2[1].x = 400 enemy_sprite2[1].y = 225 enemy_sprite2[0].xspeed = -enemy_sprite2[0].xspeed enemy_sprite2[1].xspeed = -enemy_sprite2[1].xspeed gamebox.timer_loop(60, tick) elif level == 3: player_sprite[2].x = 10 player_sprite[2].y = 75 gamebox.timer_loop(60, tick) elif level == 4: player_sprite[3].x = 10 player_sprite[3].y = 300 gamebox.timer_loop(60, tick) elif level == 5: camera.clear('black') camera.draw( gamebox.from_text( 400, 300, 'You failed to win, quit the game and reopen to try again.', 40, 'red')) gamebox.stop_loop() camera.display()
def main(): music = musicpicker.music() musicplayer = music.play(-1) global camera_controller, button camera_controller = CameraController() button = UI.Button(300, 250, "CLICK ANYWHERE TO START""\n" "|--Tilden and Alec's Roguelike--| \n |-----Dungeon Dive-----|" " \nTry the dungeon if you dare!\n""\n""Controls:\n""WASD to move Character\n" "Arrow keys to move screen\n""\n" "Alec Ross (asr3b)\n""Tilden Winston (tw8rt)\n", "black", UI.text_descriptor(), None, splash_end) gamebox.timer_loop(30, splash_screen) button.deactivate() UI.background() camera_controller.world.load() gamebox.timer_loop(15, play) return
def start_frame(): global player_number global frame frame = 0 pygame.init() start_img = pygame.image.load("start_screen.png") text1 = my_font.render("Welcome To The Hungry Snake Game!", True, (0, 200, 0)) text2 = my_font.render("Press Any Key to Start", True, (0, 200, 0)) init_screen.fill(white) init_screen.blit(start_img, [400, 300]) init_screen.blit(text1, [50, 200]) init_screen.blit(text2, [50, 250]) pygame.display.flip() mode1 = gamebox.from_image(200, 200, 'button.png') mode1.scale_by(0.4) mode2 = gamebox.from_image(600, 200, 'button.png') mode2.scale_by(0.4) while True: event = pygame.event.wait() if event.type == pygame.QUIT: return if event.type == pygame.KEYDOWN: break while True: clock.tick(30) event = pygame.event.poll() animation() if event.type == pygame.QUIT: return if event.type == pygame.MOUSEBUTTONDOWN: if mode1.x - mode1.width / 2 < camera.mousex < mode1.x + mode1.width / 2: if mode1.y - mode1.height / 2 < camera.mousey < mode1.y + mode1.height / 2: player_number = 1 break if mode2.x - mode2.width / 2 < camera.mousex < mode2.x + mode2.width / 2: if mode2.y - mode2.height / 2 < camera.mousey < mode2.y + mode2.height / 2: player_number = 2 break for players in range(player_number): snake_set["player{}".format(players + 1)] = add_player(players + 1) gamebox.timer_loop(30, tick) # start the actual game
def intro(keys): global score, agreed if agreed == True: gamebox.timer_loop(ticks_per_second, tick) else: camera.clear("yellow") start_statement = gamebox.from_text(camera.x, camera.y + 50, "PRESS THE 'S' KEY TO START", "arial", 25, "black") instructions1 = gamebox.from_text( camera.x, camera.y - 30, "Try to collect all 20 coins in 30 seconds!", "arial", 34, "black") instructions2 = gamebox.from_text( camera.x, camera.y, "Use the arrow keys to move around and space to jump", "arial", 34, "black") camera.draw(start_statement) camera.draw(instructions1) camera.draw(instructions2) if pygame.K_s in keys: agreed = True camera.display()
def intro(keys): global time, score, minutes, agreed if agreed == True: gamebox.timer_loop(ticks_per_second, tick) else: camera.clear("white") messages = [ gamebox.from_text(450, 25, "Game project: Santa's Big Adventure", "Arial", 34, "red"), gamebox.from_text( 450, 75, "Anne Moshyedi (acm4xb) and Julie Bond (jab5cr)", "Arial", 34, "red"), gamebox.from_text(450, 175, "Rules:", "Arial", 34, "red"), gamebox.from_text(450, 225, "Use arrows to help Santa fly", "Arial", 34, "red"), gamebox.from_text(450, 275, "Collect presents to increase score", "Arial", 34, "red"), gamebox.from_text(450, 325, "Collect cookies to increase health", "Arial", 34, "red"), gamebox.from_text( 450, 375, "The Grinch steals presents and lowers the score", "Arial", 34, "red"), gamebox.from_text(450, 425, "Jack Frost's ice lowers Santa's health", "Arial", 34, "red"), gamebox.from_text( 450, 475, "Collect all the presents you can until the timer runs out or Santa dies!", "Arial", 34, "red"), gamebox.from_text(450, 575, "Press space to start", "Arial", 34, "red"), ] for message in messages: camera.draw(message) if pygame.K_SPACE in keys: agreed = True camera.display()
15, 'white') instructionshighlight = gamebox.from_color(400, 125, "red", 350, 50) howtoplayhighlight = gamebox.from_color(400, 460, "red", 350, 125) nameshighlight = gamebox.from_color(600, 590, "red", 385, 20) ## DRAWING INSTRUCTIONS FOR GAME camera.draw(background) camera.draw(instructionshighlight) camera.draw(howtoplayhighlight) camera.draw(nameshighlight) camera.draw(instructions) camera.draw(howtoplay) camera.draw(player1instructions) camera.draw(player2instructions) camera.draw(generalinstructions) camera.draw(generalinstructions1) camera.draw(generalinstructions2) camera.draw(names) ## DEFINING USER INPUT TO START GAME if pygame.K_SPACE in keys: start = True backgroundsound.stop() camera.display() ## DEFINING TICKS PER SECOND ticks_per_second = 30 ## PLAYING BACKGROUND MUSIC backgroundsound.play(-1) ## DEFINING TICK FUNCTION LOOP gamebox.timer_loop(ticks_per_second, intro)
camera.clear("Black") if pizza_health > 0: for platform in platform_object: camera.draw(platform) for entry in background: camera.draw(entry) for entry in house: camera.draw(entry) camera.draw(customer_house) for platform in platform_list: camera.draw(platform) camera.draw(rock_an) camera.move(rock.xspeed, 0) for cockroach in cockroach_list: if rock.x + 1300 > cockroach.x and rock.x - 300 < cockroach.x: camera.draw(cockroach) camera.draw(health_hud) else: rock.xspeed = 0 if death_move_check == 0: camera.move(19440, 0) death_move_check = 1 death_screen = gamebox.from_image(rock.x + 20000, 400, "deathscreen.jpg") quit_text = gamebox.from_text(rock.x + 20200, 400, "Press q to quit", "Cambria",100, "White") camera.draw(death_screen) camera.draw(quit_text) camera.display() gamebox.timer_loop(30, sponge_run_function)
credit_count += 1 if credit_count != 0: tick_creds(keys) if option_count != 0: tick_options(keys) if global_stage.level == 1: musicplayer1 = music1.play(-1) gamebox.timer_loop(30, level_one.tick) elif global_stage.level == 2: music1.stop() musicplayer2 = music2.play(-1) gamebox.timer_loop(30, level_two.sponge_run_function) if play_count == 0 and credit_count == 0 and option_count == 0: camera.display() while global_stage.quit_check == 0: if global_stage.level == 0: gamebox.timer_loop(30, title) if global_stage.level == 1: music1 = gamebox.load_sound('Spongebob_Uke.wav') musicplayer1 = music1.play(-1) gamebox.timer_loop(30, level_one.tick) if global_stage.level == 2: music1.stop() music2 = gamebox.load_sound('Spongebob Pizza song.wav') musicplayer2 = music2.play(-1) if music2_count != 0: music2.stop() gamebox.timer_loop(30, level_two.sponge_run_function)
def flappybird(keys): """ This is the main function that runs the flappybird app. The function is run 30 times per second. This keeps the game going until the player loses. :return: Shows a score of the player based on the number of obstacles passed. """ global fall_speed # Accesses external fall speed. global bird_straight # Accesses external sprite image global bird_down # Accesses external sprite image global bird_game # Accesses external sprite image made. global bird # Accesses external sprite image variable. global counter # Accesses the counter global score_number # Accesses the score global obstacles # Access tbe obstacles list global position # Accesses the obstacle making position. global game_on # Accesses the variable outside the function global leave # Accesses the external variable camera.clear( "white") # Clears the screen so that it can be painted on newly. score = gamebox.from_text( 400, 50, str(int(score_number)), 50, "yellow", True) # Sets the score position for the number of obstacles avoided. game_over_end = gamebox.from_text( 400, 300, "Score: " + str(int(score_number)), 40, 'brown', True) # This is the position for the game over score item. if pygame.K_SPACE in keys: # If the space bar is clicked game_on = True # Start the game if game_on: # If they started the game counter += 1 # Counter for the obstacle. if counter % obstacles_generation == 0: # When the counter divided by a number has no remainder num_obs = 1 # how many obs to be created for i in range(num_obs): # For every obstacle to be created distance_apart = 150 # Ideal number is 150, the math needs it to be this, any other number will be weird. lower_bound = random.randint( -200, 200) # Set the lower bound to be a random number if lower_bound < 0: # If the lower bound is negative upper_bound = 750 - (abs(lower_bound) + distance_apart ) # Set the upper bound accordingly else: # If the lower bound is negative upper_bound = 790 - abs( lower_bound - distance_apart) # Set the lower bound accordingly top_obstacles = gamebox.from_image( position, lower_bound, obstacle_top) # Make the top obstacle. bottom_obstacles = gamebox.from_image( position, upper_bound, obstacle_bottom) # Make the bottom obstacle. obstacles.append(top_obstacles) # Append the top obstacle. obstacles.append( bottom_obstacles) # Append the bottom obstacle. position += 200 # Set the position to increase by 200. camera.draw(game_background) # Draw the background for the game. if pygame.K_SPACE in keys: # If the user hits the space bar width_game = bird_game.x # Set the width of the game to be the width of position of the bird image height_game = bird_game.y # Set the height of the game to be the height of the position of the bird image bird = bird_straight # Draw the bird in the normal position bird_game = gamebox.from_image( width_game, height_game, bird) # Gets the bird image from my folder bird_game.y -= 50 # Set the bird to fly 50 pixels higher than it was before. fall_speed = 1 # Reset the fall speed. keys.remove( pygame.K_SPACE) # Stop the key from being pressed down. elif pygame.K_UP in keys: # If the user hits the up arrow width_game = bird_game.x # Set the width of the game to be the width of position of the bird image height_game = bird_game.y # Set the height of the game to be the height of the position of the bird image bird = bird_straight # Draw the bird in the normal position bird_game = gamebox.from_image( width_game, height_game, bird) # Gets the bird image from my folder bird_game.y -= 50 # Set the bird to fly 50 pixels higher than it was before. fall_speed = 1 # Reset the fall speed. keys.remove(pygame.K_UP) # Stop the key from being pressed down. elif pygame.K_w in keys: # If the user hits the w key width_game = bird_game.x # Set the width of the game to be the width of position of the bird image height_game = bird_game.y # Set the height of the game to be the height of the position of the bird image bird = bird_straight # Draw the bird in the normal position bird_game = gamebox.from_image( width_game, height_game, bird) # Gets the bird image from my folder bird_game.y -= 50 # Set the bird to fly 50 pixels higher than it was before. fall_speed = 1 # Reset the fall speed. keys.remove(pygame.K_w) # Stop the key from being pressed down. else: # If no appropriate keys are being pressed width_game = bird_game.x # Set the width of the game to be the width of position of the bird image height_game = bird_game.y # Set the height of the game to be the height of the position of the bird image bird = bird_down # Set the bird image to be the bird down image. bird_game = gamebox.from_image( width_game, height_game, bird) # Gets the bird image from my folder if fall_speed + 1 >= fall_speed: # If the next fall speed is greater than the current one bird_game.y += fall_speed # Set the bird speed to be equal to the fall speed fall_speed += 1 # Then increment the fall speed to provide a faster falling rate. if pygame.K_e in keys: # Sets the key to do the following action. exec(open("Game_Project.py").read(), globals()) # Returns to the main screen quit() # Quits the game. for obstacle in obstacles: # For every obstacle in the game obstacle.x += obstacle_speed # The x position of the obstacle is incremented by the speed the obstacle is to move in camera.draw(obstacle) # Draw the obstacle. if obstacle.x == score.x: # For every obstacle that is equal to the position of the sprite bird score_number += 0.5 # Increment the score by half (The 30 times per second screen compensates for the other half to make it one) if bird_game.touches( obstacle ) or 0 >= bird_game.y or bird_game.y >= height: # If the bird touches an obstacle or touches the bottom of the screen if pygame.K_SPACE in keys: # If the user hits the space bar keys.remove(pygame.K_SPACE ) # Stop the key from being pressed down. score = gamebox.from_text( -100, -100, str(int(score_number)), 50, "yellow", False) # Set the score to be the current score camera.draw(obstacle) # Draw the obstacle camera.draw(bird_game) # Draw the bird sprite camera.draw(game_over) # Draw the game over screen camera.draw(game_over_end) # Draw the game over score camera.draw(leave) # Leaves the game camera.display() # Display the images gamebox.timer_loop( 3, flappybird ) # Slows down the screen so that they cannot play the game any more. else: # If the game has not been started camera.draw(game_background) # Show the background camera.draw(game_instruction) # Instructions before start camera.draw(game_score_instruction) # Instructions before start camera.draw(game_sprite_instruction) # Instructions before start camera.draw(game_background_start) # Instructions before start camera.draw(score) # Draw the score camera.draw(bird_game) # Draw the bird camera.display() # Display the game
) # Stop the key from being pressed down. score = gamebox.from_text( -100, -100, str(int(score_number)), 50, "yellow", False) # Set the score to be the current score camera.draw(obstacle) # Draw the obstacle camera.draw(bird_game) # Draw the bird sprite camera.draw(game_over) # Draw the game over screen camera.draw(game_over_end) # Draw the game over score camera.draw(leave) # Leaves the game camera.display() # Display the images gamebox.timer_loop( 3, flappybird ) # Slows down the screen so that they cannot play the game any more. else: # If the game has not been started camera.draw(game_background) # Show the background camera.draw(game_instruction) # Instructions before start camera.draw(game_score_instruction) # Instructions before start camera.draw(game_sprite_instruction) # Instructions before start camera.draw(game_background_start) # Instructions before start camera.draw(score) # Draw the score camera.draw(bird_game) # Draw the bird camera.display() # Display the game gamebox.timer_loop( 30, flappybird) # Calls the flappybird loop 30 times every second.
camera.clear("skyblue") camera.draw(game_over) camera.display() for bluehole in blueholes: bluehole.image = blue_hole_sheet[y] if bluehole.x < (camera.x-500): blueholes.remove(bluehole) if alien.touches(bluehole): end() if alien.y >= 800: end() ticks_per_second = 30 def start(keys): camera.clear("skyblue") camera.draw(gamebox.from_text(500,500,"Our Game", "Futura",20,"black")) camera.draw(gamebox.from_text(500,600,"Press SPACE to start", "Futura",20,'black')) camera.display() if pygame.K_SPACE in keys: gamebox.timer_loop(ticks_per_second, tick) gamebox.timer_loop(ticks_per_second,start) # keep this line the last one in your program
def tick(keys): ''' This function provides the mechanics of the maze game. :param keys: :return: ''' global game_on global time global level global points time -= 1 / 60 if game_on is False: time = 120 camera.clear('dark grey') for each in starting_menu_text: camera.draw(each) if pygame.K_SPACE in keys: game_on = True level = 1 if game_on is True: camera.clear('turquoise') camera.draw(background[0]) if level == 1: for each in level_1_walls: camera.draw(each) camera.draw( gamebox.from_text(camera.left + 80, 20, 'Time Remaining: ' + str(int(time)), 20, 'white')) camera.draw( gamebox.from_text(camera.left + 80, 30, 'Points: ' + str(int(points)), 20, 'white')) camera.draw(level_endpoints[0]) camera.draw(player_sprite[0]) for each in enemy_sprite1: camera.draw(each) each.move_speed() for each in level_1_walls: if enemy_sprite1[0].touches(each): enemy_sprite1[0].xspeed = -enemy_sprite1[0].xspeed if enemy_sprite1[1].touches(each): enemy_sprite1[1].xspeed = -enemy_sprite1[1].xspeed if enemy_sprite1[2].touches(each): enemy_sprite1[2].xspeed = -enemy_sprite1[2].xspeed for each in enemy_sprite1: if player_sprite[0].touches(each, padding=-17): camera.draw( gamebox.from_text( 400, 300, 'You hit an ENEMY, press SPACE to reset', 30, 'white')) gamebox.pause() keys.clear() gamebox.timer_loop(60, restart) for each in coins1: camera.draw(each) if player_sprite[0].touches(coins1[0]): points += 10 coins1[0].x = 8000 coins1[0].y = 8000 if pygame.K_UP in keys: player_sprite[0].y -= 3 if pygame.K_DOWN in keys: player_sprite[0].y += 3 if pygame.K_RIGHT in keys: player_sprite[0].x += 3 if pygame.K_LEFT in keys: player_sprite[0].x -= 3 for each in level_1_walls: if player_sprite[0].touches(each, padding=-10): camera.draw( gamebox.from_text( 400, 300, 'You hit a WALL, press SPACE to reset', 30, 'white')) gamebox.pause() keys.clear() gamebox.timer_loop(60, restart) if player_sprite[0].touches(level_endpoints[0]): level = 2 camera.clear('turquoise') if level == 2: camera.draw(background[1]) for each in level_2_walls: camera.draw(each) camera.draw( gamebox.from_text(camera.left + 80, 20, 'Time Remaining: ' + str(int(time)), 20, 'white')) camera.draw( gamebox.from_text(camera.left + 80, 30, 'Points: ' + str(int(points)), 20, 'white')) camera.draw(level_endpoints[1]) camera.draw(player_sprite[1]) for each in enemy_sprite2: camera.draw(each) each.move_speed() for each in level_2_walls: if enemy_sprite2[1].touches(each): enemy_sprite2[1].xspeed = -enemy_sprite2[1].xspeed if enemy_sprite2[0].x == camera.right: enemy_sprite2[0].xspeed = -enemy_sprite2[0].xspeed if enemy_sprite2[0].x == camera.left: enemy_sprite2[0].xspeed = -enemy_sprite2[0].xspeed for each in enemy_sprite2: if player_sprite[1].touches(each, padding=-17): camera.draw( gamebox.from_text( 400, 300, 'You hit an ENEMY, press SPACE to reset', 30, 'white')) gamebox.pause() keys.clear() gamebox.timer_loop(60, restart) for each in coins2: camera.draw(each) if player_sprite[1].touches(each): points += 10 each.x = 8000 each.y = 8000 if pygame.K_UP in keys: player_sprite[1].y -= 3 if pygame.K_DOWN in keys: player_sprite[1].y += 3 if pygame.K_RIGHT in keys: player_sprite[1].x += 3 if pygame.K_LEFT in keys: player_sprite[1].x -= 3 for each in level_2_walls: if player_sprite[1].touches(each, padding=-10): camera.draw( gamebox.from_text( 400, 300, 'You hit a WALL, press SPACE to reset', 30, 'white')) gamebox.pause() keys.clear() gamebox.timer_loop(60, restart) if player_sprite[1].touches(level_endpoints[1]): level = 3 camera.clear('turquoise') if level == 3: camera.draw(background[2]) for each in level_3_walls: camera.draw(each) camera.draw( gamebox.from_text(camera.left + 80, 20, 'Time Remaining: ' + str(int(time)), 20, 'white')) camera.draw( gamebox.from_text(camera.left + 80, 30, 'Points: ' + str(int(points)), 20, 'white')) camera.draw(level_endpoints[2]) camera.draw(player_sprite[2]) camera.draw( gamebox.from_text(400, 560, 'Is it worth getting this coin? :)', 20, 'white')) for each in enemy_sprite3: camera.draw(each) each.move_speed() for each in enemy_sprite3: if each.y == 0: each.yspeed = -each.yspeed for each in level_3_walls: if enemy_sprite3[0].touches(each): enemy_sprite3[0].yspeed = -enemy_sprite3[0].yspeed for each in enemy_sprite3: if player_sprite[2].touches(each, padding=-17): camera.draw( gamebox.from_text( 400, 300, 'You hit an ENEMY, press SPACE to reset', 30, 'white')) gamebox.pause() keys.clear() gamebox.timer_loop(60, restart) for each in coins3: camera.draw(each) if player_sprite[2].touches(each): points += 10 each.x = 8000 each.y = 8000 if coins3[0].x == 8000: camera.draw( gamebox.from_text(400, 580, 'I guess it was worth', 20, 'white')) if pygame.K_UP in keys: player_sprite[2].y -= 3 if pygame.K_DOWN in keys: player_sprite[2].y += 3 if pygame.K_RIGHT in keys: player_sprite[2].x += 3 if pygame.K_LEFT in keys: player_sprite[2].x -= 3 for each in level_3_walls: if player_sprite[2].touches(each, padding=-10): camera.draw( gamebox.from_text( 400, 300, 'You hit a WALL, press SPACE to reset', 30, 'white')) gamebox.pause() keys.clear() gamebox.timer_loop(60, restart) if player_sprite[2].touches(level_endpoints[2]): level = 4 camera.clear('turquoise') if level == 4: for each in level_4_blue_walls: camera.draw(each) camera.draw(background[3]) for each in level_4_walls: camera.draw(each) camera.draw( gamebox.from_text(camera.left + 80, 20, 'Time Remaining: ' + str(int(time)), 20, 'white')) camera.draw( gamebox.from_text(camera.left + 80, 30, 'Points: ' + str(int(points)), 20, 'white')) camera.draw(level_endpoints[3]) camera.draw(player_sprite[3]) camera.draw( gamebox.from_text(600, 580, 'You\'re almost there...', 40, 'white')) for each in enemy_sprite4: camera.draw(each) each.move_speed() for each in enemy_sprite4: if each.y == 0 or each.y == 600: each.yspeed = -each.yspeed for each in level_4_walls: if enemy_sprite4[0].touches(each): enemy_sprite4[0].yspeed = -enemy_sprite4[0].yspeed if enemy_sprite4[1].touches(each): enemy_sprite4[1].yspeed = -enemy_sprite4[1].yspeed for each in enemy_sprite4: if player_sprite[3].touches(each, padding=-17): camera.draw( gamebox.from_text( 400, 300, 'You hit an ENEMY, press SPACE to reset', 30, 'white')) gamebox.pause() keys.clear() gamebox.timer_loop(60, restart) for each in coins4: camera.draw(each) if player_sprite[3].touches(each): points += 10 each.x = 8000 each.y = 8000 if pygame.K_UP in keys: player_sprite[3].y -= 3 if pygame.K_DOWN in keys: player_sprite[3].y += 3 if pygame.K_RIGHT in keys: player_sprite[3].x += 3 if pygame.K_LEFT in keys: player_sprite[3].x -= 3 for each in level_4_walls: if player_sprite[3].touches(each, padding=-10): camera.draw( gamebox.from_text( 400, 300, 'You hit a WALL, press SPACE to reset', 30, 'white')) gamebox.pause() keys.clear() gamebox.timer_loop(60, restart) if player_sprite[3].touches(level_endpoints[3]): level = 5 camera.clear('turquoise') if level == 5: camera.draw(background[4]) for each in level_5_walls: camera.draw(each) camera.draw(level_endpoints[4]) camera.draw( gamebox.from_text(camera.left + 80, 20, 'Time Remaining: ' + str(int(time)), 20, 'white')) camera.draw( gamebox.from_text(camera.left + 80, 30, 'Points: ' + str(int(points)), 20, 'white')) camera.draw(player_sprite[4]) camera.draw(enemy_sprite5[0]) if player_sprite[4].x >= 30: camera.draw( gamebox.from_text(100, 430, 'What\'s this?..', 30, 'white')) if pygame.K_RIGHT in keys: player_sprite[4].x += 1 if player_sprite[4].x > 300 and enemy_sprite5[0].y < 350: enemy_sprite5[0].yspeed = 10 enemy_sprite5[0].move_speed() if enemy_sprite5[0].y >= 350: enemy_sprite5[0].yspeed = 0 enemy_sprite5[0].move_speed() camera.draw(gamebox.from_text(250, 450, 'huh...?', 30, 'white')) if player_sprite[4].x > 465: camera.draw( gamebox.from_text( 500, 475, 'You should run. DO. NOT. STOP. MOVING.', 30, 'white')) if player_sprite[4].x > 550: enemy_sprite5[0].x = 325 camera.draw(gamebox.from_text(300, 150, 'run.', 30, 'white')) if player_sprite[4].x > 645: enemy_sprite5[0].x = 350 camera.draw(gamebox.from_text(500, 175, 'RUN.', 40, 'white')) if player_sprite[4].x > 740: camera.draw(gamebox.from_text(400, 300, 'R U N', 250, 'red')) enemy_sprite5[0].xspeed += 13 enemy_sprite5[0].move_speed() if enemy_sprite5[0].touches(player_sprite[4]): points += 100 # pop up image: https://i.ytimg.com/vi/HaxM_RzELm8/maxresdefault.jpg camera.draw(gamebox.from_image(400, 300, 'pop_up.png')) camera.draw( gamebox.from_text(400, 300, 'You LOSE. Press SPACE', 90, 'red')) gamebox.pause() gamebox.timer_loop(60, restart) elif player_sprite[4].touches(level_endpoints[4]): camera.clear('white') gamebox.pause() congrats = gamebox.from_image(400, 300, 'congrats.png') congrats.scale_by(1.5) camera.draw(congrats) camera.draw( gamebox.from_text(400, 400, 'You beat the game!!!', 90, 'light blue', bold=True)) if time <= 0: camera.draw( gamebox.from_text(400, 300, 'TIMES UP! Press SPACE', 30, 'white')) points = 0 gamebox.pause() keys.clear() gamebox.timer_loop(60, restart) camera.display()
quit() # Quits the game. if pygame.K_e in keys: # Sets the key to do the following action. exec(open("Game_Project.py").read(), globals()) # Returns to the main screen quit() # Quits the game. if 0 < green_score >= numberLimit: # IF the green score is 10 first ball.move(width/2, height/2) # Moves the ball to the specified coordinate camera.draw(gamebox.from_text(width / 2, height / 2 + 50, "Green Wins!", 40, "green", True)) # Print green wins ballInstructions = gamebox.from_text(width / 2, height / 2, 'Press "e" to leave the game', 30, 'yellow', False) # This is the instruction for leaving the game instruction = gamebox.from_text(400, 200, '', 80, 'purple', True) # This is the instruction instruction1 = gamebox.from_text(400, 500, '', 40, 'yellow', False) # This is the instruction instruction2 = gamebox.from_text(400, 550, '', 40, 'yellow', False) # This is the instruction redInstructions = gamebox.from_text(170, height / 2, '', 30, 'red', False) # This is the instruction for the player greenInstructions = gamebox.from_text(650, height / 2, '', 30, 'green', False) # This is the instruction for the player redScore = gamebox.from_text(200, 50, '', 30, 'red', False) # This is the instruction for the score greenScore = gamebox.from_text(610, 50, '', 30, 'green', False) # This is the instruction for the score if pygame.K_SPACE in keys: # Sets the key to do the following actions exec(open("Game_Project.py").read(), globals()) # Returns to the main screen quit() # Quits the game if pygame.K_e in keys: # Sets the key to do the following action. exec(open("Game_Project.py").read(), globals()) # Returns to the main screen quit() # Quits the game. camera.display() # Displays the screen gamebox.timer_loop(30, pong) # Moves through the screen 30 times per second.
def char_select(): camera.clear('black') camera.draw(select_screen) gamebox.timer_loop(ticks_per_second, tick)
if health_home <= 0: # Alters the score health_home = 0 # Alters the score if health_ship <= 0: # Alters the score health_ship = 0 # Alters the score ship_health_level = gamebox.from_text( width / 2, height / 2 + 50, 'Ship Health: ' + str(int(health_ship)), 50, 'yellow', True) # Show the ship health home_health_level = gamebox.from_text( width / 2, height / 2 + 100, 'Earth Health: ' + str(int(health_home)), 50, 'yellow', True) # Show the Earth health score = gamebox.from_text( width / 2, height / 2, 'Score: ' + str(int(kills)), 50, "yellow", True ) # Sets the score position for the number of obstacles avoided. leave = gamebox.from_text(width / 2, height / 2 + 150, 'Press "e" to leave the game', 30, "yellow", False) # Set the leave text camera.draw(score) # Draw the score camera.draw(leave) # Leaves the game camera.draw(ship_health_level) # Draw the Earth health camera.draw(home_health_level) # Draw the home health camera.draw(game_over) # Draw the Game Over text camera.display() # Displays the screen gamebox.timer_loop( 30, asteroids) # Loops through the code again 30 times per second.
import pygame import gamebox import random camera = gamebox.Camera(800, 600) images = gamebox.load_sprite_sheet('enemy.png', 1, 5) tick_count = 0 to_draw = [] x = 100 y = 100 enemy = gamebox.from_image(x, y, images[0]) enemy.scale_by(0.2) def animation_enemy(keys): global tick_count camera.clear('green') enemy.image = images[tick_count // 2 % len(images)] # Rotates through images tick_count += 1 to_draw.append(enemy) for i in to_draw: camera.draw(i) camera.display() gamebox.timer_loop(30, animation_enemy)
if health[2] == True: camera.draw(health3) # create score and draw it char_score = gamebox.from_text(700, 50, str(char_counter), "Comic Sans MS", 30, "red") enemy_score = gamebox.from_text(500, 50, str(enemy_counter), "Comic Sans MS", 30, "green") camera.draw(char_score) camera.draw(enemy_score) # game over screen if health[2] == False and char_counter <= enemy_counter: camera.draw(game_over_background) camera.draw(game_over_text) camera.draw(char_score) camera.draw(enemy_score) gamebox.pause() if health[2] == False and char_counter > enemy_counter: camera.draw(game_over_background) camera.draw(win_game_over_text) camera.draw(char_score) camera.draw(enemy_score) gamebox.pause() camera.display() ticks_per_second = 30 #keep this line the last one in your program gamebox.timer_loop(ticks_per_second,tick)
for wall in invis_wall: camera.draw(wall) for patch in grass: camera.draw(patch) camera.draw(statue) camera.draw(steps) for wall in brick: camera.draw(wall) for roof in top_roofs: camera.draw(roof) move_player(player, keys) move_trainer(trainer) move_trainer2(trainer2) move_squirrel1(squirrel) move_squirrel2(squirrel2) move_squirrel3(squirrel3) move_girl(girl) move_girl2(girl2) move_police(police) move_police2(police2) for roof in roofs: camera.draw(roof) draw_score() if not game_on: camera.draw(start) camera.display() gamebox.timer_loop(30, tick)
def home_screen(): camera.clear('black') camera.draw(gamebox.from_image(400, 300, 'Title.png')) gamebox.timer_loop(ticks_per_second, tick)
camera.draw(player) # camera.x -= 1.33 if counter == 0: for i in range(5): generate_enemy() counter += 1 enemy_chase() damage() enemy_death() lose_health() for enemy in enemies.values(): if type(enemy) != str: camera.draw(enemy[0]) fix_overlap() for item in health_bars: camera.draw(item) walk_controls(keys) if Player_HP > 0: camera.draw(player) print(Player_HP) else: print('YOU LOSE') camera.draw(Player_HP_bar) camera.draw(Player_HP_bar_fill) camera.display() # draw the buffer to the window TICKS_PER_SECOND = 60 gamebox.timer_loop(TICKS_PER_SECOND, tick)
import pygame import gamebox camera = gamebox.Camera(800, 600) #width, height of the window box = gamebox.from_color( 200, 100, 'red', 40, 80 ) # center at (200,100) coordinate (left to right, top to bottom), 40 pixels wide, 80 pixels tall def tick(keys): camera.clear('cyan') if pygame.K_RIGHT in keys: box.x += 10 camera.draw(box) # usually camera.display() should be the last line of the tick method camera.display() ticks_per_second = 30 # keep this line the last one in your program gamebox.timer_loop(ticks_per_second, tick) # run the 'tick' function 30 times every second # y increases going down and to the right, y decreases going up and to the left
def levels(): global border, ladder, doors, door_r, door_t, door_l, door_b, background, level background = gamebox.from_image(400, 300, 'Rooms.png') background.height = 700 outer_b = gamebox.from_color(400, 600, "black", 800, 25) outer_t = gamebox.from_color(400, 0, "black", 800, 25) outer_l = gamebox.from_color(0, 300, "black", 25, 600) outer_r = gamebox.from_color(800, 300, "black", 25, 600) border = [outer_b, outer_t, outer_l, outer_r] door_b = gamebox.from_image(400, 560, door_sheet[4]) door_t = gamebox.from_image(400, 40, door_sheet[0]) door_l = gamebox.from_image(40, 300, door_sheet[2]) door_r = gamebox.from_image(760, 300, door_sheet[6]) doors = [[door_l, True, 2], [door_r, True, 6], [door_t, True, 0], [door_b, True, 4]] ladder = gamebox.from_image(775, 300, 'Ladder.png') enemies = [] # list of enemies... room_0_enemies = [] # and lists of enemies in each room room_1_enemies = [] room_2_enemies = [] room_3_enemies = [] global enemies, room_0_enemies, room_1_enemies, room_2_enemies, room_3_enemies character.x = 50 character.y = 300 # handling of enemies is really convoluted. There is a list of lists of lists # outer layer is a master list that contains lists for each level. [room0, room1, room2, room3] # each level contains a list with all the enemies on that level. [enemy1, enemy2, enemy3] # each enemy has its own list that has attributes of it. [enemy_object, alive?, type] if level == 1: for i in range( 3): # different species of enemy in rooms 0-2 of level 1 for room_num, species in enumerate( ('slime', 'zombie', 'skeleton')): create_enemy(species, room_num) for i in ('slime', 'zombie', 'skeleton'): # one of each species in room 3 of level 1 create_enemy(i, 3) if level == 2: for i in range(3): create_enemy('slime', 0) create_enemy('zombie', 0) for i in range(6): create_enemy('skeleton', 1) for i in range(3): create_enemy('skeleton', 2) create_enemy('zombie', 2) create_enemy('slime', 2) for i in range(5): create_enemy('slime', 3) create_enemy('zombie', 3) if i <= 2: create_enemy('skeleton', 3) # create list with enemies from all rooms enemies.append(room_0_enemies) enemies.append(room_1_enemies) enemies.append(room_2_enemies) enemies.append(room_3_enemies) boss_health = 100 if level == 1: boss = boss_slime if level == 2: boss = boss_phantom dead_boss = False # can only go to next level if boss is killed global boss, boss_health, dead_boss gamebox.timer_loop(ticks_per_second, tick) del enemies level += 1
import pygame # Gets the pygame library import gamebox # Gets the gamebox library import random # Imports the random library """ This is a bricks like game made as an assignment for CS-1111 Game project. This project was done using the gamebox module developed by Professor Luther Tychonievich. This is the section of the game that runs a simple bricks game. """ width = 800 # This is the width of the screen height = 600 # This is the height of the screen camera = gamebox.Camera(width, height) # Sets the camera to view in these many pixels walls = \ [ gamebox.from_color(400, 600, "yellow", 1000, 20), # This is the bottom wall on the screen gamebox.from_color(400, 0, "yellow", 1000, 20), # This is the top wall on the screen ] def bricks(keys): for wall in walls: # For every wall in the game camera.draw(wall) # Draws the wall for the game. camera.display() gamebox.timer_loop(30, bricks)
# Send it to the tie screen level = 11 elif p_two_score == 2: # Send to player two wins screen level = 13 # Time Runs Out Scenario if time_left == 0: level = 10 resetPostitions() keys.clear() time_left = 10 counter = 0 if pygame.K_SPACE in keys: level = 0 resetPostitions() keys.clear() time_left = 10 counter = 0 # Display Window camera.display() # ticks per second tps = 60 gamebox.timer_loop(tps, tick) #
game_on = True ''' ''' #top_barrier.move(8,0) # Draw all the walls for wall in walls: camera.draw(wall) camera.draw(top_barrier) camera.draw(bot_barrier) #camera.draw(ball) # ---- CHECKING FOR WIN ---- if p1_score >= 10: camera.draw( gamebox.from_text(400, 100, "Red Wins!", "Arial", 40, "Red", True)) gamebox.pause() if p2_score >= 10: camera.draw( gamebox.from_text(400, 100, "Yellow Wins!", "Arial", 40, "Yellow", True)) gamebox.pause() camera.display() ticks_per_second = 30 # keep this line the last one in your program gamebox.timer_loop(ticks_per_second, tick)
if pygame.K_ESCAPE in keys: gamebox.stop_loop() if credit_count != 0: tick_creds(keys) if option_count != 0: tick_options(keys) if global_stage.level == 1: musicplayer1 = music1.play(-1) gamebox.timer_loop(30, game_final_1.tick) elif global_stage.level == 2: music1.stop() musicplayer2 = music2.play(-1) gamebox.timer_loop(30, sponge_run.sponge_run_function) if play_count == 0 and credit_count == 0 and option_count == 0: camera.display() while global_stage.quit_check == 0: if global_stage.level == 0: gamebox.timer_loop(30, title) if global_stage.level == 1: music1 = gamebox.load_sound('Spongebob_Uke.wav') musicplayer1 = music1.play(-1) gamebox.timer_loop(30, game_final_1.tick) if global_stage.level == 2: music1.stop() music2 = gamebox.load_sound('Spongebob Pizza song.wav') musicplayer2 = music2.play(-1) if music2_count != 0: music2.stop() gamebox.timer_loop(30, sponge_run.sponge_run_function)