Skip to content

Commit

Permalink
Update, work on issue pythonarcade#118
Browse files Browse the repository at this point in the history
  • Loading branch information
pvcraven committed Jul 14, 2017
1 parent 1db1854 commit e9c56c6
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
4 changes: 2 additions & 2 deletions arcade/buffered_draw_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,12 @@ def render(shape: VertexBuffer):
T = TypeVar('T', bound=VertexBuffer)


class ShapeList(Generic[T]):
class ShapeElementList(Generic[T]):
"""
>>> import arcade
>>> arcade.open_window(800,600,"Drawing Example")
>>> my_list = ShapeList()
>>> my_list = ShapeElementList()
>>> my_shape = arcade.create_ellipse_outline(50, 50, 20, 20, arcade.color.RED, 45)
>>> my_list.append(my_shape)
>>> my_shape = arcade.create_ellipse_filled(50, 50, 20, 20, arcade.color.RED, 2, 45)
Expand Down
2 changes: 1 addition & 1 deletion examples/array_backed_grid_buffered.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __init__(self, width, height):
"""
super().__init__(width, height)

self.shape_list = arcade.ShapeList()
self.shape_list = arcade.ShapeElementList()

# Create a 2 dimensional array. A two dimensional
# array is simply a list of lists.
Expand Down
2 changes: 1 addition & 1 deletion examples/lines_buffered.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __init__(self, width, height):
"""
super().__init__(width, height)

self.shape_list = arcade.ShapeList()
self.shape_list = arcade.ShapeElementList()

"""
my_line = arcade.create_line(-100, 0, 100, 0, arcade.color.PURPLE, 10)
Expand Down
32 changes: 20 additions & 12 deletions examples/pinball.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ def __init__(self, width, height, x, y, angle = 0):
class Poly(Shape):
def __init__(self, x, y, angle, vertices):
self.graphic_shape = arcade.create_polygon(vertices, arcade.color.WHITE, 1)
self.graphic_shape.center_x = x
self.graphic_shape.center_y = y
self.body = pymunk.Body(body_type=pymunk.Body.STATIC)

self.body.position = pymunk.Vec2d(x, y)
Expand All @@ -68,8 +70,8 @@ def __init__(self, width, height):
self.set_location(20, 20)
arcade.set_background_color(arcade.color.BLACK)

self.shape_list = arcade.ShapeList()

self.board_shape_element_list = arcade.ShapeElementList()
self.left_flipper = arcade.ShapeElementList()
self.balls = []

# -- Pymunk --
Expand All @@ -91,7 +93,7 @@ def __init__(self, width, height):
width = float(parameters[4])
height = float(parameters[5])
my_shape = Box(width, height, x, y, angle=angle)
self.shape_list.append(my_shape.graphic_shape)
self.board_shape_element_list.append(my_shape.graphic_shape)
self.space.add(my_shape.pymunk_shape)

if parameters[0] == "Poly":
Expand All @@ -107,22 +109,26 @@ def __init__(self, width, height):
y = float(parameters[i * 2 + 2])
vertices.append((x, y))

my_shape = Poly(vertices)
self.shape_list.append(my_shape.graphic_shape)
my_shape = Poly(0, 0, 0, vertices)
self.board_shape_element_list.append(my_shape.graphic_shape)
self.space.add(my_shape.pymunk_shape)
print("Poly")

except:
except Exception as e:
print(f"Error parsing line {line_number}: '{line}'")
print(e)
return


# vertices = [(20, -20), (-120, 0), (20, 20)]
# mass = 100
# moment = pymunk.moment_for_poly(mass, vertices)
vertices = [(2, -2), (-12, 0), (2, 2)]
#vertices = [(3, 3), (5, 3), (5, 5)]

mass = 100
moment = pymunk.moment_for_poly(mass, vertices)

# # right flipper
# graphic_shape = arcade.create_polygon(vertices, arcade.color.WHITE, 1)
# right flipper
left_flipper = Poly(5, 0, 0, vertices)
self.left_flipper.append(left_flipper.graphic_shape)
#
# r_flipper_body = pymunk.Body(mass, moment)
# r_flipper_body.position = 450, 100
Expand Down Expand Up @@ -155,7 +161,9 @@ def on_draw(self):
# This command has to happen before we start drawing
arcade.start_render()

self.shape_list.draw()
self.board_shape_element_list.draw()
self.left_flipper.draw()

for ball in self.balls:
arcade.draw_circle_filled(ball.position.x, ball.position.y, BALL_RADIUS, arcade.color.WHITE)

Expand Down

0 comments on commit e9c56c6

Please sign in to comment.