From db26d0621f876d730a3529eac1dd2d42d2ca5eae Mon Sep 17 00:00:00 2001 From: zman27 Date: Sat, 29 Jan 2022 14:10:06 -0500 Subject: [PATCH] poorly coded enemies --- Actors/Enemy.gd | 15 +++++++++++++++ Actors/Enemy.tscn | 18 ++++++++++++++++++ World.tscn | 6 +++++- 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 Actors/Enemy.gd create mode 100644 Actors/Enemy.tscn diff --git a/Actors/Enemy.gd b/Actors/Enemy.gd new file mode 100644 index 0000000..3797c47 --- /dev/null +++ b/Actors/Enemy.gd @@ -0,0 +1,15 @@ +extends KinematicBody2D + +var velocity = Vector2(0,-100) +var push = 2500 + +func _ready(): + pass + +func _process(delta: float) -> void: + move_and_slide(velocity, Vector2.UP, false, 4, PI/4, false) + for index in get_slide_count(): + var collision = get_slide_collision(index) + if collision.collider.is_in_group("Balls"): + print("balls") + collision.collider.apply_central_impulse(collision.normal * push) diff --git a/Actors/Enemy.tscn b/Actors/Enemy.tscn new file mode 100644 index 0000000..ad52e4b --- /dev/null +++ b/Actors/Enemy.tscn @@ -0,0 +1,18 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://icon.png" type="Texture" id=1] +[ext_resource path="res://Actors/Enemy.gd" type="Script" id=2] + +[sub_resource type="CapsuleShape2D" id=1] +radius = 26.0 + +[node name="Enemy" type="KinematicBody2D"] +collision_layer = 4 +collision_mask = 4 +script = ExtResource( 2 ) + +[node name="Sprite" type="Sprite" parent="."] +texture = ExtResource( 1 ) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +shape = SubResource( 1 ) diff --git a/World.tscn b/World.tscn index 9dc417d..bc74593 100644 --- a/World.tscn +++ b/World.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=9 format=2] +[gd_scene load_steps=10 format=2] [ext_resource path="res://ServeArea.gd" type="Script" id=1] [ext_resource path="res://Cups/Cup.tscn" type="PackedScene" id=2] @@ -6,6 +6,7 @@ [ext_resource path="res://Levels/Level001.tscn" type="PackedScene" id=4] [ext_resource path="res://GUI.tscn" type="PackedScene" id=5] [ext_resource path="res://Items/Item.tscn" type="PackedScene" id=6] +[ext_resource path="res://Actors/Enemy.tscn" type="PackedScene" id=7] [sub_resource type="RectangleShape2D" id=1] extents = Vector2( 269.25, 124 ) @@ -70,6 +71,9 @@ position = Vector2( 266, 918 ) [node name="Item" parent="." instance=ExtResource( 6 )] position = Vector2( 370, 627 ) +[node name="Node2D" parent="." instance=ExtResource( 7 )] +position = Vector2( 162, 918 ) + [connection signal="mouse_exited" from="ServeArea" to="ServeArea" method="_on_ServeArea_mouse_exited"] [connection signal="button_down" from="ServeArea/TextureButton" to="ServeArea" method="_on_TextureButton_button_down"] [connection signal="button_up" from="ServeArea/TextureButton" to="ServeArea" method="_on_TextureButton_button_up"]