Merge branch 'bos_testing' into devRefactor

This commit is contained in:
2020-04-19 21:29:28 +02:00
committed by GitHub
7 changed files with 173 additions and 71 deletions

View File

@@ -15,9 +15,8 @@ height = 18.0
radius = 18.0
height = 18.0
[sub_resource type="CapsuleShape2D" id=3]
radius = 8.0
height = 15.0
[sub_resource type="CircleShape2D" id=3]
radius = 12.5
[node name="Boss_template" type="KinematicBody2D"]
script = ExtResource( 4 )

View File

@@ -8,7 +8,7 @@ var prio_grid : Array = []
var used_grid : Array = []
var time_passed := 0.0
var offset
export(float,0,42.0) var refresh_rate = 5.0
export(float,0,42.0) var refresh_rate = 1
func _draw_object_grid():
@@ -31,9 +31,9 @@ func _reset_grids():
for x in range(14):
for y in range(7):
var lulul = object_grid[x][y].back()
while (object_grid[x][y].back()!=Kind.FIELD) and (Kind.WALL != object_grid[x][y].back()):
while (object_grid[x][y].size()!=1):
object_grid[x][y].pop_back()
while (prio_grid[x][y].back()!=Kind.TERMINAL_SYMBOL):
while (prio_grid[x][y].size()!=1):
prio_grid[x][y].pop_back()
func _ready():

View File

@@ -11,7 +11,7 @@ extents = Vector2( 16, 16 )
[node name="Kind" parent="." instance=ExtResource( 3 )]
general = 2
kind = 10
kind = 2
[node name="Sprite" type="Sprite" parent="."]
texture = ExtResource( 1 )

View File

