Skip to content

Commit

Permalink
Первые зачатки врага
Browse files Browse the repository at this point in the history
Добавил врага который follow you
  • Loading branch information
Allespro committed Apr 23, 2019
1 parent 7eb5eff commit b26436a
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 35 deletions.
14 changes: 14 additions & 0 deletions Enemy/KnightBody.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
extends Area2D



func _on_Body_area_entered(area):
var groups = area.get_groups()
if (groups.has("player")):
$"../".attack()


func _on_Body_area_exited(area):
var groups = area.get_groups()
if (groups.has("player")):
$"../".stop_attack()
44 changes: 22 additions & 22 deletions Enemy1.tscn
Original file line number Diff line number Diff line change
@@ -1,55 +1,50 @@
[gd_scene load_steps=14 format=2]

[ext_resource path="res://Enemy1.gd" type="Script" id=1]
[ext_resource path="res://KinematicEnemy1.gd" type="Script" id=2]
[ext_resource path="res://enemy/amg1_lf1.png" type="Texture" id=3]
[ext_resource path="res://enemy/amg1_lf2.png" type="Texture" id=4]
[ext_resource path="res://enemy/amg1_rt1.png" type="Texture" id=5]
[ext_resource path="res://enemy/amg1_rt2.png" type="Texture" id=6]
[ext_resource path="res://enemy/amg1_bk1.png" type="Texture" id=7]
[ext_resource path="res://enemy/amg1_bk2.png" type="Texture" id=8]
[ext_resource path="res://enemy/amg1_fr1.png" type="Texture" id=9]
[ext_resource path="res://enemy/amg1_fr2.png" type="Texture" id=10]
[ext_resource path="res://KinematicEnemy1.gd" type="Script" id=1]
[ext_resource path="res://enemy/amg1_lf1.png" type="Texture" id=2]
[ext_resource path="res://enemy/amg1_lf2.png" type="Texture" id=3]
[ext_resource path="res://enemy/amg1_rt1.png" type="Texture" id=4]
[ext_resource path="res://enemy/amg1_rt2.png" type="Texture" id=5]
[ext_resource path="res://enemy/amg1_bk1.png" type="Texture" id=6]
[ext_resource path="res://enemy/amg1_bk2.png" type="Texture" id=7]
[ext_resource path="res://enemy/amg1_fr1.png" type="Texture" id=8]
[ext_resource path="res://enemy/amg1_fr2.png" type="Texture" id=9]
[ext_resource path="res://Enemy/KnightBody.gd" type="Script" id=10]

[sub_resource type="CapsuleShape2D" id=1]
radius = 15.6866
height = 13.8927

[sub_resource type="SpriteFrames" id=2]
animations = [ {
"frames": [ ExtResource( 3 ), ExtResource( 4 ) ],
"frames": [ ExtResource( 2 ), ExtResource( 3 ) ],
"loop": true,
"name": "LEFT",
"speed": 5.0
}, {
"frames": [ ExtResource( 5 ), ExtResource( 6 ) ],
"frames": [ ExtResource( 4 ), ExtResource( 5 ) ],
"loop": true,
"name": "RIGHT",
"speed": 5.0
}, {
"frames": [ ExtResource( 7 ), ExtResource( 8 ) ],
"frames": [ ExtResource( 6 ), ExtResource( 7 ) ],
"loop": true,
"name": "UP",
"speed": 5.0
}, {
"frames": [ ExtResource( 9 ), ExtResource( 10 ) ],
"frames": [ ExtResource( 8 ), ExtResource( 9 ) ],
"loop": true,
"name": "DOWN",
"speed": 5.0
} ]

[sub_resource type="CircleShape2D" id=3]
radius = 246.873
radius = 148.282

[node name="Enemy1" type="Node2D"]

[node name="Enemy1" type="RigidBody2D" parent="."]
mode = 2
gravity_scale = 0.0
script = ExtResource( 1 )

[node name="KinematicEnemy1" type="KinematicBody2D" parent="."]
script = ExtResource( 2 )
script = ExtResource( 1 )

