Add dynamic map loading and spawnpoints

This commit is contained in:
Hamcha 2020-07-10 10:45:57 +02:00
parent 4b4288c0eb
commit 95bdff8c37
Signed by: hamcha
GPG Key ID: 477AFB9A47CD4B7F
12 changed files with 92 additions and 66 deletions

View File

@ -0,0 +1,12 @@
tool
extends Node2D
class_name SpawnpointPlayer
var poitype = POIData.POIType.SpawnPoint
var poiclass = POIData.POIClass.Player
func _draw():
if Engine.editor_hint:
draw_arc(Vector2.ZERO, 10, 0, PI*2, 16, Color.red)

View File

@ -55,7 +55,7 @@ func _input_event(_viewport, event, _shape_idx):
if activationRange.in_range():
set_lit(!lit)
func _power_status_changed(powered: bool) -> void:
func _power_status_changed(_powered: bool) -> void:
update_light()
refresh_sprite()

View File

@ -11,7 +11,7 @@ var grip = 1.0
var stamina = MAX_STAMINA
var speed_boost = 0
onready var world = $"/root/scene/world" as GameWorld
onready var world = $"/root/scene/world"
export var is_controlled = false setget set_is_controlled

1
Actors/Player/Player.tscn Executable file → Normal file
View File

@ -8,6 +8,7 @@ radius = 10.4436
height = 5.44386
[node name="Player" type="KinematicBody2D"]
z_index = 10
script = ExtResource( 2 )
[node name="Camera" type="Camera2D" parent="."]

9
Classes/POI.gd Normal file
View File

@ -0,0 +1,9 @@
class_name POIData
enum POIType {
SpawnPoint
}
enum POIClass {
Player
}

View File

@ -3,14 +3,12 @@ extends Node
class_name GameInstance
onready var ui = $CanvasLayer/ui
onready var world = $world as GameWorld
onready var world = $world
onready var systems = $systems
func _ready():
randomize()
ui.connect("command", world, "process_command")
$world/runtime.queue_free()
func process_command(cmd: UICommand):
match cmd.cmd_type:

View File

@ -1,11 +1,8 @@
[gd_scene load_steps=7 format=2]
[gd_scene load_steps=4 format=2]
[ext_resource path="res://Scenes/Maps/odyssey.tscn" type="PackedScene" id=1]
[ext_resource path="res://Actors/Player/Player.tscn" type="PackedScene" id=2]
[ext_resource path="res://Scenes/UI.tscn" type="PackedScene" id=3]
[ext_resource path="res://Scenes/World.gd" type="Script" id=4]
[ext_resource path="res://Scenes/Game.gd" type="Script" id=5]
[ext_resource path="res://Scenes/Maps/runtime.tscn" type="PackedScene" id=7]
[node name="scene" type="Node"]
script = ExtResource( 5 )
@ -13,18 +10,7 @@ script = ExtResource( 5 )
[node name="world" type="Node2D" parent="."]
scale = Vector2( 2, 2 )
script = ExtResource( 4 )
player_path = NodePath("player")
map_path = NodePath("odyssey")
[node name="runtime" parent="world" instance=ExtResource( 7 )]
visible = false
[node name="odyssey" parent="world" instance=ExtResource( 1 )]
[node name="player" parent="world" instance=ExtResource( 2 )]
position = Vector2( 206.017, 250.966 )
z_index = 10
is_controlled = true
mapToLoad = 1
[node name="CanvasLayer" type="CanvasLayer" parent="."]

View File

