변경사항:
맵 함수 생성방식이 변경됨
@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 를 사용하시면 됩니다.
.
'pygame_phyics' 카테고리의 다른 글
[pygame] 버튼, text 줄넘김 구현 (0) | 2023.11.05 |
---|---|
[pygame_phyics] 기본 오브젝트 예제 & 설명 (0) | 2023.11.02 |
pygame 입력 필드 만들기 (3) | 2023.11.02 |
[pygame_phyics] save 소개 & 사용시 GameObject 주의사항 (0) | 2023.10.31 |
[pygame_phyics] 라이브러리 소개 (0) | 2023.10.04 |