[WIP] new way wo warp between levels. Need some work still to get back from warp to hub (mutiple exits/enterences in a level). Currently it is supporting 1 entrence and one exit from each level...

This commit is contained in:
Sagi Dayan 2020-10-26 08:21:11 -04:00
parent 5b76f72ca6
commit d2902ac4aa
30 changed files with 755 additions and 147 deletions

18
.vscode/launch.json vendored Normal file
View file

@ -0,0 +1,18 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "GDScript Godot",
"type": "godot",
"request": "launch",
"project": "${workspaceFolder}",
"port": 6007,
"address": "127.0.0.1",
"launch_game_instance": true,
"launch_scene": false
}
]
}

View file

@ -0,0 +1,7 @@
extends TileMap
class_name TrapTiles
func _ready() -> void:
var cells = get_used_cells()
pass

View file

@ -0,0 +1,40 @@
[gd_scene load_steps=5 format=2]
[ext_resource path="res://assets/Tiles/spikes.png" type="Texture" id=1]
[sub_resource type="OccluderPolygon2D" id=1]
polygon = PoolVector2Array( 0, 13.9545, 0, 13.7219, 3.48895, 8.37286, 6.97746, 14.1871, 11.6288, 8.1403, 15.3499, 13.7219, 16, 14.1871, 16, 16, 0, 16 )
[sub_resource type="ConvexPolygonShape2D" id=2]
points = PoolVector2Array( 16, 16, 0, 16, 0, 7.90773, 16, 7.90773 )
[sub_resource type="TileSet" id=3]
0/name = "spikes.png 0"
0/texture = ExtResource( 1 )
0/tex_offset = Vector2( 0, 0 )
0/modulate = Color( 1, 1, 1, 1 )
0/region = Rect2( 0, 0, 16, 16 )
0/tile_mode = 0
0/occluder_offset = Vector2( 0, 0 )
0/occluder = SubResource( 1 )
0/navigation_offset = Vector2( 0, 0 )
0/shape_offset = Vector2( 0, 0 )
0/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
0/shape = SubResource( 2 )
0/shape_one_way = false
0/shape_one_way_margin = 1.0
0/shapes = [ {
"autotile_coord": Vector2( 0, 0 ),
"one_way": false,
"one_way_margin": 1.0,
"shape": SubResource( 2 ),
"shape_transform": Transform2D( 1, 0, 0, 1, 0, 0 )
} ]
0/z_index = 0
[node name="TrapTiles" type="TileMap"]
tile_set = SubResource( 3 )
cell_size = Vector2( 16, 16 )
collision_layer = 4
occluder_light_mask = 0
format = 1

