poorly coded enemies

This commit is contained in:
zman27 2022-01-29 14:10:06 -05:00
parent f2ef5dfbb3
commit db26d0621f
3 changed files with 38 additions and 1 deletions

15
Actors/Enemy.gd Normal file
View File

@ -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)

18
Actors/Enemy.tscn Normal file
View File

@ -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 )

View File

@ -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://ServeArea.gd" type="Script" id=1]
[ext_resource path="res://Cups/Cup.tscn" type="PackedScene" id=2] [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://Levels/Level001.tscn" type="PackedScene" id=4]
[ext_resource path="res://GUI.tscn" type="PackedScene" id=5] [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://Items/Item.tscn" type="PackedScene" id=6]
[ext_resource path="res://Actors/Enemy.tscn" type="PackedScene" id=7]
[sub_resource type="RectangleShape2D" id=1] [sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 269.25, 124 ) extents = Vector2( 269.25, 124 )
@ -70,6 +71,9 @@ position = Vector2( 266, 918 )
[node name="Item" parent="." instance=ExtResource( 6 )] [node name="Item" parent="." instance=ExtResource( 6 )]
position = Vector2( 370, 627 ) 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="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_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"] [connection signal="button_up" from="ServeArea/TextureButton" to="ServeArea" method="_on_TextureButton_button_up"]