Fixed the random position move state

This commit is contained in:
Paul Norberger
2020-04-20 14:39:51 +02:00
parent 37ccf67677
commit efacd63543
8 changed files with 117 additions and 24 deletions

View File

@@ -477,11 +477,11 @@ one_shot = true
script = ExtResource( 12 )
[node name="Sprite" type="Sprite" parent="."]
position = Vector2( 0, -28 )
texture = ExtResource( 5 )
vframes = 10
hframes = 24
frame = 2
position = Vector2( -5, -28 )
texture = ExtResource( 6 )
vframes = 7
hframes = 11
frame = 50
[node name="Hitbox" parent="." instance=ExtResource( 2 )]
visible = false

View File

@@ -0,0 +1,20 @@
extends "res://Overlap/StateMachine/State.gd"
onready var animation_player = owner.get_node("AnimationPlayer")
onready var animation_tree = owner.get_node("AnimationTree")
onready var animation_playback = animation_tree.get("parameters/playback")
var _animation_type = ANIMATION_TYPE.TREE
enum ANIMATION_TYPE {
PLAYER,
TREE
}
func set_animation_type(val):
print("wow")
_animation_type = val
animation_player.playback_active = _animation_type == ANIMATION_TYPE.PLAYER
animation_tree.active = _animation_type == ANIMATION_TYPE.TREE

View File

@@ -0,0 +1,23 @@
extends "res://Boss/SlimeBoss/States/BossState.gd"
export(float) var SPEED = 1000.0
var player_pos = owner.get_parent().get_node("Player").global_position
var direction = Vector2()
func enter():
# Set animation
set_animation_type(ANIMATION_TYPE.TREE)
animation_playback.play("move")
direction = (player_pos - owner.global_position).normalized()
owner.set_particles_active(true)
func exit():
owner.set_particles_active(false)
func update(delta):
owner.move_and_slide(SPEED * direction)
if owner.get_slide_count() > 0 or owner.position.x > 1800:
emit_signal('finished')

View File

@@ -1,7 +1,4 @@
extends "res://Overlap/StateMachine/State.gd"
onready var animation_player = owner.get_node("AnimationPlayer")
onready var animation_tree = owner.get_node("AnimationTree")
extends "BossState.gd"
func enter():
animation_tree.active = false

View File

@@ -1,28 +1,35 @@
extends "res://Overlap/StateMachine/State.gd"
extends "../BossState.gd"
export(float) var ARRIVE_DISTANCE = 6.0
export(float) var SLOW_RADIUS = 200.0
export(float) var MASS = 4.0
export(float) var MASS = 5.0
export(float) var MAX_SPEED = 300.0
export(float) var ROAM_RADIUS = 150.0
export(float) var ROAM_RADIUS = 200.0
var time_since_start = 0
var target_position = Vector2()
var start_position = Vector2()
var velocity = Vector2()
var last_vel = Vector2()
func enter():
# Set animation
set_animation_type(ANIMATION_TYPE.TREE)
animation_playback.start("move")
time_since_start = 0
start_position = get_parent().start_position
target_position = calculate_new_target_position()
owner.get_node('AnimationPlayer').play('move')
func update(delta):
velocity = Steering.arrive_to(velocity, owner.global_position, target_position, MASS, SLOW_RADIUS, MAX_SPEED)
owner.move_and_slide(velocity)
time_since_start += delta
last_vel = owner.move_and_slide(velocity)
animation_tree.set("parameters/move/blend_position", last_vel)
if owner.global_position.distance_to(target_position) < ARRIVE_DISTANCE:
if owner.global_position.distance_to(target_position) < ARRIVE_DISTANCE or time_since_start > 2.0:
emit_signal('finished')

View File

@@ -1,7 +1,8 @@
extends "res://Overlap/StateMachine/State.gd"
extends "res://Boss/SlimeBoss/States/BossState.gd"
func enter():
owner.get_node('AnimationPlayer').play('idle')
set_animation_type(ANIMATION_TYPE.PLAYER)
# owner.get_node('AnimationPlayer').play('idle')
$Timer.start()
func update(delta):

View File

