Skip to content
This repository was archived by the owner on Nov 25, 2021. It is now read-only.

Commit 3764ff5

Browse files
committed
Optimize and clean up the scorpion
1 parent a56e788 commit 3764ff5

File tree

2 files changed

+15
-35
lines changed

2 files changed

+15
-35
lines changed

Enteties/Enemies/Scorpion/Scorpion.tscn

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,39 +38,22 @@ rect = Rect2( -30, 0, 60, 20 )
3838
process_parent = true
3939
physics_process_parent = true
4040

41-
[node name="FloorDetector" type="Node2D" parent="."]
42-
43-
[node name="Left" type="RayCast2D" parent="FloorDetector"]
44-
modulate = Color( 0, 1, 0.0392157, 1 )
45-
position = Vector2( -55, 40 )
41+
[node name="FloorDetector" type="RayCast2D" parent="."]
42+
position = Vector2( -50, 40 )
4643
enabled = true
47-
cast_to = Vector2( 0, 10 )
44+
cast_to = Vector2( 0, 15 )
4845
collision_mask = 8
4946

50-
[node name="Right" type="RayCast2D" parent="FloorDetector"]
51-
modulate = Color( 0, 1, 0.0392157, 1 )
52-
position = Vector2( 55, 40 )
53-
enabled = true
54-
cast_to = Vector2( 0, 10 )
55-
collision_mask = 2147483656
56-
5747
[node name="KillerInstinct" type="Area2D" parent="."]
5848

5949
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="KillerInstinct"]
6050
modulate = Color( 0, 0, 0, 1 )
6151
polygon = PoolVector2Array( -55.7638, 43.9623, 54.2375, 43.9623, 37.6812, -34.3294, 7.0941, -55.0949, -11.9877, -47.7989, -55.2025, 4.39556 )
6252

63-
[node name="PlayerRight" type="RayCast2D" parent="KillerInstinct"]
53+
[node name="Player" type="RayCast2D" parent="KillerInstinct"]
6454
modulate = Color( 0.486275, 0.0941176, 0.0941176, 1 )
6555
position = Vector2( 40, 30 )
6656
rotation = -1.5708
6757
enabled = true
6858
cast_to = Vector2( 0, 200 )
69-
70-
[node name="PlayerLeft" type="RayCast2D" parent="KillerInstinct"]
71-
modulate = Color( 0.486275, 0.0941176, 0.0941176, 1 )
72-
position = Vector2( -40, 30 )
73-
rotation = 1.5708
74-
enabled = true
75-
cast_to = Vector2( 0, 200 )
7659
[connection signal="body_entered" from="KillerInstinct" to="." method="_on_KillerInstinct_body_entered"]

Enteties/Enemies/Scorpion/scorpion.gd

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,28 @@ extends "res://Enteties/Enemies/enemy.gd"
22

33
export var enable_floor_detect = true
44

5-
onready var LeftD = $FloorDetector/Left
6-
onready var RightD = $FloorDetector/Right
5+
onready var Floor = $FloorDetector
6+
onready var Player = $KillerInstinct/Player
77
onready var ASprite = $AnimatedSprite
8-
onready var PlayerR = $KillerInstinct/PlayerRight
9-
onready var PlayerL = $KillerInstinct/PlayerLeft
108

119
onready var player = get_tree().get_root().find_node("Chameleon", true, false)
1210

1311
func _ready():
14-
if !enable_floor_detect:
15-
LeftD.enabled = false
16-
RightD.enabled = false
12+
Floor.enabled = enable_floor_detect
1713

1814
func _physics_process(delta: float):
1915
velocity.y += GRAVITY * delta
2016

21-
var need_turn = is_on_wall() or !LeftD.is_colliding() or !RightD.is_colliding()
22-
var sees_left = velocity.x == SPEED and !player.hidden and PlayerL.is_colliding()
23-
var sees_right = velocity.x == -SPEED and !player.hidden and PlayerR.is_colliding()
17+
var need_turn = is_on_wall() or (Floor.enabled and !Floor.is_colliding()) # Collision returns false if disabled for some reason
18+
var sees_player = !player.hidden and Player.is_colliding()
2419

25-
if !enable_floor_detect:
26-
need_turn = is_on_wall()
27-
28-
if need_turn or sees_left or sees_right:
20+
if !(need_turn == sees_player):
2921
velocity.x *= -1
22+
23+
# Need to flip the detection on changing direction
24+
Floor.position.x = -Floor.position.x
25+
Player.rotation_degrees = -Player.rotation_degrees
26+
Player.position.x = -Player.position.x
3027

3128
ASprite.flip_h = velocity.x > 0
3229
velocity.y = move_and_slide(velocity, UP).y

0 commit comments

Comments
 (0)