Skip to content

Commit 5b4b19d

Browse files
committed
Update easing_example_1 with center_*
* Use center_x and center_y arguments * Use shared kwargs to shorten code
1 parent d69238e commit 5b4b19d

File tree

1 file changed

+26
-19
lines changed

1 file changed

+26
-19
lines changed

arcade/examples/easing_example_1.py

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
If Python and Arcade are installed, this example can be run from the command line with:
1111
python -m arcade.examples.easing_example_1
1212
"""
13+
1314
import arcade
1415
from arcade import easing
1516
from arcade.types import Color
@@ -34,13 +35,13 @@
3435

3536

3637
class EasingCircle(arcade.SpriteCircle):
37-
""" Player class """
38+
"""Player class"""
3839

39-
def __init__(self, radius, color):
40-
""" Set up the player """
40+
def __init__(self, radius, color, center_x: float = 0, center_y: float = 0):
41+
"""Set up the player"""
4142

4243
# Call the parent init
43-
super().__init__(radius, color)
44+
super().__init__(radius, color, center_x=center_x, center_y=center_y)
4445

4546
self.easing_x_data = None
4647
self.easing_y_data = None
@@ -52,10 +53,12 @@ def update(self, delta_time: float = 1 / 60):
5253
x = X_START
5354
if self.center_x < WINDOW_WIDTH / 2:
5455
x = X_END
55-
ex, ey = easing.ease_position(self.position,
56-
(x, self.center_y),
57-
rate=180,
58-
ease_function=self.easing_x_data.ease_function)
56+
ex, ey = easing.ease_position(
57+
self.position,
58+
(x, self.center_y),
59+
rate=180,
60+
ease_function=self.easing_x_data.ease_function,
61+
)
5962
self.easing_x_data = ex
6063

6164
if self.easing_y_data is not None:
@@ -65,10 +68,10 @@ def update(self, delta_time: float = 1 / 60):
6568

6669

6770
class GameView(arcade.View):
68-
""" Main application class. """
71+
"""Main application class."""
6972

7073
def __init__(self):
71-
""" Initializer """
74+
"""Initializer"""
7275

7376
# Call the parent class initializer
7477
super().__init__()
@@ -81,15 +84,16 @@ def __init__(self):
8184
self.lines = None
8285

8386
def setup(self):
84-
""" Set up the game and initialize the variables. """
87+
"""Set up the game and initialize the variables."""
8588

8689
# Sprite lists
8790
self.ball_list = arcade.SpriteList()
8891
self.lines = arcade.shape_list.ShapeElementList()
92+
color = Color.from_hex_string(BALL_COLOR)
93+
shared_ball_kwargs = dict(radius=BALL_RADIUS, color=color)
8994

9095
def create_ball(ball_y, ease_function):
91-
ball = EasingCircle(BALL_RADIUS, Color.from_hex_string(BALL_COLOR))
92-
ball.position = X_START, ball_y
96+
ball = EasingCircle(**shared_ball_kwargs, center_x=X_START, center_y=ball_y)
9397
p1 = ball.position
9498
p2 = (X_END, ball_y)
9599
ex, ey = easing.ease_position(p1, p2, time=TIME, ease_function=ease_function)
@@ -100,9 +104,12 @@ def create_ball(ball_y, ease_function):
100104

101105
def create_line(line_y):
102106
line = arcade.shape_list.create_line(
103-
X_START, line_y - BALL_RADIUS - LINE_WIDTH,
104-
X_END, line_y - BALL_RADIUS,
105-
line_color, line_width=LINE_WIDTH,
107+
X_START,
108+
line_y - BALL_RADIUS - LINE_WIDTH,
109+
X_END,
110+
line_y - BALL_RADIUS,
111+
line_color,
112+
line_width=LINE_WIDTH,
106113
)
107114
return line
108115

@@ -161,7 +168,7 @@ def add_item(item_y, ease_function, text):
161168
add_item(y, easing.ease_in_out_sin, "Ease in out sin")
162169

163170
def on_draw(self):
164-
""" Render the screen. """
171+
"""Render the screen."""
165172

166173
# This command has to happen before we start drawing
167174
self.clear()
@@ -175,15 +182,15 @@ def on_draw(self):
175182
text.draw()
176183

177184
def on_update(self, delta_time):
178-
""" Movement and game logic """
185+
"""Movement and game logic"""
179186

180187
# Call update on all sprites (The sprites don't do much in this
181188
# example though.)
182189
self.ball_list.update(delta_time)
183190

184191

185192
def main():
186-
""" Main function """
193+
"""Main function"""
187194
# Create a window class. This is what actually shows up on screen
188195
window = arcade.Window(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_TITLE)
189196

0 commit comments

Comments
 (0)