# 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):
return self.radius 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_centre = info.get_centre() self.image_size = info.get_size() self.radius = info.get_radius() def draw(self, canvas):
asteroid_image.append(simplegui.load_image("http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/asteroid_brown.png")) asteroid_image.append(simplegui.load_image("http://commondatastorage.googleapis.com/codeskulptor-assets/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_alpha = simplegui.load_image("http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/explosion_alpha.png") explosion_image_orange = simplegui.load_image("http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/explosion_orange.png") # list of blue explosions explosion_image_blue = list() explosion_image_blue.append(simplegui.load_image("http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/explosion_blue.png")) explosion_image_blue.append(simplegui.load_image("http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/explosion_blue2.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") # 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 class Ship:
# define draw handler def draw_handler(canvas): '''This draw handlers draw the training stop watch, the resting stop watch and the interval number''' canvas.draw_text(workout_watch(training_minutes),[110,180], 60, "White") canvas.draw_text(resting_watch(resting_seconds),[110,330], 60, "Yellow") canvas.draw_text(interval(interval_num),[345,60], 40, "Green") # create frame frame = simplegui.create_frame('Stop Watch: The Game', 400, 400) # create sound variables go = simplegui.load_sound('https://www.dropbox.com/s/qwj153wzm7derup/lets_go.ogg?dl=1') rest = simplegui.load_sound('https://www.dropbox.com/s/m921ljc4whji8pc/rest.ogg?dl=1') # register event handlers timer = simplegui.create_timer(100, timer_handler) frame.set_draw_handler(draw_handler) #frame.set_draw_handler() frame.add_button("Start", start, 80) frame.add_button("Stop", stop, 80) frame.add_button("Reset", reset, 80) frame.add_input('Excercise, Enter Minutes',train_input_handler,140) frame.add_input('Rest, Enter Seconds',rest_input_handler,140) frame.add_input('intervals',intervals_input_handler,140)
# missile image - shot1.png, shot2.png, shot3.png missile_info = ImageInfo([5,5], [10, 10], 3, 50) missile_image = simplegui.load_image("https://dl.dropbox.com/s/mopmaasmcw4s2le/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/rrbr4nx1g5nsmrh/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.dropbox.com/s/77tmkiovimuukvl/explosion_alpha.png") # sound assets purchased from sounddogs.com, please do not redistribute # soundtrack = simplegui.load_sound("https://dl.dropbox.com/s/pb3gk4umf2gw0p6/soundtrack.mp3") missile_sound = simplegui.load_sound("https://www.dropbox.com/s/qy740p7a25vujhp/missile.mp3") missile_sound.set_volume(.5) ship_thrust_sound = simplegui.load_sound("https://dl.dropbox.com/s/5kztd3jqw2buy98/thrust.mp3") # explosion_sound = simplegui.load_sound("https://dl.dropbox.com/s/1cs4483k0hivthh/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 class Ship: def __init__(self, pos, vel, angle, image, info, sound = None):
if vol < 10: vol = vol + 1 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()
paddle2_vel -= 8 key_type[1]="up" def keyup(key): global paddle1_vel, paddle2_vel if key == simplegui.KEY_MAP["s"]: paddle1_vel = 0 if key == simplegui.KEY_MAP["w"]: paddle1_vel = 0 if key == simplegui.KEY_MAP["down"]: paddle2_vel = 0 if key == simplegui.KEY_MAP["up"]: paddle2_vel = 0 # create frame frame = simplegui.create_frame("Pong", WIDTH, HEIGHT) frame.set_draw_handler(draw) frame.set_keydown_handler(keydown) frame.set_keyup_handler(keyup) sound = simplegui.load_sound("http://www.freesoundeffects.com/pirsounds/PD_SOUNDFX/BEEPS/BEEPPURE.WAV") button = frame.add_button("Restart", new_game, 100) # start frame frame.start() direction = random.randrange(0, 2) if direction == 1: ball_init("true") else: ball_init("flase")
# 创建窗口 # 8强共16张图片,每个图片的显示大小为128x128像素 # 16张图片显示为4行4列,因此窗口的宽度为128x4=512像素,高度为128x4=512像素 frame = simplegui.create_frame("2014巴西世界杯8强连连看", 512, 512) frame.add_button("重新开始", new_game, 100) label = frame.add_label("回合次数 = 0") # 注册事件处理函数 frame.set_mouseclick_handler(mouseclick) frame.set_draw_handler(draw) # 读取图片 background_image = simplegui.load_image("images\\background.png") logo_image = simplegui.load_image("images\\Logo.png") flag_image.append(simplegui.load_image("images\\Argentina.png")) flag_image.append(simplegui.load_image("images\\Belgium.png")) flag_image.append(simplegui.load_image("images\\Brazil.png")) flag_image.append(simplegui.load_image("images\\Colombia.png")) flag_image.append(simplegui.load_image("images\\Costa-rica.png")) flag_image.append(simplegui.load_image("images\\France.png")) flag_image.append(simplegui.load_image("images\\Germany.png")) flag_image.append(simplegui.load_image("images\\Netherlands.png")) # 读取世界杯之歌 background_sound = simplegui.load_sound("sound\\We_Are_One.ogg") # 启动游戏 new_game() frame.start()
bonus_image2 = simplegui.load_image(BONUS2) bonus_image3 = simplegui.load_image(BONUS3) bonus_image4 = simplegui.load_image(BONUS4) # 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(EXPLOSION) # bonus seconds = 0 timer3 = None immortal = False scoreBonus = False # ------------------- SOUNDS ------------------------# soundtrack = simplegui.load_sound(SOUNDTRACK) explosion_sound = simplegui.load_sound(EXPLOSIONSOUND) tick_tock_sound = simplegui.load_sound(TICKTOCKSOUND) asteroid_image = simplegui.load_image(ASTEROID) # 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(EXPLOSION) # ------------------- SOUNDS ------------------------# # purchased from sounddogs.com soundtrack = simplegui.load_sound(SOUNDTRACK) explosion_sound = simplegui.load_sound(EXPLOSIONSOUND) def process_sprite_group(group, canvas): copy = group.copy()
arrow_info = ImageInfo([21, 5], [42, 10],5,60) arrow_image = simplegui.load_image("resources/arrow.png") # 箭 castle_info = ImageInfo([54, 52], [109, 105],50) castle_image = simplegui.load_image("resources/castle.png") # 城堡 enemy_info = ImageInfo([32, 15], [64, 29], 15, 1000, True) enemy_image = simplegui.load_image("resources/enemy.png") # 敌人,图像文件中包含4副图片用来实现动画 soldier_info = ImageInfo([32, 26], [64, 52]) soldier_image = simplegui.load_image("resources/soldier.png") # 战士,图像文件中包含2副图片用来实现动画 win_info = ImageInfo([320, 240], [640, 480]) win_image = simplegui.load_image("resources/win.png") # 游戏成功 gameover_info = ImageInfo([320, 240], [640, 480]) gameover_image = simplegui.load_image("resources/gameover.png") # 游戏结束 explosion_info = ImageInfo([64, 64], [128, 128], 17, 24, True) explosion_image = simplegui.load_image("resources/explosion.png") # 爆炸,图像文件中包含多副图片用来实现动画 back_sound = simplegui.load_sound("resources/moonlight.wav") # 背景音乐 shoot_sound = simplegui.load_sound("resources/shoot.wav") # 箭发射声音 explode_sound = simplegui.load_sound("resources/explode.wav") # 箭击中敌人的声音 enemy_sound = simplegui.load_sound("resources/enemy.wav") # 敌人击中城堡的声音 # helper functions to calculate distance of two points def dist(p,q): return math.sqrt((p[0] - q[0]) ** 2+(p[1] - q[1]) ** 2) # helper functions to process multiple process def process_sprite_group(sprites,canvas): set_sprites = set(sprites) for sprite in set_sprites: sprite.draw(canvas) if not gameover and not success: if not sprite.update():
#index_image = [0,1,2] turns = 0 #表示局数 score1,score2 = 0, 0 #得分 started = False #控制是否进入游戏界面 mouse_pos =(0,0) message = "" #屏幕上显示输赢的信息 background1_image = simplegui.load_image("images\\background1.png") background2_image = simplegui.load_image("images\\background2.png") start_image = simplegui.load_image("images\\start.png") gesture_image.append(simplegui.load_image("images\\scissors.png")) gesture_image.append(simplegui.load_image("images\\stone.png")) gesture_image.append(simplegui.load_image("images\\cloth.png")) choice_image.append(simplegui.load_image("images\\stone.png")) choice_image.append(simplegui.load_image("images\\stone.png")) background_sound = simplegui.load_sound("sound\\sound1.ogg") # 定义函数 #定义事件处理函数 def newgame(): global turns, score1, score2, message turns = 0 score1,score2 = 0, 0 #choice_image.append(gesture_image[1]) #choice_image.append(gesture_image[1]) background_sound.rewind() background_sound.play() message = "" def clicked_card(point): return (point[0]-38) // image_size[0] -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://raw.githubusercontent.com/EduIbanez/introduction-programming-python/master/mini-project-7/images/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://raw.githubusercontent.com/EduIbanez/introduction-programming-python/master/mini-project-7/images/explosion_alpha.png" ) # sound assets purchased soundtrack = simplegui.load_sound( "https://raw.githubusercontent.com/EduIbanez/introduction-programming-python/master/mini-project-7/audio/soundtrack.ogg" ) missile_sound = simplegui.load_sound( "https://raw.githubusercontent.com/EduIbanez/introduction-programming-python/master/mini-project-7/audio/missile.ogg" ) missile_sound.set_volume(0.5) ship_thrust_sound = simplegui.load_sound( "https://raw.githubusercontent.com/EduIbanez/introduction-programming-python/master/mini-project-7/audio/thrust.ogg" ) explosion_sound = simplegui.load_sound( "https://raw.githubusercontent.com/EduIbanez/introduction-programming-python/master/mini-project-7/audio/explosion.ogg" ) # helper functions to handle transformations def angle_to_vector(ang):
bullet_info = ImageInfo([6, 10], [12, 20], 6, 50) bullet_image = simplegui.load_image("image\\bullet.png") #敌机2图像 enemy2_info = ImageInfo([24, 18], [48, 36],24) enemy2_image = simplegui.load_image("image\\enemy2.png") #敌机3图像 enemy3_info = ImageInfo([24, 108], [48, 216]) enemy3_image = simplegui.load_image("image\\enemy3.png") #敌机1爆炸图像 enemy1_explosion_info = ImageInfo([35, 45], [70, 90], 35, 4, True) enemy1_explosion_image = simplegui.load_image("image\\enemy1_exp.png") #敌机2爆炸图像 enemy2_explosion_info = ImageInfo([24, 18], [48, 36],24, 4, True) enemy2_explosion_image = simplegui.load_image("image\\enemy2_exp.png") #爆炸声音 explosion_sound = simplegui.load_sound("sound\\enemy2_down.wav") #游戏结束声音 gameover_sound = simplegui.load_sound("sound\\game_over.wav") gameover_sound.set_volume(.2) #子弹声音 bullet_sound = simplegui.load_sound("sound\\bullet.wav") bullet_sound.set_volume(.2) #游戏声音 gamemusic_sound = simplegui.load_sound("sound\\game_music.wav") gamemusic_sound.set_volume(.2) # 计算两点之间距离 def dist(p, q): return math.sqrt((p[0] - q[0]) ** 2 + (p[1] - q[1]) ** 2) # 子弹类
import simpleguitk as simplegui #win #import SimpleGUICS2Pygame.simpleguics2pygame as simplegui #linux from Sprite import Sprite from ImageInfo import ImageInfo from Utils import Utils from Constants import * ship_thrust_sound = simplegui.load_sound(THRUST) # missile image - shot1.png, shot2.png, shot3.png missile_info = ImageInfo([5,5], [10, 10], 3, 150) missile_image = simplegui.load_image(SHOT) missile_sound = simplegui.load_sound(MISSILE) FRICTION = 0.97 FACTOR = 2 ship_thrust_sound = simplegui.load_sound(THRUST) # missile image - shot1.png, shot2.png, shot3.png missile_info = ImageInfo([5,5], [10, 10], 3, 150) missile_image = simplegui.load_image(SHOT) missile_sound = simplegui.load_sound(MISSILE) missile_sound.set_volume(.5) # Ship class class Ship: def __init__(self, pos, vel, angle, image, info, Wwith, WHeight): self.pos = [pos[0],pos[1]]