コード例 #1
0
def main():
    # this function sets the background

    # sets the background to image 0 in the bank
    # backgrounds do not have magents as a transparent color
    background = stage.Grid(image_bank_1, 10, 8)

    # create a sprite
    # parameters (image bank, image # in bank, x, y)
    alien = stage.Sprite(image_bank_1, 4, 4, 5)
    sprites.append(alien)
    ship = stage.Sprite(image_bank_1, 6, 12, 10)
    sprites.insert(0, ship)  # insert at top of sprite list

    # create a stage for the background to show up on
    #   and set the frame rate to 60fps
    game = stage.Stage(ugame.display, 60)
    # set the background layer
    game.layers = sprites + [background]
    # render the background
    # most likely you will only render background once per scene
    game.render_block()

    # repeat forever, or you turn it off!
    while True:
        # get user input

        # update game logic

        game.render_sprites(sprites)
        game.tick()  # wait for refresh rate to finish
コード例 #2
0
def main():
    # this function sets the background

    # sets the background to image 0 in the bank
    background = stage.Grid(image_bank_1, 10, 8)

    # create a sprite
    # parameters (image_bank_1, image # in bank, x, y)
    ball_one = stage.Sprite(image_bank_1, 3, 64, 56)
    sprites.append(ball_one)
    ball_two = stage.Sprite(image_bank_1, 2, 75, 56)
    sprites.insert(0, ball_two)  # insert at top of sprite list

    # create a stage for the background to show up on
    #   and set the frame rate to 60fps
    game = stage.Stage(ugame.display, 60)
    # set the background layer
    game.layers = sprites + [background]
    # render the background
    # most likely you will only render background once per scene
    game.render_block()

    while True:
        # get user inputs

        # update game logic

        # redraw sprtie list
        game.render_sprites(sprites)
        game.tick()  # wait until refresh rate finishes
コード例 #3
0
def main():
    # this function sets the background

    # sets the background to image 0 in the bank
    background = stage.Grid(image_bank_1, 10, 8)

    # create sprite
    alien = stage.Sprite(image_bank_1, 9, 64, 56)
    sprites.append(alien)
    ship = stage.Sprite(image_bank_1, 5, 75, 56)
    sprites.insert(0, ship)

    # create a stage for the background to show up on
    #   and set the frame rate to 60fps
    game = stage.Stage(ugame.display, 60)
    # set the background layer
    game.layers = sprites + [background]
    # render the background
    # most likely you will only render background once per scene
    game.render_block()

    while True:
        # get user input

        # update game logic

        # redraw sprite list
        game.render_sprites(sprites)
        game.tick()
コード例 #4
0
ファイル: code.py プロジェクト: matsuru-hoshi/ICS3U-FP-3
def main():
    # this function sets the background

    # sets the background to image 0 in the bank
    # backgrounds do not have magenta as a transparent color
    background = stage.Grid(image_bank_1, 10, 8)
    # changes (0,0) image to the 3rd image

    ship = stage.Sprite(image_bank_1, 5, 75, 56)
    sprites.append(ship)
    alien = stage.Sprite(image_bank_1, 9, 64, 56)
    sprites.append(alien)
    # create a stage for the background to show up on
    #   and set the frame rate to 60fps
    game = stage.Stage(ugame.display, 60)
    # set the background layer
    game.layers = [background]
    # render the background
    # most likely you will only render background once per scene
    game.render_block()

    # repeat forever, game loop
    while True:
        #get user input

        #update game logic

        #redraw sprite list
        game.render_sprites(sprites)
        game.tick()  #wait until refresh rate finishes
コード例 #5
0
def main():
    # this function is a scene

    # sets the background to image 0 in the bank
    background = stage.Grid(image_bank_1, 10, 8)

    # create a sprite
    # parameters (image_bank, image # in bank, x, y)
    alien = stage.Sprite(image_bank_1, 9, 64, 56)
    sprites.append(alien)
    ship = stage.Sprite(image_bank_1, 5, 75, 56)
    sprites.insert(0, ship)  # insert at top of sprite list

    # create a stage for the background to show up on
    #   and set the frame rate to 60fps
    game = stage.Stage(ugame.display, 60)
    # set the layers, items show up in order
    game.layers = sprites + [background]
    # render the background and initial location of sprite list
    # most likely you will only render background once per scene
    game.render_block()

    # repeat forever, game loop
    while True:
        # get user input

        # update game logic

        # redraw sprite list
        game.render_sprites(sprites)
        game.tick()  # wait until refresh rate finishes
コード例 #6
0
def main():

    # sets the backround to the image 0 in the bank
    # if your 0 image is magenta, your backround will most lickley be distorted
    # backrounds do not have megenta as a transparent color
    background = stage.Grid(bank, 10, 8)

    alien = stage.Sprite(bank, 9, 64, 56)
    sprites.append(alien)
    ship = stage.Sprite(bank, 5, 75, 56)
    sprites.insert(0, ship)

    # create a stage for the backround to show up on
    #     and set the frame rate to 60 fps
    game = stage.Stage(ugame.display, 60)
    # set the backround layer
    game.layers = sprites + [background]
    # render the backround
    # most likely you will only render backound once per scene
    game.render_block()

    while True:

        game.render_sprites(sprites)
        game.tick()
