got something running and added object oriented
This commit is contained in:
parent
ede0769767
commit
e116c3add0
1 changed files with 49 additions and 15 deletions
66
src/main.py
66
src/main.py
|
@ -1,24 +1,58 @@
|
||||||
|
__docformat__ = "reStructuredText"
|
||||||
|
|
||||||
import pymunk, pymunk.pygame_util, pygame
|
import pymunk, pymunk.pygame_util, pygame
|
||||||
|
|
||||||
space = pymunk.Space()
|
class riseToFall(object):
|
||||||
space.gravity = 0,-1000
|
"""
|
||||||
|
riseToFall game class
|
||||||
|
"""
|
||||||
|
|
||||||
body = pymunk.Body(1,1666)
|
def __init__(self) -> None:
|
||||||
body.position = 50,100
|
# create space
|
||||||
|
self._space = pymunk.Space()
|
||||||
|
self._space.gravity = 0,10
|
||||||
|
|
||||||
poly = pymunk.Poly.create_box(body)
|
# initialize pygame
|
||||||
|
pygame.init()
|
||||||
|
self._screen = pygame.display.set_mode((400,600))
|
||||||
|
self._clock = pygame.time.Clock()
|
||||||
|
|
||||||
space.add(body, poly)
|
# set caption
|
||||||
|
pygame.display.set_caption("rise to fall")
|
||||||
|
|
||||||
pygame.init()
|
self._running = True
|
||||||
screen = pygame.display.set_mode([400,600])
|
# font = pygame.font.SysFont("Arial",16)
|
||||||
clock = pygame.time.Clock()
|
|
||||||
running = True
|
# set draw options
|
||||||
# font = pygame.font.SysFont("Arial",16)
|
self._print_options = pymunk.pygame_util.DrawOptions(self._screen)
|
||||||
|
|
||||||
|
def _createBox(self):
|
||||||
|
body = pymunk.Body(1,1666)
|
||||||
|
body.position = 50,100
|
||||||
|
|
||||||
|
poly = pymunk.Poly.create_box(body)
|
||||||
|
|
||||||
|
self._space.add(body, poly)
|
||||||
|
|
||||||
|
def _processEvents(self):
|
||||||
|
for event in pygame.event.get():
|
||||||
|
if event.type == pygame.QUIT:
|
||||||
|
self._running = False
|
||||||
|
if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
|
||||||
|
self._running = False
|
||||||
|
if event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE:
|
||||||
|
self._createBox()
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
while self._running:
|
||||||
|
self._processEvents();
|
||||||
|
self._space.step(0.02)
|
||||||
|
self._screen.fill(pygame.Color("white"))
|
||||||
|
self._space.debug_draw(self._print_options)
|
||||||
|
pygame.display.flip()
|
||||||
|
|
||||||
|
|
||||||
print_options = pymunk.pygame_util.DrawOptions(screen)
|
if __name__ == "__main__":
|
||||||
|
game = riseToFall()
|
||||||
while True:
|
game._createBox()
|
||||||
space.step(0.02)
|
game.run()
|
||||||
space.debug_draw(print_options)
|
|
||||||
|
|
Loading…
Reference in a new issue