def __init__(self, pos): self.center_x = pos self.y_top = random.randrange(PIPE_HEAD_HEIGHT * 2, GAME_HEIGHT - PIPE_OPENING_HEIGHT - (PIPE_HEAD_HEIGHT * 2)) self.y_bottom = self.y_top + PIPE_OPENING_HEIGHT self.is_stop = True self.is_passed = False self.pipe_body_image = simplegui.load_image(PIPE_BODY_IMAGE) self.pipe_head_down_image = simplegui.load_image(PIPE_HEAD_DOWN_IMAGE) self.pipe_head_up_image = simplegui.load_image(PIPE_HEAD_UP_IMAGE)
def start(): global lives, score, time, started, debris_image, nebula_image lives = 3 score = 0 time = 0 timer.start() soundtrack.play() started = True debris_image = simplegui.load_image("http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/debris3_brown.png") nebula_image = simplegui.load_image("http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/nebula_blue.png")
def init(self): global card_images, card_back, score card_images = simplegui.load_image("http://commondatastorage.googleapis.com/codeskulptor-assets/cards.jfitz.png") card_back = simplegui.load_image("http://commondatastorage.googleapis.com/codeskulptor-assets/card_back.png") self.deal() # Score is just reset at start of game score = 0 return
def __init__(self, pos): self.width = PIPE_WIDTH self.center_x = pos self.y_top = random.randrange(70, STAGE_HEIGHT - PIPE_GAP_Y - 70) self.y_bottom = self.y_top + PIPE_GAP_Y self.is_stop = True self.is_passed = False self.body_image = simplegui.load_image("https://raw.github.com/ben7th/flappy-html5-bird/gh-pages/ui/images/pipe_body.png") self.head1_image = simplegui.load_image("https://raw.github.com/ben7th/flappy-html5-bird/gh-pages/ui/images/pipe_head_1.png") self.head2_image = simplegui.load_image("https://raw.github.com/ben7th/flappy-html5-bird/gh-pages/ui/images/pipe_head_2.png")
def build_game(self): # create timer and frame self.frame = simplegui.create_frame("Blackjack", CANVAS_W, CANVAS_H) self.cards_url = simplegui.load_image("http://commondatastorage.googleapis.com/codeskulptor-assets/cards.jfitz.png") self.card_back = simplegui.load_image("http://commondatastorage.googleapis.com/codeskulptor-assets/card_back.png") # register event handlers self.frame.add_button(" Deal ", self.deal, 100) self.frame.add_button(" Hit ", self.hit, 100) self.frame.add_button(" Stand ", self.stand, 100) self.frame.set_draw_handler(self.draw_handler) self.frame.set_canvas_background("Green") # start frame self.frame.start()
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 rock_spawner(): if asteroids.started: if len(asteroids.rock_group) <12: if asteroids.time % 100 == 0: rock_pos = [random.randrange(0, asteroids.width), random.randrange(0, asteroids.height)] rock_vel = [random.random() * .6 - .3, random.random() * .6 - .3] rock_avel = random.random() * .2 - .1 url = "http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/" url_asteroid_1 = url + "asteroid_blue.png" url_asteroid_2 = url + "asteroid_brown.png" url_asteroid_3 = url + "asteroid_blend.png" urls = [url_asteroid_1, url_asteroid_2, url_asteroid_3] print str(random.choice(urls)) asteroid_image = simplegui.load_image(str(random.choice(urls))) new_set = [] print "new pos", new_set for p in group_of_players: if (dist(rock_pos, p.pos) > p.radius + asteroid_info.radius): new_set.append (True) else: new_set.append(False) print new_set # for n in new_set: if new_set[len(new_set)-1] == True and new_set[0] == True: a_rock = Sprite(rock_pos, rock_vel, 0, rock_avel, asteroid_image, asteroid_info) asteroids.rock_group.add(a_rock)
def __init__(self): self.tl = ( 400, 770 - 182 ) self.br = ( 400 + 150 , 770 ) #Rectangle.__init__(self,tl,br) url3 = 'https://lh3.googleusercontent.com/-ISPY4T0J2Kw/VQuHOqIHB9I/AAAAAAAAHw8/p-8OF-7fayc/w150-h182-no/waste.png' self.garbage = simplegui.load_image(url3)
def draw(self, canvas): if self.destroy == False: canvas.draw_image(self.image, self.image_center, self.image_size, self.pos, self.image_size, self.angle) if dist(self.pos, self.lifespan) > 300: if self.radius < 10: missile_group.remove(self) if self.destroy == True: if self.time1<25: explosion_image = simplegui.load_image("http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/explosion_alpha.png") EXPLOSION_CENTER = [64, 64] EXPLOSION_SIZE = [128, 128] EXPLOSION_DIM = [24, 9] explosion_index = [self.time1 % EXPLOSION_DIM[0], 0] canvas.draw_image(explosion_image, [EXPLOSION_CENTER[0] + explosion_index[0] * EXPLOSION_SIZE[0], EXPLOSION_CENTER[1] + explosion_index[1] * EXPLOSION_SIZE[1]], EXPLOSION_SIZE, self.pos, EXPLOSION_SIZE) self.time1+=1 else: self.time1=0 rock_group.remove(self) if self.destroy == False and self.radius > 10: for m in missile_group: if dist(self.pos, m.pos) < self.radius + m.radius: self.destroy_itself() explosion_sound.rewind() explosion_sound.play() m.destroy_itself()
def init(): global WIDTH, HEIGHT, number_cards, cards, flipped, game_state, moves global image_atlas, image_coords WIDTH = 150 * 4 HEIGHT = 150 * 4 number_cards = 16 # 4x4=16 cards = list() for i in range(number_cards // 2): for j in range(2): card = Card() card.value = i cards.append(card) random.shuffle(cards) # unsort card list flipped = list() # list of flipped cards game_state = False moves = 0 # number of moves image_atlas = simplegui.load_image("http://goo.gl/0Ea0R") # card image image_coords = {"0": ((100, 100), (200, 200)), "1": ((300, 100), (200, 200)), "2": ((500, 100), (200, 200)), "3": ((100, 300), (200, 200)), "4": ((300, 300), (200, 200)), "5": ((500, 300), (200, 200)), "6": ((100, 500), (200, 200)), "7": ((300, 500), (200, 200)), "8": ((500, 500), (200, 200))}
def draw_tops(canvas): # Draws the blank tops and if the length of the top is greater # than 0 it draws the last card in the top global top0, top1, top2, top3 TOPBLANK = simplegui.load_image('http://i.imgur.com/MOQhHbc.png') CARDWIDTH = TOPBLANK.get_width() CARDHEIGHT = TOPBLANK.get_height() DRAWSCALE = 1.1 LOC_BACK_Y = 76 START_X = 500 DIST_BETWEEN = 100 top_dict = [top0, top1, top2, top3] for tops in range(4): LOC_BACK_X = START_X + DIST_BETWEEN * tops canvas.draw_image(TOPBLANK, (CARDWIDTH /2 , CARDHEIGHT / 2), (CARDWIDTH, CARDHEIGHT), (LOC_BACK_X, LOC_BACK_Y), (CARDWIDTH * DRAWSCALE, CARDHEIGHT * DRAWSCALE)) if len(top_dict[tops]) > 0: top_dict[tops][-1].set_X(LOC_BACK_X) top_dict[tops][-1].set_Y(LOC_BACK_Y) top_dict[tops][-1].get_cardfront(canvas)
def __init__(self, url, size, animated = False, layout = "horizontal", n_tiled = [1]): """The data like size, animated, etc. are not valid for another image source, so why not integrate the image url into the class. :url: @ imaage url :size: @ size of one tiled image, may not be the full size of image source :animated: @ will it automatically iterate through tiled images when drawing :layout: @ geometry indexing of tiled images :n_tiled: @ number of tiled images in each dimensions get_center(*indexes) @ get the center coordinates according to indexes draw(canvas, pos, output_size, *indexes) @ draw image on canvas at pos with output_size. """ self.img = simplegui.load_image(url) self.size = size self._center = [l // 2 for l in size] self.animated = animated self.layout = layout self.n_tiled = n_tiled if animated: # cache the current displayed tiled image's index self.tiled_pos = [0] * len(n_tiled) if len(self.n_tiled) < len(self.size): # because I can't use izip_longest self.n_tiled += [float('inf')] * (len(self.size) - len(self.n_tiled))
def guess_a_letter(guess): global correct_input, guessed_letter, cnt, guessed_letters, word, missed_letters, guess_result, warning_msg, result_msg, hangmanpic, guess_result_str, missed_letters_str, image if result_msg == "": if cnt < 6: correct_input = False if len(guess) != 1: warning_msg = "*ONLY ONE* letter!" elif not ('a' <= guess.lower() <= 'z'): warning_msg = "a *LETTER*!" elif guess in guessed_letters: warning_msg = "Already guessed!" else: guessed_letters += guess.lower() warning_msg = "" correct_input = True if correct_input: new_guess_result = "" if guess in word: for i in range(0, len(word)): if word[i] == guess: new_guess_result += guess else: new_guess_result += guess_result[i] guess_result = new_guess_result else: missed_letters += guess cnt += 1 image = simplegui.load_image("https://dl.dropboxusercontent.com/u/52743103/hangman/hangman" + str(cnt) + ".jpg") guess_result_str = add_underline(guess_result) missed_letters_str = "Missed letter: " + missed_letters if guess_result == word: result_msg = "You win!" elif cnt == 6: result_msg = "You lose!"
def __init__(self): self.speed = 0 self.gravity = 0 self.is_dead = False self.width = BIRD_WIDTH self.height = BIRD_HEIGHT self.set_pos(99, 237) self.image = simplegui.load_image("https://github.com/ben7th/flappy-html5-bird/blob/gh-pages/ui/images/bird.png?raw=true")
def loadImages(): global imageMap global imageList global facedownImage # Make 1 single list of all image names for key in IMAGE_NAME_MAP: print "Adding " + key + " to image list" print "Adding " + IMAGE_NAME_MAP[key] + " to image list" imageList.append(key) imageList.append(IMAGE_NAME_MAP[key]) # Load each image for imageName in imageList: imageMap[imageName] = simplegui.load_image(GAME_ASSETS + imageName) # Load the facedown image - from weheartnintendo.tumblr facedownImage = simplegui.load_image(GAME_ASSETS + "unturned.jpg")
def __init__(self, img, center, size, radius = 0, lifespan = 0, animated = False, dimensions = []): self.center = center self.size = size self.radius = radius self.dimensions = dimensions self.lifespan = lifespan self.animated = animated COMMON_URL = ASSETS_URL if lifespan != 60: COMMON_URL += "lathrop/" self.image = simplegui.load_image(COMMON_URL + img)
def draw(canvas): global time, lives, score, debris_image, nebula_image # animiate background time += 1 wtime = (time / 4) % WIDTH center = debris_info.get_center() size = debris_info.get_size() canvas.draw_image(nebula_image, nebula_info.get_center(), nebula_info.get_size(), [WIDTH / 2, HEIGHT / 2], [WIDTH, HEIGHT]) canvas.draw_image(debris_image, center, size, (wtime - WIDTH / 2, HEIGHT / 2), (WIDTH, HEIGHT)) canvas.draw_image(debris_image, center, size, (wtime + WIDTH / 2, HEIGHT / 2), (WIDTH, HEIGHT)) # draw user interface canvas.draw_text("lives = " + str(lives), [WIDTH / 6, HEIGHT / 10], 22, "White") canvas.draw_text("score = " + str(score), [WIDTH * 4 / 6, HEIGHT / 10], 22, "White") # draw and update rocks and missiles process_sprite_group(rock_group, canvas) process_sprite_group(missile_group, canvas) process_sprite_group(explosion_group, canvas) # draw and update ship my_ship.draw(canvas) my_ship.update() # update lives if ship collides rock if group_collide(rock_group, my_ship): lives -= 1 if lives < 1: stop() # update score score += 10 * group_group_collide(rock_group, missile_group) if score == 300: debris_image = simplegui.load_image("http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/debris_blend.png") nebula_image = simplegui.load_image("http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/nebula_brown.png") # draw splash screen if not started if not started: canvas.draw_image(splash_image, splash_info.get_center(), splash_info.get_size(), [WIDTH / 2, HEIGHT / 2], splash_info.get_size())
def __init__(self, fname, center, size, radius = 0, lifespan = None, animated = False): self.center = center self.size = size self.radius = radius if lifespan: self.lifespan = lifespan else: self.lifespan = float('inf') self.animated = animated #print fullpath(self.depath,fname) self.image = gui.load_image(fullpath(self.depath,fname))
def __init__(self, name, image, center, size, radius = 0, lifespan = None, animated = False): self.name = name self.center = center self.size = size self.radius = radius self.image = simplegui.load_image(image) if lifespan: self.lifespan = lifespan else: self.lifespan = float('inf') self.animated = animated
def draw_card_back(canvas, LOC_BACK_X, LOC_BACK_Y): # returns a graphic that represents the back of a card SET = simplegui.load_image('http://i.imgur.com/p6hCw9U.png') CARDWIDTH = SET.get_width() CARDHEIGHT = SET.get_height() DRAWSCALE = 1.2 return canvas.draw_image(SET, (CARDWIDTH /2 , CARDHEIGHT / 2), (CARDWIDTH, CARDHEIGHT), (LOC_BACK_X, LOC_BACK_Y), (CARDWIDTH * DRAWSCALE, CARDHEIGHT * DRAWSCALE))
def __init__(self,image_file,center,size,radius=0,lifespan=0,animated=False,tiles=1): self.image=simplegui.load_image(image_file) self.center = center self.size = size self.radius = radius self.tiles=tiles if lifespan: self.lifespan = lifespan else: self.lifespan = float('inf') self.animated = animated
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()
def __init__(self): """ Create a frame and load the cancer data """ self._frame = simplegui.create_frame("Cancer risk visualization", CANVAS_WIDTH, CANVAS_HEIGHT) self._frame.set_canvas_background("White") self._frame.set_draw_handler(self.draw) self._frame.add_input("Enter cutoff (scaled by 0.00001)", self.enter_cutoff, 200) self._frame.add_button("Print data table in CSV", self.print_table, 200) self._data_table = self.load_data() self.enter_cutoff("0.0") self._USA_Counties = simplegui.load_image(MAP_URL) self._frame.start()
def draw(self,canvas): global lives, started, rock_group if self.destroy == False and started==True: if self.thrust: canvas.draw_image(self.image, [self.image_center[0] + self.image_size[0], self.image_center[1]] , self.image_size, self.pos, self.image_size, self.angle) else: canvas.draw_image(self.image, self.image_center, self.image_size, self.pos, self.image_size, self.angle) elif self.destroy == True and started==True: EXPLOSION_CENTERs = [50, 50] EXPLOSION_SIZEs = [100, 100] EXPLOSION_DIMs = [9, 9] explosion_images = simplegui.load_image("http://commondatastorage.googleapis.com/codeskulptor-assets/explosion.hasgraphics.png") if self.time2<73: explosion_indexs = [self.time2 % EXPLOSION_DIMs[0], (self.time2 // EXPLOSION_DIMs[0]) % EXPLOSION_DIMs[1]] canvas.draw_image(explosion_images, [EXPLOSION_CENTERs[0] + explosion_indexs[0] * EXPLOSION_SIZEs[0], EXPLOSION_CENTERs[1] + explosion_indexs[1] * EXPLOSION_SIZEs[1]], EXPLOSION_SIZEs, self.pos, EXPLOSION_SIZEs) self.time2+=1 self.angle_vel = 0 else: #after destroying my_ship all times self.time2=0 self.pos = [WIDTH / 2, HEIGHT / 2] self.vel = [0,0] self.thrust = False self.angle = 0 self.angle_vel = 0 self.destroy = False if self.destroy == False: for r in rock_group: if r.destroy == False and dist(self.pos, r.pos) < self.radius + r.radius: r.destroy_itself() lives-=1 explosion_sound.rewind() explosion_sound.play() self.destroy = True self.vel = [0,0] self.angle_vel = 0 if lives>0: global score score -= 1 else: started = False lives = 3 timer.stop() rock_group = set([])
def group_collide(group, other_object): '''Return True if group of sprites collide with other object and removes sprite from the group''' global explosion_group temp_group = set(group) for item in temp_group: if item.collide(other_object): expl = random.choice(['explosion_orange.png', 'explosion_blue.png', 'explosion_blue2.png', 'explosion_alpha.png']) explosion_image = simplegui.load_image("http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/%s" % expl) explosion = (Sprite(item.pos, item.vel, item.angle, item.angle_vel, explosion_image, explosion_info, explosion_sound)) explosion_group.add(explosion) group.remove(item) return True return False
def new_game(): global card_images, card_images_done, card_face_image, state, card_exposed, card_done, selected_cards, card_exposed_track, turn card_images = [] card_images_done = [] for i in range(len(card_images_url)): # card_images consists of card images, its value & card object done images card_images.append([simplegui.load_image(card_images_url[i]), i, simplegui.load_image(card_images_done_url[i])]) card_images.append([simplegui.load_image(card_images_url[i]), i, simplegui.load_image(card_images_done_url[i])]) card_face_image = simplegui.load_image(card_face_url) card_exposed = [ [False, False], [False, False], [False, False], [False, False], [False, False], [False, False], [False, False], [False, False], [False, False], [False, False], [False, False], [False, False], [False, False], [False, False], [False, False], [False, False], ] random.shuffle(card_images) state = 0 selected_cards = [] card_exposed_track = [] turn = 0 label.set_text("Turns = " + str(turn))
def __init__(self, game): self._rows = game.get_grid_height() self._cols = game.get_grid_width() self._frame = simplegui.create_frame('2048', self._cols * TILE_SIZE + 2 * BORDER_SIZE, self._rows * TILE_SIZE + 3 * BORDER_SIZE) self._frame.add_button('New Game', self.start) self._frame.set_keydown_handler(self.keydown) self._frame.set_draw_handler(self.draw) self._frame.set_canvas_background("#A39480") self._frame.start() self._game = game self._tiles = simplegui.load_image(IMAGEURL) self._directions = {"up": UP, "down": DOWN, "left": LEFT, "right": RIGHT}
def __init__(self, url, size, center=None): # sets the url self.url = url # loads the image if CACHE_STORE.has_key(url): self.image = CACHE_STORE[url] else: self.image = simplegui.load_image(url) CACHE_STORE[url] = self.image # sets the dimensions of the image self.set_size(size) # if the center is not set if center is None: self.set_center((size[0] / 2, size[1] / 2)) else: self.set_center(center)
def rock_spawner(): global rock_group #Increases velocity of the spawning rocks every 500 points add_vel_step = score // 500 * 0.01 rock_pos = [random_num(1,0,WIDTH), random_num(1,0,HEIGHT)] rock_vel = [random_num(0.03 + add_vel_step), random_num(0.03 + add_vel_step)] asteroid = random.choice(['asteroid_blue.png', 'asteroid_brown.png', 'asteroid_blend.png']) if started and len(rock_group) < 12: asteroid_image = simplegui.load_image("http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/%s" % asteroid) a_rock = Sprite(rock_pos,rock_vel, 0, random_num(0.0004), asteroid_image, asteroid_info) #If a_rock tries to spawn to close to the ship it is ignored if not a_rock.collide(my_ship, 50): rock_group.add(a_rock)
def new_game(): global cnt, guessed_letters, word, missed_letters, guess_result, warning_msg, result_msg, hangmanpic, guess_result_str, missed_letters_str, image word = words[random.randrange(0, len(words))] guessed_letters = "" print(word) missed_letters = "" guess_result = "_" * len(word) cnt = 0 image = simplegui.load_image("https://dl.dropboxusercontent.com/u/52743103/hangman/hangman0.jpg") guess_result_str = add_underline(guess_result) missed_letters_str = "Missed letter: " + missed_letters warning_msg = "" result_msg = ""
return self.radius def get_lifespan(self): '''returns the images lifespan''' return self.lifespan def get_animated(self): '''returns the animation status of an image stack/array''' return self.animated # 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") #"http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/double_ship.png")
# Mini-project #6 - Blackjack import simplegui import random # load card sprite - 936x384 - source: jfitz.com CARD_SIZE = (72, 96) CARD_CENTER = (36, 48) card_images = simplegui.load_image("http://storage.googleapis.com/codeskulptor-assets/cards_jfitz.png") CARD_BACK_SIZE = (72, 96) CARD_BACK_CENTER = (36, 48) card_back = simplegui.load_image("http://storage.googleapis.com/codeskulptor-assets/card_jfitz_back.png") background_im = simplegui.load_image('https://s-media-cache-ak0.pinimg.com/736x/05/c8/ed/05c8ed7391615bdf0e253375fc08832d.jpg') # initialize some useful global variables in_play = False outcome = "" score = 0 CARD_SPACE = 25 message = '' # 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
def get_radius(self): 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 # 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") debris_image = simplegui.load_image("http://127.0.0.1:8080/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") nebula_image = simplegui.load_image( "http://127.0.0.1:8080/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") splash_image = simplegui.load_image("http://127.0.0.1:8080/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")
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 # 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
def __init__(self): self.transition_image = simplegui.load_image(ResourcePaths.transition_screen) self.transition_img_pos = None
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 # 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://i.space.com/images/i/000/023/673/wS1/vista-look-at-helix-nebula-1600.jpg?1352931499" ) # 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
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( "https://dl.dropbox.com/s/uelrcnu4aexo2he/debris.png") #"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( "https://dl.dropbox.com/s/h5awm7onocm9v10/space.png") #"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( "https://dl.dropbox.com/s/jyly627nc8v1zku/missile.png") #"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")
import simplegui image = simplegui.load_image("http://commondatastorage.googleapis.com/codeskulptor-assets/alphatest.png") source_center = [220, 100] source_size = [100, 100] frame_size = list(source_size) frame_center = [ source_size[0] / 2, source_size[1] /2 ] def draw(canvas): canvas.draw_image( image, source_center, source_size, frame_center, frame_size) frame = simplegui.create_frame("Image", frame_size[0], frame_size[1]) frame.set_draw_handler(draw) frame.start() print frame_size, frame_center, source_size, source_center
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 # 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.f2013.png") #nebula_info = ImageInfo([400, 300], [800, 600]) #nebula_image = simplegui.load_image("https://dl.dropboxusercontent.com/u/12070649/galaxies-antennae.jpg") nebula_info = ImageInfo([400, 300], [800, 600]) nebula_image = simplegui.load_image( "https://dl.dropboxusercontent.com/u/12070649/nebula_swan.jpg") # splash image splash_info = ImageInfo([200, 150], [400, 300]) splash_image = simplegui.load_image( "http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/splash.png" )
# Sprite Animation # Running Bunny # This program draws an animated spiral sprite. import simplegui import math import random # Global Variables canvas_width = 200 canvas_height = 200 image = simplegui.load_image( "http://commondatastorage.googleapis.com/codeskulptor-assets/week8-bunny_sprite.png" ) image_size = [100, 100] image_center = [50, 50] num_tiles = 3 cur_tile = 0 # This image doesn't look good when run at 60 fps, so # the delay variable slows it down to 6 fps delay = 10 # Time keeps track of how many frames have passed since # the last tile incrementation. time = 0 # Event Handlers
def load_image(link): global pic pic = simplegui.load_image("")
import simplegui frame_size = [200, 200] image_size = [1521, 1818] def draw(canvas): canvas.draw_image(image, [image_size[0] / 2, image_size[1] / 2], image_size, [frame_size[0] / 2, frame_size[1] / 2], frame_size) frame = simplegui.create_frame("test", frame_size[0], frame_size[1]) frame.set_draw_handler(draw) image = simplegui.load_image( "http://commondatastorage.googleapis.com/codeskulptor-assets/gutenberg.jpg" ) frame.start()
# Mini-project #6 - Blackjack import simplegui import random # constants FRAME_SIZE = 600 TITLE = "Blackjack" TITLE_SIZE = 50 TITLE_LOC = [200, 100] # 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") SPACING = 5 DH_LOC = (50, 250) PH_LOC = (50, 450) TIP_OFFSET = 25 COL_1_OFFSET = 100 COL_2_OFFSET = 400 DH_LABEL_LOC = (DH_LOC[0], DH_LOC[1] - TIP_OFFSET) INST_LOC = (DH_LABEL_LOC[0] + COL_1_OFFSET, DH_LABEL_LOC[1]) DH_TIP_LOC = (DH_LOC[0], DH_LOC[1] + CARD_SIZE[1] + TIP_OFFSET) PH_LABEL_LOC = (PH_LOC[0], PH_LOC[1] - TIP_OFFSET) OUTCOME_LOC = (PH_LABEL_LOC[0] + COL_1_OFFSET, PH_LABEL_LOC[1]) SCORE_LOC = (PH_LABEL_LOC[0] + COL_2_OFFSET, PH_LABEL_LOC[1]) PH_TIP_LOC = (PH_LOC[0], PH_LOC[1] + CARD_SIZE[1] + TIP_OFFSET) CARD_BACK_SIZE = (71, 96) CARD_BACK_CENTER = (35.5, 48)
# implementation of card game - Memory # sources for card images: # http://www.loadtve.biz/playing-card-back.html # https://bonafideplayingcards.com/portfolio/count-monte-cristo-playing-cards/ # import modules try: import simplegui except ImportError: import SimpleGUICS2Pygame.simpleguics2pygame as simplegui import random # load images of cards back_card = simplegui.load_image('https://i.imgur.com/W1V4z7G.png') back_card_size = [427, 600] #ratio-lock ~1.4 back_card_center = [back_card_size[0]/2, back_card_size[1]/2] ace = simplegui.load_image('https://i.imgur.com/Iv0tM7Q.png') #ace of diamonds two = simplegui.load_image('https://i.imgur.com/k59hwth.png') #2 of diamonds three = simplegui.load_image('https://i.imgur.com/Zd16VhN.png') #3 of hearts four = simplegui.load_image('https://i.imgur.com/l3mfLhp.png') #4 of clubs five = simplegui.load_image('https://i.imgur.com/nvZQK4W.png') #5 of clubs six = simplegui.load_image('https://i.imgur.com/KNQp4A7.png') #6 of spades seven = simplegui.load_image('https://i.imgur.com/PM3RbR7.png') #7 of hearts joker = simplegui.load_image('https://i.imgur.com/Za73zWO.png') cards = [joker, ace, two, three, four, five, six, seven] front_card_size = [500, 704] #ratio-lock ~1.4 front_card_center = [front_card_size[0]/2, front_card_size[1]/2]
# Image positioning problem # Copy and paste the code in codeSkulptor to see how it works # @author (Aymar N.) # @version (2020) Version 1 import simplegui # global constants WIDTH = 400 HEIGHT = 300 img_pos = [WIDTH // 2, HEIGHT // 2] # load test image test_image = simplegui.load_image("https://snipboard.io/eqSEJN.jpg") test_image_size = [95, 93] test_image_center = [test_image_size[0] // 2, test_image_size[1] // 2] # mouseclick handler def click(pos): global img_pos img_pos = list(pos) # draw handler def draw(canvas): canvas.draw_image(test_image, test_image_center, test_image_size, img_pos, test_image_size) # create frame and register draw handler
def get_radius(self): 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 # 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)
def get_radius(self): return self.radius def get_lifespan(self): return self.lifespan def get_animated(self): return self.animated # 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 = sg.load_image("http://commondatastorage.googleapis.com/" "codeskulptor-assets/lathrop/debris4_blue.png") # NEBULA IMAGES: nebula_brown.png, nebula_blue.png nebula_info = ImageInfo([400, 300], [800, 600]) nebula_image = sg.load_image("http://commondatastorage.googleapis.com/" "codeskulptor-assets/lathrop/nebula_brown.png") # SPLASH IMAGE splash_info = ImageInfo([WIDTH / 2, HEIGHT / 2], [WIDTH, HEIGHT]) splash_image = sg.load_image( "https://github.com/andsnleo/python-simplegui-games/blob/master/ricerocks/assets/splash.png?raw=true" ) # SHIP IMAGE ship_info = ImageInfo([45, 45], [90, 90], 35) ship_image = sg.load_image("http://commondatastorage.googleapis.com/"
# Mini-project #6 - Blackjack import simplegui import random # load card sprite - 949x392 - source: jfitz.com outcome = '' question = 'deal?' CARD_SIZE = (73, 98) CARD_CENTER = (36.5, 49) card_images = simplegui.load_image( "http://commondatastorage.googleapis.com/codeskulptor-assets/cards.jfitz.png" ) 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,
# start program init(217) timer.start() --------------------------------------------------------------------------- # animation of explosion using 2D sprite sheet import simplegui # load 81 frame sprite sheer for explosion - image generated by phaedy explosion generator, source is hasgraphics.com EXPLOSION_CENTER = [50, 50] EXPLOSION_SIZE = [100, 100] EXPLOSION_DIM = [9, 9] explosion_image = simplegui.load_image("http://commondatastorage.googleapis.com/codeskulptor-assets/explosion.hasgraphics.png") # create timer that iterates current_sprite_center through sprite time = 0 # define draw handler def draw(canvas): global time explosion_index = [time % EXPLOSION_DIM[0], (time // EXPLOSION_DIM[0]) % EXPLOSION_DIM[1]] canvas.draw_image(explosion_image, [EXPLOSION_CENTER[0] + explosion_index[0] * EXPLOSION_SIZE[0], EXPLOSION_CENTER[1] + explosion_index[1] * EXPLOSION_SIZE[1]], EXPLOSION_SIZE, EXPLOSION_CENTER, EXPLOSION_SIZE) time += 1
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")
#import modules import simplegui import random import math #load image tile_cover = simplegui.load_image( "https://www.dropbox.com/s/ukemajgulc175en/BicycleStandardBlue_4.jpg?dl=1") deck_of_cards = simplegui.load_image( "https://www.dropbox.com/s/wgupp562otlh07e/Deck%20of%20cards.png?dl=1") #define globals turns = 0 CARD_SUIT = ('C', 'D', 'H', 'S') CARD_RANK = ('A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K') NUMBER_OF_TILES = 2 EXPOSED = [True, False] MY_LIST = ['2', '3', '4', '5', '6', '7', '8', '9'] MY_LIST.extend(['2', '3', '4', '5', '6', '7', '8', '9']) random.shuffle(MY_LIST) TILE_WIDTH = 60 TILE_HEIGHT = 100 WIDTH = tile_cover.get_width() HEIGHT = tile_cover.get_height() TILE_COVER_CENTER = [WIDTH / 2, HEIGHT / 2] TILE_COVER_SIZE = [WIDTH, HEIGHT]
# Step 1: import modules import simplegui import random # Step 2: declare some global variables CANVAS_SIZE = (740, 650) IMG_CARDS = simplegui.load_image('http://commondatastorage.googleapis.com/codeskulptor-assets/cards.jfitz.png') IMG_BACK = simplegui.load_image('http://commondatastorage.googleapis.com/codeskulptor-assets/card_back.png') CARD_WIDTH = 73 CARD_HEIGHT = 98 RANKS = ('A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K') COLORS = ('Club', 'Spade', 'Heart', 'Diamond') VALUES = {'A':1, '2':2, '3':3, '4':4, '5':5, '6':6, '7':7, '8':8, '9':9, '10':10, 'J':10, 'Q':10, 'K':10} FONT_OFFSET = 2 TABLE_UPPER_LEFT_CORNER = (CANVAS_SIZE[0] - 200, CANVAS_SIZE[1] - 120) score_dealer = 0 score_player = 0 message_upper = '' message_lower = '' state = 'stop' # There are 2 states: 'stop' and 'running' deck = None dealer_hand = None player_hand = None # Step 3: create 3 classes: Card, Deck, Hand class Card: def __init__(self, rank, color, exposed = True): self.rank = rank
def input_handler(url): global g_image_loaded, g_image g_image_loaded = False g_image = simplegui.load_image(url)
# Image positioning problem ################################################### # Student should enter code below import simplegui # global constants WIDTH = 400 HEIGHT = 300 asteroid_w = 95 asteroid_h = 93 pos = [WIDTH / 2, HEIGHT / 2] # load test image asteroid = simplegui.load_image( "http://commondatastorage.googleapis.com/codeskulptor-assets/asteroid.png") # mouseclick handler def click(mpos): global pos pos = mpos # mousedrag handler def drag(mpos): global pos if abs(pos[0] - mpos[0]) < (asteroid_w / 2) and abs(pos[1] - mpos[1]) < ( asteroid_h / 2): # print pos, mpos pos = mpos
def get_size(self): return self.size def get_radius(self): return self.radius def get_lifespan(self): return self.lifespan def get_animated(self): return self.animated debris_info = ImageInfo([320, 240], [640, 480]) #object of image info debris_image = simplegui.load_image("D:\debris2_blue.png") nebula_info = ImageInfo([400, 300], [800, 600]) nebula_image = simplegui.load_image("D:/nebula_blue.png") splash_info = ImageInfo([200, 150], [400, 300]) splash_image = simplegui.load_image("D:\splash.png") ship_info = ImageInfo([45, 45], [90, 90], 35) ship_image = simplegui.load_image("D:\double_ship.png") missile_info = ImageInfo([5, 5], [10, 10], 3, 50) missile_image = simplegui.load_image("D:\shot2.png") asteroid_info = ImageInfo([45, 45], [90, 90], 40) asteroid_image = simplegui.load_image("D:\asteroid_blue.png")
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 # 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/debris1_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_brown.png" ) # powerUp image powerUpInfo = ImageInfo([10, 10], [20, 20], 10, 200) powerUpImage = simplegui.load_image( "http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/shot3.png" ) # splash image
# Mini-project #6 - Blackjack import simplegui import random # load card sprite - 936x384 - source: jfitz.com CARD_SIZE = (72, 96) CARD_CENTER = (36, 48) card_images = simplegui.load_image( "http://storage.googleapis.com/codeskulptor-assets/cards_jfitz.png") CARD_BACK_SIZE = (72, 96) CARD_BACK_CENTER = (36, 48) card_back = simplegui.load_image( "http://storage.googleapis.com/codeskulptor-assets/card_jfitz_back.png") card_back_alt = simplegui.load_image( 'http://images.all-free-download.com/images/graphiclarge/poker_background_3d_design_red_ribbon_cards_decoration_6829319.jpg' ) ALT_SIZE = [600, 598] ALT_CENTER = [600 // 2, 598 // 2] # 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 = {
# the user to attempt to balance a stick using the arrow keys. # The code using acceleration can be found in the update method # of the Stick class. import simplegui import math import random # Global Variables canvas_width = 400 canvas_height = 400 # Note that the center of the image is located at the black # circle at the base of the stick. stick_image = simplegui.load_image( "http://commondatastorage.googleapis.com/codeskulptor-assets/week7-stick.png" ) # Classes class Stick: def __init__(self, radius, center, image, image_center, image_size): self.radius = radius self.center = center self.angle = random.random() * random.choice([-1, 1]) * .01 self.angle_vel = 0 self.angle_acc = 0 self.key_acc = 0 self.image = image self.image_center = image_center
def get_radius(self): 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 # 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_image1 = simplegui.load_image("http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/debris3_brown.png") debris_image2 = simplegui.load_image("http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/debris4_blue.png") # nebula images - nebula_brown.png, nebula_blue.png nebula_info = ImageInfo([400, 300], [800, 600]) nebula_image1 = simplegui.load_image("http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/nebula_blue.png") nebula_image2 = simplegui.load_image("http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/nebula_brown.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")
#Juego de cartas, donde el usuario presiona una carta y debe #ir encontrando su pareja #0. Importar Modulos import simplegui import random #1. Variables Globales ANCHO = 800 ALTO = 100 TURNO = 0 MOSTRAR = [] AUXILIAR = 0 UNO = simplegui.load_image("https://i.imgur.com/hslVkVI.jpg") DOS = simplegui.load_image("https://i.imgur.com/VtVfd6h.jpg") TRES = simplegui.load_image("https://i.imgur.com/DeySWza.jpg") CUATRO = simplegui.load_image("https://i.imgur.com/zwkjpkm.jpg") CINCO = simplegui.load_image("https://i.imgur.com/74WGqZu.jpg") SEIS = simplegui.load_image("https://i.imgur.com/uzVfTxy.jpg") SIETE = simplegui.load_image("https://i.imgur.com/fB6BqdN.jpg") OCHO = simplegui.load_image("https://i.imgur.com/qg7laPt.jpg") CARTAS = [UNO, DOS, TRES, CUATRO, CINCO, SEIS, SIETE, OCHO] VARAJA = list(CARTAS) + list(CARTAS) IMAGEN = simplegui.load_image("https://i.imgur.com/pHMuwwv.jpg") NINGUNA = 16 IMAGEN_CENTRO = [IMAGEN.get_width() // 2, IMAGEN.get_height() // 2] IMAGEN_TAMANIO = [IMAGEN.get_width(), IMAGEN.get_height()] #2. Clases #3. Funciones de Ayuda #Funcion que mezcla la varaja #AƱade cartas 'alreves' o sea con valor=0