Coimment about installing pymunk
This commit is contained in:
parent
3717b318b0
commit
225eada259
|
@ -5,6 +5,7 @@ import random
|
|||
import socket
|
||||
|
||||
"""
|
||||
python -m pip install pymunk==5.7.0
|
||||
Demo that shows integrating PySimpleGUI with the pymunk library. This combination
|
||||
of PySimpleGUI and pymunk could be used to build games.
|
||||
Note this exact same demo runs with PySimpleGUIWeb by changing the import statement
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import PySimpleGUIWeb as sg
|
||||
import PySimpleGUI as sg
|
||||
# import PySimpleGUIWeb as sg
|
||||
import pymunk
|
||||
import random
|
||||
import socket
|
||||
|
@ -7,6 +8,8 @@ import socket
|
|||
|
||||
|
||||
"""
|
||||
To get a good version of pymunk that works with this code:
|
||||
python -m pip install pymunk==5.7.0
|
||||
Demo that shows integrating PySimpleGUI with the pymunk library. This combination
|
||||
of PySimpleGUI and pymunk could be used to build games.
|
||||
Note this exact same demo runs with PySimpleGUIWeb by changing the import statement
|
||||
|
@ -28,7 +31,8 @@ class Ball():
|
|||
|
||||
|
||||
class Playfield():
|
||||
def __init__(self):
|
||||
def __init__(self, graph_elem):
|
||||
self.graph_elem = graph_elem
|
||||
self.space = pymunk.Space()
|
||||
self.space.gravity = 0, 200
|
||||
self.add_wall((0, 400), (600, 400)) # ground
|
||||
|
@ -50,9 +54,13 @@ class Playfield():
|
|||
r = random.randint(1, 10)
|
||||
ball = Ball(x, y, r)
|
||||
self.arena_balls.append(ball)
|
||||
area.space.add(ball.body, ball.shape)
|
||||
ball.gui_circle_figure = graph_elem.draw_circle(
|
||||
(x, y), r, fill_color='black', line_color='red')
|
||||
self.space.add(ball.body, ball.shape)
|
||||
ball.gui_circle_figure = self.graph_elem.draw_circle(
|
||||
(x, y), r, fill_color='black', line_width=0)
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
|
||||
|
||||
# ------------------- Build and show the GUI Window -------------------
|
||||
|
@ -67,12 +75,12 @@ layout = [[sg.Text('Ball Test'), sg.Text('My IP '+hostname)],
|
|||
|
||||
window = sg.Window('Window Title', layout, finalize=True)
|
||||
|
||||
area = Playfield()
|
||||
area = Playfield(graph_elem)
|
||||
area.add_balls()
|
||||
|
||||
# ------------------- GUI Event Loop -------------------
|
||||
while True: # Event Loop
|
||||
event, values = window.read(timeout=0)
|
||||
event, values = window.read(timeout=1)
|
||||
# print(event, values)
|
||||
if event in (sg.WIN_CLOSED, 'Exit'):
|
||||
break
|
||||
|
@ -86,3 +94,6 @@ while True: # Event Loop
|
|||
ball.gui_circle_figure, ball.body.position[0], ball.body.position[1])
|
||||
|
||||
window.close()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Loading…
Reference in New Issue