BIN
assets/Tiles/spikes.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 644 B

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/spikes.png-c7b541d2d82e62d5802b55df14f95e12.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/Tiles/spikes.png"
dest_files=[ "res://.import/spikes.png-c7b541d2d82e62d5802b55df14f95e12.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

View file

@ -9,6 +9,11 @@
config_version=4 config_version=4
_global_script_classes=[ { _global_script_classes=[ {
"base": "Camera2D",
"class": "CameraGame",
"language": "GDScript",
"path": "res://src/Actors/Camera.gd"
}, {
"base": "Node2D", "base": "Node2D",
"class": "CheckPoint", "class": "CheckPoint",
"language": "GDScript", "language": "GDScript",
@ -39,6 +44,11 @@ _global_script_classes=[ {
"language": "GDScript", "language": "GDScript",
"path": "res://src/HUD/HUD.gd" "path": "res://src/HUD/HUD.gd"
}, { }, {
"base": "Node2D",
"class": "Level",
"language": "GDScript",
"path": "res://src/GameWorld/Levels/Level.gd"
}, {
"base": "KinematicBody2D", "base": "KinematicBody2D",
"class": "Player", "class": "Player",
"language": "GDScript", "language": "GDScript",
@ -48,16 +58,24 @@ _global_script_classes=[ {
"class": "Spike", "class": "Spike",
"language": "GDScript", "language": "GDScript",
"path": "res://src/Hazards/Spike.gd" "path": "res://src/Hazards/Spike.gd"
}, {
"base": "TileMap",
"class": "TrapTiles",
"language": "GDScript",
"path": "res://assets/Tiles/TrapTiles.gd"
} ] } ]
_global_script_class_icons={ _global_script_class_icons={
"CameraGame": "",
"CheckPoint": "", "CheckPoint": "",
"Coin": "", "Coin": "",
"CutScene": "", "CutScene": "",
"DialogBubble": "", "DialogBubble": "",
"Enemy": "", "Enemy": "",
"HUD": "", "HUD": "",
"Level": "",
"Player": "", "Player": "",
"Spike": "" "Spike": "",
"TrapTiles": ""
} }
[application] [application]

View file

@ -1,5 +1,7 @@
extends Camera2D extends Camera2D
class_name CameraGame
var _shake_config := { var _shake_config := {
'amplitude': .0, 'amplitude': .0,
'transition': Tween.TRANS_SINE, 'transition': Tween.TRANS_SINE,

View file

@ -64,6 +64,7 @@ func _physics_process(delta: float) -> void:
_input_check() _input_check()
_velocity = calculate_move_velocity(_direction,_is_jump_canceled, delta) _velocity = calculate_move_velocity(_direction,_is_jump_canceled, delta)
_velocity = move_and_slide(_velocity, Vector2.UP) _velocity = move_and_slide(_velocity, Vector2.UP)
_check_collisions()
update_sprite(_direction) update_sprite(_direction)
@ -78,7 +79,12 @@ func _input_check() -> void:
_direction = Vector2.ZERO _direction = Vector2.ZERO
func _check_collisions():
for i in get_slide_count():
var collision = get_slide_collision(i)
if collision.collider.name == 'TrapTiles':
die()
return
func _update_state(new_state:int = -1): func _update_state(new_state:int = -1):
@ -98,6 +104,7 @@ func _update_state(new_state:int = -1):
elif _velocity.y >=0 and is_on_wall(): elif _velocity.y >=0 and is_on_wall():
if _state != States.WALL_SLIDING: if _state != States.WALL_SLIDING:
_velocity.y=0 _velocity.y=0
_falling_start_position = position.y
new_state = States.WALL_SLIDING new_state = States.WALL_SLIDING
elif _state == States.WALL_SLIDING: elif _state == States.WALL_SLIDING:
if is_on_floor() or not is_on_wall(): if is_on_floor() or not is_on_wall():
@ -107,7 +114,7 @@ func _update_state(new_state:int = -1):
func _transition_state(old_state, new_state, auto_update): func _transition_state(old_state, new_state, auto_update):
if new_state != old_state: if new_state != old_state:
print("[Player]: State Update: [%s] -> [%s] | Automatic: %s" % [old_state, new_state, auto_update]) # print("[Player]: State Update: [%s] -> [%s] | Automatic: %s" % [old_state, new_state, auto_update])
_state = new_state _state = new_state
if old_state == States.IDLE: if old_state == States.IDLE:
# idle -> attak = ground attack - stop _velocity.x # idle -> attak = ground attack - stop _velocity.x
@ -213,14 +220,15 @@ func _revive():
func update_sprite(_direction:Vector2) -> void: func update_sprite(_direction:Vector2) -> void:
if not _alive: return;
var air_animation = "jump" if _velocity.y <= 0 else "fall" var air_animation = "jump" if _velocity.y <= 0 else "fall"
if _state == States.ATTACKING: return if _state == States.ATTACKING: return
var attack = Input.is_action_just_pressed("attack") and abilities.attack var attack = Input.is_action_just_pressed("attack") and abilities.attack
if _velocity.x > .5 and not _state == States.WALL_SLIDING: if _velocity.x > .5 and not _state == States.WALL_SLIDING:
$Sprite.scale = Vector2(1,1) face_player(true)
$AnimationPlayer.play("run" if is_on_floor() else air_animation) $AnimationPlayer.play("run" if is_on_floor() else air_animation)
elif _velocity.x < -.5 and not _state == States.WALL_SLIDING: elif _velocity.x < -.5 and not _state == States.WALL_SLIDING:
$Sprite.scale = Vector2(-1,1) face_player(false)
$AnimationPlayer.play("run" if is_on_floor() else air_animation) $AnimationPlayer.play("run" if is_on_floor() else air_animation)
else: else:
if not _state == States.IN_AIR: $AnimationPlayer.play("idle") if not _state == States.IN_AIR: $AnimationPlayer.play("idle")
@ -257,17 +265,17 @@ func _attack():
_update_state(States.IDLE) _update_state(States.IDLE)
func _on_die_animation_done(): func _on_die_animation_done():
emit_signal("died")
_respawn() _respawn()
_revive() _revive()
func die(): func die():
emit_signal("died")
_alive = false _alive = false
$AnimationPlayer.play("die") $AnimationPlayer.play("die")
$Camera.start_shake() $Camera.start_shake()
GameState.player_died(self) GameState.player_died()
func setAbility(ability:String, enabled:bool=false): func set_ability(ability:String, enabled:bool=false):
if ability == 'dash': if ability == 'dash':
abilities.dash = enabled abilities.dash = enabled
elif ability == 'wall_jump': elif ability == 'wall_jump':
@ -290,3 +298,11 @@ func _on_SordRange_body_entered(body: Node) -> void:
if body.is_in_group("Enemies"): if body.is_in_group("Enemies"):
body.take_damage($Sprite.scale.x) body.take_damage($Sprite.scale.x)
pass # Replace with function body. pass # Replace with function body.
func get_camera():
return $Camera
func face_player(right:bool = true):
$Sprite.scale = Vector2(
1 if right else -1,
1
)

View file

@ -1,8 +1,9 @@
[gd_scene load_steps=4 format=2] [gd_scene load_steps=5 format=2]
[ext_resource path="res://src/Actors/WiseOldDude/wize_old_dude.png" type="Texture" id=1] [ext_resource path="res://src/Actors/WiseOldDude/wize_old_dude.png" type="Texture" id=1]
[ext_resource path="res://assets/Items/torch_ligt_texture.png" type="Texture" id=2]
[sub_resource type="Animation" id=2] [sub_resource type="Animation" id=1]
resource_name = "fade" resource_name = "fade"
length = 0.5 length = 0.5
tracks/0/type = "value" tracks/0/type = "value"
@ -29,9 +30,20 @@ tracks/1/keys = {
"update": 0, "update": 0,
"values": [ Color( 1, 1, 1, 0 ), Color( 1, 1, 1, 1 ) ] "values": [ Color( 1, 1, 1, 0 ), Color( 1, 1, 1, 1 ) ]
} }
tracks/2/type = "value"
tracks/2/path = NodePath("Sprite/Light2D:energy")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/keys = {
"times": PoolRealArray( 0, 0.3 ),
"transitions": PoolRealArray( 1, 1 ),
"update": 0,
"values": [ 0.0, 1.0 ]
}
[sub_resource type="Animation" id=1] [sub_resource type="Animation" id=2]
resource_name = "idle"
length = 0.8 length = 0.8
loop = true loop = true
tracks/0/type = "value" tracks/0/type = "value"
@ -46,6 +58,30 @@ tracks/0/keys = {
"update": 1, "update": 1,
"values": [ 17, 18, 19, 20, 21 ] "values": [ 17, 18, 19, 20, 21 ]
} }
tracks/1/type = "value"
tracks/1/path = NodePath("Sprite/Light2D:energy")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/keys = {
"times": PoolRealArray( 0, 0.4, 0.8 ),
"transitions": PoolRealArray( 1, 1, 1 ),
"update": 0,
"values": [ 1.0, 0.9, 1.0 ]
}
tracks/2/type = "value"
tracks/2/path = NodePath("Sprite/Light2D:texture_scale")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/keys = {
"times": PoolRealArray( 0, 0.4, 0.8 ),
"transitions": PoolRealArray( 1, 1, 1 ),
"update": 0,
"values": [ 15.0, 10.0, 15.0 ]
}
[node name="WiseOldDude" type="Node2D"] [node name="WiseOldDude" type="Node2D"]
@ -56,8 +92,16 @@ scale = Vector2( 0.6875, 0.6875 )
texture = ExtResource( 1 ) texture = ExtResource( 1 )
vframes = 6 vframes = 6
hframes = 9 hframes = 9
frame = 17 frame = 21
[node name="Light2D" type="Light2D" parent="Sprite"]
texture = ExtResource( 2 )
texture_scale = 15.0
color = Color( 0.768627, 0.913725, 0.992157, 1 )
energy = 0.0
shadow_enabled = true
shadow_item_cull_mask = 9
[node name="AnimationPlayer" type="AnimationPlayer" parent="."] [node name="AnimationPlayer" type="AnimationPlayer" parent="."]
anims/fade = SubResource( 2 ) anims/fade = SubResource( 1 )
anims/idle = SubResource( 1 ) anims/idle = SubResource( 2 )

View file

@ -29,7 +29,8 @@ var _old_man_dialog2 = [
}, },
] ]
func start_scene(camera:Camera2D): func start_scene(camera:CameraGame = null):
_started = true;
_main_camera_ref = camera _main_camera_ref = camera
position = camera.get_global_transform().get_origin() position = camera.get_global_transform().get_origin()
_camera = camera.duplicate() _camera = camera.duplicate()
@ -48,7 +49,6 @@ func start_scene(camera:Camera2D):
yield($AnimationPlayer, "animation_finished") yield($AnimationPlayer, "animation_finished")
var dialog_bubble:DialogBubble = _dialog_bubble.instance() var dialog_bubble:DialogBubble = _dialog_bubble.instance()
dialog_bubble.allow_fast_skip = bool(GameState.get_statistics().total_time_played)
dialog_bubble.dialog = _old_man_dialog dialog_bubble.dialog = _old_man_dialog
$Overlay.add_child(dialog_bubble) $Overlay.add_child(dialog_bubble)
dialog_bubble.start_dialog() dialog_bubble.start_dialog()
@ -89,6 +89,10 @@ func start_scene(camera:Camera2D):
_on_scene_exited() _on_scene_exited()
pass pass
func _input(event: InputEvent) -> void:
if not _started: return
if Input.is_action_just_pressed("jump"):
if allow_skip: _on_scene_exited()
func _on_scene_exited(): func _on_scene_exited():

View file

@ -2,7 +2,6 @@ extends Control
class_name DialogBubble class_name DialogBubble
signal dialog_finished signal dialog_finished
var allow_fast_skip := false
var dialog = [] # Dictionary[] {text:string, callback:function}[] var dialog = [] # Dictionary[] {text:string, callback:function}[]
var _position := 0 var _position := 0
@ -33,8 +32,6 @@ func _show_text():
func _input(event: InputEvent) -> void: func _input(event: InputEvent) -> void:
if not _started: return if not _started: return
if Input.is_action_just_pressed("jump"): if Input.is_action_just_pressed("jump"):
if allow_fast_skip: dismiss()
else:
_position += 1 _position += 1
$AnimationPlayer.play_backwards("show_text") $AnimationPlayer.play_backwards("show_text")
yield($AnimationPlayer, "animation_finished") yield($AnimationPlayer, "animation_finished")

View file

@ -3,8 +3,7 @@ extends CutScene
func _ready() -> void: func _ready() -> void:
start_scene() start_scene()
func start_scene(camera:Camera2D = null): func start_scene(camera:CameraGame = null):
var text_show_delay = 2 var text_show_delay = 2
var no_text_delay = 1 var no_text_delay = 1

View file

@ -1,17 +1,99 @@
extends Node2D extends Node2D
signal level_ready
var _level_resources := {
"pre_game": load("res://src/GameWorld/Levels/PreGame.tscn"),
"hub" : load("res://src/GameWorld/Levels/WorldHub.tscn"),
"zones": {
1: [
],
2: [
],
3: [
]
}
}
var _levels = [
[_level_resources.pre_game, _level_resources.hub],
[load("res://src/GameWorld/Levels/FirstLevels/TMP.tscn")],
[load("res://src/GameWorld/Levels/FirstLevels/TMP2.tscn")]
]
export var _current_zone_level: = Vector2(0,1)
onready var _player:Player = (load("res://src/Actors/Player.tscn")).instance()
func _ready() -> void: func _ready() -> void:
$Player/Camera.limit_bottom = 250 _player.connect("died", self, "_on_player_died")
$Player/Camera.limit_left = -45 _change_level(_current_zone_level)
$Player/Camera.limit_right = 700 yield(self, "level_ready")
func _process(delta: float) -> void:
if $Player.global_position.x > 330: func _change_level( newLevel:Vector2 = Vector2.ZERO, oldLevel:Vector2 = Vector2(0,-1)):
$AmbiantLighting.change_light("NIGHT") if oldLevel.y != -1:
GameState.set_state(GameState.States.TRANSITIONING)
Stage.fade_out(.5)
yield(Stage, "fade_finished")
_levels[oldLevel.x][oldLevel.y].remove_player()
_levels[oldLevel.x][oldLevel.y].disconnect("level_exited", self, "_on_level_exited")
$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].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])
_levels[newLevel.x][newLevel.y]._set_active(true)
Stage.fade_in()
yield(Stage, "fade_finished")
GameState.set_state(_levels[newLevel.x][newLevel.y].game_state)
_current_zone_level = newLevel
emit_signal("level_ready")
func _get_player_entering(oldLevel:Vector2, newLevel:Vector2) -> bool:
if oldLevel.y == -1: return true;
return oldLevel.x < newLevel.x || (oldLevel.x == newLevel.x && oldLevel.y < newLevel.y)
func _on_player_died():
var prev_state = _levels[_current_zone_level.x][_current_zone_level.y].game_state
GameState.set_state(GameState.States.TRANSITIONING)
Stage.fade_out(.8)
yield(Stage, "fade_finished")
Stage.fade_in(.8)
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])
var next = Vector2.ZERO
if zone != -1:
next = Vector2(
zone,
0 if next_level else len(_levels[zone]) -1
)
else: else:
$AmbiantLighting.change_light("DAY") next = Vector2(
_current_zone_level.x,
_current_zone_level.y + 1 if next_level 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)
yield(self, "level_ready")

