def main(): """ Main function for photocopier, this is where it starts. """ # Toggle: 1 -> Register # Toggle: 0 -> Login scr = screen.Screen() menu1 = menu.menu_screen( scr, "Start", ["", "Welcome to the Boring Company photocopier", ""]) # Login menu1.add_menu("Login", account.register_or_login, False, screen=scr, toggle=True) # Register menu1.add_menu("Register", account.register_or_login, False, screen=scr, toggle=False) # Shutdown menu1.add_menu("Shutdown", shutdown, False, screen=scr) menu1.print_menu() ret, info = menu1.select_menu() if not ret: account.fix_file() Home.home(info[0], info[1], info[2], info[3]) else: return
def Settings(kwargs): screen = kwargs["screen"] photocopier = kwargs["photocopier"] users = kwargs["users"] username = kwargs["username"] screen.clear_screen() home_menu = menu.menu_screen( screen, "Home", ["Ink " + str(photocopier["Ink"]), "Settings", username]) # Add Ink home_menu.add_menu("Add Ink", add_ink, False, screen=screen, photocopier=photocopier, user=users[username]) # Show Logs home_menu.add_menu("Show Logs", show_logs, False, screen=screen, photocopier=photocopier, user=users[username]) # Exit home_menu.add_menu("Exit", Exit_Photocopier, None) while True: ret, info = home_menu.select_menu() if ret: account.update_file(users, photocopier) break else: screen = info[0] photocopier = info[1] users[username] = info[2] home_menu.information[0] = "Ink " + str(photocopier["Ink"]) account.update_file(users, photocopier) return True, None
def run_game(): # function to run the game """game play interface""" screen = pygame.display.set_mode( (800, 600)) # set the height and width of the screen display.set_caption("Jet mission") # set the title of the game scores = 0 # set the score start from 0 theClock = pygame.time.Clock() # object to track time bg_image = Star_bg( "star.gif") # insert the star.gif image for the background #coordinate of moving background x = 0 # set the coordinate x start from 0 y = 0 # set the coordinate y start from 0 x1 = bg_image.width # x1 is equal to background width y1 = 0 # y1 is equal to 0 pygame.init() # initialize pygame #creating a jet : jet1 = Jet(screen) # make an object called jet1 from Jet class Jet_sprites = Group(jet1) #create asteroid object group asteroid_group = Group() #create bullets object Group bullets = Group() Fps = 40 # set fps to 40 asteroid_timer = pygame.time.get_ticks() # get time for the asteroid_timer while True: # if the condition is True loop it theClock.tick(Fps) Fps += 0.01 # game phase goes faster after every frame """background move""" x -= 5 # for moving the background backward x1 -= 5 # for moving the background backward bg_image.draw( screen, x, y) # show the background image according to x,y coordinate bg_image.draw( screen, x1, y1) # show the background image according to x1,y1 coordinate if x < -bg_image.width: # if x is less than minus background width, run the code x = 0 if x1 < 0: # if x1 is less than 0, run the code x1 = bg_image.width # create score board font = pygame.font.SysFont("Times New Romans", 36) # set the font and the font size score_board = font.render( "score:" + str(scores), True, (255, 255, 255)) # update the score , set color to white # update refered to the word's method screen.blit(score_board, (10, 550)) # draw the socre board in game Jet_sprites.draw(screen) # draw the jet in game bullets.draw(screen) # draw the bullet asteroid_group.draw(screen) # draw the asteroid display.update() # update jet and screen view event.get() # get the event """moving the jet according to key pressed""" key = pygame.key.get_pressed( ) # make a variable for pygame.key.get_pressed if key[K_LEFT] and jet1.rect.x > 0: # if key left and jet1.rect x is greater than 0, run the code jet1.moveleft() # move the jet to left if key[K_RIGHT] and jet1.rect.x <= 700: # if key right and jet1.rect.x is less than 700, run the code jet1.moveright() # move the jet to right if key[K_DOWN] and jet1.rect.y <= 500: # if key down and jet1.rect.y is less than 500, run the code jet1.movedown() # move it down if key[K_UP] and jet1.rect.y > 0: # if key up and jet1.rect.y is greater than 0, run the code jet1.moveup() # move it up if key[K_SPACE] and len(bullets) <= jet1.firerates + (scores / 4000): bullet = Bullet( screen, jet1.rect.x + 50, jet1.rect.y + 42) # to set the bullet position based on jet position bullets.add(bullet) # add bullets pygame.mixer.music.load( "LaserBlast.wav") # set the sound when you shoot the bullet pygame.mixer.music.play( ) # play the sound when you shoot the bullet if key[K_ESCAPE]: # if space is pressed, run the code menu.menu_screen(Button, run_game) # end the game if key[K_p]: # if p is pressedn, run the code menu.pause_menu(Button, run_game) # paused the game """generate asteroid randomly""" if pygame.time.get_ticks() - asteroid_timer >= 200: asteroid = Asteroid(screen, 50, 50, random.randint(1, 4) * 6, 800, (random.randint(1, 28) * 20)) # spawn the asteroid randomly asteroid_group.add(asteroid) # add asteroid asteroid_timer = pygame.time.get_ticks( ) # set time to spawn the asteroid """update the movement of asteroid""" for asteroid in asteroid_group: asteroid.movement() if asteroid.rect.right <= 0: # if asteroid.rect.right is equal or less than 0, run the code asteroid_group.remove(asteroid) # remove after screen if groupcollide(Jet_sprites, asteroid_group, dokilla=True, dokillb=True): # condition check menu.lose_menu(Button, run_game, scores) """update bullet movement on screen""" for bullet in bullets: bullet.movement() if bullet.rect.left > 800: # if bullet.rect.left is greater than 800 bullets.remove(bullet) # remove the bullet from the screen if groupcollide(bullets, asteroid_group, dokilla=True, dokillb=True): # if the bullet hit the asteroid scores += 100 # add score 100
asteroid_group.add(asteroid) # add asteroid asteroid_timer = pygame.time.get_ticks( ) # set time to spawn the asteroid """update the movement of asteroid""" for asteroid in asteroid_group: asteroid.movement() if asteroid.rect.right <= 0: # if asteroid.rect.right is equal or less than 0, run the code asteroid_group.remove(asteroid) # remove after screen if groupcollide(Jet_sprites, asteroid_group, dokilla=True, dokillb=True): # condition check menu.lose_menu(Button, run_game, scores) """update bullet movement on screen""" for bullet in bullets: bullet.movement() if bullet.rect.left > 800: # if bullet.rect.left is greater than 800 bullets.remove(bullet) # remove the bullet from the screen if groupcollide(bullets, asteroid_group, dokilla=True, dokillb=True): # if the bullet hit the asteroid scores += 100 # add score 100 menu.menu_screen(Button, run_game) # call the function #---------------SPECIAL THANKS to Pier,Excel,georgius,William,Nicander,Nicolas,Andy,Guntur,Adrian----------------------- """Acknowledgement: LaserBlast.wav(shooting sound) http://soundbible.com/472-Laser-Blasts.html """
if key[K_p]: menu.pause_menu(Button,run_game) """generate asteroid randomly""" if pygame.time.get_ticks() - asteroid_timer >= 200: asteroid = Asteroid(screen, 50, 50, random.randint(1,4)*6, 800, (random.randint(1,28) * 20)) asteroid_group.add(asteroid) asteroid_timer = pygame.time.get_ticks() """update the movement of asteroid""" for asteroid in asteroid_group: asteroid.movement() if asteroid.rect.right <= 0: asteroid_group.remove(asteroid) #remove after screen if groupcollide(Jet_sprites,asteroid_group,dokilla=True,dokillb=True):#collition check menu.lose_menu(Button,run_game,scores) """update bullet movement on screen""" for bullet in bullets: bullet.movement() if bullet.rect.left > 800: bullets.remove(bullet) if groupcollide(bullets,asteroid_group,dokilla=True,dokillb=True): scores += 100 pygame.mixer.music.load('oof.mp3') pygame.mixer.music.play(0) # run game menu.menu_screen(Button,run_game)
def run_game(): #define the run_game #game play interface screen = pygame.display.set_mode( (800, 600)) #this is for the screen width and height display.set_caption("SPACE COW") #set the title for the gam scores = 0 #set the current score when you start the game which is Zero theClock = pygame.time.Clock() #create an object to help track time bg_image = Star_bg("star.gif") #to call the star picture into the game x = 0 y = 0 x1 = bg_image.width y1 = 0 #make the coordinate of moving background pygame.init() #initialize all imported pygame modules cow1 = Cow(screen) Cow_sprites = Group(cow1) #creating a jet asteroid_group = Group() #create asteroid object group bullets = Group() #create bullets object Group Fps = 120 asteroid_timer = pygame.time.get_ticks( ) #get the time in milliseconds for the asteroid_timer while True: #make a while loop theClock.tick( Fps ) #sets up how fast game should run or how often while loop should update itself, run through itself. Fps += 0.01 #game phase goes faster after every frame x -= 5 x1 -= 5 bg_image.draw(screen, x, y) bg_image.draw(screen, x1, y1) if x < -bg_image.width: x = 0 if x1 < 0: #spawn the asteroid from the right x1 = bg_image.width font = pygame.font.SysFont("", 36) #input the score in 36fontsize score_board = font.render( "score:" + str(scores), True, (255, 255, 255) ) #to input the score inside the game in white color and add "score:" before it screen.blit(score_board, (10, 550)) # update refered to the word's method Cow_sprites.draw(screen) #put the space cow inside the screen game bullets.draw(screen) #put the bullets inside the screen game asteroid_group.draw(screen) #put the asteroid inside the screen game display.update() #update cow and screen view event.get() #summon and get the event from other file #moving the cow according to key pressed key = pygame.key.get_pressed( ) #make key variable for what hotkey we will press while playing the game if key[K_LEFT] and cow1.rect.x > 0: #if you press left key, and the cow is not over the left screen which is x = 0 in the screen width, the cow will move to the left cow1.moveleft() if key[K_RIGHT] and cow1.rect.x <= 550: #if you press right key, and the cow is not over the right screen which is x = 700 in the screen width because the half of the cow picture is 100 width, cow1.moveright() # then the cow will move to the right if key[K_DOWN] and cow1.rect.y <= 450: #if you press down key, and the cow is not over the bottom screen which is y=500, the cow will move down cow1.movedown() if key[K_UP] and cow1.rect.y > 0: #if you press up key, and the cow is no over the top screen which is y = 0, the cow will move up cow1.moveup() if key[K_SPACE] and len(bullets) <= cow1.firerates + ( scores / 4000 ): #if you press space and total of the bullet in game game is not bigger than the cow firerate + score/4000 bullet = Bullet( screen, cow1.rect.x + 150, cow1.rect.y + 42) #set the bullet spawn place when you press space bullets.add(bullet) #add the bullet spawn place to the bullets pygame.mixer.music.load( "LaserBlast.wav" ) #to add the sound everytime you shot the bullet pygame.mixer.music.play() #to play the sound if key[K_ESCAPE]: #if you press escape key, it will go to main menu screen and call the Button class and run_game so you can run the game again menu.menu_screen(Button, run_game) if key[K_p]: #if you press p key, it will go to pause menu screen and call the Button class and run_game so you can run the game again menu.pause_menu(Button, run_game) #generate asteroid randomly if pygame.time.get_ticks( ) - asteroid_timer >= 200: #if the millisecond time - the asteroid timer is bigger or equal to 200 asteroid = Asteroid( screen, 50, 50, random.randint(1, 4) * 6, 800, (random.randint(1, 28) * 20) ) #make variable asteroid and set the spawn place which is random by using random.randint asteroid_group.add( asteroid) #add the variable asteroid to the asteroid_group asteroid_timer = pygame.time.get_ticks( ) #get the time in milliseconds for the asteroid_timer #update the movement of asteroid for asteroid in asteroid_group: #make asteroid loop in the asteroid_group asteroid.movement() #movement for the asteroid if asteroid.rect.right <= 0: #if the asteroid goes beyond the left screen asteroid_group.remove(asteroid) #the asteroid will be removed if groupcollide(Cow_sprites, asteroid_group, dokilla=True, dokillb=True): #collition check menu.lose_menu( Button, run_game, scores ) #if the asteroid touch your space cow, the game will go to the lose menu and call Button class, run_game to play again, and scores to reveal your score #update bullet movement on screen for bullet in bullets: #make bullet loop in the bullets(variable from classes file) bullet.movement() #movement for the bullet if bullet.rect.left > 800: #if the bullet goes beyond the right screen, the bullet will be removed bullets.remove(bullet) if groupcollide(bullets, asteroid_group, dokilla=True, dokillb=True): #collition check scores += 100 #if the bullet touch the asteroid, your score will be up by 100
) #get the time in milliseconds for the asteroid_timer #update the movement of asteroid for asteroid in asteroid_group: #make asteroid loop in the asteroid_group asteroid.movement() #movement for the asteroid if asteroid.rect.right <= 0: #if the asteroid goes beyond the left screen asteroid_group.remove(asteroid) #the asteroid will be removed if groupcollide(Cow_sprites, asteroid_group, dokilla=True, dokillb=True): #collition check menu.lose_menu( Button, run_game, scores ) #if the asteroid touch your space cow, the game will go to the lose menu and call Button class, run_game to play again, and scores to reveal your score #update bullet movement on screen for bullet in bullets: #make bullet loop in the bullets(variable from classes file) bullet.movement() #movement for the bullet if bullet.rect.left > 800: #if the bullet goes beyond the right screen, the bullet will be removed bullets.remove(bullet) if groupcollide(bullets, asteroid_group, dokilla=True, dokillb=True): #collition check scores += 100 #if the bullet touch the asteroid, your score will be up by 100 menu.menu_screen( Button, run_game ) #to run the game , go to main menu first so we call the Button class and run_game to play the game
def rungame(): #Gameplay screen resolution and caption title screen = pygame.display.set_mode((800, 600)) display.set_caption("Jet mission") #starting scores and background image scores = 0 theClock = pygame.time.Clock() bg_image = Star_bg("star.gif") #The starting coordinate of the moving background x = 0 y = 0 x1 = bg_image.width y1 = 0 #initiate pygame pygame.init() #Creating the jet jet1 = Jet(screen) Jet_sprites = Group(jet1) #Create group for the moving asteroid asteroid_group = Group() #Create group for shooting bullets bullets = Group() #Initial Fps and that it will be faster after every frame Fps = 40 asteroid_timer = pygame.time.get_ticks() while True: theClock.tick(Fps) Fps += 0.01 #Moving background x -= 5 x1 -= 5 bg_image.draw(screen,x,y) bg_image.draw(screen,x1, y1) if x < -bg_image.width: x = 0 if x1 < 0: x1 = bg_image.width #Making The score board with Font style and size font=pygame.font.SysFont("Times New Romans",36) score_board=font.render("score:"+str(scores),True,(255,255,255)) screen.blit(score_board,(10,550)) #Draws the jet Jet_sprites.draw(screen) #Draws the bullets bullets.draw(screen) #Draws the moving asteroid asteroid_group.draw(screen) #update jet when the game is run display.update() event.get() #Controls to move the jet and fire bullets key = pygame.key.get_pressed() if key[K_LEFT] and jet1.rect.x>0: jet1.moveleft() if key[K_RIGHT] and jet1.rect.x<=700: jet1.moveright() if key[K_DOWN] and jet1.rect.y<=500: jet1.movedown() if key[K_UP] and jet1.rect.y>0: jet1.moveup() if key[K_SPACE] and len(bullets) <= jet1.firerates+(scores/4000): bullet = Bullet(screen, jet1.rect.x+50, jet1.rect.y+42) bullets.add(bullet) pygame.mixer.music.load("LaserBlast.wav") pygame.mixer.music.play() if key[K_ESCAPE]: menu.menu_screen(Button,rungame) if key[K_p]: menu.pause_menu(Button,rungame) #Creating the asteroid randomly on the screen and moves if pygame.time.get_ticks() - asteroid_timer >= 200: asteroid = Asteroid(screen, 50, 50, random.randint(1,4)*6, 800, (random.randint(1,28) * 20)) asteroid_group.add(asteroid) asteroid_timer = pygame.time.get_ticks() #Updating the movement of the asteroids for asteroid in asteroid_group: asteroid.movement() if asteroid.rect.right <= 0: asteroid_group.remove(asteroid) #remove after screen if groupcollide(Jet_sprites,asteroid_group,dokilla=True,dokillb=True):#collition check menu.lose_menu(Button,rungame,scores) #Updating the bullets on screen for bullet in bullets: bullet.movement() if bullet.rect.left > 800: bullets.remove(bullet) if groupcollide(bullets,asteroid_group,dokilla=True,dokillb=True): scores += 100
"""update the movement of asteroid""" for asteroid in asteroid_group: #looping asteroid in the asteroid_group asteroid.movement() #thw movement of the asteroid if asteroid.rect.right <= 0: #the asteroid disappear when arrive the left screen asteroid_group.remove(asteroid) #remove after screen if groupcollide(Jet_sprites, asteroid_group, dokilla=True, dokillb=True): #collition check menu.lose_menu( Button, run_game, scores ) #when the asteroid touch the jet the game will end and show the lose menu and shoing the score that you get """update bullet movement on screen""" for bullet in bullets: #looping the bullet in bullets bullet.movement() if bullet.rect.left > 800: #the bullet will disappear if the bullet reach the right side of the screen bullets.remove(bullet) if groupcollide(bullets, asteroid_group, dokilla=True, dokillb=True): scores += 100 #when everytime the bullet touch the asteroid, the score will increase 100 menu.menu_screen(Button, run_game) #call to run the game #---------------SPECIAL THANKS to Pier,Excel,georgius,William,Nicander,Nicolas,Andy,Guntur,Adrian----------------------- """Acknowledgement: LaserBlast.wav(shooting sound) http://soundbible.com/472-Laser-Blasts.html """
def run_game(): """game play interface""" screen = pygame.display.set_mode( (800, 600)) #the widht of the display for the game display.set_caption("Jet mission") #set the title of the game scores = 0 #the score starts from 0 theClock = pygame.time.Clock() bg_image = Star_bg("star.gif") #call the star image into the game #coordinate of moving background x = 0 y = 0 x1 = bg_image.width y1 = 0 pygame.init() #initialize pygame #creating a jet jet1 = Jet(screen) Jet_sprites = Group(jet1) #create asteroid object group asteroid_group = Group() #create bullets object Group bullets = Group() Fps = 60 asteroid_timer = pygame.time.get_ticks() while True: theClock.tick(Fps) Fps += 0.01 #game phase goes faster after every frame """background move""" x -= 5 x1 -= 5 bg_image.draw(screen, x, y) bg_image.draw(screen, x1, y1) #spawn the asteroids if x < -bg_image.width: x = 0 if x1 < 0: x1 = bg_image.width # create score board font = pygame.font.SysFont("Times New Romans", 36) score_board = font.render("score:" + str(scores), True, (255, 255, 255)) # update refered to the word's method screen.blit(score_board, (10, 550)) Jet_sprites.draw(screen) #to make the jet in the screen bullets.draw(screen) #to make the bullets in the screen asteroid_group.draw(screen) #to make the asteroid in the screen display.update() #update jet and screen view event.get() """moving the jet according to key pressed""" key = pygame.key.get_pressed() if key[K_LEFT] and jet1.rect.x > 0: #moves the jet to the left, and if it is not over the screen jet1.moveleft() #moves the jet to the left if key[K_RIGHT] and jet1.rect.x <= 700: #moves the jet to the right, and if it is not over the right screen jet1.moveright() if key[K_DOWN] and jet1.rect.y <= 500: #moves the jet downwards, and if it is not over the screen jet1.movedown() if key[K_UP] and jet1.rect.y > 0: #moves the jet upwards, and if it is not over the screen jet1.moveup() if key[K_SPACE] and len(bullets) <= jet1.firerates + (scores / 4000): bullet = Bullet( screen, jet1.rect.x + 50, jet1.rect.y + 42) #set the bullets spawning place when space is pressed bullets.add(bullet) #add the bullets pygame.mixer.music.load( "LaserBlast.wav") #make a sound every time you shoot pygame.mixer.music.play() #play the sound if key[K_ESCAPE]: menu.menu_screen( Button, run_game ) #press escape to go back to the menu screen, and run the main menu to start the game again if wanted if key[K_p]: menu.pause_menu( Button, run_game) #press p to pause the game, and run the pause menu """generate asteroid randomly""" if pygame.time.get_ticks() - asteroid_timer >= 200: asteroid = Asteroid( screen, 50, 50, random.randint(1, 4) * 6, 800, (random.randint(1, 28) * 20)) #set the spawn place for the asteroid random asteroid_group.add( asteroid) #add the variable asteroid to asteroid group asteroid_timer = pygame.time.get_ticks() """update the movement of asteroid""" for asteroid in asteroid_group: asteroid.movement() #movement for asteroids if asteroid.rect.right <= 0: #if the asteroid moves to the left of the screen and didnt hit asteroid_group.remove(asteroid) #remove after screen if groupcollide(Jet_sprites, asteroid_group, dokilla=True, dokillb=True): #collition check menu.lose_menu( Button, run_game, scores ) #if the jet touches the asteroid, it goes to the lose menu and shows the score and ask if you want to play again """update bullet movement on screen""" for bullet in bullets: bullet.movement() #movements for bullets if bullet.rect.left > 800: #if the bullet goes further than the screen of the right, it is removed bullets.remove(bullet) #removes bullet if groupcollide(bullets, asteroid_group, dokilla=True, dokillb=True): scores += 100 #if the bullet touches the asteroid, the score will be up by 100
"""update the movement of asteroid""" for asteroid in asteroid_group: asteroid.movement() #movement for asteroids if asteroid.rect.right <= 0: #if the asteroid moves to the left of the screen and didnt hit asteroid_group.remove(asteroid) #remove after screen if groupcollide(Jet_sprites, asteroid_group, dokilla=True, dokillb=True): #collition check menu.lose_menu( Button, run_game, scores ) #if the jet touches the asteroid, it goes to the lose menu and shows the score and ask if you want to play again """update bullet movement on screen""" for bullet in bullets: bullet.movement() #movements for bullets if bullet.rect.left > 800: #if the bullet goes further than the screen of the right, it is removed bullets.remove(bullet) #removes bullet if groupcollide(bullets, asteroid_group, dokilla=True, dokillb=True): scores += 100 #if the bullet touches the asteroid, the score will be up by 100 menu.menu_screen(Button, run_game) #TO RUN THE GAME #---------------SPECIAL THANKS to Pier,Excel,georgius,William,Nicander,Nicolas,Andy,Guntur,Adrian----------------------- """Acknowledgement: LaserBlast.wav(shooting sound) http://soundbible.com/472-Laser-Blasts.html """
def main_loop(): pygame.init() pygame.display.set_caption('Ground ctrl') # Create clock and time for event handling clock_tick = pygame.USEREVENT + 1 pygame.time.set_timer(clock_tick, 20) # Instantiate the Players player = Player(menu.menu_screen(screen)) # Instantiate the levels level_1_map = mp.build_obj_map_tutorial() level_2_map = mp.build_obj_map_level_2() level_3_map = mp.build_obj_map_level_3() level_4_map = mp.build_obj_map_level_5() level_01 = Level(number=1, Player=player, level_map=level_1_map, level_limit=mp.limit, background=os.path.join('images', 'stars.png')) level_02 = Level(number=2, Player=player, level_map=level_2_map, level_limit=mp.limit, background=os.path.join('images', 'stars.png')) level_03 = Level(number=3, Player=player, level_map=level_3_map, level_limit=mp.limit, background=os.path.join('images', 'stars.png')) level_04 = Level(number=4, Player=player, level_map=level_4_map, level_limit=mp.limit, background=os.path.join('images', 'stars.png')) # Set up the end level end_level = Level(number="END", Player=player, level_map=[], level_limit=-4000, background='images/ejiri.jpg') end_level.vx = 0 end_level.shift_x = 0 # blit(source, dest, area=None, special_flags=0) ms_text = pygame.font.Font('1.ttf', 60).render("MISSION SUCCESS", True, (0, 0, 0)) menu_text = pygame.font.Font('1.ttf', 30).render("Press ENTER to return to MENU", True, (0, 0, 0)) end_level.background.blit( ms_text, (screen.get_width() // 4, screen.get_height() // 2 - 60)) end_level.background.blit( menu_text, (screen.get_width() // 4, screen.get_height() // 2)) #level_01, level_02, level_03, level_list = [level_01, level_02, level_03, level_04, end_level] current_level = get_current_level(level_list) player.level = current_level active_sprite_list = pygame.sprite.Group() active_sprite_list.add(player) clock = pygame.time.Clock() pygame.display.flip() # Begins playing background music pygame.mixer.music.load( os.path.join(os.getcwd(), 'images', '8-bit-win.mp3')) pygame.mixer.music.set_volume(0.2) pygame.mixer.music.play(loops=-1) run = True while run: for event in pygame.event.get(): if event.type == pygame.QUIT: run = False pass if event.type == pygame.KEYDOWN: if event.key == pygame.K_LEFT: player.move_left() if event.key == pygame.K_RIGHT: player.move_right() if event.key == pygame.K_UP: player.jump(5.6) if event.key == pygame.K_RETURN: if current_level.number == "END": menu.menu_screen(screen) else: menu.pause_screen(screen) if event.type == clock_tick: #if clockTick event is met then call an update method for ob's player.handle_glue() blit_text(text="Score:" + str(player.score), size=20, x_c=int(MAP_UNIT_X), y_c=int(MAP_UNIT_Y)) current_level.ob_update() if event.type == pygame.KEYUP: if (event.key == pygame.K_LEFT and player.vx < 0) or ( event.key == pygame.K_RIGHT and player.vx > 0): # and player.vx < 0 and player.vx > 0 #if (event.key == pygame.K_LEFT and player.vy <0) or (event.key == pygame.K_RIGHT and player.vx > 0):# and player.vx < 0 and player.vx > 0 player.stop() if player.rect.right <= 0: # if the player goes off the edge of the screen player.die() # If the player gets to the end of the level, go to the next level current_position = current_level.world_shift - player.rect.x if current_level.is_complete(current_position): current_level.end_animation(clock) player.end_level() current_level = get_current_level(level_list) player.level = current_level else: current_level.shift_world() # Make this not run for the end level current_level.draw(screen) active_sprite_list.update() active_sprite_list.draw(screen) clock.tick(40) pygame.display.flip()
def run_game(): # function for running the game """game play interface""" screen = pygame.display.set_mode( (1000, 1000)) # the code for running the game display.set_caption("Jet mission") # setting the title for the game scores = 0 # set the original score to 0 theClock = pygame.time.Clock() # create an object to track time bg_image = Star_bg( "star.gif") # To the star picture to be the background in the game #coordinate of moving background x = 0 # coordinate start from x = 0 y = 0 # coordinate start from y = 0 x1 = bg_image.width y1 = 0 pygame.init() # Initialize the pygame modules #creating a jet jet1 = Jet(screen) #Creating the object jet1 from the class Jet Jet_sprites = Group(jet1) #creating the group #create asteroid object group asteroid_group = Group() #create bullets object Group bullets = Group() Fps = 200 # for setting the fps of the game asteroid_timer = pygame.time.get_ticks( ) # get the time for the asteroid_timer while True: # while the condition is true (Looping) theClock.tick( Fps) # set ups how often the while loop should update each self Fps += 0.01 #game phase goes faster after every frame """background move""" x -= 5 x1 -= 5 bg_image.draw(screen, x, y) bg_image.draw(screen, x1, y1) if x < -bg_image.width: x = 0 if x1 < 0: # this will make spawn the asteroids from the right x1 = bg_image.width # create score board font = pygame.font.SysFont( "Times New Romans", 36) # create an object for input the score in 36 fontsize score_board = font.render( "score:" + str(scores), True, (255, 255, 255)) # Object for the score to update itself in white color # update refered to the word's method screen.blit(score_board, (10, 550)) Jet_sprites.draw(screen) # put the jest inside the screen game bullets.draw(screen) # put the bullets inside the screen game asteroid_group.draw( screen) # put the group of asteroids in the screen game display.update() #update jet and screen view event.get() """moving the jet according to key pressed""" key = pygame.key.get_pressed( ) # Make an object for inputing the hotkey we press when we play the game if key[K_LEFT] and jet1.rect.x > 0: # if you press the left key and the jet is not in the most left screen jet1.moveleft() # then you can press left if key[K_RIGHT] and jet1.rect.x <= 700: # If you press right key before it reaches the most right screen jet1.moveright() # then you can press right if key[K_DOWN] and jet1.rect.y <= 500: # if you press down key before it reaches the most bottom of the screen jet1.movedown() # then you can press down if key[K_UP] and jet1.rect.y > 0: #if you press up before it reaches the upper screen jet1.moveup() # then you can press up if key[K_SPACE] and len(bullets) <= jet1.firerates + ( scores / 4000 ): # if you press space and the length of bullets fired will not be greater than the fire rate of the jet and score + 4000 bullet = Bullet(screen, jet1.rect.x + 50, jet1.rect.y + 42) # object bullet and set the bullet spawn place bullets.add(bullet) # add the bullet spawn place to the bullets pygame.mixer.music.load( "LaserBlast.wav") #add sound evertime you shoot the bullet pygame.mixer.music.play() # play the sound effect if key[K_ESCAPE]: # if I press the escape key menu.menu_screen( Button, run_game ) # it will go the main menu screen and call the button class and run_game function so you can play the game again. if key[K_p]: # if I press the p key menu.pause_menu(Button, run_game) #iy will pause the game """generate asteroid randomly""" #if the asteroid timer is bigger or equal to 200 if pygame.time.get_ticks() - asteroid_timer >= 200: asteroid = Asteroid( screen, 50, 50, random.randint(1, 4) * 6, 800, (random.randint(1, 28) * 20) ) # make object asteroid and set the spawn place which is random by using the mothod random.randint asteroid_group.add(asteroid) #add asteroids to the group asteroid_timer = pygame.time.get_ticks( ) # get the time in the asteroid timer """update the movement of asteroid""" for asteroid in asteroid_group: # for looping in the condition the asteroid is in the asteroid group asteroid.movement() # movement if asteroid.rect.right <= 0: # if the asteroid goes beyond the left screen asteroid_group.remove(asteroid) #remove after screen if groupcollide(Jet_sprites, asteroid_group, dokilla=True, dokillb=True): #collition check menu.lose_menu( Button, run_game, scores ) #if the asteroid touches the jet, the game will go to the lose menu and it will call the Buton class, run_game function so you can either restart or quit the game """update bullet movement on screen""" for bullet in bullets: # for looping for bullet from bullet class bullet.movement() # getting the movement for bullet if bullet.rect.left > 800: # if the bullet goes beyond the right screen, the bullet will be removed bullets.remove(bullet) if groupcollide( bullets, asteroid_group, dokilla=True, dokillb=True): # checking if the bullet hit the asteroids scores += 100 # the score will be up by 100
) # make object asteroid and set the spawn place which is random by using the mothod random.randint asteroid_group.add(asteroid) #add asteroids to the group asteroid_timer = pygame.time.get_ticks( ) # get the time in the asteroid timer """update the movement of asteroid""" for asteroid in asteroid_group: # for looping in the condition the asteroid is in the asteroid group asteroid.movement() # movement if asteroid.rect.right <= 0: # if the asteroid goes beyond the left screen asteroid_group.remove(asteroid) #remove after screen if groupcollide(Jet_sprites, asteroid_group, dokilla=True, dokillb=True): #collition check menu.lose_menu( Button, run_game, scores ) #if the asteroid touches the jet, the game will go to the lose menu and it will call the Buton class, run_game function so you can either restart or quit the game """update bullet movement on screen""" for bullet in bullets: # for looping for bullet from bullet class bullet.movement() # getting the movement for bullet if bullet.rect.left > 800: # if the bullet goes beyond the right screen, the bullet will be removed bullets.remove(bullet) if groupcollide( bullets, asteroid_group, dokilla=True, dokillb=True): # checking if the bullet hit the asteroids scores += 100 # the score will be up by 100 menu.menu_screen( Button, run_game ) # going to the menu screen which we call the Button class and the run_game function to run the game
def home(screen, users, username, photocopier): screen.clear_screen() home_menu = menu.menu_screen( screen, "Home", ["Credits: " + str(users[username]["Credits"]), "Home", username]) # Photocopy home_menu.add_menu("Photocopy", Photocopy_Print, False, screen=screen, photocopier=photocopier, user=users[username], toggle=0) # Add Credit home_menu.add_menu("Add Credit", Add_Credit, False, screen=screen, photocopier=photocopier, user=users[username]) # Print home_menu.add_menu("Print", Photocopy_Print, False, screen=screen, photocopier=photocopier, user=users[username], toggle=1) # Settings home_menu.add_menu("Settings", Settings, False, screen=screen, photocopier=photocopier, users=users, username=username) # Exit home_menu.add_menu("Exit", Exit_Photocopier, False, yes="yes") while True: ret, info = home_menu.select_menu() if ret: account.update_file(users, photocopier) break else: screen = info[0] photocopier = info[1] users[username] = info[2] home_menu.information[0] = "Credits: " + \ str(users[username]["Credits"]) account.update_file(users, photocopier) return False, None
def run_game( ): #to define run_game, so the code can be call when using "run_game" code """game play interface""" screen = pygame.display.set_mode( (800, 600)) #size of the game's window display pygame.display.set_caption("Jet mission") #to set the name of the game scores = 0 #to set the score on the game theClock = pygame.time.Clock() #to track the time bg_image = Star_bg("star.gif") #to put the background of the game #coordinate of moving background x = 0 y = 0 x1 = bg_image.width y1 = 0 pygame.init() #creating a jet jet1 = Jet(screen) Jet_sprites = Group(jet1) #create asteroid object group asteroid_group = Group() #create bullets object Group bullets = Group() Fps = 40 asteroid_timer = pygame.time.get_ticks( ) #to set the time for asteroid_timer while True: #loop so it can run it agian theClock.tick(Fps) #to sets the game's speed to run Fps += 0.01 #game phase goes faster after every frame """background move""" x -= 5 x1 -= 5 bg_image.draw(screen, x, y) bg_image.draw(screen, x1, y1) if x < -bg_image.width: x = 0 if x1 < 0: #spawning the asteroid x1 = bg_image.width # create score board font = pygame.font.SysFont("Times New Romans", 36) #the size and type of the font score_board = font.render( "score:" + str(scores), True, (255, 255, 255)) #to input the color for the "score" and "score:" # update refered to the word's method screen.blit(score_board, (10, 550)) #put where the score will show # Jet_sprites.draw(screen) #to input the jet to inside the game bullets.draw(screen) #to input the bullet to inside the game asteroid_group.draw(screen) #to input the asteroid to inside the game display.update() #update jet and screen view event.get() #to summon and get the event from others files """moving the jet according to key pressed""" key = pygame.key.get_pressed() #to make the key for playing the game if key[K_LEFT] and jet1.rect.x > 0: #make the jet go to the left side by pressing the left key and will not disappear when going to the over left jet1.moveleft() if key[K_RIGHT] and jet1.rect.x <= 700: #make the jet go to the right side by pressing the right key and will not disappear when going to the over right jet1.moveright() if key[K_DOWN] and jet1.rect.y <= 500: #make the jet go to the down side by pressing the down key and will not disappear when going to the over down jet1.movedown() if key[K_UP] and jet1.rect.y > 0: #make the jet go to the up side by pressing the up key and will not disappear when going to the over up jet1.moveup() if key[K_SPACE] and len(bullets) <= jet1.firerates + ( scores / 4000 ): #press space key to call the bullet and and the total of the bullets are not bigger than the jet1 firerate bullet = Bullet(screen, jet1.rect.x + 50, jet1.rect.y + 42) bullets.add(bullet) #to add the place for bullets spawn pygame.mixer.music.load( "LaserBlast.wav") #to make a sound everytime the bullet spawn pygame.mixer.music.play() #to run and play the sound if key[K_ESCAPE]: #to make the game back to the fist show which is the menu when pressing escape key menu.menu_screen(Button, run_game) if key[K_p]: #to stop the the game for a while by pressing p key menu.pause_menu(Button, run_game) """generate asteroid randomly""" if pygame.time.get_ticks( ) - asteroid_timer >= 200: #asteroid timer is bigger than 200 or equal with 200 asteroid = Asteroid(screen, 50, 50, random.randint(1, 4) * 6, 800, (random.randint(1, 28) * 20)) asteroid_group.add( asteroid) #add the asteroid to the asteroid group asteroid_timer = pygame.time.get_ticks( ) #get the time in pygame.time.get_ticks() for asteroid_timer """update the movement of asteroid""" for asteroid in asteroid_group: #looping asteroid in the asteroid_group asteroid.movement() #thw movement of the asteroid if asteroid.rect.right <= 0: #the asteroid disappear when arrive the left screen asteroid_group.remove(asteroid) #remove after screen if groupcollide(Jet_sprites, asteroid_group, dokilla=True, dokillb=True): #collition check menu.lose_menu( Button, run_game, scores ) #when the asteroid touch the jet the game will end and show the lose menu and shoing the score that you get """update bullet movement on screen""" for bullet in bullets: #looping the bullet in bullets bullet.movement() if bullet.rect.left > 800: #the bullet will disappear if the bullet reach the right side of the screen bullets.remove(bullet) if groupcollide(bullets, asteroid_group, dokilla=True, dokillb=True): scores += 100 #when everytime the bullet touch the asteroid, the score will increase 100
elif option == 3: RUNNING = False else: if option == 0: pass elif option == 1: if sound: pygame.mixer.music.pause() sound = False else: pygame.mixer.music.unpause() sound = True elif option == 2: pass click = False menu.menu_screen(sound, paused) pygame.display.flip() continue # Borders pygame.draw.rect(screen, purple, [ screen_distance, screen_distance, screen_width - screen_distance * 2, border_width ]) pygame.draw.rect(screen, purple, [ screen_distance, screen_distance, border_width, screen_height - screen_distance * 2 ]) pygame.draw.rect(screen, purple, [ screen_distance, screen_height - screen_distance - border_width, screen_width - screen_distance * 2, border_width
def run_game(): #if game is running do the this """game play interface""" screen = pygame.display.set_mode((800, 600)) #to set the scale display.set_caption("Jet mission") #to add the text Jet Mission scores = 0 #to set the scores 0 theClock = pygame.time.Clock() #to add time bg_image = Star_bg("star.gif") #to add an image #coordinate of moving background x = 0 y = 0 x1 = bg_image.width y1 = 0 pygame.init() #creating a jet jet1 = Jet(screen) Jet_sprites = Group(jet1) #create asteroid object group asteroid_group = Group() #create bullets object Group bullets = Group() Fps = 40 #to set the frame per second asteroid_timer = pygame.time.get_ticks() #to set the time ticking while True: #while condition true theClock.tick(Fps) #to set the fps of the clock Fps += 0.01 #game phase goes faster after every frame """background move""" x -= 5 #to make the background move to the left by 5 x1 -= 5 bg_image.draw(screen, x, y) #to set the background movement bg_image.draw(screen, x1, y1) if x < -bg_image.width: #to set the background x = 0 if x1 < 0: x1 = bg_image.width # create score board font = pygame.font.SysFont("Times New Romans", 36) #to set the font score_board = font.render("score:" + str(scores), True, (255, 255, 255)) #to set the scores # update refered to the word's method screen.blit(score_board, (10, 550)) #to set screen blit of the score board Jet_sprites.draw(screen) #to activate the jet bullets.draw(screen) #to acvtivate the bullets asteroid_group.draw(screen) #to activate the asteroid display.update() #update jet and screen view event.get() #to do the movement as the key pressed key = pygame.key.get_pressed() if key[K_LEFT] and jet1.rect.x > 0: jet1.moveleft() if key[K_RIGHT] and jet1.rect.x <= 700: jet1.moveright() if key[K_DOWN] and jet1.rect.y <= 500: jet1.movedown() if key[K_UP] and jet1.rect.y > 0: jet1.moveup() if key[K_SPACE] and len(bullets) <= jet1.firerates + ( scores / 4000 ): #to set space as shooting and add score if it hit the target bullet = Bullet(screen, jet1.rect.x + 50, jet1.rect.y + 42) #to set the bullet coordinate bullets.add(bullet) #to set the bullet pygame.mixer.music.load("LaserBlast.wav") #to set sound of bullet pygame.mixer.music.play() #to add soune if key[K_ESCAPE]: menu.menu_screen(Button, run_game) #to set esc as themenu screen if key[K_p]: menu.pause_menu(Button, run_game) #to set p as pause button if pygame.time.get_ticks( ) - asteroid_timer >= 200: #to add asteroid randomly as the time flows asteroid = Asteroid(screen, 50, 50, random.randint(1, 4) * 6, 800, (random.randint(1, 28) * 20)) asteroid_group.add(asteroid) asteroid_timer = pygame.time.get_ticks() for asteroid in asteroid_group: asteroid.movement() #to get the movement def if asteroid.rect.right <= 0: #to move the asteroid asteroid_group.remove(asteroid) #remove after screen if groupcollide(Jet_sprites, asteroid_group, dokilla=True, dokillb=True): #collition check menu.lose_menu(Button, run_game, scores) #if the asteroid hit then lose for bullet in bullets: bullet.movement() #to get bullet movement def if bullet.rect.left > 800: #if the bullet exceded the map than it gone bullets.remove(bullet) if groupcollide(bullets, asteroid_group, dokilla=True, dokillb=True): scores += 100 #if it hit then add 100 to point