def loadSounds(): global matchSound global failSound global victorySound matchSound = simplegui.load_sound(GAME_ASSETS + "win.ogg") failSound = simplegui.load_sound(GAME_ASSETS + "lose.ogg") victorySound = simplegui.load_sound(GAME_ASSETS + "goal.ogg")
def __init__(self, url): self.url = url if CACHE_STORE.has_key(url): self.sound = CACHE_STORE[url] else: self.sound = simplegui.load_sound(url) CACHE_STORE[url] = self.sound
def __init__(self): self.center_x = 99 self.center_y = 260 self.speed = 0 self.gravity = 0 self.image = simplegui.load_image(BIRD_IMAGE) self.flap_sound = simplegui.load_sound(FLAP_SOUND)
def __init__(self, pos, vel, angle, image, info, BOARD_WIDTH, BOARD_HEIGHT): self.pos = [pos[0], pos[1]] self.vel = [vel[0], vel[1]] self.thrust = False self.angle = angle self.angle_vel = 0 self.FRICTION = 0.009 self.BOARD_WIDTH = BOARD_WIDTH self.BOARD_HEIGHT = BOARD_HEIGHT self.MISSILE_SPEED = 7 self.image = image self.image_center = info.get_center() self.image_size = info.get_size() self.radius = info.get_radius() self.timer = None self.time_passed = 0.0 self.ship_thrust_sound = simplegui.load_sound("http://commondatastorage.googleapis.com/codeskulptor-assets/sounddogs/thrust.mp3") self.missile_info = ImageInfo([5, 5], [10, 10], 3, 40) self.missile_image = simplegui.load_image("http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/shot2.png") self.missile_sound = simplegui.load_sound("http://commondatastorage.googleapis.com/codeskulptor-assets/sounddogs/missile.mp3") self.missile_sound.set_volume(.7)
def __init__(self): self.my_ship = Ship([WIDTH / 2, HEIGHT / 2], [0, 0], 0) self.rock_group = set() self.explosion_group = set() self.lives = 3 self.started = False self.score = 0 self.time = 0.5 self.max_rock_velocity = 10 self.points_to_velocity_map = { 20: 13, 30: 17, 40: 21, 50: 25, 60: 29, 70: 33, 80: 37, 90: 41, 100: 45 } self.soundtrack = simplegui.load_sound( MEDIA_HOST + 'sounddogs/soundtrack.mp3') self.splash_info = ImageInfo([200, 150], [400, 300]) self.splash_image = simplegui.load_image( MEDIA_HOST + 'lathrop/splash.png') self.asteroid_info = ImageInfo([45, 45], [90, 90], 40) self.asteroid_image = simplegui.load_image( MEDIA_HOST + 'lathrop/asteroid_blue.png') self.ship_explosion_image = simplegui.load_image( MEDIA_HOST + 'lathrop/explosion_alpha.png') self.asteroid_explosion_image = simplegui.load_image( MEDIA_HOST + 'lathrop/explosion_blue2.png') self.ship_thrust_sound = simplegui.load_sound( MEDIA_HOST + 'sounddogs/thrust.mp3') self.explosion_info = ImageInfo([64, 64], [128, 128], 17, 24, True) self.explosion_sound = simplegui.load_sound( MEDIA_HOST + 'sounddogs/explosion.mp3') self.debris_info = ImageInfo([320, 240], [640, 480]) self.debris_image = simplegui.load_image( MEDIA_HOST + 'lathrop/debris3_brown.png') self.nebula_info = ImageInfo([400, 300], [800, 600]) self.nebula_image = simplegui.load_image( MEDIA_HOST + 'lathrop/nebula_blue.s2014.png')
def __init__(self, size, radius = 0, lifespan = float('inf'), sound_url = None): """All the resuable data :size: @ output size of image :radius: @ for collision determination :lifespan: @ automatically disappear if not infinite, count in drawing frames :sound_url: @ sound file url """ self.size = size self.radius = radius self.lifespan = lifespan self.sound = simplegui.load_sound(sound_url) if sound_url else None
def __init__(self, pos, vel, angle, image, info): self.pos = [pos[0],pos[1]] self.vel = [vel[0],vel[1]] self.thrust = False self.angle = angle self.angle_vel = 0 self.image = image self.image_center = info.get_center() self.image_size = info.get_size() self.radius = info.get_radius() self.ANGULAR_VEL_CHANGE = 0.10 self.info = info self.ship_thrust_sound = simplegui.load_sound("http://commondatastorage.googleapis.com/codeskulptor-assets/sounddogs/thrust.mp3") self.ship_thrust_sound.set_volume(1) self.friction_constant = SHIP_FRICTION_CONSTANT
def init(): global paddle1_pos, paddle2_pos, paddle1_vel, paddle2_vel, message # these are floats global score1, score2 # these are ints restart = simplegui.load_sound("http://www.mediacollege.com/downloads/sound-effects/star-wars/yoda/yoda_doordonot.wav") restart.play() paddle1_pos = (HEIGHT-PAD_HEIGHT)/2 paddle2_pos = (HEIGHT-PAD_HEIGHT)/2 paddle1_vel = 0 paddle2_vel = 0 score1 = 0 score2 = 0 message = "" start_serve = random.randrange(0,2) if (start_serve == 0): ball_init(False) else: ball_init(True)
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. """ try: from simplegui import load_image, load_sound SIMPLEGUICS2PYGAME = False except ImportError: from SimpleGUICS2Pygame.simpleguics2pygame import load_image, \ load_sound SIMPLEGUICS2PYGAME = True self._SIMPLEGUICS2PYGAME = SIMPLEGUICS2PYGAME if SIMPLEGUICS2PYGAME: handler_saved = self._frame._canvas._draw_handler self._frame._canvas._draw_handler = self._draw_loading for name in self._sounds: if 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 SIMPLEGUICS2PYGAME: self._frame._canvas._draw() if isinstance(self._images[name], str): self._images[name] = load_image(self._images[name]) if SIMPLEGUICS2PYGAME: self._frame._canvas._draw() self._frame._canvas._draw_handler = handler_saved
def draw(canvas): """ Print str representation of each SimpleGUI object. :param canvas: simpleguics2pygame.Canvas or simplegui.Canvas """ image = simplegui.load_image('') sound = simplegui.load_sound('') timer = simplegui.create_timer(1000, lambda: None) for name, o in (('button', button), ('canvas', canvas), ('frame', frame), ('image', image), ('input', input), ('label', label), ('sound', sound), ('timer', timer)): print(name + str(type(o)) + repr(o) + str(o)) frame.stop()
def __init__(self, position, velocity, angle): self.position = [position[0], position[1]] self.velocity = [velocity[0], velocity[1]] self.angle = angle self.ship_image_info = ImageInfo([45, 45], [90, 90], 35) self.missile_info = ImageInfo([5,5], [10, 10], 3, 50) self.missile_image = simplegui.load_image( MEDIA_HOST + 'lathrop/shot2.png') self.missile_sound = simplegui.load_sound( MEDIA_HOST + 'sounddogs/missile.mp3') self.missile_sound.set_volume(.5) self.image = simplegui.load_image( MEDIA_HOST + 'lathrop/double_ship.png') self.image_center = self.ship_image_info.get_center() self.image_size = self.ship_image_info.get_size() self.radius = self.ship_image_info.get_radius() self.animated = self.ship_image_info.get_animated() self.thrust = False self.angle_velocity = 0 self.missile_group = set()
ship_image = simplegui.load_image("http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/double_ship.png") # missile image - shot1.png, shot2.png, shot3.png 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") # sound assets purchased from sounddogs.com, please do not redistribute soundtrack = simplegui.load_sound("http://www.soundjay.com/free-music/sounds/iron-man-01.mp3") missile_sound = simplegui.load_sound("http://commondatastorage.googleapis.com/codeskulptor-assets/sounddogs/missile.mp3") missile_sound.set_volume(.3) ship_thrust_sound = simplegui.load_sound("http://commondatastorage.googleapis.com/codeskulptor-assets/sounddogs/thrust.mp3") explosion_sound = simplegui.load_sound("http://www.pacdv.com/sounds/fart-sounds/fart-2.wav") # helper functions to handle transformations def angleToVector(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 class Ship:
Event handler to deal click on restart button. """ global pong pong = Pong() button_pause.set_text('Pause on') button_protect_left.set_text('Protect left player') button_protect_right.set_text('Protect right player') protect_left() # 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('') button_protect_left = frame.add_button('Protect left player', protect_left, 200) button_protect_right = frame.add_button('Protect right player',
def image_and_sound_declarations(): '''I zipped all these up into a function because they are a mess to look at and now I can collapse them as I work :D''' global splash_image, splash_info global debris_info, debris_image global nebula_info, nebula_image global ship_info, ship_image global missile_info, missile_image global asteroid_info, asteroid_image global soundtrack, missile_sound, ship_thrust_sound, explosion_sound #THESE ARE MY IMAGES AND SOUNDS - PLEASE COMMENT OUT IF THEY DON'T LOAD - THANK YOU!!!! splash_info = ImageInfo([200, 150], [400, 300]) splash_image = simplegui.load_image( "https://dl.dropbox.com/s/yaazzsgnraxz5jm/my_splash.png") debris_info = ImageInfo([320, 240], [640, 480]) debris_image = simplegui.load_image( "https://dl.dropbox.com/s/uelrcnu4aexo2he/debris.png") nebula_info = ImageInfo([400, 300], [800, 600]) nebula_image = simplegui.load_image( "https://dl.dropbox.com/s/h5awm7onocm9v10/space.png") ship_info = ImageInfo([45, 45], [90, 90], ship_radius) ship_image = simplegui.load_image( "https://dl.dropbox.com/s/ezp7v5d7ti7dhpg/spaceship.png") missile_info = ImageInfo([5, 5], [10, 10], missile_radius, missile_lifespan) missile_image = simplegui.load_image( "https://dl.dropbox.com/s/jyly627nc8v1zku/missile.png") asteroid_info = ImageInfo([45, 45], [90, 90], asteroid_radius) asteroid_image = simplegui.load_image( "https://dl.dropbox.com/s/gvja7maw8ppthe9/asteroid.png") ###Sound asset from http://www-pw.physics.uiowa.edu/space-audio/cassini/SKR1/ soundtrack = simplegui.load_sound( "https://dl.dropbox.com/s/41w472w2b3b4ij2/space.mp3") ###Original recording: missile_sound = simplegui.load_sound( "https://dl.dropbox.com/s/jciomfzbvklfzyk/pow.mp3") ship_thrust_sound = simplegui.load_sound( "https://dl.dropbox.com/s/2298a7diby28hth/thrust.mp3") #BELOW ARE THE COURSERA IMAGES - PLEASE UNCOMMENT IF MINE (ABOVE) DON'T WORK, THANK YOU! # # art assets created by Kim Lathrop, may be freely re-used in non-commercial projects, please credit Kim # # debris images - debris1_brown.png, debris2_brown.png, debris3_brown.png, debris4_brown.png # # debris1_blue.png, debris2_blue.png, debris3_blue.png, debris4_blue.png, debris_blend.png # debris_info = ImageInfo([320, 240], [640, 480]) # debris_image = simplegui.load_image("http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/debris2_blue.png") # # # nebula images - nebula_brown.png, nebula_blue.png # nebula_info = ImageInfo([400, 300], [800, 600]) # nebula_image = simplegui.load_image("http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/nebula_blue.f2014.png") # # # splash image # splash_info = ImageInfo([200, 150], [400, 300]) # splash_image = simplegui.load_image("http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/splash.png") # # # ship image # ship_info = ImageInfo([45, 45], [90, 90], 35) # ship_image = simplegui.load_image("http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/double_ship.png") # # # missile image - shot1.png, shot2.png, shot3.png # 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") # SOUNDS # sound assets purchased from sounddogs.com, please do not redistribute # alternative upbeat soundtrack by composer and former IIPP student Emiel Stopler # please do not redistribute without permission from Emiel at http://www.filmcomposer.nl # 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(\ # "http://commondatastorage.googleapis.com/codeskulptor-assets/sounddogs/soundtrack.mp3") # missile_sound = simplegui.load_sound(\ # "http://commondatastorage.googleapis.com/codeskulptor-assets/sounddogs/missile.mp3") # 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")
Event handler to deal click on restart button. """ global pong pong = Pong() button_pause.set_text('Pause on') button_protect_left.set_text('Protect left player') button_protect_right.set_text('Protect right player') protect_left() # 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('') button_protect_left = frame.add_button('Protect left player', protect_left, 200) button_protect_right = frame.add_button('Protect right player', protect_right,
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 # .ogg versions of sounds are also available, just replace .mp3 by .ogg #soundtrack = simplegui.load_sound("http://commondatastorage.googleapis.com/codeskulptor-assets/sounddogs/soundtrack.mp3") soundtrack = simplegui.load_sound( "https://s3.amazonaws.com/python_assets/1400348538_1nMHB1PCFdhu5iBJKbLE.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
# Mini-project #6 - Blackjack import simplegui import random import math # load card sprite - 949x392 - source: jfitz.com sound1 = simplegui.load_sound( "https://www.dropbox.com/s/gpxm5lork4634cs/soundcoin.mp3?dl=1") sound2 = simplegui.load_sound( "https://www.dropbox.com/s/xk4bcyw5h5lh3nz/drwa1.mp3?dl=1") play_sound2 = [] WIDTH_SCREEN = 1024 HEIGHT_SCREEN = 700 CARD_SIZE = (73, 98) CARD_CENTER = (36.5, 49) Deck_image = simplegui.load_image( "https://www.dropbox.com/s/wblurd2icoik8mf/table.png?dl=1") DECK_SIZE = (1019, 703) DECK_SIZE_CENTER = (509.5, 351.5) card_images = simplegui.load_image( "http://commondatastorage.googleapis.com/codeskulptor-assets/cards.jfitz.png" ) MOVE_WIDTH = [] MOVE_HEIGHT = [] ROTATE = [] FLIPS = [] ANIMATION = 30 CARD_BACK_SIZE = (71, 96) CARD_BACK_CENTER = (35.5, 48) card_back = simplegui.load_image( "http://commondatastorage.googleapis.com/codeskulptor-assets/card_back.png"
# info(self, center, size, radius = 0, lifespan = None, animated = False): # missile image - shot1.png, shot2.png, shot3.png missile_info = ImageInfo([5,5], [10, 10], 3, 30) 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, 1200) 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 # def __init__(self, center, size, radius = 0, lifespan = None, animated = False): explosion_info = ImageInfo([64, 64], [128, 128], 17, 120, 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("http://commondatastorage.googleapis.com/codeskulptor-assets/sounddogs/soundtrack.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") good_sound = simplegui.load_sound("https://www.dropbox.com/s/no4xabzohgqdv4l/mgod_clip.mp3") #good_sound = explosion_sound # ship angle_vel SHIP_ANGLE_VEL = 0 ANGLE_DELTA = math.pi/30 NAKE_SHIP_POS = [45, 45] THRUSTER_SHIP_POS = [45+90, 45] THRUST_SPEED = 3.618 started = False
# project - Blackjack import simplegui import random # load card sprite - 949x392 - source: jfitz.com CARD_SIZE = (73, 98) CARD_CENTER = (36.5, 49) card_images = simplegui.load_image("http://commondatastorage.googleapis.com/codeskulptor-assets/cards.jfitz.png") button_not_working = simplegui.load_sound("https://www.dropbox.com/s/fyd6o2bu2fq5v3g/button%20not%20working.ogg?dl=1") won_game = simplegui.load_sound("https://www.dropbox.com/s/um0decuhbs5ljd9/won.ogg?dl=1") deal_new_card = simplegui.load_sound("https://www.dropbox.com/s/47zech3mdxs4nzx/deal_card.ogg?dl=1") deal_new_card.set_volume(0.3) CARD_BACK_SIZE = (71, 96) CARD_BACK_CENTER = (35.5, 48) card_back = simplegui.load_image("http://commondatastorage.googleapis.com/codeskulptor-assets/card_back.png") # initialize some useful global variables in_play = False outcome = "" score = 0 # 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} # define card class class Card:
def __init__(self): self.score = 0 self.score_sound = simplegui.load_sound(SCORE_SOUND)
#Debris_image = simplegui.load_image ("http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/debris2_blue.png") Debris_image = simplegui.load_image ("http://i.imgur.com/Bb8tjOD.png") Debris_Info = Image_info ([320, 240], [640, 480]) #Ship Image : Ship_Info = Image_info([45, 45], [90, 90], 35) Ship_Image = simplegui.load_image("http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/double_ship.png") #Astroid : Astroid_Image = simplegui.load_image ("http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/asteroid_blue.png") Astroid_Info = Image_info ([45,45],[90,90],50) #Missiles Images : Missile_Info = Image_info([5, 5], [10, 10], 3, 50) Missile_Image = simplegui.load_image ("http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/shot2.png") Missile_Sound = simplegui.load_sound ("http://commondatastorage.googleapis.com/codeskulptor-assets/sounddogs/missile.mp3") #Explosion Explosion_Image = simplegui.load_image("http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/explosion_alpha.png") Explosion_Info = Image_info([64, 64], [128, 128], 17, 24, True) Explosion_Sound = simplegui.load_sound ("http://commondatastorage.googleapis.com/codeskulptor-assets/sounddogs/explosion.mp3") #Introduction Image : Intro_Image = simplegui.load_image ("http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/splash.png") Intro_Info = Image_info([200, 150], [400, 300]) #Backgorund Sound of the Game : Sound = simplegui.load_sound ("http://www.sounddogs.com/previews/3972/mp3/616644_SOUNDDOGS__sp.mp3")
volume_button.set_text("Volume = " + str(vol)) # create frame - canvas will be blank frame = simplegui.create_frame("Music demo", 250, 250, 100) # set up control elements frame.add_button("play", play, 100) frame.add_button("pause", pause, 100) frame.add_button("rewind", rewind, 100) frame.add_button("laugh", laugh, 100) frame.add_button("Vol down", vol_down, 100) frame.add_button("Vol up", vol_up, 100) # initialize volume, create button whose label will display the volume vol = 7 volume_button = frame.add_label("Volume = " + str(vol)) # load some sounds music = simplegui.load_sound( "http://commondatastorage.googleapis.com/codeskulptor-assets/Epoq-Lepidoptera.ogg" ) laugh = simplegui.load_sound( "http://commondatastorage.googleapis.com/codeskulptor-assets/Evillaugh.ogg" ) # make the laugh quieter so my ears don't bleed laugh.set_volume(.1) frame.start()
ship_image = simplegui.load_image("http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/double_ship.png") # missile image - shot1.png, shot2.png, shot3.png 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") # sound assets purchased from sounddogs.com, please do not redistribute soundtrack = simplegui.load_sound("http://commondatastorage.googleapis.com/codeskulptor-assets/sounddogs/soundtrack.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") ouch_sound = simplegui.load_sound("https://dl.dropbox.com/u/9374021/uughh.wav") applause_sound = simplegui.load_sound("https://dl.dropbox.com/u/9374021/applause.wav") THRUST_CONST = 0.3 FRICTION_CONST = 0.040 MISSILE_FACTOR = 5 ANGLE_VEL = 6 # helper functions to handle transformations
def get_lifespan(self): return self.lifespan def get_animated(self): return self.animated # art assets created by Kim Lathrop, may be freely re-used in non-commercial projects, please credit Kim # ship image ship_info = ImageInfo([45, 45], [90, 90], 35) ship_image = simplegui.load_image("http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/double_ship.png") # sound assets purchased from sounddogs.com, please do not redistribute ship_thrust_sound = simplegui.load_sound("http://commondatastorage.googleapis.com/codeskulptor-assets/sounddogs/thrust.mp3") # Ship class class Ship: def __init__(self, pos, vel, angle, image, info): self.pos = [pos[0],pos[1]] self.vel = [vel[0],vel[1]] self.thrust = False self.angle = angle self.angle_vel = 0 self.image = image self.image_center = info.get_center() self.image_size = info.get_size() self.radius = info.get_radius()
frame = simplegui.create_frame("Pong", WIDTH, HEIGHT) frame.add_label("Instructions:") frame.add_label( "1. To Win the game, either one of you needs to have a 10 points !!!", 200) frame.add_label("") frame.add_label("2. Left player keys are 'w' = Upward, and 's' = downward", 200) frame.add_label("") frame.add_label( "3. Right player keys are 'Upper Arrow' = Upward, and 'Lower Arrow' = downward", 200) frame.add_label("") frame.add_label("Enjoy the game !!!") frame.add_label("") frame.add_button("Restart!", new_game, 200) frame.add_label("") frame.add_button("Exit!", exit_game, 200) frame.set_draw_handler(draw) frame.set_keydown_handler(keydown) frame.set_keyup_handler(keyup) # Loading music (Ref: Desperados 2: Music Clip) music = simplegui.load_sound( "https://dl-web.dropbox.com/get/Desperados%201.mp3?_subject_uid=220055480&w=AABsaCLWEbsE4cGgEdqjYOs9quXBqcY1igby6BWbKC4yig" ) # start frame new_game() frame.start()
def load_resources(self): # art assets created by Kim Lathrop, may be freely re-used in non-commercial projects, please credit Kim # debris images - debris1_brown.png, debris2_brown.png, debris3_brown.png, debris4_brown.png # debris1_blue.png, debris2_blue.png, debris3_blue.png, debris4_blue.png, debris_blend.png global debris_info, debris_image debris_info = ImageInfo([320, 240], [640, 480]) debris_image = simplegui.load_image( "http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/debris2_blue.png" ) # nebula images - nebula_brown.png, nebula_blue.png global nebula_info, nebula_image nebula_info = ImageInfo([400, 300], [800, 600]) nebula_image = simplegui.load_image( "http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/nebula_blue.s2014.png" ) # splash image global splash_info, splash_image splash_info = ImageInfo([200, 150], [400, 300]) splash_image = simplegui.load_image( "http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/splash.png" ) # ship image global ship_info, ship_image ship_info = ImageInfo([45, 45], [90, 90], 35) ship_image = simplegui.load_image( "http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/double_ship.png" ) # missile image - shot1.png, shot2.png, shot3.png global missile_image, missile_info 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 global asteroid_image, asteroid_info 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 global explosion_image, explosion_info 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 # .ogg versions of sounds are also available, just replace .mp3 by .ogg global soundtrack, missile_sound, ship_thrust_sound, explosion_sound soundtrack = simplegui.load_sound( "http://commondatastorage.googleapis.com/codeskulptor-assets/sounddogs/soundtrack.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" )
# implementation of card game - Memory import simplegui import random sound = simplegui.load_sound("http://hangtar.fikszradio.hu/Otorai_tea/2008/Otorai_tea_20080619/07%20-%20Rick%20Astley%20-%20Never%20Gonna%20Give%20You%20Up.mp3") image = simplegui.load_image("http://myhometruths.com/wp-content/uploads/2013/02/rick-astley.jpg") moves = 0 i = 0 index = [0,0] state = 0 card_list1 = range(0,8) card_list2 = range(0,8) main_list = card_list1 + card_list2 exposed_list = [] rick = 0 while i < 16: exposed_list.append(False) i += 1 # helper function to initialize globals def init(): global state, exposed_list i = 0 state = 0 random.shuffle(main_list) for i in range(0,16): exposed_list[i] = False # define event handlers
# missile image - shot1.png, shot2.png, shot3.png 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 - asteroids_blue.png, asteroids_brown.png, asteroids_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") explosion_sound = simplegui.load_sound( "http://commondatastorage.googleapis.com/codeskulptor-assets/sounddogs/explosion.mp3") # helper function to determine distance between p and q def dist(p, q): return math.sqrt((p[0] - q[0]) ** 2 + (p[1] - q[1]) ** 2) # Sprite class class Sprite: def __init__(self, pos, vel, ang, ang_vel, image, info, sound=None): self.pos = [pos[0], pos[1]] self.vel = [vel[0], vel[1]] self.angle = ang self.angle_vel = ang_vel self.image = image
import simplegui as S,math as M,random as R _="_blue" y="http://commondatastorage.googleapis.com/codeskulptor-assets/" j=y+"sounddogs/" q=y+"lathrop/" z=m=t=s=0 W=800 H=600 C=[W/2,H/2] l=3 Z=[0,1] L=lambda s:S.load_image(s+".png") O=lambda s:S.load_sound(s) r=lambda a,b:R.random()*(b-a)+a A=lambda a:[M.cos(a),M.sin(a)] h=O(j+"thrust.mp3") def D(a,b,c,d,e,f,g=0):a.draw_image(b,c,d,e,f,g) class I: def __init__(s,c,z,r=0,l=0,a=0):s.c=c;s.z=z;s.r=r;s.a=a;s.l=l if l else float('inf') class X: def __init__(s,p,v,a,g,i,n,d=0): s.p=p;s.v=v;s.a=a;s.g=g;s.i=i;s.c=n.c;s.z=n.z;s.r=n.r if d:d.rewind();d.play() def d(s,c,a=0):D(c,s.i,[s.c[0]+a,s.c[1]],s.z,s.p,s.z,s.a) def w(s):s.a+=s.g;s.p[1]+=s.v[1];s.p[0]+=s.v[0];s.p[0]%=W;s.p[1]%=H class T(X): def __init__(s,p,v,a,i,n):X.__init__(s,p,v,0,0,i,n);s.t=0 def e(s):s.t=1-s.t;[h.rewind,h.play][s.t]() def f(a): global z;k=A(a.a);p=a.p[:];v=a.v[:] for i in Z:p[i]+=40*k[i];v[i]+=8*k[i]
if key == simplegui.KEY_MAP["space"]: if game_state == 0: game_state = 1 elif game_state == 1: welcome() elif game_state == 3: new_game() game_state = 1 if key == simplegui.KEY_MAP["p"]: comp_mode() #Music laugh_sound = simplegui.load_sound( "http://commondatastorage.googleapis.com/codeskulptor-assets/Evillaugh.ogg" ) #Set frame and handlers frame = simplegui.create_frame("Snake", WIDTH, HEIGHT) frame.set_draw_handler(draw) lh = frame.add_label("Your score: 0") frame.add_label("", 200) ls = frame.add_label("Snake score: 0", 200) frame.add_label("", 200) lt = frame.add_label("Total score: 0/" + str(GRID_SIZE**2), 200) frame.add_label("", 200) frame.add_label("", 200) frame.add_label("", 200) frame.add_label("", 200)
message_colour_timer = simplegui.create_timer(colour_interval, message_colour_tick) message_blink_timer = simplegui.create_timer(blink_interval, message_blink_tick) music_timer = simplegui.create_timer(music_interval, music_tick) # load graphics background = simplegui.load_image("http://www.chloeunrau.com/stuff/es-c.jpg") cheevo5 = simplegui.load_image("http://www.chloeunrau.com/stuff/es-5a.jpg") cheevo10 = simplegui.load_image("http://www.chloeunrau.com/stuff/es-10a.jpg") cheevo25 = simplegui.load_image("http://www.chloeunrau.com/stuff/es-25a.jpg") cheevo50 = simplegui.load_image("http://www.chloeunrau.com/stuff/es-50a.jpg") cheevo100 = simplegui.load_image("http://www.chloeunrau.com/stuff/es-100a.jpg") # load sounds music = simplegui.load_sound("http://www.chloeunrau.com/stuff/music.ogg") music.set_volume(0.5) # music source: # http://www.flashkit.com/ sound_cheevo = simplegui.load_sound( "http://www.chloeunrau.com/stuff/achievement.ogg") sound_cheevo.set_volume(1.0) sound_score = simplegui.load_sound("http://www.chloeunrau.com/stuff/score.ogg") sound_score.set_volume(0.3) sound_fail = simplegui.load_sound("http://www.chloeunrau.com/stuff/fail.ogg") sound_fail.set_volume(0.5) sound_score_streak = simplegui.load_sound( "http://www.chloeunrau.com/stuff/score-streak.ogg") sound_score_streak.set_volume(0.5) sound_reset = simplegui.load_sound("http://www.chloeunrau.com/stuff/reset.ogg") sound_reset.set_volume(1.0)
def get_animated(self): return self.animated # art assets created by Kim Lathrop, may be freely re-used in non-commercial projects, please credit Kim # ship image ship_info = ImageInfo([45, 45], [90, 90], 35) ship_image = simplegui.load_image( "http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/double_ship.png" ) # sound assets purchased from sounddogs.com, please do not redistribute ship_thrust_sound = simplegui.load_sound( "http://commondatastorage.googleapis.com/codeskulptor-assets/sounddogs/thrust.mp3" ) # Ship class class Ship: def __init__(self, pos, vel, angle, image, info): self.pos = [pos[0], pos[1]] self.vel = [vel[0], vel[1]] self.thrust = False self.angle = angle self.angle_vel = 0 self.image = image self.image_center = info.get_center() self.image_size = info.get_size() self.radius = info.get_radius()
import math import time ############################################################################### # INITIALIZE GLOBAL VARIABLES # ############################################################################### # Pixels per inch PPI = 10 game_states = ['menu', '8ball', 'arcade', 'highscores', 'settings', 'how2'] game_state = 'menu' soundtrack_url = \ 'https://s1.vocaroo.com/media/download_temp/Vocaroo_s14kDrIbIZgu.mp3' soundtrack = simplegui.load_sound(soundtrack_url) soundtrack_vol = 0.5 soundtrack_max_vol = 0.5 soundtrack_time = (5 * 60 + 54) * 1000 alt_soundtrack_url = \ 'https://s1.vocaroo.com/media/download_temp/Vocaroo_s1AZW8DJNBY5.mp3' alt_soundtrack = simplegui.load_sound(alt_soundtrack_url) alt_soundtrack_vol = 0.3 alt_soundtrack_max_vol = 0.3 alt_soundtrack_time = (3 * 60 + 26) * 1000 current_soundtrack = soundtrack current_soundtrack_vol = soundtrack_vol current_soundtrack_max_vol = soundtrack_max_vol current_soundtrack_time = soundtrack_time
import simplegui import random # initialize globals - pos and vel encode vertical info for paddles WIDTH = 600 HEIGHT = 400 BALL_RADIUS = 20 PAD_WIDTH = 8 PAD_HEIGHT = 80 HALF_PAD_WIDTH = PAD_WIDTH / 2 HALF_PAD_HEIGHT = PAD_HEIGHT / 2 LEFT = -1 RIGHT = 1 # array of pong sounds to be randomly played SOUNDS = [ simplegui.load_sound("http://empact.io/pong/1.wav"), simplegui.load_sound("http://empact.io/pong/2.wav"), simplegui.load_sound("http://empact.io/pong/3.wav"), simplegui.load_sound("http://empact.io/pong/4.wav"), ] fail = simplegui.load_sound("http://empact.io/pong/loser.mp3") ball_pos = [WIDTH / 2, HEIGHT / 2] ball_vel = [0, 0] paddle1_X = PAD_WIDTH / 2 paddle1_pos = [HEIGHT / 2 - PAD_HEIGHT / 2, HEIGHT / 2 + PAD_HEIGHT / 2] paddle2_X = WIDTH - PAD_WIDTH / 2 paddle2_pos = [HEIGHT / 2 - PAD_HEIGHT / 2, HEIGHT / 2 + PAD_HEIGHT / 2] paddle1_vel = [0, 0] paddle2_vel = [0, 0] player1 = 0
HEIGHT = 600 FIRING_POSITION = [WIDTH // 2, HEIGHT] FIRING_LINE_LENGTH = 60 FIRING_ANGLE_VEL_INC = 0.02 BUBBLE_RADIUS = 20 COLOR_LIST = ["Red", "Green", "Blue", "White"] # global variables firing_angle = math.pi / 2 firing_angle_vel = 0 bubble_stuck = True stuck_bubbles = set([]) # firing sound firing_sound = simplegui.load_sound( "http://commondatastorage.googleapis.com/codeskulptor-assets/Collision8-Bit.ogg" ) # 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) # class defintion for Bubbles class Bubble: def __init__(self, sound):
def timer_handler(): global time global coords time -= 1 if time == 0: timer.stop() coords == [-1,3] frame = simplegui.create_frame("Truck", 1000, 400) frame.set_canvas_background("Pink") frame.set_keydown_handler(key_down) frame.set_keyup_handler(key_up) button = frame.add_button("Pink", color_changer) button = frame.add_button("Red", color_more) button = frame.add_button("Orange", color_yay) button = frame.add_button("Yellow", color_evenmore) button = frame.add_button("Green", color_changeagain) button = frame.add_button("Blue", color_almostdone) button = frame.add_button("Purple", color_last) button = frame.add_button("Play music", icecream_song) button = frame.add_button("Pause music", icecream_stop) button = frame.add_button("Increase volume", song_volumemore) button = frame.add_button("Decrease volume", song_volumeless) sound = simplegui.load_sound('http://commondatastorage.googleapis.com/codeskulptor-assets/Epoq-Lepidoptera.ogg') timer = simplegui.create_timer(500, timer_handler) timer.start() game_stop() sound.set_volume(y) frame.set_draw_handler(draw_handler) 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( "http://commondatastorage.googleapis.com/codeskulptor-assets/sounddogs/soundtrack.mp3" ) missile_sound = simplegui.load_sound( "http://www.sa-matra.net/sounds/starwars/XWing-Laser.wav") missile_sound.set_volume(.5) ship_thrust_sound = simplegui.load_sound( "http://www.sa-matra.net/sounds/starwars/XWing-Fly3.wav") 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)]
# 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( "http://commondatastorage.googleapis.com/codeskulptor-assets/sounddogs/soundtrack.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):
p1scored = simplegui.load_image( 'http://dax.rip/static/files/pong/p1-scored.jpg') p2scored = simplegui.load_image( 'http://dax.rip/static/files/pong/p2-scored.jpg') aiscored = simplegui.load_image( 'http://dax.rip/static/files/pong/ai-scored.jpg') countdown_3 = simplegui.load_image('http://dax.rip/static/files/pong/cd3.jpg') countdown_2 = simplegui.load_image('http://dax.rip/static/files/pong/cd2.jpg') countdown_1 = simplegui.load_image('http://dax.rip/static/files/pong/cd1.jpg') none = simplegui.load_image('') effect_message = none # load music # music is from http://www.flashkit.com/loops/Techno-Dance/Techno/Technola-Billy_Pf-10125/index.php # and is under a Shareware license, with no license details specified by the author music = simplegui.load_sound('http://dax.rip/static/files/pong/music.ogg') music.set_volume(0.7) # load sound effects # All sound effects are from www.freesound.org under a Creative Commons license sound_gutter = simplegui.load_sound( 'http://dax.rip/static/files/pong/gutter.ogg') sound_bounce = simplegui.load_sound( 'http://dax.rip/static/files/pong/bounce.ogg') sound_score = simplegui.load_sound( 'http://dax.rip/static/files/pong/score.ogg') sound_fail = simplegui.load_sound( 'http://dax.rip/static/files/pong/failure.ogg') sound_countdown = simplegui.load_sound( 'http://dax.rip/static/files/pong/countdown.ogg') sound_launch = simplegui.load_sound(
# missile image - shot1.png, shot2.png, shot3.png 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_image1 = simplegui.load_image("http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/explosion_alpha.png") explosion_image2 = simplegui.load_image("http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/explosion_orange.png") # 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("http://commondatastorage.googleapis.com/codeskulptor-assets/sounddogs/soundtrack.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") # free sound assets from freesfx.co.uk # mp3 only high_score_sound = simplegui.load_sound("https://dl-web.dropbox.com/get/correct_sound.mp3?_subject_uid=164632267&w=AADE4aKlfneb1CU_F1vSpKiH17d0K9faxMGCCys47Pug2g") extra_life_sound = simplegui.load_sound("https://dl-web.dropbox.com/get/classic_video_game_level_up.mp3?_subject_uid=164632267&w=AAC-H74Od0kTi5_1LhRA9gpBquGmApd696Zla2BO7hcDDA") death_sound = simplegui.load_sound("https://dl-web.dropbox.com/get/robotic_transition.mp3?_subject_uid=164632267&w=AAAMnZel24Htd3LaHeaBqv7oyllODlNaEiVNBfsNPsahfg") # helper functions to handle transformations def angle_to_vector(ang): return [math.cos(ang), math.sin(ang)] def dist(p, q):
# 2 => MonteCarlo AUTO_RESTART = True # for the AI corners = [(0, 0), (0, 2), (2, 0), (2, 2)] # statistics wins = [0, 0] draws = 0 played = 0 PREFIX = "http://5.189.177.192/info/" # sounds VOLUME = 0.7 errorSound = simplegui.load_sound(PREFIX + 'error.mp3') errorSound.set_volume(VOLUME) plopSound = simplegui.load_sound(PREFIX + 'plop.mp3') plopSound.set_volume(VOLUME) backGroundMusic = simplegui.load_sound(PREFIX + 'background.mp3') backGroundMusic.set_volume(VOLUME) # images speakerQuiet = simplegui.load_image(PREFIX + 'speaker_quiet.png') speakerLoud = simplegui.load_image(PREFIX + 'speaker_loud.png') # boolean flag for whether the animating # rainbow background should be toggled on or not. background = False ####################################################
global success time = 0 attempts=0 success=0 timer.stop() # define event handler for timer with 0.1 sec interval def tick(): global time time = time + 1 def draw(canvas): canvas.draw_text(format(time), [100,100], 36, "White") canvas.draw_text(str(success)+"/"+str(attempts), [275,50], 14, "Green") # create frame frame = simplegui.create_frame("StopWatch", 300,200) # lagniappe - added sound sound = simplegui.load_sound("https://dl-web.dropbox.com/get/Public/ding.wav?w=AABBCdYCqAnKcyluYUs6ndE3MsEMdAWQVdvDfgaeICVdAA") # register event handlers timer = simplegui.create_timer(100, tick) frame.add_button("Start", start, 100) frame.add_button("Stop", stop, 100) frame.add_button("Reset", reset, 100) frame.set_draw_handler(draw) # start timer and frame frame.start()
PONG = Pong() BUTTON_PAUSE.set_text('Pause on') BUTTON_PROTECT_LEFT.set_text('Protect left player') BUTTON_PROTECT_RIGHT.set_text('Protect right player') if SIMPLEGUICS2PYGAME and (_joypads._joypad_nb > 0): # pylint: disable=protected-access # noqa protect_right() else: protect_left() # 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('') BUTTON_PROTECT_LEFT = FRAME.add_button('Protect left player', protect_left, 200) BUTTON_PROTECT_RIGHT = FRAME.add_button('Protect right player', protect_right,
# Mini-project #6 - Blackjack import simplegui import random import math # load card sprite - 949x392 - source: jfitz.com sound1 = simplegui.load_sound("https://www.dropbox.com/s/gpxm5lork4634cs/soundcoin.mp3?dl=1") sound2 = simplegui.load_sound("https://www.dropbox.com/s/xk4bcyw5h5lh3nz/drwa1.mp3?dl=1") play_sound2 = [] WIDTH_SCREEN = 1024 HEIGHT_SCREEN = 700 CARD_SIZE = (73, 98) CARD_CENTER = (36.5, 49) Deck_image = simplegui.load_image("https://www.dropbox.com/s/wblurd2icoik8mf/table.png?dl=1") DECK_SIZE = (1019,703) DECK_SIZE_CENTER = (509.5,351.5) card_images = simplegui.load_image("http://commondatastorage.googleapis.com/codeskulptor-assets/cards.jfitz.png") MOVE_WIDTH = [] MOVE_HEIGHT = [] ROTATE = [] FLIPS = [] ANIMATION = 30 CARD_BACK_SIZE = (71, 96) CARD_BACK_CENTER = (35.5, 48) card_back = simplegui.load_image("http://commondatastorage.googleapis.com/codeskulptor-assets/card_back.png") pos_player = [100,430] pos_computer = [100,100] pos_deck = [900,50] pos_text = [] size_text = 30 #image coin
missile_info = ImageInfo([5, 5], [10, 10], 3, 50) missile_image = simplegui.load_image( "https://dl.dropboxusercontent.com/u/54846026/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( "https://dl.dropboxusercontent.com/u/54846026/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( "https://dl.dropboxusercontent.com/u/54846026/explosion_alpha.png") # sound assets purchased from sounddogs.com, please do not redistribute soundtrack = simplegui.load_sound( "https://dl.dropboxusercontent.com/u/54846026/soundtrack.mp3") missile_sound = simplegui.load_sound( "https://dl.dropboxusercontent.com/u/54846026/missile.mp3") missile_sound.set_volume(.5) ship_thrust_sound = simplegui.load_sound( "https://dl.dropboxusercontent.com/u/54846026/thrust.mp3") explosion_sound = simplegui.load_sound( "https://dl.dropboxusercontent.com/u/54846026/explosion.mp3") # helper functions to handle transformations def angle_to_vector(ang): return [math.cos(ang), math.sin(ang)] # Helper function using pythogrous theorm to find the length of hypthoneus
# missile image - shot1.png, shot2.png, shot3.png 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") # sound assets purchased from sounddogs.com, please do not redistribute #soundtrack = simplegui.load_sound("http://commondatastorage.googleapis.com/codeskulptor-assets/sounddogs/soundtrack.mp3") soundtrack = simplegui.load_sound("http://www.lunerouge.org/sons/sf/LRAngoisse%2001%20by%20Teza.ogg") #missile_sound = simplegui.load_sound("http://commondatastorage.googleapis.com/codeskulptor-assets/sounddogs/missile.mp3") missile_sound = simplegui.load_sound("http://www.lunerouge.org/sons/engins/LR9mm%20one%20shot%20by%20Lionel%20Allorge.ogg") missile_sound.set_volume(.5) #ship_thrust_sound = simplegui.load_sound("http://commondatastorage.googleapis.com/codeskulptor-assets/sounddogs/thrust.mp3") ship_thrust_sound = simplegui.load_sound("http://www.lunerouge.org/sons/engins/LRThruster%201%20by%20Lionel%20Allorge.ogg") ship_thrust_sound.set_volume(.5) 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)]
# Global constants WIDTH = 800 HEIGHT = 600 FIRING_POSITION = [WIDTH // 2, HEIGHT] FIRING_LINE_LENGTH = 60 FIRING_ANGLE_VEL_INC = 0.02 BUBBLE_RADIUS = 20 COLOR_LIST = ["Red", "Green", "Blue", "White"] # global variables firing_angle = math.pi / 2 firing_angle_vel = 0 bubble_stuck = True # firing sound firing_sound = simplegui.load_sound("http://commondatastorage.googleapis.com/codeskulptor-assets/Collision8-Bit.ogg") # 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) # class defintion for Bubbles class Bubble: def __init__(self, sound = None): self.pos = list(FIRING_POSITION)
# define timers timer = simplegui.create_timer(stopwatch_interval, tick) message_colour_timer = simplegui.create_timer(colour_interval, message_colour_tick) message_blink_timer = simplegui.create_timer(blink_interval, message_blink_tick) music_timer = simplegui.create_timer(music_interval, music_tick) # load graphics background = simplegui.load_image("http://www.chloeunrau.com/stuff/es-c.jpg") cheevo5 = simplegui.load_image("http://www.chloeunrau.com/stuff/es-5a.jpg") cheevo10 = simplegui.load_image("http://www.chloeunrau.com/stuff/es-10a.jpg") cheevo25 = simplegui.load_image("http://www.chloeunrau.com/stuff/es-25a.jpg") cheevo50 = simplegui.load_image("http://www.chloeunrau.com/stuff/es-50a.jpg") cheevo100 = simplegui.load_image("http://www.chloeunrau.com/stuff/es-100a.jpg") # load sounds music = simplegui.load_sound("http://www.chloeunrau.com/stuff/music.ogg") music.set_volume(0.5) # music source: # http://www.flashkit.com/ sound_cheevo = simplegui.load_sound("http://www.chloeunrau.com/stuff/achievement.ogg") sound_cheevo.set_volume(1.0) sound_score = simplegui.load_sound("http://www.chloeunrau.com/stuff/score.ogg") sound_score.set_volume(0.3) sound_fail = simplegui.load_sound("http://www.chloeunrau.com/stuff/fail.ogg") sound_fail.set_volume(0.5) sound_score_streak = simplegui.load_sound("http://www.chloeunrau.com/stuff/score-streak.ogg") sound_score_streak.set_volume(0.5) sound_reset = simplegui.load_sound("http://www.chloeunrau.com/stuff/reset.ogg") sound_reset.set_volume(1.0) sound_game_over = simplegui.load_sound("http://www.chloeunrau.com/stuff/game-over.ogg") sound_game_over.set_volume(1.0)
CARDS = X_CARDS * Y_CARDS CARD_WIDTH = 150 CARD_HEIGHT = 175 X_PAD = 20 Y_PAD = 20 SLOT_WIDTH = CARD_WIDTH + X_PAD SLOT_HEIGHT = CARD_HEIGHT + Y_PAD # define media assets FRONT_IMAGE = simplegui.load_image('http://i.istockimg.com/file_thumbview_approve/6910013/2/stock-illustration-6910013-slot-symbols.jpg') FRONT_IMAGE_BW = simplegui.load_image('https://dl.dropboxusercontent.com/u/1237849/stock-illustration-6910013-slot-symbols-black-and-white.jpg') FRONT_IMAGE_POS = { 0: (67, 70), 1: (193, 69), 2: (310, 69), 3: (65, 191), 4: (311, 313), 5: (311, 191), 6: (66, 313), 7: (190, 313) } BACK_IMAGE = simplegui.load_image('http://media-hearth.cursecdn.com/attachments/2/101/cardback-rankedladder.png') CARD_FLIP_SOUND = simplegui.load_sound('http://www.soundrangers.com/demos/gambling/card_deal02.mp3') # helper function to initialize globals def new_game(): global cards, exposed, state, card_clicked, card1, card2, match, turns, matched cards = list(range(CARDS / 2)) + list(range(CARDS / 2)) random.shuffle(cards) exposed = [False for i in range(CARDS)] matched = [False for i in range(CARDS)] state = 0 turns = 0 card_clicked = None card1 = None card2 = None match = False
music.set_volume(vol / 10.0) volume_button.set_text("Volume = " + str(vol)) # create frame - canvas will be blank frame = simplegui.create_frame("Music demo", 250, 250, 100) # set up control elements frame.add_button("play", play,100) frame.add_button("pause", pause,100) frame.add_button("rewind",rewind,100) frame.add_button("laugh",laugh,100) frame.add_button("Vol down", vol_down,100) frame.add_button("Vol up", vol_up,100) # initialize volume, create button whose label will display the volume vol = 7 volume_button = frame.add_label("Volume = " + str(vol)) # load some sounds music = simplegui.load_sound("http://commondatastorage.googleapis.com/codeskulptor-assets/Epoq-Lepidoptera.ogg") laugh = simplegui.load_sound("http://commondatastorage.googleapis.com/codeskulptor-assets/Evillaugh.ogg") # make the laugh quieter so my ears don't bleed laugh.set_volume(.1) frame.start()
global paddle1_vel, paddle2_vel if key == simplegui.KEY_MAP["w"]: paddle1_vel[1] = 0 if key == simplegui.KEY_MAP["s"]: paddle1_vel[1] = 0 if key == simplegui.KEY_MAP["up"]: paddle2_vel[1] = 0 if key == simplegui.KEY_MAP["down"]: paddle2_vel[1] = 0 # create frame frame = simplegui.create_frame("Pong", WIDTH, HEIGHT) frame.add_button('Restart', restart, 100) frame.set_draw_handler(draw) frame.set_keydown_handler(keydown) frame.set_keyup_handler(keyup) # Add sounds sound = simplegui.load_sound( 'https://archive.org/download/EvilLaughMale_201506/Evil_Laugh_Male.wav') pongsound = simplegui.load_sound( 'https://archive.org/download/pingpong_ball_bounce_201506/pingpong_ball_bounce.wav' ) sound.set_volume(0.7) pongsound.set_volume(0.7) # start frame new_game() frame.start()
ship_image = simplegui.load_image("http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/double_ship.png") # missile image - shot1.png, shot2.png, shot3.png missile_info = ImageInfo([5,5], [10, 10], 3, 75) 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") # sound assets purchased from sounddogs.com, please do not redistribute soundtrack = simplegui.load_sound("http://commondatastorage.googleapis.com/codeskulptor-assets/sounddogs/soundtrack.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") ## CC 3.0 sound file by Jesus Lastra, http://opengameart.org/content/8-bit-pickup-1 extra_life_sound = simplegui.load_sound("http://mwales.net/junk/SFX_Pickup_44.mp3") # helper functions to handle transformations def angle_to_vector(ang): return [math.cos(ang), math.sin(ang)] def vector_to_angle(v): return math.atan2(v[0],v[1])
"https://dl.dropboxusercontent.com/u/15465715/python_resources/ricerocks/asteroid.png" ) dstar_image = simplegui.load_image( "https://dl.dropboxusercontent.com/u/15465715/python_resources/ricerocks/d_star.png" ) evil_image = simplegui.load_image( "https://dl.dropboxusercontent.com/u/15465715/python_resources/ricerocks/evil.png" ) # animated explosion 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://dl.dropboxusercontent.com/u/15465715/python_resources/ricerocks/ost1.mp3" ) missile_sound = simplegui.load_sound( "https://dl.dropboxusercontent.com/u/15465715/python_resources/ricerocks/shot.wav" ) 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" ) explosion_sound.set_volume(.5) # helper functions
# 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 # .ogg versions of sounds are also available, just replace .mp3 by .ogg soundtrack = simplegui.load_sound( "https://dl.dropbox.com/s/ufp49dj57hmews8/Dragon%20Ball%20Z%20Budokai%203%20Theme%20Song%20Japanese%20Version.ogg?dl=0" ) 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" ) # alternative upbeat soundtrack by composer and former IIPP student Emiel Stopler # please do not redistribute without permission from Emiel at http://www.filmcomposer.nl #soundtrack = simplegui.load_sound("https://storage.googleapis.com/codeskulptor-assets/ricerocks_theme.mp3")
ship_image = simplegui.load_image(ASSETS_PATH + "lathrop/double_ship.png") # missile image - shot1.png, shot2.png, shot3.png missile_info = ImageInfo([5,5], [10, 10], 3, 50) missile_image = simplegui.load_image(ASSETS_PATH + "lathrop/shot1.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(ASSETS_PATH + "lathrop/asteroid_blend.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(ASSETS_PATH + "lathrop/explosion_alpha.png") # sound assets purchased from sounddogs.com, please do not redistribute soundtrack = simplegui.load_sound(ASSETS_PATH + "sounddogs/soundtrack.mp3") missile_sound = simplegui.load_sound(ASSETS_PATH + "sounddogs/missile.mp3") missile_sound.set_volume(.5) ship_thrust_sound = simplegui.load_sound(ASSETS_PATH + "sounddogs/thrust.mp3") explosion_sound = simplegui.load_sound(ASSETS_PATH + "sounddogs/explosion.mp3") class Sprite: def __init__(self, pos, vel, ang, ang_vel, image, info, sound = None): self.pos = [pos[0],pos[1]] self.vel = [vel[0],vel[1]] self.angle = ang self.angle_vel = ang_vel self.image = image self.image_center = info.get_center() self.image_size = info.get_size()
ship_image = simplegui.load_image("https://dl.dropboxusercontent.com/u/21868561/images/x-wing_double.png") # missile image - shot1.png, shot2.png, shot3.png missile_info = ImageInfo([5,5], [10, 10], 3, 50) missile_image = simplegui.load_image("https://dl.dropboxusercontent.com/u/21868561/images/photon.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") # sound assets purchased from sounddogs.com, please do not redistribute soundtrack = simplegui.load_sound("http://commondatastorage.googleapis.com/codeskulptor-assets/sounddogs/soundtrack.mp3") missile_sound = simplegui.load_sound("http://www.sa-matra.net/sounds/starwars/XWing-Laser.wav") ship_thrust_sound = simplegui.load_sound("http://www.sa-matra.net/sounds/starwars/XWing-Fly3.wav") explosion_sound = simplegui.load_sound("https://dl.dropboxusercontent.com/u/21868561/sfx/torpedo-hit.mp3") explode_asteroid = simplegui.load_sound("https://dl.dropboxusercontent.com/u/21868561/sfx/d-charge-short.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) def process_sprite_group(canvas, group): sprite_set = set(group) for sprite in sprite_set:
def declarations(): '''I zipped all these up into a function because they are really ugly to look at and now I can collapse them as I work :D''' global debris_info, debris_image, \ nebula_info, nebula_image, \ splash_info, splash_image, \ ship_info, ship_image, \ missile_info, missile_image, \ asteroid_info, asteroid_image, \ explosion_info, explosion_image, \ soundtrack, missile_sound, ship_thrust_sound, explosion_sound # IMAGES # art assets created by Kim Lathrop, may be freely re-used in non-commercial projects, please credit Kim # debris images: debris1_brown.png, debris2_brown.png, debris3_brown.png, debris4_brown.png # debris1_blue.png, debris2_blue.png, debris3_blue.png, debris4_blue.png, debris_blend.png debris_info = ImageInfo([320, 240], [640, 480]) debris_image = simplegui.load_image(\ "http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/debris2_blue.png") # nebula images - nebula_brown.png, nebula_blue.png nebula_info = ImageInfo([400, 300], [800, 600]) nebula_image = simplegui.load_image(\ "http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/nebula_blue.f2014.png") # splash image splash_info = ImageInfo([200, 150], [400, 300]) splash_image = simplegui.load_image("\ http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/splash.png" ) # ship image ship_info = ImageInfo([45, 45], [90, 90], 35) ship_image = simplegui.load_image( "https://dl.dropbox.com/s/ezp7v5d7ti7dhpg/spaceship.png") #PDK #"http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/double_ship.png") # missile image - shot1.png, shot2.png, shot3.png missile_info = ImageInfo([5, 5], [10, 10], 3, 120) 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( "https://dl.dropbox.com/s/gvja7maw8ppthe9/asteroid.png") #PDK #"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") # SOUNDS # sound assets purchased from sounddogs.com, please do not redistribute # alternative upbeat soundtrack by composer and former IIPP student Emiel Stopler # please do not redistribute without permission from Emiel at http://www.filmcomposer.nl #soundtrack = simplegui.load_sound("https://storage.googleapis.com/codeskulptor-assets/ricerocks_theme.mp3") soundtrack = simplegui.load_sound(\ "http://commondatastorage.googleapis.com/codeskulptor-assets/sounddogs/soundtrack.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")
ship_image = simplegui.load_image("http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/double_ship.png") # missile image - shot1.png, shot2.png, shot3.png 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") # sound assets purchased from sounddogs.com, please do not redistribute soundtrack = simplegui.load_sound("http://commondatastorage.googleapis.com/codeskulptor-assets/sounddogs/soundtrack.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(angle): return [math.cos(angle), math.sin(angle)] def distance(p,q): return math.sqrt((p[0] - q[0]) ** 2 + (p[1] - q[1]) ** 2) def process_sprite_group(canvas, sprite_group): collisions = set([]) for sprite in sprite_group:
# 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" ) # alternative upbeat soundtrack by composer and former IIPP student Emiel Stopler # please do not redistribute without permission from Emiel at http://www.filmcomposer.nl soundtrack = simplegui.load_sound( "https://storage.googleapis.com/codeskulptor-assets/ricerocks_theme.mp3") # Ship class class Ship: def __init__(self, pos, vel, angle, image, info, sound=None): self.pos = [pos[0], pos[1]] self.vel = [vel[0], vel[1]] self.thrust = False self.angle = angle self.angle_vel = 0 self.image = image self.image_center = info.get_center() self.image_size = info.get_size() self.radius = info.get_radius() self.missile_group = set([])