View file

@ -1,10 +1,7 @@
[gd_scene load_steps=6 format=2] [gd_scene load_steps=3 format=2]
[ext_resource path="res://src/HUD/HUD.tscn" type="PackedScene" id=1] [ext_resource path="res://src/HUD/HUD.tscn" type="PackedScene" id=1]
[ext_resource path="res://src/GameWorld/PreGame.tscn" type="PackedScene" id=2]
[ext_resource path="res://src/Actors/Player.tscn" type="PackedScene" id=3]
[ext_resource path="res://src/GameWorld/GameWorld.gd" type="Script" id=5] [ext_resource path="res://src/GameWorld/GameWorld.gd" type="Script" id=5]
[ext_resource path="res://src/GameWorld/AmbiantLighting.tscn" type="PackedScene" id=10]
[node name="GameWorld" type="Node2D"] [node name="GameWorld" type="Node2D"]
script = ExtResource( 5 ) script = ExtResource( 5 )
@ -12,17 +9,4 @@ script = ExtResource( 5 )
[node name="HUD" parent="." instance=ExtResource( 1 )] [node name="HUD" parent="." instance=ExtResource( 1 )]
layer = 2 layer = 2
[node name="PreGame" parent="." instance=ExtResource( 2 )] [node name="Level" type="Node2D" parent="."]
[node name="Player" parent="." instance=ExtResource( 3 )]
position = Vector2( 73, 222 )
abilities = {
"attack": true,
"dash": true,
"light_beam": true,
"wall_jump": true
}
[node name="AmbiantLighting" parent="." instance=ExtResource( 10 )]
[editable path="AmbiantLighting"]