[node name="CollisionShape2D" type="CollisionShape2D" parent="KinematicEnemy1"]
shape = SubResource( 1 )
Expand All @@ -58,9 +53,14 @@ shape = SubResource( 1 )
frames = SubResource( 2 )
animation = "RIGHT"

[node name="Body" type="Area2D" parent="KinematicEnemy1"]
[node name="Body" type="Area2D" parent="KinematicEnemy1" groups=[
"noheavy",
]]
script = ExtResource( 10 )

[node name="CollisionShape2D2" type="CollisionShape2D" parent="KinematicEnemy1/Body"]
position = Vector2( -0.71698, 0 )
shape = SubResource( 3 )

[connection signal="area_entered" from="KinematicEnemy1/Body" to="KinematicEnemy1/Body" method="_on_Body_area_entered"]
[connection signal="area_exited" from="KinematicEnemy1/Body" to="KinematicEnemy1/Body" method="_on_Body_area_exited"]
23 changes: 13 additions & 10 deletions KinematicEnemy1.gd
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
extends KinematicBody2D

var IsPlayerNear = false
var SPEED = 120
var PlayerPos = Vector2(0,0)

var SPEED = 150
func _physics_process(delta):
if(IsPlayerNear == true):
PlayerPos.x = $"../../../../KinematicPlayer".global_position.x - self.global_position.x
PlayerPos.y = $"../../../../KinematicPlayer".global_position.y - self.global_position.y
var motion = PlayerPos.normalized() * SPEED
move_and_slide(motion, Vector2(0,0))



func _physics_process(delta):

var MOVE = Vector2()
var body = get_node("Body").get_overlapping_bodies()
func attack():
IsPlayerNear = true

if(body.size() != 0):
for tinge in body:
if(tinge.is_in_group("player")):
print('kek')
#if(tinge.global_position().x < self.global_position().x):
# print('good')
func stop_attack():
IsPlayerNear = false
6 changes: 5 additions & 1 deletion levels/FreeWorld.tscn
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[gd_scene load_steps=3 format=2]
[gd_scene load_steps=4 format=2]

[ext_resource path="res://tiles/16x16-tiles.tres" type="TileSet" id=1]
[ext_resource path="res://Enemy1.tscn" type="PackedScene" id=2]

[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 17.1977, 4.73711 )
Expand All @@ -24,3 +25,6 @@ position = Vector2( 269, 238 )
position = Vector2( 0.252991, -14.933 )
shape = SubResource( 1 )

[node name="Enemy1" parent="." instance=ExtResource( 2 )]
position = Vector2( 870.453, 419.867 )

1 change: 0 additions & 1 deletion player/BulletArea.gd
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ func _on_BulletArea_area_entered(area): # Если в зону файрболл

func _on_BulletArea_body_entered(body):
var groups = body.get_groups()

if(!(groups.has("noheavy"))):
remove_from_group("bullet")
boom()
Expand Down
4 changes: 3 additions & 1 deletion player/KinematicPlayer.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ tracks/0/keys = {
extents = Vector2( 5.94487, 7.99627 )

[node name="KinematicPlayer" type="KinematicBody2D"]
position = Vector2( 655.295, 361.761 )
script = ExtResource( 1 )

[node name="anim" type="AnimationPlayer" parent="."]
Expand Down Expand Up @@ -239,9 +240,10 @@ frame = 8
shape = SubResource( 13 )

[node name="Camera2D" type="Camera2D" parent="."]
visible = false
current = true
zoom = Vector2( 0.6, 0.6 )
smoothing_enabled = true
editor_draw_drag_margin = true

[node name="player1_area" type="Area2D" parent="." groups=[
"player",
Expand Down
2 changes: 2 additions & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,6 @@ ui_use={

[rendering]

quality/intended_usage/framebuffer_allocation.mobile=0
quality/2d/use_pixel_snap=true
environment/default_environment="res://default_env.tres"

0 comments on commit b26436a

Please sign in to comment.