コード例 #7
0
def main():
    # this function is a scene

    # sets the background to image 0 in the bank
    background = stage.Grid(image_bank_1, 10, 8)

    # create a sprite
    # parameters (image_bank, image # in bank, x, y)
    alien = stage.Sprite(image_bank_1, 9, 64, 56)
    sprites.append(alien)
    ship = stage.Sprite(image_bank_1, 5, 74, 56)
    sprites.insert(0, ship) # insert at top of sprite list


    # create a stage for the background to show up on
    #   and set the frame rate to 60fps
    game = stage.Stage(ugame.display, 60)
    # set the layers, items show up in order
    game.layers = sprites + [background]
    # render the background and initial location of sprite list
    # most likely will only render background once per scene
    game.render_block()

    # repeat forever. game loop
    while True:
        # get user input
        keys = ugame.buttons.get_pressed()
        #print(keys)

        if keys & ugame.K_X:
            #print("A")
            pass
        if keys & ugame.K_O:
            #print("B")
            pass
        if keys & ugame.K_START:
            #print("K_START")
            pass
        if keys & ugame.K_SELECT:
            #print("K_SELECT")
            pass
        if keys & ugame.K_RIGHT:
            ship.move(ship.x + 1, ship.y)
            pass
        if keys & ugame.K_LEFT:
            ship.move(ship.x - 1, ship.y)
            pass
        elif keys & ugame.K_UP:
            ship.move(ship.x, ship.y - 1)
            pass
        elif keys & ugame.K_DOWN:
            ship.move(ship.x, ship.y + 1)
            pass

        # update game logic

        # redraw sprite list
        game.render_sprites(sprites)
        game.tick() # wait until refresh rate finishes
コード例 #8
0
def main():
    # this function sets the background

    # sets the background to image 0 in the bank
    background = stage.Grid(image_bank_1, 10, 8)

    # create a sprite
    # parameters (image_bank_1, image # in bank, x, y)
    ball_one = stage.Sprite(image_bank_1, 3, 64, 56)
    sprites.append(ball_one)
    ball_two = stage.Sprite(image_bank_1, 2, 75, 56)
    sprites.insert(0, ball_two)  # insert at top of sprite list

    # create a stage for the background to show up on
    #   and set the frame rate to 60fps
    game = stage.Stage(ugame.display, constants.FPS)
    # set the background layer
    game.layers = sprites + [background]
    # render the background
    # most likely you will only render background once per scene
    game.render_block()

    while True:
        # get user inputs
        keys = ugame.buttons.get_pressed()
        # print(keys)

        if keys & ugame.K_UP != 0:
            if ball_one.y < 0:
                ball_one.move(ball_one.x, 0)
            else:
                ball_one.move(ball_one.x, ball_one.y - 1)
            pass
        if keys & ugame.K_DOWN != 0:
            if ball_one.y > constants.SCREEN_Y - constants.SCREEN_GRID_Y:
                ball_one.move(ball_one.x,
                              constants.SCREEN_Y - constants.SPRITE_SIZE)
            else:
                ball_one.move(ball_one.x, ball_one.y + 1)
            pass
        if keys & ugame.K_LEFT != 0:
            if ball_one.x < 0:
                ball_one.move(0, ball_one.y)
            else:
                ball_one.move(ball_one.x - 1, ball_one.y)
            pass
        if keys & ugame.K_RIGHT != 0:
            if ball_one.x > constants.SCREEN_X - constants.SCREEN_GRID_X:
                ball_one.move(constants.SCREEN_X - constants.SPRITE_SIZE,
                              ball_one.y)
            else:
                ball_one.move(ball_one.x + 1, ball_one.y)
            pass
        # update game logic

        # redraw sprtie list
        game.render_sprites(sprites)
        game.tick()  # wait until refresh rate finishes
コード例 #9
0
def main():
    # this function sets the scene
    # an image bank for circuitpython
    image_bank_1 = stage.Bank.from_bmp16("space_aliens.bmp")
    # a list of sprites that will be updated every frame
    sprites = []

    ship = stage.Sprite(
        image_bank_1, 5,
        int(Constants.SCREEN_X / 2 - Constants.SPRITE_SIZE / 2),
        int(Constants.SCREEN_Y - Constants.SPRITE_SIZE +
            Constants.SPRITE_SIZE / 2))
    sprites.append(ship)  # insert at the top of the sprite list

    # sets the background to image 0 in the bank
    # backgrounds do not have magents as a transparent color
    background = stage.Grid(image_bank_1, 10, 8)
    # create a sprite
    # parameters (image_bank, image # in bank, x, y)
    alien = stage.Sprite(image_bank_1, 8, 64, 56)
    sprites.append(alien)

    # create a stage for the background to show up on
    #  and set the frame rate to 60
    game = stage.Stage(ugame.display, Constants.FPS)
    # set the layers, items show up in order
    game.layers = sprites + [background]
    # render the background and initial location of sprite list
    # most likely you will only render background once per scene
    game.render_block()

    # repeat forever, or you turn it off
    while True:
        # get user input
        keys = ugame.buttons.get_pressed()
        # update_game_logic
        # move ship to the right and the left
        if keys & ugame.K_RIGHT != 0:
            if ship.x > Constants.SCREEN_X - Constants.SPRITE_SIZE:
                ship.move(Constants.SCREEN_X - Constants.SPRITE_SIZE, ship.y)
            else:
                ship.move(ship.x + 1, ship.y)

        if keys & ugame.K_LEFT != 0:
            if ship.x < 0:
                ship.move(0, ship.y)
            else:
                ship.move(ship.x - 1, ship.y)
            pass
        # move ship up and down
        if keys & ugame.K_UP:
            ship.move(ship.x, ship.y - 1)
        elif keys & ugame.K_DOWN:
            ship.move(ship.x, ship.y + 1)
            pass
        # redraw sprite list
        game.render_sprites(sprites)
        game.tick()  # wait until refresh rate finishes
