Scuffed caterpillar enemy
This commit is contained in:
parent
ec1dac9453
commit
8a7df91bc1
@ -3,7 +3,7 @@ extends Camera2D
|
|||||||
var horizontal_facing = 0
|
var horizontal_facing = 0
|
||||||
var vertical_facing = 0
|
var vertical_facing = 0
|
||||||
var camera_horizontal_shift = 90
|
var camera_horizontal_shift = 90
|
||||||
var camera_vertical_shift = 90
|
var camera_vertical_shift = 0
|
||||||
var time: float = 0
|
var time: float = 0
|
||||||
|
|
||||||
onready var tween = $ShiftTween
|
onready var tween = $ShiftTween
|
||||||
@ -62,18 +62,18 @@ func _adapt_to_movement():
|
|||||||
# TODO Make smarter
|
# TODO Make smarter
|
||||||
if(time > 0.1):
|
if(time > 0.1):
|
||||||
time = 0.0
|
time = 0.0
|
||||||
var cam_offset = get_camera_screen_center().x - prev_camera_pos.x
|
var cam_offset = get_camera_screen_center() - prev_camera_pos
|
||||||
var new_h_facing = sign(cam_offset)
|
var new_h_facing = sign(cam_offset.x)
|
||||||
if new_h_facing != 0 && horizontal_facing != new_h_facing:
|
if new_h_facing != 0 && horizontal_facing != new_h_facing:
|
||||||
horizontal_facing = new_h_facing
|
horizontal_facing = new_h_facing
|
||||||
target_offset.x = camera_horizontal_shift * horizontal_facing
|
target_offset.x = camera_horizontal_shift * horizontal_facing
|
||||||
tween_h = true
|
tween_h = true
|
||||||
|
|
||||||
# var new_v_facing = sign(get_camera_position().y - prev_camera_pos.y)
|
# var new_v_facing = sign(cam_offset.y)
|
||||||
# if new_v_facing != 0 && vertical_facing != new_v_facing:
|
# if new_v_facing != 0 && vertical_facing != new_v_facing:
|
||||||
# vertical_facing = new_v_facing
|
# vertical_facing = new_v_facing
|
||||||
|
# target_offset.x = offset.x if !new_h_facing else target_offset.x
|
||||||
# target_offset.y = camera_vertical_shift * vertical_facing
|
# target_offset.y = camera_vertical_shift * vertical_facing
|
||||||
# print(target_offset)
|
|
||||||
# tween_v = true
|
# tween_v = true
|
||||||
|
|
||||||
prev_camera_pos = get_camera_screen_center()
|
prev_camera_pos = get_camera_screen_center()
|
||||||
@ -88,7 +88,6 @@ func _adapt_to_movement():
|
|||||||
Tween.TRANS_SINE,
|
Tween.TRANS_SINE,
|
||||||
Tween.EASE_OUT
|
Tween.EASE_OUT
|
||||||
)
|
)
|
||||||
|
|
||||||
tween.start()
|
tween.start()
|
||||||
position = blobby.position
|
position = blobby.position
|
||||||
|
|
||||||
|
|||||||
@ -273,6 +273,8 @@ zoom = Vector2( 0.75, 0.75 )
|
|||||||
process_mode = 0
|
process_mode = 0
|
||||||
drag_margin_h_enabled = true
|
drag_margin_h_enabled = true
|
||||||
drag_margin_v_enabled = true
|
drag_margin_v_enabled = true
|
||||||
|
drag_margin_top = 0.0
|
||||||
|
drag_margin_bottom = 0.0
|
||||||
editor_draw_screen = false
|
editor_draw_screen = false
|
||||||
script = ExtResource( 1 )
|
script = ExtResource( 1 )
|
||||||
|
|
||||||
|
|||||||
39
src/Actors/Enemies/Beings/Caterpillar.gd
Normal file
39
src/Actors/Enemies/Beings/Caterpillar.gd
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
extends Player
|
||||||
|
|
||||||
|
export var score := 100
|
||||||
|
|
||||||
|
onready var left_rc = $SlopeRaycastLeft
|
||||||
|
onready var right_rc = $SlopeRaycastRight
|
||||||
|
|
||||||
|
var snap = Vector2.DOWN * 128
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
set_physics_process(false)
|
||||||
|
velocity.x = -30
|
||||||
|
|
||||||
|
|
||||||
|
# TODO adapt to groups
|
||||||
|
func _on_StompDetector_body_entered(body: Node) -> void:
|
||||||
|
if body.global_position.y > get_node("StompDetector").global_position.y:
|
||||||
|
return
|
||||||
|
get_node("EnemyBody").disabled = true
|
||||||
|
die()
|
||||||
|
|
||||||
|
func _physics_process(delta: float) -> void:
|
||||||
|
if(left_rc.is_colliding() && right_rc.is_colliding()):
|
||||||
|
var length_vector: Vector2 = right_rc.get_collision_point() - left_rc.get_collision_point()
|
||||||
|
rotation = length_vector.angle()
|
||||||
|
else:
|
||||||
|
print(rad2deg(rotation))
|
||||||
|
rotation += sign(velocity.x) * delta * 1.2
|
||||||
|
move_and_slide_with_snap(velocity.rotated(rotation), snap.rotated(rotation), FLOOR_NORMAL, false, 4, PI)
|
||||||
|
|
||||||
|
|
||||||
|
func die() -> void:
|
||||||
|
queue_free()
|
||||||
|
GlobalState.score += score
|
||||||
|
|
||||||
|
func _on_EnemySkin_area_entered(area:Area2D) -> void:
|
||||||
|
if area.is_in_group("harmful"):
|
||||||
|
get_node("EnemyBody").disabled = true
|
||||||
|
die()
|
||||||
70
src/Actors/Enemies/Beings/Caterpillar.tscn
Normal file
70
src/Actors/Enemies/Beings/Caterpillar.tscn
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
[gd_scene load_steps=6 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://assets/enemy/enemy.png" type="Texture" id=1]
|
||||||
|
[ext_resource path="res://src/Actors/Enemies/Beings/Caterpillar.gd" type="Script" id=2]
|
||||||
|
|
||||||
|
[sub_resource type="RectangleShape2D" id=1]
|
||||||
|
extents = Vector2( 2.72463, 1.17848 )
|
||||||
|
|
||||||
|
[sub_resource type="RectangleShape2D" id=2]
|
||||||
|
extents = Vector2( 15, 6.12039 )
|
||||||
|
|
||||||
|
[sub_resource type="RectangleShape2D" id=3]
|
||||||
|
extents = Vector2( 15.534, 10.0962 )
|
||||||
|
|
||||||
|
[node name="Caterpillar" type="KinematicBody2D" groups=["harmful"]]
|
||||||
|
scale = Vector2( 0.8, 0.8 )
|
||||||
|
collision_layer = 2
|
||||||
|
collision_mask = 9
|
||||||
|
script = ExtResource( 2 )
|
||||||
|
|
||||||
|
[node name="enemy" type="Sprite" parent="."]
|
||||||
|
position = Vector2( 0, -1.90735e-06 )
|
||||||
|
scale = Vector2( 0.286789, 0.276348 )
|
||||||
|
texture = ExtResource( 1 )
|
||||||
|
|
||||||
|
[node name="VisibilityEnabler2D" type="VisibilityEnabler2D" parent="."]
|
||||||
|
position = Vector2( 1362.81, -0.138177 )
|
||||||
|
scale = Vector2( 15.4865, 1.28502 )
|
||||||
|
rect = Rect2( -89, -10, 2, 20 )
|
||||||
|
process_parent = true
|
||||||
|
physics_process_parent = true
|
||||||
|
|
||||||
|
[node name="EnemyBody" type="CollisionShape2D" parent="." groups=["harmful"]]
|
||||||
|
position = Vector2( 0, 6.48802 )
|
||||||
|
scale = Vector2( 5.68128, 5.29182 )
|
||||||
|
shape = SubResource( 1 )
|
||||||
|
|
||||||
|
[node name="SlopeRaycastLeft" type="RayCast2D" parent="."]
|
||||||
|
position = Vector2( -11.25, 12.5 )
|
||||||
|
enabled = true
|
||||||
|
cast_to = Vector2( 0, 13.75 )
|
||||||
|
collision_mask = 8
|
||||||
|
|
||||||
|
[node name="SlopeRaycastRight" type="RayCast2D" parent="."]
|
||||||
|
position = Vector2( 11.25, 12.5 )
|
||||||
|
enabled = true
|
||||||
|
cast_to = Vector2( -9.53674e-07, 13.75 )
|
||||||
|
collision_mask = 8
|
||||||
|
|
||||||
|
[node name="StompDetector" type="Area2D" parent="." groups=["weakpoint"]]
|
||||||
|
modulate = Color( 0, 0.0392157, 1, 1 )
|
||||||
|
position = Vector2( 0, -6.44095 )
|
||||||
|
collision_layer = 2
|
||||||
|
input_pickable = false
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="StompDetector"]
|
||||||
|
position = Vector2( -4.76837e-07, 0.561345 )
|
||||||
|
shape = SubResource( 2 )
|
||||||
|
|
||||||
|
[node name="EnemySkin" type="Area2D" parent="." groups=["player"]]
|
||||||
|
process_priority = -1
|
||||||
|
collision_mask = 126
|
||||||
|
|
||||||
|
[node name="CollisionPolygon2D" type="CollisionShape2D" parent="EnemySkin"]
|
||||||
|
position = Vector2( -5.68434e-14, 0 )
|
||||||
|
scale = Vector2( 1.03, 1.04 )
|
||||||
|
shape = SubResource( 3 )
|
||||||
|
|
||||||
|
[connection signal="body_entered" from="StompDetector" to="." method="_on_StompDetector_body_entered"]
|
||||||
|
[connection signal="area_entered" from="EnemySkin" to="." method="_on_EnemySkin_area_entered"]
|
||||||
File diff suppressed because one or more lines are too long
@ -4,7 +4,7 @@
|
|||||||
[ext_resource path="res://assets/environment/blocks/24BlockBasic.png" type="Texture" id=2]
|
[ext_resource path="res://assets/environment/blocks/24BlockBasic.png" type="Texture" id=2]
|
||||||
[ext_resource path="res://src/UserInterface/UserInterface.tscn" type="PackedScene" id=3]
|
[ext_resource path="res://src/UserInterface/UserInterface.tscn" type="PackedScene" id=3]
|
||||||
[ext_resource path="res://src/ObstacleObjects/Spikes.tscn" type="PackedScene" id=4]
|
[ext_resource path="res://src/ObstacleObjects/Spikes.tscn" type="PackedScene" id=4]
|
||||||
[ext_resource path="res://src/Actors/Enemies/Beings/Enemy.tscn" type="PackedScene" id=5]
|
[ext_resource path="res://src/Actors/Enemies/Beings/Caterpillar.tscn" type="PackedScene" id=5]
|
||||||
[ext_resource path="res://src/Actors/Enemies/Beings/SimpleEnemy.tscn" type="PackedScene" id=6]
|
[ext_resource path="res://src/Actors/Enemies/Beings/SimpleEnemy.tscn" type="PackedScene" id=6]
|
||||||
[ext_resource path="res://src/Actors/Enemies/Beings/SmortEnemy.tscn" type="PackedScene" id=7]
|
[ext_resource path="res://src/Actors/Enemies/Beings/SmortEnemy.tscn" type="PackedScene" id=7]
|
||||||
[ext_resource path="res://src/Actors/Enemies/Beings/DartingEnemy.tscn" type="PackedScene" id=8]
|
[ext_resource path="res://src/Actors/Enemies/Beings/DartingEnemy.tscn" type="PackedScene" id=8]
|
||||||
@ -53,8 +53,8 @@ position = Vector2( -259.915, 710.547 )
|
|||||||
[node name="SmortEnemy" parent="." instance=ExtResource( 7 )]
|
[node name="SmortEnemy" parent="." instance=ExtResource( 7 )]
|
||||||
position = Vector2( 220, 804 )
|
position = Vector2( 220, 804 )
|
||||||
|
|
||||||
[node name="Enemy" parent="." instance=ExtResource( 5 )]
|
[node name="Caterpillar" parent="." instance=ExtResource( 5 )]
|
||||||
position = Vector2( 0, 780 )
|
position = Vector2( -41, 782 )
|
||||||
|
|
||||||
[node name="Enemy2" parent="." instance=ExtResource( 6 )]
|
[node name="Enemy2" parent="." instance=ExtResource( 6 )]
|
||||||
position = Vector2( 492, 804 )
|
position = Vector2( 492, 804 )
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user