コード例 #1
0
 def __init__(self, x, y, width, height):
     self.blocks = []
     for i in range(width):
         for j in range(height):
             blockx = x + Barrier.block_size_x * i
             blocky = y + Barrier.block_size_y * j
             block = gamebox.from_color(blockx, blocky, "red", Barrier.block_size_x, Barrier.block_size_y)
             self.blocks.append(block)
コード例 #2
0
def create_enemy():
    enemy = gamebox.from_color(random.randint(0, 800), random.randint(0,2) * 75 + 50, "yellow", 50, 50)

    # randomize their speed and direction
    enemy.xspeed = random.randint(3, 10)
    if random.randint(0,1) == 0:
        enemy.xspeed *= -1

    return enemy
コード例 #3
0
def boss_health():
    global boss_health_level
    return gamebox.from_color(cam.left + (400 * boss_health_level / 100), cam.top + 15, "red", (800 * boss_health_level / 100), 30)
コード例 #4
0
]
defeated_boss_text = [
    gamebox.from_text(400, 150, "CONGRATULATIONS, HERO", 50, "white"),
    gamebox.from_text(400, 200, "YOU HAVE DEFEATED THE EVIL GOBLIN KING!", 50, "white")
]
victory_text = [
    gamebox.from_text(400, 200, "CONGRATULATIONS!", 60, "white"),
    gamebox.from_text(400, 250, "You have bested the Goblin King", 60, "white"),
    gamebox.from_text(400, 300, "and saved the Princess!", 60, "white")
]
defeated_text = [
    gamebox.from_text(400, 250, "YOUR ADVENTURE HAS", 60, "red"),
    gamebox.from_text(400, 300, "ENDED", 100, "red")
]
walls = [
    gamebox.from_color(-2000, 0, "black", 50, 3600),
    gamebox.from_color(2000, 0, "black", 50, 3600),
    gamebox.from_color(0, -1800, "black", 4050, 50),
    gamebox.from_color(0, 1800, "black", 4050, 50)
]

# Character info
character = gamebox.from_image(300, 200, "character_front.png")
character.scale_by(1.25)
cam_locked = True

# Boss and boss room info
boss = gamebox.from_image(400, 150, "goblin_king.png")
boss.scale_by(.25)

boss_room = gamebox.from_image(400, 300, "boss_room.png")
コード例 #5
0

music2_count = 0
counter = 0
credit_count = 0
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)

コード例 #6
0
ファイル: test3.py プロジェクト: elcrawfodor/BeginnerShooter
import gamebox, pygame

char = gamebox.from_color(90, 4, "yellow", 8, 2)

print(char.yspeed)
コード例 #7
0
ファイル: game.py プロジェクト: ruolinchen/python-game
camera = gamebox.Camera(1142, 636)
background = gamebox.from_image(camera.x, camera.y, "night_time.png")
creators = gamebox.from_text(280, 20, "Creators: Christine Li (cjl4ev), Ruolin Chen (rlc8my)", "Snap ITC", 18, "white")
game_name = gamebox.from_text(camera.x, 280, "Counting Sheep", "Snap ITC", 60, "white")
description = gamebox.from_text(camera.x, 340, "How long can you jump fences for?", "Snap ITC", 24, "white")
rules1 = gamebox.from_text(camera.x, 370, "Jump fences without touching them or you lose a life!", "Snap ITC", 24,
                           "white")
rules2 = gamebox.from_text(camera.x, 400, "You get three lives, collect clovers to recover lives.", "Snap ITC", 24,
                           "white")
p1_instructions = gamebox.from_text(camera.x, 440, "Press SPACE to Jump", "Snap ITC", 24, "white")
to_start = gamebox.from_text(camera.x, 480, "Press ENTER to Start", "Snap ITC", 32, "white")
music = gamebox.load_sound('crickets_compressed.wav')
music_player = music.play(-1)

ground = gamebox.from_color(600, 634, "black", 1200, 50)

fence = gamebox.from_image(1000, 550, "fence.png")
fence.scale_by(.50)

character = gamebox.from_image(350, 545, "sheep.png")
character.scale_by(.20)

lives = gamebox.from_text(950, 40, "Lives left:", "Snap ITC", 24, "white")

health3 = gamebox.from_image(1075, 100, "sheep.png")
health3.scale_by(.1)
health2 = gamebox.from_image(990, 100, "sheep.png")
health2.scale_by(.1)
health1 = gamebox.from_image(905, 100, "sheep.png")
health1.scale_by(.1)
コード例 #8
0
ファイル: game.py プロジェクト: benlife5/SpaceRace
def drawMainBoard():
    for coord in board_space_coords:
        outer_box = gamebox.from_color(coord[0] * 50 + 25, coord[1] * 50 + 25, "black", 50, 50)
        inner_box = gamebox.from_color(coord[0] * 50 + 26, coord[1] * 50 + 26, "white", 46, 46)
        camera.draw(outer_box)
        camera.draw(inner_box)
コード例 #9
0
ファイル: game.py プロジェクト: h4ck3rk3y/unworthy
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


#red.png is the red flag
player_two_flag = [gamebox.from_image(750, 550, "red.png")]
player_two_flag[0].scale_by(0.15)
player_two_counter = 0
player_two_goal = gamebox.from_color(700, 300, "red", 10, 600)  # goal line for player 2

player_one_has_flag = False
player_two_has_flag = False

