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 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) minimap.material.set_shader_param('enable_tile_globbing', true) # 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 = 192 minimap.rect_scale = Vector2.ONE * 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 / 4 self.minimap_tween = clamp(minimap_tween, 0, 1) var l = ease(minimap_tween, -3.75) l = minimap_tween var minimap_scale = lerp(0.125, 0.5, l) minimap.rect_scale = Vector2.ONE * minimap_scale minimap.rect_position = Vector2(lerp(8, 64, l), lerp(168, -8, l)) minimap.modulate.a8 = lerp(192, 240, l) # minimap.material.set_shader_param('subtile_offset', Vector2.ONE*0/8.0) # minimap.material.set_shader_param('uv_scale', 64 * minimap_scale) minimap.material.set_shader_param('uv_scale', lerp(512, 1<<5, l)) # minimap.material.set_shader_param('uv_scale', 512/16) 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