Ejemplo n.º 1
0
 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)
Ejemplo n.º 2
0
 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)
Ejemplo n.º 3
0
    def resolve_collisions(self):
        tiles = self.levels[self.current_level_idx].tiles
        p = self.player
        v = self.v
        if self.game_over:
            p.position += v
            return
        collision_tiles = []
        result_pos = list(p.position + self.v)
        result_v = list(self.v)
        p_hitbox = sk.Rect(p.position.x - 16, p.position.y - 31, 32, 63)
        hit_ground = False
        for a1, a2 in enumerate((1, 0)):
            if v[a1] == 0:
                continue
            d = 1.0 if v[a1] > 0 else -1.0
            p_edge = p_hitbox.max(a1) if d > 0 else p_hitbox.min(a1)
            p_edge_min, p_edge_max = (f(p_edge, p_edge + v[a1])
                                      for f in (min, max))
            target_frame = p_hitbox.translate(v.x, v.y)
            tile_edge_idx = (a1 * 2) + (1 if v[a1] > 0 else 0)
            for tile in tiles:
                if tile_edge_idx not in tile.edges: continue
                t_frame = tile.hitbox
                if t_frame.min(a2) >= target_frame.max(a2) or t_frame.max(
                        a2) <= target_frame.min(a2):
                    continue
                tile_edge = t_frame.min(a1) if d > 0 else t_frame.max(a1)
                if p_edge_max >= tile_edge >= p_edge_min:
                    if a1 == 1 and tile_edge_idx == 2:
                        self.ground_t = self.t
                    result_pos[a1] = tile_edge - d * p_hitbox[a1 +
                                                              2] / 2 - d * 0.5
                    result_v[a1] = 0
                    collision_tiles.append(tile)
                    break
            v = sk.Vector2(*result_v)
        p.position = result_pos
        self.v = v
        self.standing = self.t - self.ground_t < 4

        for t in collision_tiles:
            if t.name.startswith('tile_spring'):
                t.texture = spring_texture2
                reset = sk.call(partial(setattr, t, 'texture',
                                        spring_texture1))
                t.run_action(sk.sequence([sk.wait(0.2), reset]))
                self.jump(24)
                self.play_sound('spring')
Ejemplo n.º 4
0
	def resolve_collisions(self):
		tiles = self.levels[self.current_level_idx].tiles
		p = self.player
		v = self.v
		if self.game_over:
			p.position += v
			return
		collision_tiles = []
		result_pos = list(p.position + self.v)
		result_v = list(self.v)
		p_hitbox = sk.Rect(p.position.x-16, p.position.y-31, 32, 63)
		hit_ground = False
		for a1, a2 in enumerate((1, 0)):
			if v[a1] == 0:
				continue
			d = 1.0 if v[a1] > 0 else -1.0
			p_edge = p_hitbox.max(a1) if d > 0 else p_hitbox.min(a1)
			p_edge_min, p_edge_max = (f(p_edge, p_edge+v[a1]) for f in (min, max))
			target_frame = p_hitbox.translate(v.x, v.y)
			tile_edge_idx = (a1 * 2) + (1 if v[a1] > 0 else 0)
			for tile in tiles:
				if tile_edge_idx not in tile.edges: continue
				t_frame = tile.hitbox
				if t_frame.min(a2) >= target_frame.max(a2) or t_frame.max(a2) <= target_frame.min(a2):
					continue
				tile_edge = t_frame.min(a1) if d > 0 else t_frame.max(a1)
				if p_edge_max >= tile_edge >= p_edge_min:
					if a1 == 1 and tile_edge_idx == 2:
						self.ground_t = self.t
					result_pos[a1] = tile_edge - d*p_hitbox[a1+2]/2 - d*0.5
					result_v[a1] = 0
					collision_tiles.append(tile)
					break
			v = sk.Vector2(*result_v)
		p.position = result_pos
		self.v = v
		self.standing = self.t - self.ground_t < 4
		
		for t in collision_tiles:
			if t.name.startswith('tile_spring'):
				t.texture = spring_texture2
				reset = sk.call(partial(setattr, t, 'texture', spring_texture1))
				t.run_action(sk.sequence([sk.wait(0.2), reset]))
				self.jump(24)
				self.play_sound('spring')
Ejemplo n.º 5
0
 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
Ejemplo n.º 6
0
 def touch_ended(self, node, touch):
     e = self.emitters.get(touch.touch_id)
     e.p_birth_rate = 0
     e.run_action(sk.sequence([sk.wait(5), sk.call(e.remove_from_parent)]))
     del self.emitters[touch.touch_id]