@@ -7,6 +7,7 @@ const Grid = preload("res://Maps/Grid.gd")
var grid
enum{
LENGTH,
WAY
@@ -24,7 +25,7 @@ enum{
}
var ExecutionState = AI_MOVE
var movmentState = NOTHING
var ai_movement_state = NOTHING
var numbers = [0,0,0,0,0,0,0,0,0,0]
var prios = [7,0,6,5,4,3,2,1,1,4]
@@ -33,8 +34,14 @@ var totalPrioTurn = 0
var executesTurn = false
var abortProb = 0.01
var targetField = [0,0]
var targetFieldCur = [0,0]
var targetFieldUsed = false
var actionField = [0,0]
var actionFieldUsed = false
var threadTime = 0.4
var threadDelta = 0.0
#calculates the sum of all present prios
func calcTotalPrio():
var sum = 0
@@ -66,10 +73,10 @@ func calcPrioTable():
i += 1
return table
#14+7 0.999
#updates heart and bonfire prio
func adjustPrio(currentHealth, maxHealth):
var prioVal = 1000 - (float(currentHealth)/float(maxHealth))*1000
var prioVal = 40.0 - (float(currentHealth)/float(maxHealth))*40.0
var bonfire = prioVal
var hearts = prioVal - 1
if(hearts < 0):
@@ -93,39 +100,41 @@ func getMoveDescription(myPosition : Vector2, targetPositions):
func getCost(field):
var cost = 0
for i in grid.prio_grid[field.x][field.y]:
for i in grid.object_grid[field.x][field.y]:
match i:
Grid.Kind.DAMAGE:
cost += prios[Grid.Kind.BONFIRE] * 6
cost += prios[Grid.Kind.BONFIRE] * 32
Grid.Kind.SLOW:
cost += 2
cost += 1
return cost
#return an heurestic of distance
# curr - current position
# targ - a target position
func h(curr, target):
return min(abs(target[0]-curr[0]),abs(target[0]-curr[0]))
func h_fn(curr, target):
return sqrt(pow(target[0]-curr[0],2)+pow(target[0]-curr[0],2))
# currCost - currentCost
# target - position of the field to move to
func g(currCost, target):
func g_fn(currCost, target):
return currCost + getCost(target)
# Returns the list of adjacent nodes
func adjacent(currentPosition, can_roll = false):
func adjacent(currentPosition, can_roll = true):
var adj := []
#adj.append([STEP, Vector2(0,0)])
var p = currentPosition
var pot_adj_step = [[p[0]-1, p[1]-1], [p[0]-1, p[1]-0], [p[0]-1, p[1]+1],
var pot_adj_step = [[p[0]-1, p[1]-1], [p[0]-1, p[1]-0], [p[0]-1, p[1]+1],
[p[0]+0, p[1]-1], [p[0]+0, p[1]+1],
[p[0]+1, p[1]-1], [p[0]+1, p[1]+0], [p[0]+1, p[1]+1]]
var pot_adj_roll = [[p[0]-2, p[1]-2], [p[0]-2, p[1]-0], [p[0]-2, p[1]+2],
[p[0]+0, p[1]-2], [p[0]+0, p[1]+2],
[p[0]+2, p[1]-2], [p[0]+2, p[1]+0], [p[0]+2, p[1]+2]]
for next in pot_adj_step:
for i in range(pot_adj_step.size()):
var next = pot_adj_step[i]
if(next[0]<0):
continue
if(next[0]>13):
@@ -137,12 +146,31 @@ func adjacent(currentPosition, can_roll = false):
if(grid.used_grid[next[0]][next[1]]):
continue
if(grid.object_grid[next[0]][next[1]][0]!=Grid.Kind.WALL):
adj.append([STEP, Vector2(next[0],next[1])])
if(i==0):
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):
adj.append([STEP, Vector2(next[0],next[1]),1.1])
continue
if(i==2):
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):
adj.append([STEP, Vector2(next[0],next[1]),1.1])
continue
if(i==5):
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):
adj.append([STEP, Vector2(next[0],next[1]),1.1])
continue
if(i==7):
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):
adj.append([STEP, Vector2(next[0],next[1]),1.1])
continue
adj.append([STEP, Vector2(next[0],next[1]),1.0])
if not can_roll:
return adj
for next in pot_adj_roll:
for i in range(pot_adj_roll.size()):
var next = pot_adj_roll[i]
if(next[0]<0):
continue
if(next[0]>13):
@@ -154,7 +182,48 @@ func adjacent(currentPosition, can_roll = false):
if(grid.used_grid[next[0]][next[1]]):
continue
if(grid.object_grid[next[0]][next[1]][0]!=Grid.Kind.WALL):
adj.append([ROLL, Vector2(next[0],next[1])])
continue
if(grid.object_grid[next[0]][next[1]][0]!=Grid.Kind.WALL):
if(i==0):
if(grid.object_grid[next[0]+0][next[1]+1][0]!=Grid.Kind.WALL &&
grid.object_grid[next[0]+1][next[1]+0][0]!=Grid.Kind.WALL &&
grid.object_grid[next[0]+1][next[1]+1][0]!=Grid.Kind.WALL &&
grid.object_grid[next[0]+1][next[1]+2][0]!=Grid.Kind.WALL &&
grid.object_grid[next[0]+2][next[1]+1][0]!=Grid.Kind.WALL):
adj.append([ROLL, Vector2(next[0],next[1]),2.1])
if(i==1):
if(grid.object_grid[next[0]+0][next[1]+1][0]!=Grid.Kind.WALL):
adj.append([ROLL, Vector2(next[0],next[1]),2.0])
if(i==2):
if(grid.object_grid[next[0]-0][next[1]+1][0]!=Grid.Kind.WALL &&
grid.object_grid[next[0]-1][next[1]+0][0]!=Grid.Kind.WALL &&
grid.object_grid[next[0]-1][next[1]+1][0]!=Grid.Kind.WALL &&
grid.object_grid[next[0]-1][next[1]+2][0]!=Grid.Kind.WALL &&
grid.object_grid[next[0]-2][next[1]+1][0]!=Grid.Kind.WALL):
adj.append([ROLL, Vector2(next[0],next[1]),2.1])
if(i==3):
if(grid.object_grid[next[0]+1][next[1]+0][0]!=Grid.Kind.WALL):
adj.append([ROLL, Vector2(next[0],next[1]),2.0])
if(i==4):
if(grid.object_grid[next[0]-1][next[1]+0][0]!=Grid.Kind.WALL):
adj.append([ROLL, Vector2(next[0],next[1]),2.0])
if(i==5):
if(grid.object_grid[next[0]+0][next[1]-1][0]!=Grid.Kind.WALL &&
grid.object_grid[next[0]+1][next[1]-0][0]!=Grid.Kind.WALL &&
grid.object_grid[next[0]+1][next[1]-1][0]!=Grid.Kind.WALL &&
grid.object_grid[next[0]+1][next[1]-2][0]!=Grid.Kind.WALL &&
grid.object_grid[next[0]+2][next[1]-1][0]!=Grid.Kind.WALL):
adj.append([ROLL, Vector2(next[0],next[1]),2.1])
if(i==6):
if(grid.object_grid[next[0]+0][next[1]-1][0]!=Grid.Kind.WALL):
adj.append([ROLL, Vector2(next[0],next[1]),2.0])
if(i==7):
if(grid.object_grid[next[0]-0][next[1]-1][0]!=Grid.Kind.WALL &&
grid.object_grid[next[0]-1][next[1]-0][0]!=Grid.Kind.WALL &&
grid.object_grid[next[0]-1][next[1]-1][0]!=Grid.Kind.WALL &&
grid.object_grid[next[0]-1][next[1]-2][0]!=Grid.Kind.WALL &&
grid.object_grid[next[0]-2][next[1]-1][0]!=Grid.Kind.WALL):
adj.append([ROLL, Vector2(next[0],next[1]),2.1])
return adj
@@ -179,14 +248,10 @@ func AStar(source, target):
grid.used_grid[node[2][0]][node[2][1]] = true
var adj_list = adjacent(node[2])
for i in adj_list:
var move_cost = 0
if (i[0] == STEP):
move_cost = 1
else:
move_cost = 2
var move_cost = i[2]
var g_val = g(node[1]+move_cost, i[1])
var h_val = h(i[1], target)
var g_val = g_fn(node[1]+move_cost, i[1])
var h_val = h_fn(i[1], target)
#[g+h(x), g(x), current, from, kind]
var new_node = [g_val+h_val, g_val,i[1], node[2], i[0]]
@@ -194,43 +259,68 @@ func AStar(source, target):
return [NOTHING, [0,0]]
func makeMove(delta):
#if(actionFieldUsed==true):
# var random = randf()
# if(random < mindChangeProbability):
# ExecutionState = AI_MOVE
if ExecutionState == AI_MOVE:
threadDelta = 0
var currentPosition = grid._pixel_to_grid_coords(global_position)
var enemyKind = calcEnemyKind()
if(enemyKind==Grid.Kind.TERMINAL_SYMBOL):
return
var target = grid.get_nearest(currentPosition, enemyKind)
var MoveAdvice = getMoveDescription(currentPosition, target)
var calcNew = false
var target
var MoveAdvice
if(actionFieldUsed==false):
calcNew = true
if(calcNew==true):
var enemyKind = calcEnemyKind()
if(enemyKind==Grid.Kind.TERMINAL_SYMBOL):
return
target = grid.get_nearest(currentPosition, enemyKind)
actionField = target
actionFieldUsed = true
MoveAdvice = getMoveDescription(currentPosition, target)
else:
MoveAdvice = getMoveDescription(currentPosition, actionField)
grid.reset_history()
target = MoveAdvice[1]
if(MoveAdvice[0]==STEP):
run(Vector2(target[0]-currentPosition[0], target[1]-currentPosition[1]), delta*10)
targetField = target
run(Vector2(target[0]-currentPosition[0], target[1]-currentPosition[1]), delta*4)
targetFieldCur = target
targetFieldUsed = true
movmentState = STEP
ai_movement_state = STEP
elif(MoveAdvice[0]==ROLL):
roll(Vector2(target[0]-currentPosition[0], target[1]-currentPosition[1]), delta*10)
roll(Vector2(target[0]-currentPosition[0], target[1]-currentPosition[1]), delta*4)
targetFieldCur = target
targetFieldUsed = true
targetField = target
ExecutionState = EXECUTING
grid.reset_history()
elif ExecutionState == EXECUTING:
if(targetFieldUsed):
var cur = grid._pixel_to_grid_coords(global_position)
var distance = sqrt(pow(cur[0]-targetField[0],2)+ pow(cur[1]-targetField[1],2))
if(distance<0.01):
var distance = sqrt(pow(cur[0]-targetFieldCur[0],2)+ pow(cur[1]-targetFieldCur[1],2))
if(distance<0.4):
targetFieldUsed = false
ExecutionState = AI_MOVE
if(targetFieldCur[0]==actionField[0]&&targetFieldCur[1]==actionField[1]):
actionFieldUsed = false
else:
var currentPosition = grid._pixel_to_grid_coords(global_position)
if(movmentState==STEP):
run(Vector2(targetField[0]-currentPosition[0], targetField[1]-currentPosition[1]), delta*10)
elif(movmentState==ROLL):
roll(Vector2(targetField[0]-currentPosition[0], targetField[1]-currentPosition[1]), delta*10)
else:
if(ai_movement_state==STEP):
run(Vector2(targetFieldCur[0]-currentPosition[0], targetFieldCur[1]-currentPosition[1]), delta*4)
elif(ai_movement_state==ROLL):
run(Vector2(targetFieldCur[0]-currentPosition[0], targetFieldCur[1]-currentPosition[1]), delta*4)
threadDelta = threadDelta + delta
if(threadDelta>threadTime):
ExecutionState = AI_MOVE
pass
actionFieldUsed = false
# API Interface for ai_hero -> methods are handled in player.gd
func attac(direction, delta):

