Beispiel #1
0
    def _update_position(self):
        """Updates the vertex list"""
        if not self._visible:
            self._vertex_list.vertices[:] = [0, 0, 0, 0, 0, 0, 0, 0]
            return

        img = self._texture
        if self.transform_anchor_x == self.transform_anchor_y == 0:

            if self._rotation:
                x1 = -self._image_anchor_x * self._scale * self._scale_x
                y1 = -self._image_anchor_y * self._scale * self._scale_y
                x2 = x1 + img.width*self._scale*self._scale_x
                y2 = y1 + img.height*self._scale*self._scale_y
                x = self._x
                y = self._y

                r = -math.radians(self._rotation)
                cr = math.cos(r)
                sr = math.sin(r)
                ax = int(x1*cr - y1*sr + x)
                ay = int(x1*sr + y1*cr + y)
                bx = int(x2*cr - y1*sr + x)
                by = int(x2*sr + y1*cr + y)
                cx = int(x2*cr - y2*sr + x)
                cy = int(x2*sr + y2*cr + y)
                dx = int(x1*cr - y2*sr + x)
                dy = int(x1*sr + y2*cr + y)

                self._vertex_list.vertices[:] = [ax, ay, bx, by, cx, cy, dx, dy]
            elif self._scale != 1.0 or self._scale_x != 1.0 or self._scale_y != 1.0:
                x1 = int(self._x - self._image_anchor_x*self._scale*self._scale_x)
                y1 = int(self._y - self._image_anchor_y*self._scale*self._scale_y)
                x2 = int(x1 + img.width*self._scale*self._scale_x)
                y2 = int(y1 + img.height*self._scale*self._scale_y)
                self._vertex_list.vertices[:] = [x1, y1, x2, y1, x2, y2, x1, y2]
            else:
                x1 = int(self._x - self._image_anchor_x)
                y1 = int(self._y - self._image_anchor_y)
                x2 = x1 + img.width
                y2 = y1 + img.height
                self._vertex_list.vertices[:] = [x1, y1, x2, y1, x2, y2, x1, y2]
        else:
            x1 = int(-self._image_anchor_x)
            y1 = int(-self._image_anchor_y)
            x2 = x1 + img.width
            y2 = y1 + img.height
            m = self.get_local_transform()
            p1 = m * euclid.Point2(x1, y1)
            p2 = m * euclid.Point2(x2, y1)
            p3 = m * euclid.Point2(x2, y2)
            p4 = m * euclid.Point2(x1, y2)

            self._vertex_list.vertices[:] = [
                int(p1.x), int(p1.y), int(p2.x), int(p2.y),
                int(p3.x), int(p3.y), int(p4.x), int(p4.y)]
Beispiel #2
0
 def generate_control_points(self):
     if self.editable_skeleton:
         skinpos = euclid.Point2(*self.editable_skin.position)
         for cp in self.editable_skeleton.get_control_points():
             if isinstance(cp, Skeleton):
                 self.add(SkeletonControl(cp, skinpos))
             else:
                 self.add(BoneControl(cp, skinpos))
Beispiel #3
0
    def point_to_local(self, p):
        '''returns an euclid.Vector2 converted to local space

        :rtype: euclid.Vector2
        '''
        v = euclid.Point2(p[0], p[1])
        matrix = self.get_world_inverse()
        return matrix * v
 def update(self, dt):
     if self.planet is not None:
         super(Player, self).update(dt)
         gx = 20 * math.cos(self.angle)
         gy = 20 * math.sin(self.angle)
         self.particles.gravity = eu.Point2(gx, -gy)
     else:
         self.position += self.direction * dt
Beispiel #5
0
    def point_to_world(self, p):
        '''returns an euclid.Vector2 converted to world space

        :rtype: euclid.Vector2
        '''
        v = euclid.Point2(p[0], p[1])
        matrix = self.get_world_transform()
        return matrix * v
Beispiel #6
0
 def __init__(self, label, size, rotation, translation):
     self.size = size
     self.label = label
     self.children = []
     self.matrix = euclid.Matrix3.new_translate(*translation) * \
         euclid.Matrix3.new_rotate(math.radians(rotation))
     self.parent_matrix = euclid.Matrix3.new_identity()
     self.translation = euclid.Point2(*translation)
     self.rotation = math.radians(rotation)
