mirror of
https://github.com/creyD/ludum_dare_46.git
synced 2026-06-14 06:22:22 +02:00
AI API Interface
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
extends Player
|
extends KinematicBody2D
|
||||||
|
|
||||||
|
class_name Hero
|
||||||
|
|
||||||
const PrioQueue = preload("prio_queue.gd") # Relative path
|
const PrioQueue = preload("prio_queue.gd") # Relative path
|
||||||
const Grid = preload("res://Maps/Grid.gd")
|
const Grid = preload("res://Maps/Grid.gd")
|
||||||
@@ -195,25 +197,32 @@ func AStar(source, target):
|
|||||||
return [NOTHING, [0,0]]
|
return [NOTHING, [0,0]]
|
||||||
|
|
||||||
|
|
||||||
func makeMove():
|
func makeMove(delta):
|
||||||
match ExecutionState:
|
#match ExecutionState:
|
||||||
EXECUTING:
|
# EXECUTING:
|
||||||
pass
|
# pass
|
||||||
AI_MOVE:
|
# AI_MOVE:
|
||||||
var field = [0.1 * prios[Grid.Kind.BONFIRE], 1]
|
# var field = [0.1 * prios[Grid.Kind.BONFIRE], 1]
|
||||||
var decision = randf()
|
# var decision = randf()
|
||||||
var i = 0
|
## var i = 0
|
||||||
while field[i] > decision:
|
#while field[i] > decision:
|
||||||
i += 1
|
# i += 1
|
||||||
if (i == 0):
|
## if (i == 0):
|
||||||
var targetField = getTargetField(Grid.prio_grid)
|
# var targetField = getTargetField(Grid.prio_grid)
|
||||||
# Todo: move player
|
# run(targetField)
|
||||||
else:
|
# else:
|
||||||
pass
|
# pass
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
# API Interface for ai_hero -> methods are handled in player.gd
|
||||||
|
func attac(direction, delta):
|
||||||
|
pass
|
||||||
|
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
||||||
#func _process(delta):
|
func roll(direction, delta):
|
||||||
# pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
func run(direction, delta):
|
||||||
|
pass
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
extends KinematicBody2D
|
extends Hero
|
||||||
class_name Player
|
class_name Player
|
||||||
"""
|
"""
|
||||||
This is an example player controller script created by Paul
|
This is an example player controller script created by Paul
|
||||||
@@ -21,7 +21,8 @@ onready var animation_state = animation_tree.get("parameters/playback")
|
|||||||
enum moveState{
|
enum moveState{
|
||||||
MOVE,
|
MOVE,
|
||||||
ROLL,
|
ROLL,
|
||||||
HIT
|
HIT,
|
||||||
|
IDLE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -38,12 +39,12 @@ func _debug_update():
|
|||||||
|
|
||||||
|
|
||||||
func _physics_process(delta):
|
func _physics_process(delta):
|
||||||
totaldamage+=damage_per_second*delta
|
totaldamage += damage_per_second*delta
|
||||||
player_stats.speed+=10*delta
|
player_stats.speed += 10 * delta
|
||||||
while(totaldamage>1):
|
while(totaldamage>1):
|
||||||
totaldamage-=1
|
totaldamage -= 1
|
||||||
player_stats.health-=1
|
player_stats.health-=1
|
||||||
while(totaldamage<-1):
|
while(totaldamage < -1):
|
||||||
totaldamage+=1
|
totaldamage+=1
|
||||||
player_stats.health+=1
|
player_stats.health+=1
|
||||||
_debug_update()
|
_debug_update()
|
||||||
@@ -55,7 +56,15 @@ func _physics_process(delta):
|
|||||||
movement_roll()
|
movement_roll()
|
||||||
moveState.HIT:
|
moveState.HIT:
|
||||||
movement_hit()
|
movement_hit()
|
||||||
|
elif movementState == moveState.ROLL:
|
||||||
|
movement_roll()
|
||||||
|
elif movementState == moveState.HIT:
|
||||||
|
movement_hit()
|
||||||
|
elif movementState == moveState.IDLE:
|
||||||
|
movement_idle()
|
||||||
|
else:
|
||||||
|
movement_run(Vector2(0,0), delta)
|
||||||
|
makeMove(delta)
|
||||||
move()
|
move()
|
||||||
|
|
||||||
# IMPORTANT: If you are using move_and_slide don't multiply by delta
|
# IMPORTANT: If you are using move_and_slide don't multiply by delta
|
||||||
@@ -71,25 +80,35 @@ func set_animation_tree_vector():
|
|||||||
animation_tree.set("parameters/roll/blend_position", rollvector)
|
animation_tree.set("parameters/roll/blend_position", rollvector)
|
||||||
animation_tree.set("parameters/run/blend_position", rollvector)
|
animation_tree.set("parameters/run/blend_position", rollvector)
|
||||||
|
|
||||||
|
|
||||||
# API Interface for ai_hero
|
# API Interface for ai_hero
|
||||||
func attac(direction):
|
func attac(direction, delta):
|
||||||
|
direction = direction.normalized()
|
||||||
rollvector = direction
|
rollvector = direction
|
||||||
set_animation_tree_vector()
|
set_animation_tree_vector()
|
||||||
movementState = moveState.HIT
|
movementState = moveState.HIT
|
||||||
|
|
||||||
|
|
||||||
# API Interface for ai_hero
|
# API Interface for ai_hero
|
||||||
func roll(direction):
|
func roll(direction, delta):
|
||||||
|
direction = direction.normalized()
|
||||||
rollvector = direction
|
rollvector = direction
|
||||||
set_animation_tree_vector()
|
set_animation_tree_vector()
|
||||||
movementState = moveState.ROLL
|
movementState = moveState.ROLL
|
||||||
|
|
||||||
|
|
||||||
# API Interface for ai_hero
|
# API Interface for ai_hero
|
||||||
func run(direction):
|
func run(direction, delta):
|
||||||
|
direction = direction.normalized()
|
||||||
rollvector = direction
|
rollvector = direction
|
||||||
set_animation_tree_vector()
|
set_animation_tree_vector()
|
||||||
movementState = moveState.MOVE
|
movementState = moveState.MOVE
|
||||||
|
velocity = velocity.move_toward(player_stats.speed * rollvector, ACCELERATION * delta)
|
||||||
|
|
||||||
|
if direction == Vector2.ZERO:
|
||||||
|
animation_state.travel("idle")
|
||||||
|
else:
|
||||||
|
animation_state.travel("run")
|
||||||
|
|
||||||
|
|
||||||
func movement_move(delta):
|
func movement_move(delta):
|
||||||
@@ -108,10 +127,7 @@ func movement_move(delta):
|
|||||||
velocity = Vector2.ZERO
|
velocity = Vector2.ZERO
|
||||||
else:
|
else:
|
||||||
rollvector = input_vector
|
rollvector = input_vector
|
||||||
animation_tree.set("parameters/idle/blend_position", input_vector)
|
set_animation_tree_vector()
|
||||||
animation_tree.set("parameters/hit/blend_position", input_vector)
|
|
||||||
animation_tree.set("parameters/roll/blend_position", input_vector)
|
|
||||||
animation_tree.set("parameters/run/blend_position", input_vector)
|
|
||||||
animation_state.travel("run")
|
animation_state.travel("run")
|
||||||
velocity = velocity.move_toward(player_stats.speed * input_vector, ACCELERATION * delta)
|
velocity = velocity.move_toward(player_stats.speed * input_vector, ACCELERATION * delta)
|
||||||
if Input.is_action_just_pressed("roll"):
|
if Input.is_action_just_pressed("roll"):
|
||||||
@@ -119,19 +135,26 @@ func movement_move(delta):
|
|||||||
elif Input.is_action_just_pressed("attack"):
|
elif Input.is_action_just_pressed("attack"):
|
||||||
movementState = moveState.HIT
|
movementState = moveState.HIT
|
||||||
|
|
||||||
|
|
||||||
func movement_hit():
|
func movement_hit():
|
||||||
velocity = Vector2.ZERO
|
velocity = Vector2.ZERO
|
||||||
animation_state.travel("hit")
|
animation_state.travel("hit")
|
||||||
|
|
||||||
|
|
||||||
func hit_finished():
|
func hit_finished():
|
||||||
movementState = moveState.MOVE
|
movementState = moveState.IDLE
|
||||||
|
ExecutionState = AI_MOVE
|
||||||
|
|
||||||
|
|
||||||
func movement_roll():
|
func movement_roll():
|
||||||
velocity = rollvector * ROLL_SPEED
|
velocity = rollvector * ROLL_SPEED
|
||||||
animation_state.travel("roll")
|
animation_state.travel("roll")
|
||||||
|
ExecutionState = EXECUTING
|
||||||
|
|
||||||
|
|
||||||
func roll_finished():
|
func roll_finished():
|
||||||
movementState = moveState.MOVE
|
movementState = moveState.IDLE
|
||||||
|
ExecutionState = AI_MOVE
|
||||||
|
|
||||||
|
|
||||||
func _on_Hurtbox_area_entered(area):
|
func _on_Hurtbox_area_entered(area):
|
||||||
@@ -151,3 +174,13 @@ func _on_Hitbox_area_entered(area):
|
|||||||
currency += area.currency_value
|
currency += area.currency_value
|
||||||
player_stats.health = player_stats.health+area.health_value
|
player_stats.health = player_stats.health+area.health_value
|
||||||
player_stats.speed -= area.slowdown_value
|
player_stats.speed -= area.slowdown_value
|
||||||
|
|
||||||
|
|
||||||
|
func movement_run(direction, delta):
|
||||||
|
run(direction, delta)
|
||||||
|
|
||||||
|
|
||||||
|
func movement_idle():
|
||||||
|
movementState = moveState.IDLE
|
||||||
|
velocity = Vector2.ZERO
|
||||||
|
animation_state.travel("idle")
|
||||||
|
|||||||
@@ -684,7 +684,7 @@ shape = SubResource( 47 )
|
|||||||
|
|
||||||
[node name="Pivot" type="Position2D" parent="."]
|
[node name="Pivot" type="Position2D" parent="."]
|
||||||
position = Vector2( 0, -4.16248 )
|
position = Vector2( 0, -4.16248 )
|
||||||
rotation = 1.5708
|
rotation = 3.14159
|
||||||
__meta__ = {
|
__meta__ = {
|
||||||
"_gizmo_extents_": 20.0
|
"_gizmo_extents_": 20.0
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,9 +32,8 @@ __meta__ = {
|
|||||||
position = Vector2( 152, 120 )
|
position = Vector2( 152, 120 )
|
||||||
|
|
||||||
[node name="Player" parent="YSort" instance=ExtResource( 1 )]
|
[node name="Player" parent="YSort" instance=ExtResource( 1 )]
|
||||||
position = Vector2( 296, -32 )
|
position = Vector2( 84.2923, 24.0572 )
|
||||||
scale = Vector2( 2, 2 )
|
scale = Vector2( 2, 2 )
|
||||||
debug = true
|
|
||||||
FRICTION = 200
|
FRICTION = 200
|
||||||
|
|
||||||
[node name="Bonfire" parent="YSort" instance=ExtResource( 7 )]
|
[node name="Bonfire" parent="YSort" instance=ExtResource( 7 )]
|
||||||
|
|||||||
@@ -15,6 +15,11 @@ _global_script_classes=[ {
|
|||||||
"path": "res://Boss/Boss_template.gd"
|
"path": "res://Boss/Boss_template.gd"
|
||||||
}, {
|
}, {
|
||||||
"base": "KinematicBody2D",
|
"base": "KinematicBody2D",
|
||||||
|
"class": "Hero",
|
||||||
|
"language": "GDScript",
|
||||||
|
"path": "res://Overlap/AI/AI_Hero.gd"
|
||||||
|
}, {
|
||||||
|
"base": "Hero",
|
||||||
"class": "Player",
|
"class": "Player",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://Player/Player.gd"
|
"path": "res://Player/Player.gd"
|
||||||
@@ -31,6 +36,7 @@ _global_script_classes=[ {
|
|||||||
} ]
|
} ]
|
||||||
_global_script_class_icons={
|
_global_script_class_icons={
|
||||||
"Boss": "",
|
"Boss": "",
|
||||||
|
"Hero": "",
|
||||||
"Player": "",
|
"Player": "",
|
||||||
"TitleSceenButton": "",
|
"TitleSceenButton": "",
|
||||||
"TitleScreen": ""
|
"TitleScreen": ""
|
||||||
|
|||||||
Reference in New Issue
Block a user