コード例 #10
0
def main():
    # this function sets the background

    # sets the background to image 0 in the bank
    background = stage.Grid(image_bank_1, 10, 8)

    # create sprite
    alien = stage.Sprite(image_bank_1, 9, 64, 56)
    sprites.append(alien)
    ship = stage.Sprite(image_bank_1, 5, 75, 56)
    sprites.insert(0, ship)

    # create a stage for the background to show up on
    #   and set the frame rate to 60fps
    game = stage.Stage(ugame.display, 60)
    # set the background layer
    game.layers = sprites + [background]
    # render the background
    # most likely you will only render background once per scene
    game.render_block()

    while True:
        # get user input
        keys = ugame.buttons.get_pressed()
        # print(keys)

        if keys & ugame.K_X:
            # print("A")
            pass
        if keys & ugame.K_O:
            # print("B")
            pass
        if keys & ugame.K_START:
            # print("K_START")
            pass
        if keys & ugame.K_SELECT:
            # print("K_SELECT")
            pass
        if keys & ugame.K_RIGHT:
            ship.move(ship.x + 1, ship.y)
            pass
        if keys & ugame.K_LEFT:
            ship.move(ship.x - 1, ship.y)
            pass
        if keys & ugame.K_UP:
            ship.move(ship.x, ship.y - 1)
            pass
        if keys & ugame.K_DOWN:
            ship.move(ship.x, ship.y + 1)
            pass

        # update game logic

        # redraw sprite list
        game.render_sprites(sprites)
        game.tick()
コード例 #11
0
def main():
    # an image bank for CircuitPython

    image_bank_1 = stage.Bank.from_bmp16("space_aliens.bmp")

    # a list of sprites
    sprites = []

    # this function sets the background
    ship = stage.Sprite(
        image_bank_1, 5,
        int(constants.SCREEN_X / 2 - constants.SPRITE_SIZE / 2),
        int(constants.SCREEN_Y - constants.SPRITE_SIZE +
            constants.SPRITE_SIZE / 2))
    sprites.append(ship)  # insert at the top of the sprite list

    # sets the background to image 0 in the bank
    background = stage.Grid(image_bank_1, 10, 8)

    # create sprite
    alien = stage.Sprite(image_bank_1, 9, 64, 56)
    sprites.append(alien)
    ship = stage.Sprite(image_bank_1, 5, 75, 56)
    sprites.insert(0, ship)

    # create a stage for the background to show up on
    #   and set the frame rate to 60fps
    game = stage.Stage(ugame.display, constants.FPS)
    # set the background layer
    game.layers = sprites + [background]
    # render the background
    # most likely you will only render background once per scene
    game.render_block()

    # repeat forever, game loop
    while True:
        # get user input
        keys = ugame.buttons.get_pressed()

        # moves ship in different directions
        if keys & ugame.K_RIGHT != 0:
            if ship.x > constants.SCREEN_X - constants.SPRITE_SIZE:
                ship.move(constants.SCREEN_X - constants.SPRITE_SIZE, ship.y)
            else:
                ship.move(ship.x + 1, ship.y)
        if keys & ugame.K_LEFT != 0:
            if ship.x < 0:
                ship.move(0, ship.y)
            else:
                ship.move(ship.x - 1, ship.y)
        # update game logic

        # redraw sprite list
        game.render_sprites(sprites)
        game.tick()  # wait until refresh rate finishes
コード例 #12
0
def main():
    # this functionm is a scene

    # sets the background to image 0 in the bank
    background = stage.Grid(image_bank_1, 10, 8)

    # creating the sprites
    alien = stage.Sprite(image_bank_1, 9, 64, 56)
    sprites.append(alien)
    ship = stage.Sprite(image_bank_1, 5, 75, 56)
    sprites.insert(0, ship)

    # create a stage for the background to show up
    # setting the frame rate to 60fps
    game = stage.Stage(ugame.display, 60)
    # setting the layers to show them in order
    game.layers = sprites + [background]
    # rendering the background and the locations of the sprites
    game.render_block()

    # repeat forever game loop
    while True:
        # get user input
        keys = ugame.buttons.get_pressed()
        # print(keys)

        if keys & ugame.K_X:
            # print("A")
            pass
        if keys & ugame.K_O:
            # print("B")
            pass
        if keys & ugame.K_START:
            # print("K_START")
            pass
        if keys & ugame.K_SELECT:
            # print("K_SELECT")
            pass
        if keys & ugame.K_RIGHT:
            ship.move(ship.x + 1, ship.y)
            pass
        if keys & ugame.K_LEFT:
            ship.move(ship.x - 1, ship.y)
            pass
        if keys & ugame.K_UP:
            ship.move(ship.x, ship.y - 1)
            pass
        if keys & ugame.K_DOWN:
            ship.move(ship.x, ship.y + 1)
            pass

        # update game logic
        # redraw sprites
        game.render_sprites(sprites)
        game.tick()
