docs: added comments

This commit is contained in:
Topvennie 2024-04-18 15:53:19 +02:00
parent af4cdd6a3a
commit 6e62c50930
11 changed files with 119 additions and 81 deletions

View file

@ -19,7 +19,7 @@ dock_filesystem_split=0
dock_filesystem_display_mode=0
dock_filesystem_file_sort=0
dock_filesystem_file_list_display_mode=1
dock_filesystem_selected_paths=PackedStringArray("res://")
dock_filesystem_selected_paths=PackedStringArray("res://Player.tscn")
dock_filesystem_uncollapsed_paths=PackedStringArray("Favorites", "res://")
dock_3="Scene,Import"
dock_4="FileSystem"
@ -27,17 +27,17 @@ dock_5="Inspector,Node,History"
[EditorNode]
open_scenes=PackedStringArray("res://Main.tscn")
current_scene="res://Main.tscn"
open_scenes=PackedStringArray("res://Main.tscn", "res://Player.tscn")
current_scene="res://Player.tscn"
center_split_offset=0
selected_default_debugger_tab_idx=0
selected_main_editor_idx=2
selected_bottom_panel_item=1
selected_bottom_panel_item=0
[ScriptEditor]
open_scripts=["res://Camera2D.gd", "res://Player.gd"]
selected_script="res://Camera2D.gd"
open_scripts=["res://Main.gd", "res://Player.gd", "res://Tower.gd", "res://UI.gd"]
selected_script="res://Player.gd"
open_help=[]
script_split_offset=70
list_split_offset=0

View file

@ -1,14 +1,14 @@
ea4bc82a6ad023ab7ee23ee620429895
::res://::1713198935
Camera2D.gd::GDScript::-1::1713198916::0::1::::<>Node<>::
default_env.tres::Environment::-1::1713198916::0::1::::<><>::
icon.png::CompressedTexture2D::224231617940432086::1713198714::1713198936::1::::<><>::
Main.tscn::PackedScene::-1::1713198916::0::1::::<><>::res://Camera2D.gd<>res://Player.tscn<>res://res/sprites.png<>res://UI.tscn
Player.gd::GDScript::-1::1713198916::0::1::::<>Area2D<>::
Player.tscn::PackedScene::-1::1713198916::0::1::::<><>::res://Player.gd<>res://res/sprites.png
Tower.gd::GDScript::-1::1713198916::0::1::::<>Node2D<>::
Tower.tscn::PackedScene::-1::1713198916::0::1::::<><>::res://Tower.gd<>res://res/sprites.png
UI.gd::GDScript::-1::1713198916::0::1::::<>CanvasLayer<>::
UI.tscn::PackedScene::-1::1713198916::0::1::::<><>::res://UI.gd
::res://res/::1713198714
sprites.png::CompressedTexture2D::1870513174833790166::1713198714::1713198936::1::::<><>::
::res://::1713445642
default_env.tres::Environment::2706437284641004306::1713444527::0::1::::<><>::
icon.png::CompressedTexture2D::224231617940432086::1713444527::1713444527::1::::<><>::
Main.gd::GDScript::-1::1713444527::0::1::::<>Node<>::
Main.tscn::PackedScene::798496173305188108::1713445635::0::1::::<><>::res://Main.gd<>res://Player.tscn<>uid://1wdcw8ne7j5w::::res://res/sprites.png<>res://UI.tscn
Player.gd::GDScript::-1::1713444527::0::1::::<>Area2D<>::
Player.tscn::PackedScene::-1::1713444527::0::1::::<><>::res://Player.gd<>res://res/sprites.png
Tower.gd::GDScript::-1::1713444527::0::1::::<>Node2D<>::
Tower.tscn::PackedScene::-1::1713444527::0::1::::<><>::res://Tower.gd<>res://res/sprites.png
UI.gd::GDScript::-1::1713444527::0::1::::<>CanvasLayer<>::
UI.tscn::PackedScene::-1::1713444527::0::1::::<><>::res://UI.gd
::res://res/::1713444527
sprites.png::CompressedTexture2D::1870513174833790166::1713444527::1713444527::1::::<><>::

View file

@ -1,4 +1,6 @@
res://default_env.tres
res://Main.tscn
res://Camera2D.gd
res://Player.tscn
res://Player.gd
res://Tower.gd
res://Main.gd

View file

