def __init__(self): self.v = [sk.SpriteNode() for x in xrange(int(W) * 2)] for i, sp in enumerate(self.v): sp.size = (5, 5) sp.position = (i / 2., H / 2) sp.color = (i / W / 2, (1 - i / W / 2), (0.5 + i / 800.0)) self.add_child(sp) self.a1 = sk.Action.call(self.update_y) self.a2 = sk.wait(0.1) self.a3 = sk.sequence([self.a1, self.a2]) self.a4 = sk.Action.repeat_forever(self.a3) n = sk.Node() self.add_child(n) n.run_action(self.a4)
def generate_star_background(self): if self.background_node: self.background_node.remove_from_parent() self.background_node = sk.Node() w, h = self.size for i in range(NUM_STARS): star = sk.SpriteNode(STAR_TEXTURE) star.position = random() * w, random() * h + 150 star.alpha = 0.5 + random() * 0.5 fade_in = sk.Action.fade_alpha_to(0.5 + random() * 0.5) fade_in.duration = random() * 2 + 1.5 fade_out = sk.Action.fade_out() fade_out.duration = random() * 2 + 1.5 fade = sk.Action.sequence([fade_out, fade_in]) star.run_action(sk.Action.repeat_forever(fade)) self.background_node.add_child(star) self.add_child(self.background_node)
def __init__(self): with open('words_en.data') as f: self.words = marshal.load(f) self.root = sk.Node() self.add_child(self.root) self.background_color = '#0b1d28' textures = {} for letter in letter_freq: with ui.ImageContext(tile_size, tile_size) as ctx: shadow = ui.Path.rounded_rect(2, 2, tile_size - 4, tile_size - 4, 5) ui.set_color('silver') shadow.fill() bg = ui.Path.rounded_rect(2, 2, tile_size - 4, tile_size - 8, 5) ui.set_color('white') bg.fill() font = ('AvenirNext-Regular', font_size) w, h = ui.measure_string(letter.upper(), font=font) x, y = (tile_size - w) / 2, (tile_size - h) / 2 ui.draw_string(letter.upper(), rect=(x, y, w, h), font=font, color='black') textures[letter] = sk.Texture(ctx.get_image()) self.tile_textures = textures self.tiles = [] #[[None]*rows for i in xrange(cols)] for x, y in product(xrange(cols), xrange(rows)): s = self.create_tile(x, y) self.tiles.append(s) self.root.add_child(s) self.selected = [] self.touched_tile = None self.score_label = sk.LabelNode() self.score_label.font_name = 'AvenirNext-Regular' self.score_label.font_size = 50 self.score_label.h_align = sk.H_ALIGN_CENTER self.score_label.text = '0' self.score = 0 self.add_child(self.score_label) self.did_change_size(None)
def __init__(self): with open('words_en.data') as f: self.words = marshal.load(f) self.root = sk.Node() self.did_change_size(None) self.add_child(self.root) self.background_color = '#0b1d28' textures = {} for letter in letter_freq: with ui.ImageContext(tile_size, tile_size) as ctx: shadow = ui.Path.rounded_rect(0, 0, tile_size, tile_size, 5) ui.set_color('silver') shadow.fill() bg = ui.Path.rounded_rect(0, 0, tile_size, tile_size - 4, 5) ui.set_color('white') bg.fill() font = ('AvenirNext-Regular', font_size) w, h = ui.measure_string(letter.upper(), font=font) x, y = (tile_size - w) / 2, (tile_size - h) / 2 ui.draw_string(letter.upper(), rect=(x, y, w, h), font=font, color='black') textures[letter] = sk.Texture(ctx.get_image()) self.tile_textures = textures self.tiles = [[None] * rows for i in xrange(cols)] for x, y in product(xrange(cols), xrange(rows)): letter = choice(letter_bag) s = sk.SpriteNode(self.tile_textures[letter]) s.user_info = {'letter': letter, 'x': x, 'y': y} pos_x = tile_size / 2 + x * (tile_size + padding) pos_y = tile_size / 2 + y * (tile_size + padding) if x % 2 != 0: pos_y += tile_size / 2 s.position = pos_x, pos_y s.color_blend_factor = 1 s.color = 'white' self.tiles[x][y] = s self.root.add_child(s) self.selected = [] self.touched_tile = None
def __init__(self): with open('words_en.data') as f: self.words = marshal.load(f) self.root = sk.Node() self.add_child(self.root) self.background_color = '#0b1d28' self.tiles = [] self.selected = [] self.touched_tile = None self.score_label = sk.LabelNode() self.score_label.font_name = 'AvenirNext-Regular' self.score_label.font_size = 50 self.score_label.h_align = sk.H_ALIGN_CENTER self.score_label.text = '0' self.score = 0 self.game_over = False self.game_over_time = 0 self.add_child(self.score_label) self.word_label = sk.LabelNode() self.word_label.font_name = 'AvenirNext-Regular' self.add_child(self.word_label) self.time_label = sk.LabelNode() self.time_label.font_name = 'AvenirNext-Regular' self.time_label.text = '00:00' self.add_child(self.time_label) self.start_time = time.time() self.overlay = sk.SpriteNode() self.overlay.z_position = 3 self.overlay.color_blend_factor = 1 self.overlay.color = 'black' self.overlay.alpha = 0 time_up_label = sk.LabelNode() time_up_label.font_name = 'AvenirNext-Regular' time_up_label.text = 'Time Up!' time_up_label.font_size = 72 time_up_label.h_align = sk.H_ALIGN_CENTER self.overlay.add_child(time_up_label) self.add_child(self.overlay) self.did_change_size(None) self.new_game()
def __init__(self, dofft=False): self.v = [sk.SpriteNode() for x in xrange(int(Np))] for i, sp in enumerate(self.v): sp.size = (1.5, 1.5) sp.position = (float(i) / Np * W, H / 2) sp.color = (1.0 * i / Np, (1 - 1.0 * i / Np), (0.5 + i / 2.0)) self.add_child(sp) # first, start r[0] # then, 0.5 sec later, start r[1] # then, 0.5 sec later, start r[2], stop r[0] # read r[0], then start r[0], stop r[1] # basically, each frame we read/start one, and stop i+1 self.a1 = sk.Action.call(self.update_y) self.a2 = sk.wait(T / (Nr - 1)) self.a3 = sk.sequence([self.a1, self.a2]) self.a4 = sk.Action.repeat_forever(self.a3) n = sk.Node() n.name = 'n' self.add_child(n) n.run_action(self.a4) self.dofft = dofft self.idx = 0
def __init__(self, name, x=0): self.node = sk.load(name, sk.Node()) self.node.position = (x, 0) self.tiles = self.node['tile_*_*'] edge_types = 'RLTB' self.max_x = x for t in self.tiles: name_comps = t.name.split('_') tile_type = name_comps[1] tile_edges = name_comps[2] t.edges = {edge_types.index(e) for e in tile_edges} t.hitbox = t.frame.translate(x, 0) self.max_x = max(x + t.frame.max_x, self.max_x) if tile_type == 'spring': t.edges = {2} t.hitbox = sk.Rect(t.frame.x + x, t.frame.y, t.frame.w, t.frame.h / 2) self.hazards = self.node['hazard_*_*'] spike_insets = { 'T': (0, 5, 32, 5), 'B': (32, 5, 0, 5), 'L': (0, 32, 0, 0), 'R': (0, 0, 0, 32) } for t in self.hazards: name_comps = t.name.split('_') hazard_type = name_comps[1] if hazard_type == 'spikes': insets = spike_insets[name_comps[-1]] t.hitbox = t.frame.inset(*insets).translate(x, 0) else: t.hitbox = t.frame.translate(x, 0) self.items = self.node['item_*'] for i in self.items: i.hitbox = sk.Rect(i.position.x + x - 18, i.position.y - 18, 36, 36) i.collected = False i.z_position = 3
def __init__(self): self.music = sound.Player('Music/FranticLevel.m4a') self.music.number_of_loops = -1 self.music.volume = 0.1 self.game_paused = True self.background_color = '#ccf4f7' self.tiled_bg = sk.TiledSpriteNode(bg_texture, (1024, 512)) self.tiled_bg.position = 512, 256 self.add_child(self.tiled_bg) self.t = 0 self.ground_t = 0 self.standing = False self.jump_t = 0 self.jump_down = False self.game_over = False self.game_finished = False self.score = 0 self.highscore = 0 self.last_score = 0 try: with open('.Highscore.txt', 'r') as f: self.highscore = int(f.read()) except IOError: pass self.jetpack_active = False self.jetpack_fuel = 0 self.v = sk.Vector2(0, 0) self.player_speed = 4 self.player = player_and_effects['player'][0].__copy__() self.player.position = 50, 97 self.jetpack = self.player['jetpack'][0] self.jetpack['jetpack_flame'][0].hidden = True self.jetpack.alpha = 0 self.player.z_position = 2 self.player_sprite = self.player['sprite'][0] self.foreground_layer = sk.Node() self.foreground_layer.x_scale = zoom self.foreground_layer.y_scale = zoom self.foreground_layer.add_child(self.player) self.dust_effect = player_and_effects['dust'][0].__copy__() self.dust_effect.num_particles_to_emit = 0 self.foreground_layer.add_child(self.dust_effect) self.add_child(self.foreground_layer) self.levels = [] self.load_levels() self.score_hud = ScoreHUD() self.add_child(self.score_hud) self.highscore_label = sk.LabelNode() self.highscore_label.font_name = 'Avenir Next Condensed' self.highscore_label.font_size = 17 self.highscore_label.font_color = '#68c3d1' self.highscore_label.text = 'last: 0 / high: %i' % self.highscore self.add_child(self.highscore_label) paused_label = sk.LabelNode() paused_label.font_name = 'Avenir Next Condensed' paused_label.font_size = 50 paused_label.text = 'Tap to play' self.paused_overlay = sk.SpriteNode() self.paused_overlay.size = 1024, 1024 self.paused_overlay.color = (0, 0, 0, 0.4) self.paused_overlay.z_position = 10 self.paused_overlay.add_child(paused_label) self.add_child(self.paused_overlay)
# coding: utf-8 # (work-in-progress, but playable) import sk import sound from itertools import chain from random import choice from functools import partial import gc import ui zoom = 1.0 if max(ui.get_screen_size()) > 768 else 0.7 player_and_effects = sk.load('PlayerAndEffects.pysk', sk.Node()) star_effect = player_and_effects['stars'][0] standing_texture = sk.Texture('plf:AlienPink_stand') walk_textures = [ sk.Texture('plf:AlienPink_walk1'), sk.Texture('plf:AlienPink_walk2') ] jump_texture = sk.Texture('plf:AlienPink_jump') hit_texture = sk.Texture('plf:AlienPink_hit') spring_texture1 = sk.Texture('plf:Tile_Spring') spring_texture2 = sk.Texture('plf:Tile_Sprung') bg_texture = sk.Texture('plf:BG_Blue_grass') sounds = { 'coin': 'digital:PowerUp2', 'star': 'digital:PowerUp7', 'jump': 'digital:PhaserUp2', 'spring': 'digital:PhaserUp3', 'die': 'digital:ZapThreeToneDown', 'jetpack': 'digital:LowRandom',