commit 3e8d5754f94f2325f3f7419eef633e6ae4cb516d Author: nakurai Date: Mon Jul 28 21:08:53 2025 -0400 week1 - collisions diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..f28239b --- /dev/null +++ b/.editorconfig @@ -0,0 +1,4 @@ +root = true + +[*] +charset = utf-8 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..8ad74f7 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Normalize EOL for all files that Git considers text files. +* text=auto eol=lf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0af181c --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +# Godot 4+ specific ignores +.godot/ +/android/ diff --git a/icon.svg b/icon.svg new file mode 100644 index 0000000..9d8b7fa --- /dev/null +++ b/icon.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/icon.svg.import b/icon.svg.import new file mode 100644 index 0000000..890de69 --- /dev/null +++ b/icon.svg.import @@ -0,0 +1,37 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://oltgucr60ffk" +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/project.godot b/project.godot new file mode 100644 index 0000000..364e523 --- /dev/null +++ b/project.godot @@ -0,0 +1,16 @@ +; 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="ttlmaker" +run/main_scene="uid://dk3bbsqf7yi08" +config/features=PackedStringArray("4.4", "Forward Plus") +config/icon="res://icon.svg" diff --git a/scenes/game.tscn b/scenes/game.tscn new file mode 100644 index 0000000..0071fa2 --- /dev/null +++ b/scenes/game.tscn @@ -0,0 +1,64 @@ +[gd_scene load_steps=8 format=3 uid="uid://dk3bbsqf7yi08"] + +[ext_resource type="Script" uid="uid://c3o8iur48idhr" path="res://scripts/gamecontroller.gd" id="1_lnu2h"] +[ext_resource type="Script" uid="uid://bg8hstdeqf43x" path="res://scripts/player.gd" id="1_uwrxv"] +[ext_resource type="PackedScene" uid="uid://e5y4obsl2kcv" path="res://scenes/trigger.tscn" id="2_yqjtg"] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_8cj0n"] +size = Vector2(144, 20) + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_uwrxv"] + +[sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_8cj0n"] + +[sub_resource type="CircleShape2D" id="CircleShape2D_8cj0n"] + +[node name="game" type="Node2D"] +script = ExtResource("1_lnu2h") + +[node name="StaticBody2D" type="StaticBody2D" parent="."] +position = Vector2(498, 356) +metadata/_edit_group_ = true + +[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D"] +shape = SubResource("RectangleShape2D_8cj0n") + +[node name="RigidBody2D" type="RigidBody2D" parent="."] +position = Vector2(475, 269) +rotation = -0.698132 +metadata/_edit_group_ = true + +[node name="CollisionShape2D" type="CollisionShape2D" parent="RigidBody2D"] +shape = SubResource("RectangleShape2D_uwrxv") +debug_color = Color(0.841123, 0.368839, 0.275526, 0.42) + +[node name="RigidBody2D2" type="RigidBody2D" parent="."] +position = Vector2(856, 194) +rotation = -0.698132 +metadata/_edit_group_ = true + +[node name="CollisionShape2D" type="CollisionShape2D" parent="RigidBody2D2"] +shape = SubResource("RectangleShape2D_uwrxv") +debug_color = Color(0.841123, 0.368839, 0.275526, 0.42) + +[node name="ground" type="StaticBody2D" parent="."] +position = Vector2(485, 460) +metadata/_edit_group_ = true + +[node name="CollisionShape2D" type="CollisionShape2D" parent="ground"] +shape = SubResource("WorldBoundaryShape2D_8cj0n") + +[node name="player" type="CharacterBody2D" parent="."] +position = Vector2(472, 333) +script = ExtResource("1_uwrxv") +metadata/_edit_group_ = true + +[node name="CollisionShape2D" type="CollisionShape2D" parent="player"] +shape = SubResource("CircleShape2D_8cj0n") +debug_color = Color(0.285278, 0.619884, 0.338524, 0.42) + +[node name="Area2D" parent="." instance=ExtResource("2_yqjtg")] +position = Vector2(851, 421) +scale = Vector2(3.02324, 2.78272) + +[connection signal="areaTriggerSignal" from="Area2D" to="." method="_on_trigger"] diff --git a/scenes/trigger.tscn b/scenes/trigger.tscn new file mode 100644 index 0000000..5360050 --- /dev/null +++ b/scenes/trigger.tscn @@ -0,0 +1,17 @@ +[gd_scene load_steps=3 format=3 uid="uid://e5y4obsl2kcv"] + +[ext_resource type="Script" uid="uid://ce32s4sac7kf0" path="res://scripts/trigger.gd" id="1_du5ex"] + +[sub_resource type="CircleShape2D" id="CircleShape2D_uwrxv"] + +[node name="trigger" type="Area2D"] +scale = Vector2(3.02324, 2.78272) +script = ExtResource("1_du5ex") +effect = "destroy" +metadata/_edit_group_ = true + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +shape = SubResource("CircleShape2D_uwrxv") +debug_color = Color(0.525515, 0.426125, 0.975229, 0.42) + +[connection signal="body_entered" from="." to="." method="_on_body_entered"] diff --git a/scripts/gamecontroller.gd b/scripts/gamecontroller.gd new file mode 100644 index 0000000..24f365f --- /dev/null +++ b/scripts/gamecontroller.gd @@ -0,0 +1,19 @@ +extends Node2D + + + +# 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_trigger(effect: Variant, body: Variant) -> void: + print("game controller sees trigger "+effect+" "+body.name) + if not body is Player: + body.queue_free() + diff --git a/scripts/gamecontroller.gd.uid b/scripts/gamecontroller.gd.uid new file mode 100644 index 0000000..474b6a1 --- /dev/null +++ b/scripts/gamecontroller.gd.uid @@ -0,0 +1 @@ +uid://c3o8iur48idhr diff --git a/scripts/player.gd b/scripts/player.gd new file mode 100644 index 0000000..9c12b16 --- /dev/null +++ b/scripts/player.gd @@ -0,0 +1,31 @@ +class_name Player extends CharacterBody2D + + +const SPEED = 300.0 +const JUMP_VELOCITY = -400.0 + + +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 collision := get_slide_collision(i) + var collider := collision.get_collider() + if collider is RigidBody2D: + collider.apply_central_impulse(-collision.get_normal()*100) diff --git a/scripts/player.gd.uid b/scripts/player.gd.uid new file mode 100644 index 0000000..7cd8ea2 --- /dev/null +++ b/scripts/player.gd.uid @@ -0,0 +1 @@ +uid://bg8hstdeqf43x diff --git a/scripts/trigger.gd b/scripts/trigger.gd new file mode 100644 index 0000000..a822232 --- /dev/null +++ b/scripts/trigger.gd @@ -0,0 +1,10 @@ +extends Area2D + +@export var effect:String + +#custom signal +signal areaTriggerSignal(effect, Object) + + +func _on_body_entered(body: Node2D) -> void: + areaTriggerSignal.emit(effect, body) diff --git a/scripts/trigger.gd.uid b/scripts/trigger.gd.uid new file mode 100644 index 0000000..2799e02 --- /dev/null +++ b/scripts/trigger.gd.uid @@ -0,0 +1 @@ +uid://ce32s4sac7kf0