Arcade

Installation

https://informatik.mygymer.ch/python/?page=imperative.1-3-thonny-packages

Dokumentation

http://arcade.academy/quick_index.html

Vorlage


"""
Name
Datum
Beschreibung
"""

import arcade

# Set up the constants
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600

class Ball:
    """ Class to represent a rectangle on the screen """

    def __init__(self, x, y, radius, color):
        """ Initialize our rectangle variables """

        # Position
        self.x = x
        self.y = y

        # Speed
        self.vx = 40
        self.vy = 10

        # Vector
        self.delta_x = 0
        self.delta_y = 0

        # Size and color
        self.radius = radius 
        self.color = color

    def draw(self):
        """ Draw our Ball """
        arcade.draw_circle_outline(self.x, self.y, self.radius, self.color, 5)

    def move(self, dt):
        """ Move our rectangle """
        self.x = self.x + self.vx * dt
        self.y = self.y + self.vy * dt

class MyApplication(arcade.Window):
    """
    Main application class.
    """
    def __init__(self, width, height):
        super().__init__(width, height, title="Keyboard control")
        self.player1 = None
        self.player2 = None

    def setup(self):
        """ Set up the game and initialize the variables. """
        self.player1 = Ball(0, 200, 10, arcade.color.YELLOW)
        self.player2 = Ball(0, 300, 20, arcade.color.RED)

    def update(self, dt):
        """ Move everything """
        self.player1.move(dt)
        self.player2.move(dt)

    def on_draw(self):
        """
        Render the screen.
        """
        arcade.start_render()

        arcade.draw_rectangle_filled(SCREEN_WIDTH/2, 50, SCREEN_WIDTH, 100, arcade.color.DARK_OLIVE_GREEN)
        arcade.draw_rectangle_filled(300, 120, 100, 200, arcade.color.GRAY)

        self.player1.draw()
        self.player2.draw()

def main():
    window = MyApplication(SCREEN_WIDTH, SCREEN_HEIGHT)
    window.setup()
    arcade.run()

if __name__ == "__main__":
    main()