@@ -619,19 +619,17 @@ height = 0.2
radius = 4.03497
height = 9.42006
[sub_resource type="CircleShape2D" id=51]
[sub_resource type="CircleShape2D" id=49]
radius = 13.3924
[sub_resource type="DynamicFont" id=50]
size = 12
font_data = ExtResource( 6 )
[node name="Player" type="KinematicBody2D" groups=[
"hero",
]]
collision_mask = 14
script = ExtResource( 1 )
ROLL_SPEED = 120
FRICTION = 270
@@ -724,7 +722,7 @@ damage = 0.0
[node name="CollisionShape2D" parent="Pivot/SwordRange" index="0"]
position = Vector2( 0, -4.56405 )
shape = SubResource( 51 )
shape = SubResource( 49 )
[node name="DebugLabel" type="Label" parent="."]
margin_left = -8.12021

View File

@@ -1,4 +1,4 @@
[gd_scene load_steps=11 format=2]
[gd_scene load_steps=13 format=2]
[ext_resource path="res://Player/Player.tscn" type="PackedScene" id=1]
[ext_resource path="res://World.gd" type="Script" id=2]
@@ -8,7 +8,9 @@
[ext_resource path="res://Menus/DialogueBox/DialogueBox.tscn" type="PackedScene" id=6]
[ext_resource path="res://Maps/Background/Background.tscn" type="PackedScene" id=7]
[ext_resource path="res://Boss/SlimeBoss/SlimeBoss.tscn" type="PackedScene" id=8]
[ext_resource path="res://Fonts/Harmonic/Harmonic12.tres" type="DynamicFont" id=9]
[ext_resource path="res://Objects/Bonfire/Bonfire.tscn" type="PackedScene" id=10]
[ext_resource path="res://Debug/BossStateDisplay.gd" type="Script" id=11]
[ext_resource path="res://Maps/Grid.tscn" type="PackedScene" id=18]
[node name="World" type="Node2D"]
@@ -21,7 +23,7 @@ region_enabled = true
region_rect = Rect2( 0, 0, 1280, 720 )
[node name="Background" parent="." instance=ExtResource( 7 )]
frame = 20
frame = 50
[node name="FloorTileMap" type="TileMap" parent="."]
visible = false
@@ -45,6 +47,7 @@ position = Vector2( 265.543, -16 )
[node name="Player" parent="YSort" instance=ExtResource( 1 )]
position = Vector2( 344, 125.768 )
scale = Vector2( 2, 2 )
debug = true
ROLL_SPEED = 140
FRICTION = 200
@@ -59,3 +62,47 @@ position = Vector2( 104, 80 )
visible = false
[node name="DragNDropUI" parent="CanvasLayer" instance=ExtResource( 5 )]
[node name="DebugLabel" type="Control" parent="CanvasLayer"]
anchor_right = 1.0
anchor_bottom = 1.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="BossStateDisplay" type="Panel" parent="CanvasLayer/DebugLabel"]
anchor_left = 1.0
anchor_right = 1.0
margin_left = -80.0
margin_bottom = 50.0
script = ExtResource( 11 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="VBoxContainer" type="VBoxContainer" parent="CanvasLayer/DebugLabel/BossStateDisplay"]
margin_right = 40.0
margin_bottom = 40.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Title" type="Label" parent="CanvasLayer/DebugLabel/BossStateDisplay/VBoxContainer"]
margin_right = 40.0
margin_bottom = 12.0
custom_fonts/font = ExtResource( 9 )
text = "Boss"
[node name="Phase" type="Label" parent="CanvasLayer/DebugLabel/BossStateDisplay/VBoxContainer"]
margin_top = 16.0
margin_right = 40.0
margin_bottom = 28.0
custom_fonts/font = ExtResource( 9 )
[node name="State" type="Label" parent="CanvasLayer/DebugLabel/BossStateDisplay/VBoxContainer"]
margin_top = 32.0
margin_right = 40.0
margin_bottom = 44.0
custom_fonts/font = ExtResource( 9 )
[connection signal="phase_changed" from="YSort/SlimeBoss" to="CanvasLayer/DebugLabel/BossStateDisplay" method="_on_SlimeBoss_phase_changed"]
[connection signal="state_changed" from="YSort/SlimeBoss" to="CanvasLayer/DebugLabel/BossStateDisplay" method="_on_SlimeBoss_state_changed"]