View File

@@ -56,7 +56,7 @@ func _physics_process(delta):
while(totaldamage < -1):
totaldamage+=1
player_stats.health+=1
#adjustPrio(player_stats.health, player_stats.max_health)
adjustPrio(player_stats.health, player_stats.max_health)
_debug_update()
if debug == true:
match movementState:
@@ -165,7 +165,8 @@ func movement_roll():
func roll_finished():
movementState = moveState.IDLE
ExecutionState = AI_MOVE
ai_movement_state = STEP
ExecutionState = EXECUTING
func _on_Hurtbox_area_entered(area):

View File

@@ -14,9 +14,8 @@
[ext_resource path="res://Player/PlayerStateMachine.gd" type="Script" id=15]
[ext_resource path="res://Player/States/Roll.gd" type="Script" id=16]
[sub_resource type="CapsuleShape2D" id=1]
radius = 2.15976
height = 3.85866
[sub_resource type="CircleShape2D" id=50]
radius = 3.0
[sub_resource type="Animation" id=2]
resource_name = "HitDown"
@@ -629,6 +628,7 @@ script = ExtResource( 1 )
FRICTION = 270
[node name="Kind" parent="." instance=ExtResource( 7 )]
general = 4
kind = 1
[node name="Sprite" type="Sprite" parent="."]
@@ -640,9 +640,9 @@ hframes = 60
frame = 12
[node name="Body" type="CollisionShape2D" parent="."]
position = Vector2( -0.0470657, -0.609329 )
position = Vector2( 0.0107212, 0.0456073 )
rotation = 1.5708
shape = SubResource( 1 )
shape = SubResource( 50 )
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
anims/HitDown = SubResource( 2 )
@@ -678,7 +678,7 @@ collision_layer = 0
collision_mask = 32
[node name="CollisionShape2D" parent="Hitbox" index="0"]
position = Vector2( 0, -0.5 )
position = Vector2( -0.0192623, 0.000833511 )
shape = SubResource( 46 )
[node name="Hurtbox" parent="." instance=ExtResource( 3 )]
@@ -686,7 +686,7 @@ position = Vector2( 0, 0.0375252 )
collision_mask = 0
[node name="CollisionShape2D" parent="Hurtbox" index="0"]
position = Vector2( 0, -0.5 )
position = Vector2( 1.90735e-06, 0.000833988 )
shape = SubResource( 47 )
[node name="Pivot" type="Position2D" parent="."]

