aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeightonGinty <leightonginty@gmail.com>2022-10-29 16:37:26 +0100
committerLeightonGinty <leightonginty@gmail.com>2022-10-29 16:37:26 +0100
commit4c0bd4f0ab32a2489130d04b08c39d008c8c9961 (patch)
tree75d2c138b24bb09ab15ce7f1204b69cfe7a40abe
parent078392d1d4478e552d362c2e76c2d50a1917f10e (diff)
can shoot now
-rw-r--r--Bullet.gd37
-rw-r--r--Bullet.tscn19
-rw-r--r--KinematicBody2D.gd11
-rw-r--r--Node2D.tscn7
-rw-r--r--Player.tscn2
-rw-r--r--project.godot5
6 files changed, 78 insertions, 3 deletions
diff --git a/Bullet.gd b/Bullet.gd
new file mode 100644
index 0000000..311a8b2
--- /dev/null
+++ b/Bullet.gd
@@ -0,0 +1,37 @@
+extends KinematicBody2D
+export (int) var speed = 2000
+
+var velocity = Vector2()
+var target = Vector2.ZERO
+var player = load("")
+var shot = false;
+func get_input():
+ velocity = Vector2()
+ if Input.is_action_pressed("right"):
+ velocity.x += 1
+ if Input.is_action_pressed("left"):
+ velocity.x -= 1
+ if Input.is_action_pressed("down"):
+ velocity.y += 1
+ if Input.is_action_pressed("up"):
+ velocity.y -= 1
+
+ velocity = velocity.normalized() * speed
+
+
+
+
+func _physics_process(delta):
+
+
+
+
+ target = get_global_mouse_position()
+ if(Input.is_action_pressed("click") && shot == false):
+ velocity = global_position.direction_to(target) * speed
+ shot = true
+ velocity = move_and_slide(velocity)
+
+
+
+
diff --git a/Bullet.tscn b/Bullet.tscn
new file mode 100644
index 0000000..d2f4c14
--- /dev/null
+++ b/Bullet.tscn
@@ -0,0 +1,19 @@
+[gd_scene load_steps=4 format=2]
+
+[ext_resource path="res://Bullet.gd" type="Script" id=1]
+[ext_resource path="res://icon.png" type="Texture" id=2]
+
+[sub_resource type="CapsuleShape2D" id=1]
+radius = 8.0
+
+[node name="Bullet" type="KinematicBody2D"]
+position = Vector2( 648, 360 )
+script = ExtResource( 1 )
+
+[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
+position = Vector2( -1, 1 )
+shape = SubResource( 1 )
+disabled = true
+
+[node name="Sprite" type="Sprite" parent="."]
+texture = ExtResource( 2 )
diff --git a/KinematicBody2D.gd b/KinematicBody2D.gd
index dad1eb5..a1a3770 100644
--- a/KinematicBody2D.gd
+++ b/KinematicBody2D.gd
@@ -1,7 +1,7 @@
extends KinematicBody2D
export (int) var speed = 200
-
+var spawn_object = load("res://Bullet.tscn")
var velocity = Vector2()
func get_input():
@@ -17,5 +17,14 @@ func get_input():
velocity = velocity.normalized() * speed
func _physics_process(delta):
+
+
+
get_input()
velocity = move_and_slide(velocity)
+ if Input.is_action_just_pressed("click"):
+ var obj = spawn_object.instance()
+ obj.position = get_position()
+ obj.position.x -= 500
+ obj.position.y -= 250
+ add_child(obj)
diff --git a/Node2D.tscn b/Node2D.tscn
index a5ed610..612e27f 100644
--- a/Node2D.tscn
+++ b/Node2D.tscn
@@ -1,12 +1,17 @@
-[gd_scene load_steps=4 format=2]
+[gd_scene load_steps=5 format=2]
[ext_resource path="res://HUD.tscn" type="PackedScene" id=1]
[ext_resource path="res://Player.tscn" type="PackedScene" id=2]
[ext_resource path="res://Enemy0.tscn" type="PackedScene" id=3]
+[ext_resource path="res://Bullet.tscn" type="PackedScene" id=4]
[node name="Node" type="Node2D"]
[node name="KinematicBody2D" parent="." instance=ExtResource( 2 )]
+position = Vector2( 544, 216 )
+
+[node name="Bullet" parent="KinematicBody2D" instance=ExtResource( 4 )]
+position = Vector2( 4, 9 )
[node name="Node" type="Node" parent="."]
diff --git a/Player.tscn b/Player.tscn
index 7084f49..dd8180b 100644
--- a/Player.tscn
+++ b/Player.tscn
@@ -14,6 +14,6 @@ script = ExtResource( 1 )
shape = SubResource( 1 )
[node name="Sprite" type="Sprite" parent="CollisionShape2D"]
-position = Vector2( -15.5, -15 )
+position = Vector2( -1, -4 )
scale = Vector2( 0.515625, 0.53125 )
texture = ExtResource( 2 )
diff --git a/project.godot b/project.godot
index e2fc52c..04d6f9c 100644
--- a/project.godot
+++ b/project.godot
@@ -47,6 +47,11 @@ down={
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777234,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
]
}
+click={
+"deadzone": 0.5,
+"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":32,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
+ ]
+}
[physics]