WIP - world generation
This commit is contained in:
parent
d2902ac4aa
commit
83415745ec
5 changed files with 53 additions and 54 deletions
|
@ -63,6 +63,11 @@ _global_script_classes=[ {
|
|||
"class": "TrapTiles",
|
||||
"language": "GDScript",
|
||||
"path": "res://assets/Tiles/TrapTiles.gd"
|
||||
}, {
|
||||
"base": "Area2D",
|
||||
"class": "WarpZone",
|
||||
"language": "GDScript",
|
||||
"path": "res://src/Scripts/WarpZone.gd"
|
||||
} ]
|
||||
_global_script_class_icons={
|
||||
"CameraGame": "",
|
||||
|
@ -75,7 +80,8 @@ _global_script_class_icons={
|
|||
"Level": "",
|
||||
"Player": "",
|
||||
"Spike": "",
|
||||
"TrapTiles": ""
|
||||
"TrapTiles": "",
|
||||
"WarpZone": ""
|
||||
}
|
||||
|
||||
[application]
|
||||
|
|
|
@ -26,14 +26,14 @@ var _levels = [
|
|||
]
|
||||
|
||||
|
||||
export var _current_zone_level: = Vector2(0,1)
|
||||
export var _current_zone_level: = Vector2(0,0)
|
||||
|
||||
onready var _player:Player = (load("res://src/Actors/Player.tscn")).instance()
|
||||
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
_player.connect("died", self, "_on_player_died")
|
||||
var _void = _player.connect("died", self, "_on_player_died")
|
||||
_change_level(_current_zone_level)
|
||||
yield(self, "level_ready")
|
||||
|
||||
|
@ -49,7 +49,7 @@ func _change_level( newLevel:Vector2 = Vector2.ZERO, oldLevel:Vector2 = Vector2(
|
|||
$Level.remove_child(_levels[oldLevel.x][oldLevel.y])
|
||||
if !_levels[newLevel.x][newLevel.y].is_class("Node2D"):
|
||||
_levels[newLevel.x][newLevel.y] = _levels[newLevel.x][newLevel.y].instance()
|
||||
|
||||
_levels[newLevel.x][newLevel.y].level_coords = newLevel
|
||||
_levels[newLevel.x][newLevel.y].set_player(_player, _get_player_entering(oldLevel, newLevel))
|
||||
_levels[newLevel.x][newLevel.y].connect("level_exited", self, "_on_level_exited")
|
||||
$Level.add_child(_levels[newLevel.x][newLevel.y])
|
||||
|
@ -73,18 +73,15 @@ func _on_player_died():
|
|||
yield(Stage, "fade_finished")
|
||||
GameState.set_state(prev_state)
|
||||
|
||||
func _on_level_exited(next_level:bool = true, zone:int = -1):
|
||||
print("current level: %s, next_level: %s zone: %s" % [_current_zone_level, next_level, zone])
|
||||
func _on_level_exited(is_exit:bool, to_coords:Vector2, position:Vector2):
|
||||
print("current level: %s, is_exit: %s to_coords: %s position %s" % [_current_zone_level, is_exit, to_coords, position])
|
||||
var next = Vector2.ZERO
|
||||
if zone != -1:
|
||||
next = Vector2(
|
||||
zone,
|
||||
0 if next_level else len(_levels[zone]) -1
|
||||
)
|
||||
if to_coords.x == -1: # The zone is to a specific plase
|
||||
next = to_coords
|
||||
else:
|
||||
next = Vector2(
|
||||
_current_zone_level.x,
|
||||
_current_zone_level.y + 1 if next_level else _current_zone_level.y - 1
|
||||
_current_zone_level.y + 1 if is_exit else _current_zone_level.y - 1
|
||||
)
|
||||
if next.y < 0:
|
||||
next.x -= 1
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -14,11 +14,9 @@ export var game_state = GameState.States.GAME
|
|||
export var level_entry_point := Vector2.ZERO
|
||||
export var level_exit_point := Vector2.ZERO
|
||||
|
||||
export var exit_area_2d_path : NodePath
|
||||
export var enter_area_2d_path : NodePath
|
||||
var level_coords :=Vector2.ZERO
|
||||
export(Vector2) var prev_level = null
|
||||
|
||||
var _exit_area_2d = null;
|
||||
var _enter_area_2d = null;
|
||||
|
||||
export var camer_limits := {
|
||||
"top": 0,
|
||||
|
@ -28,24 +26,23 @@ export var camer_limits := {
|
|||
}
|
||||
|
||||
func _ready():
|
||||
self._exit_area_2d = get_node(exit_area_2d_path)
|
||||
self._enter_area_2d = get_node(enter_area_2d_path)
|
||||
pass
|
||||
|
||||
|
||||
|
||||
func _set_active(activated:bool = true):
|
||||
is_active_level = activated;
|
||||
func _set_active(activated:bool, prev_level_:Vector2):
|
||||
is_active_level = activated
|
||||
self.prev_level = prev_level_
|
||||
if activated:
|
||||
if _exit_area_2d != null: _exit_area_2d.connect("player_entered", self, "_on_ExitLevelAreaNext_player_entered")
|
||||
if _enter_area_2d != null: _enter_area_2d.connect("player_entered", self, "_on_ExitLevelArea_player_entered")
|
||||
for warp in _get_all_warps():
|
||||
warp.connect("player_entered", self, "_on_WarpZone_player_entered")
|
||||
emit_signal("level_ready")
|
||||
|
||||
func set_player(player:Player, is_entering:bool):
|
||||
func set_player(player:Player, is_entering:bool, spesific_position=null):
|
||||
_player = player
|
||||
_camera = _player.get_camera()
|
||||
_set_camera_limits()
|
||||
_set_player_position(is_entering)
|
||||
_set_player_position(is_entering, spesific_position)
|
||||
add_child(player)
|
||||
|
||||
func remove_player():
|
||||
|
@ -59,26 +56,25 @@ func _set_camera_limits():
|
|||
_camera.limit_bottom = camer_limits.bottom
|
||||
_camera.limit_left = camer_limits.left
|
||||
|
||||
func _set_player_position(is_entering:bool):
|
||||
_player.position = level_entry_point if is_entering else level_exit_point
|
||||
func _set_player_position(is_entering:bool, spesific_position=null):
|
||||
if spesific_position != null:
|
||||
_player.position = spesific_position
|
||||
else:
|
||||
_player.position = level_entry_point if is_entering else level_exit_point
|
||||
_player.face_player(is_entering)
|
||||
_player.respawn_position = _player.position
|
||||
|
||||
|
||||
func set_exit_area_enabled(enabled:bool=true):
|
||||
if _exit_area_2d != null: _exit_area_2d.set_block_signals(enabled)
|
||||
|
||||
func set_enter_area_enabled(enabled:bool=true):
|
||||
if _enter_area_2d != null: _enter_area_2d.set_block_signals(enabled)
|
||||
|
||||
func _on_ExitLevelArea_player_entered(is_exit, zone) -> void:
|
||||
print("_on_ExitLevelArea_player_entered")
|
||||
func _on_WarpZone_player_entered(is_exit, to_coords, position) -> void:
|
||||
print("_on_WarpZone_player_entered is_exit=%s to_coord=%s position=%s" % [is_exit, to_coords, position])
|
||||
self.is_active_level = false;
|
||||
emit_signal("level_exited", false)
|
||||
emit_signal("level_exited", is_exit, to_coords)
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
func _on_ExitLevelAreaNext_player_entered(is_exit, zone) -> void:
|
||||
print("_on_ExitLevelAreaNext_player_entered")
|
||||
self.is_active_level = false;
|
||||
emit_signal("level_exited", true)
|
||||
pass # Replace with function body.
|
||||
func _get_all_warps():
|
||||
var warps := []
|
||||
for node in get_children():
|
||||
if node.is_in_group("WarpZones"):
|
||||
warps.push_back(node)
|
||||
return warps
|
|
@ -4,9 +4,14 @@ class_name WarpZone
|
|||
|
||||
signal player_entered
|
||||
|
||||
export(int,-1, 3) var zone = -1;
|
||||
var NON_SPECIFIED_LEVEL :=Vector2(-1, -1)
|
||||
|
||||
export var to_level_coord:Vector2 =NON_SPECIFIED_LEVEL
|
||||
export var is_exit:bool = true
|
||||
|
||||
func _ready() -> void:
|
||||
add_to_group("WarpZones")
|
||||
|
||||
func _on_body_entered(body:Node):
|
||||
if body.name == "Player" and get_parent().is_active_level:
|
||||
emit_signal("player_entered", is_exit, zone)
|
||||
emit_signal("player_entered", is_exit, to_level_coord, position)
|
||||
|
|
Loading…
Reference in a new issue