@ -17,6 +17,8 @@ const ProbeElectricity = preload("res://Actors/Systems/Electricity/ElectricProbe
onready var tilemaps = [ $base, $cables, $floor, $walls ]
onready var pois = $pois
export var unlit = false setget set_unlit
onready var darkness = $darkness
@ -73,3 +75,13 @@ func make_electric_probes(tilemap: TileMap, tile_name: String):
var probe = ProbeElectricity.instance()
probe.position = coord
tilemap.add_child(probe)
func get_pois(type_filter, class_filter) -> Array:
var filtered = []
for child in $pois.get_children():
if type_filter != null and child.poitype != type_filter:
continue
if class_filter != null and child.poiclass != class_filter:
continue
filtered.append(child)
return filtered

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=16 format=2]
[gd_scene load_steps=17 format=2]
[ext_resource path="res://Graphics/tgstation/walls.tres" type="TileSet" id=1]
[ext_resource path="res://Graphics/tgstation/1x1.tres" type="TileSet" id=2]
@ -14,6 +14,7 @@
[ext_resource path="res://Actors/Objects/PowerStorage/PowerStorage.tscn" type="PackedScene" id=12]
[ext_resource path="res://Graphics/tgstation/cables.tres" type="TileSet" id=13]
[ext_resource path="res://Actors/Objects/ElectricSocket/ElectricSocket.tscn" type="PackedScene" id=14]
[ext_resource path="res://Actors/Meta/POI/Spawnpoints/Player.gd" type="Script" id=15]
[sub_resource type="CanvasItemMaterial" id=1]
light_mode = 1
@ -455,115 +456,91 @@ __meta__ = {
[node name="Lighttube" parent="lights" instance=ExtResource( 8 )]
position = Vector2( 80, 144 )
direction = 3
lit = true
[node name="Lighttube2" parent="lights" instance=ExtResource( 8 )]
position = Vector2( 336, 144 )
direction = 3
lit = true
[node name="Lighttube3" parent="lights" instance=ExtResource( 8 )]
position = Vector2( 336, 368 )
direction = 2
lit = true
[node name="Lighttube4" parent="lights" instance=ExtResource( 8 )]
position = Vector2( 80, 368 )
direction = 2
lit = true
[node name="Lighttube7" parent="lights" instance=ExtResource( 8 )]
position = Vector2( -112, 144 )
direction = 3
lit = true
[node name="Lighttube8" parent="lights" instance=ExtResource( 8 )]
position = Vector2( -112, 368 )
direction = 2
lit = true
[node name="Lighttube5" parent="lights" instance=ExtResource( 8 )]
position = Vector2( 528, 368 )
direction = 2
lit = true
[node name="Lighttube6" parent="lights" instance=ExtResource( 8 )]
position = Vector2( 528, 144 )
direction = 3
lit = true
[node name="Lighttube9" parent="lights" instance=ExtResource( 8 )]
position = Vector2( 80, -48 )
direction = 2
lit = true
[node name="Lighttube10" parent="lights" instance=ExtResource( 8 )]
position = Vector2( 272, -48 )
direction = 2
lit = true
[node name="Lighttube11" parent="lights" instance=ExtResource( 8 )]
position = Vector2( 272, -208 )
direction = 3
lit = true
[node name="Lighttube12" parent="lights" instance=ExtResource( 8 )]
position = Vector2( -16, -208 )
direction = 0
lit = true
[node name="Lighttube13" parent="lights" instance=ExtResource( 8 )]
position = Vector2( -240, -208 )
direction = 3
lit = true
[node name="Lighttube14" parent="lights" instance=ExtResource( 8 )]
position = Vector2( -240, -48 )
direction = 2
lit = true
[node name="Lighttube15" parent="lights" instance=ExtResource( 8 )]
position = Vector2( 208, 112 )
direction = 0
lit = true
[node name="Lighttube16" parent="lights" instance=ExtResource( 8 )]
position = Vector2( 208, -16 )
direction = 1
lit = true
[node name="Lighttube17" parent="lights" instance=ExtResource( 8 )]
position = Vector2( 208, 400 )
direction = 1
lit = true
[node name="Lighttube18" parent="lights" instance=ExtResource( 8 )]
position = Vector2( 208, 528 )
direction = 0
lit = true
[node name="Lighttube19" parent="lights" instance=ExtResource( 8 )]
position = Vector2( 48, 560 )
direction = 3
lit = true
[node name="Lighttube21" parent="lights" instance=ExtResource( 8 )]
position = Vector2( -240, 560 )
direction = 3
lit = true
[node name="Lighttube23" parent="lights" instance=ExtResource( 8 )]
position = Vector2( -240, 720 )
direction = 2
lit = true
[node name="Lighttube20" parent="lights" instance=ExtResource( 8 )]
position = Vector2( 272, 720 )
direction = 2
lit = true
[node name="Lighttube22" parent="lights" instance=ExtResource( 8 )]
position = Vector2( 80, 720 )
direction = 2
lit = true
[node name="pois" type="Node2D" parent="."]
z_index = 999
[node name="SpawnpointPlayer" type="Node2D" parent="pois"]
position = Vector2( 208, 256 )
script = ExtResource( 15 )

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=14 format=2]
[gd_scene load_steps=15 format=2]
[ext_resource path="res://Graphics/tgstation/walls.tres" type="TileSet" id=1]
[ext_resource path="res://Graphics/tgstation/1x1.tres" type="TileSet" id=2]
@ -7,6 +7,7 @@
[ext_resource path="res://Scenes/Maps/runtime.gd" type="Script" id=5]
[ext_resource path="res://Actors/Objects/Computer/Computer.tscn" type="PackedScene" id=6]
[ext_resource path="res://Graphics/space.png" type="Texture" id=7]
[ext_resource path="res://Actors/Meta/POI/Spawnpoints/Player.gd" type="Script" id=8]
[ext_resource path="res://Graphics/tgstation/floor.tres" type="TileSet" id=9]
[ext_resource path="res://Actors/Objects/Engine/Engine.tscn" type="PackedScene" id=10]
[ext_resource path="res://Graphics/tgstation/base.tres" type="TileSet" id=11]
@ -135,49 +136,41 @@ computer_type = 6
[node name="ElectricSocket4" parent="objects" instance=ExtResource( 13 )]
position = Vector2( -128, 160 )
z_index = -8
connectionPaths = [ NodePath("../Computer6") ]
flow = 1
[node name="ElectricSocket5" parent="objects" instance=ExtResource( 13 )]
position = Vector2( -96, 160 )
z_index = -8
connectionPaths = [ NodePath("../Computer5") ]
flow = 1
[node name="ElectricSocket6" parent="objects" instance=ExtResource( 13 )]
position = Vector2( -64, 160 )
z_index = -8
connectionPaths = [ NodePath("../Computer") ]
flow = 1
[node name="ElectricSocket7" parent="objects" instance=ExtResource( 13 )]
position = Vector2( -32, 160 )
z_index = -8
connectionPaths = [ NodePath("../Computer2") ]
flow = 1
[node name="ElectricSocket8" parent="objects" instance=ExtResource( 13 )]
position = Vector2( 0, 160 )
z_index = -8
connectionPaths = [ NodePath("../Computer3") ]
flow = 1
[node name="ElectricSocket9" parent="objects" instance=ExtResource( 13 )]
position = Vector2( 32, 160 )
z_index = -8
connectionPaths = [ NodePath("../Computer4") ]
flow = 1
[node name="ElectricSocket10" parent="objects" instance=ExtResource( 13 )]
position = Vector2( 64, 160 )
z_index = -8
connectionPaths = [ NodePath("../Computer7") ]
flow = 1
[node name="ElectricSocket3" parent="objects" instance=ExtResource( 13 )]
position = Vector2( 128, 160 )
z_index = -8
connectionPaths = [ NodePath("../SMES2") ]
[node name="lights" type="Node2D" parent="."]
@ -186,3 +179,10 @@ __meta__ = {
"_edit_group_": true,
"_edit_lock_": true
}
[node name="pois" type="Node2D" parent="."]
z_index = 999
[node name="SpawnpointPlayer" type="Node2D" parent="pois"]
position = Vector2( 112, 272 )
script = ExtResource( 8 )

