Overworld rajzolás és "Main Character" kontroller

This commit is contained in:
markojozsef
2026-09-23 12:58:15 +02:00
parent d97b5b9fb7
commit 8e060ce43f
7 changed files with 139 additions and 5 deletions

BIN
res/sprite/balthasar.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 496 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 344 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 344 B

View File

@@ -1,7 +1,9 @@
import arcade import arcade
sprites = { sprites = {
"cursor": arcade.load_texture("res/sprite/handcursor.png"), "cursor" : arcade.load_texture("res/sprite/handcursor.png"),
"font": arcade.load_spritesheet("res/sprite/font.png"), "font" : arcade.load_spritesheet("res/sprite/font.png"),
"panel": arcade.load_spritesheet("res/sprite/panel.png"), "panel" : arcade.load_spritesheet("res/sprite/panel.png"),
"balthasar": arcade.load_spritesheet("res/sprite/balthasar.png"),
"overworld": arcade.load_spritesheet("res/sprite/overworld_sheet.png"),
} }

View File

@@ -1,9 +1,11 @@
import gamestates.none import gamestates.none
import gamestates.title import gamestates.title
import gamestates.overworld
gamestates = { gamestates = {
"none": gamestates.none, "none": gamestates.none,
"title": gamestates.title "title": gamestates.title,
"overworld": gamestates.overworld
} }
gamestate = "none" gamestate = "none"

View File

@@ -2,4 +2,4 @@ import gamestate
# Azért létezik ez a "none" gamestate hogy meghívja az elsö gamestate init() funkcióját # Azért létezik ez a "none" gamestate hogy meghívja az elsö gamestate init() funkcióját
def update(dt): def update(dt):
gamestate.switch_gamestate("title") gamestate.switch_gamestate("overworld")

130
src/gamestates/overworld.py Normal file
View File

@@ -0,0 +1,130 @@
import arcade
import assets
import controls
import menu
import text
import renderers
import math
DIR_DOWN = 0
DIR_UP = 1
DIR_RIGHT = 2
DIR_LEFT = 3
B_SPRITE_WIDHT = 16
B_SPRITE_HEIGHT = 24
B_SPRITE_WALKING = 3
OVERWORLD_LB_X = 0
OVERWORLD_LB_Y = 0
OVERWORLD_TILE_WIDTH = 16
OVERWORLD_TILE_HEIGHT = 16
OVERWORLD_MAP = [
[1,0,0,0],
[1,0,1,0],
[0,1,0,0],
[0,0,0,0],
]
class BalthasarController:
def __init__(self):
self.direction = DIR_UP
self.walking = False
self.anim_timer = 0
def set_direction(self, direction):
self.direction = direction
def set_walking(self, walking):
self.walking = walking
if walking == False:
self.anim_timer = 0
def update(self):
self.anim_timer += 1
if self.anim_timer > 30:
self.anim_timer = 0
def render(self, game):
sprite_h = self.direction if self.direction < 3 else 2
sprite_v = 1 if (self.walking and self.anim_timer <= 15) else 0
flip_h = self.direction == DIR_LEFT
sprite = assets.sprites["balthasar"].get_texture(arcade.LBWH(B_SPRITE_WIDHT*sprite_h, B_SPRITE_HEIGHT*sprite_v, B_SPRITE_WIDHT, B_SPRITE_HEIGHT))
arcade.draw_texture_rect(
sprite.flip_horizontally() if flip_h else sprite,
arcade.LBWH((game.screen_width / 2) - (B_SPRITE_WIDHT / 2), (game.screen_height / 2) - (B_SPRITE_HEIGHT / 2), B_SPRITE_WIDHT, B_SPRITE_HEIGHT),
pixelated=True
)
class OverworldMap:
def __init__(self):
self.sprites = []
x = 0
y = len(OVERWORLD_MAP)
for row in OVERWORLD_MAP:
for tile in row:
self.sprites.append([
assets.sprites["overworld"].get_texture(arcade.LBWH((tile % 16) * 16, (tile // 16) * 12, OVERWORLD_TILE_WIDTH, OVERWORLD_TILE_HEIGHT)),
arcade.LBWH(
(x * OVERWORLD_TILE_WIDTH),
(y * OVERWORLD_TILE_HEIGHT),
OVERWORLD_TILE_WIDTH,
OVERWORLD_TILE_HEIGHT
)
])
x += 1
y -= 1
x = 0
def render(self, game):
for s in self.sprites:
arcade.draw_texture_rect(
s[0],
s[1].move(
(game.screen_width / 2),
(game.screen_height / 2)
),
pixelated=True
)
controller = BalthasarController()
overworld = OverworldMap()
def switch():
pass
def update(dt):
controller.update()
if controls.is_control_pressed(0): # Fel
controller.set_direction(DIR_UP)
elif controls.is_control_pressed(1): # Le
controller.set_direction(DIR_DOWN)
elif controls.is_control_pressed(2): # Bal
controller.set_direction(DIR_LEFT)
elif controls.is_control_pressed(3): # Jobb
controller.set_direction(DIR_RIGHT)
if controls.is_control_held(0): # Fel
controller.set_walking(True)
elif controls.is_control_held(1): # Le
controller.set_walking(True)
elif controls.is_control_held(2): # Bal
controller.set_walking(True)
elif controls.is_control_held(3): # Jobb
controller.set_walking(True)
else:
controller.set_walking(False)
def draw(game):
controller.render(game)
overworld.render(game)