🧱: Level 4 and 5 are done !

-- Plus lose & win screen
main alpha
Ervan Lefevre 2 years ago
parent 1adc44150b
commit 65369ec029
  1. 1
      nodes/npc_factory/npc_factory.gd
  2. 2
      nodes/npc_factory/npc_factory.tscn
  3. 27
      nodes/player/player.gd
  4. 1
      nodes/player/player.tscn
  5. 27
      nodes/triggers/level_trigger.gd
  6. 7
      nodes/triggers/level_trigger.tscn
  7. 11
      nodes/triggers/win_trigger.gd
  8. 8
      nodes/triggers/win_trigger.tscn
  9. 43
      scenes/lose_screen.tscn
  10. 81
      scenes/poc.tscn
  11. 43
      scenes/win_screen.tscn
  12. 2
      scripts/ia/fsm.gd

@ -9,6 +9,7 @@ var current_spawn_duration = 0
func _ready():
if !NPC_SCENE:
push_error("npc scene is null")
set_physics_process(false)
func _physics_process(delta):
current_spawn_duration += delta

@ -8,7 +8,7 @@
[node name="npc_factory" type="Node2D"]
script = ExtResource("1_p5cuf")
NPC_SCENE = ExtResource("2_exj6u")
SPAWN_DELAY = 2.0
SPAWN_DELAY = 8.0
[node name="factory_death" type="Area2D" parent="." groups=["factory_death"]]
monitoring = false