コード例 #13
0
def game_scene():
    # Main game scene

    # IMAGE BANKS
    game_image_bank = stage.Bank.from_bmp16("image_bank_1.bmp")

    # BACKGROUND
    # Sets background to the 0th image in the image bank, 10x8 grid
    game_background = stage.Grid(game_image_bank, constants.SCREEN_GRID_X,
                                 constants.SCREEN_GRID_Y)

    # Sets the floor as the 1st image in the image bank, the walls are
    # still going to be the 0th image
    for x_location in range(1, constants.SCREEN_GRID_X - 1):
        for y_location in range(1, constants.SCREEN_GRID_Y - 1):
            tile_picked = 1
            game_background.tile(x_location, y_location, tile_picked)

    # SPRITES CREATION
    # Character sprite being displayed
    character = stage.Sprite(game_image_bank, 2, 75, 66)

    # STAGE AND RENDER
    # Creates a stage for the background
    # Sets frame rate to 60fps
    game = stage.Stage(ugame.display, constants.FPS)
    # Sets sprite layers and show up in order
    game.layers = ([character] + [game_background])
    # Renders all sprites, only once
    game.render_block()

    # GAME LOOP
    while True:
        pass
コード例 #14
0
ファイル: code.py プロジェクト: Ryan-Nguyen-7/Pybadge
def game_scene():
    # this function is the main game game_scene

    # image banks for CIrcuitPython
    image_bank_background = stage.Bank.from_bmp16(
        "space_aliens_background.bmp")
    image_bank_sprites = stage.Bank.from_bmp16("space_aliens.bmp")

    # sets the background to image 0 in the image Bank
    #   and the size (10x8 tiles of size 16x16)
    background = stage.Grid(image_bank_background, 10, 8)

    ship = stage.Sprite(image_bank_sprites, 5, 75, 66)

    # create a stage for the background to show up on
    #   and set the frame rate to 60fps
    game = stage.Stage(ugame.display, 60)
    # set the layers, items show up in order
    game.layers = [ship] + [background]
    # render the background and initial location of sprite list
    # most likely you will only render background once per scene
    game.render_block()

    # repeat forever, game loop
    while True:
        # get user input

        # update game logic

        # redraw image_bank_sprites
        game.render_sprites([ship])
        game.tick()
コード例 #15
0
ファイル: fun.py プロジェクト: khang-le/fbd5
def game_scence():

    # this function is a scence
    image_bank_1 = stage.Bank.from_bmp16("space_aliens.bmp")
    background = stage.Grid(image_bank_1, constants.SCREEN_X,
                            constants.SCREEN_Y)
    sprites = []
    ship = stage.Sprite(
        image_bank_1, 5,
        int(constants.SCREEN_X / 2 - constants.SPRITE_SIZE / 2),
        int(constants.SCREEN_Y - constants.SPRITE_SIZE +
            constants.SPRITE_SIZE / 2))
    sprites.append(ship)
    game = stage.Stage(ugame.display, constants.FPS)
    game.layers = sprites + [background]
    game.render_block()

    while True:
        keys = ugame.buttons.get_pressed()
        if keys & ugame.K_RIGHT != 0:
            if ship.x > constants.SCREEN_X - constants.SPRITE_SIZE:
                ship.move(constants.SCREEN_X - constants.SPRITE_SIZE, ship.y)
            else:
                ship.move(ship.x + 1, ship.y)
        if keys & ugame.K_LEFT != 0:
            if ship.x < 0:
                ship.move(0, ship.y)
            else:
                ship.move(ship.x - 1, ship.y)

        game.render_sprites(sprites)
        game.tick()
コード例 #16
0
def main():
    # this functionm is a scene

    # sets the background to image 0 in the bank
    background = stage.Grid(image_bank_1, 10, 8)

    # creating the sprites
    alien = stage.Sprite(image_bank_1, 7, 64, 56)
    sprites.append(alien)
    ship = stage.sprites(image_bank_1, 8, 75, 56)
    sprites.insert(0, ship)

    # create a stage for the background to show up
    # setting the frame rate to 60fps
    game = stage.Stage(ugame.display, 60)
    # setting the layers to show them in order
    game.layers = sprites + [background]
    # rendering the background and the locations of the sprites
    game.render_block()

    # repeat forever game loop
    while True:

        # redraw sprites
        game.render_sprites(sprites)
        game.tick()
コード例 #17
0
def main():
    # set background
    background = stage.Grid(bank_1, 10, 8)
    # creates sprite
    alien = stage.Sprite(bank_1, 9, 64, 56)
    sprites.append(alien)
    ship = stage.Sprite(bank_1, 9, 64, 56)
    sprites.insert(0, ship)

    game = stage.Stage(ugame.display, 60)
    game.layers = sprites + [background]
    game.rander_block()

    while True:
        game.render_sprites(sprites)
        game.tick()
