ai movement, ai hit and move treshhold added

This commit is contained in:
Jonas Mucke
2020-04-20 14:38:58 +02:00
parent 37ccf67677
commit d60f93db3e
5 changed files with 52 additions and 31 deletions

View File

@@ -20,7 +20,7 @@ radius = 18.0
height = 18.0 height = 18.0
[sub_resource type="CapsuleShape2D" id=2] [sub_resource type="CapsuleShape2D" id=2]
radius = 18.0 radius = 20.0
height = 18.0 height = 18.0
[sub_resource type="CircleShape2D" id=3] [sub_resource type="CircleShape2D" id=3]
@@ -448,7 +448,7 @@ states/move/position = Vector2( 143, 70 )
[node name="SlimeBoss" type="KinematicBody2D"] [node name="SlimeBoss" type="KinematicBody2D"]
collision_layer = 4 collision_layer = 4
collision_mask = 3 collision_mask = 131
script = ExtResource( 4 ) script = ExtResource( 4 )
__meta__ = { __meta__ = {
"_edit_group_": true "_edit_group_": true
@@ -491,9 +491,11 @@ collision_layer = 4
position = Vector2( 0, -15 ) position = Vector2( 0, -15 )
shape = SubResource( 1 ) shape = SubResource( 1 )
[node name="Hurtbox" parent="." instance=ExtResource( 1 )] [node name="Hurtbox" parent="." groups=[
"HittableByPlayer",
] instance=ExtResource( 1 )]
collision_layer = 4 collision_layer = 4
collision_mask = 0 collision_mask = 128
[node name="CollisionShape2D" parent="Hurtbox" index="0"] [node name="CollisionShape2D" parent="Hurtbox" index="0"]
position = Vector2( 0, -15 ) position = Vector2( 0, -15 )

View File

@@ -45,7 +45,7 @@ shape = SubResource( 2 )
[node name="Hitbox" parent="." instance=ExtResource( 4 )] [node name="Hitbox" parent="." instance=ExtResource( 4 )]
collision_layer = 16 collision_layer = 16
damage = -0.5 damage = -1.5
[node name="CollisionShape2D" parent="Hitbox" index="0"] [node name="CollisionShape2D" parent="Hitbox" index="0"]
position = Vector2( 0, -2 ) position = Vector2( 0, -2 )

View File

@@ -33,9 +33,15 @@ var actionFieldUsed = false
var areaRefList = [] var areaRefList = []
var threadTime = 0.6 var threadTime = 0.4
var threadDelta = 0.0 var threadDelta = 0.0
var hitDelta = 0.0
var hitTreshhold = 0.1
var aiDelta = 0.0
var aiTreshhold = 0.4
#calculates the sum of all present prios #calculates the sum of all present prios
func calcTotalPrio(): func calcTotalPrio():
var sum = 0 var sum = 0
@@ -70,7 +76,7 @@ func calcPrioTable():
#14+7 0.999 #14+7 0.999
#updates heart and bonfire prio #updates heart and bonfire prio
func adjustPrio(currentHealth, maxHealth): func adjustPrio(currentHealth, maxHealth):
var prioVal = 10.0 - (float(currentHealth)/float(maxHealth))*10.0 var prioVal = 20.0 - (float(currentHealth)/float(maxHealth))*20.0
var bonfire = prioVal + 1 var bonfire = prioVal + 1
var hearts = prioVal var hearts = prioVal
if(hearts < 0): if(hearts < 0):
@@ -106,6 +112,7 @@ func getCost(field):
# curr - current position # curr - current position
# targ - a target position # targ - a target position
func h_fn(curr, target): func h_fn(curr, target):
var h = min(target[0]-curr[0],target[1]-curr[1])
return 0 return 0
# currCost - currentCost # currCost - currentCost
@@ -143,21 +150,25 @@ func adjacent(currentPosition, can_roll = true):
continue continue
if(grid.object_grid[next[0]][next[1]][0]!=Grid.Kind.WALL): if(grid.object_grid[next[0]][next[1]][0]!=Grid.Kind.WALL):
if(i==0): if(i==0):
continue
if(grid.object_grid[pot_adj_step[1][0]][pot_adj_step[1][1]][0]!=Grid.Kind.WALL && if(grid.object_grid[pot_adj_step[1][0]][pot_adj_step[1][1]][0]!=Grid.Kind.WALL &&
grid.object_grid[pot_adj_step[3][0]][pot_adj_step[3][1]][0]!=Grid.Kind.WALL): grid.object_grid[pot_adj_step[3][0]][pot_adj_step[3][1]][0]!=Grid.Kind.WALL):
adj.append([STEP, Vector2(next[0],next[1]),1.1]) adj.append([STEP, Vector2(next[0],next[1]),1.1])
continue continue
if(i==2): if(i==2):
continue
if(grid.object_grid[pot_adj_step[1][0]][pot_adj_step[1][1]][0]!=Grid.Kind.WALL && if(grid.object_grid[pot_adj_step[1][0]][pot_adj_step[1][1]][0]!=Grid.Kind.WALL &&
grid.object_grid[pot_adj_step[4][0]][pot_adj_step[4][1]][0]!=Grid.Kind.WALL): grid.object_grid[pot_adj_step[4][0]][pot_adj_step[4][1]][0]!=Grid.Kind.WALL):
adj.append([STEP, Vector2(next[0],next[1]),1.1]) adj.append([STEP, Vector2(next[0],next[1]),1.1])
continue continue
if(i==5): if(i==5):
continue
if(grid.object_grid[pot_adj_step[3][0]][pot_adj_step[3][1]][0]!=Grid.Kind.WALL && if(grid.object_grid[pot_adj_step[3][0]][pot_adj_step[3][1]][0]!=Grid.Kind.WALL &&
grid.object_grid[pot_adj_step[6][0]][pot_adj_step[6][1]][0]!=Grid.Kind.WALL): grid.object_grid[pot_adj_step[6][0]][pot_adj_step[6][1]][0]!=Grid.Kind.WALL):
adj.append([STEP, Vector2(next[0],next[1]),1.1]) adj.append([STEP, Vector2(next[0],next[1]),1.1])
continue continue
if(i==7): if(i==7):
continue
if(grid.object_grid[pot_adj_step[4][0]][pot_adj_step[4][1]][0]!=Grid.Kind.WALL && if(grid.object_grid[pot_adj_step[4][0]][pot_adj_step[4][1]][0]!=Grid.Kind.WALL &&
grid.object_grid[pot_adj_step[6][0]][pot_adj_step[6][1]][0]!=Grid.Kind.WALL): grid.object_grid[pot_adj_step[6][0]][pot_adj_step[6][1]][0]!=Grid.Kind.WALL):
adj.append([STEP, Vector2(next[0],next[1]),1.1]) adj.append([STEP, Vector2(next[0],next[1]),1.1])
@@ -267,11 +278,15 @@ func hit_or_miss(target, current, delta):
func movement_decider_ai(target, kindOfStep, delta): func movement_decider_ai(target, kindOfStep, delta):
var currentPosition = grid._pixel_to_grid_coords(global_position) var currentPosition = grid._pixel_to_grid_coords(global_position)
var currentPixel = global_position
var hitPixelTarget = is_hittable()
if hitPixelTarget!=null: if hitDelta >= hitTreshhold && randf() <0.5:
hit_or_miss(hitPixelTarget, currentPixel, delta*4) hitDelta -= hitTreshhold
var currentPixel = global_position
var hitPixelTarget = is_hittable()
if hitPixelTarget!=null:
hit_or_miss(hitPixelTarget, currentPixel, delta*4)
return
else: else:
if(kindOfStep==STEP): if(kindOfStep==STEP):
@@ -288,12 +303,15 @@ func movement_decider_ai(target, kindOfStep, delta):
func movement_execution(delta): func movement_execution(delta):
var currentPixel = global_position
var hitPixelTarget = is_hittable()
if hitPixelTarget!=null: if hitDelta >= hitTreshhold && randf() <0.5:
hit_or_miss(hitPixelTarget, currentPixel, delta*4) hitDelta -= hitTreshhold
return var currentPixel = global_position
var hitPixelTarget = is_hittable()
if hitPixelTarget!=null:
hit_or_miss(hitPixelTarget, currentPixel, delta*4)
return
if(targetFieldUsed): if(targetFieldUsed):
var cur = grid._pixel_to_grid_coords(global_position) var cur = grid._pixel_to_grid_coords(global_position)
@@ -320,16 +338,19 @@ func reset_exeution_state(delta):
func makeMove(delta): func makeMove(delta):
if ExecutionState == AI_MOVE: hitDelta += delta
threadDelta = 0 aiDelta+=delta
var MoveAdvice = movement_calulcaotr() if(aiDelta>aiTreshhold):
if(MoveAdvice==null): if ExecutionState == AI_MOVE:
return threadDelta = 0
var target = MoveAdvice[1] var MoveAdvice = movement_calulcaotr()
movement_decider_ai(target, MoveAdvice[0], delta) if(MoveAdvice==null):
return
var target = MoveAdvice[1]
movement_decider_ai(target, MoveAdvice[0], delta)
elif ExecutionState == EXECUTING: if ExecutionState == EXECUTING:
movement_execution(delta) movement_execution(delta)
reset_exeution_state(delta) reset_exeution_state(delta)

View File

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

View File

@@ -21,7 +21,7 @@ region_enabled = true
region_rect = Rect2( 0, 0, 1280, 720 ) region_rect = Rect2( 0, 0, 1280, 720 )
[node name="Background" parent="." instance=ExtResource( 7 )] [node name="Background" parent="." instance=ExtResource( 7 )]
frame = 20 frame = 41
[node name="FloorTileMap" type="TileMap" parent="."] [node name="FloorTileMap" type="TileMap" parent="."]
visible = false visible = false
@@ -40,7 +40,7 @@ __meta__ = {
[node name="YSort" type="YSort" parent="."] [node name="YSort" type="YSort" parent="."]
[node name="Bonfire" parent="YSort" instance=ExtResource( 10 )] [node name="Bonfire" parent="YSort" instance=ExtResource( 10 )]
position = Vector2( 265.543, -16 ) position = Vector2( 448, 32 )
[node name="Player" parent="YSort" instance=ExtResource( 1 )] [node name="Player" parent="YSort" instance=ExtResource( 1 )]
position = Vector2( 344, 125.768 ) position = Vector2( 344, 125.768 )