View file

@ -0,0 +1,8 @@
extends Level
func _ready() -> void:
print("TMP ready")

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,21 @@
extends Level
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

@ -0,0 +1,84 @@
extends Node2D
class_name Level
signal level_exited
signal level_ready
var _player:Player
var _camera:CameraGame
var is_active_level := false
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 _exit_area_2d = null;
var _enter_area_2d = null;
export var camer_limits := {
"top": 0,
"right": 400,
"bottom": 400,
"left": 0,
}
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;
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")
emit_signal("level_ready")
func set_player(player:Player, is_entering:bool):
_player = player
_camera = _player.get_camera()
_set_camera_limits()
_set_player_position(is_entering)
add_child(player)
func remove_player():
remove_child(_player)
_camera = null
_player = null
func _set_camera_limits():
_camera.limit_top = camer_limits.top
_camera.limit_right = camer_limits.right
_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
_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")
self.is_active_level = false;
emit_signal("level_exited", false)
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.

View file

@ -1,27 +1,46 @@
extends Node2D extends Level
var _Cutscenes = { var _Cutscenes = {
"old_man_intro": "res://src/CutScenes/ChallengeCutscene.tscn" "old_man_intro": "res://src/CutScenes/ChallengeCutscene.tscn"
} }
var _played_old_man_cutscene = false var _played_old_man_cutscene = false
func _ready() -> void:
print("preGameReady")
_player.set_ability("dash", true)
_player.set_ability("wall_jump", true)
_player.set_ability("attack", true)
func _on_OldDudeIntroArea_body_entered(body: Node) -> void: func _on_OldDudeIntroArea_body_entered(body: Node) -> void:
if _played_old_man_cutscene: return if _played_old_man_cutscene: return
if body.name == 'Player': if body.name == 'Player':
GameState.set_state(GameState.States.CUTSCENE)
AudioManager.play_music(AudioManager.Music.Abandon)
var old_man_animation_palyer = $WiseOldDude/AnimationPlayer var old_man_animation_palyer = $WiseOldDude/AnimationPlayer
old_man_animation_palyer.play("fade") old_man_animation_palyer.play("fade")
yield(old_man_animation_palyer, "animation_finished") yield(old_man_animation_palyer, "animation_finished")
old_man_animation_palyer.play("idle") old_man_animation_palyer.play("idle")
_played_old_man_cutscene = true _played_old_man_cutscene = true
AudioManager.play_music(AudioManager.Music.Abandon) var scene:CutScene = (load(_Cutscenes.old_man_intro)).instance()
GameState.start_cutscene()
var scene = (load(_Cutscenes.old_man_intro)).instance()
add_child(scene) add_child(scene)
scene.allow_skip = !GameState.is_first_run
scene.start_scene(body.get_node("Camera")) scene.start_scene(body.get_node("Camera"))
yield(scene, "cutscene_finished") yield(scene, "cutscene_finished")
old_man_animation_palyer.play_backwards("fade") old_man_animation_palyer.play_backwards("fade")
yield(old_man_animation_palyer, "animation_finished") yield(old_man_animation_palyer, "animation_finished")
GameState.end_cutscene(GameState.States.NEW_GAME) GameState.set_state(GameState.States.NEW_GAME)
pass # Replace with function body. pass # Replace with function body.
func _process(delta: float) -> void:
if is_active_level:
if _player.position.x > 330:
$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)

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,12 @@
extends Level
func _ready() -> void:
$AmbiantLighting.change_light("NIGHT")
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

