Csata transition
This commit is contained in:
100
src/objects.py
Normal file
100
src/objects.py
Normal file
@@ -0,0 +1,100 @@
|
||||
import assets
|
||||
import arcade
|
||||
|
||||
# Main character(balthasar) renderer
|
||||
DIR_DOWN = 0
|
||||
DIR_UP = 1
|
||||
DIR_RIGHT = 2
|
||||
DIR_LEFT = 3
|
||||
|
||||
B_SPRITE_WIDHT = 16
|
||||
B_SPRITE_HEIGHT = 24
|
||||
B_SPRITE_WALKING = 3
|
||||
|
||||
|
||||
class BalthasarRenderer:
|
||||
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
|
||||
)
|
||||
|
||||
# Overworld Map
|
||||
|
||||
OVERWORLD_LB_X = 0
|
||||
OVERWORLD_LB_Y = 0
|
||||
OVERWORLD_TILE_WIDTH = 16
|
||||
OVERWORLD_TILE_HEIGHT = 16
|
||||
OVERWORLD_WIDTH = 4
|
||||
OVERWORLD_HEIGHT = 4
|
||||
OVERWORLD_MAP = [
|
||||
[5,3,3,6],
|
||||
[1,0,0,2],
|
||||
[1,0,0,2],
|
||||
[7,4,4,8],
|
||||
]
|
||||
|
||||
class OverworldMap:
|
||||
def __init__(self):
|
||||
self.sprites = []
|
||||
|
||||
self.scroll_x = 0
|
||||
self.scroll_y = 0
|
||||
|
||||
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 % 4) * OVERWORLD_TILE_WIDTH, (tile // 4) * OVERWORLD_TILE_HEIGHT,
|
||||
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(
|
||||
self.scroll_x + (game.screen_width / 2) - ((OVERWORLD_WIDTH * OVERWORLD_TILE_WIDTH) / 2),
|
||||
self.scroll_y + (game.screen_height / 2) - ((OVERWORLD_HEIGHT * OVERWORLD_TILE_HEIGHT) / 2)
|
||||
),
|
||||
pixelated=True
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user