Esempio n. 1
0
    def update_rect(self):
        pos = Vector2()
        if self.pos:
            pos = self.pos
        if self.screen_relative_pos:
            pos = pos+self.screen_relative_pos*engine.get_screen_size()
        self.rect = Rect(pos, self.size, self.angle)

        center_pos = Vector2()
        if self.body:
            center_pos = physics_manager.get_body_position(self.body)
            if self.screen_relative_pos:
                center_pos = center_pos - self.screen_relative_pos*engine.get_screen_size()

            self.not_rot_pos = center_pos

        v = self.size/2
        v.rotate(-self.angle)
        if self.angle > 0:
            pos = self.not_rot_pos + (v-self.size/2)
        else:
            pos = self.not_rot_pos + (self.size/2-v)

        size_y = Vector2(self.size.x, 0)
        size_y.rotate(self.angle)
        v = Vector2(self.size.x, self.size.y + math.fabs(size_y.y))
        self.click_rect = Rect(self.not_rot_pos-v/2, v)
Esempio n. 2
0
 def update_state(self):
     RIGHT = get_button('player_right')
     LEFT = get_button('player_left')
     UP = get_button('player_up')
     DOWN = get_button('player_down')
     
     horizontal = RIGHT-LEFT
     vertical = UP-DOWN
     
     physics_events = get_physics_event()
     
     for event in physics_events:
         if (event.a.userData == 2 and event.b.userData == 11 ) or \
                 ( event.b.userData == 2 and event.a.userData == 11):
             if event.begin:
                 self.foot += 1
             else:
                 self.foot -= 1
     
     if horizontal == -1:
         self.direction = False
         if self.foot:
             self.state = 'move'
         self.player.flip = True
         physics_manager.move(self.player.body, -self.speed)
     elif horizontal == 1:
         self.direction = True
         if self.foot:
             self.state = 'move'
         self.player.flip = False
         physics_manager.move(self.player.body, self.speed)
     else:
         if self.foot:
             if self.direction:
                 self.state = 'still'
                 self.player.flip = False
             else:
                 self.state = 'still'
                 self.player.flip = True
         physics_manager.move(self.player.body, 0)
     if not self.foot:
         if self.direction:
             self.state = 'jump'
             self.player.flip = False
         else:
             self.state = 'jump_left'
             self.player.flip = True
     physics_pos = physics_manager.get_body_position(self.player.body)
     
     if physics_pos:
         pos = physics_pos-self.player.size/2
     else:
         pos = self.player.pos
     if self.player.screen_relative_pos:
         pos = pos-self.player.screen_relative_pos*engine.get_screen_size()
     self.player.pos = pos
Esempio n. 3
0
    def set_angle(self, angle, center=True):
        pos = Vector2()

        self.angle = angle % 360
        if self.angle > 180:
            self.angle -= 360

        if self.body:
            self.body.angle = self.angle*math.pi/180
        if center:
            if self.body:
                pos = physics_manager.get_body_position(self.body)
                if self.screen_relative_pos:
                    pos = pos - self.screen_relative_pos*physics_manager.get_screen_size()
                self.not_rot_pos = pos - self.size/2
                v = self.size/2
                v.rotate(self.angle)
                self.pos = self.not_rot_pos - v + self.size/2
        else:
            '''TODO: Readjust body pos'''
            pass

        self.update_rect()
Esempio n. 4
0
 def move(self, delta):
     self.pos = self.pos+delta
     if self.body:
         body_pos = physics_manager.get_body_position(self.body)
         physics_manager.set_body_position(self.body,body_pos+delta)
     self.update_rect()