85 lines
2.5 KiB
Python
85 lines
2.5 KiB
Python
"""
|
|
This program shows how to:
|
|
* Display a sequence of screens in your game. The "arcade.View"
|
|
class makes it easy to separate the code for each screen into
|
|
its own class.
|
|
* This example shows the absolute basics of using "arcade.View".
|
|
See the "different_screens_example.py" for how to handle
|
|
screen-specific data.
|
|
|
|
Make a separate class for each view (screen) in your game.
|
|
The class will inherit from arcade.View. The structure will
|
|
look like an arcade.Window as each View will need to have its own draw,
|
|
update and window event methods. To switch a View, simply create a View
|
|
with `view = MyView()` and then use the "self.window.set_view(view)" method.
|
|
|
|
If Python and Arcade are installed, this example can be run from the command line with:
|
|
python -m arcade.examples.view_screens_minimal
|
|
"""
|
|
|
|
import arcade
|
|
import os
|
|
|
|
|
|
file_path = os.path.dirname(os.path.abspath(__file__))
|
|
os.chdir(file_path)
|
|
|
|
|
|
WIDTH = 800
|
|
HEIGHT = 600
|
|
|
|
|
|
class MenuView(arcade.View):
|
|
def on_show(self):
|
|
arcade.set_background_color(arcade.color.WHITE)
|
|
|
|
def on_draw(self):
|
|
arcade.start_render()
|
|
arcade.draw_text("Menu Screen - click to advance", WIDTH/2, HEIGHT/2,
|
|
arcade.color.BLACK, font_size=30, anchor_x="center")
|
|
|
|
def on_mouse_press(self, x, y, button, modifiers):
|
|
game_view = GameView()
|
|
self.window.show_view(game_view)
|
|
|
|
|
|
class GameView(arcade.View):
|
|
def on_show(self):
|
|
arcade.set_background_color(arcade.color.ORANGE_PEEL)
|
|
|
|
def on_draw(self):
|
|
arcade.start_render()
|
|
arcade.draw_text("Game - press SPACE to advance", WIDTH/2, HEIGHT/2,
|
|
arcade.color.BLACK, font_size=30, anchor_x="center")
|
|
|
|
def on_key_press(self, key, modifiers):
|
|
if key == arcade.key.SPACE:
|
|
game_over_view = GameOverView()
|
|
self.window.show_view(game_over_view)
|
|
|
|
|
|
class GameOverView(arcade.View):
|
|
def on_show(self):
|
|
arcade.set_background_color(arcade.color.BLACK)
|
|
|
|
def on_draw(self):
|
|
arcade.start_render()
|
|
arcade.draw_text("Game Over - press ESCAPE to advance", WIDTH/2, HEIGHT/2,
|
|
arcade.color.WHITE, 30, anchor_x="center")
|
|
|
|
def on_key_press(self, key, modifiers):
|
|
if key == arcade.key.ESCAPE:
|
|
menu_view = MenuView()
|
|
self.window.show_view(menu_view)
|
|
|
|
|
|
def main():
|
|
window = arcade.Window(WIDTH, HEIGHT, "Different Views Minimal Example")
|
|
menu_view = MenuView()
|
|
window.show_view(menu_view)
|
|
arcade.run()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|