Dynamic level linking via warp zones

This commit is contained in:
Sagi Dayan 2020-10-31 17:50:16 -04:00
parent 83415745ec
commit 1c62db1cf8
14 changed files with 108 additions and 145 deletions

View file

@ -90,7 +90,6 @@ config/name="Platformer"
run/main_scene="res://src/Intro/Intro.tscn"
boot_splash/image="res://assets/SplashScreen/BLANK.png"
boot_splash/use_filter=false
boot_splash/bg_color=Color( 0.141176, 0.141176, 0.141176, 1 )
config/icon="res://icon.png"
[autoload]
@ -202,5 +201,4 @@ attack={
[rendering]
quality/2d/use_pixel_snap=true
environment/default_clear_color=Color( 0, 0, 0, 1 )
environment/default_environment="res://default_env.tres"

View file

@ -69,7 +69,7 @@ func _physics_process(delta: float) -> void:
func _input_check() -> void:
if GameState.get_state() == GameState.States.GAME or GameState.get_state() == GameState.States.NEW_GAME:
if self._alive and (GameState.get_state() == GameState.States.GAME or GameState.get_state() == GameState.States.NEW_GAME):
_is_jump_canceled = Input.is_action_just_released("jump") and !_is_wall_jumping and _velocity.y < 0.0;
_get_direction()
_check_dash()

View file

@ -40,6 +40,7 @@ func _ready() -> void:
func _change_level( newLevel:Vector2 = Vector2.ZERO, oldLevel:Vector2 = Vector2(0,-1)):
print("Changing level [%s] -> [%s]" % [oldLevel, newLevel])
if oldLevel.y != -1:
GameState.set_state(GameState.States.TRANSITIONING)
Stage.fade_out(.5)
@ -49,11 +50,11 @@ 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].init_level_config(oldLevel, newLevel)
_levels[newLevel.x][newLevel.y].set_player(_player)
_levels[newLevel.x][newLevel.y].connect("level_exited", self, "_on_level_exited")
$Level.add_child(_levels[newLevel.x][newLevel.y])
_levels[newLevel.x][newLevel.y]._set_active(true)
_levels[newLevel.x][newLevel.y]._set_active(true, _get_player_entering(oldLevel, newLevel))
Stage.fade_in()
yield(Stage, "fade_finished")
GameState.set_state(_levels[newLevel.x][newLevel.y].game_state)
@ -73,24 +74,8 @@ func _on_player_died():
yield(Stage, "fade_finished")
GameState.set_state(prev_state)
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 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 is_exit else _current_zone_level.y - 1
)
if next.y < 0:
next.x -= 1
next.y = len(_levels[next.x]) - 1
if next.y > len(_levels[next.x]) - 1:
next.x += 1
next.y = 0
_change_level(next, _current_zone_level)
func _on_level_exited(is_exit:bool, to_coords:Vector2):
print("current level: %s, is_exit: %s to_coords: %s" % [_current_zone_level, is_exit, to_coords])
_change_level(to_coords, _current_zone_level)
yield(self, "level_ready")

View file

