test2.py

Created by kbenson8400

Created on December 17, 2025

1.41 KB


from kandinsky import *
from random import *
from ion import *
from time import *

SCREEN_WIDTH = 320
SCREEN_HEIGHT = 222

BG_COLOR = (141, 180, 242)
PLAYER_COLOR = (214, 56, 177)

def run_game():
    fill_rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, BG_COLOR)

    player: Player = Player(100, 100)

    while True:
        player.update()

class GameObject:
    old_x, old_y = 0, 0
    x, y = 0, 0

    WIDTH = 10
    HEIGHT = 10

    def __init__(self, x, y):
        self.x = x
        self.y = y
        self.old_x = x
        self.old_y = y

    def update(self) -> None:
       self.erase_prev_frame()
       self.step()
       self.draw()
       self.old_x = self.x
       self.old_y = self.y

    def erase_prev_frame(self) -> None:
       fill_rect(self.old_x, self.old_y, self.WIDTH, self.HEIGHT, BG_COLOR)
    
    def step(self) -> None:
       pass # Custom game logic
    
    def draw(self) -> None:
       pass # Custom draw


class Player(GameObject):
    COLOR = PLAYER_COLOR
    SPEED = 2  # pixels per frame

    def step(self):
        if keydown(KEY_LEFT):
            self.x -= self.SPEED
        if keydown(KEY_RIGHT):
            self.x += self.SPEED
        if keydown(KEY_UP):
            self.y -= self.SPEED
        if keydown(KEY_DOWN):
            self.y += self.SPEED

    def draw(self):
        fill_rect(self.x, self.y,
                    self.WIDTH, self.HEIGHT,
                    self.COLOR)

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.