Compare commits
0
Commits
No files matched your search
@@ -1,19 +1,22 @@
|
|||||||
extends Node
|
extends Node
|
||||||
|
|
||||||
# Main scene
|
|
||||||
var mainSceneInstance
|
|
||||||
|
|
||||||
# Screen
|
|
||||||
var screen_size = Vector2(1920.0, 1080.0) # Default screen size (this is a float for some reason)
|
var screen_size = Vector2(1920.0, 1080.0) # Default screen size (this is a float for some reason)
|
||||||
var viewport_size
|
var viewport_size
|
||||||
@onready var extent: Rect2 = get_viewport().get_visible_rect()
|
@onready var extent: Rect2 = get_viewport().get_visible_rect()
|
||||||
|
|
||||||
|
# Main menu & game spawning
|
||||||
|
@onready
|
||||||
|
var mainMenuScene = preload("res://main_menu.tscn").instantiate()
|
||||||
|
@onready
|
||||||
|
var gameScene = preload("res://molecular/molecular_stage.tscn").instantiate()
|
||||||
|
|
||||||
# utils.
|
# utils.
|
||||||
var rng = RandomNumberGenerator.new()
|
var rng = RandomNumberGenerator.new()
|
||||||
var eps: float = 1e-4
|
var eps: float = 1e-4
|
||||||
|
|
||||||
# managers
|
# managers
|
||||||
var foodManager: FoodManager2D
|
@onready
|
||||||
|
var foodManager = gameScene.get_node("FoodManager")
|
||||||
|
|
||||||
# A world "current"
|
# A world "current"
|
||||||
# polar
|
# polar
|
||||||
@@ -30,26 +33,24 @@ var t: float = 0.0
|
|||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
# Start game
|
|
||||||
mainSceneInstance = get_tree().root.get_child(-1)
|
|
||||||
|
|
||||||
# Create viewport
|
# Create viewport
|
||||||
viewport_size = get_viewport().get_visible_rect().size
|
viewport_size = get_viewport().get_visible_rect().size
|
||||||
|
|
||||||
|
# Create game (main menu)
|
||||||
|
add_child(mainMenuScene)
|
||||||
|
|
||||||
# initial world current
|
# initial world current
|
||||||
get_new_flow()
|
get_new_flow()
|
||||||
|
|
||||||
|
|
||||||
func _physics_process(delta: float) -> void:
|
func _physics_process(delta: float) -> void:
|
||||||
t += delta
|
t += delta
|
||||||
|
|
||||||
# Flow current change
|
# Flow current change
|
||||||
if abs(fmod(t, flowT)) < eps:
|
if abs(fmod(t, flowT)) < eps:
|
||||||
get_new_flow()
|
get_new_flow()
|
||||||
|
|
||||||
func switch_scene(name:String) -> void:
|
func start_game() -> void:
|
||||||
if name == "respawn":
|
add_child(gameScene)
|
||||||
mainSceneInstance.go_to_respawn_scene()
|
|
||||||
|
|
||||||
# TODO: This needs to be called from a script inheriting a CharacterBody2D (e.g. the player)
|
# TODO: This needs to be called from a script inheriting a CharacterBody2D (e.g. the player)
|
||||||
# Alternative would be to pass the player reference to this script (which might be better?)
|
# Alternative would be to pass the player reference to this script (which might be better?)
|
||||||
@@ -66,14 +67,15 @@ func get_boundaried_position(position):
|
|||||||
position.x = wrapf(position.x, 0, screen_size.x)
|
position.x = wrapf(position.x, 0, screen_size.x)
|
||||||
position.y = wrapf(position.y, 0, screen_size.y)
|
position.y = wrapf(position.y, 0, screen_size.y)
|
||||||
return position
|
return position
|
||||||
|
|
||||||
func get_new_flow():
|
func get_new_flow():
|
||||||
flow_dir = rng.randf()*2*PI
|
flow_dir = rng.randf()*2*PI
|
||||||
flow_mag = rng.randf()
|
flow_mag = rng.randf()
|
||||||
|
|
||||||
flow_x = flow_mag * cos(flow_dir)
|
flow_x = flow_mag * cos(flow_dir)
|
||||||
flow_y = flow_mag * sin(flow_dir)
|
flow_y = flow_mag * sin(flow_dir)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func calc_distance(one, two) -> float:
|
func calc_distance(one, two) -> float:
|
||||||
var candidate = one.distance_to(two)
|
var candidate = one.distance_to(two)
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
[gd_scene format=3 uid="uid://bsrxph8oa7uuj"]
|
|
||||||
|
|
||||||
[node name="Main" type="Node" unique_id=1994328839]
|
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
extends Control
|
||||||
|
|
||||||
|
|
||||||
|
func _on_play_button_pressed() -> void:
|
||||||
|
print("Starting game by pressing button...")
|
||||||
|
GameManager.start_game()
|
||||||
|
self.queue_free()
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
uid://dxc66bci2ivrj
|
||||||
@@ -1,14 +1,6 @@
|
|||||||
[gd_scene format=3 uid="uid://drgv154ei1vrl"]
|
[gd_scene format=3 uid="uid://drgv154ei1vrl"]
|
||||||
|
|
||||||
[sub_resource type="GDScript" id="GDScript_rhts7"]
|
[ext_resource type="Script" uid="uid://dxc66bci2ivrj" path="res://main_menu.gd" id="1_06t4h"]
|
||||||
script/source = "extends Control
|
|
||||||
|
|
||||||
|
|
||||||
func _on_play_button_pressed() -> void:
|
|
||||||
print(\"Starting game by pressing button...\")
|
|
||||||
GameManager.start_game()
|
|
||||||
self.queue_free()
|
|
||||||
"
|
|
||||||
|
|
||||||
[sub_resource type="LabelSettings" id="LabelSettings_rhts7"]
|
[sub_resource type="LabelSettings" id="LabelSettings_rhts7"]
|
||||||
font_size = 64
|
font_size = 64
|
||||||
@@ -20,7 +12,7 @@ anchor_right = 1.0
|
|||||||
anchor_bottom = 1.0
|
anchor_bottom = 1.0
|
||||||
grow_horizontal = 2
|
grow_horizontal = 2
|
||||||
grow_vertical = 2
|
grow_vertical = 2
|
||||||
script = SubResource("GDScript_rhts7")
|
script = ExtResource("1_06t4h")
|
||||||
|
|
||||||
[node name="PlayButton" type="Button" parent="." unique_id=1831335357]
|
[node name="PlayButton" type="Button" parent="." unique_id=1831335357]
|
||||||
layout_mode = 1
|
layout_mode = 1
|
||||||
@@ -50,3 +42,5 @@ text = "The Main Menu"
|
|||||||
label_settings = SubResource("LabelSettings_rhts7")
|
label_settings = SubResource("LabelSettings_rhts7")
|
||||||
horizontal_alignment = 1
|
horizontal_alignment = 1
|
||||||
vertical_alignment = 1
|
vertical_alignment = 1
|
||||||
|
|
||||||
|
[connection signal="pressed" from="PlayButton" to="." method="_on_play_button_pressed"]
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
extends Node
|
|
||||||
|
|
||||||
# Main menu & game spawning
|
|
||||||
@onready
|
|
||||||
var mainMenuScene = preload("res://main_menu.tscn")
|
|
||||||
var mainMenuSceneInstance: Node
|
|
||||||
@onready
|
|
||||||
var gameScene = preload("res://molecular/molecular_stage.tscn")
|
|
||||||
var gameSceneInstance: Node
|
|
||||||
@onready
|
|
||||||
var respawnScene = preload("res://respawn_menu.tscn")
|
|
||||||
var respawnSceneInstance: Node
|
|
||||||
# Currently active scene (instance)
|
|
||||||
var currentSceneInstance:Node
|
|
||||||
|
|
||||||
# UI effects
|
|
||||||
var fadeEffect: CanvasLayer
|
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
|
||||||
# Instantiate effects
|
|
||||||
fadeEffect = $UI/Fade
|
|
||||||
fadeEffect.visible = false
|
|
||||||
|
|
||||||
# Create game (main menu)
|
|
||||||
print("Creating Main menu...")
|
|
||||||
mainMenuSceneInstance = mainMenuScene.instantiate()
|
|
||||||
currentSceneInstance = mainMenuSceneInstance
|
|
||||||
add_child(currentSceneInstance)
|
|
||||||
|
|
||||||
# Link MainMenu button to start_game
|
|
||||||
print("Linking Play button...")
|
|
||||||
mainMenuSceneInstance.get_node("PlayButton").connect("pressed", start_game)
|
|
||||||
|
|
||||||
|
|
||||||
func start_game() -> void:
|
|
||||||
print("Starting game...")
|
|
||||||
|
|
||||||
# Instatiate
|
|
||||||
currentSceneInstance.queue_free()
|
|
||||||
gameSceneInstance = gameScene.instantiate()
|
|
||||||
currentSceneInstance = gameSceneInstance
|
|
||||||
add_child(currentSceneInstance)
|
|
||||||
|
|
||||||
# Populate GameManager with game scene
|
|
||||||
GameManager.foodManager = gameSceneInstance.get_node("FoodManager")
|
|
||||||
|
|
||||||
|
|
||||||
func go_to_respawn_scene() -> void:
|
|
||||||
fadeEffect.visible = true
|
|
||||||
await fadeEffect.fade(1.0, 1.5).finished
|
|
||||||
print("Switching to Respawn scene.")
|
|
||||||
currentSceneInstance.queue_free()
|
|
||||||
|
|
||||||
respawnSceneInstance = respawnScene.instantiate()
|
|
||||||
respawnSceneInstance.get_node("RespawnButton").connect("pressed", start_game)
|
|
||||||
currentSceneInstance = respawnSceneInstance
|
|
||||||
|
|
||||||
add_child(currentSceneInstance)
|
|
||||||
await fadeEffect.fade(0.0, 1.5).finished
|
|
||||||
fadeEffect.visible = false
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
uid://wiv0plsu04s
|
|
||||||
@@ -1,11 +1,6 @@
|
|||||||
[gd_scene format=3 uid="uid://b8gt8os2m28lv"]
|
[gd_scene format=3 uid="uid://b8gt8os2m28lv"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://wiv0plsu04s" path="res://main_scene.gd" id="1_2c62f"]
|
[ext_resource type="Script" uid="uid://vsbibc5fanou" path="res://game_manager.gd" id="1_0f027"]
|
||||||
[ext_resource type="PackedScene" uid="uid://3eg3a8ceom4l" path="res://molecular/fade.tscn" id="2_2c62f"]
|
|
||||||
|
|
||||||
[node name="MainScene" type="Node" unique_id=1897047571]
|
[node name="MainScene" type="Node" unique_id=1897047571]
|
||||||
script = ExtResource("1_2c62f")
|
script = ExtResource("1_0f027")
|
||||||
|
|
||||||
[node name="UI" type="Node2D" parent="." unique_id=1032224503]
|
|
||||||
|
|
||||||
[node name="Fade" parent="UI" unique_id=853660457 instance=ExtResource("2_2c62f")]
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
extends CanvasLayer
|
|
||||||
|
|
||||||
@onready var color_rect: ColorRect = $ColorRect
|
|
||||||
|
|
||||||
func _ready() -> void:
|
|
||||||
color_rect.color.a = 0
|
|
||||||
|
|
||||||
func fade(target_alpha: float, duration: float):
|
|
||||||
var tween = create_tween()
|
|
||||||
tween.tween_property(color_rect, "color:a", target_alpha, duration)
|
|
||||||
return tween
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
uid://bwf56ehqo32gr
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
[gd_scene format=3 uid="uid://3eg3a8ceom4l"]
|
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://bwf56ehqo32gr" path="res://molecular/fade.gd" id="1_rx8rx"]
|
|
||||||
|
|
||||||
[node name="Fade" type="CanvasLayer" unique_id=853660457]
|
|
||||||
script = ExtResource("1_rx8rx")
|
|
||||||
|
|
||||||
[node name="ColorRect" type="ColorRect" parent="." unique_id=1320853444]
|
|
||||||
anchors_preset = 15
|
|
||||||
anchor_right = 1.0
|
|
||||||
anchor_bottom = 1.0
|
|
||||||
grow_horizontal = 2
|
|
||||||
grow_vertical = 2
|
|
||||||
color = Color(0, 0, 0, 0)
|
|
||||||
@@ -18,7 +18,6 @@ var desired_rotation: float = 0
|
|||||||
var resources: int = 0
|
var resources: int = 0
|
||||||
|
|
||||||
# Health
|
# Health
|
||||||
var maxHealth: int = 100
|
|
||||||
var healthPoints: int = 100
|
var healthPoints: int = 100
|
||||||
var isAlive: bool = true
|
var isAlive: bool = true
|
||||||
@onready var invulnerable_cooldown_timer: Timer = $InvulnerableCooldownTimer
|
@onready var invulnerable_cooldown_timer: Timer = $InvulnerableCooldownTimer
|
||||||
@@ -31,8 +30,6 @@ func _ready() -> void:
|
|||||||
attack_area.monitoring = false # no collision until attacking TODO: Thing about being attacked
|
attack_area.monitoring = false # no collision until attacking TODO: Thing about being attacked
|
||||||
attack_timer.wait_time = attack_duration
|
attack_timer.wait_time = attack_duration
|
||||||
attack_cooldown_timer.wait_time = attack_cooldown_duration
|
attack_cooldown_timer.wait_time = attack_cooldown_duration
|
||||||
|
|
||||||
sprite.play("default")
|
|
||||||
|
|
||||||
|
|
||||||
func _process(delta):
|
func _process(delta):
|
||||||
@@ -100,25 +97,10 @@ func handle_damage(dmg: int, src: Node) -> void:
|
|||||||
healthPoints -= dmg
|
healthPoints -= dmg
|
||||||
hasiframes = true
|
hasiframes = true
|
||||||
invulnerable_cooldown_timer.start()
|
invulnerable_cooldown_timer.start()
|
||||||
if isAlive and healthPoints <= 0:
|
if healthPoints <= 0:
|
||||||
die()
|
print("Player died. Respawn button not implemented.")
|
||||||
|
isAlive = false
|
||||||
|
|
||||||
func collect_resource(damnt: int) -> void:
|
func collect_resource(damnt: int) -> void:
|
||||||
resources += damnt
|
resources += damnt
|
||||||
print("Resource collected! Total: ", resources)
|
print("Resource collected! Total: ", resources)
|
||||||
|
|
||||||
func die() -> void:
|
|
||||||
print("Player died.")
|
|
||||||
isAlive = false
|
|
||||||
GameManager.switch_scene("respawn")
|
|
||||||
|
|
||||||
# TODO: Is this used or should it be removed? (currently unused)
|
|
||||||
func respawm() -> void:
|
|
||||||
healthPoints = maxHealth
|
|
||||||
isAlive = true
|
|
||||||
hasiframes = true
|
|
||||||
attack_cooldown_timer.start()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -43,7 +43,6 @@ script = ExtResource("1_0ix7k")
|
|||||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="." unique_id=1745800698]
|
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="." unique_id=1745800698]
|
||||||
visibility_layer = 2
|
visibility_layer = 2
|
||||||
sprite_frames = SubResource("SpriteFrames_onrkg")
|
sprite_frames = SubResource("SpriteFrames_onrkg")
|
||||||
animation = &"attacking"
|
|
||||||
|
|
||||||
[node name="AttackArea" type="Area2D" parent="." unique_id=187975387]
|
[node name="AttackArea" type="Area2D" parent="." unique_id=187975387]
|
||||||
position = Vector2(0, 56)
|
position = Vector2(0, 56)
|
||||||
|
|||||||
@@ -1,56 +0,0 @@
|
|||||||
[gd_scene format=3 uid="uid://dg72ceo3c1u3q"]
|
|
||||||
|
|
||||||
[sub_resource type="LabelSettings" id="LabelSettings_3i7aq"]
|
|
||||||
font_size = 64
|
|
||||||
|
|
||||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_3i7aq"]
|
|
||||||
content_margin_left = 4.0
|
|
||||||
content_margin_top = 4.0
|
|
||||||
content_margin_right = 4.0
|
|
||||||
content_margin_bottom = 4.0
|
|
||||||
bg_color = Color(0, 0, 0, 1)
|
|
||||||
corner_radius_top_left = 3
|
|
||||||
corner_radius_top_right = 3
|
|
||||||
corner_radius_bottom_right = 3
|
|
||||||
corner_radius_bottom_left = 3
|
|
||||||
corner_detail = 5
|
|
||||||
|
|
||||||
[node name="RespawnMenu" type="Control" unique_id=1895105935]
|
|
||||||
layout_mode = 3
|
|
||||||
anchors_preset = 15
|
|
||||||
anchor_right = 1.0
|
|
||||||
anchor_bottom = 1.0
|
|
||||||
grow_horizontal = 2
|
|
||||||
grow_vertical = 2
|
|
||||||
|
|
||||||
[node name="YouDiedLabel" type="Label" parent="." unique_id=1672619325]
|
|
||||||
layout_mode = 1
|
|
||||||
anchors_preset = 8
|
|
||||||
anchor_left = 0.5
|
|
||||||
anchor_top = 0.5
|
|
||||||
anchor_right = 0.5
|
|
||||||
anchor_bottom = 0.5
|
|
||||||
offset_left = -66.0
|
|
||||||
offset_top = -146.695
|
|
||||||
offset_right = 66.0
|
|
||||||
offset_bottom = -123.69501
|
|
||||||
grow_horizontal = 2
|
|
||||||
grow_vertical = 2
|
|
||||||
text = "Oh, no! You died!"
|
|
||||||
label_settings = SubResource("LabelSettings_3i7aq")
|
|
||||||
|
|
||||||
[node name="RespawnButton" type="Button" parent="." unique_id=1508413909]
|
|
||||||
layout_mode = 1
|
|
||||||
anchors_preset = 8
|
|
||||||
anchor_left = 0.5
|
|
||||||
anchor_top = 0.5
|
|
||||||
anchor_right = 0.5
|
|
||||||
anchor_bottom = 0.5
|
|
||||||
offset_left = -160.0
|
|
||||||
offset_top = -63.0
|
|
||||||
offset_right = 162.0
|
|
||||||
offset_bottom = -5.0
|
|
||||||
grow_horizontal = 2
|
|
||||||
grow_vertical = 2
|
|
||||||
theme_override_styles/normal = SubResource("StyleBoxFlat_3i7aq")
|
|
||||||
text = "Respawn"
|
|
||||||