From 7c292f7cec3443b0536431bbdf2a7a1a6d8481c2 Mon Sep 17 00:00:00 2001 From: Darius Date: Mon, 10 Feb 2025 11:30:11 -0500 Subject: [PATCH] adding buggy hover, teleport --- dariusgodotproject/project.godot | 10 +++ dariusgodotproject/scenes/game.tscn | 77 +++++++++++++++++-- dariusgodotproject/scenes/level2.tscn | 74 +++++++++++++++++- .../scripts/charactercontroller.gd | 23 +++++- dariusgodotproject/scripts/gamecontroller.gd | 2 +- dariusgodotproject/scripts/scenemanager.gd | 2 +- dariusgodotproject/scripts/trigger.gd | 2 + 7 files changed, 179 insertions(+), 11 deletions(-) diff --git a/dariusgodotproject/project.godot b/dariusgodotproject/project.godot index 75f9976..8d2e6f6 100644 --- a/dariusgodotproject/project.godot +++ b/dariusgodotproject/project.godot @@ -62,3 +62,13 @@ shoot={ "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":90,"key_label":0,"unicode":122,"location":0,"echo":false,"script":null) ] } +hover={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":72,"key_label":0,"unicode":104,"location":0,"echo":false,"script":null) +] +} +teleport={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":81,"key_label":0,"unicode":113,"location":0,"echo":false,"script":null) +] +} diff --git a/dariusgodotproject/scenes/game.tscn b/dariusgodotproject/scenes/game.tscn index de7e0f4..5253173 100644 --- a/dariusgodotproject/scenes/game.tscn +++ b/dariusgodotproject/scenes/game.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=17 format=4 uid="uid://dcmyx5g6dksl8"] +[gd_scene load_steps=24 format=4 uid="uid://dcmyx5g6dksl8"] [ext_resource type="PackedScene" uid="uid://d1ej2kiy7jcpv" path="res://scenes/crate.tscn" id="1_uivx3"] [ext_resource type="Script" path="res://scripts/trigger.gd" id="3_2qbah"] @@ -10,7 +10,8 @@ [ext_resource type="Script" path="res://scripts/scenemanager.gd" id="6_n2kp0"] [ext_resource type="Texture2D" uid="uid://btdvc25chjgd" path="res://assets/graphics/terrains/Terrain (32x32).png" id="7_v20os"] [ext_resource type="PackedScene" uid="uid://ix6oxq0kduyx" path="res://scenes/coin.tscn" id="10_nxy68"] -[ext_resource type="PackedScene" uid="uid://clitp4u6pd426" path="res://scenes/badguy.tscn" id="11_dbqj0"] +[ext_resource type="Script" path="res://scripts/badguy.gd" id="11_k2u02"] +[ext_resource type="Texture2D" uid="uid://ds7phwfwavsqj" path="res://assets/graphics/enemies/slime_green.png" id="12_u2djp"] [sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_3ut3v"] texture = ExtResource("7_v20os") @@ -381,6 +382,45 @@ distance = -181.0 [sub_resource type="CircleShape2D" id="CircleShape2D_mfh1j"] +[sub_resource type="AtlasTexture" id="AtlasTexture_s1yph"] +atlas = ExtResource("12_u2djp") +region = Rect2(0, 24, 24, 24) + +[sub_resource type="AtlasTexture" id="AtlasTexture_ft2a6"] +atlas = ExtResource("12_u2djp") +region = Rect2(24, 24, 24, 24) + +[sub_resource type="AtlasTexture" id="AtlasTexture_gg3ce"] +atlas = ExtResource("12_u2djp") +region = Rect2(48, 24, 24, 24) + +[sub_resource type="AtlasTexture" id="AtlasTexture_dlo6y"] +atlas = ExtResource("12_u2djp") +region = Rect2(72, 24, 24, 24) + +[sub_resource type="SpriteFrames" id="SpriteFrames_dgoyr"] +animations = [{ +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_s1yph") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_ft2a6") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_gg3ce") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_dlo6y") +}], +"loop": true, +"name": &"idle", +"speed": 12.0 +}] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_i8bk0"] +size = Vector2(15, 18) + [node name="Game" type="Node2D"] [node name="SceneManager" type="Node" parent="."] @@ -429,8 +469,8 @@ shape = SubResource("WorldBoundaryShape2D_bqh70") [node name="CharacterBody2D" parent="." instance=ExtResource("3_8h5jv")] [node name="Area2D" type="Area2D" parent="."] -position = Vector2(359, 141) -scale = Vector2(5, 5) +position = Vector2(43, -53) +scale = Vector2(2.5, 2.5) script = ExtResource("3_2qbah") metadata/_edit_group_ = true @@ -480,8 +520,35 @@ position = Vector2(400, 40) [node name="enemies" type="Node2D" parent="."] -[node name="Area2D3" parent="enemies" instance=ExtResource("11_dbqj0")] +[node name="Area2D3" type="Area2D" parent="enemies" groups=["enemies"]] position = Vector2(369, 55) +script = ExtResource("11_k2u02") +metadata/_edit_group_ = true + +[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="enemies/Area2D3"] +texture_filter = 1 +sprite_frames = SubResource("SpriteFrames_dgoyr") +animation = &"idle" +frame_progress = 0.764829 + +[node name="CollisionShape2D" type="CollisionShape2D" parent="enemies/Area2D3"] +position = Vector2(0, 2) +shape = SubResource("RectangleShape2D_i8bk0") + +[node name="RightRay" type="RayCast2D" parent="enemies/Area2D3"] +target_position = Vector2(14, 0) + +[node name="LeftRay" type="RayCast2D" parent="enemies/Area2D3"] +target_position = Vector2(-14, 0) + +[node name="RightFloorRay" type="RayCast2D" parent="enemies/Area2D3"] +position = Vector2(9, 0) +target_position = Vector2(0, 18) + +[node name="LeftFloorRay" type="RayCast2D" parent="enemies/Area2D3"] +position = Vector2(-9, 0) +target_position = Vector2(0, 18) [connection signal="areaTrigger" from="Area2D" to="." method="_on_trigger"] [connection signal="body_entered" from="Area2D" to="Area2D" method="_on_body_entered"] +[connection signal="body_entered" from="enemies/Area2D3" to="enemies/Area2D3" method="_on_body_entered"] diff --git a/dariusgodotproject/scenes/level2.tscn b/dariusgodotproject/scenes/level2.tscn index 4388846..a3ac712 100644 --- a/dariusgodotproject/scenes/level2.tscn +++ b/dariusgodotproject/scenes/level2.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=15 format=4 uid="uid://d383o6j0l3d2m"] +[gd_scene load_steps=23 format=4 uid="uid://d383o6j0l3d2m"] [ext_resource type="Script" path="res://scripts/scenemanager.gd" id="1_g37ru"] [ext_resource type="Texture2D" uid="uid://jlbx6yvcmten" path="res://assets/graphics/terrains/backgrounds/forestbackground.png" id="2_ehg0h"] @@ -9,6 +9,8 @@ [ext_resource type="Script" path="res://scripts/trigger.gd" id="7_2y6a6"] [ext_resource type="PackedScene" uid="uid://ix6oxq0kduyx" path="res://scenes/coin.tscn" id="9_fv1rd"] [ext_resource type="PackedScene" uid="uid://d1ej2kiy7jcpv" path="res://scenes/crate.tscn" id="9_sys65"] +[ext_resource type="Script" path="res://scripts/badguy.gd" id="10_5rofm"] +[ext_resource type="Texture2D" uid="uid://ds7phwfwavsqj" path="res://assets/graphics/enemies/slime_green.png" id="11_1pe1f"] [sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_3ut3v"] texture = ExtResource("5_p6mo5") @@ -379,6 +381,45 @@ distance = -181.0 [sub_resource type="CircleShape2D" id="CircleShape2D_mfh1j"] +[sub_resource type="AtlasTexture" id="AtlasTexture_s1yph"] +atlas = ExtResource("11_1pe1f") +region = Rect2(0, 24, 24, 24) + +[sub_resource type="AtlasTexture" id="AtlasTexture_ft2a6"] +atlas = ExtResource("11_1pe1f") +region = Rect2(24, 24, 24, 24) + +[sub_resource type="AtlasTexture" id="AtlasTexture_gg3ce"] +atlas = ExtResource("11_1pe1f") +region = Rect2(48, 24, 24, 24) + +[sub_resource type="AtlasTexture" id="AtlasTexture_dlo6y"] +atlas = ExtResource("11_1pe1f") +region = Rect2(72, 24, 24, 24) + +[sub_resource type="SpriteFrames" id="SpriteFrames_8wjrh"] +animations = [{ +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_s1yph") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_ft2a6") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_gg3ce") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_dlo6y") +}], +"loop": true, +"name": &"idle", +"speed": 12.0 +}] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_060tc"] +size = Vector2(15, 18) + [node name="Game" type="Node2D"] [node name="SceneManager" type="Node" parent="."] @@ -473,5 +514,36 @@ position = Vector2(370, 40) [node name="Area2D2" parent="coins" instance=ExtResource("9_fv1rd")] position = Vector2(400, 40) +[node name="enemies" type="Node2D" parent="."] + +[node name="Area2D3" type="Area2D" parent="enemies" groups=["enemies"]] +position = Vector2(369, 55) +script = ExtResource("10_5rofm") +metadata/_edit_group_ = true + +[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="enemies/Area2D3"] +texture_filter = 1 +sprite_frames = SubResource("SpriteFrames_8wjrh") +animation = &"idle" + +[node name="CollisionShape2D" type="CollisionShape2D" parent="enemies/Area2D3"] +position = Vector2(0, 2) +shape = SubResource("RectangleShape2D_060tc") + +[node name="RightRay" type="RayCast2D" parent="enemies/Area2D3"] +target_position = Vector2(14, 0) + +[node name="LeftRay" type="RayCast2D" parent="enemies/Area2D3"] +target_position = Vector2(-14, 0) + +[node name="RightFloorRay" type="RayCast2D" parent="enemies/Area2D3"] +position = Vector2(9, 0) +target_position = Vector2(0, 18) + +[node name="LeftFloorRay" type="RayCast2D" parent="enemies/Area2D3"] +position = Vector2(-9, 0) +target_position = Vector2(0, 18) + [connection signal="areaTrigger" from="Area2D" to="." method="_on_trigger"] [connection signal="body_entered" from="Area2D" to="Area2D" method="_on_body_entered"] +[connection signal="body_entered" from="enemies/Area2D3" to="enemies/Area2D3" method="_on_body_entered"] diff --git a/dariusgodotproject/scripts/charactercontroller.gd b/dariusgodotproject/scripts/charactercontroller.gd index d8802fa..0aa510e 100644 --- a/dariusgodotproject/scripts/charactercontroller.gd +++ b/dariusgodotproject/scripts/charactercontroller.gd @@ -14,13 +14,14 @@ var pushRightEnabled = false var pushLeftEnabled = false @export var PUSH_FORCE = 700 @onready var animation: AnimatedSprite2D = $AnimatedSprite2D +@onready var teleportZone: Area2D = $"../Area2D" # Bullet Attack Variables @onready var right_target: Node2D = $RightTarget @onready var left_target: Node2D = $LeftTarget var isJumping = false - +var safeTeleport = false func _physics_process(delta: float) -> void: # Add the gravity. if not is_on_floor(): @@ -32,19 +33,35 @@ func _physics_process(delta: float) -> void: velocity.y = JUMP_VELOCITY animation.play("jump") isJumping = true - + # Hover + if not is_on_floor() and Input.is_action_pressed("hover"): + velocity.x = 0 + velocity.y = 0 # Shove Attack if Input.is_action_just_pressed("shove"): if pushRightEnabled && faceLeft == false: pushTarget.apply_central_impulse(Vector2(1,0) * PUSH_FORCE * 2) if pushLeftEnabled && faceLeft == true: pushTarget.apply_central_impulse(Vector2(-1,0) * PUSH_FORCE * 2) + # Teleport + if Input.is_action_just_pressed("teleport"): + while not safeTeleport: + teleportZone.position = Vector2(position.x+randf_range(-300,300),position.y+randf_range(-300,300)) + if teleportZone.has_overlapping_bodies(): + safeTeleport = false + else: + safeTeleport = true + safeTeleport= false + position = Vector2(teleportZone.position.x,teleportZone.position.y) + + + # Handle Shooting if Input.is_action_just_pressed("shoot"): #print("I want to shoot") #make a new bullet - + if faceLeft == true: var myBullet = %SceneManager.makeBullet(left_target.global_transform,-700) diff --git a/dariusgodotproject/scripts/gamecontroller.gd b/dariusgodotproject/scripts/gamecontroller.gd index 6f3b9f9..e6823a8 100644 --- a/dariusgodotproject/scripts/gamecontroller.gd +++ b/dariusgodotproject/scripts/gamecontroller.gd @@ -21,7 +21,7 @@ signal levelComplete (levelToLoad) -# C alled when the node enters the scene tree for the first time. +# Called when the node enters the scene tree for the first time. func _ready() -> void: player = load("res://scripts/res/playerstats.tres") print("Player health " +str(player.health)) diff --git a/dariusgodotproject/scripts/scenemanager.gd b/dariusgodotproject/scripts/scenemanager.gd index a55f419..2d16012 100644 --- a/dariusgodotproject/scripts/scenemanager.gd +++ b/dariusgodotproject/scripts/scenemanager.gd @@ -3,6 +3,7 @@ extends Node @onready var coins: Node2D = $"../coins" @onready var enemies: Node2D = $"../enemies" + var bullet = preload("res://scenes/bullet.tscn") var bulletArray:Array = [] var bulletsMadeTotal :=0 @@ -23,7 +24,6 @@ func _ready() -> void: if obj.is_in_group("collectibles"): totalCoins +=1 obj.coinCollected.connect(Gamecontroller.coinCollected) - var totalEnemies = 0 for obj in enemies.get_children(): if obj.is_in_group("enemies"): diff --git a/dariusgodotproject/scripts/trigger.gd b/dariusgodotproject/scripts/trigger.gd index 83f8752..82eba8e 100644 --- a/dariusgodotproject/scripts/trigger.gd +++ b/dariusgodotproject/scripts/trigger.gd @@ -1,4 +1,5 @@ extends Area2D +@onready var character: CharacterBody2D = $"../CharacterBody2D" @export var effect = "alert" signal areaTrigger(effect, Object) @@ -14,4 +15,5 @@ func _process(delta: float) -> void: func _on_body_entered(body: Node2D) -> void: print("Something in the trigger.") + print(character.position) areaTrigger.emit(effect, body)