コード例 #18
0
def game_scene():
    # Main game scene

    # IMAGE BANKS
    game_image_bank = stage.Bank.from_bmp16("image_bank_1.bmp")

    # BACKGROUND
    # Sets background to the 0th image in the image bank, 10x8 grid
    game_background = stage.Grid(game_image_bank, constants.SCREEN_GRID_X,
                                 constants.SCREEN_GRID_Y)

    # Sets the floor as the 1st image in the image bank, the walls are
    # still going to be the 0th image
    for x_location in range(1, constants.SCREEN_GRID_X - 1):
        for y_location in range(1, constants.SCREEN_GRID_Y - 1):
            tile_picked = 1
            game_background.tile(x_location, y_location, tile_picked)

    # SPRITES CREATION
    # Character sprite being displayed
    character = stage.Sprite(game_image_bank, 2, 75, 66)

    # STAGE AND RENDER
    # Creates a stage for the background
    # Sets frame rate to 60fps
    game = stage.Stage(ugame.display, constants.FPS)
    # Sets sprite layers and show up in order
    game.layers = ([character] + [game_background])
    # Renders all sprites, only once
    game.render_block()

    # GAME LOOP
    while True:
        # USER MOVEMENT
        keys = ugame.buttons.get_pressed()

        if keys & ugame.K_RIGHT:
            # Move right
            character.move(character.x + 1, character.y)
            character.set_frame(2, 0)
        if keys & ugame.K_LEFT:
            # Move left
            character.move(character.x - 1, character.y)
            character.set_frame(2, 4)
        if keys & ugame.K_UP:
            # Move up
            character.move(character.x, character.y - 1)
            character.set_frame(3, 0)
        if keys & ugame.K_DOWN:
            # Move down
            character.move(character.x, character.y + 1)
            character.set_frame(4, 0)

        # RENDER AND REDRAW
        # Renders and redraws the sprites that move
        game.render_sprites([character])
        # Waits until refresh rate finishes
        game.tick()
コード例 #19
0
ファイル: code.py プロジェクト: matsuru-hoshi/ICS3U-FP-7
def game_scene():
    image_bank_1 = stage.Bank.from_bmp16("space_aliens.bmp")

    a_button = constants.button_state["button_up"]

    pew_sound = open("pew.wav", 'rb')
    sound = ugame.audio
    sound.stop()
    sound.mute(False)

    background = stage.Grid(image_bank_1, constants.SCREEN_X,
                            constants.SCREEN_Y)

    sprites = []

    ship = stage.Sprite(
        image_bank_1, 5,
        int(constants.SCREEN_X / 2 - constants.SPRITE_SIZE / 2),
        int(constants.SCREEN_Y - constants.SPRITE_SIZE +
            constants.SPRITE_SIZE / 2))
    sprites.append(ship)

    game = stage.Stage(ugame.display, constants.FPS)
    game.layers = sprites + [background]
    game.render_block()

    while True:
        keys = ugame.buttons.get_pressed()
        # print (keys)

        if keys & ugame.K_X != 0:
            if a_button == constants.button_state["button_up"]:
                a_button = constants.button_state["button_just_pressed"]
            elif a_button == constants.button_state["button_just_pressed"]:
                a_button = constants.button_state["button_still_pressed"]
        else:
            if a_button == constants.button_state["button_still_pressed"]:
                a_button = constants.button_state["button_released"]
            else:
                a_button = constants.button_state["button_up"]

        if keys & ugame.K_RIGHT != 0:
            if ship.x > constants.SCREEN_X - constants.SPRITE_SIZE:
                ship.move(constants.SCREEN_X - constants.SPRITE_SIZE, ship.y)
            else:
                ship.move(ship.x + 1, ship.y)

        if keys & ugame.K_LEFT != 0:
            if ship.x < 0:
                ship.move(0, ship.y)
            else:
                ship.move(ship.x - 1, ship.y)

        # if a_button == constants.button_state["button_just_pressed"]:
            sound.play(pew_sound)

        game.render_sprites(sprites)
        game.tick()  # wait until refresh rate finishes
コード例 #20
0
def game_scene():
    # this function is the main game scene

    # image bank
    image_bank_background = stage.Bank.from_bmp16(
        "space_aliens_background.bmp")
    image_bank_sprites = stage.Bank.from_bmp16("space_aliens.bmp")

    # set background to img 0 and 10x8 tiles of size 16x16
    background = stage.Grid(image_bank_background, constants.SCREEN_GRID_X,
                            constants.SCREEN_GRID_Y)

    # sprite that will be updated every frame
    ship = stage.Sprite(image_bank_sprites, 5, 75,
                        constants.SCREEN_Y - (2 * constants.SPRITE_SIZE))

    # creates stage and sets it to 60fps
    game = stage.Stage(ugame.display, constants.FPS)

    # sets the layers of all sprites, in order
    game.layers = [ship] + [background]

    # renders all sprites, only once
    game.render_block()

    # forever game loop
    while True:
        # get user input
        keys = ugame.buttons.get_pressed()

        if keys & ugame.K_X:
            pass
        if keys & ugame.K_O:
            pass
        if keys & ugame.K_START:
            pass
        if keys & ugame.K_SELECT:
            pass
        if keys & ugame.K_RIGHT:
            if ship.x <= constants.SCREEN_X - constants.SPRITE_SIZE:
                ship.move(ship.x + constants.SPRITE_MOVEMENT_SPEED, ship.y)
            else:
                ship.move(constants.SCREEN_X - constants.SPRITE_SIZE, ship.y)
        if keys & ugame.K_LEFT:
            if ship.x >= 0:
                ship.move(ship.x - constants.SPRITE_MOVEMENT_SPEED, ship.y)
            else:
                ship.move(0, ship.y)
        if keys & ugame.K_UP:
            pass
        if keys & ugame.K_DOWN:
            pass
        # update game logic

        #redraw Sprite
        game.render_sprites([ship])
        game.tick()
