mirror of
https://github.com/creyD/ludum_dare_46.git
synced 2026-06-15 06:42:22 +02:00
torch, minion, ai attack
This commit is contained in:
@@ -16,6 +16,7 @@ enum{
|
||||
enum{
|
||||
STEP,
|
||||
ROLL,
|
||||
ATTAC,
|
||||
NOTHING
|
||||
}
|
||||
|
||||
@@ -77,8 +78,8 @@ func calcPrioTable():
|
||||
#updates heart and bonfire prio
|
||||
func adjustPrio(currentHealth, maxHealth):
|
||||
var prioVal = 40.0 - (float(currentHealth)/float(maxHealth))*40.0
|
||||
var bonfire = prioVal
|
||||
var hearts = prioVal - 1
|
||||
var bonfire = prioVal + 1
|
||||
var hearts = prioVal
|
||||
if(hearts < 0):
|
||||
hearts = 0
|
||||
prios[Grid.Kind.BONFIRE]=bonfire
|
||||
@@ -260,53 +261,81 @@ func AStar(source, target):
|
||||
return [NOTHING, [0,0]]
|
||||
|
||||
|
||||
func movement_calulcaotr():
|
||||
var currentPosition = grid._pixel_to_grid_coords(global_position)
|
||||
var calcNew = false
|
||||
var MoveAdvice
|
||||
|
||||
if(actionFieldUsed==false):
|
||||
calcNew = true
|
||||
|
||||
if(calcNew==true):
|
||||
var enemyKind = calcEnemyKind()
|
||||
if(enemyKind==Grid.Kind.TERMINAL_SYMBOL):
|
||||
return
|
||||
actionField = grid.get_nearest(currentPosition, enemyKind)
|
||||
if(actionField==[-1,-1]):
|
||||
return
|
||||
actionFieldUsed = true
|
||||
|
||||
MoveAdvice = getMoveDescription(currentPosition, actionField)
|
||||
grid.reset_history()
|
||||
|
||||
return MoveAdvice
|
||||
|
||||
func makeMove(delta):
|
||||
func is_hittable(target):
|
||||
for element in grid.prio_grid[target[0]][target[1]]:
|
||||
if(element == grid.Kind.BOSS || element == grid.Kind.TORCH || element == grid.Kind.MINION):
|
||||
return true
|
||||
return false
|
||||
|
||||
func hit_or_miss(target, current, hitable, delta):
|
||||
run(Vector2(target[0]-current[0], target[1]-current[1]), delta*8)
|
||||
attac(Vector2(target[0]-current[0], target[1]-current[1]), delta*4)
|
||||
return hitable
|
||||
|
||||
func movement_decider_ai(target, kindOfStep, delta):
|
||||
var currentPosition = grid._pixel_to_grid_coords(global_position)
|
||||
var field_of_movement = target
|
||||
|
||||
#if(actionFieldUsed==true):
|
||||
# var random = randf()
|
||||
# if(random < mindChangeProbability):
|
||||
# ExecutionState = AI_MOVE
|
||||
var top = [currentPosition[0]+0, currentPosition[1]-1]
|
||||
var left = [currentPosition[0]-1, currentPosition[1]-0]
|
||||
var right = [currentPosition[0]+1, currentPosition[1]-0]
|
||||
var down = [currentPosition[0]+0, currentPosition[1]+1]
|
||||
var field = [currentPosition[0]+0, currentPosition[1]+0]
|
||||
|
||||
if ExecutionState == AI_MOVE:
|
||||
threadDelta = 0
|
||||
var currentPosition = grid._pixel_to_grid_coords(global_position)
|
||||
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):
|
||||
if(grid._is_in_grid(Vector2(field[0], field[1])) && hit_or_miss(field, currentPosition, is_hittable(field), delta)):
|
||||
pass
|
||||
elif(grid._is_in_grid(Vector2(target[0], target[1])) && hit_or_miss(target, currentPosition, is_hittable(target), delta)):
|
||||
pass
|
||||
elif(grid._is_in_grid(Vector2(left[0], left[1])) && hit_or_miss(left, currentPosition, is_hittable(left), delta)):
|
||||
pass
|
||||
elif(grid._is_in_grid(Vector2(down[0], down[1])) && hit_or_miss(down, currentPosition, is_hittable(down), delta)):
|
||||
pass
|
||||
elif(grid._is_in_grid(Vector2(top[0], top[1])) && hit_or_miss(top, currentPosition, is_hittable(top), delta)):
|
||||
pass
|
||||
elif(grid._is_in_grid(Vector2(down[0], down[1])) && hit_or_miss(down, currentPosition, is_hittable(down), delta)):
|
||||
pass
|
||||
else:
|
||||
if(kindOfStep==STEP):
|
||||
run(Vector2(target[0]-currentPosition[0], target[1]-currentPosition[1]), delta*4)
|
||||
targetFieldCur = target
|
||||
targetFieldUsed = true
|
||||
ai_movement_state = STEP
|
||||
elif(MoveAdvice[0]==ROLL):
|
||||
elif(kindOfStep==ROLL):
|
||||
roll(Vector2(target[0]-currentPosition[0], target[1]-currentPosition[1]), delta*4)
|
||||
targetFieldCur = target
|
||||
targetFieldUsed = true
|
||||
ExecutionState = EXECUTING
|
||||
|
||||
elif ExecutionState == EXECUTING:
|
||||
if(targetFieldUsed):
|
||||
ExecutionState = EXECUTING
|
||||
|
||||
|
||||
|
||||
func movement_execution(delta):
|
||||
if(targetFieldUsed):
|
||||
var cur = grid._pixel_to_grid_coords(global_position)
|
||||
var distance = sqrt(pow(cur[0]-targetFieldCur[0],2)+ pow(cur[1]-targetFieldCur[1],2))
|
||||
if(distance<0.4):
|
||||
if(distance<0.01):
|
||||
targetFieldUsed = false
|
||||
ExecutionState = AI_MOVE
|
||||
if(targetFieldCur[0]==actionField[0]&&targetFieldCur[1]==actionField[1]):
|
||||
@@ -317,10 +346,35 @@ func makeMove(delta):
|
||||
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
|
||||
actionFieldUsed = false
|
||||
|
||||
|
||||
func reset_exeution_state(delta):
|
||||
threadDelta = threadDelta + delta
|
||||
if(threadDelta>threadTime):
|
||||
ExecutionState = AI_MOVE
|
||||
actionFieldUsed = false
|
||||
|
||||
|
||||
|
||||
func makeMove(delta):
|
||||
|
||||
#if(actionFieldUsed==true):
|
||||
# var random = randf()
|
||||
# if(random < mindChangeProbability):
|
||||
# ExecutionState = AI_MOVE
|
||||
|
||||
if ExecutionState == AI_MOVE:
|
||||
threadDelta = 0
|
||||
var MoveAdvice = movement_calulcaotr()
|
||||
if(MoveAdvice==null):
|
||||
return
|
||||
var target = MoveAdvice[1]
|
||||
movement_decider_ai(target, MoveAdvice[0], delta)
|
||||
|
||||
elif ExecutionState == EXECUTING:
|
||||
movement_execution(delta)
|
||||
reset_exeution_state(delta)
|
||||
|
||||
|
||||
# API Interface for ai_hero -> methods are handled in player.gd
|
||||
func attac(direction, delta):
|
||||
@@ -333,3 +387,5 @@ func roll(direction, delta):
|
||||
|
||||
func run(direction, delta):
|
||||
pass
|
||||
|
||||
#todo
|
||||
|
||||
Reference in New Issue
Block a user