Beispiel #7
0
    def test_add(self):
        a = (3.0, 7.0)
        b = (1.0, 2.0)
        va = eu.Vector2(*a)
        vb = eu.Vector2(*b)

        self.assertTrue(isinstance(va + vb, eu.Vector2))
        self.assertEqual(repr(va + vb), 'Vector2(%.2f, %.2f)' % (4.0, 9.0))

        c = (11.0, 17.0)
        pc = eu.Point2(*c)
        d = (13.0, 23.0)
        pd = eu.Point2(*d)

        self.assertTrue(isinstance(va + pc, eu.Point2))
        self.assertTrue(isinstance(pc + pd, eu.Vector2))

        self.assertTrue(isinstance(va + b, eu.Vector2))
        self.assertEqual(va + vb, va + b)
Beispiel #8
0
    def on_dragged(self, dx, dy):
        super(BoneControl, self).on_dragged(dx, dy)

        def angle_between(v1, v2):
            v1 = v1.normalized()
            v2 = v2.normalized()
            a1 = v2a(*v1)
            a2 = v2a(*v2)
            return a2 - a1

        o = self.bone.get_start()
        e = self.bone.get_end()
        ne = euclid.Point2(self.x + dx - self.delta[0],
                           self.y + dy - self.delta[1])
        v1 = euclid.Point2(*(e - o))
        v2 = euclid.Point2(*(ne - o))

        alpha = angle_between(v1, v2)
        self.bone.rotate(alpha)
Beispiel #9
0
    def __init__(self):
        super(Pipes, self).__init__()

        self.winow_width, self.window_height = director.get_window_size()

        self.image = pyglet.resource.image('pipe.png')
        self.speedX = -100
        self.pos = eu.Point2(self.winow_width + self.image.width,
                             self.window_height / 2)
        self.update_collision_box()
Beispiel #10
0
    def point_to_local(self, p):
        """returns an :class:`.euclid.Vector2` converted to local space.

        Arguments:
            p (Vector2): Vector to convert.

        Returns:
            Vector2: ``p`` vector converted to local coordinates.
        """
        v = euclid.Point2(p[0], p[1])
        matrix = self.get_world_inverse()
        return matrix * v
Beispiel #11
0
    def point_to_world(self, p):
        """Returns an :class:`.euclid.Vector2` converted to world space.

        Arguments:
            p (Vector2): Vector to convert

        Returns:
            Vector2: ``p`` vector converted to world coordinates.
        """
        v = euclid.Point2(p[0], p[1])
        matrix = self.get_world_transform()
        return matrix * v
Beispiel #12
0
    def __init__(self):
        super(Bird, self).__init__()

        width, height = director.get_window_size()

        self.image = pyglet.resource.image('bird1.png')
        self.top_of_screen = height
        self.gravity = -300
        self.speedY = 0.0
        self.pos = eu.Point2(width / 2 - 30, height / 2)
        self.radius = 2
        self.update_collision_box()
Beispiel #13
0
 def generate_control_points(self):
     skinpos = euclid.Point2(*self.skin.position)
     for cp in self.skeleton.get_control_points():
         if isinstance(cp, Skeleton):
             self.add(SkeletonControl(cp, skinpos), z=3)
         else:
             self.add(BoneControl(cp, skinpos), z=4)
     bones = self.skeleton.visit_children(lambda bone: (bone.label, bone))
     bones = dict(bones)
     for bone in bones.values():
         self.add(BonePositionControl(bone, skinpos), z=2)
     for idx, name in self.skin.get_control_points():
         self.add(SkinControl(self.skin, idx, bones[name], skinpos), z=5)
Beispiel #14
0
    def test_swizzle_get(self):
        xy = (1.0, 2.0)
        v2 = eu.Point2(*xy)
        self.assertEqual(v2.x, xy[0])
        self.assertEqual(v2.y, xy[1])
        self.assertEqual(v2.xy, xy)
        self.assertEqual(v2.yx, (xy[1], xy[0]))

        exception = None
        try:
            v2.z == 11.0
        except Exception as a:
            exception = a
        assert isinstance(exception, AttributeError)
Beispiel #15
0
    def set_end_pos(self, position):
        position = self.get_world_inverse() * euclid.Point2(position[0], position[1])
        if self.end_square is None:
            self.end_square = cocos.layer.ColorLayer(
                200, 0, 0, 255,
                g_grid_size * g_player_size,
                g_grid_size * g_player_size)
            self.add(self.end_square)

        # align to grid
        aligned_pos = self.world_to_aligned_world(position)
        if aligned_pos != self.end_square.position:
            self.end_square.position = aligned_pos
            self.update_path()