@ -10,8 +10,6 @@
script = ExtResource( 1 )
level_entry_point = Vector2( 16, 240 )
level_exit_point = Vector2( 675, 240 )
exit_area_2d_path = NodePath("ExitLevelArea")
enter_area_2d_path = NodePath("ExitLevelNextArea")
camer_limits = {
"bottom": 240,
"left": 0,
@ -26,9 +24,6 @@ tile_data = PoolIntArray( -131072, 0, 0, -131071, 0, 131076, -131070, 0, 131076,
position = Vector2( -15, 240 )
is_exit = false
[node name="ExitLevelNextArea" parent="." instance=ExtResource( 5 )]
position = Vector2( 680, 240 )
[node name="SpawnPoint" parent="." instance=ExtResource( 4 )]
position = Vector2( 239, 240 )
node = ExtResource( 3 )

View file

@ -5,17 +5,3 @@ func _ready() -> void:
print("TMP ready")
func _on_ExitLevelArea_body_entered(body: Node) -> void:
if body == _player and is_active_level:
print("_on_ExitLevelArea_body_entered")
self.is_active_level = false;
emit_signal("level_exited", false)
pass # Replace with function body.
func _on_ExitLevelAreaNext_body_entered(body: Node) -> void:
if body == _player and is_active_level:
print("_on_ExitLevelAreaNext_body_entered")
self.is_active_level = false;
emit_signal("level_exited", true)
pass # Replace with function body.

File diff suppressed because one or more lines are too long

View file

@ -16,6 +16,9 @@ export var level_exit_point := Vector2.ZERO
var level_coords :=Vector2.ZERO
export(Vector2) var prev_level = null
export(Vector2) var next_level = null
var _first_time_init = true
export var camer_limits := {
@ -30,22 +33,31 @@ func _ready():
func _set_active(activated:bool, prev_level_:Vector2):
is_active_level = activated
func init_level_config(prev_level_:Vector2, level_coords_:Vector2):
print("Initializing [%s]: prev = %s | current = %s" % [self.name, prev_level_, level_coords_])
self.prev_level = prev_level_
self.level_coords = level_coords_
self.next_level = Vector2(level_coords.x, level_coords.y + 1)
func _set_active(activated:bool, is_entering:bool):
print("Setting active [%s]: active = %s " % [self.name, activated])
is_active_level = activated
if activated:
for warp in _get_all_warps():
warp.connect("player_entered", self, "_on_WarpZone_player_entered")
if _first_time_init: _set_wrap_zones()
_set_player_position(is_entering)
emit_signal("level_ready")
func set_player(player:Player, is_entering:bool, spesific_position=null):
func set_player(player:Player):
print("Setting player [%s]" % [self.name])
_player = player
_camera = _player.get_camera()
_set_camera_limits()
_set_player_position(is_entering, spesific_position)
add_child(player)
add_child(_player)
func remove_player():
print("Removing player [%s]" % [self.name])
remove_child(_player)
_camera = null
_player = null
@ -56,19 +68,32 @@ func _set_camera_limits():
_camera.limit_bottom = camer_limits.bottom
_camera.limit_left = camer_limits.left
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_player_position(is_entering:bool):
var warps = _get_all_warps()
for warp in warps:
if warp.to_level_coord == prev_level:
_player.position = warp.get_checkpoint_position()
_player.face_player(is_entering)
_player.respawn_position = _player.position
print("Found point warp.position.x = %s player spawn.x = %s" % [warp.position.x, _player.position.x])
func _set_wrap_zones():
_first_time_init = false
var warps = _get_all_warps()
for warp in warps:
warp.connect("player_entered", self, "_on_WarpZone_player_entered")
var has_custom_level = warp.to_level_coord != warp.NON_SPECIFIED_LEVEL
if not has_custom_level:
if not warp.is_exit: warp.to_level_coord = self.prev_level
else: warp.to_level_coord = self.next_level
print("Warp has no costum level set to: %s" % [warp.to_level_coord])
else:
print("Warp a costum level: %s" % [warp.to_level_coord])
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])
func _on_WarpZone_player_entered(is_exit, to_level_coord) -> void:
print("_on_WarpZone_player_entered is_exit=%s to_level=%s" % [is_exit, to_level_coord])
self.is_active_level = false;
emit_signal("level_exited", is_exit, to_coords)
emit_signal("level_exited", is_exit, to_level_coord)
pass # Replace with function body.
@ -77,4 +102,5 @@ func _get_all_warps():
for node in get_children():
if node.is_in_group("WarpZones"):
warps.push_back(node)
return warps
print("_get_all_warps [%s]: #%d of warps found" % [self.name, len(warps)])
return warps

View file

@ -39,8 +39,3 @@ func _process(delta: float) -> void:
$AmbiantLighting.change_light("NIGHT")
else:
$AmbiantLighting.change_light("DAY")
if _player.position.x > 700:
print("exited")
is_active_level = false
emit_signal("level_exited", true)

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=23 format=2]
[gd_scene load_steps=24 format=2]
[ext_resource path="res://src/GameWorld/Levels/PreGame.gd" type="Script" id=1]
[ext_resource path="res://assets/Tiles/background_0.png" type="Texture" id=2]
@ -14,6 +14,7 @@
[ext_resource path="res://assets/Tiles/SolidsTileMap.tscn" type="PackedScene" id=12]
[ext_resource path="res://src/Actors/WiseOldDude/WiseOldDude.tscn" type="PackedScene" id=13]
[ext_resource path="res://src/GameWorld/AmbiantLighting.tscn" type="PackedScene" id=14]
[ext_resource path="res://src/Scripts/WarpZone.tscn" type="PackedScene" id=15]
[sub_resource type="TileSet" id=1]
0/name = "tileset.png 0"
@ -260,4 +261,8 @@ position = Vector2( 15, -12 )
position = Vector2( 535, 42 )
[node name="AmbiantLighting" parent="." instance=ExtResource( 14 )]
[node name="WarpZone" parent="." instance=ExtResource( 15 )]
position = Vector2( 723, 225 )
to_level_coord = Vector2( 0, 1 )
[connection signal="body_entered" from="CutsceneAreas/OldDudeIntroArea" to="." method="_on_OldDudeIntroArea_body_entered"]

