def game_over(final_score): image_bank_1 = stage.Bank.from_bmp16("iib_sprites.bmp") background = stage.Grid(image_bank_1, constants.SCREEN_GRID_X, constants.SCREEN_GRID_Y) for x_location in range(constants.SCREEN_GRID_X): for y_location in range(constants.SCREEN_GRID_X): background.tile(x_location, y_location, 3) sprites = [] text = [] text_game_over = [] text_game_over_list = [] text_game_over = stage.Text(width=29, height=12, font=None, palette=constants.ICE_ICE_BABY_PALETTE, buffer=None) text_game_over.move(45, 50) text_game_over.text("Game Over") text.append(text_game_over) # V If game lags, change this V game = stage.Stage(ugame.display, constants.FPS) # add text at top of screen for score score_text = stage.Text(width=29, height=14, font=None, palette=constants.SCORE_PALETTE, buffer=None) score_text.clear() score_text.cursor(0, 0) score_text.move(16, 80) score_text.text("Final Score: {0}".format(final_score)) game.layers = [score_text] + [text_game_over] + [background] game.render_block() while True: pass
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
def splash_scene(): # This is the splash 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, 160, 120) # 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() # repeat forever, game loop while True: # get user input # update game logic # Wait for 1 seconds time.sleep(1.0) menu_scene()
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
def game_over_scene(final_score): # this function is the game over scene image_bank_2 = stage.Bank.from_bmp16("mt_game_studio.bmp") background = stage.Grid(image_bank_2, constants.SCREEN_GRID_X, constants.SCREEN_GRID_Y) text = [] text0 = stage.Text(width=29, height=14, font=None, palette=constants.MT_GAME_STUDIO_PALETTE, buffer=None) text0.move(22, 20) text0.text("Final Score: {:0>2d}".format(final_score)) text.append(text0) text1 = stage.Text(width=29, height=14, font=None, palette=constants.MT_GAME_STUDIO_PALETTE, buffer=None) text1.move(43, 60) text1.text("GAME OVER") text.append(text1) text2 = stage.Text(width=29, height=14, font=None, palette=constants.MT_GAME_STUDIO_PALETTE, buffer=None) text2.move(32, 110) text2.text("PRESS SELECT") text.append(text2) game = stage.Stage(ugame.display, 60) game.layers = text + [background] game.render_block() while True: keys = ugame.buttons.get_pressed() if keys & ugame.K_SELECT != 0: # Start button keys = 0 menu_scene()
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()
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()
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()
def blank_white_reset_scene(): # this function is the splash scene game loop # do house keeping to ensure everythng is setup # set up the NeoPixels # pixels = neopixel.NeoPixel(board.NEOPIXEL, 5, auto_write=False) # pixels.deinit() # and turn them all off # reset sound to be off sound = ugame.audio sound.stop() sound.mute(False) # an image bank for CircuitPython image_bank_1 = stage.Bank.from_bmp16("mt_game_studio.bmp") # sets the background to image 0 in the bank background = stage.Grid(image_bank_1, 160, 120) # 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() # repeat forever, game loop while True: # get user input # update game logic # Wait for 1/2 seconds time.sleep(0.5) mt_splash_scene()
def blank_white_reset_scene(): # this function is the splash scene game loop # do house keeping to ensure everythng is setup # reset sound to be off sound = ugame.audio sound.stop() sound.mute(False) # an image bank for CircuitPython image_bank_1 = stage.Bank.from_bmp16("mt_game_studio.bmp") # sets the background to image 0 in the bank background = stage.Grid(image_bank_1, 160, 120) # 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() # repeat forever, game loop while True: time.sleep(0.5) mt_splash_scene()
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()
def menu_scene(): # this function is the splash game loop # new pallet for black filled text NEW_PALETTE = ( b'\xff\xff\x00\x22\xcey\x22\xff\xff\xff\xff\xff\xff\xff\xff\xff' b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff') # An image bank for CicuitPython 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 = [] # add text objects text = [] text1 = stage.Text(width=29, height=12, font=None, palette=NEW_PALETTE, buffer=None) text1.move(20, 10) text1.text("Dylan & Ben\n Game Studios") text.append(text1) text2 = stage.Text(width=29, height=12, font=None, palette=NEW_PALETTE, buffer=None) text2.move(40, 110) text2.text("Press Start") text.append(text2) # 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 = text + 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 keys = ugame.buttons.get_pressed() # print(keys) # A button to fire if keys & ugame.K_START != 0: sound.play(start_sound) game_scene() # update game logic game.tick() # wait until refresh rate finishes
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()
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
def menu(): background = stage.Grid(image_bank_1, 10, 8) text = [] text1 = stage.Text(width=29, height=14, font=None, palette=constants.MT_GAME_STUDIO_PALETTE, buffer=None) text1.move(55, 50) text1.text("WELCOME!") text.append(text1) text2 = stage.Text(width=29, height=14, font=None, palette=constants.MT_GAME_STUDIO_PALETTE, buffer=None) text2.move(40, 70) text2.text("PRESS START") text.append(text2) game = stage.Stage(ugame.display, 60) # set the layers, items show up in order game.layers = text + [background] # render the background and inital location of sprite list # most likely you will only render background once per scene game.render_block() while True: keys = ugame.buttons.get_pressed() if keys & ugame.K_START != 0: game_scene()
def game_splash_scene(): # this function is the MT splash scene # an image bank for CircuitPython image_bank_2 = stage.Bank.from_bmp16("break_out.bmp") # sets the background to image 0 in the bank background = stage.Grid(image_bank_2, constants.SCREEN_GRID_X, constants.SCREEN_GRID_Y) text = [] text1 = stage.Text(width=29, height=15, font=None, palette=constants.MT_GAME_STUDIO_PALETTE, buffer=None) text1.move(50, 60) text1.text("Ferda Games") text.append(text1) # 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 = text + [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 # update game logic # Wait for 3 seconds time.sleep(3.0) main_menu_scene()
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
def game_over_scene(): global score image_bank_2 = stage.Bank.from_bmp16("mt_game_studio.bmp") background = stage.Grid(image_bank_2, constants.SCREEN_GRID_X, constants.SCREEN_GRID_Y) text = [] text0 = stage.Text(29, 14, None, constants.PLT, buffer=None) text0.move(22, 20) text0.text("Final Score: {:0>2d}".format(score)) text.append(text0) text1 = stage.Text(29, 14, None, constants.PLT, buffer=None) text1.move(43, 60) text1.text("GAME OVER") text.append(text1) text2 = stage.Text(29, 14, None, constants.PLT, buffer=None) text2.move(32, 110) text2.text("PRESS START") text.append(text2) game = stage.Stage(ugame.display, 60) game.layers = text + [background] game.render_block() while True: keys = ugame.buttons.get_pressed() if keys & ugame.K_SELECT != 0: keys = 0 menu_scene()
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) # 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 = [game_background] # Renders all sprites, only once game.render_block() # GAME LOOP while True: pass
def game_over_scene(score): # this function is the game over scene # an image bank for CircuitPython image_bank_2 = stage.Bank.from_bmp16("egg_collector_image_bank_test.bmp") # sets the background to image 0 in the bank background = stage.Grid(image_bank_2, constants.SCREEN_GRID_X, constants.SCREEN_GRID_Y) # a list to hold game over text text = [] text0 = stage.Text(width=29, height=14, font=None, palette=constants.SCORE_PALETTE, buffer=None) text0.move(22, 20) text0.text("Final Score: {:0>2d}".format(score)) text.append(text0) text1 = stage.Text(width=29, height=14, font=None, palette=constants.SCORE_PALETTE, buffer=None) text1.move(43, 60) text1.text("GAME OVER") text.append(text1) text2 = stage.Text(width=29, height=14, font=None, palette=constants.SCORE_PALETTE, buffer=None) text2.move(32, 110) text2.text("PRESS SELECT") text.append(text2) # 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 = text + [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 # update game logic keys = ugame.buttons.get_pressed() # print(keys) if keys & ugame.K_SELECT != 0: # Start button keys = 0 main_menu_scene()
def splash_scene(): # this function is the splash scene # get sound ready coin_sound = open("coin.wav", 'rb') sound = ugame.audio sound.stop() sound.mute(False) sound.play(coin_sound) # image bank image_bank_mt_background = stage.Bank.from_bmp16("mt_game_studio.bmp") # sets bg to image 0 in the image bank background = stage.Grid(image_bank_mt_background, constants.SCREEN_X, constants.SCREEN_Y) # used this program to split the image into tile: # https://ezgif.com/sprite-cutter/ezgif-5-818cdbcc3f66.png background.tile(2, 2, 0) # blank white background.tile(3, 2, 1) background.tile(4, 2, 2) background.tile(5, 2, 3) background.tile(6, 2, 4) background.tile(7, 2, 0) # blank white background.tile(2, 3, 0) # blank white background.tile(3, 3, 5) background.tile(4, 3, 6) background.tile(5, 3, 7) background.tile(6, 3, 8) background.tile(7, 3, 0) # blank white background.tile(2, 4, 0) # blank white background.tile(3, 4, 9) background.tile(4, 4, 10) background.tile(5, 4, 11) background.tile(6, 4, 12) background.tile(7, 4, 0) # blank white background.tile(2, 5, 0) # blank white background.tile(3, 5, 0) background.tile(4, 5, 13) background.tile(5, 5, 14) background.tile(6, 5, 0) background.tile(7, 5, 0) # blank white # creates stage and sets it to 60fps game = stage.Stage(ugame.display, constants.FPS) # sets the layers of all sprites, in order game.layers = [background] # renders all sprites, only once game.render_block() while True: time.sleep(2.0) menu_scene()
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
def game_over_scene(final_score): # this function is the game over scene # image bank for CircuitPython image_bank_2 = stage.Bank.from_bmp16("space_aliens.bmp") # sets the background to image 0 in the image Bank background = stage.Grid(image_bank_2, constants.SCREEN_GRID_X, constants.SCREEN_GRID_Y) # add text objects text = [] text1 = stage.Text(width=29, height=14, font=None, palette=constants.BLUE_PALETTE, buffer=None) text1.move(22, 20) text1.text("Final Score: {:0>2d}".format(final_score)) text.append(text1) text2 = stage.Text(width=29, height=14, font=None, palette=constants.BLUE_PALETTE, buffer=None) text2.move(43, 60) text2.text("GAME OVER") text.append(text2) text3 = stage.Text(width=29, height=14, font=None, palette=constants.BLUE_PALETTE, buffer=None) text3.move(32, 110) text3.text("PRESS SELECT") text.append(text3) # 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 will show up in order game.layers = text + [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() # Start button selected if keys & ugame.K_SELECT != 0: supervisor.reload() # update game logic game.tick() # wait until refresh rate finishes
def mt_splash_scene(): # this function is the MT splash scene # an image bank for CircuitPython image_bank_2 = stage.Bank.from_bmp16("mt_game_studio.bmp") # sets the background to image 0 in the bank background = stage.Grid(image_bank_2, constants.SCREEN_GRID_X, constants.SCREEN_GRID_Y) # used this program to split the iamge into tile: https://ezgif.com/sprite-cutter/ezgif-5-818cdbcc3f66.png background.tile(2, 2, 0) # blank white background.tile(3, 2, 1) background.tile(4, 2, 2) background.tile(5, 2, 3) background.tile(6, 2, 4) background.tile(7, 2, 0) # blank white background.tile(2, 3, 0) # blank white background.tile(3, 3, 5) background.tile(4, 3, 6) background.tile(5, 3, 7) background.tile(6, 3, 8) background.tile(7, 3, 0) # blank white background.tile(2, 4, 0) # blank white background.tile(3, 4, 9) background.tile(4, 4, 10) background.tile(5, 4, 11) background.tile(6, 4, 12) background.tile(7, 4, 0) # blank white background.tile(2, 5, 0) # blank white background.tile(3, 5, 0) background.tile(4, 5, 13) background.tile(5, 5, 14) background.tile(6, 5, 0) background.tile(7, 5, 0) # blank white text = [] text1 = stage.Text(width=29, height=14, font=None, palette=constants.MT_GAME_STUDIO_PALETTE, buffer=None) text1.move(20, 10) text1.text("MT Game Studios") text.append(text1) # get sound ready # follow this guide to convert your other sounds to something that will work # https://learn.adafruit.com/microcontroller-compatible-audio-file-conversion coin_sound = open("coin.wav", 'rb') sound = ugame.audio sound.stop() sound.mute(False) sound.play(coin_sound) # 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 = text + [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 # update game logic # Wait for 1/2 seconds time.sleep(1.0) game_splash_scene()
def game_splash_scene(): # this function is the game scene text = [] sprites = [] image_bank_3 = stage.Bank.from_bmp16("jungle_joe.bmp") image_bank_4 = stage.Bank.from_bmp16("elemental_studios.bmp") # sets the background to image 0 in the bank background = stage.Grid(image_bank_3, constants.SCREEN_GRID_X, constants.SCREEN_GRID_Y) text_1 = stage.Text(width=29, height=14, font=None, palette=constants.SCORE_PALETTE, buffer=None) text_1.move(13, 60) text_1.text("ELEMENTAL STUDIOS") text.append(text_1) fire_upper_right = stage.Sprite(image_bank_4, 0, 16, 0) sprites.append(fire_upper_right) fire_bottom_right = stage.Sprite(image_bank_4, 1, 16, 16) sprites.append(fire_bottom_right) fire_upper_left = stage.Sprite(image_bank_4, 2, 0, 0) sprites.append(fire_upper_left) fire_bottom_left = stage.Sprite(image_bank_4, 3, 0, 16) sprites.append(fire_bottom_left) water_upper_right = stage.Sprite(image_bank_4, 6, 144, 0) sprites.append(water_upper_right) water_bottom_right = stage.Sprite(image_bank_4, 7, 144, 16) sprites.append(water_bottom_right) water_upper_left = stage.Sprite(image_bank_4, 4, 128, 0) sprites.append(water_upper_left) water_bottom_left = stage.Sprite(image_bank_4, 5, 128, 16) sprites.append(water_bottom_left) earth_upper_right = stage.Sprite(image_bank_4, 10, 16, 98) sprites.append(earth_upper_right) earth_bottom_right = stage.Sprite(image_bank_4, 11, 16, 112) sprites.append(earth_bottom_right) earth_upper_left = stage.Sprite(image_bank_4, 8, 0, 98) sprites.append(earth_upper_left) earth_bottom_left = stage.Sprite(image_bank_4, 9, 0, 112) sprites.append(earth_bottom_left) wind_upper_right = stage.Sprite(image_bank_4, 14, 144, 98) sprites.append(wind_upper_right) wind_bottom_right = stage.Sprite(image_bank_4, 15, 144, 112) sprites.append(wind_bottom_right) wind_upper_left = stage.Sprite(image_bank_4, 12, 128, 98) sprites.append(wind_upper_left) wind_bottom_left = stage.Sprite(image_bank_4, 13, 128, 112) sprites.append(wind_bottom_left) game = stage.Stage(ugame.display, 60) # set the layers, items show up in order game.layers = sprites + text + [background] # render the background and inital location of sprite list # most likely you will only render background once per scene # wait until refresh rate finishes game.render_block() # repeat forever, game loop while True: # get user input # update game logic time.sleep(1.0) main_menu_scene() # redraw sprite list pass # just a placeholder until you write the code
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()
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()
def game_over_scene(final_score): # this function is the game over scene # an image bank for CircuitPython image_bank_2 = stage.Bank.from_bmp16("sprites.bmp") # sets the background to image 0 in the bank background = stage.Grid(image_bank_2, constants.SCREEN_GRID_X, constants.SCREEN_GRID_Y) text = [] text1 = stage.Text(width=29, height=14, font=None, palette=constants.MT_GAME_STUDIO_PALETTE, buffer=None) text1.move(22, 20) text1.text("Final Score: {:0>2d}".format(final_score)) text.append(text1) text2 = stage.Text(width=29, height=14, font=None, palette=constants.MT_GAME_STUDIO_PALETTE, buffer=None) text2.move(43, 60) text2.text("GAME OVER") text.append(text2) text3 = stage.Text(width=29, height=14, font=None, palette=constants.MT_GAME_STUDIO_PALETTE, buffer=None) text3.move(32, 110) text3.text("PRESS SELECT") text.append(text3) # 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 = text + [background] # render the background # most likely you will only render background once per scene game.render_block() # Game loop while True: # Update game logic keys = ugame.buttons.get_pressed() if keys & ugame.K_SELECT != 0: keys = 0 main_menu_scene()
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
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