コード例 #21
0
def game_scene():
    # this function is the main game game_scene

   # image banks for CircuitPython
   image_bank_bankground = stage.Bank.from_bmp16("space_aliens_background.bmp")
   image_bank_sprites = stage.Bank.from_bmp16("space_aliens.bmp")
   
   # set the background to image 0 in the image Bank
   #   and the size (10x8 tiles of the size 16x16)
   background = stage.Grid(image_bank_bankground, 10,8)
   
   # a sprite that will be updated every frame
   ship = stage.Sprite(image_bank_sprites, 5, 75, constants.SCREEN_Y - (2 * constants.SPRITE_SIZE))

   # create a stage for the background to show up on
   #   and set the frame rate for 60fps
   game = stage.Stage(ugame.display, 60)
   # set layers of all sprites, items show up in order
   game.layers = [ship] + [background]
   # render all sprites
   #   most likely you will only render the background once per game scene
   game.render_block()

    # repeat forever, game loop
   while True:
       # get user input
       keys = ugame.buttons.get_pressed()
       
       if keys & ugame.K_X:
           print("A")
       if keys & ugame.K_O:
           print("Start")
       if keys & ugame.K_START:
           print("A")
       if keys & ugame.K_SELECT:
           print("Select")
       if keys & ugame.K_RIGHT != 0:
           if ship.x < (constants.SCREEN_X - constants.SPRITE_SIZE):
               ship.move((ship.x + constants.SPRITE_MOVEMENT_SPEED), ship.y)
           else:
               ship.move((constants.SCREEN_X - constants.SPRITE_SIZE), ship.y)

       if keys & ugame.K_LEFT != 0:
            if ship.x > 0:
                ship.move((ship.x - constants.SPRITE_MOVEMENT_SPEED), ship.y)
            else:
                ship.move(0, ship.y)

       if keys & ugame.K_UP:
           pass
       if keys & ugame.K_DOWN:
           pass 
       # update game logic
       
       # redraw Sprite
       game.render_sprites([ship])
       game.tick() # wait until refresh rate finishes
コード例 #22
0
def game_scene():
    # this function is the main game game_scene

    # image banks for CIrcuitPython
    image_bank_background = stage.Bank.from_bmp16("space_aliens_background.bmp")
    image_bank_sprites = stage.Bank.from_bmp16("space_aliens.bmp")

    # sets the background to image 0 in the image Bank
    #   and the size (10x8 tiles of size 16x16)
    background = stage.Grid(image_bank_background, constants.SCREEN_GRID_X, constants.SCREEN_GRID_Y)
    
    ship = stage.Sprite(image_bank_sprites, 5, 75, constants.SCREEN_Y - (2 * constants.SPRITE_SIZE))
    
    # create a stage for the background to show up on
    #   and set the frame rate to 60fps
    game = stage.Stage(ugame.display, 60)
    # set the layers, items show up in order
    game.layers = [ship] + [background]
    # render the background and initial location of sprite list
    # most likely you will only render background once per scene
    game.render_block()

    # repeat forever, game loop
    while True:
        # get user input
        keys = ugame.buttons.get_pressed()

        if keys & ugame.K_X:
            pass
        if keys & ugame.K_O:
            pass
        if keys & ugame.K_START:
            pass
        if keys & ugame.K_SELECT:
            pass
        if keys & ugame.K_RIGHT:
            if ship.x <= constants.SCREEN_X - constants.SPRITE_SIZE:
                ship.move(ship.x + 1, ship.y)
            else:
                ship.move(constants.SCREEN_X - constants.SPRITE_SIZE, ship.y)
                
        if keys & ugame.K_LEFT:
            if ship.x >= 0:
                ship.move(ship.x - 1, ship.y)
            else:
                ship.move(0, ship.y)
        if keys & ugame.K_UP:
            pass
        if keys & ugame.K_DOWN:
            pass

        # update game logic

        # redraw image_bank_sprites
        game.render_sprites([ship])
        game.tick()
