Skip to content

Initializing, updating & drawing

Nick Jordan edited this page Oct 20, 2023 · 2 revisions

Page contents

  1. Init, Update and Draw
  2. Setting up the screen
  3. Loading assets
  4. Using assets
  5. Initializing & using UI components

Init, Update and Draw

The three core functions for your game are setup, update, and draw. Here's a basic template:

from slitherzenith import *


def setup() -> None:
    pass


def update() -> None:
    pass


def draw() -> None:
    pass

Setting up the screen

Modify screen properties using helper methods in the setup function:

def setup() -> None:
    screen(800, 600)
    title("My wonderful game")
    backdrop((50, 50, 255))

Loading assets

Load assets from using provided functions:

heart_image = load_image("sprites/symbols/heart.png")
point_sound = load_sound("audio/point.wav")

Using assets

Incorporate assets into your game's logic and rendering:

def update() -> None:
    point_sound.play()


def draw() -> None:
    image(heart_image,
          get_screen_width() / 2,
          get_screen_height() / 2,
          10)

Initializing & using UI components

Initialize UI components in the Init method. Update and draw them in the Update and Draw methods, respectively:

from slitherzenith import *
from Components.UI.button import Button

button = Button((get_screen_width() / 2, get_screen_height() / 2),
                100,
                50,
                "Hello",
                20,
                (255, 255, 255),
                (1, 1, 1),
                (100, 100, 100),
                True,
                5,
                (255, 255, 255))


def setup() -> None:
    screen(800, 600)
    title("My wonderful game")
    backdrop((50, 50, 255))


def update() -> None:
    button.update()
    if button.clicked():
        print("Clicked!")


def draw() -> None:
    button.draw()
Clone this wiki locally