gamestatek
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
src/__pycache__/*
|
||||
src/gamestates/__pycache__/*
|
||||
2
mkvenv.bat
Normal file
2
mkvenv.bat
Normal file
@@ -0,0 +1,2 @@
|
||||
python -m venv venv
|
||||
.\venv\Scripts\pip install pygame
|
||||
BIN
res/sprite/louisb.png
Normal file
BIN
res/sprite/louisb.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 244 B |
BIN
res/sprite/louisd.png
Normal file
BIN
res/sprite/louisd.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 260 B |
BIN
res/sprite/louisl.png
Normal file
BIN
res/sprite/louisl.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 240 B |
BIN
res/sprite/louisu.png
Normal file
BIN
res/sprite/louisu.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 267 B |
12
src/assets.py
Normal file
12
src/assets.py
Normal 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
19
src/gamestate.py
Normal 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
11
src/gamestates/none.py
Normal 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
12
src/gamestates/title.py
Normal 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
53
src/main.py
Normal 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()
|
||||
Reference in New Issue
Block a user