コード例 #23
0
ファイル: spacey.py プロジェクト: cameron-teed/ICS3U-FP5-PY
def main():
    # this function is a scene

    # sets the background to image 0 in the bank
    background = stage.Grid(image_bank_1, constants.SCREEN_X,
                            constants.SCREEN_Y)

    # create a sprite
    # parameters (image_bank, image # in bank, x, y)
    ship = stage.Sprite(
        image_bank_1, 5,
        int(constants.SCREEN_X / 2 - constants.SPRITE_SIZE / 2),
        int(constants.SCREEN_Y - constants.SPRITE_SIZE +
            constants.SPRITE_SIZE / 2))
    sprites.append(ship)  # insert at the top of sprite list

    # create a stage for the background to show up on
    #   and set the frame rate to 60fps
    game = stage.Stage(ugame.display, constants.FPS)
    # set the layers, items show up in order
    game.layers = sprites + [background]
    # render the background and inital location of sprite list
    # most likely you will only render background once per scene
    game.render_block()

    # repeat forever, game loop
    while True:
        # get user input
        keys = ugame.buttons.get_pressed()
        # print(keys)
        if keys & ugame.K_X:  # a
            pass
        if keys & ugame.K_O:  # b
            pass
        if keys & ugame.K_START:  # start
            pass
        if keys & ugame.K_SELECT:  # select
            pass
        if keys & ugame.K_RIGHT != 0:  # right
            if ship.x > constants.SCREEN_X - constants.SPRITE_SIZE:
                ship.move(constants.SCREEN_X - constants.SPRITE_SIZE, ship.y)
            else:
                ship.move(ship.x + 1, ship.y)
            pass
        if keys & ugame.K_LEFT != 0:  # left
            if ship.x < 0:
                ship.move(0, ship.y)
            else:
                ship.move(ship.x - 1, ship.y)
            pass

        # update game logic

        # redraw sprite list
        game.render_sprites(sprites)
        game.tick()  # wait until refresh rate finishes
コード例 #24
0
def game_splash_scene():
    # this function is the MT splash scene

    # an image bank for CircuitPython
    image_bank_2 = stage.Bank.from_bmp16("sprites.bmp")
    image_bank_3 = stage.Bank.from_bmp16("splash_screen.bmp")

    # sets the background to image 0 in the bank
    background = stage.Grid(image_bank_2, constants.SCREEN_GRID_X,
                            constants.SCREEN_GRID_Y)

    T = stage.Sprite(image_bank_3, 0, 65, 45)
    sprites.append(T)

    J = stage.Sprite(image_bank_3, 1, 81, 45)
    sprites.append(J)

    G = stage.Sprite(image_bank_3, 2, 40, 63)
    sprites.append(G)

    A = stage.Sprite(image_bank_3, 3, 56, 63)
    sprites.append(A)

    M = stage.Sprite(image_bank_3, 4, 72, 63)
    sprites.append(M)

    E = stage.Sprite(image_bank_3, 5, 88, 63)
    sprites.append(E)

    S = stage.Sprite(image_bank_3, 6, 104, 63)
    sprites.append(S)

    # create a stage for the background to show up on
    #   and set the frame rate to 60fps
    game = stage.Stage(ugame.display, 60)
    # set the layers, items show up in order
    game.layers = [background]
    # render the background and inital location of sprite list
    # most likely you will only render background once per scene
    game.render_block()

    sprites.remove(T)
    sprites.remove(J)
    sprites.remove(G)
    sprites.remove(A)
    sprites.remove(M)
    sprites.remove(E)
    sprites.remove(S)

    # repeat forever, game loop
    while True:
        # get user input

        # update game logic

        # Wait for 3 seconds
        time.sleep(3.0)
        main_menu_scene()
コード例 #25
0
def game_scene():
    # this function is a scene

    # an image bank for CircuitPython
    image_bank_1 = stage.Bank.from_bmp16("space_aliens.bmp")

    # sets the background to image 0 in the bank
    background = stage.Grid(image_bank_1, constants.SCREEN_X,
                            constants.SCREEN_Y)

    # a list of sprites that will be updated every frame
    sprites = []

    ship = stage.Sprite(
        image_bank_1, 5,
        int(constants.SCREEN_X / 2 - constants.SPRITE_SIZE / 2),
        int(constants.SCREEN_Y - constants.SPRITE_SIZE +
            constants.SPRITE_SIZE / 2))
    sprites.append(ship)

    # insert at the top of sprite list
    # create a stage for the background to show up on
    #   and set the frame rate to 60fps
    game = stage.Stage(ugame.display, constants.FPS)
    # set in layers, items shi\ow up in order
    game.layers = sprites + [background]
    # render the background and initial location of sprite list
    # mpst likely you will only render background once per scene
    game.render_block()

    # repeat forever, game loop
    while True:
        # get user input
        keys = ugame.buttons.get_pressed()
        # primt(keys)

        # update game logic
        # move ship right
        if keys & ugame.K_RIGHT != 0:
            if ship.x > constants.SCREEN_X - constants.SPRITE_SIZE:
                ship.move(constants.SCREEN_X - constants.SPRITE_SIZE, ship.y)
            else:
                ship.move(ship.x + 1, ship.y)

        # move ship left
        if keys & ugame.K_LEFT != 0:
            if ship.x < 0:
                ship.move(0, ship.y)
            else:
                ship.move(ship.x - 1, ship.y)

        # redraw sprite list

        game.render_sprites(sprites)
        game.tick()