View File

@ -2,13 +2,32 @@ extends Node2D
class_name GameWorld
export(NodePath) var player_path
export(NodePath) var map_path
enum Map { RUNTIME, ODYSSEY }
onready var player = get_node(player_path) as Node2D
onready var map = get_node(map_path) as GameMap
export(Map) var mapToLoad = Map.RUNTIME
const runtimeRes = preload("res://Scenes/Maps/runtime.tscn")
const odysseyRes = preload("res://Scenes/Maps/odyssey.tscn")
const playerRes = preload("res://Actors/Player/Player.tscn")
var map = null
var player = null
func _ready():
match mapToLoad:
Map.RUNTIME:
map = runtimeRes.instance()
Map.ODYSSEY:
map = odysseyRes.instance()
add_child(map)
for tilemap in map.tilemaps:
if tilemap is MapTiles:
tilemap.set_occluder_origin(player)
player = playerRes.instance()
player.is_controlled = true
var spawnpoints = map.get_pois(POIData.POIType.SpawnPoint, POIData.POIClass.Player)
if spawnpoints.size() > 0:
player.transform.origin = (spawnpoints[0] as Node2D).transform.origin
else:
print("Map does not have Player spawnpoint POI! Spawning at origin (very bad)")
add_child(player)

View File

@ -74,6 +74,11 @@ _global_script_classes=[ {
"language": "GDScript",
"path": "res://Scenes/Rendering/Occluder.gd"
}, {
"base": "Reference",
"class": "POIData",
"language": "GDScript",
"path": "res://Classes/POI.gd"
}, {
"base": "Node",
"class": "PowerManager",
"language": "GDScript",
@ -89,6 +94,11 @@ _global_script_classes=[ {
"language": "GDScript",
"path": "res://Actors/Systems/Electricity/ElectricProbe.gd"
}, {
"base": "Node2D",
"class": "SpawnpointPlayer",
"language": "GDScript",
"path": "res://Actors/Meta/POI/Spawnpoints/Player.gd"
}, {
"base": "Reference",
"class": "UICommand",
"language": "GDScript",
@ -108,9 +118,11 @@ _global_script_class_icons={
"GameWorld": "",
"MapTiles": "",
"Occluder": "",
"POIData": "",
"PowerManager": "",
"PowerNetwork": "",
"ProbeElectric": "",
"SpawnpointPlayer": "",
"UICommand": ""
}