View file

@ -8,5 +8,3 @@ func _enter_tree() -> void:
AudioManager.play_music(AudioManager.Music.PreGame)
func _on_WarpZone_player_entered(is_exit, zone):
emit_signal("level_exited", is_exit, zone)

File diff suppressed because one or more lines are too long

View file

@ -2,7 +2,6 @@ extends Node2D
class_name CheckPoint
signal activated
export var activated:=false
@ -16,13 +15,8 @@ func activate() -> void:
activated = true
$AnimationPlayer.play("activated")
$Particles2D.emitting = true
emit_signal("activated", self)
func _on_activated_animation_finished():
$Particles2D.amount = 5
$AnimationPlayer.play("active")
func _on_Area2D_body_entered(body: Node) -> void:
if body.name == "Player":
activate()

View file

@ -1,13 +1,10 @@
[gd_scene load_steps=15 format=2]
[gd_scene load_steps=14 format=2]
[ext_resource path="res://assets/Items/save_point_anim_strip_9.png" type="Texture" id=1]
[ext_resource path="res://assets/Items/torch_ligt_texture.png" type="Texture" id=2]
[ext_resource path="res://src/Items/CheckPoint.gd" type="Script" id=3]
[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 10, 11 )
[sub_resource type="Animation" id=2]
[sub_resource type="Animation" id=1]
length = 0.7
tracks/0/type = "value"
tracks/0/path = NodePath("Light2D:enabled")
@ -72,7 +69,7 @@ tracks/4/keys = {
} ]
}
[sub_resource type="Animation" id=3]
[sub_resource type="Animation" id=2]
resource_name = "active"
length = 0.7
loop = true
@ -125,7 +122,7 @@ tracks/3/keys = {
"values": [ Vector2( 1, 1 ), Vector2( 1.63405, 1.63405 ), Vector2( 2.21172, 2.21172 ), Vector2( 2.11387, 2.11387 ) ]
}
[sub_resource type="Animation" id=4]
[sub_resource type="Animation" id=3]
length = 0.7
loop = true
tracks/0/type = "value"
@ -165,27 +162,27 @@ tracks/2/keys = {
"values": [ 1, 2, 3, 4, 5, 6, 7, 8 ]
}
[sub_resource type="Gradient" id=5]
[sub_resource type="Gradient" id=4]
colors = PoolColorArray( 0.145098, 1, 1, 1, 0.941176, 0.713726, 0, 0.870588 )
[sub_resource type="GradientTexture" id=6]
gradient = SubResource( 5 )
[sub_resource type="GradientTexture" id=5]
gradient = SubResource( 4 )
[sub_resource type="Curve" id=7]
[sub_resource type="Curve" id=6]
min_value = -200.0
max_value = 200.0
_data = [ Vector2( 0, 200 ), 0.0, -253.551, 0, 0, Vector2( 1, -200 ), 74.3008, 0.0, 0, 0 ]
[sub_resource type="CurveTexture" id=8]
curve = SubResource( 7 )
[sub_resource type="CurveTexture" id=7]
curve = SubResource( 6 )
[sub_resource type="Curve" id=9]
[sub_resource type="Curve" id=8]
_data = [ Vector2( 0.00784314, 1 ), 0.0, 0.0, 0, 0, Vector2( 1, 0.0772727 ), 0.0, 0.0, 0, 0 ]
[sub_resource type="CurveTexture" id=10]
curve = SubResource( 9 )
[sub_resource type="CurveTexture" id=9]
curve = SubResource( 8 )
[sub_resource type="ParticlesMaterial" id=11]
[sub_resource type="ParticlesMaterial" id=10]
emission_shape = 2
emission_box_extents = Vector3( 5, 4, 1 )
flag_disable_z = true
@ -197,25 +194,17 @@ orbit_velocity = 0.0
orbit_velocity_random = 0.0
linear_accel = 100.0
linear_accel_random = 0.2
linear_accel_curve = SubResource( 8 )
linear_accel_curve = SubResource( 7 )
angle = 31.8
angle_random = 0.5
scale = 1.5
scale_random = 0.06
scale_curve = SubResource( 10 )
color_ramp = SubResource( 6 )
scale_curve = SubResource( 9 )
color_ramp = SubResource( 5 )
[node name="CheckPoint" type="Node2D"]
script = ExtResource( 3 )
[node name="Area2D" type="Area2D" parent="."]
collision_layer = 16
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
visible = false
position = Vector2( 0, -11 )
shape = SubResource( 1 )
[node name="Sprite" type="Sprite" parent="."]
position = Vector2( 0, -10 )
texture = ExtResource( 1 )
@ -233,9 +222,9 @@ shadow_item_cull_mask = -2147483639
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
autoplay = "idle"
anims/activated = SubResource( 2 )
anims/active = SubResource( 3 )
anims/idle = SubResource( 4 )
anims/activated = SubResource( 1 )
anims/active = SubResource( 2 )
anims/idle = SubResource( 3 )
[node name="Particles2D" type="Particles2D" parent="."]
position = Vector2( 0, -4.625 )
@ -244,5 +233,4 @@ amount = 7
lifetime = 0.3
speed_scale = 0.5
explosiveness = 0.25
process_material = SubResource( 11 )
[connection signal="body_entered" from="Area2D" to="." method="_on_Area2D_body_entered"]
process_material = SubResource( 10 )

View file

@ -3,15 +3,25 @@ extends Area2D
class_name WarpZone
signal player_entered
var NON_SPECIFIED_LEVEL :=Vector2(-1, -1)
export var to_level_coord:Vector2 =NON_SPECIFIED_LEVEL
export var to_level_coord:Vector2 = Vector2(-1, -1)
export var is_exit:bool = true
const spawn_offset = 30
var initialized = false
const NON_SPECIFIED_LEVEL :=Vector2(-1, -1)
func _ready() -> void:
add_to_group("WarpZones")
if not initialized: add_to_group("WarpZones")
initialized = true;
func _on_body_entered(body:Node):
if body.name == "Player" and get_parent().is_active_level:
emit_signal("player_entered", is_exit, to_level_coord, position)
print("Warp - exit=%s to_level=%s" % [is_exit, to_level_coord])
emit_signal("player_entered", is_exit, to_level_coord)
func get_checkpoint_position():
var factor = -1 if is_exit else 1
return position + Vector2(factor * spawn_offset, 0)