コード例 #26
0
def main():

    background = stage.Grid(image_bank_1, 10, 8)
    alien = stage.Sprite(image_bank_1, 9, 64, 56)
    sprites.append(alien)
    ship = stage.Sprite(image_bank_1, 5, 74, 56)
    sprites.append(ship)

    game = stage.Stage(ugame.display, 60)
    game.layers = sprites + [background]
    game.render_block()

    while True:
        keys = ugame.buttons.get_pressed()
        print(keys)

        if keys & ugame.K_X:
            pass

        if keys & ugame.K_O:
            pass

        if keys & ugame.K_START:
            pass

        if keys & ugame.K_SELECT:
            pass

        if keys & ugame.K_LEFT:
            ship.move(ship.x - 1, ship.y)

        if keys & ugame.K_RIGHT:
            ship.move(ship.x + 1, ship.y)

        if keys & ugame.K_UP:
            ship.move(ship.x, ship.y - 1)

        if keys & ugame.K_DOWN:
            ship.move(ship.x, ship.y + 1)

        game.render_sprites(sprites)
        game.tick()
コード例 #27
0
 def __init__(self, text1, text2=None):
     bank = stage.Bank.from_bmp16("gui.bmp")
     super().__init__(bank,
                      width=game.tilesX,
                      height=2,
                      text1=text1,
                      text2=text2)
     self.fromHexList(["0111111112", "3444444445"])
     self.sprite1 = stage.Sprite(bank, 10, game.width - 2 * game.spriteSize,
                                 game.height - int(1.5 * game.spriteSize))
     self.move(0, game.height - 2 * game.spriteSize)
コード例 #28
0
def main():

    # sets the background to image 0 in the bank
    background = stage.Grid(image_bank_1, 10, 8)

    alien = stage.Sprite(image_bank_1, 9, 64, 56)
    sprites.append(alien)
    ship = stage.Sprite(image_bank_1, 5, 75, 56)
    sprites.insert(0, ship)

    # setting up the background to show up on the PyPadge
    # setting up the frame rate to 60fps
    game = stage.Stage(ugame.display, 60)
    game.layers = sprites + [background]

    game.render_block()

    while True:
        game.render_sprites(sprites)
        game.tick()
コード例 #29
0
def main():
    # this function sets the scene

    # sets the background to image 0 in the bank
    # backgrounds do not have magents as a transparent color
    background = stage.Grid(image_bank_1, 10, 8)
    # create a sprite
    # parameters (image_bank, image # in bank, x, y)
    alien = stage.Sprite(image_bank_1, 8, 64, 56)
    sprites.append(alien)
    ship = stage.Sprite(image_bank_1, 4, 75, 56)
    sprites.insert(0, ship)  # insert at top of sprite list

    # create a stage for the background to show up on
    #  and set the frame rate to 60
    game = stage.Stage(ugame.display, 60)
    # set the layers, items show up in order
    game.layers = sprites + [background]
    # render the background and initial location of sprite list
    # most likely you will only render background once per scene
    game.render_block()

    # repeat forever, or you turn it off
    while True:
        # get user input
        keys = ugame.buttons.get_pressed()
        # update_game_logic
        if keys & ugame.K_LEFT:
            ship.move(ship.x - 1, ship.y)
        elif keys & ugame.K_RIGHT:
            ship.move(ship.x + 1, ship.y)
            pass
        if keys & ugame.K_UP:
            ship.move(ship.x, ship.y - 1)
        elif keys & ugame.K_DOWN:
            ship.move(ship.x, ship.y + 1)
            pass
        # redraw sprite list
        game.render_sprites(sprites)
        game.tick()  # wait until refresh rate finishes
コード例 #30
0
def game_scene():
    # this function is a scene

    # an image bank of CircuitPython
    image_bank_1 = stage.Bank.from_bmp16("space_aliens.bmp")

    # sets the background to image 0 in the bank
    background = stage.Grid(image_bank_1, constants.SCREEN_X,
                            constants.SCREEN_Y)

    # the list of the sprites that will be on the device
    sprites = []

    ship = stage.Sprite(
        image_bank_1, 5,
        int(constants.SCREEN_X / 2 - constants.SPRITE_SIZE / 2),
        int(constants.SCREEN_Y - constants.SPRITE_SIZE +
            constants.SPRITE_SIZE / 2))
    sprites.append(ship)  # insert at the top of sprite list

    # create a stage for the background to show up
    # setting the frame rate to 60fps
    game = stage.Stage(ugame.display, constants.FPS)
    # setting the layers to show them in order
    game.layers = sprites + [background]
    # rendering the background and the locations of the sprites
    game.render_block()

    # repeat forever game loop
    while True:
        # get user input
        keys = ugame.buttons.get_pressed()
        #print(keys)

        # update game logic
        # move ship right
        if keys & ugame.K_RIGHT != 0:
            if ship.x > constants.SCREEN_X - constants.SPRITE_SIZE:
                ship.move(constants.SCREEN_X - constants.SPRITE_SIZE, ship.y)
            else:
                ship.move(ship.x + 1, ship.y)

        # move ship right
        if keys & ugame.K_LEFT != 0:
            if ship.x < 0:
                ship.move(0, ship.y)
            else:
                ship.move(ship.x - 1, ship.y)

        # redraw sprite list
        game.render_sprites(sprites)
        game.tick()  # wait until refresh rate finishes