def enemieslvl2(): """ :return: second level enemies are created, drop from the top of the screen, and then get removed once it passes mario's location """ global lvl1_enemies global ticks ticks += 1 rand_1 = random.randrange(60, 200) rand_2 = random.randrange(60, 200) rand_3 = random.randrange(60, 200) if game_on: if ticks % rand_1 == 0: enemy_1 = gamebox.from_image(camera.x, camera.top, """https://vignette.wikia.nocookie.net/mario/images/8/8a/Boo_Artwork_-_Mario_Party_7.png""") enemy_1.scale_by(0.15) if rand_1 != rand_2: lvl1_enemies.append(enemy_1) if ticks % rand_2 == 0: enemy_2 = gamebox.from_image(150, camera.top, """https://vignette.wikia.nocookie.net/mario/images/8/8a/Boo_Artwork_-_Mario_Party_7.png""") enemy_2.scale_by(0.15) lvl1_enemies.append(enemy_2) if ticks % rand_3 == 0: enemy_3 = gamebox.from_image(650, camera.top, """https://vignette.wikia.nocookie.net/mario/images/8/8a/Boo_Artwork_-_Mario_Party_7.png""") enemy_3.scale_by(0.15) if rand_2 != rand_3 or rand_1 != rand_3: lvl1_enemies.append(enemy_3) for enemy in lvl1_enemies: camera.draw(enemy) enemy.y += 12 if enemy.y > character.y: lvl1_enemies.remove(enemy)
def enemieslvl3(): """ :return: third level enemies are created, drop from the top of the screen, and then get removed once it passes mario's location """ global lvl1_enemies global ticks ticks += 1 rand_1 = random.randrange(60, 200) rand_2 = random.randrange(60, 200) rand_3 = random.randrange(60, 200) if game_on: if ticks % rand_1 == 0: enemy_1 = gamebox.from_image(camera.x, camera.top, """https://upload.wikimedia.org/wikipedia/en/thumb/e/ec/Bowser_-_New_Super_Mario_Bros_2.png/220px-Bowser_-_New_Super_Mario_Bros_2.png""") enemy_1.scale_by(0.3) if rand_1 != rand_2: lvl1_enemies.append(enemy_1) if ticks % rand_2 == 0: enemy_2 = gamebox.from_image(150, camera.top, """https://upload.wikimedia.org/wikipedia/en/thumb/e/ec/Bowser_-_New_Super_Mario_Bros_2.png/220px-Bowser_-_New_Super_Mario_Bros_2.png""") enemy_2.scale_by(0.3) lvl1_enemies.append(enemy_2) if ticks % rand_3 == 0: enemy_3 = gamebox.from_image(650, camera.top, """https://upload.wikimedia.org/wikipedia/en/thumb/e/ec/Bowser_-_New_Super_Mario_Bros_2.png/220px-Bowser_-_New_Super_Mario_Bros_2.png""") enemy_3.scale_by(0.3) if rand_2 != rand_3 or rand_1 != rand_3: lvl1_enemies.append(enemy_3) for enemy in lvl1_enemies: camera.draw(enemy) enemy.y += 16 if enemy.y > character.y: lvl1_enemies.remove(enemy)
def splash(keys): global show_splash camera.clear('black') white_house = gamebox.from_image( camera.x, camera.bottom - 190, "http://www.pngmart.com/files/4/White-House-PNG-HD.png") face = gamebox.from_image(830, 240, "http://tinyurl.com/y86pwv9o") title = gamebox.from_text(350, 100, "MISSION TRUMP", 'sys', 100, 'white') white_house.width = 1000 camera.draw(white_house) camera.draw(face) camera.draw(title) camera.draw( gamebox.from_text(350, 150, "Press SPACE to start", 'sys', 30, 'white')) camera.draw(gamebox.from_text(100, 170, "Controls:", 'sys', 30, 'white')) camera.draw(gamebox.from_text(166, 190, "SPACE - Jump", 'sys', 30, 'white')) camera.draw( gamebox.from_text(240, 210, "Right and Left Arrows - Move", 'sys', 30, 'white')) camera.draw( gamebox.from_text(855, 90, "- Avoid FAKE NEWS", 'sys', 30, 'red')) camera.draw(gamebox.from_text(820, 115, "- Collect $$$", 'sys', 30, 'red')) camera.draw( gamebox.from_text(camera.left + 170, camera.bottom - 20, "Quang Nguyen", 'sys', 20, 'white')) menu_music.play(loops=-1) if pygame.K_SPACE in keys: show_splash = False menu_music.stop() background_music.play(loops=-1) camera.display()
def coin_countlvl3(): """ :return: the coins from level three are created and removed if Mario doesn't collect them """ global ticks global score ticks += 1 if game_on: if ticks % random.randrange(40, 60) == 0: coin_1 = gamebox.from_image(camera.x, camera.top, """http://icons.iconarchive.com/icons/ph03nyx/super-mario/256/Retro-Coin-icon.png""") coin_1.scale_by(0.1) coins.append(coin_1) if ticks % random.randrange(40, 60) == 0: coin_2 = gamebox.from_image(150, camera.top, """http://icons.iconarchive.com/icons/ph03nyx/super-mario/256/Retro-Coin-icon.png""") coin_2.scale_by(0.1) coins.append(coin_2) if ticks % random.randrange(40, 60) == 0: coin_3 = gamebox.from_image(650, camera.top, """http://icons.iconarchive.com/icons/ph03nyx/super-mario/256/Retro-Coin-icon.png""") coin_3.scale_by(0.1) coins.append(coin_3) for coin in coins: camera.draw(coin) coin.y += 16 if character.touches(coin): score *= 1.05 coins.remove(coin) if coin.y > camera.bottom: coins.remove(coin)
def create_enemy(species, room_num): if species == 'slime': new = gamebox.from_image(random_x_coord(), random_y_coord(), 'Slime_WIP.png') sprinting.append(None) elif species == 'skeleton': new = gamebox.from_image(random_x_coord(), random_y_coord(), 'Skelly WIP.png') sprinting.append(None) elif species == 'zombie': new = gamebox.from_image(random_x_coord(), random_y_coord(), 'Zombie WIP.png') sprinting.append(0) else: print("not a valid enemy type") new.height = 60 if room_num == 0: room_0_enemies.append([new, True, species]) elif room_num == 1: room_1_enemies.append([new, True, species]) elif room_num == 2: room_2_enemies.append([new, True, species]) elif room_num == 3: room_3_enemies.append([new, True, species]) else: print("not a valid room number")
def snake_generator(keys): """ generate the snake using linked list data structure snake_head is the beginning snake_tail is the end the snake sprite has two additional attributes: their next link and their current direction """ global snake_set global body tail = snake_set[keys][1] # this is the head if tail.direction == "up": body = gamebox.from_image(tail.x, tail.y + snake_size, 'body.png') body.scale_by(0.3) body.direction = "up" elif tail.direction == "down": body = gamebox.from_image(tail.x, tail.y - snake_size, 'body.png') body.scale_by(0.3) body.direction = "down" elif tail.direction == "left": body = gamebox.from_image(tail.x + snake_size, tail.y, 'body.png') body.scale_by(0.3) body.direction = "left" elif tail.direction == "right": body = gamebox.from_image(tail.x - snake_size, tail.y, 'body.png') body.scale_by(0.3) body.direction = "right" body.next = None tail.next = body snake_set[keys][1] = body points(keys)
def saw_attack(): saw_tr.append(gamebox.from_image(boss.x, boss.y, "saw.png")) saw_tl.append(gamebox.from_image(boss.x, boss.y, "saw.png")) saw_bl.append(gamebox.from_image(boss.x, boss.y, "saw.png")) saw_br.append(gamebox.from_image(boss.x, boss.y, "saw.png")) saw_tr[-1].scale_by(.025), saw_tl[-1].scale_by(.025) saw_br[-1].scale_by(.025), saw_bl[-1].scale_by(.025)
def end_frame(player_have_lost): text1 = my_font.render(player_have_lost + " has lost!", True, (0, 200, 0)) while True: init_screen.fill(white) init_screen.blit(text1, [50, 200]) mode1 = gamebox.from_image(200, 300, 'button.png') mode1.scale_by(0.4) mode2 = gamebox.from_image(600, 300, 'button.png') mode2.scale_by(0.4) camera.draw(mode1) camera.draw( gamebox.from_text(200, 300, "Start Over", 25, 'black', True)) camera.draw(mode2) camera.draw( gamebox.from_text(600, 300, "End the Game", 25, 'black', True)) pygame.display.flip() break while True: event = pygame.event.wait() 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: start_frame() 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: sys.exit()
def tick_options(keys): global control_count, option_count, sound_count camera.clear("sky blue") if pygame.K_q in keys: quit() opt1 = gamebox.from_text(683, 200, "press 't' for controller controls", "Cambria", 40, "red") opt2 = gamebox.from_text(683, 500, "press 's' for sound controls", "Cambria", 40, "red") pic1 = gamebox.from_image(683, 350, "https://d30y9cdsu7xlg0.cloudfront.net/png/195040-200.png") pic2 = gamebox.from_image(683, 650, "http://images.clipartpanda.com/music-note-transparent-background-RTAR6agTL.png") back = gamebox.from_text(125, 50, "press 'b' for back", "Cambria", 30, "red") pic1.size = 200, 220 pic2.size = 200, 220 camera.draw(opt1) camera.draw(opt2) camera.draw(pic1) camera.draw(pic2) camera.draw(back) if pygame.K_t in keys: control_count += 1 if pygame.K_s in keys: sound_count += 1 if control_count != 0: control(keys) if pygame.K_b in keys: option_count = 0 if option_count == 0: title(keys) if sound_count != 0: set_all_volume(keys) if control_count == 0 and sound_count == 0: camera.display()
def enemieslvl1(): """ :return: first level enemies are created, drop from the top of the screen, and then get removed once it passes mario's location """ global lvl1_enemies global ticks ticks += 1 rand_1 = random.randrange(60, 200) rand_2 = random.randrange(60, 200) rand_3 = random.randrange(60, 200) if game_on: if ticks % rand_1 == 0: enemy_1 = gamebox.from_image(camera.x, camera.top, """https://aff5fa4925746bf9c161-fb36f18ca122a30f6899af8eef8fa39b.ssl.cf5.rackcdn.com/images/Masthead_Goomba.17345b1513ac044897cfc243542899dce541e8dc.9afde10b.png""") enemy_1.scale_by(0.1) if rand_1 != rand_2: lvl1_enemies.append(enemy_1) if ticks % rand_2 == 0: enemy_2 = gamebox.from_image(150, camera.top, """https://aff5fa4925746bf9c161-fb36f18ca122a30f6899af8eef8fa39b.ssl.cf5.rackcdn.com/images/Masthead_Goomba.17345b1513ac044897cfc243542899dce541e8dc.9afde10b.png""") enemy_2.scale_by(0.1) lvl1_enemies.append(enemy_2) if ticks % rand_3 == 0: enemy_3 = gamebox.from_image(650, camera.top, """https://aff5fa4925746bf9c161-fb36f18ca122a30f6899af8eef8fa39b.ssl.cf5.rackcdn.com/images/Masthead_Goomba.17345b1513ac044897cfc243542899dce541e8dc.9afde10b.png""") enemy_3.scale_by(0.1) if rand_2 != rand_3 or rand_1 != rand_3: lvl1_enemies.append(enemy_3) for enemy in lvl1_enemies: camera.draw(enemy) enemy.y += 8 if enemy.y > character.y: lvl1_enemies.remove(enemy)
def make_player(x, y): """ generates list of player sprites for animation :param x: x coordinate :param y: y coordinate :return: list of player sprites """ global frames, player_down images1 = gamebox.load_sprite_sheet("Textures/naked_up.png", 1, 4) images2 = gamebox.load_sprite_sheet("Textures/naked_down.png", 1, 4) images3 = gamebox.load_sprite_sheet("Textures/naked_left.png", 1, 4) images4 = gamebox.load_sprite_sheet("Textures/naked_right.png", 1, 4) player = [] for image in images1: player.append(gamebox.from_image(x, y, image)) for image in images2: player.append(gamebox.from_image(x, y, image)) for image in images3: player.append(gamebox.from_image(x, y, image)) for image in images4: player.append(gamebox.from_image(x, y, image)) frames = 4 for each in player: each.scale_by(.15) return player
def draw_heart(): global all_hearts all_hearts = [] heart = gamebox.from_image(50, 50, 'heart.png') heart.scale_by(.05) heart2 = gamebox.from_image(100, 50, 'heart.png') heart2.scale_by(.05) all_hearts.append(heart) all_hearts.append(heart2)
def create_tiles(self): tiles = self.level.tiles for i in range(0, len(tiles)): for j in range(0, len(tiles[i])): if not tiles[i][j].walkable: # box = from_color(tiles[i][j].world_x, tiles[i][j].world_y, "red", 50, 50) box = from_image(tiles[i][j].world_x, tiles[i][j].world_y, "Rock.png") box.scale_by(0.5) UI.add_to_draw(box, "game_objects", False) else: box = from_image(tiles[i][j].world_x, tiles[i][j].world_y, "Rock_floor.png") UI.add_to_draw(box, "Tiles", False)
def set_up2(level): """adds additional variables (gameboxes) from 'setup' to create level 2""" global level2screen, background, left_angled_bumper2, right_angled_bumper2, diagonal_bumpers, left_angled_bumpers global right_angled_bumpers, square_bumpers, moving_bumpers, targets, target_dict, coin_1, coin_2, coin_3, coin_4 global coins, boundary level2screen = True setup(level) # change the backbox to level 2 backbox2 = gamebox.from_image(camera_x / 2, 0, 'backbox_lvl_2.png') backbox2.scale_by(.30) backbox2.top = camera.top background.append(backbox2) # new diagonal bumpers left_angled_bumper2 = create_diagonal_45(camera_x / 2 - 110, 320, camera_x / 2 - 150, 15, 'blue') left_angled_bumpers.append(left_angled_bumper2) diagonal_bumpers.append(left_angled_bumper2) right_angled_bumper2 = create_diagonal_45(camera_x / 2 + 110, 320, camera_x / 2 + 150, 15, 'blue') right_angled_bumpers.append(right_angled_bumper2) diagonal_bumpers.append(right_angled_bumper2) # new square bumper square_bumper3 = gamebox.from_color(camera_x / 2, 400, 'red', 40, 25) square_bumpers.append(square_bumper3) # new moving bumper moving_bumper_4 = gamebox.from_color(camera_x / 2 - 45, 325, 'black', 75, 15) moving_bumpers.append(moving_bumper_4) # new target target200_1 = gamebox.from_image(400, 300, 'target200_1.png') target200_1.scale_by(.1) targets.append(target200_1) target_dict[3] = 200 # add the points to the target dictionary # new coins coin_3 = gamebox.from_image(camera_x / 2, 380, 'gold_coin.png') coin_4 = gamebox.from_image(boundary[1].left - 10, boundary[2].bottom + 10, 'gold_coin.png') for each in [coin_3, coin_4]: coins.append(each) for each in [coin_1, coin_2]: # remove old coins coins.remove(each) for each in coins: each.scale_by(.1)
def enemy_movement( ): # enemy coming randomly from left or right and the number and # shooting frequency are based on level global count, frame_enemy_0, frame_enemy_1 count += 1 frame_enemy_0 += 1 frame_enemy_1 += 1 if frame_enemy_1 == number_of_frame_enemy_1 + 3: frame_enemy_1 = 0 if frame_enemy_0 == number_of_frame_enemy_0 * 6: frame_enemy_0 = 0 if count % (180 // level) == 0: direction = random.randint(0, 1) if direction == 0: enemy_0.append( gamebox.from_image(450, 0, enemy_0_sheet[frame_enemy_0])) if direction == 1: enemy_1.append( gamebox.from_image(-50, 0, enemy_1_sheet[frame_enemy_1])) for unit0 in enemy_0: if count % 1 == 0: unit0.image = enemy_0_sheet[frame_enemy_0] unit0.move(-3, 2 * random.random()) if unit0.x < -500: enemy_0.remove(unit0) if count % (90 // level) == random.randint(0, 18): enemy_bullet0.append( gamebox.from_image(unit0.x, unit0.y, "img/enemy missile.png")) camera.draw(unit0) for i in enemy_bullet0: i.y += 5 if i.y > 700: enemy_bullet0.remove(i) camera.draw(i) for unit1 in enemy_1: if count % 1 == 0: unit1.image = enemy_1_sheet[frame_enemy_1] unit1.move(3, 2 * random.random()) if unit1.x > 900: enemy_1.remove(unit1) if count % (90 // level) == random.randint(0, 18): enemy_bullet1.append( gamebox.from_image(unit1.x, unit1.y, "img/enemy missile.png")) camera.draw(unit1) for i in enemy_bullet1: i.y += 5 if i.y > 700: enemy_bullet1.remove(i) camera.draw(i)
def start_screen(keys): global screendone, start camera.clear('cadet blue') screen1 = gamebox.from_image(0, 0, 'Screen1.png') screen1.center = camera.center screen2 = gamebox.from_image(0, 0, 'StarScreen2.png') screen2.center = camera.center if screendone != True: camera.draw(screen1) if pygame.K_b in keys: screendone = True if screendone: camera.draw(screen2) if pygame.K_g in keys: start = True
def draw_lives(num_lives): '''draws the lives''' first_x = camera.right - 20 y = camera.top + 50 for i in range(num_lives): life = gamebox.from_image(first_x - i * 40, y, 'heart.png') camera.draw(life)
def coin_collectibles(keys): global counter, frame, sheet, coin_lst, time1, player_lst, score player = player_lst[0] # coin for coin in coin_lst: if player.touches(coin): score += 1 coin_lst.remove(coin) camera.draw(coin) if frame >= number_of_frames: frame = 0 if counter % 1 == 0: # control coin spinning speed by changing 1 coin.image = sheet[frame] frame += 1 counter += 1 time1 += 1 if time1 % 60 == 0: coin_x = random.randint(50, 750) coin_y = random.randint(200, 480) for coin in coin_lst: if coin_x == coin.x: coin_x -= 100 if coin_y == coin.y: coin_y -= 100 new_coin = gamebox.from_image(coin_x, coin_y, sheet[0]) new_coin.scale_by(.5) coin_lst.append(new_coin)
def end_game(): global level, game_over level = -2 camera.draw(gamebox.from_image(400, 300, 'GameOver.png')) game_over = False if camera.mouseclick: gamebox.stop_loop()
def splash(keys): global screen, ticks #camera.clear('cyan') back = gamebox.from_image(50, 100, 'stars.png') back.scale_by(1.5) camera.draw(back) text = gamebox.from_text(400, 100, "Battle for Planet Wassel", "Arial", 50, 'white') names = gamebox.from_text(400, 100, "By Alex Wassel", "Arial", 20, 'white') names.top = text.bottom camera.draw(text) camera.draw(names) directions = gamebox.from_text( 400, 300, "Player 1: use W to move your spaceship up and S to move it down. Use the Space Bar to shoot.", "Arial", 17, 'white') directions1 = gamebox.from_text( 400, 300, "Player 2: use the Up and Down arrow keys to move your spaceship. Use the comma key to shoot.", "Arial", 17, 'white') directions2 = gamebox.from_text(400, 300, "Press SPACE to start", "Arial", 20, 'yellow') camera.draw(directions) directions1.top = directions.bottom directions2.top = directions1.bottom camera.draw(directions1) camera.draw(directions2) if pygame.K_SPACE in keys: screen = False camera.display()
def loading_screen(keys): """ :param keys: keys used to start the game :return: once the keys are hit, the player gets transferred to the intro screen """ global ticks global background_number ticks += 1 camera.clear("Black") background_intro = gamebox.from_image(camera.x, camera.y, """http://www.desktopimages.org/pictures/2014/0522/1/video-games-mario-bowser-princess-peach-goomba-wallpaper-455562.jpg""") background_intro.scale_by(1.2) text = "Press SPACE BAR to Begin" loading_screen_text = gamebox.from_text(400, 320, text, 60, "white", bold=False) game_name = "Mario's Quest" name_text = "Michael Masner(mm6md) and Joel Tavarez(jt3bk)" game_title = gamebox.from_text(400, 230, game_name, 85, "white", italic=True, bold=True) names = gamebox.from_text(400, 450, name_text, 45, "cyan", bold=False) camera.draw(background_intro) camera.draw(game_title) camera.draw(loading_screen_text) camera.draw(names) if pygame.K_SPACE in keys: background_number += 1
def check_collision(): global ship global asteroids global t1_start global lives global enemies_onscreen global game_over for i in asteroids: for g in ships: if i.touches(g): if len(asteroids) > 0: asteroids.remove(i) ships.remove(g) ship = gamebox.from_image(ship.x, ship.y, 'explosion.png') ships.append(ship) camera.draw(ship) asteroids = [] enemies_onscreen = 0 for d in all_hearts: all_hearts.remove(d) break camera.display() sleep(2) t1_start += 3 if lives > 0: lives -= 1 draw_ship() else: print('hit') lives -= 1 game_over = True check_highscore()
def draw_coin(speed): global coin coin = gamebox.from_image(random.randrange(0, 800), random.randrange(-100, 0), coins[0]) coin.scale_by(0.2) coin.speedy = speed return coin
def make_trainer(x, y): """ creates enemy pokemon trainer sprites :param x: x coordinate :param y: y coordinate :return: trainer and trainer2 lists of sprites """ images1 = gamebox.load_sprite_sheet("Textures/player_left.png", 1, 4) images2 = gamebox.load_sprite_sheet("Textures/player_right.png", 1, 4) trainer = [] for image in images1: trainer.append(gamebox.from_image(x, y, image)) for image in images2: trainer.append(gamebox.from_image(x, y, image)) trainer2 = trainer return trainer, trainer2
def lvl2_startscreen(keys): global lvl_two_go camera.clear('cadet blue') lvl2_Screen = gamebox.from_image(0, 0, 'Screenlvl2.png') lvl2_Screen.center = camera.center camera.draw(lvl2_Screen) if pygame.K_h in keys: lvl_two_go = True
def dead_enemy(bad): global kill_count if kill_count < 5: # kill_count bar can only be filled to 5 kill_count += 1 maybe = random.randrange(100) if maybe > 75: new_life = gamebox.from_image(bad.x, bad.y, 'Heart.png') life.append(new_life)
def defeated_by_m(): global defeated if defeated: camera.clear('paleturquoise') defeat = gamebox.from_image(0, 0, 'defeated.png') defeat.center = camera.center camera.draw(defeat) gamebox.pause()
def make_walker(x, y): global frames images = gamebox.load_sprite_sheet("walk_stand.png", 1, 6) frames = len(images) walker = [] # walker is a list of gameboxes for image in images: walker.append(gamebox.from_image(x, y, image)) return walker
def enemy_fire(enemy): if enemy == boss: arrow = gamebox.from_image(enemy.x, enemy.y, 'PhantonBlast.png') else: arrow = gamebox.from_image(enemy.x, enemy.y, 'Arrow.png') arrow_speed = 10 x_diff = character.x - enemy.x y_diff = character.y - enemy.y scalar = math.sqrt( x_diff**2 + y_diff**2) // arrow_speed # ensures that all arrows travel same speed direction = x_diff / scalar, y_diff / scalar if x_diff < 0: # flip enemies moving to the left arrow.flip() if enemy == boss: boss_arrows.append((arrow, direction)) else: skeleton_arrows.append((arrow, direction))
def draw_stats(): """draws the gameplay information (lives, score)""" scorebox = gamebox.from_text(75, 25, "score: " + str(score), 36, 'red') camera.draw(scorebox) for i in range(lives): heart = gamebox.from_image(775, 25, 'heart.png') heart.x -= 50 * i heart.scale_by(0.5) camera.draw(heart)
def level3_screen(keys): """displays the level 3 screen and starts level 3 when '3' is pressed""" global level3screen camera.clear('white') level3image = gamebox.from_image(367, camera_y / 2, 'level3screen.png') level3image.scale_by(.65) camera.draw(level3image) if pygame.K_3 in keys: level3screen = False
def create_enemy(): # enemy = gamebox.from_color(random.randint(0, 800), random.randint(0,2) * 75 + 50, "yellow", 50, 50) enemy = gamebox.from_image(random.randint(0, 800), random.randint(0, 2) * 75 + 50, enemy_animations[0]) # randomize their speed and direction enemy.xspeed = random.randint(3, 10) if random.randint(0,1) == 0: enemy.xspeed *= -1 return enemy
def platform_creator(): global plat_count, scroll_speed, platforms height_position = random.randint(400, 700) mirror_position = height_position - 500 new_platform = gamebox.from_image(800, height_position, "pipe_b.png") mirror_platform = gamebox.from_image(800, mirror_position, "pipe_u.png") if plat_count < 120: plat_count += 1 if plat_count == 120: platforms.append(new_platform) platforms.append(mirror_platform) plat_count = 0 for platform in platforms: platform.x -= scroll_speed if platform.x < -50: platforms.remove(platform) for platform in platforms[::2]: if 200 <= platform.x < 200 + scroll_speed: platform.x -= scroll_speed
def y_coins(): global p1_score, platforms, yellow_coins, scroll_speed, p1_health, tick_count, tick_count_2 for platform in platforms[1::2]: if 600 <= platform.x < 600 + scroll_speed: coin_height = random.randint(150, 450) yellow_coin = gamebox.from_image(800, coin_height, "coin_1.png") yellow_coins.append(yellow_coin) if yellow_coin.touches(platform): yellow_coin.move_to_stop_overlapping(platform) for yellow_coin in yellow_coins: yellow_coin.image = "coin_"+str(tick_count_2+1)+".png" yellow_coin.x -= scroll_speed if p1.touches(yellow_coin): yellow_coins.remove(yellow_coin) p1_score += 1 music0 = gamebox.load_sound("hit_sound.wav") musicplayer0 = music0.play() if yellow_coin.x < -50: yellow_coins.remove(yellow_coin) tick_count = (tick_count+1) % 128 tick_count_2 = tick_count//16
# Matthew Keitelman (mak2vr) # Fernando Mata Cordero (fm5ew) import pygame import gamebox import random camera = gamebox.Camera(1000,800,True) alien = gamebox.from_image(300, 15, "http://people.virginia.edu/~mak2vr/files/alien/alien.png") alien.scale_by(1.3) alien.yspeed = 0 platforms = [ gamebox.from_color(500,400,"black",1000,30), gamebox.from_color(1500,600,"black",500,30), ] radius = 250 platform_x = 1500 platform_length = 500 platform_end = 1750 prev_length = 0 prev_end = 0 prev_x = 0 prev_radius = 0 platform_end time_on = 300 y=0
jump_check = 0 seconds = 0 minutes = 0 jf_stage = 1 spat_stage = 1 secretformula_check = 0 spat_check = 0 stick_check = 0 pizza_health = 8 bear_stage = 1 move_check = 0 cockroach_list = [] platform_list = [] c_stage = 1 rock_stage = 1 customer_house = gamebox.from_image(35320, y-30, "customers_house.png") customer_house.scale_by(2) rock = gamebox.from_image(origin_x, origin_y, "rock_4.png") ground = gamebox.from_color(0, y + 230, "Peach Puff", 100000, 150) sand = [] house = [gamebox.from_image(5320, y - 100, "track.png"), gamebox.from_image(21320, y - 100, "track.png"), gamebox.from_image(37320, y - 100, "track.png")] wall = [gamebox.from_color(0, y, "White", 520, 1000), gamebox.from_color(10000, y, "White", 520, 1000)] cockroach_an = [] for i in range(1, 50): background.append(gamebox.from_image(x/2 + 1000*(i - 1), y/2, "backgrund.jpg")) sand.append(gamebox.from_image(x, y+140, "ground.png")) if i < 2 or i > 3:
play_count = 0 option_count = 0 control_count = 0 sound_count = 0 camera = global_stage.camera level_1 = 0 level_2 = 0 level_3 = 0 wasd_count = 0 sound_level = 0.5 char1 = gamebox.from_color(10, 10, "red", 50, 5) char2 = gamebox.from_text(250, 50, "ya Motha", "Cambria", 70, "orange", True, True) # char3 = gamebox.from_image(100, 100, "http://images6.fanpop.com/ # image/photos/33000000/The-Customer-s-House-krusty-krab-pizza-33032845-512-384.jpg") char3 = gamebox.from_image(200, 400, "http://3219a2.medialib.glogster.com/creeperman913/media" "/18/18ee0bb8dd40f9d96af0d3dfd14687f97923fdf2/spongebob.png") char4 = gamebox.from_text(350, 150, "By Luke and Connor (lsm5fm and cb4wa)", "Cambria", 30, "orange", False, True) char5 = gamebox.from_text(683, 200, "Press 'P' to Play", "Cambria", 50, "red") char6 = gamebox.from_text(683, 400, "Press 'O' for Options", "Cambria", 50, "red") char7 = gamebox.from_text(683, 600, "Press 'C' for Credits", "Cambria", 50, "red") titlebackground = gamebox.from_image(683, 384, "http://i.imgur.com/liXLthM.png") titlebackground.size = 1366, 768 pygame.mouse.set_visible(False) def set_all_volume(keys): global sound_count, sound_level camera.clear("sky blue") if pygame.K_q in keys: quit()
# Matthew Keitelman (mak2vr) # Fernando Mata Cordero (fm5ew) import pygame import gamebox camera = gamebox.Camera(1000,800,True) alien = gamebox.from_image(150, 10, "alien.png") alien.scale_by(1.4) alien.yspeed = 0 levels = gamebox.from_image(400,400,"levels.png") levels.scale_by(1.5) blue_hole_sheet = gamebox. platforms = [ # gamebox.from_color(-100, 600, "black", 3000, 100), levels # ground1 ] def tick(keys): # GRAVITY alien.yspeed += 1 alien.y = alien.y + alien.yspeed if pygame.K_s in keys: alien.image = "alien_top.png" elif pygame.K_d in keys:
import pygame import gamebox import random # camera camera = gamebox.Camera(800, 600) # player ship player_animations = gamebox.load_sprite_sheet("PlayerSprite.png", 1, 6) player = gamebox.from_image(400, 550, player_animations[0]) # player = gamebox.from_color(400, 550, "red", 30, 30) # default bullets bullet1 = gamebox.from_color(-5, 520, "yellow", 5, 5) bullet2 = gamebox.from_color(-5, 520, "yellow", 5, 5) bullet3 = gamebox.from_color(-5, 520, "yellow", 5, 5) bullets = [bullet1, bullet2, bullet3] # enemies and their weapons enemies = [] en_bullet1 = gamebox.from_color(-5, 520, "red", 5, 5) en_bullet2 = gamebox.from_color(-5, 520, "red", 5, 5) en_bullet3 = gamebox.from_color(-5, 520, "red", 5, 5) en_bullets = [en_bullet1, en_bullet2, en_bullet3] enemy_animations = gamebox.load_sprite_sheet("EnemySprite.png", 1, 6) def create_enemy(): # enemy = gamebox.from_color(random.randint(0, 800), random.randint(0,2) * 75 + 50, "yellow", 50, 50) enemy = gamebox.from_image(random.randint(0, 800), random.randint(0, 2) * 75 + 50, enemy_animations[0])
tick_count = 0 wave_started = False PRE_WAVE_TIME = 30 TANK_VALUE = 100 # Camera camera = gamebox.Camera(800, 600) # Images tank_image_url = "http://www.xnaresources.com/images/tutorialimages/sprites/MulticolorTanks.png" tank_sprite_sheet = gamebox.load_sprite_sheet(tank_image_url, 8, 8) background_path = "background001.png" background = gamebox.from_image(400, 300, background_path) boom_image_url = "http://flashvhtml.com/html/img/action/explosion/Explosion_Sequence_A%2012.png" tankstuff.Boom.image = boom_image_url mine_image_path = "mine001.png" tankstuff.Mine.image = mine_image_path #Game Objects enemy_tanks = [] friendly_tanks = [] bullets = [] barriers = [] mines = [] turrets = [] buttons = []
def tick(keys): global player_one_frame global player_two_frame global player_one_has_flag global player_two_has_flag global player_one_counter global player_two_counter global game_start global game_end global direction global counter global timer global monster_frame global monster_sheet global touched_monster if game_start: camera.clear("black") beginning_title = gamebox.from_text(400, 250, "CAPTURE THE FLAG", "Arial", 46, "white") beginning_description = gamebox.from_text(400, 325, "PRESS SPACEBAR TO BEGIN", "Arial", 46, "white") camera.draw(beginning_title) camera.draw(beginning_description) if pygame.K_SPACE in keys: game_start = False else: timer -= 1 camera.clear("green") player_one_frame += 1 player_two_frame += 1 counter += 1 #animate the monster so that he walks in place monster_frame +=1 #adjusts hulks speed here. #make the monster move ahead monster.y +=20 if monster.y == 800: monster.y = 0 if monster_frame == 16: monster_frame = 12 if player_one_frame == 12: player_one_frame = 8 if player_two_frame == 8: player_two_frame = 4 if counter % 5 == 0: player_one.image = player_one_sheet[player_one_frame+direction*10] player_two.image = player_two_sheet[player_two_frame+direction*10] #place the monster on screen monster.image = monster_sheet[monster_frame + direction*10] if pygame.K_RIGHT in keys: player_one.x += 10 if pygame.K_LEFT in keys: player_one.x -= 10 if pygame.K_UP in keys: player_one.y -= 10 if pygame.K_DOWN in keys: player_one.y += 10 if pygame.K_d in keys: player_two.x += 10 if pygame.K_a in keys: player_two.x -= 10 if pygame.K_w in keys: player_two.y -= 10 if pygame.K_s in keys: player_two.y += 10 # detect if player 2 touched monster if player_two.touches(monster): game_end = True touched_monster = 2 # detect if player 1 touched monster if player_one.touches(monster): game_end = True touched_monster = 1 for flag in player_one_flag: if player_two.touches(flag): flag_sound.play() player_two_has_flag = True player_one_flag.remove(flag) camera.draw(flag) for flag in player_two_flag: if player_one.touches(flag): flag_sound.play() player_one_has_flag = True player_two_flag.remove(flag) camera.draw(flag) if player_one.touches(player_one_goal) and player_one_has_flag: goal_sound.play() new_flag = gamebox.from_image(750, 550, "red.png") player_two_flag.append(new_flag) player_two_flag[0].scale_by(0.15) player_one_counter += 1 player_one_has_flag = False if player_two.touches(player_two_goal) and player_two_has_flag: goal_sound.play() new_flag = gamebox.from_image(50, 50, "blue.png") player_one_flag.append(new_flag) player_one_flag[0].scale_by(0.15) player_two_counter += 1 player_two_has_flag = False player_one_counter_text = gamebox.from_text(75, 75, str(player_one_counter), "Arial", 28, "blue", italic = True) player_two_counter_text = gamebox.from_text(775, 575, str(player_two_counter), "Arial", 28, "red", italic = True) timer_display = gamebox.from_text(400, 25, str(timer // 30) + " seconds", "Arial", 46, "black") camera.draw(player_one) camera.draw(player_two) #draw the monster on screen camera.draw(monster) camera.draw(player_one_goal) camera.draw(player_two_goal) camera.draw(player_one_counter_text) camera.draw(player_two_counter_text) camera.draw(timer_display) if timer == 0: game_end = True if game_end: camera.clear("black") game_over_text = gamebox.from_text(400, 250, "GAME OVER", "Arial", 46, "white") continue_text = gamebox.from_text(400, 400, "PRESS ENTER TO REPLAY", "Arial", 46, "white") # player one had touched monster if touched_monster == 1: win_text = gamebox.from_text(400, 325, "PLAYER 2 wins as PLAYER 1 was eaten by monster", "Arial", 30, "white") # player 2 had touched monster elif touched_monster == 2: win_text = gamebox.from_text(400, 325, "PLAYER 2 wins as PLAYER 1 was eaten by monster", "Arial", 30, "white") elif player_one_counter > player_two_counter: win_text = gamebox.from_text(400, 325, "PLAYER 1 WINS WITH " + str(player_one_counter) + " FLAGS", "Arial", 46, "white") elif player_two_counter > player_one_counter: win_text = gamebox.from_text(400, 325, "PLAYER 2 WINS WITH " + str(player_two_counter) + " FLAGS", "Arial", 46, "white") else: win_text = gamebox.from_text(400, 325, "TIE", "Arial", 46, "white") camera.draw(game_over_text) camera.draw(win_text) camera.draw(continue_text) # reset the numbers if pygame.K_RETURN in keys: game_end = False game_start = True timer = 30 * 60 player_one_counter = 0 player_two_counter = 0 touched_monster = 0 player_one.x = 350 player_one.y = 300 player_two.x = 450 player_two.y = 300 camera.display()
#add monster sprite sheet monster_sheet = gamebox.load_sprite_sheet("http://untamed.wild-refuge.net/images/rpgxp/avengers/hulk.png", 4, 4) player_one_frame = 8 player_two_frame = 4 #starting frame of monster looking downards monster_frame = 12 timer = 30*60 direction = 0 counter = 0 player_one = gamebox.from_image(350, 300, player_one_sheet[player_one_frame]) player_two = gamebox.from_image(450, 300, player_two_sheet[player_two_frame]) #set monster between the two monster = gamebox.from_image(400, 300, monster_sheet[monster_frame]) # a monster should be bigger than both of them monster.scale_by(1.5) touched_monster = 0 #blue.png is essentially the blue flag player_one_flag = [gamebox.from_image(50, 50, "blue.png")] player_one_flag[0].scale_by(0.15) player_one_goal = gamebox.from_color(100, 300, "blue", 10, 600) # goal line for player 1 player_one_counter = 0
def sponge_run_function(keys): global cockroach_count, hit_moment, hit_interval, hit_check, pizza_health, c_stage, jump_check, time, rock_stage platform_object = [] if pygame.K_q in keys: quit() platform_object.append(ground) for platform in platform_list: platform_object.append(gamebox.from_color(platform.x, platform.y + 15, "white", 240, 100)) hit_interval += 1 time += 2 rock.yspeed += 1 if hit_interval == 2 and global_stage.level == 2 and level_one.spat_check == 1: camera.move(-9200, 0) if pygame.K_DOWN in keys: rock.yspeed += 4 c_stage += 1/1.7 if hit_interval == hit_moment + 25: hit_check = 0 if c_stage >= 4: c_stage = 1 if time == 30: time = 0 jump_check = 0 if rock.bottom_touches(ground): rock_stage += 1/1.2 if int(rock_stage) >= 4: rock_stage = 1 if not rock.bottom_touches(ground): rock_stage = 4 rock.x = rock.x + rock.speedx rock.y = rock.y + rock.speedy ''' for platform in platform_object: platform.y = platform.y + platform.yspeed ''' # ----- COLLISION ------ for cockroach in cockroach_list: if rock.touches(cockroach) and hit_check == 0: hit_moment = hit_interval pizza_health -= 1 hit_check = 1 if rock.x > 35250: quit() for platform in platform_object: if rock.bottom_touches(platform): rock.yspeed = 0 rock.move_to_stop_overlapping(platform) if platform != platform_object[0]: platform.y += 100 if pygame.K_SPACE in keys: rock.yspeed = -20 jump_check = 1 if rock.right_touches(platform) and hit_check == 0: pizza_health -= 1 hit_check = 1 hit_moment = hit_interval if pizza_health == 0: quit() # ----- GEN ANIMATION ----- health_file = 'pizza_health_{}'.format(pizza_health) + ".png" health_hud = gamebox.from_image(rock.x + 4*x/5, 100, health_file) rock_file = 'rock_{}'.format(int(rock_stage)) + '.png' rock_an = gamebox.from_image(rock.x, rock.y, rock_file) camera.clear("White") if hit_check == 1: rock_stage = 4 rock.xspeed = 15 else: rock.xspeed = 25 for shift in range(3): if hit_check == 1 and hit_interval >= hit_moment + shift*4 and hit_interval < hit_moment + (shift+1)*4: rock_an.rotate(random.randint(-30, 5)) # ----- DRAWING ------ camera.clear("Black") 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) camera.display()
hit_interval = 0 circle_stage = 1 face_check = 0 time = 0 jump_check = 0 seconds = 0 minutes = 0 jf_stage = 1 spat_stage = 1 secretformula_check = 0 spat_check = 0 stick_check = 0 health = 3 bear_stage = 1 move_check = 0 platforms = [gamebox.from_image(5385, y/2 - y/6, "platform_kelp.png"), gamebox.from_image(5180, y/2 - y/6, "platform_kelp.png")] character = gamebox.from_image(origin_x, origin_y, 'spongebob_run.png') ground = gamebox.from_color(0, y, "Peach Puff", 100000, 70) house = gamebox.from_image(5320, y - 240, "house.png") wall = [gamebox.from_color(0, y, "White", 520, 1000), gamebox.from_color(10000, y, "White", 950, 1000)] bear_list = [gamebox.from_image(6900, y - y/10, "seabear_1.png"), gamebox.from_image(8500, y - y/10, "seabear_1.png"), gamebox.from_image(4500, y - y/10, "seabear_1.png"), gamebox.from_image(5000, y - y/10, "seabear_1.png"), gamebox.from_image(4000, y - y/10, "seabear_1.png"), gamebox.from_image(3500, y - y/10, "seabear_1.png"), gamebox.from_image(2500, y - y/10, "seabear_1.png"), gamebox.from_image(3000, y - y/10, "seabear_1.png")] jump_list = [ground] jf_list = [gamebox.from_image(5550, y/2 + 20, "jellyfish_1.png"), gamebox.from_image(5575, y/2 + 20, "jellyfish_1.png"), gamebox.from_image(2850, y/2 + 20, "jellyfish_1.png"), gamebox.from_image(2875, y/2 + 20, "jellyfish_1.png")] kelp_list = [] for xy in range(4):
def tick(keys): global hit_interval, hit_moment, hit_check, health, secretformula_check, stick_check,\ move_check, x, y, stage, face_check, time, seconds, minutes, jf_stage, check, \ spat_stage, spat_check, bear_stage, circle_stage, x_coord, level hud = [gamebox.from_color(character.x, 0, "White", 100000, 120)] hit_interval += 1 character.xspeed = 0 character.yspeed += 1 circle_check = 0 time += 1 jf_stage += 1/3 spat_stage += 1/3 bear_stage += 1/3 if circle_stage >= 9: circle_stage = 8 if time == 30: seconds += 1 move_check = 0 if time == 60: check = 0 time = 0 seconds += 1 if seconds == 60: seconds = 0 minutes += 1 if int(seconds) < 10: second = '0{}'.format(str(seconds)) else: second = str(seconds) if hit_moment + 30 == hit_interval: hit_check = 0 for jellyfish in jf_list: if time < 30: jellyfish.yspeed = -2 else: jellyfish.yspeed = 2 jellyfish.y = jellyfish.y + jellyfish.yspeed for bear in bear_list: if time < 30: bear.speedx = -10 else: bear.speedx = 10 bear.x = bear.x + bear.speedx character.y = character.y + character.yspeed # ----- GEN ANIMATION ----- timer = gamebox.from_text(character.x - 225, y/25, "{}".format(str(int(minutes))) + ":{}".format(second), "haettenschweiler", 40, "Black") hud.append(timer) tie_hud = gamebox.from_image(character.x + 400, y/20 - 20, "tie_hud.png") tie_hud.scale_by(0.8) hud.append(tie_hud) secretformula_hud_file = 'secretformula_check{}'.format(str(secretformula_check)) + ".png" secretformula_hud = gamebox.from_image(character.x - 50, y/20 - 5, secretformula_hud_file) hud.append(secretformula_hud) health_hud_file = 'health_hud_1.png' health_hud_a = gamebox.from_image(character.x + 850, y/20 - 8, health_hud_file) health_hud_b = gamebox.from_image(character.x + 925, y/20 - 8, health_hud_file) health_hud_c = gamebox.from_image(character.x + 1000, y/20 - 8, health_hud_file) if health <= 2: health_hud_a = gamebox.from_image(character.x + 850, y/20 - 8, 'health_hud_0.png') if health <= 1: health_hud_b = gamebox.from_image(character.x + 925, y/20 - 8, 'health_hud_0.png') if health <= 0: health_hud_c = gamebox.from_image(character.x + 1000, y/20 - 8, 'health_hud_0.png') hud.append(health_hud_a) hud.append(health_hud_b) hud.append(health_hud_c) stick_hud_file = "stick_check{}".format(str(stick_check)) + ".png" stick_hud= gamebox.from_image(character.x - 150, y/20 - 5, stick_hud_file) hud.append(stick_hud) spat_hud_file = "spat_check{}".format(str(spat_check))+".png" spat_hud = gamebox.from_image(character.x - 100, y/20, spat_hud_file) hud.append(spat_hud) if stage >= 7: stage = 1 if spat_stage >= 4 or bear_stage >= 4: spat_stage = 1 bear_stage = 1 if int(jf_stage) == 8: jf_stage = 1 sb = 'running_{}'.format(str(int(stage)))+'.png' character_an = gamebox.from_image(character.x, character.y - 10, sb) character_an.scale_by(.5) jf_file = 'jellyfish_{}'.format(str(int(jf_stage)))+'.png' jellyfish_an = [] secretformula_file = 'secretformula_{}'.format(str(int(spat_stage)))+".png" secretformula = gamebox.from_image(7500, 700, secretformula_file) spat_file = 'spatula_{}'.format(str(int(spat_stage)))+".png" spatula = gamebox.from_image(5100, 100, spat_file) stick_file = 'stick_{}'.format(str(int(spat_stage)))+".png" stick = gamebox.from_image(2100, 100, stick_file) circle = gamebox.from_image(character.x, character.y + 30, 'circle_8.png') bear_an = [] seabear_file = 'seabear_{}'.format(str(int(bear_stage)))+".png" # ----- DRAW DISTANCE ----- for bear in bear_list: if character.x + 1123 > bear.x and character.x - 300 < bear.x: bear_an.append(gamebox.from_image(bear.x, bear.y, seabear_file)) for seabear in bear_an: if time > 30: seabear.flip() for jellyfish in jf_list: if character.x + 1123 > jellyfish.x and character.x - 300 < jellyfish.x: jellyfish_an.append(gamebox.from_image(jellyfish.x, jellyfish.y, jf_file)) if pygame.K_q in keys: quit() # ----- WASD INPUT ----- if character.touches(ground) and stick_check == 1: if pygame.K_c in keys: circle_check = 1 else: circle_check = 0 if global_stage.wasd_count != 0: if pygame.K_d in keys and circle_check == 0: character.xspeed += 9.5 character.x += 9.5 for item in hud: item.speedx += 9.5 if face_check == 1: character_an.flip() face_check = 0 if pygame.K_a in keys and circle_check == 0: character.speedx -= 9.5 character.x -= 9.5 for item in hud: item.speedx -= 9.5 if face_check == 0: character_an.flip() face_check = 1 # -----WASD COLLISION ----- for object in jump_list: if character.bottom_touches(object): if pygame.K_a not in keys and pygame.K_d not in keys: stage = 1 if pygame.K_a in keys or pygame.K_d in keys and pygame.K_SPACE not in keys: stage += 1/1.3 character.yspeed = 0 character.move_to_stop_overlapping(object) if pygame.K_SPACE in keys: stage = 5 character.yspeed = -16 # ----- ARROW INPUT ----- if global_stage.wasd_count == 0: if pygame.K_RIGHT in keys and circle_check == 0: character.xspeed += 95 character.x += 95 for item in hud: item.speedx += 9.5 if face_check == 1: character_an.flip() face_check = 0 if pygame.K_LEFT in keys and circle_check == 0: character.speedx -= 9.5 character.x -= 9.5 for item in hud: item.speedx -= 9.5 if face_check == 0: character_an.flip() face_check = 1 # ----- ARROW COLLISION ----- for object in jump_list: if character.bottom_touches(object): if pygame.K_LEFT not in keys and pygame.K_RIGHT not in keys: stage = 1 if pygame.K_LEFT in keys or pygame.K_RIGHT in keys and pygame.K_SPACE not in keys: stage += 1/1.3 character.yspeed = 0 character.move_to_stop_overlapping(object) if pygame.K_SPACE in keys: stage = 5 character.yspeed = -16 for w in wall: if character.touches(w): character.move_to_stop_overlapping(w) if character.touches(spatula) and spat_check == 0: spat_check = 1 not_lame.play() if character.touches(stick) and stick_check == 0: stick_check = 1 not_lame.play(0) if character.touches(secretformula) and secretformula_check == 0: secretformula_check = 1 not_lame.play(0) for platform in platforms: if character.bottom_touches(platform): if pygame.K_DOWN in keys: character.y = character.y + y/10 # ----- DEATH CHECK ----- for jellyfish in jf_list: if character.bottom_touches(jellyfish): stage = 2 if character.top_touches(jellyfish) and hit_check == 0: health -= 1 hit_check = 1 hit_moment = hit_interval for seabear in bear_an: if character.touches(seabear) and hit_check == 0 and circle_check == 0: health -= 1 hit_check = 1 hit_moment = hit_interval if circle_check == 1 and character.touches(seabear): health += 0 if health == 0: character_an = gamebox.from_image(character.x, character.y, 'crying.png') gamebox.pause() # ----- DRAWING ----- camera.clear("Black") for entry in background: camera.draw(entry) camera.draw(ground) camera.draw(house) for jellyfish in jellyfish_an: camera.draw(jellyfish) if secretformula_check == 0: camera.draw(secretformula) if stick_check == 0: camera.draw(stick) if spat_check == 0: camera.draw(spatula) for seabear in bear_an: camera.draw(seabear) if face_check == 1: character_an.flip() if circle_check == 1: camera.draw(circle) camera.draw(character_an) for entry in hud: camera.draw(entry) for platform in platforms: if character.x + 1300 > platform.x and character.x - 400 < platform.x: camera.draw(platform) camera.move(character.speedx, 0) if health == 0: x_coord = character.x if stick_check == 1 and spat_check == 1 and secretformula_check == 1 and character.x >= 9400: camera.draw(gamebox.from_image(9750, 400,"continue.png")) level = 2 camera.display() health = 3 spat_check = 1 secretformula_check = 1 stick_check = 1
def tick(keys): for bluehole in blueholes: bluehole.scale_by(1.018) global x, score, y, platform_x, time_on, speed, platform_length, platform_end, prev_length, prev_end, prev_x, radius, prev_radius if y > 3: y =0 y+=1 if camera.x % 1000 == 0: speed += 4 score = int(camera.x) scoreboard = gamebox.from_text(camera.x+300,50,(str(score)),"Verdana",26,"black") camera.x += speed alien.x += speed if alien.x >= (platform_x - platform_length/2) and alien.x <= (platform_x - platform_length/2): time_on += speed elif alien.x >= platform_x - platform_length/2: time_on = 0 if len(platforms) < 10: prev_length = int(platform_length) prev_x = int(platform_x) prev_end = int(platform_end) prev_radius = radius platform_length = int(random.randint(300,600)) radius = int(platform_length/2) platform_x = prev_end + radius + random.randint(25,200) platform_end = platform_x + radius height = random.randint(300,700) platforms.append(gamebox.from_color(platform_x,height,"black",2*radius,30)) if len(blueholes) < 2: bluehole_x = random.randint(camera.x,camera.x+500) bluehole_y = random.randint(0,800) blueholes.append(gamebox.from_image(bluehole_x,bluehole_y,blue_hole_sheet[y])) # GRAVITY alien.yspeed += 1.5 alien.y = alien.y + alien.yspeed if pygame.K_s in keys: alien.image = "http://people.virginia.edu/~mak2vr/files/alien/alien_top.png" elif pygame.K_d in keys: alien.image = "http://people.virginia.edu/~mak2vr/files/alien/alien_middle.png" elif pygame.K_f in keys: alien.image = "http://people.virginia.edu/~mak2vr/files/alien/alien_bottom.png" else: alien.image = "http://people.virginia.edu/~mak2vr/files/alien/alien.png" for platform in platforms: if alien.bottom_touches(platform): alien.move_to_stop_overlapping(platform) if platform.x < (camera.x-1000): platforms.remove(platform) if alien.touches(platform): if pygame.K_SPACE in keys: alien.yspeed -= 30 if pygame.K_RIGHT in keys: alien.x += 5 if pygame.K_LEFT in keys: alien.x -= 5 camera.clear("skyblue") camera.draw(alien) camera.draw(scoreboard) for platform in platforms: camera.draw(platform) for bluehole in blueholes: camera.draw(bluehole) camera.display() game_over = gamebox.from_text(camera.x,400,"Game Over","Arial",40,"black",True) def end(): gamebox.pause() 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()
import pygame import gamebox import random multiplier = 1 camera = gamebox.Camera(800,600) character = gamebox.from_image(100,200,'http://www.illustrationsof.com/royalty-free-rf-yeti-clipart-illustration-by-cory-thoman-stock-sample-102505.jpg') character.yspeed = 0 character.scale_by(.05) b1 = gamebox.from_image(400,300, 'http://thumbs.dreamstime.com/z/christmas-snowflake-background-white-wallpaper-35056457.jpg') walls = [ gamebox.from_color(50,250, "black", 200, 10), gamebox.from_color(400,150, "black", 200, 10), gamebox.from_color(600,25, "black", 200, 10), ] coins = [ gamebox.from_color(75,400, "yellow", 10, 10), gamebox.from_color(160,200, "yellow", 10, 10), gamebox.from_color(280,250, "yellow", 10, 10) ] enemy = [ ] counter = 0 lives = 3 character_score= 0 game_over = False
import sys sys.path.insert(0, './ProjectDependencies') import pygame import gamebox import random # http://wallpaper.zone/img/16093.png # http://www.appsrox.com/screenshots/flappychick/Flappy_Pipe.png # http://us.123rf.com/450wm/anastasiaromb/anastasiaromb1603/anastasiaromb160300021/53104705-cute-set-of-forest-wild-animals-nature-fauna-collection.jpg?ver=6 # Camera Window camera = gamebox.Camera(800,600) # Player Sprites p1 = gamebox.from_image(200, 50, "hedgehog.png") background1 = gamebox.from_image(800, 300, "background.png") background2 = gamebox.from_image(2400, 300, "background.png") ground = gamebox.from_color(400, 600, "light green", 800, 100) ceiling = gamebox.from_color(400, -500, "white", 800, 1000) black_bar = gamebox.from_color(500, 50, "black", 255, 30) # Global Values p1_score = 0 p1_health = 10 game_start = False pause = False p1.yspeed = 0