04_views.py差异#
04_views.py#
--- /pb1/repo/arcade/doc/tutorials/views/03_views.py
+++ /pb1/repo/arcade/doc/tutorials/views/04_views.py
@@ -37,6 +37,31 @@
self.window.show_view(game_view)
+class GameOverView(arcade.View):
+ """ View to show when game is over """
+
+ def __init__(self):
+ """ This is run once when we switch to this view """
+ super().__init__()
+ self.texture = arcade.load_texture("game_over.png")
+
+ # Reset the viewport, necessary if we have a scrolling game and we need
+ # to reset the viewport back to the start so we can see what we draw.
+ self.window.default_camera.use()
+
+ def on_draw(self):
+ """ Draw this view """
+ self.clear()
+ self.texture.draw_sized(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2,
+ SCREEN_WIDTH, SCREEN_HEIGHT)
+
+ def on_mouse_press(self, _x, _y, _button, _modifiers):
+ """ If the user presses the mouse button, re-start the game. """
+ game_view = GameView()
+ game_view.setup()
+ self.window.show_view(game_view)
+
+
class GameView(arcade.View):
""" Our custom Window Class"""
@@ -56,7 +81,7 @@
# Don't show the mouse cursor
self.window.set_mouse_visible(False)
- self.window.background_color = arcade.color.AMAZON
+ self.background_color = arcade.color.AMAZON
def setup(self):
""" Set up the game and initialize the variables. """
@@ -123,6 +148,12 @@
coin.remove_from_sprite_lists()
self.score += 1
+ # Check length of coin list. If it is zero, flip to the
+ # game over view.
+ if len(self.coin_list) == 0:
+ view = GameOverView()
+ self.window.show_view(view)
+
def main():
""" Main function """