@ -1,6 +1,6 @@
[editor_metadata]
executable_path="C:/Users/Gebruiker/Desktop/Godot_v4.2.1-stable_win64.exe/Godot_v4.2.1-stable_win64.exe"
executable_path="/home/vincent/Documents/programming/godot/Godot_v4.2.1-stable_linux.x86_64"
[debug_options]
@ -9,8 +9,8 @@ run_reload_scripts=true
[recent_files]
scenes=["res://Main.tscn"]
scripts=["res://Player.gd", "res://Camera2D.gd"]
scenes=["res://Player.tscn", "res://Main.tscn"]
scripts=["res://UI.gd", "res://Main.gd", "res://Tower.gd", "res://Player.gd", "res://Camera2D.gd"]
[linked_properties]
@ -18,3 +18,4 @@ Node2D:scale=true
Sprite2D:scale=true
ParallaxLayer:motion_scale=true
ParallaxLayer:scale=true
Area2D:scale=true

View file

@ -1,26 +1,54 @@
[res://Camera2D.gd]
state={
"bookmarks": PackedInt32Array(),
"breakpoints": PackedInt32Array(),
"column": 12,
"folded_lines": Array[int]([]),
"h_scroll_position": 0,
"row": 41,
"scroll_position": 0.0,
"selection": false,
"syntax_highlighter": "GDScript"
}
[res://Player.gd]
state={
"bookmarks": PackedInt32Array(),
"breakpoints": PackedInt32Array(),
"column": 46,
"column": 1,
"folded_lines": Array[int]([]),
"h_scroll_position": 0,
"row": 8,
"row": 68,
"scroll_position": 25.0,
"selection": false,
"syntax_highlighter": "GDScript"
}
[res://Tower.gd]
state={
"bookmarks": PackedInt32Array(),
"breakpoints": PackedInt32Array(),
"column": 0,
"folded_lines": Array[int]([]),
"h_scroll_position": 0,
"row": 16,
"scroll_position": 0.0,
"selection": false,
"syntax_highlighter": "GDScript"
}
[res://Main.gd]
state={
"bookmarks": PackedInt32Array(),
"breakpoints": PackedInt32Array(),
"column": 0,
"folded_lines": Array[int]([]),
"h_scroll_position": 0,
"row": 25,
"scroll_position": 0.0,
"selection": false,
"syntax_highlighter": "GDScript"
}
[res://UI.gd]
state={
"bookmarks": PackedInt32Array(),
"breakpoints": PackedInt32Array(),
"column": 0,
"folded_lines": Array[int]([]),
"h_scroll_position": 0,
"row": 19,
"scroll_position": 0.0,
"selection": false,
"syntax_highlighter": "GDScript"

Binary file not shown.

View file

@ -1,17 +1,16 @@
extends Node
@export var Tower = preload("res://Tower.tscn");
@onready var screen_size = Vector2(ProjectSettings.get("display/window/size/viewport_width"), ProjectSettings.get("display/window/size/viewport_height"))
@export var tower_density = 250
signal spawn
var last_built = 300
# Tower variables
@export var Tower = preload("res://Tower.tscn"); # Tower scene
@export var tower_density = 250 # How often a tower should be added
var last_built = 300 # Helper variable to adhear the tower density
var towers = []
signal spawn # A tower is spawned in
# Build a single tower
func build_tower():
var tower = Tower.instantiate()
tower.connect("exit", Callable(self, "_on_Tower_exit"))
@ -25,6 +24,7 @@ func build_tower():
add_child(tower)
last_built += tower_density
# Build all towers
func build_all_towers():
get_tree().call_group("tower", "queue_free")
last_built = 300
@ -32,6 +32,7 @@ func build_all_towers():
build_tower()
func _ready():
# Connect signals
var ui = get_node("UI")
var player = get_node("Player")
player.connect("start", Callable(self, "build_all_towers"))

View file

@ -1,7 +1,7 @@
[gd_scene load_steps=6 format=3 uid="uid://lm2d6kimhksi"]
[ext_resource type="Script" path="res://Camera2D.gd" id="1"]
[ext_resource type="PackedScene" path="res://Player.tscn" id="2"]
[ext_resource type="Script" path="res://Main.gd" id="1"]
[ext_resource type="PackedScene" uid="uid://bkppr8vsso41l" path="res://Player.tscn" id="2"]
[ext_resource type="Texture2D" uid="uid://1wdcw8ne7j5w" path="res://res/sprites.png" id="3"]
[ext_resource type="PackedScene" path="res://UI.tscn" id="4"]

View file

@ -25,9 +25,9 @@ func start_game():
# Called when the node enters the scene tree for the first time.
func _ready():
screen_size = get_viewport_rect().size
# x_offset = get_global_transform().get_origin().x
func _process(delta):
# Called every frame
func _process(_delta):
if Input.is_action_just_pressed("ui_accept"):
if not playing:
start_game()
@ -40,6 +40,7 @@ func _process(delta):
if not playing:
return
# Adjust the birds position
speed_y += speed_inc
position += Vector2(speed, speed_y * speed)
@ -49,17 +50,18 @@ func _process(delta):
emit_signal("passed")
tower_locations.pop_front()
# Rotate the bird
update_rotation()
if position.y > screen_size.y:
emit_signal("hit")
print(position)
playing = false
func update_rotation():
rotation = atan(speed_y / speed)
func _on_Player_body_entered(body):
# Hit detection
func _on_Player_body_entered(_body):
playing = false
start_game()

View file

@ -1,60 +1,64 @@
[gd_scene load_steps=6 format=2]
[gd_scene load_steps=7 format=3 uid="uid://bkppr8vsso41l"]
[ext_resource path="res://Player.gd" type="Script" id=1]
[ext_resource path="res://res/sprites.png" type="Texture2D" id=2]
[ext_resource type="Script" path="res://Player.gd" id="1"]
[ext_resource type="Texture2D" uid="uid://1wdcw8ne7j5w" path="res://res/sprites.png" id="2"]
[sub_resource type="AtlasTexture" id=1]
atlas = ExtResource( 2 )
region = Rect2( -4, 488, 84, 16 )
[sub_resource type="AtlasTexture" id="1"]
atlas = ExtResource("2")
region = Rect2(-4, 488, 84, 16)
[sub_resource type="Animation" id=2]
[sub_resource type="Animation" id="2"]
length = 0.8
loop = true
loop_mode = 1
step = 0.2
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Node2D/Sprite2D:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PackedFloat32Array( 0, 0.2, 0.4, 0.6 ),
"transitions": PackedFloat32Array( 1, 1, 1, 1 ),
"times": PackedFloat32Array(0, 0.2, 0.4, 0.6),
"transitions": PackedFloat32Array(1, 1, 1, 1),
"update": 1,
"values": [ 0, 1, 2, 1 ]
"values": [0, 1, 2, 1]
}
[sub_resource type="CapsuleShape2D" id=3]
radius = 12.8837
[sub_resource type="AnimationLibrary" id="AnimationLibrary_s168r"]
_data = {
"fly": SubResource("2")
}
[sub_resource type="CapsuleShape2D" id="3"]
radius = 2.03742
height = 4.07484
[node name="Area2D" type="Area2D"]
position = Vector2( 9.25964, 6.09653 )
scale = Vector2( 1, 1.02134 )
script = ExtResource( 1 )
__meta__ = {
"_edit_group_": true
}
position = Vector2(9.25964, 6.09653)
scale = Vector2(1, 1.02134)
script = ExtResource("1")
[node name="Node2D" type="Node2D" parent="."]
[node name="Sprite2D" type="Sprite2D" parent="Node2D"]
position = Vector2( -3.46641, -2.14102 )
scale = Vector2( 2.14565, 2.14019 )
texture = SubResource( 1 )
position = Vector2(-3.46641, -2.14102)
scale = Vector2(2.14565, 2.14019)
texture = SubResource("1")
hframes = 3
[node name="AnimationPlayer" type="AnimationPlayer" parent="Node2D"]
root_node = NodePath("../..")
libraries = {
"": SubResource("AnimationLibrary_s168r")
}
autoplay = "fly"
anims/fly = SubResource( 2 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
rotation = 1.5708
shape = SubResource( 3 )
shape = SubResource("3")
[node name="Camera2D" type="Camera2D" parent="."]
current = true
limit_top = 0
limit_bottom = 0
[connection signal="body_entered" from="." to="." method="_on_Player_body_entered"]

View file

@ -8,7 +8,7 @@ func _ready():
add_to_group("tower")
pass # Replace with function body.
func _on_Tower_body_entered(body):
func _on_Tower_body_entered(_body):
emit_signal("hit")
func _on_Visibility_screen_exited():