@ -2,9 +2,14 @@ extends CharacterBody2D
class_name Player
@export_file('*.tscn') var LOSE_SCREEN;
const SPEED = 100.0
const JUMP_VELOCITY = 200.0
const APNEA_DURATION = 10
const DURATION_BEFORE_LOSE_SCREEN = 2
const STATES= [
"climb",
@ -132,6 +137,8 @@ func climb_state(_delta):
func after_state(delta):
move_and_slide()
if is_dead():
return
if use_gravity[$fsm.current_state] == true:
handle_gravity(delta)
@ -221,15 +228,31 @@ func on_exit_swim_state():
sprite.modulate = Color(1,1,1)
func swim():
if is_dead():
return
$fsm.set_next_state("swim")
func unswim():
if is_dead():
return
$fsm.set_next_state("idle")
func die():
$fsm.set_next_state("die")
func is_dead():
return $fsm.current_state == "die"
func on_enter_die_state():
velocity = Vector2(0, -500)
velocity = Vector2(0, 0)
$shape.disabled = true
# $AnimationPlayer.play("die")
$oriented_container.rotation = 0
sprite.flip_v = true
func die_state(_delta):
prints("die_state", $fsm.state_duration)
if $fsm.state_duration > DURATION_BEFORE_LOSE_SCREEN:
get_tree().change_scene_to_file(LOSE_SCREEN)

@ -10,6 +10,7 @@ height = 24.0
[node name="player" type="CharacterBody2D"]
script = ExtResource("1_exx2i")
LOSE_SCREEN = "res://scenes/lose_screen.tscn"
[node name="fsm" type="Node2D" parent="." node_paths=PackedStringArray("root")]
script = ExtResource("2_ix1o4")

@ -0,0 +1,27 @@
extends Area2D
@export var KILL_ALL_NPCS = false
@export var LEVEL_MESSAGE : String = ''
@export var ENABLED_NODES : Array[Node] = []
@export var DISABLED_NODES : Array[Node] = []
# Called when the node enters the scene tree for the first time.
func _ready():
body_entered.connect(on_body_entered)
func on_body_entered(body):
if !body.is_in_group('player'):
return
if KILL_ALL_NPCS:
if body.is_in_group("npc"):
body.queue_free()
if LEVEL_MESSAGE:
# TODO
print(LEVEL_MESSAGE)
pass
for node in ENABLED_NODES:
node.set_physics_process(true)
for node in DISABLED_NODES:
node.set_physics_process(false)

@ -0,0 +1,7 @@
[gd_scene load_steps=2 format=3 uid="uid://cdq58egi0j65h"]
[ext_resource type="Script" path="res://nodes/triggers/level_trigger.gd" id="1_amwjw"]
[node name="level_trigger" type="Area2D"]
monitorable = false
script = ExtResource("1_amwjw")

@ -0,0 +1,11 @@
extends Area2D
@export_file('*.tscn') var WIN_SCENE;
# Called when the node enters the scene tree for the first time.
func _ready():
body_entered.connect(on_body_entered)
func on_body_entered(body):
if body.is_in_group('player'):
get_tree().change_scene_to_file(WIN_SCENE)

@ -0,0 +1,8 @@
[gd_scene load_steps=2 format=3 uid="uid://de7ehbowni47v"]
[ext_resource type="Script" path="res://nodes/triggers/win_trigger.gd" id="1_jk7wd"]
[node name="win_trigger" type="Area2D"]
monitorable = false
script = ExtResource("1_jk7wd")
WIN_SCENE = "res://scenes/win_screen.tscn"

@ -0,0 +1,43 @@
[gd_scene load_steps=3 format=3 uid="uid://ckt2twwgcgwtt"]
[ext_resource type="Script" path="res://scripts/ui/change_scene_button.gd" id="1_oyu1u"]
[ext_resource type="Script" path="res://scripts/ui/quit_button.gd" id="2_7spq8"]
[node name="lose_screen" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="Panel" type="Panel" parent="."]
layout_mode = 0
offset_right = 1920.0
offset_bottom = 1080.0
[node name="Label" type="Label" parent="Panel"]
layout_mode = 0
offset_right = 1912.0
offset_bottom = 376.0
text = "You lose"
horizontal_alignment = 1
vertical_alignment = 1
[node name="Button" type="Button" parent="Panel"]
layout_mode = 0
offset_left = 800.0
offset_top = 744.0
offset_right = 1144.0
offset_bottom = 840.0
text = "Play Again"
script = ExtResource("1_oyu1u")
TARGET_SCENE = "res://scenes/main_menu.tscn"
[node name="quit" type="Button" parent="Panel"]
offset_left = 629.0
offset_top = 875.0
offset_right = 1284.0
offset_bottom = 952.0
text = "Quit"
script = ExtResource("2_7spq8")

File diff suppressed because one or more lines are too long

@ -0,0 +1,43 @@
[gd_scene load_steps=3 format=3 uid="uid://tb03t1t5hcxs"]
[ext_resource type="Script" path="res://scripts/ui/change_scene_button.gd" id="1_ajo3i"]
[ext_resource type="Script" path="res://scripts/ui/quit_button.gd" id="2_6iycq"]
[node name="win_screen" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="Panel" type="Panel" parent="."]
layout_mode = 0
offset_right = 1920.0
offset_bottom = 1080.0
[node name="Label" type="Label" parent="Panel"]
layout_mode = 0
offset_right = 1912.0
offset_bottom = 376.0
text = "You won"
horizontal_alignment = 1
vertical_alignment = 1
[node name="Button" type="Button" parent="Panel"]
layout_mode = 0
offset_left = 800.0
offset_top = 744.0
offset_right = 1144.0
offset_bottom = 840.0
text = "Play Again"
script = ExtResource("1_ajo3i")
TARGET_SCENE = "res://scenes/main_menu.tscn"
[node name="quit" type="Button" parent="Panel"]
offset_left = 629.0
offset_top = 875.0
offset_right = 1284.0
offset_bottom = 952.0
text = "Quit"
script = ExtResource("2_6iycq")

@ -41,7 +41,7 @@ func _transition():
previous_state = current_state
current_state = next_state
next_state = null
print(self.name + " transitioning to " + current_state)
print(get_parent().name + " transitioning to " + current_state)
if previous_state:
var on_exit_state_method = "on_exit_" + previous_state + "_state"

Loading…
Cancel
Save