11"""
2- Arrange widgets in vertical or horizontal lines with UIBoxLayout
2+ This example shows how to use arcade.gui with a camera.
3+ It is a simple game where the player can move around and collect coins.
4+ The player can upgrade their speed and the spawn rate of the coins.
5+ The game has a timer and ends after 60 seconds.
6+ The game is controlled with the arrow keys or WASD.
37
4- The direction UIBoxLayout follows is controlled by the `vertical` keyword
5- argument. It is True by default. Pass False to it to arrange elements in
6- a horizontal line.
8+ At the beginning of the game, the UI camera is used, to apply some animations.
79
810If arcade and Python are properly installed, you can run this example with:
911python -m arcade.gui.examples.gui_and_camera
@@ -26,7 +28,7 @@ class MyCoinGame(UIView):
2628 basic GUI setup. We add UIManager to the view under `self.ui`.
2729
2830 The example showcases how to:
29- - use UIView to setup a basic GUI
31+ - use UIView to set up a basic GUI
3032 - add a button to the view and connect it to a function
3133 - use camera to move the view
3234
@@ -37,8 +39,8 @@ def __init__(self):
3739
3840 # basic camera setup
3941 self .keys = set ()
40- self .ingame_camera = arcade .Camera2D ()
41- self .ingame_camera .bottom_left = 100 , 100
42+ self .in_game_camera = arcade .Camera2D ()
43+ self .in_game_camera .bottom_left = 100 , 100
4244
4345 # in-game counter
4446 self ._total_time = 0
@@ -157,7 +159,7 @@ def upgrade_spawn_rate(event: UIOnClickEvent):
157159 self .cam_pos = self .ui .camera .position
158160
159161 def on_draw_before_ui (self ):
160- self .ingame_camera .use () # use the in-game camera to draw in-game objects
162+ self .in_game_camera .use () # use the in-game camera to draw in-game objects
161163 self .sprites .draw ()
162164 self .coins .draw ()
163165
@@ -212,7 +214,7 @@ def on_update(self, delta_time: float) -> Optional[bool]:
212214 self .player .top -= self ._player_speed
213215
214216 # move the camera with the player
215- self .ingame_camera .position = self .player .position
217+ self .in_game_camera .position = self .player .position
216218
217219 # collect coins
218220 collisions = self .player .collides_with_list (self .coins )
@@ -246,9 +248,6 @@ def on_key_press(self, symbol: int, modifiers: int) -> Optional[bool]:
246248 arcade .close_window ()
247249 if symbol == arcade .key .ENTER :
248250 self .window .show_view (MyCoinGame ())
249- if symbol == arcade .key .SPACE :
250- # Allows user to rotate camera to show off full functionality of the ui camera
251- self .ui .camera .angle += 5
252251
253252 return False
254253
@@ -259,7 +258,7 @@ def on_key_release(self, symbol: int, modifiers: int) -> Optional[bool]:
259258
260259
261260if __name__ == "__main__" :
262- window = arcade .Window (1280 , 720 , "CoinGame Example" , resizable = True )
261+ window = arcade .Window (1280 , 720 , "CoinGame Example" , resizable = False )
263262 window .background_color = arcade .color .DARK_BLUE_GRAY
264263 window .show_view (MyCoinGame ())
265264 window .run ()
0 commit comments