def enter(): global title_font, score_font gfw.world.init(['bg']) center = get_canvas_width() // 2, get_canvas_height() // 2 gfw.world.add(gfw.layer.bg, gobj.ImageObject('결과배경.png', center)) score_font = gfw.font.load(gobj.res('NanumGothic.TTF'), 100) title_font = gfw.font.load(gobj.res('NanumGothic.TTF'), TITLE_FONT_SIZE)
def load_stage_data(): global entrance, exit load_count = 0 map_x = 0 map_y = 0 while load_count < 16: if (map_x, map_y) in room_shape: file_fmt = 'stages/stage_type%d.txt' fn = file_fmt % room_shape[(map_x, map_y)] stage_gen.load(gobj.res(fn), map_x, map_y) stage_gen.update() else: file_fmt = 'stages/stage_type%d.txt' fn = file_fmt % random.randint(0, 3) stage_gen.load(gobj.res(fn), map_x, map_y) stage_gen.update() if (map_x, map_y) == entrance: fn = 'stages/entrance.txt' stage_gen.load_door(gobj.res(fn), map_x, map_y) stage_gen.update() elif (map_x, map_y) == exit: fn = 'stages/exit.txt' stage_gen.load_door(gobj.res(fn), map_x, map_y) stage_gen.update() map_x += 1 map_x = map_x % 4 load_count += 1 map_y = load_count // 4
def __init__(self, x, y): self.x, self.y = x, y self.FPS = 10 self.time = 0 self.cooldown = random.randint(1, 3) self.frame = 0 self.state = Lupin.IDLE if Lupin.images is None: Lupin.images = [[] for _ in range(3)] Lupin.images[Lupin.IDLE].append( gfw.image.load(gobj.res('monsters/lupin/idle/Frame0.png'))) for i in range(9 + 1): Lupin.images[Lupin.THROW].append( gfw.image.load( gobj.res('monsters/lupin/throw/Frame' + str(i) + '.png'))) for i in range(2 + 1): Lupin.images[Lupin.DEAD].append( gfw.image.load( gobj.res('monsters/lupin/dead/Frame' + str(i) + '.png')))
def build_world(): gfw.world.init(['bg', 'ui']) center = (gobj.canvas_width // 2, gobj.canvas_height // 2) bg = gobj.ImageObject('Title_Bg.png', center) gfw.world.add(gfw.layer.bg, bg) # Button(l, b, w, h, font, text, callback, btnClass=None): font = gfw.font.load(gobj.res('ENCR10B.TTF'), 40) l, b, w, h = gobj.canvas_width / 2 - 270 / 2, 120, 270, 140 btn = Button(l, b, w, h, font, '', lambda: push_play_select()) btn.normalBg = ('Play', 'Normal') btn.hoverBg = ('Play', 'Hover') btn.pressedBg = ('Play', 'Pressed') btn.update_Img() gfw.world.add(gfw.layer.ui, btn) b -= 100 btn = Button(l, b, w, h, font, "", lambda: push_record_select()) btn.normalBg = ('Record', 'Normal') btn.hoverBg = ('Record', 'Hover') btn.pressedBg = ('Record', 'Pressed') btn.update_Img() gfw.world.add(gfw.layer.ui, btn) global bgm bgm = load_music(gobj.res('Bgm_Main.mp3')) bgm.repeat_play()
def enter(): gfw.world.init([ 'bg', 'enemy', 'throwing', 'platform', 'meso', 'item', 'player', 'ui' ]) bg = Background('background/stage1_bg_far.png') bg.speed = 10 gfw.world.add(gfw.layer.bg, bg) bg = Background('background/stage1_bg_near.png') bg.speed = 100 bg.y_scale = 1.75 gfw.world.add(gfw.layer.bg, bg) global player player = Player() gfw.world.add(gfw.layer.player, player) global font font = gfw.font.load(gobj.res('font/Maplestory Bold.ttf'), FONT_SIZE) global font_meso font_meso = gfw.font.load(gobj.res('font/morris9.ttf'), 20) stage_gen.load(gobj.res('stage_01.txt'))
def handle_mouse(e): global main_sound, capture, title if e.type == SDL_MOUSEMOTION: pos = gobj.mouse_xy(e) if not capture: if pos[1] <= canvas_height * 0.87 + 50 and pos[ 1] >= canvas_height * 0.87 - 50: main_sound.play() for obj in gfw.world.objects_at(gfw.layer.title): obj.image = gfw.image.load(gobj.res('음악선택이미지클릭.png')) capture = True return False if capture: if pos[1] > canvas_height * 0.87 + 50 or pos[ 1] < canvas_height * 0.87 - 50: main_sound.stop() for obj in gfw.world.objects_at(gfw.layer.title): obj.image = gfw.image.load(gobj.res('음악선택이미지.png')) capture = False return False if e.type == SDL_MOUSEBUTTONDOWN and e.button == SDL_BUTTON_LEFT: pos = gobj.mouse_xy(e) if pos[1] <= canvas_height * 0.87 and pos[ 1] >= canvas_height * 0.87 - 50 and pos[ 0] > canvas_width // 2 and pos[0] < canvas_width * 0.9: main_sound.stop() del main_sound return gfw.push(main_state) return False
def enter(): gfw.world.init(['bg', 'card']) center = get_canvas_width()//2, get_canvas_height()//2 gfw.world.add(gfw.layer.bg, gobj.ImageObject(theme + '/bg.png', center)) x,y = start_x, start_y idxs = [n + 1 for n in range(10)] * 2 # print('before:', idxs) random.shuffle(idxs) # print('after: ', idxs) for i in range(15, -1, -5): print(idxs[i:i+5]) for i in idxs: c = Card(i, (x,y), theme) gfw.world.add(gfw.layer.card, c) x += Card.WIDTH + PADDING if x > get_canvas_width(): x = start_x y += Card.HEIGHT + PADDING global last_card last_card = None global score, font score = 0 font = gfw.font.load(gobj.res('ENCR10B.TTF'), 20) global bg_music, flip_wav bg_music = load_music(gobj.res('bg.mp3')) bg_music.set_volume(60) flip_wav = load_wav(gobj.res('pipe.wav')) bg_music.repeat_play()
def __init__(self, speed): self.num = 1 self.image = gfw.image.load(gobj.res('skill_jelly.png')) self.effect_image = gfw.image.load(gobj.res('skill1_effect_1.png')) self.x = random.randrange(800, 1000) self.y = random.randrange(100, 300) self.rect = 0, 0, 66, 66 self.speed = speed
def load(): global objectimage if objectimage is None: objectimage = gfw.image.load(gobj.res('object.png')) with open(gobj.res('object.json')) as f: data = json.load(f) for name in data: object_rects[name] = tuple(data[name])
def __init__(self, color, left, bottom): if color == 'red': self.name = 'RedPotion' self.image = gfw.image.load(gobj.res(ITEM_DIR + 'potion_red.png')) elif color == 'blue': self.name = 'BluePotion' self.image = gfw.image.load(gobj.res(ITEM_DIR + 'potion_blue.png')) self.init(left, bottom) self.size = 64
def update(self): if self.num < 6: self.num += 0.5 self.effect_image1 = gfw.image.load( gobj.res('skill3_effect_%d.png' % self.num)) self.effect_image2 = gfw.image.load( gobj.res('skill3_effect2_%d.png' % self.num)) else: gfw.world.remove(self)
def __init__(self): self.num = 1 self.effect_image2 = gfw.image.load(gobj.res('skill3_effect2_1.png')) self.effect_image1 = gfw.image.load(gobj.res('skill3_effect_1.png')) self.x1 = random.randrange(300, 800) self.y1 = random.randrange(100, 400) self.x2 = random.randrange(300, 800) self.y2 = random.randrange(100, 400) self.rect1 = 0, 0, 210, 210 self.rect2 = 0, 0, 217, 217
def update(self): self.x -= self.speed * gfw.delta_time if self.x < 800 and self.idx == 1: self.image = gfw.image.load(gobj.res('Lspine_2.png')) self.idx = 2 if self.idx == 2: self.image = gfw.image.load(gobj.res('Lspine_3.png')) if self.x + 131 < 0: gfw.world.remove(self)
def enter(): enemy.dead = 0 enemy.life = 100 gfw.world.init(['bg', 'card', 'state', 'ui']) gfw.world.remove(highscore) center = get_canvas_width() // 2, get_canvas_height() // 1.4 center2 = get_canvas_width() // 2, 250 hp = 150, 700 gfw.world.add(gfw.layer.bg, gobj.ImageObject(theme + '/black.png', center2)) gfw.world.add(gfw.layer.bg, gobj.ImageObject(theme + '/bg.png', center)) #gfw.world.add(gfw.layer.bg, gobj.ImageObject(theme + '/gaugefg.png', hp)) x, y = start_x, start_y idxs = [n + 1 for n in range(9)] #print('before:', idxs) #random.shuffle(idxs) #print('after: ', idxs) for i in range(0, 9, +3): print(idxs[i:i + 3]) for i in idxs: c = Pattern(i, (x, y), theme) gfw.world.add(gfw.layer.card, c) x += Pattern.WIDTH + PADDING - 100 if x > get_canvas_width(): x = start_x y -= Pattern.HEIGHT + PADDING - 100 icon = Skil(1, (150, 200), theme) gfw.world.add(gfw.layer.card, icon) pla = Player(1, (550, 450), theme) gfw.world.add(gfw.layer.card, pla) ene = Enemy(1, (150, 480), theme) gfw.world.add(gfw.layer.card, ene) global last_card last_card = None global TIME, font TIME = 1000 font = gfw.font.load(gobj.res('ENCR10B.TTF'), 20) highscore.load() global bg_music, flip_wav bg_music = load_music(gobj.res('bg1.mp3')) bg_music.set_volume(60) flip_wav = load_wav(gobj.res('pipe.wav')) bg_music.repeat_play()
def exit(): global back, bg, fg gfw.image.unload(res('loading.jpg')) gfw.image.unload(res('progress_bg.png')) gfw.image.unload(res('progress_fg.png')) del back del bg del fg global frame_interval gfw.frame_interval = frame_interval
def enter(): global title_font, score_font gfw.world.init(['bg', 'button']) center = get_canvas_width() // 2, get_canvas_height() // 2 gfw.world.add(gfw.layer.bg, gobj.ImageObject('결과배경.png', center)) pos = get_canvas_width() // 2, 150 gfw.world.add(gfw.layer.button, gobj.ImageObject('결과화면 버튼.png', pos)) score_font = gfw.font.load(gobj.res('NanumGothic.TTF'), 100) title_font = gfw.font.load(gobj.res('NanumGothic.TTF'), TITLE_FONT_SIZE) highscore.load(TITLE_FONT_SIZE) highscore.add(Tile.SCORE)
def exit(): global back, bg, fg gfw.image.unload(res('kpu_logo_800x600.png')) gfw.image.unload(res('progress_bg.png')) gfw.image.unload(res('progress_fg.png')) del back del bg del fg global frame_interval gfw.frame_interval = frame_interval
def get(player): if not hasattr(DeadState, 'singleton'): DeadState.singleton = DeadState() DeadState.singleton.player = player DeadState.singleton.images = [[] for _ in range(2)] for i in range(11 + 1): DeadState.singleton.images[DeadState.FALLING].append(gfw.image.load(gobj.res('tombstone/fall/Frame' + str(i) + '.png'))) DeadState.singleton.images[DeadState.LANDING].append(gfw.image.load(gobj.res('tombstone/land/Frame0.png'))) return DeadState.singleton
def load(): global font, image, button_image font = gfw.font.load(gobj.res('ConsolaMalgun.ttf'), 20) image = gfw.image.load(gobj.res('game_over.png')) button_image = gfw.image.load(gobj.res('continue.png')) try: f = open(FILENAME, "rb") gameclears = pickle.load(f) f.close() except: print("No clear file")
def load(): global font, image font = gfw.font.load(gobj.res('ConsolaMalgun.ttf'), 20) image = gfw.image.load(gobj.res('game_over.png')) global scores try: f = open(FILENAME, "rb") scores = pickle.load(f) f.close() print("Scores:", scores) except: print("No highscore file")
def get(player): if not hasattr(AttackState, 'singleton'): AttackState.singleton = AttackState() AttackState.singleton.player = player AttackState.singleton.images = [] for i in range(2 + 1): AttackState.singleton.images.append(gfw.image.load(gobj.res('player/attack/Frame' + str(i) + '.png'))) AttackState.singleton.claw_images = [] for i in range(4 + 1): AttackState.singleton.claw_images.append(gfw.image.load(gobj.res('skill/magic_claw/Frame' + str(i) + '.png'))) return AttackState.singleton
def update(): global speed, sound, END, check_start, play_speed, PAUSE_TILE, collision_count, title_font if Tile.start: if check_start == False: gfw.world.clear_at(gfw.layer.ui) sound.play() check_start = True if END: sound.stop() gfw.change(result) else: for obj in gfw.world.objects_at(gfw.layer.tile): if obj.miss_tile == True: obj.image = gfw.image.load(gobj.res('놓친타일.png')) END = True gfw.world.update() if Tile.start: if PAUSE_TILE == False: dy = -TILE_SPEED * gfw.delta_time else: dy = 0 global last_mouse_pos last_mouse_pos = last_mouse_pos[0], last_mouse_pos[1] + dy for obj in gfw.world.objects_at(gfw.layer.tile): if PAUSE_TILE == False: obj.move(dy) for obj in gfw.world.objects_at(gfw.layer.tile): if obj.sound_time > gfw.delta_time * play_speed: sound.pause() if obj.success_tile: check_start = True obj.sound_time += gfw.delta_time for obj in gfw.world.objects_at(gfw.layer.tile): if obj.check_disappearing_tile( ) == True and obj.success_tile == True: gfw.world.remove(obj) if obj.check_disappearing_tile( ) == True and obj.success_tile == False: obj.image = gfw.image.load(gobj.res('놓친타일.png')) obj.miss_tile = True END = True if PAUSE_TILE == False: stage_gen.update(dy)
def enter(): global back, bg, fg, index, file back = gfw.image.load(res('kpu_logo_800x600.png')) bg = gfw.image.load(res('progress_bg.png')) fg = gfw.image.load(res('progress_fg.png')) index = 0 global font, display font = gfw.font.load(res('ENCR10B.TTF'), 30) display = '' global frame_interval frame_interval = gfw.frame_interval gfw.frame_interval = 0
def load(): global tilesetimage, entranceimage, exitimage, objectimage if tilesetimage is None: tilesetimage = gfw.image.load(gobj.res('tileset.png')) with open(gobj.res('all_tile.json')) as f: data = json.load(f) for name in data: tile_rects[name] = tuple(data[name]) if objectimage is None: objectimage = gfw.image.load(gobj.res('object.png')) if entranceimage is None: entranceimage = gfw.image.load(gobj.res('entrance.png')) if exitimage is None: exitimage = gfw.image.load(gobj.res('exit.png'))
def __init__(self): self.pos = get_canvas_width() // 2, get_canvas_height() // 2 self.delta = 0, 0 self.target = None self.speed = 200 self.image = gfw.image.load(gobj.res('animation_sheet1.png')) self.target_image = gfw.image.load(gobj.res('target.png')) self.time = 0 self.fidx = 0 self.action = 2 self.mag = 1 global center_x, center_y center_x = get_canvas_width() // 2 center_y = get_canvas_height() // 2
def __init__(self, speed, x, y): self.image = gfw.image.load(gobj.res('jelly.png')) idx = random.randint(3, 60) self.rect = get_jelly_rect(idx) self.x = x self.y = y self.speed = speed
def test_gen_2(): open_canvas() gfw.world.init(['item', 'platform']) load(gobj.res('stage_01.txt')) for i in range(100): update(0.1) close_canvas()
def __init__(self, speed, x): self.image = gfw.image.load(gobj.res('Hspine_1.png')) self.x = x self.y = 0 self.idx = 1 self.rect = 0, 0, 87, 222 self.speed = speed
def build_world(): gfw.world.init(['poker_bg','ingame_ui','card']) center = get_canvas_width()//2, get_canvas_height()//2 gfw.world.add(gfw.layer.poker_bg, gobj.ImageObject(theme + '/board.png', center)) global font font = gfw.font.load(gobj.res('StarcraftNormal.ttf'), 40) l,b,w,h = 25,550,get_canvas_width()-550,50 btn = Button(l,b,w,h,font,"ingame",lambda: start("ingame")) gfw.world.add(gfw.layer.ingame_ui, btn) x,y = 100,100 global c shape = ['Club','Diamond','Heart','spade'] index = [1,2,3,4,5,6,7,8,9,10,11,12,13] c1 = [random.choice(index)] c2 = [random.choice(shape)] for i in range(0,5): c = Card(c1[i],(x,y),c2[i],theme) gfw.world.add(gfw.layer.card, c) nc1 = random.choice(index) nc2 = random.choice(shape) c1.append(nc1) c2.append(nc2) x+=150 rank = check_hands.hands(c1,c2) print(rank)
def __init__(self, type, x, y): self.x, self.y = x, y if type == Tile.TYPE_1: self.image = gfw.image.load(gobj.res('시작타일.png')) self.rect = GENERATION_TILE_SIZE[0], GENERATION_TILE_SIZE[1] elif type == Tile.TYPE_2: self.image = gfw.image.load(gobj.res('타일.png')) self.rect = GENERATION_TILE_SIZE[0], GENERATION_TILE_SIZE[1] elif type == Tile.TYPE_3: self.image = gfw.image.load(gobj.res('긴타일.png')) self.rect = GENERATION_TILE_SIZE[0], GENERATION_TILE_SIZE[1] self.success_tile = False self.sound_time = 0 self.miss_tile = False self.mouse_x = 0 self.mouse_y = 0