def load(self): """ **Start loading** of all images and sounds added since last `Loader.load()` execution. * In standard Python with SimpleGUICS2Pygame: draw a progression bar on canvas and wait until the loading is finished. * In SimpleGUI of CodeSkulptor: *don't* wait. """ if Loader.__SIMPLEGUICS2PYGAME: from SimpleGUICS2Pygame.simpleguics2pygame import load_image, \ load_sound else: from simplegui import load_image, load_sound if Loader.__SIMPLEGUICS2PYGAME: handler_saved = self._frame._canvas._draw_handler self._frame._canvas._draw_handler = self._draw_loading for name in self._sounds: if Loader.__SIMPLEGUICS2PYGAME: self._frame._canvas._draw() if isinstance(self._sounds[name], str): self._sounds[name] = load_sound(self._sounds[name]) for name in self._images: if Loader.__SIMPLEGUICS2PYGAME: self._frame._canvas._draw() if isinstance(self._images[name], str): self._images[name] = load_image(self._images[name]) if Loader.__SIMPLEGUICS2PYGAME: self._frame._canvas._draw() self._frame._canvas._draw_handler = handler_saved
def load(self): # type: () -> None """ **Start loading** of all images and sounds added since last `Loader.load()` execution. * In standard Python with SimpleGUICS2Pygame: draw a progression bar on canvas and wait until the loading is finished. * In SimpleGUI of CodeSkulptor: *don't* wait. """ # noqa if Loader.__SIMPLEGUICS2PYGAME: from SimpleGUICS2Pygame.simpleguics2pygame import load_image, load_sound # pylint: disable=import-outside-toplevel # noqa else: from simplegui import load_image, load_sound # type: ignore # pytype: disable=import-error # pylint: disable=import-outside-toplevel,import-error # noqa if Loader.__SIMPLEGUICS2PYGAME: handler_saved = self._frame._canvas._draw_handler # pylint: disable=protected-access # noqa self._frame._canvas._draw_handler = self._draw_loading # pylint: disable=protected-access # noqa for name in self._sounds: if Loader.__SIMPLEGUICS2PYGAME: self._frame._canvas._draw() # pylint: disable=protected-access if isinstance(self._sounds[name], str): self._sounds[name] = load_sound(self._sounds[name]) for name in self._images: if Loader.__SIMPLEGUICS2PYGAME: self._frame._canvas._draw() # pylint: disable=protected-access if isinstance(self._images[name], str): self._images[name] = load_image(self._images[name]) if Loader.__SIMPLEGUICS2PYGAME: self._frame._canvas._draw() # pylint: disable=protected-access self._frame._canvas._draw_handler = handler_saved # pylint: disable=protected-access # noqa
# convert steps to index for platforms ind = height(steps) // 100 if ind < num_plat and pl[ind].exists: canvas.draw_line(camera([pl[ind].left, steps]), camera([pl[ind].right, steps]), 4, "Yellow") canvas.draw_text(str(height(steps)), camera([w - 50, steps]), 12, "White") # canvas.draw_line(camera([0,steps]),camera([w,steps]),1,"White") # initialize stuff w = 800 h = 600 frame = simplegui.create_frame("Doodle Jump", w, h) sound = simplegui.load_sound( "http://commondatastorage.googleapis.com/codeskulptor-assets/jump.ogg" ) #hamster republic # set handlers frame.set_keydown_handler(keydown) frame.set_keyup_handler(keyup) frame.set_draw_handler(draw) # create 1000 random platforms num_plat = 1000 pl = [platform() for i in range(0, num_plat)] # make first platform cover the whole bottom of the window so you don't die immediately pl[0].left = 0 pl[0].right = w
# initialize some useful global variables in_play = False outcome = "" message = "" score = 0 FRAME_WIDTH = 600 FRAME_HEIGHT = 600 # define globals for cards SUITS = ('C', 'S', 'H', 'D') RANKS = ('A', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K') VALUES = {'A':1, '2':2, '3':3, '4':4, '5':5, '6':6, '7':7, '8':8, '9':9, 'T':10, 'J':10, 'Q':10, 'K':10} # load some sound sound_5 = simplegui.load_sound("https://dl.dropboxusercontent.com/u/280794727/BlackJack/Short_triumphal.wav") background_sound = simplegui.load_sound("https://dl.dropboxusercontent.com/u/280794727/BlackJack/Frank_Sinatra_Snow.wav") # set the volume and play background_sound.set_volume(.2) background_sound.play() # define card class class Card: def __init__(self, suit, rank): if (suit in SUITS) and (rank in RANKS): self.suit = suit self.rank = rank else: self.suit = None
splash_info = ImageInfo([200, 150], [400, 300]) splash_image = simplegui.load_image("http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/splash.png") ship_info = ImageInfo([45, 45], [90, 90], 35) ship_image = simplegui.load_image("http://i.imgur.com/Y28T5p1.png") missile_info = ImageInfo([5,5], [10, 10], 3, 50) missile_image = simplegui.load_image("http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/" + random.choice(missile_choice)) asteroid_info = ImageInfo([45, 45], [90, 90], 40) asteroid_image = simplegui.load_image("http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/" + random.choice(asteroid_choice)) explosion_info = ImageInfo([64, 64], [128, 128], 17, 24, True) explosion_image = simplegui.load_image("http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/"+ random.choice(explosion_choice)) soundtrack = simplegui.load_sound("http://a.tumblr.com/tumblr_limv27nm7W1qi5bdzo1.mp3") missile_sound = simplegui.load_sound("http://commondatastorage.googleapis.com/codeskulptor-assets/sounddogs/missile.mp3") missile_sound.set_volume(.5) ship_thrust_sound = simplegui.load_sound("http://commondatastorage.googleapis.com/codeskulptor-assets/sounddogs/thrust.mp3") explosion_sound = simplegui.load_sound("http://commondatastorage.googleapis.com/codeskulptor-assets/sounddogs/explosion.mp3") # helper functions to handle transformations def angle_to_vector(ang): return [math.cos(ang), math.sin(ang)] def dist(p, q): return math.sqrt((p[0] - q[0]) ** 2 + (p[1] - q[1]) ** 2) # Ship class
# enumerate all multiples of 100 in range of offset[1] to offset[1] + height for steps in range(100*int(offset[1]//100),int(h+offset[1]),100): # convert steps to index for platforms ind = height(steps)//100 if ind < num_plat and pl[ind].exists: canvas.draw_line(camera([pl[ind].left,steps]),camera([pl[ind].right,steps]),4,"Yellow") canvas.draw_text(str(height(steps)),camera([w-50,steps]),12,"White") # canvas.draw_line(camera([0,steps]),camera([w,steps]),1,"White") # initialize stuff w = 800 h = 600 frame = simplegui.create_frame("Doodle Jump", w, h) sound = simplegui.load_sound("http://commondatastorage.googleapis.com/codeskulptor-assets/jump.ogg") #hamster republic # set handlers frame.set_keydown_handler(keydown) frame.set_keyup_handler(keyup) frame.set_draw_handler(draw) # create 1000 random platforms num_plat = 1000 pl = [platform() for i in range(0,num_plat)] # make first platform cover the whole bottom of the window so you don't die immediately pl[0].left = 0 pl[0].right = w # global offset store current camera information
#HANGMAN GAME import SimpleGUICS2Pygame.simpleguics2pygame as simplegui import random num_guesses=6 happ=["_","_",'_','_','_','_'] game_1,play,head,body,left_arm,right_arm,left_leg,right_leg,word=False,False,False,False,False,False,False,False,False secret,game=True,True start= True win_image = simplegui.load_image("http://www.newyorker.com/wp-content/uploads/2016/01/Duca-Donald-Trumps-Path-to-Victory-290x149-1453933086.jpg") lose_image = simplegui.load_image("http://static.tvtropes.org/pmwiki/pub/images/hanging2_3655.jpg") start_first = True loss = False win = False loss_sound = simplegui.load_sound("D:\Pygame\csProject\hangman_loss.ogg") win_sound = simplegui.load_sound("D:\Pygame\csProject\hangman_win.ogg") def draw(canvas): global num_guesses canvas.draw_text("*H-A-N-G-M-A-N*",(50,50),40,"Red") if start: canvas.draw_text(" CHOOSE AN OPTION ",(40,120),30,"Red") canvas.draw_polygon([(30,170),(190,170),(190,230),(30,230)],6,"Red") canvas.draw_polygon([(30,250),(190,250),(190,310),(30,310)],6,"Red") canvas.draw_polygon([(30,330),(190,330),(190,390),(30,390)],6,"Red") canvas.draw_polygon([(210,170),(370,170),(370,230),(210,230)],6,"Red") canvas.draw_polygon([(210,250),(370,250),(370,310),(210,310)],6,"Red") canvas.draw_polygon([(210,330),(370,330),(370,390),(210,390)],6,"Red") canvas.draw_text("ANIMALS",(40,210),30,"Red") canvas.draw_text("VOCAB",(40,290),30,"Red") canvas.draw_text("SOCIAL",(40,370),30,"Red")
Pad_Top_Right_y=0 Pad_Bottom_Right_y=50 Pad_Right=[Pad_Top_Right_y,Pad_Bottom_Right_y] Pad_Height=0 Pad_Height_1=0 Pad_Left=[Pad_Top_Left_y,Pad_Bottom_Left_y] LEFT,RIGHT=False,False start = True controls = False w_key = simplegui.load_image("https://www.wpclipart.com/computer/keyboard_keys/letters/computer_key_W.png") s_key = simplegui.load_image("https://www.wpclipart.com/computer/keyboard_keys/letters/computer_key_S.png") up_key = simplegui.load_image("https://www.wpclipart.com/computer/keyboard_keys/arrow_keys/computer_key_Arrow_Up.png") down_key = simplegui.load_image("https://www.wpclipart.com/computer/keyboard_keys/arrow_keys/computer_key_Arrow_Down.png") multi_arrow_image=simplegui.load_image("https://cdn2.iconfinder.com/data/icons/crystalproject/crystal_project_256x256/apps/restart-1.png") pong_sound = simplegui.load_sound("D:\Pygame\csProject\pong_music.ogg") pong_sound.set_volume(.5) pong_sound.play() pong_image = simplegui.load_image("http://www.slashgear.com/wp-content/uploads/2015/07/PONG.jpg") pong_restart = simplegui.load_sound("D:\Pygame\csProject\pong_restart.ogg") #HANDLER(S) def draw(canvas): global vel,score_1,LEFT,RIGHT,score_2,Pad_Height,Pad_Right,Pad_Left,Pad_Height_1 if start: canvas.draw_image(pong_image,(1280/2,714/2),(1280,714),(300,150),(600,300)) canvas.draw_polygon([(40,240),(140,240),(140,280),(20,280)],5,"Black") canvas.draw_polygon([(460,240),(555,240),(595,280),(460,280)],5,"Black") canvas.draw_text("PLAY",(50,270),30,"Red") canvas.draw_text("CONTROLS",(465,270),20,"Red")
background = simplegui.load_image("https://dl.dropboxusercontent.com/u/280794727/Pong/bg.jpg") ball_pos = [300, 200] ball_rot = 0 paddle1_pos = [10, 200] paddle2_pos = [590, 200] vel = [0, 0] paddle1_vel = 0 paddle2_vel = 0 in_play = "False" direction = "left" score1 = 0 score2 = 0 fatal_tick = 4 # sounds ceiling_hit = simplegui.load_sound('https://dl.dropboxusercontent.com/u/280794727/Pong/20.wav') paddle1_sound = simplegui.load_sound('https://dl.dropboxusercontent.com/u/280794727/Pong/07.wav') theme_song = simplegui.load_sound('https://dl.dropboxusercontent.com/u/280794727/Pong/fight_style.wav') #paddle2_sound = simplegui.load_sound('http://www.basementarcade.com/arcade/sounds/tapper/08.wav') #player_scores = simplegui.load_sound('http://www.basementarcade.com/arcade/sounds/tapper/12.wav') # initialize ball_pos and ball_vel for new bal in middle of table # if direction is RIGHT, the ball's velocity is upper right, else upper left def spawn_ball(direction): global ball_pos, vel, in_play # these are vectors stored as lists ball_pos = [300, 200] in_play = "True" vel[1] = - (float(random.randrange(120, 240))) /100 if direction == "right": vel[0] = (float(random.randrange(60, 180))) / 100
def input_handler(int_input): #Function to input difficulty pass def game_over(canvas): #Temporary GameOver screen canvas.draw_text('Game Over', (140, 40), 46, 'Red') canvas.draw_text('Score', (140, 140), 26, 'Blue') frame = sg.create_frame("Snake", LENGTH, HEIGHT) frame.set_keydown_handler(keydown_handler) eating_sound_effect = sg.load_sound( 'http://rpg.hamsterrepublic.com/wiki-images/7/73/Powerup.ogg' ) #To be called when snake collides with an apple collision_sound_effect = sg.load_sound( 'http://rpg.hamsterrepublic.com/wiki-images/3/3b/EnemyDeath.ogg' ) #To be called when snake collides with walls/itself inp = frame.add_input( "Difficulty from 1-10", input_handler, 50) #Changes the framerate and hence the speed of the snake StartGame = frame.add_button("Start", button_Start) RestartGame = frame.add_button("Restart", button_Restart) frame.set_draw_handler(canvas_Menu) frame.start()
# asteroid images - asteroid_blue.png, asteroid_brown.png, asteroid_blend.png asteroid_info = ImageInfo([45, 45], [90, 90], 40) asteroid_image = simplegui.load_image( "http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/asteroid_blue.png" ) # animated explosion - explosion_orange.png, explosion_blue.png, explosion_blue2.png, explosion_alpha.png explosion_info = ImageInfo([64, 64], [128, 128], 17, 24, True) explosion_image = simplegui.load_image( "http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/explosion_alpha.png" ) # sound assets purchased from sounddogs.com, please do not redistribute soundtrack = simplegui.load_sound( "https://ia801703.us.archive.org/15/items/StarWarsThemeSongByJohnWilliams/Star%20Wars%20Theme%20Song%20By%20John%20Williams.mp3" ) missile_sound = simplegui.load_sound( "http://commondatastorage.googleapis.com/codeskulptor-assets/sounddogs/missile.mp3" ) missile_sound.set_volume(.5) ship_thrust_sound = simplegui.load_sound( "http://commondatastorage.googleapis.com/codeskulptor-assets/sounddogs/thrust.mp3" ) explosion_sound = simplegui.load_sound( "http://commondatastorage.googleapis.com/codeskulptor-assets/sounddogs/explosion.mp3" ) # helper functions to handle transformations def angle_to_vector(ang):
asteroid_image_1 = simplegui.load_image( "https://dl.dropboxusercontent.com/u/280794727/spaceglory/asteroid1.png") asteroid_image_2 = simplegui.load_image( "https://dl.dropboxusercontent.com/u/280794727/spaceglory/asteroid2.png") asteroid_image_live = asteroid_image_0 # animated explosion - explosion_orange.png, explosion_blue.png, # explosion_blue2.png, explosion_alpha.png explosion_info = ImageInfo([64, 64], [128, 128], 17, 24, True) explosion_image = simplegui.load_image( "http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/explosion_alpha.png") # soundtracks and sound effects current_song = simplegui.load_sound( "https://dl.dropboxusercontent.com/u/280794727/spaceglory/sounds/The_Prodigy_First_Warning.wav") missile_sound = simplegui.load_sound( "https://dl.dropboxusercontent.com/u/280794727/spaceglory/sounds/alian_laser.wav") missile_sound.set_volume(.2) laser_overheat_sound = simplegui.load_sound( "https://dl.dropboxusercontent.com/u/280794727/spaceglory/sounds/laser_gun_overheat.wav") laser_overheat_sound.set_volume(0.3) shield_damage_sound = simplegui.load_sound( "https://dl.dropboxusercontent.com/u/280794727/spaceglory/sounds/shield_damage.wav") boss_defected_sound = simplegui.load_sound( "https://dl.dropboxusercontent.com/u/280794727/spaceglory/sounds/alarm_boss_detected.wav")
def restart(): """ Event handler to deal click on restart button. """ global pong pong = Pong() button_pause.set_text('Pause on') # Create frame frame = simplegui.create_frame('Pong', Pong.WIDTH, Pong.HEIGHT) # Sounds sound_balls_collision = simplegui.load_sound( 'http://rpg.hamsterrepublic.com/wiki-images/7/72/Metal_Hit.ogg') sound_bounce_border = simplegui.load_sound( 'http://rpg.hamsterrepublic.com/wiki-images/2/21/Collision8-Bit.ogg') sound_bounce_paddle = simplegui.load_sound( 'http://rpg.hamsterrepublic.com/wiki-images/d/d7/Oddbounce.ogg') sound_lost = simplegui.load_sound( 'http://rpg.hamsterrepublic.com/wiki-images/d/db/Crush8-Bit.ogg') # Register event handlers frame.add_button('Restart', restart, 200) frame.add_label('') button_pause = frame.add_button('Pause on', pause, 200) frame.add_label('') frame.add_label('') frame.add_button('Add ball', add_ball, 200)
# asteroid images - asteroid_blue.png, asteroid_brown.png, asteroid_blend.png asteroid_info = ImageInfo([45, 45], [90, 90], 40) asteroid_image = simplegui.load_image( "http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/asteroid_blue.png" ) # animated explosion - explosion_orange.png, explosion_blue.png, explosion_blue2.png, explosion_alpha.png explosion_info = ImageInfo([64, 64], [128, 128], 17, 24, True) explosion_image = simplegui.load_image( "http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/explosion_alpha.png" ) # sound assets purchased from sounddogs.com, please do not redistribute # TODO switch sound to mp3 soundtrack = simplegui.load_sound( "http://commondatastorage.googleapis.com/codeskulptor-assets/sounddogs/soundtrack.ogg" ) missile_sound = simplegui.load_sound( "http://commondatastorage.googleapis.com/codeskulptor-assets/sounddogs/missile.ogg" ) missile_sound.set_volume(.5) ship_thrust_sound = simplegui.load_sound( "http://commondatastorage.googleapis.com/codeskulptor-assets/sounddogs/thrust.ogg" ) explosion_sound = simplegui.load_sound( "http://commondatastorage.googleapis.com/codeskulptor-assets/sounddogs/explosion.ogg" ) # helper functions to handle transformations def angle_to_vector(ang):
asteroid_info = ImageInfo([45, 45], [90, 90], 40) asteroid_image = simplegui._load_local_image( os.path.join(dir, "asteroid_blue.png")) explosion_info = ImageInfo([64, 64], [128, 128], 17, 24, True) explosion_image = simplegui._load_local_image( os.path.join(dir, "explosion_alpha.png")) nebula_info = ImageInfo([400, 300], [800, 600]) nebula_image = simplegui._load_local_image(os.path.join(dir, "ngc602.png")) splash_info = ImageInfo([200, 112], [400, 224]) splash_image = simplegui._load_local_image(os.path.join(dir, "splash.png")) soundtrack = simplegui.load_sound( os.path.join(dir, "Converted_file_d781eb32.ogg")) soundtrack.set_volume(.8) missile_sound = simplegui.load_sound(os.path.join(dir, "sci_fi_lazer_shot.ogg")) missile_sound.set_volume(.3) ship_thrust_sound = simplegui.load_sound(os.path.join(dir, "flame.ogg")) ship_thrust_sound.set_volume(.5) explosion_sound = simplegui.load_sound( os.path.join(dir, "explosion_single_large_07.ogg")) explosion_sound.set_volume(.4) def angle_to_vector(ang): return [math.cos(ang), math.sin(ang)]
missile_info = ImageInfo([5, 5], [10, 10], 3, 50) missile_image = simplegui.load_image( "http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/shot2.png") # asteroid images - asteroid_blue.png, asteroid_brown.png, asteroid_blend.png asteroid_info = ImageInfo([45, 45], [90, 90], 40) asteroid_image = simplegui.load_image( "http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/asteroid_blue.png") # animated explosion - explosion_orange.png, explosion_blue.png, # explosion_blue2.png, explosion_alpha.png explosion_info = ImageInfo([64, 64], [128, 128], 17, 24, True) explosion_image = simplegui.load_image( "http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/explosion_alpha.png") soundtrack = simplegui.load_sound( "http://commondatastorage.googleapis.com/codeskulptor-assets/sounddogs/soundtrack.ogg") missile_sound = simplegui.load_sound( "http://commondatastorage.googleapis.com/codeskulptor-assets/sounddogs/missile.ogg") missile_sound.set_volume(.5) ship_thrust_sound = simplegui.load_sound( "http://commondatastorage.googleapis.com/codeskulptor-assets/sounddogs/thrust.ogg") explosion_sound = simplegui.load_sound( "http://commondatastorage.googleapis.com/codeskulptor-assets/sounddogs/explosion.ogg") # helper functions to handle transformations def angle_to_vector(ang): return [math.cos(ang), math.sin(ang)] def dist(p, q):
"https://www.dropbox.com/s/ufdkgd9botze6f7/missile.png?dl=1") # asteroid images - asteroid_blue.png, asteroid_brown.png, asteroid_blend.png asteroid_info = ImageInfo([45, 45], [90, 90], 40) asteroid_image = simplegui.load_image( "https://www.dropbox.com/s/o39bneyp9bh00w6/asteroids4.png?dl=1") # animated explosion - explosion_orange.png, explosion_blue.png, # explosion_blue2.png, explosion_alpha.png explosion_info = ImageInfo([64, 64], [128, 128], 17, 24, True) explosion_image = simplegui.load_image( "https://www.dropbox.com/s/h6bmj8cysa7a5vv/explosion.png?dl=1") # sound assets purchased from sounddogs.com, please do not redistribute # .ogg versions of sounds are also available, just replace .mp3 by .ogg soundtrack = simplegui.load_sound( "https://www.dropbox.com/s/47tvpr88kt2p3oj/powerUp.ogg?dl=1") #soundtrack.set_volume(.5) missile_sound = simplegui.load_sound( "http://rpg.hamsterrepublic.com/wiki-images/2/21/Collision8-Bit.ogg") ship_thrust_sound = simplegui.load_sound( "http://rpg.hamsterrepublic.com/wiki-images/a/a2/ThunderMagic.ogg") explosion_sound = simplegui.load_sound( "http://rpg.hamsterrepublic.com/wiki-images/0/0c/TornadoMagic.ogg") explosion_sound.set_volume(.5) # helper functions to handle transformations def angle_to_vector(ang): return [math.cos(ang), math.sin(ang)] def dist(p, q): return math.sqrt((p[0] - q[0]) ** 2 + (p[1] - q[1]) ** 2)