Beispiel #16
0
class Trail(particle_systems.Explosion):
    # customise an Explosion particle system to emit sparks
    angle = 180
    angle_var = 5
    speed = 250
    speed_var = 50
    gravity = euclid.Point2(0, 0)
    duration = 1.
    start_color = particle.Color(1, 1, 1, .5)
    start_color_var = particle.Color(0, 0, 0, 0.0)
    end_color = particle.Color(1.0, 1.0, 1.0, 0.0)
    end_color_var = particle.Color(0, 0, 0, 0)
    emission_rate = 20
    size = 10
    size_var = 5
    def blit_image(self, matrix, position, scale, image):
        x, y = image.width*scale, image.height*scale
        #dx = self.x + position[0]
        #dy = self.y + position[1]
        dx, dy = position
        glEnable(image.target)
        glBindTexture(image.target, image.id)
        glPushAttrib(GL_COLOR_BUFFER_BIT)
        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

        # blit img
        points = [
            (-dx, -dy),
            (x-dx, -dy),
            (x-dx, y-dy),
            (-dx, y-dy)
            ]
        a,b,_,c,d,_,e,f,_,g,h,_ = image.texture.tex_coords
        textures = [ a,b,c,d,e,f,g,h ]
        np = [ matrix*euclid.Point2(*p) for p in points ]


        glColor4ub(255,255,255,self.alpha)
        glBegin(GL_QUADS)
        glTexCoord2f(a,b)
        glVertex2f(*np[0])
        glTexCoord2f(c,d)
        glVertex2f(*np[1])
        glTexCoord2f(e,f)
        glVertex2f(*np[2])
        glTexCoord2f(g,h)
        glVertex2f(*np[3])
        glEnd()
        glColor4ub(255,255,255,255)
        #pyglet.graphics.draw(4, GL_QUADS,
        #    ("v2f", new_points),
        #    ("t2f", textures),
        #    ("c4B", [255,255,255,self.alpha]*4),
        #    )

        glPopAttrib()
        glDisable(image.target)
class ActorExplosion(ps.ParticleSystem):
    total_particles = 400
    duration = 0.1
    gravity = eu.Point2(0, 0)
    angle = 90.0
    angle_var = 360.0
    speed = 40.0
    speed_var = 20.0
    life = 3.0
    life_var = 1.5
    emission_rate = total_particles / duration
    start_color_var = ps.Color(0.0, 0.0, 0.0, 0.2)
    end_color = ps.Color(0.0, 0.0, 0.0, 1.0)
    end_color_var = ps.Color(0.0, 0.0, 0.0, 0.0)
    size = 15.0
    size_var = 10.0
    blend_additive = True

    def __init__(self, pos, particles):
        super(ActorExplosion, self).__init__()
        self.position = pos
        self.start_color = particles.start_color
Beispiel #19
0
 def get_start(self):
     return self.parent_matrix * self.matrix * euclid.Point2(0, 0)
Beispiel #20
0
 def get_end(self):
     return self.parent_matrix * self.matrix * euclid.Point2(0, -self.size)
Beispiel #21
0
 def toggle_grid_obstacle(self, position):
     position = self.get_world_inverse() * euclid.Point2(position[0], position[1])
     # Toggle this obstacle
     self.set_grid_obstructed(position, not self.get_grid_obstacle(position))
Beispiel #22
0
 def __init__(self, bone, delta):
     super(BoneControl, self).__init__(7, (255, 0, 0, 255))
     self.bone = bone
     self.position = bone.get_end() + euclid.Point2(*delta)
     self.delta = delta
 def move_from_left_corner_to_out_of_screen(self, sprite):
     destination = eu.Point2(-sprite.width, 0)
     action_move = MoveTo(destination, self.get_time() * 3)
     # sprite.do(sequence(action_move, CallFunc(self.keep_going())))
     sprite.do(action_move)
 def move_from_corner_right_to_center(self, sprite):
     destination = eu.Point2(0, 0)
     action_move = MoveTo(destination, self.get_time() * 3)
     sprite.do(action_move)
 def switch(self):
     new_dir = eu.Vector2(self.y - self.planet.y, self.planet.x - self.x)
     self.direction = new_dir.normalized() * self.linear_speed
     self.planet = None
     self.particles.gravity = eu.Point2(-self.direction.x, -self.direction.y)