본문 바로가기

pygame_phyics

pygame phyics 업데이트

변경사항:

맵 함수 생성방식이 변경됨

@game.phyics_world("example/example.json")
def example():
    rect : DynamicObject= Manger.scene.get_objects("hello")[0]
    circle = Manger.scene.get_objects("ello")[0]
    text = Manger.scene.get_objects("eello")[0]
    inputfield : InputField = Manger.scene.get_objects("eeldlo")[0]
    def start(cls):
        text.text = 'hello\nworld!\n 한국어'
        rect.create_joint(4.0, 0.5, circle)
        def inputd(text):
            print(text)
        inputfield.input_event.add_lisner(inputd)
    def event(cls, event):
        if event.type == pygame.K_q:
            cls.stop()
    def update(cls):
        Manger.screen.fill((60, 60, 60, 255))
    return start, event, update

 

함수 작성방식은 먼저 필요시 오브젝트를 가져와서 사용 

start, event, update 함수를 만들고

start, event, update 순으로 반환하면 됩니다.

 

시작할때, 이벤트 루프를 돌떄, 틱 업데이트때 한번씩 실행됩니다.

 

물리 오브젝트가 충돌시 실행되는 함수가 추가되었습니다

StaticObject 또는 DynamicObject 를 상속받은 오브젝트에서

class Fruit(DynamicObject):
    def __init__(self, name, tag, visible, position, collid_visible):
        super().__init__(name, tag, visible, 3, position, 0, fruitscale[tag], "circle", collid_visible, 1, 0.3)
        self.color = fruitcolor[tag]
        
    def on_collision_enter(self, collision):
        if collision.tag == self.tag:
            collision.delete()
            if self.tag != 6:
                prefab = Fruit("fr", self.tag+1, True, self.position, True)
                GameObject.instantiate(prefab)
            Manger.score += self.tag * 5
            self.delete()
            
        
    def render(self, surface, camera):
        circle = self.body.fixtures[0].shape
        body = self.body
        position = body.transform * circle.pos * PPM
        position = (position[0] - camera[0], Manger.HEIGHT - position[1] - camera[1])
        pygame.draw.circle(surface, self.color, [int(
            x) for x in position], int(circle.radius * PPM), 1)

on_collision_enter 를 사용하시면 됩니다.

.

 

github: https://github.com/fireing123/pygame_phyics