@ -1,10 +1,10 @@
[gd_scene load_steps=10 format=2] [gd_scene load_steps=10 format=2]
[ext_resource path="res://assets/SplashScreen/BLANK.png" type="Texture" id=1] [ext_resource path="res://src/Intro/Intro.gd" type="Script" id=1]
[ext_resource path="res://src/Intro/Intro.gd" type="Script" id=2] [ext_resource path="res://src/Menu/MainMenu.tscn" type="PackedScene" id=2]
[ext_resource path="res://assets/SplashScreen/SAGI.png" type="Texture" id=3] [ext_resource path="res://assets/SplashScreen/BLANK.png" type="Texture" id=3]
[ext_resource path="res://sound/SAGI.ogg" type="AudioStream" id=4] [ext_resource path="res://assets/SplashScreen/SAGI.png" type="Texture" id=4]
[ext_resource path="res://src/Menu/MainMenu.tscn" type="PackedScene" id=5] [ext_resource path="res://sound/SAGI.ogg" type="AudioStream" id=5]
[ext_resource path="res://assets/Tiles/background_0.png" type="Texture" id=6] [ext_resource path="res://assets/Tiles/background_0.png" type="Texture" id=6]
[ext_resource path="res://assets/SplashScreen/Title.png" type="Texture" id=7] [ext_resource path="res://assets/SplashScreen/Title.png" type="Texture" id=7]
[ext_resource path="res://assets/Items/torch_ligt_texture.png" type="Texture" id=8] [ext_resource path="res://assets/Items/torch_ligt_texture.png" type="Texture" id=8]
@ -140,30 +140,29 @@ tracks/9/keys = {
[node name="Intro" type="Node2D"] [node name="Intro" type="Node2D"]
pause_mode = 2 pause_mode = 2
script = ExtResource( 2 ) script = ExtResource( 1 )
next_scene = ExtResource( 5 ) next_scene = ExtResource( 2 )
[node name="AnimationPlayer" type="AnimationPlayer" parent="."] [node name="AnimationPlayer" type="AnimationPlayer" parent="."]
autoplay = "intro" autoplay = "intro"
anims/intro = SubResource( 1 ) anims/intro = SubResource( 1 )
[node name="BLANK" type="Sprite" parent="."] [node name="BLANK" type="Sprite" parent="."]
texture = ExtResource( 1 ) texture = ExtResource( 3 )
centered = false centered = false
[node name="SAGI" type="Sprite" parent="."] [node name="SAGI" type="Sprite" parent="."]
self_modulate = Color( 1, 1, 1, 0.5 ) self_modulate = Color( 1, 1, 1, 0.5 )
position = Vector2( 2, 0 ) texture = ExtResource( 4 )
texture = ExtResource( 3 )
centered = false centered = false
[node name="Light2D" type="Light2D" parent="SAGI"] [node name="Light2D" type="Light2D" parent="SAGI"]
position = Vector2( 239, 136 ) position = Vector2( 239, 136 )
texture = ExtResource( 3 ) texture = ExtResource( 4 )
texture_scale = 2.0 texture_scale = 2.0
[node name="SplashVoice" type="AudioStreamPlayer" parent="."] [node name="SplashVoice" type="AudioStreamPlayer" parent="."]
stream = ExtResource( 4 ) stream = ExtResource( 5 )
autoplay = true autoplay = true
[node name="Title" type="Node2D" parent="."] [node name="Title" type="Node2D" parent="."]

View file

@ -6,14 +6,13 @@ signal cutscene_finished
export var scene:PackedScene export var scene:PackedScene
var _main_camera_ref:Camera2D var _main_camera_ref:CameraGame
var _camera:Camera2D var _camera:CameraGame
var _started := false
var allow_skip := false
func start_scene(camera:Camera2D): func start_scene(camera:CameraGame = null):
var scene_inst = scene.instance()
add_child(scene_inst)
scene_inst.connect("tree_exited", self, "_on_scene_exited")
pass pass
func end_scene(): func end_scene():

View file

@ -1,17 +1,35 @@
extends Position2D extends Position2D
tool tool
export var node:PackedScene = null export var node:PackedScene = null
onready var player_ref:Player = get_tree().current_scene.get_node("Player") onready var player_ref:Player = get_parent().get_node("Player")
func _ready() -> void: func _ready() -> void:
if Engine.editor_hint:
_spawn() _spawn()
else:
player_ref.connect("died", self, "_on_Player_died")
func _exit_tree() -> void:
if not Engine.editor_hint:
player_ref.disconnect("died", self, "_on_Player_died")
despawn()
func _on_VisibilityNotifier2D_screen_entered() -> void: func _on_VisibilityNotifier2D_screen_entered() -> void:
if not Engine.editor_hint:
player_ref.connect("died", self, "_on_Player_died")
respawn() respawn()
func reset():
despawn()
respawn()
func despawn():
var current_node = get_node("node")
if current_node != null:
remove_child(current_node)
func respawn(): func respawn():
var current_node = get_node("node") var current_node = get_node("node")
if current_node == null and node != null: if current_node == null and node != null:
@ -20,6 +38,8 @@ func respawn():
pass pass
func _on_Player_died(): func _on_Player_died():
yield(get_tree().create_timer(.7), "timeout")
despawn()
if $VisibilityNotifier2D.is_on_screen(): if $VisibilityNotifier2D.is_on_screen():
respawn() respawn()

12
src/Scripts/WarpZone.gd Normal file
View file

@ -0,0 +1,12 @@
extends Area2D
class_name WarpZone
signal player_entered
export(int,-1, 3) var zone = -1;
export var is_exit:bool = true
func _on_body_entered(body:Node):
if body.name == "Player" and get_parent().is_active_level:
emit_signal("player_entered", is_exit, zone)

15
src/Scripts/WarpZone.tscn Normal file
View file

@ -0,0 +1,15 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://src/Scripts/WarpZone.gd" type="Script" id=1]
[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 16, 16 )
[node name="WarpZone" type="Area2D"]
collision_layer = 0
script = ExtResource( 1 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2( 0, -16 )
shape = SubResource( 1 )
[connection signal="body_entered" from="." to="." method="_on_body_entered"]

View file

@ -18,7 +18,7 @@ enum States{
var _SAVE_FILE_PATH = "user://data" var _SAVE_FILE_PATH = "user://data"
# Change key in release # Change key in release
var _ENCRYPTION_KEY = "fas3uyf076HJsiUDs24dfI9" var _ENCRYPTION_KEY = "fas3uyf076HJsiUDs24dfI9"
var is_first_run = false
var _SCENES := { var _SCENES := {
States.MAIN_MENU: "res://src/Menu/MainMenu.tscn", States.MAIN_MENU: "res://src/Menu/MainMenu.tscn",
States.NEW_GAME: "res://src/GameWorld/GameWorld.tscn", States.NEW_GAME: "res://src/GameWorld/GameWorld.tscn",
@ -66,7 +66,8 @@ var _state = States.INTRO
func _ready() -> void: func _ready() -> void:
load_data() load_data()
print(_data) for key in _data:
print("[%s]: %s" % [key, _data[key]])
func _physics_process(delta: float) -> void: func _physics_process(delta: float) -> void:
if _state == States.GAME: if _state == States.GAME:
@ -78,6 +79,7 @@ func load_data():
var e = data_file.open_encrypted_with_pass(_SAVE_FILE_PATH, File.READ, _ENCRYPTION_KEY) var e = data_file.open_encrypted_with_pass(_SAVE_FILE_PATH, File.READ, _ENCRYPTION_KEY)
if e != 0: if e != 0:
data_file.close() data_file.close()
is_first_run = true
save_data() save_data()
else: else:
var saved_data:Dictionary = data_file.get_var() var saved_data:Dictionary = data_file.get_var()
@ -93,8 +95,8 @@ func load_data():
func save_data(): func save_data():
var data_file = File.new() var data_file = File.new()
print(data_file.open_encrypted_with_pass(_SAVE_FILE_PATH, File.WRITE, _ENCRYPTION_KEY)) data_file.open_encrypted_with_pass(_SAVE_FILE_PATH, File.WRITE, _ENCRYPTION_KEY)
print(data_file.store_var(_data)) data_file.store_var(_data)
data_file.close() data_file.close()
pass pass
@ -110,10 +112,10 @@ func start_new_game(from_main_menu:bool=false, change_music:bool=true):
yield(self, "scene_changed") yield(self, "scene_changed")
# get_tree().change_scene_to(load(_SCENES[_state])) # get_tree().change_scene_to(load(_SCENES[_state]))
func start_cutscene():
_state = States.CUTSCENE func set_state(state:int = States.GAME):
func end_cutscene(state:int = States.GAME):
_state = state _state = state
func get_heigh_score(): func get_heigh_score():
return _data.heigh_score.duplicate() return _data.heigh_score.duplicate()
func get_statistics(): func get_statistics():
@ -137,16 +139,10 @@ func _change_scene(state:int,duration:float=1):
_state = state _state = state
emit_signal("scene_changed") emit_signal("scene_changed")
func player_died(player:Player): func player_died():
_run_data.deaths += 1 _run_data.deaths += 1
_data.statistics.deaths += 1 _data.statistics.deaths += 1
var prev_state = _state
_state = States.TRANSITIONING
Stage.fade_out(.8)
yield(Stage, "fade_finished")
Stage.fade_in(.8)
yield(Stage, "fade_finished")
_state = prev_state
func coin_collected(): func coin_collected():
_run_data.coins += 10 _run_data.coins += 10

View file

@ -14,5 +14,4 @@ color = Color( 0, 0, 0, 1 )
__meta__ = { __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false
} }
[connection signal="tween_completed" from="Tween" to="." method="_on_fade_finished"]
[connection signal="tween_completed" from="Tween" to="." method="_on_Tween_tween_completed"] [connection signal="tween_completed" from="Tween" to="." method="_on_Tween_tween_completed"]