View File

@@ -8,10 +8,11 @@
[ext_resource path="res://Menus/DialogueBox/DialogueBox.tscn" type="PackedScene" id=6]
[ext_resource path="res://Boss/Boss_template.tscn" type="PackedScene" id=7]
[ext_resource path="res://Objects/Bonfire/Bonfire.tscn" type="PackedScene" id=8]
[ext_resource path="res://testSprites/bannane.png" type="Texture" id=5]
[ext_resource path="res://Objects/Bonfire/Bonfire.tscn" type="PackedScene" id=7]
[ext_resource path="res://Boss/Boss_template.tscn" type="PackedScene" id=17]
[ext_resource path="res://Maps/Grid.tscn" type="PackedScene" id=18]
[sub_resource type="AnimationNodeStateMachinePlayback" id=1]
[node name="World" type="Node2D"]
script = ExtResource( 2 )
@@ -26,7 +27,7 @@ position = Vector2( 16, 16 )
tile_set = ExtResource( 3 )
cell_size = Vector2( 32, 32 )
format = 1
tile_data = PoolIntArray( -1, 47, 4, -65536, 47, 196609, -65535, 47, 196609, -65534, 47, 196609, -65533, 47, 196609, -65532, 47, 196609, -65531, 47, 196609, -65530, 47, 196609, -65529, 47, 196609, -65528, 47, 196609, -65527, 47, 196609, -65526, 47, 196609, -65525, 47, 196609, -65524, 47, 196609, -65523, 47, 196609, -65522, 47, 7, 65535, 47, 65539, 14, 47, 65539, 131071, 47, 65539, 65545, 47, 4, 65546, 47, 196609, 65547, 47, 196610, 65550, 47, 65539, 196607, 47, 65539, 131081, 47, 65539, 131086, 47, 65539, 262143, 47, 65539, 196617, 47, 196612, 196618, 47, 196609, 196619, 47, 7, 196622, 47, 65539, 327679, 47, 65539, 262155, 47, 65539, 262158, 47, 65539, 393215, 47, 65539, 327689, 47, 196608, 327690, 47, 196609, 327691, 47, 196615, 327694, 47, 65539, 458751, 47, 65539, 393230, 47, 65539, 524287, 47, 196612, 458752, 47, 196609, 458753, 47, 196609, 458754, 47, 196609, 458755, 47, 196609, 458756, 47, 196609, 458757, 47, 196609, 458758, 47, 196609, 458759, 47, 196609, 458760, 47, 196609, 458761, 47, 196609, 458762, 47, 196609, 458763, 47, 196609, 458764, 47, 196609, 458765, 47, 196609, 458766, 47, 196615 )
tile_data = PoolIntArray( -131059, 47, 0, -131058, 47, 2, -1, 47, 4, -65536, 47, 196609, -65535, 47, 196609, -65534, 47, 196609, -65533, 47, 196609, -65532, 47, 196609, -65531, 47, 196609, -65530, 47, 8, -65529, 47, 196609, -65528, 47, 8, -65527, 47, 196609, -65526, 47, 196609, -65525, 47, 196609, -65524, 47, 196609, -65523, 47, 196614, -65522, 47, 196618, -65521, 47, 196610, 65535, 47, 65539, 6, 47, 131075, 8, 47, 131075, 14, 47, 65539, 131071, 47, 65539, 65541, 47, 196611, 65550, 47, 65539, 196607, 47, 65539, 131075, 47, 196608, 131076, 47, 196610, 131086, 47, 65539, 262143, 47, 65539, 196614, 47, 196611, 196622, 47, 65539, 327679, 47, 65539, 262147, 47, 196611, 262149, 47, 196611, 262158, 47, 65539, 393215, 47, 65539, 327684, 47, 196611, 327688, 47, 196611, 327694, 47, 65539, 458751, 47, 65539, 393221, 47, 3, 393225, 47, 3, 393230, 47, 65539, 524287, 47, 196612, 458752, 47, 196609, 458753, 47, 196609, 458754, 47, 196609, 458755, 47, 196609, 458756, 47, 196609, 458757, 47, 196616, 458758, 47, 196609, 458759, 47, 196609, 458760, 47, 196609, 458761, 47, 196616, 458762, 47, 196609, 458763, 47, 196609, 458764, 47, 196609, 458765, 47, 196609, 458766, 47, 196615 )
__meta__ = {
"_edit_group_": true,
"_edit_lock_": true
@@ -36,13 +37,24 @@ __meta__ = {
position = Vector2( 152, 120 )
[node name="Player" parent="YSort" instance=ExtResource( 1 )]
position = Vector2( 176, 112 )
position = Vector2( 240, 72 )
scale = Vector2( 2, 2 )
debug = true
ROLL_SPEED = 80
FRICTION = 200
[node name="AnimationTree" parent="YSort/Player" index="4"]
parameters/playback = SubResource( 1 )
[node name="Boss_template" parent="YSort" instance=ExtResource( 17 )]
position = Vector2( -104, 40 )
debug = true
[node name="Bonfire" parent="YSort" instance=ExtResource( 7 )]
position = Vector2( 264, -16 )
[node name="Body" parent="YSort/Bonfire" index="3"]
disabled = true
[node name="bannane" type="Sprite" parent="YSort"]
position = Vector2( 104, -24 )
texture = ExtResource( 5 )
[node name="Boss_template" parent="YSort" instance=ExtResource( 7 )]
position = Vector2( -67.0889, 2.27742 )
@@ -60,4 +72,4 @@ ObjectParent = NodePath("../..")
[node name="Grid" parent="." instance=ExtResource( 18 )]
[editable path="YSort/Player"]
[editable path="YSort/Bonfire"]