Initial commit

This commit is contained in:
Crizomb 2024-11-14 13:58:15 +01:00
commit 1514fe991b
675 changed files with 6030 additions and 0 deletions

78
scripts/box.gd Normal file
View file

@ -0,0 +1,78 @@
extends StaticBody2D;
@onready var RayCastRight : RayCast2D = $RayCastRight;
@onready var RayCastDown : RayCast2D = $RayCastDown;
@onready var RayCastUp : RayCast2D = $RayCastUp;
@onready var RayCastLeft : RayCast2D = $RayCastLeft;
func go_right() -> bool:
var can_move := true;
if RayCastRight.is_colliding():
var colliding : Object = RayCastRight.get_collider();
if colliding.is_in_group("box"):
can_move = colliding.go_right();
else:
can_move = false;
if can_move:
position.x += 16;
return can_move;
func go_left() -> bool:
var can_move := true;
if RayCastLeft.is_colliding():
var colliding : Object = RayCastLeft.get_collider();
if colliding.is_in_group("box"):
can_move = colliding.go_left();
else:
can_move = false;
if can_move:
position.x -= 16;
return can_move;
func go_up() -> bool:
var can_move := true;
if RayCastUp.is_colliding():
var colliding : Object = RayCastUp.get_collider();
if colliding.is_in_group("box"):
can_move = colliding.go_up();
else:
can_move = false;
if can_move:
position.y -= 16;
return can_move;
func go_down() -> bool:
var can_move := true;
if RayCastDown.is_colliding():
var colliding : Object = RayCastDown.get_collider();
if colliding.is_in_group("box"):
can_move = colliding.go_down();
else:
can_move = false;
if can_move:
position.y += 16;
return can_move;
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass

19
scripts/button.gd Normal file
View file

@ -0,0 +1,19 @@
extends Area2D
@export var Door : StaticBody2D;
func _on_area_entered(area: Area2D) -> void:
Door.get_node("CollisionShape2D").set_deferred("disabled", true);
Door.get_node("SpriteYes").visible = true;
Door.get_node("SpriteNo").visible = false;
func _on_area_exited(area: Area2D) -> void:
Door.get_node("CollisionShape2D").set_deferred("disabled", false);
Door.get_node("SpriteYes").visible = false;
Door.get_node("SpriteNo").visible = true;

59
scripts/character.gd Normal file
View file

@ -0,0 +1,59 @@
extends Area2D
class_name Character
signal has_moved(direction : Globals.Direction)
@onready var RayCastRight : RayCast2D = $RayCastRight;
@onready var RayCastDown : RayCast2D = $RayCastDown;
@onready var RayCastUp : RayCast2D = $RayCastUp;
@onready var RayCastLeft : RayCast2D = $RayCastLeft;
var TileSize : int = 16;
func move(direction: Globals.Direction) -> bool:
var should_emit := false;
match direction:
Globals.Direction.RIGHT:
var collider : Object = RayCastRight.get_collider()
if !collider or (collider.is_in_group("box") and collider.go_right()):
position.x += TileSize
should_emit = true;
Globals.Direction.LEFT:
var collider : Object = RayCastLeft.get_collider()
if !collider or (collider.is_in_group("box") and collider.go_left()):
position.x -= TileSize
should_emit = true;
Globals.Direction.UP:
var collider : Object = RayCastUp.get_collider()
if !collider or (collider.is_in_group("box") and collider.go_up()):
position.y -= TileSize
should_emit = true;
Globals.Direction.DOWN:
var collider : Object = RayCastDown.get_collider()
if !collider or (collider.is_in_group("box") and collider.go_down()):
position.y += TileSize
should_emit = true;
Globals.Direction.NONE:
pass
_:
print("WTTFF");
print(direction);
if should_emit:
emit_signal("has_moved", direction);
return should_emit;

19
scripts/game_manager.gd Normal file
View file

@ -0,0 +1,19 @@
extends Node
@export
var levels = [
"res://scenes/level_0.tscn",
"res://scenes/level_1.tscn",
"res://scenes/level_2.tscn",
"res://scenes/level_3.tscn",
"res://scenes/final.tscn"
]
var current_level : int = 0;
func next_level() -> void:
current_level += 1;
assert(current_level < levels.size(), "Bro there is no next level, pls stop")
get_tree().change_scene_to_file(levels[current_level]);

3
scripts/globals.gd Normal file
View file

@ -0,0 +1,3 @@
extends Node
enum Direction {LEFT, RIGHT, UP, DOWN, NONE};

72
scripts/loop.gd Normal file
View file

@ -0,0 +1,72 @@
extends Area2D
class_name Loop;
var entered_count := 0;
var target_character : Character;
var shadow_resource := load("res://objects/shadow.tscn");
var shadow_created : Shadow;
@onready
var count_name = {$SpriteOff : 0, $SpriteRecording : 1, $SpriteOn : 2};
var move_list : Array[Globals.Direction];
var is_recording := false;
var is_playing := false;
var is_off := true;
var shadow_exist := false;
func _process(delta: float) -> void:
pass
func _on_area_entered(area: Area2D) -> void:
if area == shadow_created:
return;
entered_count += 1;
entered_count %= 3;
is_recording = entered_count == 1;
is_playing = entered_count == 2;
is_off = entered_count == 0;
if is_playing and !shadow_created:
shadow_created = shadow_resource.instantiate();
shadow_created.loop_origin = self;
shadow_created.position = self.position;
get_tree().current_scene.add_child(shadow_created);
if is_off:
shadow_created.queue_free();
shadow_created = null;
move_list.clear()
connect_target_character(area)
handle_visibility()
func connect_target_character(area: Area2D):
if area is Character and !target_character:
target_character = area
target_character.has_moved.connect(_on_target_moved);
print(target_character.has_moved.get_connections());
func handle_visibility():
for name in count_name:
if count_name[name] == entered_count:
name.visible = true;
else:
name.visible = false;
func _on_target_moved(direction: Globals.Direction):
if is_recording:
move_list.push_back(direction)
print(move_list)

44
scripts/player.gd Normal file
View file

@ -0,0 +1,44 @@
extends Character
class_name PlayerHEHEHE;
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
print(get_tree().root);
pass
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
other_input();
move(get_direction_input())
func get_direction_input() -> Globals.Direction:
var direction : Globals.Direction;
if Input.is_action_just_pressed("GoRight"):
direction = Globals.Direction.RIGHT;
elif Input.is_action_just_pressed("GoDown"):
direction = Globals.Direction.DOWN;
elif Input.is_action_just_pressed("GoLeft"):
direction = Globals.Direction.LEFT;
elif Input.is_action_just_pressed("GoUp"):
direction = Globals.Direction.UP;
else:
direction = Globals.Direction.NONE;
return direction;
func other_input() -> void:
if Input.is_action_just_pressed("Replay"):
get_tree().reload_current_scene()
func _on_end_area_entered(area: Area2D) -> void:
GameManager.next_level();

24
scripts/shadow.gd Normal file
View file

@ -0,0 +1,24 @@
extends Character
class_name Shadow;
var loop_origin : Loop;
var move_count := 0;
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
var player : Character = $"../Player";
player.has_moved.connect(_on_player_move);
func get_direction_input() -> Globals.Direction:
var result := loop_origin.move_list[move_count]
print(result);
return result;
func _on_player_move(direction: Globals.Direction):
print("MOOOOOOVE")
if move(get_direction_input()):
move_count += 1
move_count %= loop_origin.move_list.size();