extends Control var pal_shader_mat := preload('res://palette_mat.tres') var worldmap_shader_mat := preload('res://worldmap_palette_mat.tres') onready var minimap := $tr_minimap var current_map_id := 0 var map_images := [] var map_textures := [] var current_texture: Texture var minimap_mode := 0 var minimap_tween := 0.0 #func _create_palette_and_atlas_texrects() -> void: # for tileset in 3: # # Debug the Atlases # var texrect = TextureRect.new() # texrect.rect_position.x = tileset * 256 * 2 # texrect.rect_scale *= 16 # texrect.texture = SpriteLoader.worldmap_palette_textures[tileset] # map_texrects.append(texrect) # add_child(texrect) # texrect = TextureRect.new() # texrect.rect_position.x = tileset * 256 * 2 # texrect.rect_position.y = 256 # texrect.rect_scale *= 4 # texrect.texture = SpriteLoader.worldmap_tile_atlas_textures[tileset] # texrect.material = pal_shader_mat.duplicate() # texrect.material.set_shader_param('palette', SpriteLoader.worldmap_palette_textures[tileset]) # map_texrects.append(texrect) # add_child(texrect) # texrect = TextureRect.new() # texrect.rect_position.x = tileset * 256 * 2 # texrect.rect_position.y = 768 # texrect.rect_scale *= 4 # texrect.texture = SpriteLoader.worldmap_tile_atlas_textures[tileset] # map_texrects.append(texrect) # add_child(texrect) const map_tilesets = [0, 1, 0, 2, 2] const waterfall_scrolls = [true, false, true, false, false] const sea_scrolls = [true, true, true, false, false] func _create_worldmap_textures() -> void: for i in 5: var tileset = map_tilesets[i] var image = MapLoader.worldmaps[i].make_tile_map() self.map_images.append(image) var tex := SpriteLoader.texture_from_image(image, Texture.FLAG_REPEAT) self.map_textures.append(tex) func _set_map(id: int) -> void: if id < 0 or id >= len(map_images): print_debug('Invalid map ID %d' % id) return self.current_map_id = id var tileset = map_tilesets[id] self.current_texture = self.map_textures[self.current_map_id] self.material.set_shader_param('palette', SpriteLoader.worldmap_palette_textures[tileset]) self.material.set_shader_param('tile_atlas', SpriteLoader.worldmap_tile_atlas_textures[tileset]) self.material.set_shader_param('enable_waterfall_scroll', waterfall_scrolls[id]) self.material.set_shader_param('enable_sea_scroll', sea_scrolls[id]) minimap.texture = self.current_texture minimap.material.set_shader_param('palette', SpriteLoader.worldmap_palette_textures[tileset]) minimap.material.set_shader_param('tile_atlas', SpriteLoader.worldmap_tile_atlas_textures[tileset]) minimap.material.set_shader_param('enable_waterfall_scroll', false) minimap.material.set_shader_param('enable_sea_scroll', false) # Called when the node enters the scene tree for the first time. func _ready() -> void: # Only create this after MapLoader and SpriteLoader have loaded! _create_worldmap_textures() # _create_palette_and_atlas_texrects() self.material = worldmap_shader_mat.duplicate() minimap.material = worldmap_shader_mat.duplicate() minimap.modulate.a8 = 0xc0 minimap.rect_scale = Vector2(0.125, 0.125) minimap.rect_position = Vector2(8, 168) _set_map(0) # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta: float) -> void: self.pos = self.pos.posmod(256.0) self.minimap_tween -= sign(minimap_tween - minimap_mode) * delta #* 0.06125 self.minimap_tween = clamp(minimap_tween, 0, 1) var l = ease(minimap_tween, -3.75) # l = minimap_tween minimap.rect_scale = Vector2.ONE * lerp(0.125, 0.5, l) minimap.rect_position = Vector2(lerp(8, 64, l), lerp(168, -8, l)) minimap.modulate.a8 = lerp(192, 240, l) update() var pos := Vector2(0, 0) const VW := 48 const VH := 30 const UV_W2 := VW/1024.0 const UV_H2 := VH/1024.0 const V_POINTS := PoolVector2Array([Vector2(0, 0), Vector2(384, 0), Vector2(384, 240), Vector2(0, 240)]) const V_COLORS := PoolColorArray() func _draw() -> void: var uvpos := pos/256.0 var v_uvs := PoolVector2Array([uvpos+Vector2(-UV_W2, -UV_H2), uvpos+Vector2(UV_W2, -UV_H2), uvpos+Vector2(UV_W2, UV_H2), uvpos+Vector2(-UV_W2, UV_H2)]) draw_primitive(V_POINTS, V_COLORS, v_uvs, self.current_texture) #draw_texture_rect_region(self.map_textures[0], Rect2(0, 0, 384, 240), Rect2(pos.x, pos.y, pos.x+VW, pos.y+VH), Color.white, false, null, false) func _input(event: InputEvent) -> void: if event is InputEventKey: if event.pressed: match event.physical_scancode: KEY_RIGHT: pos.x += 1 KEY_LEFT: pos.x -= 1 KEY_DOWN: pos.y += 1 KEY_UP: pos.y -= 1 KEY_1: _set_map(0) KEY_2: _set_map(1) KEY_3: _set_map(2) KEY_4: _set_map(3) KEY_5: _set_map(4) KEY_0: self.minimap_mode = 1 - minimap_mode