From d62e6ac024fa25ab0d0e0dbba6c8aa793f134023 Mon Sep 17 00:00:00 2001 From: OddlyTimbot Date: Mon, 6 Jan 2025 20:57:34 -0500 Subject: [PATCH] big four game objects, timer, signals, week1 --- januaryproject/.gitattributes | 2 + januaryproject/.gitignore | 3 + januaryproject/icon.svg | 1 + januaryproject/icon.svg.import | 37 ++++++++++ januaryproject/project.godot | 22 ++++++ januaryproject/scenes/crate.tscn | 10 +++ januaryproject/scenes/game.tscn | 69 +++++++++++++++++++ januaryproject/scripts/charactercontroller.gd | 29 ++++++++ januaryproject/scripts/gamecontroller.gd | 35 ++++++++++ januaryproject/scripts/trigger.gd | 17 +++++ 10 files changed, 225 insertions(+) create mode 100644 januaryproject/.gitattributes create mode 100644 januaryproject/.gitignore create mode 100644 januaryproject/icon.svg create mode 100644 januaryproject/icon.svg.import create mode 100644 januaryproject/project.godot create mode 100644 januaryproject/scenes/crate.tscn create mode 100644 januaryproject/scenes/game.tscn create mode 100644 januaryproject/scripts/charactercontroller.gd create mode 100644 januaryproject/scripts/gamecontroller.gd create mode 100644 januaryproject/scripts/trigger.gd diff --git a/januaryproject/.gitattributes b/januaryproject/.gitattributes new file mode 100644 index 0000000..8ad74f7 --- /dev/null +++ b/januaryproject/.gitattributes @@ -0,0 +1,2 @@ +# Normalize EOL for all files that Git considers text files. +* text=auto eol=lf diff --git a/januaryproject/.gitignore b/januaryproject/.gitignore new file mode 100644 index 0000000..0af181c --- /dev/null +++ b/januaryproject/.gitignore @@ -0,0 +1,3 @@ +# Godot 4+ specific ignores +.godot/ +/android/ diff --git a/januaryproject/icon.svg b/januaryproject/icon.svg new file mode 100644 index 0000000..9d8b7fa --- /dev/null +++ b/januaryproject/icon.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/januaryproject/icon.svg.import b/januaryproject/icon.svg.import new file mode 100644 index 0000000..a2c2bd0 --- /dev/null +++ b/januaryproject/icon.svg.import @@ -0,0 +1,37 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://dxl2ykb67tiak" +path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://icon.svg" +dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 +svg/scale=1.0 +editor/scale_with_editor_scale=false +editor/convert_colors_with_editor_theme=false diff --git a/januaryproject/project.godot b/januaryproject/project.godot new file mode 100644 index 0000000..09152e4 --- /dev/null +++ b/januaryproject/project.godot @@ -0,0 +1,22 @@ +; Engine configuration file. +; It's best edited using the editor UI and not directly, +; since the parameters that go here are not all obvious. +; +; Format: +; [section] ; section goes between [] +; param=value ; assign values to parameters + +config_version=5 + +[application] + +config/name="JanuaryProject" +run/main_scene="res://scenes/game.tscn" +config/features=PackedStringArray("4.3", "Forward Plus") +config/icon="res://icon.svg" + +[file_customization] + +folder_colors={ +"res://scripts/": "red" +} diff --git a/januaryproject/scenes/crate.tscn b/januaryproject/scenes/crate.tscn new file mode 100644 index 0000000..3cd1c0f --- /dev/null +++ b/januaryproject/scenes/crate.tscn @@ -0,0 +1,10 @@ +[gd_scene load_steps=2 format=3 uid="uid://di3tq4f0xmdqc"] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_jqoba"] + +[node name="RigidBody2D" type="RigidBody2D"] +metadata/_edit_group_ = true + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +shape = SubResource("RectangleShape2D_jqoba") +debug_color = Color(0.801265, 0.412511, 0.212642, 0.42) diff --git a/januaryproject/scenes/game.tscn b/januaryproject/scenes/game.tscn new file mode 100644 index 0000000..0c5909a --- /dev/null +++ b/januaryproject/scenes/game.tscn @@ -0,0 +1,69 @@ +[gd_scene load_steps=9 format=3 uid="uid://r8jj43l4t6is"] + +[ext_resource type="Script" path="res://scripts/gamecontroller.gd" id="1_8i1rq"] +[ext_resource type="PackedScene" uid="uid://di3tq4f0xmdqc" path="res://scenes/crate.tscn" id="1_tfj4n"] +[ext_resource type="Script" path="res://scripts/charactercontroller.gd" id="2_e3e8k"] +[ext_resource type="Script" path="res://scripts/trigger.gd" id="3_hm0br"] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_jk5qv"] +size = Vector2(66, 20) + +[sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_acecj"] +distance = -430.0 + +[sub_resource type="CircleShape2D" id="CircleShape2D_qrixx"] + +[sub_resource type="CircleShape2D" id="CircleShape2D_8j7te"] +radius = 29.0 + +[node name="Game" type="Node2D"] +script = ExtResource("1_8i1rq") + +[node name="StaticBody2D" type="StaticBody2D" parent="."] +position = Vector2(542, 371) +metadata/_edit_group_ = true + +[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D"] +shape = SubResource("RectangleShape2D_jk5qv") + +[node name="RigidBody2D" parent="." instance=ExtResource("1_tfj4n")] +position = Vector2(526, 297) +rotation = 2.0228 + +[node name="RigidBody2D2" parent="." instance=ExtResource("1_tfj4n")] +position = Vector2(509, 216) + +[node name="RigidBody2D3" parent="." instance=ExtResource("1_tfj4n")] +position = Vector2(576, 241) +rotation = -1.0315 + +[node name="RigidBody2D4" parent="." instance=ExtResource("1_tfj4n")] +position = Vector2(540, 178) +rotation = 0.0531393 + +[node name="floor" type="StaticBody2D" parent="."] + +[node name="CollisionShape2D" type="CollisionShape2D" parent="floor"] +shape = SubResource("WorldBoundaryShape2D_acecj") + +[node name="CharacterBody2D" type="CharacterBody2D" parent="."] +position = Vector2(441, 314) +script = ExtResource("2_e3e8k") +PUSH_FORCE = 70 +metadata/_edit_group_ = true + +[node name="CollisionShape2D" type="CollisionShape2D" parent="CharacterBody2D"] +shape = SubResource("CircleShape2D_qrixx") +debug_color = Color(0.345561, 0.615334, 0.230675, 0.42) + +[node name="Area2D" type="Area2D" parent="."] +position = Vector2(597, 419) +script = ExtResource("3_hm0br") +metadata/_edit_group_ = true + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"] +shape = SubResource("CircleShape2D_8j7te") +debug_color = Color(0.827271, 0.252084, 0.761388, 0.42) + +[connection signal="areaTrigger" from="Area2D" to="." method="_on_trigger"] +[connection signal="body_entered" from="Area2D" to="Area2D" method="_on_body_entered"] diff --git a/januaryproject/scripts/charactercontroller.gd b/januaryproject/scripts/charactercontroller.gd new file mode 100644 index 0000000..c228b11 --- /dev/null +++ b/januaryproject/scripts/charactercontroller.gd @@ -0,0 +1,29 @@ +extends CharacterBody2D + + +const SPEED = 500.0 +const JUMP_VELOCITY = -600.0 +@export var PUSH_FORCE = 90 + +func _physics_process(delta: float) -> void: + # Add the gravity. + if not is_on_floor(): + velocity += get_gravity() * delta + + # Handle jump. + if Input.is_action_just_pressed("ui_accept") and is_on_floor(): + velocity.y = JUMP_VELOCITY + + # Get the input direction and handle the movement/deceleration. + # As good practice, you should replace UI actions with custom gameplay actions. + var direction := Input.get_axis("ui_left", "ui_right") + if direction: + velocity.x = direction * SPEED + else: + velocity.x = move_toward(velocity.x, 0, SPEED) + + move_and_slide() + for i in get_slide_collision_count(): + var c = get_slide_collision(i) + if c.get_collider() is RigidBody2D: + c.get_collider().apply_central_impulse(-c.get_normal() * PUSH_FORCE) diff --git a/januaryproject/scripts/gamecontroller.gd b/januaryproject/scripts/gamecontroller.gd new file mode 100644 index 0000000..969e7a0 --- /dev/null +++ b/januaryproject/scripts/gamecontroller.gd @@ -0,0 +1,35 @@ +extends Node2D + +var boxTotal = 4 +var timer:= Timer.new() +var countdown = 10 + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + add_child(timer) + timer.wait_time = 1 + timer.one_shot = false + timer.connect("timeout", secondCounter) + timer.start() + +func secondCounter(): + print("one second") + countdown -=1 + if countdown <=0: + print("YOU LOSE") + get_tree().reload_current_scene() +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta: float) -> void: + pass + + +func _on_trigger(effect: Variant, body) -> void: + print("Game Controller sees an alert") + if body is RigidBody2D: + print("I see a crate") + body.queue_free() + boxTotal -=1 + if boxTotal <=0: + print("YOU WON!!") + get_tree().reload_current_scene() + diff --git a/januaryproject/scripts/trigger.gd b/januaryproject/scripts/trigger.gd new file mode 100644 index 0000000..aabeb5e --- /dev/null +++ b/januaryproject/scripts/trigger.gd @@ -0,0 +1,17 @@ +extends Area2D + +@export var effect = "alert" +signal areaTrigger(effect, Object) +# 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 + + +func _on_body_entered(body: Node2D) -> void: + print("Something in the trigger") + areaTrigger.emit(effect, body)