ChocolateBird/widgets/BattleScene.gd

36 lines
1.3 KiB
GDScript3
Raw Normal View History

2023-08-15 16:20:40 +09:30
extends ReferenceRect
const battle_bg_shader = preload('res://shaders/tilemap_shader.gdshader')
2023-08-16 00:35:59 +09:30
onready var background := $background
2023-08-15 16:20:40 +09:30
var bg: SpriteLoader.BattleBackground
var pal_l: int
var atlas_l: int
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
var battle_bg_mat := ShaderMaterial.new()
battle_bg_mat.shader = battle_bg_shader
2023-08-16 00:35:59 +09:30
background.material = battle_bg_mat
2023-08-15 16:20:40 +09:30
set_bg(1)
const RANDOM_BGMS_PLAYLIST = [34, 43, 1, 9, 64]
func _on_menu_presented() -> void:
MusicManager.play_bgm('BGM%02d-1000'%RANDOM_BGMS_PLAYLIST.pick_random(), 0)
2023-08-15 16:20:40 +09:30
func set_bg(index: int) -> void:
self.bg = SpriteLoader.battle_backgrounds[index]
self.pal_l = len(self.bg.palette_texs)
self.atlas_l = len(self.bg.tile_atlas_texs)
2023-08-16 00:35:59 +09:30
background.texture = self.bg.tilemap_tex
background.material.set_shader_param('palette', self.bg.palette_texs[0])
background.material.set_shader_param('tile_atlas', self.bg.tile_atlas_texs[0])
2023-08-15 16:20:40 +09:30
# Called every frame. 'delta' is the elapsed time since the previous frame.
var t := 0.0
func _process(delta: float) -> void:
if not self.bg:
return
2023-08-16 00:35:59 +09:30
self.t = fmod(self.t + delta, 30.0)
background.material.set_shader_param('palette', self.bg.palette_texs[int(self.t * 30) % self.pal_l])
background.material.set_shader_param('tile_atlas', self.bg.tile_atlas_texs[int(self.t * 7.5) % self.atlas_l])