game_start = True
game_end = False
コード例 #10
0
ファイル: game.py プロジェクト: Chewy1477/Yeti-Jump
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
コード例 #11
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()
コード例 #12
0
ファイル: game.py プロジェクト: ailec-wu/HoppingHedgehog
def tick(keys):
    # Game Beginning Screen and Starting the Game
    global game_start, pause, p1_score, yellow_coins, platforms, p1_health, up_last_pressed, was_touching, bar, background1, time

    if game_start is False:
        camera.clear("light blue")
        camera.draw(gamebox.from_text(400, 300, str("PRESS SPACE BAR TO START!"), "Arial", 50, "black", True))
        camera.draw(gamebox.from_text(400, 350, str("Press UP to jump"), "Arial", 30, "black", True))
        camera.display()
        if pygame.K_SPACE in keys:
            game_start = True
    if game_start is True:
        # Player 1 Collisions with objects
        p1.yspeed += 0.5
        p1.y += p1.yspeed
        if pygame.K_UP in keys and not up_last_pressed:
            p1.yspeed = -8
            music_jump1 = gamebox.load_sound("Jump.wav")
            musicplayer3 = music_jump1.play()
            up_last_pressed = True
        if not pygame.K_UP in keys:
            up_last_pressed = False

        nothing_touched = True  # check if nothing is touched
        for platform in platforms:
            if p1.touches(platform):
                if not was_touching:
                    p1_health -= 1
                p1.x += 65
                was_touching = True
                nothing_touched = False
        if nothing_touched:
            was_touching = False

        if p1.x > 200:
            p1.x -= scroll_speed
        if p1.touches(ground):
            was_touching = True
            p1.yspeed = 0
            p1.y -= 100
            p1_health -= 1
            if pygame.K_UP in keys:
                p1.yspeed -= 5
        if p1.touches(ceiling):
            p1.yspeed = 0
            p1.move_to_stop_overlapping(ceiling)
    # Platform Creation and Removal
        platform_creator()
    # Coin Creation and Removal
        y_coins()
    # Health
        if p1_health > 10:
            p1_health = 10
        bar = [gamebox.from_color(900 - (512-chunknum*25), 50, "red", 20, 20) for chunknum in range(p1_health)]
    # Score
        for platform in platforms[1::2]:
            if 200 <= platform.x < 200 + scroll_speed:
                p1_score += 1
    # Background
        background1.x -= scroll_speed
        if background1.x <= -(800 - scroll_speed):
            background1.x = 2400
        background2.x -= scroll_speed
        if background2.x <= -(800 - scroll_speed):
            background2.x = 2400
        time += 1

    # Visuals
        if pause is False:
            camera.clear("light blue")
            camera.draw(ground)
            camera.draw(background1)
            camera.draw(background2)
            for platform in platforms:
                camera.draw(platform)
            camera.draw(gamebox.from_text(50, 50, str(int(p1_score)), "Arial", 30, "brown", True))
            camera.draw(gamebox.from_text(750, 50, str(time//ticks_per_second), "Arial", 30, "black", True))
            camera.draw(black_bar)
            for chunk in bar:
                camera.draw(chunk)
            for yellow_coin in yellow_coins:
                camera.draw(yellow_coin)
            camera.draw(p1)
            camera.display()

    # Game Ending and Restarting
        if p1_health == 0 and pause is False:
            camera.clear("light blue")
            camera.draw(gamebox.from_text(400, 200, str("GAME OVER"), "Arial", 100, "black", True))
            camera.draw(gamebox.from_text(400, 300, str("Score: " + str(int(p1_score))), "Arial", 50, "brown"))
            camera.draw(gamebox.from_text(400, 350, str("You lasted: " + str(time//ticks_per_second) + " seconds"), "Arial", 50, "black"))
            camera.draw(gamebox.from_text(400, 400, str("Play again?"), "Arial", 50, "black"))
            camera.draw(gamebox.from_text(400, 440, str("(press the space bar)"), "Arial", 20, "black"))
            camera.display()
            pause = True                # Freeze the Game Over menu

        if pygame.K_SPACE in keys and pause is True:
            platforms = []
            yellow_coins = []
            p1_health = 10
            p1.y = 50
            p1_score = 0
            time = 0
            game_start = False      # Restart the game
            pause = False           # Unfreeze the game
コード例 #13
0
ファイル: game.py プロジェクト: ailec-wu/HoppingHedgehog
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

# Platforms
platforms = []
コード例 #14
0
ファイル: main.py プロジェクト: brandonPurvis/tankdefense
tankstuff.Mine.image = mine_image_path

#Game Objects
enemy_tanks = []
friendly_tanks = []
bullets = []
barriers = []
mines = []
turrets = []
buttons = []
booms = []

# Add Objects 
button_state_machine = tankstuff.ButtonStateMachine()
barriers.append(tankstuff.Barrier(150, 150, 5, 30))
mines.append(tankstuff.Mine(400, 300))

# BUTTONS 
buttons.append(tankstuff.Button(25, 575,color = "grey", text_color = "black", text = "MINE"))
buttons.append(tankstuff.Button(75, 575, text = "TURRET"))
buttons.append(tankstuff.Button(125, 575,color = "grey", text_color = "black", text = "BARRIER"))
buttons.append(tankstuff.Button(175,575,color = "green", text_color = "black", text = "START"))

# THINGS
king = gamebox.from_color(100, 300, "yellow", 25, 25)


ticks_per_second = 60

# keep this line the last one in your program
gamebox.timer_loop(ticks_per_second, tick)
コード例 #15
0
def tick(keys):
    global start_screen
    global play
    global game_over
    global distance
    global frame
    global speed
    global y_pos
    global jump
    global jump_count
    global current_level
    global level
    global santa
    global can_jump
    global obstacles
    global slide

    # DRAW BACKGROUND
    camera.draw(background)

    # DISPLAY START SCREEN UNTIL PLAYER PRESSES SPACE OR I TO VIEW INSTRUCTIONS
    if start_screen:
        camera.draw(gamebox.from_text(250, 40, "SANTA RUN", 100, "white"))
        camera.draw(gamebox.from_text(250, 310, "Press Space To Start", 50, "white"))
        camera.draw(gamebox.from_text(240, 200, "aab4ad                         thh4yj", 40, "white"))
        santa = gamebox.from_image(275, 180, "Idle (1).png")
        camera.draw(gamebox.from_text(250, 350, 'Hold the I key to view instructions', 30, 'white'))
        santa.scale_by(.4)
        camera.draw(santa)

        if pygame.K_SPACE in keys:
            start_screen = False
            play = True

        if pygame.K_i in keys:
            camera.clear('white')
            camera.draw(background)
            instructions = ['The game will scroll at a constant speed.',
                            'It is the players job to navigate obstacles as ',
                            'they appear. Use Up or "W" key to jump',
                            'and Down or "S" key to slide.',
                            'The players progress is saved at each ',
                            'level, allowing the player to restart the level',
                            'each time they die. The player will die if',
                            'they fall off the map or collide with an obstacle.']
            camera.draw(gamebox.from_text(250, 40, "INSTRUCTIONS", 80, "white"))
            y = 150
            for i in instructions:
                camera.draw(gamebox.from_text(250, y, i, 30, 'white'))
                y += 25

    elif play is True:

        # DISPLAY PERCENT OF LEVEL COMPLETED IN TOP RIGHT --> each level has a distance of 250
        # --> may have to adjust this with levels are different lengths
        if level <= 3 and distance > 250:
            distance = 0
        if level <= 3:
            distance += 1
            camera.draw(gamebox.from_text(450, 30, str(int(distance / 250 * 100)) + " %", 25, "white"))
        if level >= 4 and distance > 50:
            distance = 0
        if level >= 4:
            distance += 1/3
            camera.draw(gamebox.from_text(450, 30, str(int(distance / 50 * 100))+" %", 25, "white"))

        # SLIDE WHEN DOWN ARROW PRESSED
        if (pygame.K_DOWN in keys or pygame.K_s in keys) and jump is False:
            santa = gamebox.from_image(150, y_pos, slide_stages[frame])
            santa.scale_by(.2)
            slide = True

        # JUMP WHEN UP ARROW PRESSED --> can only jump when on the ground
        elif (pygame.K_UP in keys or pygame.K_w in keys) and can_jump:
            jump = True
            slide = False
            speed = 30
            santa = gamebox.from_image(150, y_pos, jump_stages[0])
            santa.scale_by(.2)
            keys.clear()

        if jump:
            santa = gamebox.from_image(150, y_pos, jump_stages[jump_count])
            santa.scale_by(.2)
            # To disable single jump, comment the below code:
            jump_count += 1
            if jump_count == 16:
                jump_count = 0
                jump = False
            can_jump = False

        # RUN
        if jump is False and (pygame.K_DOWN not in keys and pygame.K_s not in keys):
            slide = False
            santa = gamebox.from_image(150, y_pos, run_stages[frame])
            santa.scale_by(.2)

        # Create hitboxes for obstacle collision for running/jumping santa or sliding santa
        # --> can view these by drawing
        hitbox = gamebox.from_color(santa.x-15, santa.y-5, "red", 40, 100)
        if slide:
            hitbox = gamebox.from_color(santa.x-10, santa.y+15, "blue", 50, 60)

        # LEVELS
        if current_level is level1:
            camera.draw(level_title1)
            level_title1.move(0, -1)
        if current_level is level2:
            camera.draw(level_title2)
            level_title2.move(0, -1)
        if current_level is level3:
            camera.draw(level_title3)
            level_title3.move(0, -1)
        if current_level is level4:
            camera.draw(level_title4)
            level_title4.move(0, -1)
        if current_level is level5:
            camera.draw(level_title5)
            level_title5.move(0, -1)

        # Path collision
        for object in current_level:

            # only draw objects on screen
            if -75 < object.x < 575:
                camera.draw(object)

            # character can land on paths
            if y_pos - speed > object.top - 50 and y_pos < object.top and object.left < santa.x < object.right:
                y_pos = object.top - 50
                speed = 0
                can_jump = True
                jump = False

            # can't touch path unless walking top of it
            elif hitbox.touches(object, 0, -20):
                game_over = True
                play = False

            # move all the objects
            object.move(-10, 0)

            # CHANGE TO NEXT LEVEL WHEN LEVEL IS OVER --> will need to add for new levels
            if distance >= 50 and level == 5:
                distance = 250
                game_over = True
                play = False
            if distance >= 50 and level == 4:
                current_level = level5
                distance = 0
                level_title5.y = 50
                level += 1
            if object.x < -2500 and level == 3:
                current_level = level4
                distance = 0
                level_title4.y = 50
                level += 1
            if object.x < -2500 and level == 2:
                current_level = level3
                distance = 0
                level_title3.y = 50
                level += 1
            if object.x < -2500 and level == 1:
                current_level = level2
                distance = 0
                level += 1
                level_title2.y = 50

        # detect collisions with obstacles
        for obstacle in obstacles[level]:
            camera.draw(obstacle)
            if hitbox.touches(obstacle, 0, -50):
                    play = False
                    game_over = True
            obstacle.move(-10, 0)

        # KEEP TRACK OF CHARACTER'S Y POSITION, AND CHANGE BY THEIR SPEED, DOWNWARD SPEED INCREASES (GRAVITY)
        y_pos = y_pos - speed
        speed -= 3

        # KEEPS TRACK OF THE ANIMATION FRAMES FOR RUNNING AND SLIDING
        frame += 1
        if frame == 11:
            frame = 0

        # END GAME IF CHARACTER FALLS OFF SCREEN
        if y_pos > 400:
            play = False
            game_over = True

    # DISPLAY END SCREEN WHEN GAME IS OVER
    elif game_over:

        # IF ALL LEVELS HAVE BEEN COMPLETED ALLOW USER TO CHOOSE A LEVEL TO REPLAY
        if distance >= 250 and level == 5:
            camera.draw(gamebox.from_text(250, 50, "CONGRATULATIONS", 50, "white"))
            camera.draw(gamebox.from_text(250, 150, "All levels completed!", 50, "white"))
            camera.draw(gamebox.from_text(250, 250, "To Replay a Level, ", 50, "white"))
            camera.draw(gamebox.from_text(250, 350, "Type Level Number ", 50, "white"))

            if pygame.K_1 in keys or pygame.K_2 in keys or pygame.K_3 in keys or pygame.K_4 in keys\
                    or pygame.K_5 in keys:

                y_pos = 250
                speed = 0
                distance = 0
                game_over = False
                play = True

                if pygame.K_1 in keys:
                    for object in level1:
                        object.move(2500, 0)
                    for obstacle in obstacles[1]:
                        obstacle.move(2500, 0)
                    level_title1.y = 50
                    current_level = level1
                    level = 1

                if pygame.K_2 in keys:
                    for object in level2:
                        object.move(2500, 0)
                    for obstacle in obstacles[2]:
                        obstacle.move(2500, 0)
                    level_title2.y = 50
                    current_level = level2
                    level = 2

                if pygame.K_3 in keys:
                    for object in level3:
                        object.move(2500, 0)
                    for obstacle in obstacles[3]:
                        obstacle.move(2500, 0)
                    level_title3.y = 50
                    current_level = level3
                    level = 3
                if pygame.K_4 in keys:
                    for object in level4:
                        object.move(1500, 0)
                    level_title4.y = 50
                    current_level = level4
                    level = 4
                if pygame.K_5 in keys:
                    for object in level5:
                        object.move(1500, 0)
                    level_title5.y = 50
                    current_level = level5
                    level = 5

        # IF ALL LEVEL FAILED COMPLETED ALLOW USER TO RETRY CURRENT LEVEL FROM BEGINNING
        else:
            camera.draw(gamebox.from_text(250, 50, "GAME OVER", 100, "white"))
            camera.draw(gamebox.from_text(250, 200, str(int(distance/250*100)) + " %", 100, "white"))
            camera.draw(gamebox.from_text(250, 350, "Press R to restart level", 50, "white"))

            if pygame.K_r in keys:
                if current_level == level1:
                    y_pos = 230
                    for object in level1:
                        object.move(10*distance, 0)
                    level_title1.y = 50
                    for obstacle in obstacles[1]:
                        obstacle.move(10*distance, 0)

                if current_level == level2:
                    y_pos = 150
                    for object in level2:
                        object.move(distance*10, 0)
                    for obstacle in obstacles[2]:
                        obstacle.move(10*distance, 0)
                    level_title2.y = 50

                if current_level == level3:
                    y_pos = 100
                    for object in level3:
                        object.move(distance*10, 0)
                    for obstacle in obstacles[3]:
                        obstacle.move(10*distance, 0)
                    level_title3.y = 50
                if current_level == level4:
                    y_pos = 70
                    for object in level4:
                        object.move(3 * 10 * distance, 0)
                    level_title4.y = 50
                if current_level == level5:
                    y_pos = 300
                    for object in level5:
                        object.move(3 * 10 * distance, 0)
                    level_title5.y = 50

                speed = 0
                distance = 0
                game_over = False
                play = True

    if not start_screen:
        camera.draw(santa)

    camera.display()
コード例 #16
0
rmm3ya.

"""
import pygame
import gamebox   # gamebox written by Luther Tychonievich
import math

CAMERA_WIDTH, CAMERA_HEIGHT = 800, 600
BOX_WIDTH, BOX_HEIGHT = 10, 10
walksprite_frame = 0
framecountforplayerwalk = 0
camera = gamebox.Camera(CAMERA_WIDTH, CAMERA_HEIGHT)  # size of window and camera points to the center
player = gamebox.from_image(camera.x, camera.y,
                            gamebox.load_sprite_sheet("/Users/rezamirzaiee/Desktop/GAME/Graphics/chara5.png", 8, 12)[1])

hammer = gamebox.from_color(player.x, player.y, "black", 10, 10)

hammer_thrown = False
has_stood = False
playerdirection = gamebox.from_image(camera.x, camera.y,
                            gamebox.load_sprite_sheet("/Users/rezamirzaiee/Desktop/GAME/Graphics/chara5.png", 8, 12)[1])
player_xspeed = 0
player_yspeed = 0
hammer_xspeed = 0
hammer_yspeed = 0
hammer_air = { 'hammer_xspeed_air': 0, 'hammer_yspeed_air': 0}

power = 0
# center gamebox x, center gamebox y, color, width of gamebox, height of gamebox

コード例 #17
0
ファイル: game.py プロジェクト: Chewy1477/Yeti-Jump
def tick(keys):
    global start_game
    global game_over
    global fail_over
    b3= gamebox.from_text(400,300,"Welcome to Yeti Jump! Get 10 points to win!", "Arial", 40, 'red', italic=True)
    b4 = gamebox.from_text(400,400, "Press s to start!","Arial", 40, 'red', italic=True)
    camera.draw(b3)
    camera.draw(b4)
    if pygame.K_s in keys:
        start_game = True
    if start_game is True:
        if fail_over is False:
            if game_over is False:
                global counter
                global lives
                global character_score
                if pygame.K_RIGHT in keys:
                    character.x += 10
                if pygame.K_LEFT in keys:
                    character.x -= 10
                character.yspeed += 1
                character.y = character.y + character.yspeed
                camera.clear("cyan")
                camera.draw(b1)
                camera.draw("Lives: " + str(lives), "Arial", 24, "red", 100, 100)

                camera.draw(character)
                if character.y > 600 or 800 >= character.x <= 0:
                    lives -= 1
                    charater_score = 0
                    character.x = walls[-1].x
                    character.y = walls[-1].y
                    camera.draw(character)

                camera.draw("Character Score: "+ str(character_score), "Arial", 24, "red", 100, 30)

                camera.y -= 3
                b1.y = camera.y

                global counter
                counter += 1
                if counter % 50 == 0:
                    new_wall = gamebox.from_color(random.randint(100,700), camera.y-300,  "black", random.randint(100,250), 10)
                    walls.append(new_wall)
                    if character.y >= new_wall.y + 600 or character.x < 0 or character.x > 800     :
                        lives -= 1
                        character.x = walls[-1].x
                        character.y = walls[-1].y
                        camera.draw(character)
                if counter%40 == 0:
                    coins.append(gamebox.from_color(random.randint(100,550),(character.y-200),"yellow",10,10))
                for coin in coins:
                    camera.draw(coin)
                    if character.touches(coin):
                        coins.remove(coin)
                        coin_sound = gamebox.load_sound('http://theodoregray.com/PeriodicTable/Sounds/029.2.wav')
                        musicplayer0=coin_sound.play()
                        character_score += 1
                        camera.draw("Character Score: " + str(character_score), "Arial", 24, "red", 100, 30)

                if counter%45 == 0:
                    enemy.append(gamebox.from_color(random.randint(100,550),(character.y-200),"red",5,5))
                multiplier = 1
                for thing in enemy:
                    thing.x += 10*multiplier
                    if thing.x >500 or thing.x<300:
                        multiplier = multiplier*-1

                    camera.draw(thing)
                    if character.touches(thing):
                        enemy.remove(thing)
                        character_score -= 5
                        lives -= 1
                        camera.draw("Character Score: " + str(character_score), "Arial", 24, "red", 100, 30)

                for wall in walls:
                    if character.bottom_touches(wall):
                        character.yspeed = 0
                        if pygame.K_SPACE in keys:
                            character.yspeed = -20
                    if character.touches(wall):
                        character.move_to_stop_overlapping(wall)
                    camera.draw(wall)


                if lives == 0:
                    fail_over = True
                if character_score is 10:
                    game_over = True



            else:
                camera.clear("white")
                camera.draw("You Win! Snooooow good", "Arial", 30,"red", 400, 300)
                camera.draw("Press q to quit", "Arial", 30, "red", 400, 500)
                if pygame.K_q in keys:
                    gamebox.stop_loop()
        else:
            camera.clear('white')
            camera.draw("Sorry you lost!", "Arial", 30, "red", 400, 250)
            camera.draw("Press q to quit", "Arial", 30, "red", 400, 450)
   
            if pygame.K_q in keys:
                gamebox.stop_loop()
    camera.display()
コード例 #18
0
# Bradley Knaysi (bak9cu) and Lillie Lyon (lal5kr)

import pygame
import gamebox
import random

camera = gamebox.Camera(800, 600)
character = gamebox.from_color(100, 100, "blue", 10, 10)
character2 = gamebox.from_color(100, 100, "cyan", 10, 10)
lives = 3
lives2 = 3
lives2_left = gamebox.from_text(680, 50, "p2 Lives: " + str(lives2), "Arial",
                                20, "Black")
lives_left = gamebox.from_text(680, 30, "p1 Lives: " + str(lives), "Arial", 20,
                               "Black")
goal_size = gamebox.from_text(700, 70, "Goal Size: = 100", "Arial", 20,
                              "Black")
respawn_zone = gamebox.from_color(20, 20, "grey", 40, 40)
game_over = False
game_on = False

orb_sound = gamebox.load_sound("wall.wav")
game_music = gamebox.load_sound("Pim Poy.wav")
game_music.play(-1)

orbs = []
for number in range(0, 30):
    size = random.randint(15, 50)
    small_size = random.randint(5, 10)
    colors = ["green", "red", "orange", "purple"]
    orbs.append(
コード例 #19
0
ファイル: aliengame.py プロジェクト: zamattiac/aliengame
# 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
コード例 #20
0
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

# Platforms
platforms = []
コード例 #21
0
ファイル: aliengame.py プロジェクト: zamattiac/aliengame
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()
コード例 #22
0
p_width = 10
p_height = 80
ball_velocity = 15
player_speed = 14
p1_score = 0
p2_score = 0
game_on = False

ticker = 0

paddle_sound = gamebox.load_sound("paddle.wav")
wall_sound = gamebox.load_sound("wall.wav")

walls = [
    gamebox.from_color(400, 600, "green", 1000, 20),
    gamebox.from_color(400, 0, "green", 1000, 20),
]

p1 = gamebox.from_color(20, 400, "red", 15, 100)
p2 = gamebox.from_color(780, 400, "yellow", 15, 100)
ball = gamebox.from_color(400, 300, "green", 20, 20)

ball.xspeed = ball_velocity
ball.yspeed = ball_velocity


def tick(keys):

    global game_on
    global p1_score
コード例 #23
0
 def __init__(self, x, y, color = "blue",text_color = "green", image = None, text = None, width = 50, height = 50):
     self.x, self.y = x, y
     self.box = gamebox.from_color(x, y, color, width, height)
     self.text_color = text_color
     self.text = text 
     self.image = image
コード例 #24
0
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
コード例 #25
0
 def clicked(self, camera):
     mx, my = camera.mousex, camera.mousey
     mouse_box = gamebox.from_color(mx, my, "white", 1, 1)
     return mouse_box.touches(self.box)
コード例 #26
0
import pygame
import gamebox
import random

camera = gamebox.Camera(800, 600)
#screen = pygame.display.set_mode((1000, 1000))
#camera = pygame.display.set_mode()
#print(camera.__setattr__())
game_on = False
player1_score = 0
player2_score = 0

# Walls:
walls = [
    gamebox.from_color(800 / 2, 0, "green", 1000, 50),
    gamebox.from_color(800 / 2, 600, "green", 1000, 50),
    gamebox.from_color(800, 600 / 2, "green", 50, 1000),
    gamebox.from_color(0, 600 / 2, "green", 50, 1000)
]

statics = []

# Sprites
player1 = gamebox.from_color(350, 300, "red", 25, 25)
player2 = gamebox.from_color(550, 300, "yellow", 25, 25)
cube = gamebox.from_color(450, 300, 'blue', 5, 5)
# Speed initialization


def tick(keys):
コード例 #27
0
# Modified from example by Prof. Tychonievich

import pygame
import gamebox
camera = gamebox.Camera(300, 300)

character = gamebox.from_color(150, 150, 'brown', 10, 10)
things = [
    gamebox.from_color(150, 250, 'green', 200, 50),
    gamebox.from_color(220, 200, 'white', 20, 100),
    gamebox.from_color(80, 100, 'black', 80, 20),
]
moving = [
    gamebox.from_color(120, 150, 'red', 20, 20),
]
for thing in moving:
    thing.being_carried = False


def tick(keys):
    camera.clear('lightblue')

    if pygame.K_LEFT in keys:
        character.x -= 5
    if pygame.K_RIGHT in keys:
        character.x += 5

    if pygame.K_UP in keys:
        for thing in things + moving:
            if character.bottom_touches(thing):
                character.speedy = -15
コード例 #28
0
def health():
    global health_level
    return gamebox.from_color(cam.left + (400 * health_level / 100), cam.bottom - 15, "green", (800 * health_level / 100), 30)
コード例 #29
0
ファイル: test.py プロジェクト: elcrawfodor/BeginnerShooter
import pygame
import gamebox

camera = gamebox.Camera(800, 600)
character = gamebox.from_color(50, 50, "red", 30, 60)
character.yspeed = 0
ground = gamebox.from_color(-100, 600, "black", 3000, 100)

def tick(keys):

    # moving left and right
    if pygame.K_RIGHT in keys:
        character.x += 5
    if pygame.K_LEFT in keys:
        character.x -= 5

    # jumping
    if pygame.K_SPACE in keys and character.bottom_touches(ground):
        character.yspeed -= 17

    # gravity
    character.yspeed += 1
    character.y = character.y + character.yspeed

    camera.clear("cyan")
    camera.draw(character)
    camera.draw(ground)

    #stop collisions with ground
    if character.bottom_touches(ground):
        character.yspeed = 0
コード例 #30
0
ファイル: game.py プロジェクト: mjq4my/Games
def tick(keys):
    global frame
    global game_on, lose_game
    global ammo
    frames = str(int(frame / 22))  #approximate time in seconds
    timer = gamebox.from_text(900, 50, "Timer: " + frames, 'impact', 30, 'red')
    if game_on == False:
        camera.clear("white")
        camera.draw(start_pic)
        camera.draw(intro)
        camera.draw(instructions)
        camera.draw(starting)
        camera.draw(names)
        camera.display()
        if pygame.K_s in keys:
            game_on = True
    if game_on == True:  #start game
        frame += 1
        camera.clear("grey")
        camera.draw(backgr)
        ammo_str = gamebox.from_text(80, 50, "Ammo: " + str(ammo), "Impact",
                                     34, "white")
        camera.draw(ammo_str)
        camera.draw(shooter)
        camera.draw(timer)
        if shooter.y <= 100:  #shooter boundaries
            shooter.y = 100
        if shooter.y >= 650:
            shooter.y = 650
        if len(first_zombies) != 0:  #Setting up wave number
            camera.draw(wave1)
        elif len(first_zombies) == 0 and len(second_zombies) != 0:
            camera.draw(wave2)
        else:
            camera.draw(finalwave)
        for zombie in first_zombies:  #if bullet touches zombie, kill zombie
            for bullet in bullets:
                if bullet.touches(zombie) and zombie.x <= 1230:
                    first_zombies.remove(zombie)
                    zombiedie.play()
                    bullets.remove(bullet)
        for zombie in second_zombies:
            for bullet in bullets:
                if bullet.touches(zombie) and zombie.x <= 1230:
                    second_zombies.remove(zombie)
                    zombiedie.play()
                    bullets.remove(bullet)
        for zombie in last_zombies:
            for bullet in bullets:
                if bullet.touches(zombie) and zombie.x <= 1230:
                    last_zombies.remove(zombie)
                    zombiedie.play()
                    bullets.remove(bullet)
        for zombie in first_zombies:
            zombie.size = 80, 130
            camera.draw(zombie)
            zombie.x -= zombie_speed
            if frame % 10 == 1:  #animation
                zombie.image = "go_1.png"
            elif frame % 10 == 2:
                zombie.image = "go_2.png"
            elif frame % 10 == 3:
                zombie.image = "go_3.png"
            elif frame % 10 == 4:
                zombie.image = "go_4.png"
            elif frame % 10 == 5:
                zombie.image = "go_5.png"
            elif frame % 10 == 6:
                zombie.image = "go_6.png"
            elif frame % 10 == 7:
                zombie.image = "go_7.png"
            elif frame % 10 == 8:
                zombie.image = "go_8.png"
            elif frame % 10 == 9:
                zombie.image = "go_9.png"
        if pygame.K_UP in keys:
            shooter.y -= shooter_speed
        if pygame.K_DOWN in keys:
            shooter.y += shooter_speed
        if pygame.K_SPACE in keys:
            bullet = gamebox.from_color(150, shooter.y - 55, "orange", 10, 2)
            gunshot.play()
            bullets.append(bullet)
            ammo -= 1
            if ammo % 10 == 0 and ammo > 0:
                for a in range(1):  #make reload sound after every 10 shots
                    reload.play()
                    keys.clear()
                    break
            keys.clear()
        if ammo <= 0:  #no more ammo
            bullets.clear()
            reload.stop()
            gunshot.stop()
            ammo = 0
        for bullet in bullets:  #shoot the bullets
            bullet.x += 80
            camera.draw(bullet)
        for zombie in first_zombies:
            if zombie.x <= shooter.x:
                lose_game = True
        for zombie in second_zombies:
            if zombie.x <= shooter.x:
                lose_game = True
        for zombie in last_zombies:
            if zombie.x <= shooter.x:
                lose_game = True
        if len(first_zombies) == 0:
            for zombie in second_zombies:
                zombie.size = 80, 130
                camera.draw(zombie)
                zombie.x -= zombie_speed + 1
                if frame % 10 == 1:
                    zombie.image = "go_1.png"
                elif frame % 10 == 2:
                    zombie.image = "go_2.png"
                elif frame % 10 == 3:
                    zombie.image = "go_3.png"
                elif frame % 10 == 4:
                    zombie.image = "go_4.png"
                elif frame % 10 == 5:
                    zombie.image = "go_5.png"
                elif frame % 10 == 6:
                    zombie.image = "go_6.png"
                elif frame % 10 == 7:
                    zombie.image = "go_7.png"
                elif frame % 10 == 8:
                    zombie.image = "go_8.png"
                elif frame % 10 == 9:
                    zombie.image = "go_9.png"
        if len(second_zombies) == 0:
            for zombie in last_zombies:
                zombie.size = 80, 130
                camera.draw(zombie)
                zombie.x -= zombie_speed + 2
                if frame % 10 == 1:
                    zombie.image = "go_1.png"
                elif frame % 10 == 2:
                    zombie.image = "go_2.png"
                elif frame % 10 == 3:
                    zombie.image = "go_3.png"
                elif frame % 10 == 4:
                    zombie.image = "go_4.png"
                elif frame % 10 == 5:
                    zombie.image = "go_5.png"
                elif frame % 10 == 6:
                    zombie.image = "go_6.png"
                elif frame % 10 == 7:
                    zombie.image = "go_7.png"
                elif frame % 10 == 8:
                    zombie.image = "go_8.png"
                elif frame % 10 == 9:
                    zombie.image = "go_9.png"
        if lose_game == True:
            losegame(keys)
            first_zombies.clear()
            second_zombies.clear()
            last_zombies.clear()
        elif len(first_zombies) == 0 and len(second_zombies) == 0 and len(
                last_zombies) == 0:
            win_game(keys)
        camera.display()
コード例 #31
0
ファイル: game_lab.py プロジェクト: ErinAlleva/CS-1110
# Alex Hicks (awh4kc)

# jumping puzzle game - pt3 - add a platform and coin that can be collected

import pygame
import gamebox
import random
camera = gamebox.Camera(800, 600)

character = gamebox.from_color(50, 50, "red", 15, 40)
character.yspeed = 0
walls = [
    gamebox.from_color(-100, 600, "black", 3000, 100),
    # gamebox.from_color(200, 550, "black", 100, 15),
    # gamebox.from_color(200, 500, "black", 100, 15),
    gamebox.from_color(200, 500, "black", 100, 5),
    # gamebox.from_color(200, 400, "black", 100, 15),
    # gamebox.from_color(200, 350, "black", 100, 15),
    # gamebox.from_color(200, 300, "black", 100, 15),
    # gamebox.from_color(200, 250, "black", 100, 15),
    # gamebox.from_color(200, 200, "black", 100, 15),
    # gamebox.from_color(200, 150, "black", 100, 15)
]
coins = [gamebox.from_color(300, 450, "yellow", 12, 12)]
time = 9000
score = 0


def tick(keys):
    global time, score
コード例 #32
0
import pygame
import gamebox
camera = gamebox.Camera(800, 600)  #width, height of the window

box = gamebox.from_color(
    camera.x, 100, 'green', 40, 40
)  # center at (200,100) coordinate (left to right, top to bottom), 40 pixels wide, 80 pixels tall
sun = gamebox.from_color(camera.x, camera.y, 'yellow', 40, 40)

box.speedx = 15
#box.speedy = -20


def tick(keys):
    camera.clear('black')
    G = 200000

    # gravity
    dx = sun.x - box.x
    dy = sun.y - box.y
    d_len = (dx * dx + dy * dy)**0.5
    box.speedx += G * dx / d_len**3
    box.speedy += G * dy / d_len**3

    box.move_speed()

    if box.left < camera.left:
        box.left = camera.left
        box.speedx = abs(box.speedx)
    if box.right > camera.right:
        box.right = camera.right
コード例 #33
0
fireball = gamebox.load_sprite_sheet("fire_spritesheet.png", 8, 8)
bat = gamebox.load_sprite_sheet("sheet_bat_fly.png", 1, 4)

# Variables
height_based_score = 0
enemy_based_score = 0
time = 0
impact_time = 0
attack_time = 0
health = 100
frame = 0
frame2 = 0

# Platforms

starting_platform1 = gamebox.from_color(400, 500, 'black', 70, 15)
starting_platform2 = gamebox.from_color(300, 400, 'black', 70, 15)
starting_platform3 = gamebox.from_color(600, 400, 'black', 70, 15)
starting_platform4 = gamebox.from_color(200, 300, 'black', 70, 15)
starting_platform5 = gamebox.from_color(750, 300, 'black', 70, 15)
starting_platform6 = gamebox.from_color(100, 50, 'black', 70, 15)
starting_platform7 = gamebox.from_color(50, 0, 'black', 70, 15)
starting_platform8 = gamebox.from_color(400, 350, 'black', 70, 15)
starting_platform9 = gamebox.from_color(400, 200, 'black', 70, 15)
starting_platform10 = gamebox.from_color(600, 200, 'black', 70, 15)
starting_platform11 = gamebox.from_color(500, 100, 'black', 70, 15)
starting_platform12 = gamebox.from_color(300, 100, 'black', 70, 15)

starting_platform = [
    starting_platform1, starting_platform2, starting_platform3,
    starting_platform4, starting_platform5, starting_platform6,
コード例 #34
0
def lose_health():
    global Player_HP_bar_fill
    Player_HP_bar_fill = gamebox.from_color(CAMERA_WIDTH-200, 100, "purple", Player_HP * 1.99, 8)
    Player_HP_bar_fill.left = Player_HP_bar.left + 1
コード例 #35
0
def tick(keys):

    global health, frame, time, game_on, enemy, character, generation_x, generation_y
    global enemy_based_score, height_based_score, green_platforms, impact_time, health_pack
    global impact_time, attack_time, frame2, attack

    if pygame.K_SPACE in keys:
        game_on = True

    if game_on:

        #Player Controls
        if pygame.K_LEFT in keys:
            character.x -= movement_x
        if pygame.K_RIGHT in keys:
            character.x += movement_x
        if pygame.K_UP in keys:
            for obstacle in starting_platform:
                if character.bottom_touches(obstacle):
                    character.y -= movement_y * 12
            for obstacle in green_platforms:
                if character.bottom_touches(obstacle):
                    character.y -= movement_y * 12
        if pygame.K_SPACE in keys:
            if time > attack_time + 30:
                attack = gamebox.from_image(character.x, character.y,
                                            fireball[frame2])
                attack_time = time

        generation_x = random.randint(50, 750)
        generation_y = camera.y - 450
        generation_plat1 = random.randint(50, 250)
        generation_plat2 = random.randint(250, 500)
        generation_plat3 = random.randint(500, 750)
        generation_plat4 = random.randint(50, 250)
        generation_plat5 = random.randint(250, 500)
        generation_plat6 = random.randint(500, 750)
        generation_plat7 = random.randint(50, 250)
        generation_plat8 = random.randint(250, 500)
        generation_plat9 = random.randint(500, 750)
        generation_plat_y = camera.y - 400

        # Animates the Character
        if frame == 5:
            frame = 0
        if frame2 == 61:
            frame2 = 0
        if time % 1 == 0:
            character.image = knight[frame]
            attack.image = fireball[frame2]
            frame += 1
            frame2 += 1

        # Generating Platforms, enemies, and potions
        if time % 8 == 0:
            new_enemy = gamebox.from_image(generation_x, generation_y, bat[1])
            enemies.append(new_enemy)

        if time % 30 == 0:
            new_potion = gamebox.from_image(generation_x,
                                            generation_plat_y + 10,
                                            "Potion_of_Healing.png")
            health_pack.append(new_potion)

        if character.y < camera.y - 150:
            normal_platform = gamebox.from_color(generation_plat1,
                                                 generation_plat_y, 'green',
                                                 70, 15)
            green_platforms.append(normal_platform)
            normal_platform2 = gamebox.from_color(generation_plat2,
                                                  generation_plat_y, 'green',
                                                  70, 15)
            green_platforms.append(normal_platform2)
            normal_platform3 = gamebox.from_color(generation_plat3,
                                                  generation_plat_y, 'green',
                                                  70, 15)
            green_platforms.append(normal_platform3)
            normal_platform4 = gamebox.from_color(generation_plat4,
                                                  generation_plat_y - 100,
                                                  'green', 70, 15)
            green_platforms.append(normal_platform4)
            normal_platform5 = gamebox.from_color(generation_plat5,
                                                  generation_plat_y - 100,
                                                  'green', 70, 15)
            green_platforms.append(normal_platform5)
            normal_platform6 = gamebox.from_color(generation_plat6,
                                                  generation_plat_y - 100,
                                                  'green', 70, 15)
            green_platforms.append(normal_platform6)
            normal_platform7 = gamebox.from_color(generation_plat7,
                                                  generation_plat_y - 200,
                                                  'green', 70, 15)
            green_platforms.append(normal_platform7)
            normal_platform8 = gamebox.from_color(generation_plat8,
                                                  generation_plat_y - 200,
                                                  'green', 70, 15)
            green_platforms.append(normal_platform8)
            normal_platform9 = gamebox.from_color(generation_plat9,
                                                  generation_plat_y - 200,
                                                  'green', 70, 15)
            green_platforms.append(normal_platform9)
            height_based_score += 1
            camera.y -= 300

        # Determines Background Color
        if time / 10 < 100:
            camera.clear('light cyan')
        elif 100 < time / 10 <= 200:
            camera.clear("pale turquoise")
        elif 200 < time / 10 <= 300:
            camera.clear("powder blue")
        elif 300 < time / 10 <= 400:
            camera.clear("cornflower blue")
        elif 400 < time / 10 <= 500:
            camera.clear("royal blue")
        elif 500 < time / 10 <= 600:
            camera.clear("blue")
        elif 600 < time / 10 <= 700:
            camera.clear("medium blue")
        elif 700 < time / 10 <= 800:
            camera.clear("navy blue")
        elif 800 < time / 10 <= 900:
            camera.clear("midnight blue")
        else:
            camera.clear("black")

# Platfroms Interactions
        for obstacle in starting_platform:
            if character.bottom_touches(obstacle):
                character.move_to_stop_overlapping(obstacle)
        for obstacle in green_platforms:
            if character.bottom_touches(obstacle):
                character.move_to_stop_overlapping(obstacle)

        for i in starting_platform:
            camera.draw(i)
        for i in green_platforms:
            camera.draw(i)

# Enemy Interactions
        for enemy in enemies:
            camera.draw(enemy)
            enemy.x += 10
            if enemy.x >= 800:
                enemy.x = 10
            if character.touches(enemy):
                if time > impact_time + 30:
                    # character.move_to_stop_overlapping(enemy)
                    impact_time = time
                    health -= 25
            if attack.touches(enemy):
                enemies.remove(enemy)
                enemy_based_score += 1
            if enemy.y > camera.y + 500:
                enemies.remove(enemy)

# Health Interactions
        for healing in health_pack:
            camera.draw(healing)
            if character.touches(healing):
                character.move_to_stop_overlapping(healing)
                health += 10
                health_pack.remove(healing)
        time += 1

        # Health Bar, Time Survived, Enemies Killed
        health_bar = gamebox.from_color(725, camera.y - 275, "tomato", health,
                                        20)
        camera.draw(health_bar)
        camera.draw(
            gamebox.from_text(725,
                              camera.y - 275,
                              "Health: " + str(health),
                              20,
                              "red",
                              bold=False))
        camera.draw(
            gamebox.from_text(725,
                              camera.y - 250,
                              "Enemies Killed: " + str(enemy_based_score),
                              20,
                              "Gold",
                              bold=False))
        camera.draw(
            gamebox.from_text(725,
                              camera.y - 225,
                              "Time Elapsed: " + str(time // 30),
                              20,
                              "Gold",
                              bold=False))

        # side movement
        if character.x < 0:
            character.x = 790
        if character.x > 800:
            character.x = 10
        if health > 100:
            health = 100


# Game Over Scenarios
        if health <= 0:
            camera.draw(
                gamebox.from_text(400,
                                  camera.y - 200,
                                  "Game Over!",
                                  80,
                                  "Blue",
                                  bold=False))
            overall_score = time // 30 + 2 * enemy_based_score
            camera.draw(
                gamebox.from_text(400,
                                  camera.y - 100,
                                  "Score: " + str(overall_score),
                                  60,
                                  "Blue",
                                  bold=False))
            gamebox.pause()

        if character.y >= camera.y + 300:
            health = 0
            camera.draw(
                gamebox.from_text(400,
                                  camera.y - 200,
                                  "Game Over!",
                                  80,
                                  "Blue",
                                  bold=False))
            overall_score = time // 30 + 2 * enemy_based_score
            camera.draw(
                gamebox.from_text(400,
                                  camera.y - 100,
                                  "Score: " + str(overall_score),
                                  60,
                                  "Blue",
                                  bold=False))
            gamebox.pause()

        camera.draw(character)
        camera.draw(attack)
        camera.display()

    gravity = 1
    character.speedy += gravity
    character.move_speed()
    attack.y -= 30
コード例 #36
0
- user input = right & left keys
- graphics/images
- start screen

optional features:
- enemies: bird
- collectables: apples
- health meter: three lives (display in the corner)
- music/sound effects

'''

camera = gamebox.Camera(800, 600)

# Background Stuff
top_border = gamebox.from_color(camera.x, 58, 'white', 800, 2)
bark = gamebox.from_image(
    camera.x, camera.y,
    'https://i.pinimg.com/originals/fd/47/66/fd47660f666b3860bf9b3aee2ef0a32b.jpg'
)
bark.rotate(90)
splash_background = gamebox.from_image(
    camera.x, camera.y,
    "https://previews.123rf.com/images/aopsan/aopsan1205/aopsan120500032/13644442-Green-grass-background-Stock-Photo.jpg"
)
show_splash = True

# Sounds
caw = gamebox.load_sound(
    'http://static1.grsites.com/archive/sounds/animals/animals010.wav')
apple_bite = gamebox.load_sound(
コード例 #37
0
ファイル: game.py プロジェクト: kkern42/pygame_project
player must jump to avoid them while collecting as many bananas as they can. Our game includes a title screen that 
prompts th user to press r, to reveal the rules, or to press space (that flashes because why not) to begin the game. 
Once space is press the text moves off the screen and the grass begins to move once the text is full of the screen the 
obstacles begin to move towards the player and the up arrow must be pressed to jump over them. Bananas will appear to 
be collected and your total will be displayed on the right side of the screen and the time you lasted with be displayed 
on the left hand side of the screen. If a spear is touched the game will end 

"""

camera = gamebox.Camera(800, 600)
# creates the jungle background
background = gamebox.from_image(400, 300, "back1.jpg")
background.size = [1000, 600]
# this blue bar is what sits at the bottom of the screen that is not seen but acts as the boarder for the player when it
# jumps
ground = gamebox.from_color(400, 602, "blue", 1000, 4)
# the monkey player that is controlled by the up arrow
player = gamebox.from_image(180, 592, "monkey.png")
player.size = [60, 40]
# list of the banana image sot be collected
bananas = [gamebox.from_image(900, 500, "banana.png")]
# Color of most of the text
color = "dark green"

title = gamebox.from_text(400, 250, "Jungle Jump", 60, color, True)
# Rules is in a list so we can show the rules if requested or keep the screen less cluttered by the long rules
# well they aren't long but I thought it was a nicer touch to be able to click something and have the rules appear
rules = [
    gamebox.from_text(400, 300, "Press r for Rules", 30, color),
    gamebox.from_text(400, 275,
                      "Use the UP Arrow to avoid the incoming Spears", 30,
コード例 #38
0
ファイル: game.py プロジェクト: benlife5/SpaceRace
    gamebox.from_image(0, 900, "asteroid.png"),
    gamebox.from_image(500, 900, "asteroid.png"),
    gamebox.from_image(1000, 900, "asteroid.png"),
]
astroid_player = gamebox.from_image(500, 350, "astronaut2.png")


def setAstroidSpeeds():
    for astroid in astroids:
        astroid.speedx = random.choice([random.randint(-20, -5), random.randint(5, 20)])
        astroid.speedy = random.randint(-20, 20)


setAstroidSpeeds()

repeatGameRed = gamebox.from_color(0, 0, "forestgreen", 500, 350)
repeatGameRed.topleft = (0, 0)
repeatGameGreen = gamebox.from_color(500, 0, "orange", 500, 350)
repeatGameGreen.topright = (1000, 0)
repeatGameBlue = gamebox.from_color(0, 350, "blue", 500, 350)
repeatGameBlue.bottomleft = (0, 700)
repeatGamePurple = gamebox.from_color(500, 350, "purple", 500, 350)
repeatGamePurple.bottomright = (1000, 700)
repeatGameBoxes = [repeatGameRed, repeatGameGreen, repeatGameBlue, repeatGamePurple]
repeatGameOrder = None
repeatGameLevel = 0
repeatGameIndex = 0
repeatGameUserTurn = False
repeatGameShowMarked = False
repeatGameShowAll = False
repeatGameNumUserClicks = 0
コード例 #39
0
ファイル: game.py プロジェクト: ohb3fs/CS1111
# Olivia Bicks ohb3fs and Charlotte Searle css7kv

import pygame
import gamebox
import random

camera = gamebox.Camera(800, 600)
sheet = gamebox.load_sprite_sheet("animation_sheet.png", 5, 6)
frame = 0
direction = 0
character = gamebox.from_image(200, 200, sheet[frame])
#character = gamebox.from_image(100, 200, "game_man.png")
character.yspeed = 0
walls = [
    gamebox.from_color(300, 500, "black", 10, 100),
    gamebox.from_color(600, 500, "black", 10, 100)
]
coins = [
    gamebox.from_image(400, 450, "new_coin.png"),
    gamebox.from_image(200, 450, "new_coin.png")
]
ground = gamebox.from_color(-100, 600, "green", 300000000, 100)
time = 0
counter = 0
score = 0
jump_sound = gamebox.load_sound("jump.wav")
coin_sound = gamebox.load_sound("coin.wav")


def tick(keys):
    global counter
コード例 #40
0
ファイル: game.py プロジェクト: benlife5/SpaceRace
def tick(keys):
    global gamePaused, miniGame, currentIndex, num_of_rolls, rollingActive, final_roll, mouse1, streetPlayerHealth
    global astroid_timer, astroid_timer, astroids, astroid_tick_counter
    global repeatGameOrder, repeatGameLevel, repeatGameUserTurn, repeatGameIndex, repeatGameShowAll
    global repeatGameShowMarked, repeatGameNumUserClicks, miniGameIndex

    if gamePaused:
        displayStartScreen()
        if pygame.K_RETURN in keys:
            gamePaused = False
            keys.clear()
    else:
        if miniGame is None:  # main game active
            camera.draw(gamebox.from_image(500, 350, "backgroundGame1.png"))
            drawMainBoard()

            currentX = board_space_coords[currentIndex][0]
            currentY = board_space_coords[currentIndex][1]

            camera.draw(gamebox.from_image(75, 75, "green_star.png"))
            camera.draw(gamebox.from_image(11 * 50 + 25, 75, "gold_star.png"))
            camera.draw(gamebox.from_image(currentX * 50 + 25, currentY * 50 + 25, "red_circle.png"))

            camera.draw(gamebox.from_color(13 * 50, 10 * 50, "white", 100, 100))

            if final_roll is not None:
                camera.draw(str(final_roll), 48, "black", 13 * 50, 10 * 50)
                camera.draw("Click to Play a Minigame", 24, "white", 13 * 50, 11 * 50 + 25)
            else:
                camera.draw("Click to Roll", 24, "white", 13 * 50, 11 * 50 + 25)

            if rollingActive:
                if num_of_rolls < 60:
                    temp_roll = random.randint(1, 6)
                    camera.draw(str(temp_roll), 48, "black", 13 * 50, 10 * 50)
                    num_of_rolls += 1
                else:
                    final_roll = random.randint(1, 6)
                    num_of_rolls = 0
                    rollingActive = False

            if camera.mouseclick:
                if final_roll is None:
                    rollingActive = True
                else:
                    miniGameIndex += 1
                    if miniGameIndex >= len(miniGames):
                        miniGameIndex = 0
                        random.shuffle(miniGames)
                    miniGame = miniGames[miniGameIndex]
                    currentIndex += final_roll
                    final_roll = None
                    rollingActive = False
                keys.clear()

            if pygame.K_RIGHT in keys:
                currentIndex += 1
                if currentIndex >= len(board_space_coords):
                    print("Game Won!")
                    currentIndex = 0
                    gamePaused = True

        if miniGame == "ClickingRainbow":  # minigame 1
            camera.clear('grey')
            camera.draw(CRDirections)
            if pygame.K_w in keys:
                CRObjects[7][0].y -= 10
            if pygame.K_s in keys:
                CRObjects[7][0].y += 10
            if pygame.K_a in keys:
                CRObjects[7][0].x -= 10
            if pygame.K_d in keys:
                CRObjects[7][0].x += 10
            for object in CRObjects:
                if CRObjects[object][2] == False:
                    camera.draw(CRObjects[object][0])
                if CRObjects[7][0].touches(CRObjects[object][0]) and object != 7:
                    if CRObjects[object][1] == mouse1 + 1:
                        CRObjects[object][2] = True
                        mouse1 = mouse1 + 1
            if CRObjects[6][2] == True:
                miniGame = None
                for object in CRObjects:
                    CRObjects[object][2] = False
                mouse1 = 0
                keys.clear()
        if miniGame == "Maze":
            camera.clear('grey')
            if pygame.K_w in keys:
                mazePlayer.y -= 10
            if pygame.K_s in keys:
                mazePlayer.y += 10
            if pygame.K_a in keys:
                mazePlayer.x -= 10
            if pygame.K_d in keys:
                mazePlayer.x += 10
            if mazePlayer.x < 0:
                mazePlayer.x = 0
            if mazePlayer.x > 1000:
                mazePlayer.x = 1000
            if mazePlayer.y < 0:
                mazePlayer.y = 0
            if mazePlayer.y > 700:
                mazePlayer.y = 700
            for wall in MazeObjects:
                camera.draw(wall)
                if mazePlayer.touches(wall):
                    mazePlayer.speedx = 0
                    mazePlayer.speedy = 0
                    mazePlayer.move_to_stop_overlapping(wall)
            camera.draw(mazePlayer)
            camera.draw(destination)
            if mazePlayer.touches(destination):
                miniGame = None
                keys.clear()
                mazePlayer.x = 50
                mazePlayer.y = 100
        if miniGame == "CrossStreet":
            camera.clear('grey')
            if pygame.K_w in keys:
                streetPlayer.y -= 10
            if pygame.K_s in keys:
                streetPlayer.y += 10
            if pygame.K_a in keys:
                streetPlayer.x -= 10
            if pygame.K_d in keys:
                streetPlayer.x += 10
            if streetPlayer.x < 0:
                streetPlayer.x = 0
            if streetPlayer.x > 1000:
                streetPlayer.x = 1000
            if streetPlayer.y < 0:
                streetPlayer.y = 0
            if streetPlayer.y > 700:
                streetPlayer.y = 700
            if streetPlayer.x > 970:
                miniGame = None
                keys.clear()
                streetPlayerHealth = 200
                streetPlayer.x = 50
                streetPlayer.y = 100
            if streetPlayerHealth <= 0:
                streetPlayer.x = 50
                streetPlayer.y = 100
                streetPlayerHealth = 200
            for street in streets:
                camera.draw(street)
            for streetObject in streetObjects:
                streetObjects[streetObject][0].speedy = streetObjects[streetObject][1]
                streetObjects[streetObject][0].move_speed()
                if streetObjects[streetObject][0].y > 800:
                    streetObjects[streetObject][0].y = -100
                camera.draw(streetObjects[streetObject][0])
                if streetObjects[streetObject][0].touches(streetPlayer):
                    streetPlayerHealth -= 10
            streetPlayerHealthBar = gamebox.from_color(500, 50, "blue", streetPlayerHealth, 30)
            camera.draw(streetPlayerHealthBarMissing)
            camera.draw(streetPlayerHealthBar)
            camera.draw(streetPlayer)
            camera.draw(streetPlayerDirections)
            camera.draw(streetPlayerHealthText)

        if miniGame == "AstroidDodge":
            camera.clear("black")
            camera.draw(str(astroid_timer), 48, "red", 18 * 50, 50)
            astroid_tick_counter += 1

            if pygame.K_w in keys:
                astroid_player.y -= astroid_player_speed
            elif pygame.K_s in keys:
                astroid_player.y += astroid_player_speed
            elif pygame.K_a in keys:
                astroid_player.x -= astroid_player_speed
            elif pygame.K_d in keys:
                astroid_player.x += astroid_player_speed

            if astroid_player.x < 0:
                astroid_player.x = 0
            elif astroid_player.x > 1000:
                astroid_player.x = 1000
            elif astroid_player.y < 0:
                astroid_player.y = 0
            elif astroid_player.y > 700:
                astroid_player.y = 700
            camera.draw(astroid_player)
            for astroid in astroids:
                astroid.move_speed()
                if astroid.x < 0:
                    astroid.x += 1050
                elif astroid.x > 1050:
                    astroid.x -= 1050
                if astroid.y < 0:
                    astroid.y += 950
                elif astroid.y > 950:
                    astroid.y -= 950
                camera.draw(astroid)
                if astroid_player.touches(astroid):
                    astroid_timer = 10
                    camera.clear("red")
                    astroid_player.x = 500
                    astroid_player.y = 305

            if astroid_tick_counter % 28 == 0:
                astroid_timer -= 1

            if astroid_timer <= 0:
                miniGame = None
                astroid_timer = 10
                astroid_player.x = 500
                astroid_player.y = 305
                setAstroidSpeeds()

        if miniGame == "PatternRepeat":
            camera.clear("white")
            if repeatGameOrder is None:
                repeatGameOrder = []
                repeatGameNumUserClicks, repeatGameIndex, repeatGameLevel = 0, 0, 0
                for i in range(5):
                    repeatGameOrder.append(random.randint(0, 3))
                repeatGameShowAll, repeatGameShowMarked = True, True
            else:
                if repeatGameShowAll:
                    repeatGameBoxes[0].color = "forestgreen"
                    repeatGameBoxes[1].color = "orange"
                    repeatGameBoxes[2].color = "blue"
                    repeatGameBoxes[3].color = "purple"
                    for box in repeatGameBoxes:
                        camera.draw(box)
                    camera.display()
                    pygame.time.wait(1000)
                    repeatGameShowAll = False
                elif repeatGameShowMarked:
                    repeatGameBoxes[repeatGameOrder[repeatGameIndex]].color = "black"
                    for box in repeatGameBoxes:
                        camera.draw(box)
                    camera.display()
                    pygame.time.wait(1000)
                    repeatGameShowAll, repeatGameShowMarked = True, False
                    if repeatGameIndex < repeatGameLevel:
                        repeatGameIndex += 1
                        repeatGameShowAll, repeatGameShowMarked = True, True
                else:
                    if camera.mouseclick:
                        areaClicked = None
                        clickX = camera.mousex
                        clickY = camera.mousey
                        if clickX < 500 and clickY < 350:
                            areaClicked = 0
                            repeatGameBoxes[0].color = "black"
                        elif clickX > 500 and clickY < 350:
                            areaClicked = 1
                            repeatGameBoxes[1].color = "black"
                        elif clickX < 500 and clickY > 350:
                            areaClicked = 2
                            repeatGameBoxes[2].color = "black"
                        elif clickX > 500 and clickY > 350:
                            areaClicked = 3
                            repeatGameBoxes[3].color = "black"

                        for box in repeatGameBoxes:
                            camera.draw(box)
                        camera.display()
                        pygame.time.wait(1000)
                        repeatGameBoxes[0].color = "forestgreen"
                        repeatGameBoxes[1].color = "orange"
                        repeatGameBoxes[2].color = "blue"
                        repeatGameBoxes[3].color = "purple"
                        for box in repeatGameBoxes:
                            camera.draw(box)
                        camera.display()

                        if areaClicked != repeatGameOrder[repeatGameNumUserClicks]:
                            camera.clear("red")
                            camera.display()
                            pygame.time.wait(400)
                            repeatGameOrder = None
                        else:
                            repeatGameNumUserClicks += 1
                            if repeatGameNumUserClicks > repeatGameLevel:
                                repeatGameShowAll, repeatGameShowMarked = True, True
                                repeatGameLevel += 1
                                repeatGameNumUserClicks, repeatGameIndex = 0, 0
                                if repeatGameLevel >= 5:
                                    repeatGameOrder = None
                                    miniGame = None

            for box in repeatGameBoxes:
                camera.draw(box)

    camera.display()
コード例 #41
0
ファイル: game.py プロジェクト: ohb3fs/CS1111
def tick(keys):
    global counter
    global frame
    global direction
    global time
    global score
    if counter < 60:
        counter += 1
        camera.clear("blue")
        camera.draw(
            gamebox.from_text(camera.x, 100, "Get Ready...", "Arial", 40,
                              "Orange", True))
        camera.draw(
            gamebox.from_text(camera.x, 300,
                              "Catch the coins and hop the walls! Good luck!",
                              "Arial", 20, "Orange", True))
        camera.draw(
            gamebox.from_text(camera.x, 400,
                              "Use the Spacebar or Up Key to Jump", "Arial",
                              15, "Orange"))
        camera.display()
    if counter >= 60:
        counter += 1
        frame += 1
        if frame == 10:
            frame = 0
        if counter % 1 == 0:
            character.image = sheet[frame + direction * 10]
        if pygame.K_RIGHT in keys:
            character.x += 10
        if character.bottom_touches(ground):
            character.yspeed = 0
            if pygame.K_SPACE in keys or pygame.K_UP in keys:
                character.yspeed = -22
                jump_sound.play()
        character.yspeed += 1
        character.y = character.y + character.yspeed
        camera.clear("blue")
        camera.draw(character)
        camera.draw(ground)
        camera.x += 3
        if character.touches(ground):
            character.move_to_stop_overlapping(ground)
        if counter % 20 == 0:
            time += 1
        if counter % 2 == 0:
            score += 1
        camera.draw(
            gamebox.from_text(camera.x + 300,
                              100,
                              "Time: " + str(time),
                              "arial",
                              12,
                              "red",
                              bold=True))
        camera.draw(
            gamebox.from_text(camera.x + 300,
                              75,
                              "Score: " + str(score),
                              "arial",
                              12,
                              "red",
                              bold=True))
        leftmost_wall = gamebox.from_color(camera.x - 400, 600, "blue", 0, 800)
        camera.draw(leftmost_wall)
        if character.touches(leftmost_wall):
            camera.draw(
                gamebox.from_text(camera.x, 100, "Game Over!", "Arial", 40,
                                  "Red", True))
            gamebox.pause()
        divisor = 120
        if counter % divisor == 0:
            new_wall = gamebox.from_color(camera.x + 800, 500, "black", 10,
                                          random.randint(100, 250))
            walls.append(new_wall)
            divisor += 20
        for wall in walls:
            if character.touches(wall):
                camera.draw(
                    gamebox.from_text(camera.x, 100, "Game Over!", "Arial", 40,
                                      "Red", True))
                gamebox.pause()
            camera.draw(wall)
        if counter % 200 == 0:
            new_coin = gamebox.from_image(
                camera.x + (random.randint(350, 600)), 350, "new_coin.png")
            coins.append(new_coin)
        for coin in coins:
            camera.draw(coin)
            if character.touches(coin):
                coins.remove(coin)
                score += 15
                coin_sound.play()
        camera.draw(ground)
        camera.display()
コード例 #42
0
def tick(keys):
    # Game Beginning Screen and Starting the Game
    global game_start, pause, p1_score, yellow_coins, platforms, p1_health, up_last_pressed, was_touching, bar, background1, time

    if game_start is False:
        camera.clear("light blue")
        camera.draw(
            gamebox.from_text(400, 300, str("PRESS SPACE BAR TO START!"),
                              "Arial", 50, "black", True))
        camera.draw(
            gamebox.from_text(400, 350, str("Press UP to jump"), "Arial", 30,
                              "black", True))
        camera.display()
        if pygame.K_SPACE in keys:
            game_start = True
    if game_start is True:
        # Player 1 Collisions with objects
        p1.yspeed += 0.5
        p1.y += p1.yspeed
        if pygame.K_UP in keys and not up_last_pressed:
            p1.yspeed = -8
            music_jump1 = gamebox.load_sound("Jump.wav")
            musicplayer3 = music_jump1.play()
            up_last_pressed = True
        if not pygame.K_UP in keys:
            up_last_pressed = False

        nothing_touched = True  # check if nothing is touched
        for platform in platforms:
            if p1.touches(platform):
                if not was_touching:
                    p1_health -= 1
                p1.x += 65
                was_touching = True
                nothing_touched = False
        if nothing_touched:
            was_touching = False

        if p1.x > 200:
            p1.x -= scroll_speed
        if p1.touches(ground):
            was_touching = True
            p1.yspeed = 0
            p1.y -= 100
            p1_health -= 1
            if pygame.K_UP in keys:
                p1.yspeed -= 5
        if p1.touches(ceiling):
            p1.yspeed = 0
            p1.move_to_stop_overlapping(ceiling)
    # Platform Creation and Removal
        platform_creator()
        # Coin Creation and Removal
        y_coins()
        # Health
        if p1_health > 10:
            p1_health = 10
        bar = [
            gamebox.from_color(900 - (512 - chunknum * 25), 50, "red", 20, 20)
            for chunknum in range(p1_health)
        ]
        # Score
        for platform in platforms[1::2]:
            if 200 <= platform.x < 200 + scroll_speed:
                p1_score += 1
    # Background
        background1.x -= scroll_speed
        if background1.x <= -(800 - scroll_speed):
            background1.x = 2400
        background2.x -= scroll_speed
        if background2.x <= -(800 - scroll_speed):
            background2.x = 2400
        time += 1

        # Visuals
        if pause is False:
            camera.clear("light blue")
            camera.draw(ground)
            camera.draw(background1)
            camera.draw(background2)
            for platform in platforms:
                camera.draw(platform)
            camera.draw(
                gamebox.from_text(50, 50, str(int(p1_score)), "Arial", 30,
                                  "brown", True))
            camera.draw(
                gamebox.from_text(750, 50, str(time // ticks_per_second),
                                  "Arial", 30, "black", True))
            camera.draw(black_bar)
            for chunk in bar:
                camera.draw(chunk)
            for yellow_coin in yellow_coins:
                camera.draw(yellow_coin)
            camera.draw(p1)
            camera.display()

    # Game Ending and Restarting
        if p1_health == 0 and pause is False:
            camera.clear("light blue")
            camera.draw(
                gamebox.from_text(400, 200, str("GAME OVER"), "Arial", 100,
                                  "black", True))
            camera.draw(
                gamebox.from_text(400, 300,
                                  str("Score: " + str(int(p1_score))), "Arial",
                                  50, "brown"))
            camera.draw(
                gamebox.from_text(
                    400, 350,
                    str("You lasted: " + str(time // ticks_per_second) +
                        " seconds"), "Arial", 50, "black"))
            camera.draw(
                gamebox.from_text(400, 400, str("Play again?"), "Arial", 50,
                                  "black"))
            camera.draw(
                gamebox.from_text(400, 440, str("(press the space bar)"),
                                  "Arial", 20, "black"))
            camera.display()
            pause = True  # Freeze the Game Over menu

        if pygame.K_SPACE in keys and pause is True:
            platforms = []
            yellow_coins = []
            p1_health = 10
            p1.y = 50
            p1_score = 0
            time = 0
            game_start = False  # Restart the game
            pause = False  # Unfreeze the game
コード例 #43
0
ファイル: Game_Lecture1.py プロジェクト: cton09/Mario-Game
import random

# Reading the high score
infile = open("info.txt", "r")
highest_score = int(infile.readline().strip())
infile.close()

agreed = False
camera = gamebox.Camera(800, 600)
score = 0
ticks_per_second = 30


# game timer
time = 400
auto_box = gamebox.from_color(780, 590, "white", 200, 20)
auto_box.speedx = 10
controlled_box = gamebox.from_color(250, 250, "Blue", 50, 20)

coins = [gamebox.from_color(random.randint(10, 750), 0, "yellow", 12, 12),
         gamebox.from_color(random.randint(10, 750), 0, "yellow", 12, 12)]

fire = []

def tick(keys):
    global time, score, minutes

    # clear display
    camera.clear("black")

    # AUTOMATED BOX
コード例 #44
0
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])
コード例 #45
0
ファイル: Game_Lecture1.py プロジェクト: cton09/Mario-Game
def tick(keys):
    global time, score, minutes

    # clear display
    camera.clear("black")

    # AUTOMATED BOX
    if auto_box.speedx > 0 and auto_box.x > 800:
        auto_box.speedx = -10
    elif auto_box.speedx < 0 and auto_box.x < 0:
        auto_box.speedx = 10
    auto_box.move_speed()
    camera.draw(auto_box)

    # Controlled Box
    if pygame.K_RIGHT in keys:
        controlled_box.x += 5
    if pygame.K_LEFT in keys:
        controlled_box.x -= 5
    if pygame.K_UP in keys:
        controlled_box.y -= 5
    if pygame.K_DOWN in keys:
        controlled_box.y += 5
    if pygame.K_SPACE in keys:
        new_shot = gamebox.from_color(controlled_box.x, controlled_box.y, 'white', 5, 5)
        # if len(fire) < 3:
        fire.append(new_shot)
    camera.draw(controlled_box)

    # increase timer
    time -= 1
    if time <= 0:
        game_over = gamebox.from_text(350, 350, "GAME OVER", "Arial", 40, "Red")
        camera.draw(game_over)
        write_score(score, highest_score)
        gamebox.pause()

    if score < 0:
        you_lose = gamebox.from_text(350, 350, "You Lose", "Arial", 40, "Red")
        camera.draw(you_lose)
        write_score(score, highest_score)
        gamebox.pause()

    # calculate minutes,seconds,fractions of seconds
    frac = str(int((time%ticks_per_second)/ticks_per_second*10))
    seconds = str(int((time/ticks_per_second)%60)).zfill(2)
    minutes = str(int((time/ticks_per_second)/60))

    # write timer to screen
    timer = gamebox.from_text(700, 50, minutes+":"+seconds+"."+frac,"Arial",40,"red")  # TEXT OBJECT
    camera.draw(timer)

    # Write Score to screen
    scr = gamebox.from_text(150, 50, "Score: " + str(score), "Arial", 60, "blue")
    camera.draw(scr)

    # Fired shots
    for shot in fire:
        shot.y -= 10
        camera.draw(shot)

    # Define the coins
    for coin in coins:
        for shot in fire:
            if shot.touches(coin):
                score += 1
                fire.remove(shot)
                if coin in coins:
                    coins.remove(coin)
        coin.speedy += 0.03
        if auto_box.touches(coin):
            score += 10
            coins.remove(coin)
        if controlled_box.touches(coin):
            score += 1
            coins.remove(coin)
        if coin.y >= 610:
            score -= 1
            coins.remove(coin)
        coin.move_speed()
        camera.draw(coin)
    if len(coins) < 4:
        new_coin = gamebox.from_color(random.randint(10, 750), 0, "yellow", 12, 12)
        coins.append(new_coin)
    camera.display()
コード例 #46
0
import pygame
import gamebox
camera = gamebox.Camera(800,600)

player = gamebox.from_color(50, 100, "red", 20, 40)
obstacle = gamebox.from_color(400, 300, "yellow", 600, 20)


def tick(keys):
    camera.clear('black')

    # move the player
    if pygame.K_RIGHT in keys:
        player.x += 5
    if pygame.K_LEFT in keys:
        player.x -= 5
    if pygame.K_UP in keys:
        player.y -= 5
    if pygame.K_DOWN in keys:
        player.y += 5

    if player.touches(obstacle):
        obstacle.color = 'blue'
        player.move_to_stop_overlapping(obstacle)

    # draw everything
    camera.draw(player)
    camera.draw(obstacle)

    # usually camera.display() should be the last line of the tick method
    camera.display()
コード例 #47
0
ファイル: game.py プロジェクト: Chewy1477/Yeti-Jump
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
コード例 #48
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):
    kelp_list.append(gamebox.from_image(2550 + xy*30, y - y/15, "ground_kelp.png"))
    kelp_list.append(gamebox.from_image(2050 + xy*30, y - y/15, "ground_kelp.png"))
for x in range(3):
コード例 #49
0
ファイル: game.py プロジェクト: Chewy1477/Yeti-Jump
def tick(keys):
    global start_game
    global game_over
    global fail_over
    b3 = gamebox.from_text(400,
                           300,
                           "Welcome to Yeti Jump! Get 10 points to win!",
                           "Arial",
                           40,
                           'red',
                           italic=True)
    b4 = gamebox.from_text(400,
                           400,
                           "Press s to start!",
                           "Arial",
                           40,
                           'red',
                           italic=True)
    camera.draw(b3)
    camera.draw(b4)
    if pygame.K_s in keys:
        start_game = True
    if start_game is True:
        if fail_over is False:
            if game_over is False:
                global counter
                global lives
                global character_score
                if pygame.K_RIGHT in keys:
                    character.x += 10
                if pygame.K_LEFT in keys:
                    character.x -= 10
                character.yspeed += 1
                character.y = character.y + character.yspeed
                camera.clear("cyan")
                camera.draw(b1)
                camera.draw("Lives: " + str(lives), "Arial", 24, "red", 100,
                            100)

                camera.draw(character)
                if character.y > 600 or 800 >= character.x <= 0:
                    lives -= 1
                    charater_score = 0
                    character.x = walls[-1].x
                    character.y = walls[-1].y
                    camera.draw(character)

                camera.draw("Character Score: " + str(character_score),
                            "Arial", 24, "red", 100, 30)

                camera.y -= 3
                b1.y = camera.y

                global counter
                counter += 1
                if counter % 50 == 0:
                    new_wall = gamebox.from_color(random.randint(100, 700),
                                                  camera.y - 300, "black",
                                                  random.randint(100, 250), 10)
                    walls.append(new_wall)
                    if character.y >= new_wall.y + 600 or character.x < 0 or character.x > 800:
                        lives -= 1
                        character.x = walls[-1].x
                        character.y = walls[-1].y
                        camera.draw(character)
                if counter % 40 == 0:
                    coins.append(
                        gamebox.from_color(random.randint(100, 550),
                                           (character.y - 200), "yellow", 10,
                                           10))
                for coin in coins:
                    camera.draw(coin)
                    if character.touches(coin):
                        coins.remove(coin)
                        coin_sound = gamebox.load_sound(
                            'http://theodoregray.com/PeriodicTable/Sounds/029.2.wav'
                        )
                        musicplayer0 = coin_sound.play()
                        character_score += 1
                        camera.draw("Character Score: " + str(character_score),
                                    "Arial", 24, "red", 100, 30)

                if counter % 45 == 0:
                    enemy.append(
                        gamebox.from_color(random.randint(100, 550),
                                           (character.y - 200), "red", 5, 5))
                multiplier = 1
                for thing in enemy:
                    thing.x += 10 * multiplier
                    if thing.x > 500 or thing.x < 300:
                        multiplier = multiplier * -1

                    camera.draw(thing)
                    if character.touches(thing):
                        enemy.remove(thing)
                        character_score -= 5
                        lives -= 1
                        camera.draw("Character Score: " + str(character_score),
                                    "Arial", 24, "red", 100, 30)

                for wall in walls:
                    if character.bottom_touches(wall):
                        character.yspeed = 0
                        if pygame.K_SPACE in keys:
                            character.yspeed = -20
                    if character.touches(wall):
                        character.move_to_stop_overlapping(wall)
                    camera.draw(wall)

                if lives == 0:
                    fail_over = True
                if character_score is 10:
                    game_over = True

            else:
                camera.clear("white")
                camera.draw("You Win! Snooooow good", "Arial", 30, "red", 400,
                            300)
                camera.draw("Press q to quit", "Arial", 30, "red", 400, 500)
                if pygame.K_q in keys:
                    gamebox.stop_loop()
        else:
            camera.clear('white')
            camera.draw("Sorry you lost!", "Arial", 30, "red", 400, 250)
            camera.draw("Press q to quit", "Arial", 30, "red", 400, 450)

            if pygame.K_q in keys:
                gamebox.stop_loop()
    camera.display()
コード例 #50
0
# Michael Crawford (mdc8wa)

import pygame
import gamebox
import random

#camera
camera = gamebox.Camera(800, 600)

# player character
character = gamebox.from_color(400, 500, "red", 30, 60)
character.yspeed = 0

# health boxes
health1 = gamebox.from_color(50, 50, "red", 20, 20)
health2 = gamebox.from_color(100, 50, "red", 20, 20)
health3 = gamebox.from_color(150, 50, "red", 20, 20)
health = [True, True, True]

def lose_health():
    for i in range(len(health)):
        if health[i] == True:
            health[i] = False
            break

# game starting screen
game_start_background = gamebox.from_color(400, 300, "black", 800, 600)
game_start_text = gamebox.from_text(400, 300, "Press Space to play!", "Comic Sans MS", 30, "yellow")
game_start_condition = True
def change_game_start():
    return False
コード例 #51
0
ファイル: test2.py プロジェクト: elcrawfodor/BeginnerShooter
def create_enemy():
    enemy = gamebox.from_color(random.randint(0, 800), 50, "yellow", 50, 50)
    return enemy