gamestatek

This commit is contained in:
markojozsef
2026-09-09 12:53:15 +02:00
commit e2890340d2
12 changed files with 112 additions and 0 deletions

12
src/assets.py Normal file
View File

@@ -0,0 +1,12 @@
import pygame
sprites = {
"louisu": pygame.image.load("res/sprite/louisu.png"),
"louisd": pygame.image.load("res/sprite/louisd.png"),
"louisl": pygame.image.load("res/sprite/louisl.png"),
"louisb": pygame.image.load("res/sprite/louisb.png"),
}
def convert():
for name, image in sprites.items():
sprites[name] = image.convert_alpha()

19
src/gamestate.py Normal file
View File

@@ -0,0 +1,19 @@
import gamestates.none
import gamestates.title
gamestates = {
"none": gamestates.none,
"title": gamestates.title
}
gamestate = "none"
def switch_gamestate(state):
global gamestate
gamestate = state
gamestates[gamestate].switch()
def update(dt):
gamestates[gamestate].update(dt)
def draw(screen):
gamestates[gamestate].draw(screen)

11
src/gamestates/none.py Normal file
View File

@@ -0,0 +1,11 @@
import gamestate
def switch():
pass
def update(dt):
gamestate.switch_gamestate("title")
def draw(screen):
pass

12
src/gamestates/title.py Normal file
View File

@@ -0,0 +1,12 @@
import assets
def switch():
print("Hello I'm switched")
def update(dt):
pass
def draw(screen):
screen.fill("blue")
screen.blit(assets.sprites["louisu"], (0, 0))

53
src/main.py Normal file
View File

@@ -0,0 +1,53 @@
import pygame
import assets
import gamestate
pygame.init()
GAME_WIDTH = 256
GAME_HEIGHT = 224
screen = pygame.display.set_mode((GAME_WIDTH, GAME_HEIGHT), pygame.RESIZABLE)
pygame.display.set_caption("Rick Roll To The Moon")
clock = pygame.time.Clock()
running = True
dt = 0
game_screen = pygame.Surface((GAME_WIDTH, GAME_HEIGHT))
assets.convert()
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
gamestate.update(dt)
gamestate.draw(game_screen)
screen.fill((0, 0, 0))
scale = min(
screen.get_width() // GAME_WIDTH,
screen.get_height() // GAME_HEIGHT
)
scale = max(1, scale)
scaled_width = GAME_WIDTH * scale
scaled_height = GAME_HEIGHT * scale
x = (screen.get_width() - scaled_width) // 2
y = (screen.get_height() - scaled_height) // 2
scaled_surface = pygame.transform.scale(
game_screen,
(scaled_width, scaled_height)
)
screen.blit(scaled_surface, (x, y))
pygame.display.flip()
dt = clock.tick(60) / 1000
pygame.quit()