This repository has been archived on 2020-09-30. You can view files and clone it, but cannot push or open issues or pull requests.
odyssey-old/Scenes/Map.gd

46 lines
1.1 KiB
GDScript3
Raw Normal View History

2020-07-07 08:38:32 +00:00
tool
2020-07-06 12:38:05 +00:00
extends Node2D
class_name Map
2020-07-06 22:00:39 +00:00
var ship_direction = 0
2020-07-06 17:23:42 +00:00
var ship_speed = 1000
2020-07-06 22:00:39 +00:00
var current_ship_direction = 0
var current_ship_speed = 0
const SPEED_EASE = 0.5
const DIRECTION_EASE = 0.5
const EPSILON = 0.01
2020-07-06 12:38:05 +00:00
export(NodePath) var tilemap_path
onready var tilemap = get_node(tilemap_path) as MapTiles
2020-07-06 17:23:42 +00:00
2020-07-07 08:38:32 +00:00
export var unlit = false setget set_unlit
onready var darkness = $darkness
func _ready():
set_unlit(false)
if not Engine.editor_hint:
$editorDarkness.queue_free()
func set_unlit(val):
unlit = val
if darkness:
darkness.visible = not val
2020-07-06 17:23:42 +00:00
func _process(delta):
2020-07-07 08:38:32 +00:00
if Engine.editor_hint:
return
2020-07-06 22:00:39 +00:00
if abs(ship_direction - current_ship_direction) < EPSILON:
current_ship_direction = ship_direction
else:
current_ship_direction = lerp(current_ship_direction, ship_direction, delta * DIRECTION_EASE)
if abs(ship_speed - current_ship_speed) < EPSILON:
current_ship_speed = ship_speed
else:
current_ship_speed = lerp(current_ship_speed, ship_speed, delta * SPEED_EASE)
$deepspace.rotation = current_ship_direction-PI/2
$deepspace.region_rect.position += Vector2(sin(current_ship_direction), cos(current_ship_direction)) * current_ship_speed * delta