Scrollozás és normális középigazítás
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 344 B After Width: | Height: | Size: 264 B |
@@ -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(game, dt):
|
def update(game, dt):
|
||||||
gamestate.switch_gamestate(game, "title")
|
gamestate.switch_gamestate(game, "overworld")
|
||||||
|
|||||||
@@ -19,14 +19,18 @@ OVERWORLD_LB_X = 0
|
|||||||
OVERWORLD_LB_Y = 0
|
OVERWORLD_LB_Y = 0
|
||||||
OVERWORLD_TILE_WIDTH = 16
|
OVERWORLD_TILE_WIDTH = 16
|
||||||
OVERWORLD_TILE_HEIGHT = 16
|
OVERWORLD_TILE_HEIGHT = 16
|
||||||
|
OVERWORLD_WIDTH = 4
|
||||||
|
OVERWORLD_HEIGHT = 4
|
||||||
OVERWORLD_MAP = [
|
OVERWORLD_MAP = [
|
||||||
[1,0,0,0],
|
[5,3,3,6],
|
||||||
[1,0,1,0],
|
[1,0,0,2],
|
||||||
[0,1,0,0],
|
[1,0,0,2],
|
||||||
[0,0,0,0],
|
[7,4,4,8],
|
||||||
]
|
]
|
||||||
|
|
||||||
class BalthasarController:
|
WALK_SPEED = 32
|
||||||
|
|
||||||
|
class BalthasarRenderer:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.direction = DIR_UP
|
self.direction = DIR_UP
|
||||||
self.walking = False
|
self.walking = False
|
||||||
@@ -60,13 +64,19 @@ class BalthasarController:
|
|||||||
class OverworldMap:
|
class OverworldMap:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.sprites = []
|
self.sprites = []
|
||||||
|
|
||||||
|
self.scroll_x = 0
|
||||||
|
self.scroll_y = 0
|
||||||
|
|
||||||
x = 0
|
x = 0
|
||||||
y = len(OVERWORLD_MAP)
|
y = len(OVERWORLD_MAP)
|
||||||
for row in OVERWORLD_MAP:
|
for row in OVERWORLD_MAP:
|
||||||
for tile in row:
|
for tile in row:
|
||||||
self.sprites.append([
|
self.sprites.append([
|
||||||
assets.sprites["overworld"].get_texture(arcade.LBWH((tile % 16) * 16, (tile // 16) * 12, OVERWORLD_TILE_WIDTH, OVERWORLD_TILE_HEIGHT)),
|
assets.sprites["overworld"].get_texture(
|
||||||
|
arcade.LBWH((tile % 4) * OVERWORLD_TILE_WIDTH, (tile // 4) * OVERWORLD_TILE_HEIGHT,
|
||||||
|
OVERWORLD_TILE_WIDTH, OVERWORLD_TILE_HEIGHT)
|
||||||
|
),
|
||||||
arcade.LBWH(
|
arcade.LBWH(
|
||||||
(x * OVERWORLD_TILE_WIDTH),
|
(x * OVERWORLD_TILE_WIDTH),
|
||||||
(y * OVERWORLD_TILE_HEIGHT),
|
(y * OVERWORLD_TILE_HEIGHT),
|
||||||
@@ -84,45 +94,48 @@ class OverworldMap:
|
|||||||
arcade.draw_texture_rect(
|
arcade.draw_texture_rect(
|
||||||
s[0],
|
s[0],
|
||||||
s[1].move(
|
s[1].move(
|
||||||
(game.screen_width / 2),
|
self.scroll_x + (game.screen_width / 2) - ((OVERWORLD_WIDTH * OVERWORLD_TILE_WIDTH) / 2),
|
||||||
(game.screen_height / 2)
|
self.scroll_y + (game.screen_height / 2) - ((OVERWORLD_HEIGHT * OVERWORLD_TILE_HEIGHT) / 2)
|
||||||
),
|
),
|
||||||
pixelated=True
|
pixelated=True
|
||||||
)
|
)
|
||||||
|
|
||||||
controller = BalthasarController()
|
balthasar = BalthasarRenderer()
|
||||||
overworld = OverworldMap()
|
overworld = OverworldMap()
|
||||||
|
|
||||||
def switch(game):
|
def switch(game):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def update(game, dt):
|
def update(game, dt):
|
||||||
controller.update()
|
balthasar.update()
|
||||||
|
|
||||||
if controls.is_control_pressed(0): # Fel
|
if controls.is_control_pressed(0): # Fel
|
||||||
controller.set_direction(DIR_UP)
|
balthasar.set_direction(DIR_UP)
|
||||||
elif controls.is_control_pressed(1): # Le
|
elif controls.is_control_pressed(1): # Le
|
||||||
controller.set_direction(DIR_DOWN)
|
balthasar.set_direction(DIR_DOWN)
|
||||||
elif controls.is_control_pressed(2): # Bal
|
elif controls.is_control_pressed(2): # Bal
|
||||||
controller.set_direction(DIR_LEFT)
|
balthasar.set_direction(DIR_LEFT)
|
||||||
elif controls.is_control_pressed(3): # Jobb
|
elif controls.is_control_pressed(3): # Jobb
|
||||||
controller.set_direction(DIR_RIGHT)
|
balthasar.set_direction(DIR_RIGHT)
|
||||||
|
|
||||||
|
walking = False
|
||||||
|
|
||||||
if controls.is_control_held(0): # Fel
|
if controls.is_control_held(0): # Fel
|
||||||
|
overworld.scroll_y -= WALK_SPEED * dt
|
||||||
controller.set_walking(True)
|
walking = True
|
||||||
elif controls.is_control_held(1): # Le
|
elif controls.is_control_held(1): # Le
|
||||||
|
overworld.scroll_y += WALK_SPEED * dt
|
||||||
controller.set_walking(True)
|
walking = True
|
||||||
elif controls.is_control_held(2): # Bal
|
|
||||||
|
if controls.is_control_held(2): # Bal
|
||||||
controller.set_walking(True)
|
overworld.scroll_x += WALK_SPEED * dt
|
||||||
|
walking = True
|
||||||
elif controls.is_control_held(3): # Jobb
|
elif controls.is_control_held(3): # Jobb
|
||||||
|
overworld.scroll_x -= WALK_SPEED * dt
|
||||||
controller.set_walking(True)
|
walking = True
|
||||||
else:
|
|
||||||
controller.set_walking(False)
|
balthasar.set_walking(walking)
|
||||||
|
|
||||||
def draw(game):
|
def draw(game):
|
||||||
controller.render(game)
|
overworld.render(game)
|
||||||
overworld.render(game)
|
balthasar.render(game)
|
||||||
|
|||||||
Reference in New Issue
Block a user