finish squig behavior
This commit is contained in:
parent
8b3a5f88a4
commit
5f3d907c3f
4 changed files with 177 additions and 7 deletions
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=26 format=2]
|
||||
[gd_scene load_steps=27 format=2]
|
||||
|
||||
[ext_resource path="res://maps/map.gd" type="Script" id=1]
|
||||
[ext_resource path="res://objects/hud/hud.tscn" type="PackedScene" id=2]
|
||||
|
@ -13,6 +13,7 @@
|
|||
[ext_resource path="res://objects/enemy/mine.tscn" type="PackedScene" id=11]
|
||||
[ext_resource path="res://scripts/random_spawner.gd" type="Script" id=12]
|
||||
[ext_resource path="res://objects/environment/bubble/bubble.tscn" type="PackedScene" id=13]
|
||||
[ext_resource path="res://objects/enemy/squig.tscn" type="PackedScene" id=14]
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id=12]
|
||||
blend_mode = 3
|
||||
|
@ -212,7 +213,7 @@ shape = SubResource( 8 )
|
|||
tile_set = SubResource( 6 )
|
||||
cell_size = Vector2( 8, 8 )
|
||||
format = 1
|
||||
tile_data = PoolIntArray( 393233, 0, 196608, 458752, 0, 65536, 458753, 0, 65537, 458754, 0, 65537, 458755, 0, 65537, 458756, 0, 65537, 458757, 0, 65537, 458758, 0, 65538, 458769, 0, 196608, 458770, 0, 0, 458771, 0, 0, 524302, 0, 0, 524303, 0, 0, 524305, 0, 196608, 589835, 0, 0, 589841, 0, 196608, 655368, 0, 0, 655377, 0, 196608, 720913, 0, 196608, 786449, 0, 196608, 851976, 0, 0, 851977, 0, 0, 851978, 0, 0, 851979, 0, 0, 851980, 0, 0, 851981, 0, 0, 851982, 0, 0, 851983, 0, 0, 851984, 0, 0, 851985, 0, 0, 851986, 0, 0, 851987, 0, 0, 917511, 0, 0, 917512, 0, 0, 917513, 0, 0, 917514, 0, 0, 917515, 0, 0, 917516, 0, 0, 917517, 0, 0, 917518, 0, 0, 917519, 0, 0, 917520, 0, 0, 917521, 0, 0, 917522, 0, 0, 983048, 0, 0, 983049, 0, 0, 983050, 0, 0, 983051, 0, 0, 983052, 0, 0, 983053, 0, 0, 983054, 0, 0, 983055, 0, 0, 983056, 0, 0, 983057, 0, 0, 983058, 0, 0, 1048586, 0, 0, 1048587, 0, 0, 1048588, 0, 0, 1048589, 0, 0, 1048590, 0, 0, 1048591, 0, 0, 1048592, 0, 0, 1048593, 0, 0, 1114124, 0, 0, 1114125, 0, 0, 1114126, 0, 0, 1114127, 0, 0, 1114128, 0, 0 )
|
||||
tile_data = PoolIntArray( 393233, 0, 196608, 458752, 0, 65536, 458753, 0, 65537, 458754, 0, 65537, 458755, 0, 65537, 458756, 0, 65537, 458757, 0, 65537, 458758, 0, 65538, 458769, 0, 196608, 458770, 0, 0, 458771, 0, 0, 524302, 0, 0, 524303, 0, 0, 524305, 0, 196608, 589835, 0, 0, 589841, 0, 196608, 655368, 0, 0, 655377, 0, 196608, 720913, 0, 196608, 786449, 0, 196608, 851976, 0, 0, 851977, 0, 0, 851978, 0, 0, 851979, 0, 0, 851980, 0, 0, 851981, 0, 0, 851982, 0, 0, 851983, 0, 0, 851984, 0, 0, 851985, 0, 0, 851986, 0, 0, 851987, 0, 0, 917511, 0, 0, 917512, 0, 0, 917513, 0, 0, 917514, 0, 0, 917515, 0, 0, 917516, 0, 0, 917517, 0, 0, 917518, 0, 0, 917519, 0, 0, 917520, 0, 0, 917521, 0, 0, 917522, 0, 0, 983048, 0, 0, 983049, 0, 0, 983050, 0, 0, 983051, 0, 0, 983052, 0, 0, 983053, 0, 0, 983054, 0, 0, 983055, 0, 0, 983056, 0, 0, 983057, 0, 0, 983058, 0, 0, 1048586, 0, 0, 1048587, 0, 0, 1048588, 0, 0, 1048589, 0, 0, 1048590, 0, 0, 1048591, 0, 0, 1048592, 0, 0, 1048593, 0, 0, 1114124, 0, 0, 1114125, 0, 0, 1114126, 0, 0, 1114127, 0, 0, 1114128, 0, 0, 2228243, 0, 0, 2228244, 0, 0, 2228245, 0, 0, 2228246, 0, 0, 2228247, 0, 0, 2228248, 0, 0, 2228249, 0, 0, 2228250, 0, 0, 2293787, 0, 0, 2359307, 0, 0, 2359308, 0, 0, 2424836, 0, 0, 2424837, 0, 0, 2424838, 0, 0, 2424839, 0, 0, 2424840, 0, 0, 2424841, 0, 0, 2424842, 0, 0 )
|
||||
|
||||
[node name="Ladders" type="Node2D" parent="."]
|
||||
|
||||
|
@ -235,3 +236,13 @@ position = Vector2( 144, 24 )
|
|||
|
||||
[node name="Mine4" parent="Enemies/Mines" instance=ExtResource( 11 )]
|
||||
position = Vector2( 72, 48 )
|
||||
|
||||
[node name="Squig" parent="." instance=ExtResource( 14 )]
|
||||
position = Vector2( 176, 152 )
|
||||
|
||||
[node name="Squig2" parent="." instance=ExtResource( 14 )]
|
||||
position = Vector2( 48, 272 )
|
||||
|
||||
[node name="Squig3" parent="." instance=ExtResource( 14 )]
|
||||
position = Vector2( 176, 312 )
|
||||
start_falling = true
|
||||
|
|
|
@ -132,13 +132,13 @@ position = Vector2( 48, 120 )
|
|||
|
||||
[node name="AnimatedSprite" parent="RollingFiend" index="0"]
|
||||
visible = false
|
||||
frame = 1
|
||||
|
||||
[node name="SawTest2" type="AnimatedSprite" parent="RollingFiend"]
|
||||
material = SubResource( 4 )
|
||||
position = Vector2( 4, 4 )
|
||||
z_index = -3
|
||||
frames = SubResource( 5 )
|
||||
frame = 1
|
||||
playing = true
|
||||
|
||||
[node name="Steam" parent="." instance=ExtResource( 23 )]
|
||||
|
@ -168,6 +168,6 @@ position = Vector2( 152, 72 )
|
|||
position = Vector2( 112, 176 )
|
||||
|
||||
[node name="Squig" parent="." instance=ExtResource( 1 )]
|
||||
position = Vector2( 128, 160 )
|
||||
position = Vector2( 128, 152 )
|
||||
|
||||
[editable path="RollingFiend"]
|
||||
|
|
|
@ -1,13 +1,104 @@
|
|||
extends "res://objects/enemy/enemy.gd"
|
||||
|
||||
enum State {SWIMMING, FALLING, TRANSITION}
|
||||
|
||||
# whether the squid should start in falling state
|
||||
export var start_falling: bool = false
|
||||
export var speed: float = 50.0
|
||||
export var damping: float = 0.9
|
||||
export var delay: float = 1.0
|
||||
# margin of screen hitbox is disabled in
|
||||
export var hitbox_clip: Rect2 = Rect2(0.0, 0.0, 7.0, 7.0)
|
||||
export var full_clip: Rect2 = Rect2(-4.0, -4.0, 16.0, 16.0)
|
||||
|
||||
|
||||
var velocity: Vector2 = Vector2.ZERO
|
||||
# start of the sector it is trapped in
|
||||
var home_sector: Vector2 = Vector2.ZERO
|
||||
var _can_transition: bool = true
|
||||
|
||||
|
||||
onready var current_state: int = State.SWIMMING
|
||||
onready var hitbox_shape: CollisionShape2D = $"%HitboxShape"
|
||||
onready var animation_player: AnimationPlayer = $AnimationPlayer
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
if start_falling:
|
||||
_start_falling()
|
||||
else:
|
||||
_start_swimming()
|
||||
home_sector = Game.get_sector(global_position)
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if Game.current_sector != home_sector:
|
||||
hitbox_shape.disabled = true
|
||||
return
|
||||
# process movement and apply damping
|
||||
velocity.y *= pow(damping, delta)
|
||||
if current_state == State.FALLING:
|
||||
velocity.y = speed
|
||||
global_position += velocity * delta
|
||||
|
||||
var sector_rect = Rect2(home_sector * Game.resolution, Game.resolution)
|
||||
|
||||
# disable hitbox at edge of screen
|
||||
var global_hitbox_clip = hitbox_clip
|
||||
global_hitbox_clip.position += global_position
|
||||
if sector_rect.encloses(global_hitbox_clip):
|
||||
hitbox_shape.disabled = false
|
||||
else:
|
||||
hitbox_shape.disabled = true
|
||||
|
||||
# check if out of sector
|
||||
var global_full_clip = full_clip
|
||||
global_full_clip.position += global_position
|
||||
if not sector_rect.intersects(global_full_clip) and _can_transition:
|
||||
match current_state:
|
||||
State.SWIMMING:
|
||||
current_state = State.TRANSITION
|
||||
_can_transition = false
|
||||
velocity = Vector2.ZERO
|
||||
var tween = create_tween()
|
||||
tween.tween_interval(delay)
|
||||
tween.tween_callback(self, "_start_falling")
|
||||
State.FALLING:
|
||||
current_state = State.TRANSITION
|
||||
_can_transition = false
|
||||
velocity = Vector2.ZERO
|
||||
var tween = create_tween()
|
||||
tween.tween_interval(delay)
|
||||
tween.tween_callback(self, "_start_swimming")
|
||||
State.TRANSITION:
|
||||
pass
|
||||
|
||||
# clip to inside of home sector
|
||||
var rid = get_canvas_item()
|
||||
var rect = Rect2(to_local(home_sector * Game.resolution), Game.resolution)
|
||||
VisualServer.canvas_item_set_custom_rect(rid, true, rect)
|
||||
VisualServer.canvas_item_set_clip(rid, true)
|
||||
|
||||
|
||||
# give a burst of speed
|
||||
func _propel() -> void:
|
||||
velocity.y = -speed
|
||||
|
||||
func _start_falling() -> void:
|
||||
if not _can_transition:
|
||||
var player = get_tree().get_nodes_in_group("player").pop_back()
|
||||
if player != null:
|
||||
global_position.x = player.global_position.x
|
||||
animation_player.play("falling")
|
||||
current_state = State.FALLING
|
||||
yield(create_tween().tween_interval(1.0), "finished")
|
||||
_can_transition = true
|
||||
|
||||
func _start_swimming() -> void:
|
||||
if not _can_transition:
|
||||
var player = get_tree().get_nodes_in_group("player").pop_back()
|
||||
if player != null:
|
||||
global_position.x = player.global_position.x
|
||||
animation_player.play("swimming")
|
||||
current_state = State.SWIMMING
|
||||
yield(create_tween().tween_interval(1.0), "finished")
|
||||
_can_transition = true
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
[gd_scene load_steps=7 format=2]
|
||||
[gd_scene load_steps=8 format=2]
|
||||
|
||||
[ext_resource path="res://objects/enemy/squig.gd" type="Script" id=1]
|
||||
[ext_resource path="res://graphics/enemy/squig.png" type="Texture" id=2]
|
||||
[ext_resource path="res://graphics/particles/dust.png" type="Texture" id=3]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id=1]
|
||||
extents = Vector2( 3.5, 3.5 )
|
||||
extents = Vector2( 2.5, 2.5 )
|
||||
|
||||
[sub_resource type="Animation" id=2]
|
||||
length = 0.001
|
||||
|
@ -33,6 +33,58 @@ tracks/1/keys = {
|
|||
"update": 0,
|
||||
"values": [ false ]
|
||||
}
|
||||
tracks/2/type = "value"
|
||||
tracks/2/path = NodePath("Sprite:scale")
|
||||
tracks/2/interp = 1
|
||||
tracks/2/loop_wrap = true
|
||||
tracks/2/imported = false
|
||||
tracks/2/enabled = true
|
||||
tracks/2/keys = {
|
||||
"times": PoolRealArray( 0 ),
|
||||
"transitions": PoolRealArray( 1 ),
|
||||
"update": 0,
|
||||
"values": [ Vector2( 1, 1 ) ]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id=5]
|
||||
resource_name = "falling"
|
||||
length = 0.001
|
||||
tracks/0/type = "value"
|
||||
tracks/0/path = NodePath("Sprite:frame")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/keys = {
|
||||
"times": PoolRealArray( 0 ),
|
||||
"transitions": PoolRealArray( 1 ),
|
||||
"update": 1,
|
||||
"values": [ 1 ]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/path = NodePath("Sprite:scale")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/keys = {
|
||||
"times": PoolRealArray( 0 ),
|
||||
"transitions": PoolRealArray( 1 ),
|
||||
"update": 0,
|
||||
"values": [ Vector2( 1, -1 ) ]
|
||||
}
|
||||
tracks/2/type = "value"
|
||||
tracks/2/path = NodePath("InkParticles:emitting")
|
||||
tracks/2/interp = 1
|
||||
tracks/2/loop_wrap = true
|
||||
tracks/2/imported = false
|
||||
tracks/2/enabled = true
|
||||
tracks/2/keys = {
|
||||
"times": PoolRealArray( 0 ),
|
||||
"transitions": PoolRealArray( 1 ),
|
||||
"update": 1,
|
||||
"values": [ true ]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id=4]
|
||||
resource_name = "swimming"
|
||||
|
@ -76,8 +128,21 @@ tracks/2/keys = {
|
|||
"method": "_propel"
|
||||
} ]
|
||||
}
|
||||
tracks/3/type = "value"
|
||||
tracks/3/path = NodePath("Sprite:scale")
|
||||
tracks/3/interp = 1
|
||||
tracks/3/loop_wrap = true
|
||||
tracks/3/imported = false
|
||||
tracks/3/enabled = true
|
||||
tracks/3/keys = {
|
||||
"times": PoolRealArray( 0 ),
|
||||
"transitions": PoolRealArray( 1 ),
|
||||
"update": 0,
|
||||
"values": [ Vector2( 1, 1 ) ]
|
||||
}
|
||||
|
||||
[node name="Squig" type="Node2D" groups=["enemy"]]
|
||||
light_mask = 8
|
||||
script = ExtResource( 1 )
|
||||
damping = 0.5
|
||||
|
||||
|
@ -96,6 +161,7 @@ damping = 4.0
|
|||
color = Color( 0, 0, 0, 1 )
|
||||
|
||||
[node name="Sprite" type="Sprite" parent="."]
|
||||
light_mask = 8
|
||||
position = Vector2( 4, 4 )
|
||||
texture = ExtResource( 2 )
|
||||
hframes = 2
|
||||
|
@ -103,13 +169,15 @@ hframes = 2
|
|||
[node name="Hitbox" type="Area2D" parent="." groups=["enemy_hitbox"]]
|
||||
position = Vector2( 4, 4 )
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Hitbox"]
|
||||
[node name="HitboxShape" type="CollisionShape2D" parent="Hitbox"]
|
||||
unique_name_in_owner = true
|
||||
position = Vector2( -0.5, -0.5 )
|
||||
shape = SubResource( 1 )
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
||||
autoplay = "swimming"
|
||||
anims/RESET = SubResource( 2 )
|
||||
anims/falling = SubResource( 5 )
|
||||
anims/swimming = SubResource( 4 )
|
||||
|
||||
[connection signal="area_entered" from="Hitbox" to="." method="_on_Hitbox_area_entered"]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue