10
10
If Python and Arcade are installed, this example can be run from the command line with:
11
11
python -m arcade.examples.easing_example_1
12
12
"""
13
+
13
14
import arcade
14
15
from arcade import easing
15
16
from arcade .types import Color
34
35
35
36
36
37
class EasingCircle (arcade .SpriteCircle ):
37
- """ Player class """
38
+ """Player class"""
38
39
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"""
41
42
42
43
# Call the parent init
43
- super ().__init__ (radius , color )
44
+ super ().__init__ (radius , color , center_x = center_x , center_y = center_y )
44
45
45
46
self .easing_x_data = None
46
47
self .easing_y_data = None
@@ -52,10 +53,12 @@ def update(self, delta_time: float = 1 / 60):
52
53
x = X_START
53
54
if self .center_x < WINDOW_WIDTH / 2 :
54
55
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
+ )
59
62
self .easing_x_data = ex
60
63
61
64
if self .easing_y_data is not None :
@@ -65,10 +68,10 @@ def update(self, delta_time: float = 1 / 60):
65
68
66
69
67
70
class GameView (arcade .View ):
68
- """ Main application class. """
71
+ """Main application class."""
69
72
70
73
def __init__ (self ):
71
- """ Initializer """
74
+ """Initializer"""
72
75
73
76
# Call the parent class initializer
74
77
super ().__init__ ()
@@ -81,15 +84,16 @@ def __init__(self):
81
84
self .lines = None
82
85
83
86
def setup (self ):
84
- """ Set up the game and initialize the variables. """
87
+ """Set up the game and initialize the variables."""
85
88
86
89
# Sprite lists
87
90
self .ball_list = arcade .SpriteList ()
88
91
self .lines = arcade .shape_list .ShapeElementList ()
92
+ color = Color .from_hex_string (BALL_COLOR )
93
+ shared_ball_kwargs = dict (radius = BALL_RADIUS , color = color )
89
94
90
95
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 )
93
97
p1 = ball .position
94
98
p2 = (X_END , ball_y )
95
99
ex , ey = easing .ease_position (p1 , p2 , time = TIME , ease_function = ease_function )
@@ -100,9 +104,12 @@ def create_ball(ball_y, ease_function):
100
104
101
105
def create_line (line_y ):
102
106
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 ,
106
113
)
107
114
return line
108
115
@@ -161,7 +168,7 @@ def add_item(item_y, ease_function, text):
161
168
add_item (y , easing .ease_in_out_sin , "Ease in out sin" )
162
169
163
170
def on_draw (self ):
164
- """ Render the screen. """
171
+ """Render the screen."""
165
172
166
173
# This command has to happen before we start drawing
167
174
self .clear ()
@@ -175,15 +182,15 @@ def on_draw(self):
175
182
text .draw ()
176
183
177
184
def on_update (self , delta_time ):
178
- """ Movement and game logic """
185
+ """Movement and game logic"""
179
186
180
187
# Call update on all sprites (The sprites don't do much in this
181
188
# example though.)
182
189
self .ball_list .update (delta_time )
183
190
184
191
185
192
def main ():
186
- """ Main function """
193
+ """Main function"""
187
194
# Create a window class. This is what actually shows up on screen
188
195
window = arcade .Window (WINDOW_WIDTH , WINDOW_HEIGHT , WINDOW_TITLE )
189
196
0 commit comments