2020-07-06 12:38:05 +00:00
|
|
|
extends Node2D
|
|
|
|
|
2020-07-06 22:00:39 +00:00
|
|
|
class_name GameWorld
|
|
|
|
|
2020-07-13 19:01:36 +00:00
|
|
|
enum Map { RUNTIME, ODYSSEY, EMPTY }
|
2020-07-10 08:45:57 +00:00
|
|
|
|
2020-09-15 23:23:45 +00:00
|
|
|
const playerRes := preload("res://Actors/Player/Player.tscn")
|
2020-07-10 08:45:57 +00:00
|
|
|
|
2020-09-15 23:23:45 +00:00
|
|
|
var map: GameMap = null
|
2020-07-10 08:45:57 +00:00
|
|
|
var player = null
|
2020-07-06 12:38:05 +00:00
|
|
|
|
2020-07-13 19:01:36 +00:00
|
|
|
onready var scene_manager = $"/root/SceneManager"
|
|
|
|
|
|
|
|
func load_map(map_name):
|
|
|
|
match map_name:
|
2020-07-10 08:45:57 +00:00
|
|
|
Map.RUNTIME:
|
2020-07-13 19:01:36 +00:00
|
|
|
map = scene_manager.queue.get_resource("res://Scenes/Maps/runtime.tscn").instance()
|
2020-07-10 08:45:57 +00:00
|
|
|
Map.ODYSSEY:
|
2020-07-13 19:01:36 +00:00
|
|
|
map = scene_manager.queue.get_resource("res://Scenes/Maps/odyssey.tscn").instance()
|
|
|
|
Map.EMPTY:
|
|
|
|
map = preload("res://Scenes/Maps/empty.tscn").instance()
|
2020-07-10 08:45:57 +00:00
|
|
|
add_child(map)
|
2020-07-13 19:01:36 +00:00
|
|
|
|
|
|
|
func spawn_player(peer: int, is_current_user: bool):
|
2020-09-15 23:23:45 +00:00
|
|
|
var playerNode := playerRes.instance()
|
2020-07-13 19:01:36 +00:00
|
|
|
playerNode.set_network_master(peer, true)
|
|
|
|
playerNode.is_controlled = is_current_user
|
2020-09-15 23:23:45 +00:00
|
|
|
var spawnpoints := map.get_pois(POI.POIType.SpawnPoint, POI.POIClass.Player)
|
2020-07-10 08:45:57 +00:00
|
|
|
if spawnpoints.size() > 0:
|
2020-07-13 19:01:36 +00:00
|
|
|
playerNode.transform.origin = (spawnpoints[0] as Node2D).transform.origin
|
2020-07-10 08:45:57 +00:00
|
|
|
else:
|
|
|
|
print("Map does not have Player spawnpoint POI! Spawning at origin (very bad)")
|
2020-07-13 19:01:36 +00:00
|
|
|
$players.add_child(playerNode, true)
|
|
|
|
if is_current_user:
|
|
|
|
player = playerNode
|
|
|
|
for tilemap in map.tilemaps:
|
|
|
|
if tilemap is MapTiles:
|
|
|
|
tilemap.set_occluder_origin(playerNode)
|
|
|
|
return playerNode
|