mirror of
https://github.com/creyD/ludum_dare_46.git
synced 2026-06-11 21:22:22 +02:00
ai fixed
This commit is contained in:
@@ -37,9 +37,11 @@ collision_mask = 65
|
||||
position = Vector2( 0, -15 )
|
||||
shape = SubResource( 1 )
|
||||
|
||||
[node name="Hurtbox" parent="." instance=ExtResource( 1 )]
|
||||
[node name="Hurtbox" parent="." groups=[
|
||||
"HittableByPlayer",
|
||||
] instance=ExtResource( 1 )]
|
||||
collision_layer = 4
|
||||
collision_mask = 0
|
||||
collision_mask = 128
|
||||
|
||||
[node name="CollisionShape2D" parent="Hurtbox" index="0"]
|
||||
position = Vector2( 0, -15 )
|
||||
|
||||
@@ -40,9 +40,11 @@ collision_mask = 65
|
||||
position = Vector2( 0, -9 )
|
||||
shape = SubResource( 2 )
|
||||
|
||||
[node name="Hurtbox" parent="." instance=ExtResource( 1 )]
|
||||
[node name="Hurtbox" parent="." groups=[
|
||||
"HittableByPlayer",
|
||||
] instance=ExtResource( 1 )]
|
||||
collision_layer = 8
|
||||
collision_mask = 0
|
||||
collision_mask = 128
|
||||
|
||||
[node name="CollisionShape2D" parent="Hurtbox" index="0"]
|
||||
position = Vector2( 0, -9 )
|
||||
|
||||
@@ -64,6 +64,9 @@ func reset_history():
|
||||
|
||||
|
||||
func countTargets(table):
|
||||
for i in range(table.size()):
|
||||
table[i]=0
|
||||
|
||||
for x in range(14):
|
||||
for y in range(7):
|
||||
for i in prio_grid[x][y]:
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
extends StaticBody2D
|
||||
|
||||
export(int,1,10) var health = 1
|
||||
var GreenDrop = 0.5
|
||||
var BlueDrop = 0.4
|
||||
var RedDrop = 0.2
|
||||
@@ -10,6 +11,9 @@ func offset_vec():
|
||||
return Vector2((randf()-0.5)*offset, (randf()-0.5)*offset)
|
||||
|
||||
func _on_Hurtbox_area_entered(area):
|
||||
health -= area.damage
|
||||
if(health>0):
|
||||
return
|
||||
queue_free()
|
||||
var GreenRubies = load("res://Objects/Rubies/Green.tscn")
|
||||
var BlueRubies = load("res://Objects/Rubies/Blue.tscn")
|
||||
|
||||
@@ -24,9 +24,11 @@ kind = 9
|
||||
position = Vector2( 0.244171, -10.0111 )
|
||||
texture = ExtResource( 3 )
|
||||
|
||||
[node name="Hurtbox" parent="." instance=ExtResource( 1 )]
|
||||
[node name="Hurtbox" parent="." groups=[
|
||||
"HittableByPlayer",
|
||||
] instance=ExtResource( 1 )]
|
||||
collision_layer = 8
|
||||
collision_mask = 0
|
||||
collision_mask = 128
|
||||
|
||||
[node name="CollisionShape2D" parent="Hurtbox" index="0"]
|
||||
position = Vector2( 0.322258, -10.0297 )
|
||||
|
||||
@@ -22,6 +22,6 @@ func _physics_process(delta):
|
||||
|
||||
func _on_Hurtbox_area_entered(area):
|
||||
lifePoints -= area.damage
|
||||
if(lifePoints<0):
|
||||
if(lifePoints<=0):
|
||||
queue_free()
|
||||
pass
|
||||
|
||||
@@ -24,9 +24,11 @@ position = Vector2( 1.88936, -12.4698 )
|
||||
position = Vector2( 0, -8 )
|
||||
texture = ExtResource( 2 )
|
||||
|
||||
[node name="Hurtbox" parent="." instance=ExtResource( 1 )]
|
||||
[node name="Hurtbox" parent="." groups=[
|
||||
"HittableByPlayer",
|
||||
] instance=ExtResource( 1 )]
|
||||
collision_layer = 8
|
||||
collision_mask = 0
|
||||
collision_mask = 128
|
||||
script = null
|
||||
|
||||
[node name="CollisionShape2D" parent="Hurtbox" index="0"]
|
||||
|
||||
@@ -38,9 +38,11 @@ var abortProb = 0.01
|
||||
var targetFieldCur = [0,0]
|
||||
var targetFieldUsed = false
|
||||
|
||||
var actionField = [0,0]
|
||||
var actionKind = Grid.Kind.TERMINAL_SYMBOL
|
||||
var actionFieldUsed = false
|
||||
|
||||
var areaRefList = []
|
||||
|
||||
var threadTime = 0.4
|
||||
var threadDelta = 0.0
|
||||
#calculates the sum of all present prios
|
||||
@@ -263,61 +265,48 @@ func AStar(source, target):
|
||||
|
||||
func movement_calulcaotr():
|
||||
var currentPosition = grid._pixel_to_grid_coords(global_position)
|
||||
var calcNew = false
|
||||
var MoveAdvice
|
||||
|
||||
var enemyKind
|
||||
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
|
||||
enemyKind = calcEnemyKind()
|
||||
actionKind = enemyKind
|
||||
actionFieldUsed = true
|
||||
else:
|
||||
enemyKind = actionKind
|
||||
|
||||
MoveAdvice = getMoveDescription(currentPosition, actionField)
|
||||
if(enemyKind==Grid.Kind.TERMINAL_SYMBOL):
|
||||
return
|
||||
|
||||
var targetField = grid.get_nearest(currentPosition, enemyKind)
|
||||
if(targetField==[-1,-1]):
|
||||
return
|
||||
|
||||
|
||||
var MoveAdvice = getMoveDescription(currentPosition, targetField)
|
||||
grid.reset_history()
|
||||
|
||||
return MoveAdvice
|
||||
|
||||
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 is_hittable():
|
||||
var length = areaRefList.size()
|
||||
if length == 0:
|
||||
return null
|
||||
var randomNumber = randi()%length
|
||||
return instance_from_id(areaRefList[randomNumber]).global_position
|
||||
|
||||
func hit_or_miss(target, current, hitable, delta):
|
||||
run(Vector2(target[0]-current[0], target[1]-current[1]), delta*8)
|
||||
func hit_or_miss(target, current, delta):
|
||||
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
|
||||
var currentPixel = global_position
|
||||
var hitPixelTarget = is_hittable()
|
||||
|
||||
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(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 hitPixelTarget!=null:
|
||||
hit_or_miss(hitPixelTarget, currentPixel, delta*4)
|
||||
actionFieldUsed = false
|
||||
else:
|
||||
if(kindOfStep==STEP):
|
||||
run(Vector2(target[0]-currentPosition[0], target[1]-currentPosition[1]), delta*4)
|
||||
targetFieldCur = target
|
||||
@@ -333,19 +322,20 @@ func movement_decider_ai(target, kindOfStep, delta):
|
||||
|
||||
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.01):
|
||||
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(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)
|
||||
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.1):
|
||||
targetFieldUsed = false
|
||||
ExecutionState = AI_MOVE
|
||||
var actionField = grid.get_nearest(cur, actionKind)
|
||||
if(targetFieldCur[0]==actionField[0]&&targetFieldCur[1]==actionField[1]):
|
||||
actionFieldUsed = false
|
||||
else:
|
||||
var currentPosition = grid._pixel_to_grid_coords(global_position)
|
||||
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)
|
||||
|
||||
|
||||
func reset_exeution_state(delta):
|
||||
|
||||
@@ -209,3 +209,13 @@ func movement_idle():
|
||||
movementState = moveState.IDLE
|
||||
velocity = Vector2.ZERO
|
||||
animation_state.change_state("idle")
|
||||
|
||||
|
||||
func _on_SwordRange_area_entered(area):
|
||||
if(area.is_in_group("HittableByPlayer")):
|
||||
areaRefList.push_back(area.get_instance_id())
|
||||
|
||||
|
||||
func _on_SwordRange_area_exited(area):
|
||||
if(area.is_in_group("HittableByPlayer")):
|
||||
areaRefList.erase(area.get_instance_id())
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=63 format=2]
|
||||
[gd_scene load_steps=64 format=2]
|
||||
|
||||
[ext_resource path="res://Player/Player.gd" type="Script" id=1]
|
||||
[ext_resource path="res://Player/player.png" type="Texture" id=2]
|
||||
@@ -619,7 +619,10 @@ height = 0.2
|
||||
radius = 4.03497
|
||||
height = 6.99104
|
||||
|
||||
[sub_resource type="DynamicFont" id=49]
|
||||
[sub_resource type="CircleShape2D" id=51]
|
||||
radius = 14.7132
|
||||
|
||||
[sub_resource type="DynamicFont" id=50]
|
||||
size = 12
|
||||
font_data = ExtResource( 6 )
|
||||
|
||||
@@ -691,7 +694,7 @@ position = Vector2( 1.90735e-06, 0.000833988 )
|
||||
shape = SubResource( 47 )
|
||||
|
||||
[node name="Pivot" type="Position2D" parent="."]
|
||||
position = Vector2( 0, -4.16248 )
|
||||
position = Vector2( 0, -4 )
|
||||
rotation = 3.14159
|
||||
__meta__ = {
|
||||
"_gizmo_extents_": 20.0
|
||||
@@ -706,12 +709,24 @@ position = Vector2( 8.43416, 0.0698299 )
|
||||
shape = SubResource( 48 )
|
||||
disabled = true
|
||||
|
||||
[node name="SwordRange" parent="Pivot" instance=ExtResource( 4 )]
|
||||
position = Vector2( 1.15451e-05, -4.16248 )
|
||||
rotation = -3.14159
|
||||
scale = Vector2( 0.909091, 0.909091 )
|
||||
collision_layer = 128
|
||||
collision_mask = 0
|
||||
damage = 0.0
|
||||
|
||||
[node name="CollisionShape2D" parent="Pivot/SwordRange" index="0"]
|
||||
position = Vector2( 0, -4.56405 )
|
||||
shape = SubResource( 51 )
|
||||
|
||||
[node name="DebugLabel" type="Label" parent="."]
|
||||
margin_left = -8.01196
|
||||
margin_top = -21.2223
|
||||
margin_right = 8.98804
|
||||
margin_bottom = -9.22228
|
||||
custom_fonts/font = SubResource( 49 )
|
||||
margin_left = -8.12021
|
||||
margin_top = -21.9801
|
||||
margin_right = 12.8798
|
||||
margin_bottom = -9.98004
|
||||
custom_fonts/font = SubResource( 50 )
|
||||
text = "Held"
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
@@ -744,6 +759,8 @@ script = ExtResource( 16 )
|
||||
[connection signal="area_entered" from="Hitbox" to="." method="_on_Hitbox_area_entered"]
|
||||
[connection signal="area_entered" from="Hurtbox" to="." method="_on_Hurtbox_area_entered"]
|
||||
[connection signal="area_exited" from="Hurtbox" to="." method="_on_Hurtbox_area_exited"]
|
||||
[connection signal="area_entered" from="Pivot/SwordRange" to="." method="_on_SwordRange_area_entered"]
|
||||
[connection signal="area_exited" from="Pivot/SwordRange" to="." method="_on_SwordRange_area_exited"]
|
||||
[connection signal="no_health" from="Stats" to="." method="_on_Stats_no_health"]
|
||||
|
||||
[editable path="Hitbox"]
|
||||
@@ -751,3 +768,5 @@ script = ExtResource( 16 )
|
||||
[editable path="Hurtbox"]
|
||||
|
||||
[editable path="Pivot/SwordHitbox"]
|
||||
|
||||
[editable path="Pivot/SwordRange"]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=11 format=2]
|
||||
[gd_scene load_steps=12 format=2]
|
||||
|
||||
[ext_resource path="res://Player/Player.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://World.gd" type="Script" id=2]
|
||||
@@ -7,6 +7,7 @@
|
||||
[ext_resource path="res://Menus/DragNDrop/DragNDropUI.tscn" type="PackedScene" id=5]
|
||||
[ext_resource path="res://Menus/DialogueBox/DialogueBox.tscn" type="PackedScene" id=6]
|
||||
[ext_resource path="res://Objects/Torch/Torch.tscn" type="PackedScene" id=7]
|
||||
[ext_resource path="res://Objects/Barrel/Barrel.tscn" type="PackedScene" id=8]
|
||||
[ext_resource path="res://Objects/Bonfire/Bonfire.tscn" type="PackedScene" id=10]
|
||||
[ext_resource path="res://Boss/Boss_template.tscn" type="PackedScene" id=17]
|
||||
[ext_resource path="res://Maps/Grid.tscn" type="PackedScene" id=18]
|
||||
@@ -15,7 +16,7 @@
|
||||
script = ExtResource( 2 )
|
||||
|
||||
[node name="WallSprite" type="Sprite" parent="."]
|
||||
position = Vector2( 355.382, 175.62 )
|
||||
position = Vector2( 360, 176 )
|
||||
texture = ExtResource( 4 )
|
||||
region_enabled = true
|
||||
region_rect = Rect2( 0, 0, 1280, 720 )
|
||||
@@ -37,18 +38,21 @@ position = Vector2( 152, 120 )
|
||||
[node name="Player" parent="YSort" instance=ExtResource( 1 )]
|
||||
position = Vector2( 200, 8 )
|
||||
scale = Vector2( 2, 2 )
|
||||
debug = true
|
||||
ROLL_SPEED = 140
|
||||
FRICTION = 200
|
||||
|
||||
[node name="Boss_template" parent="YSort" instance=ExtResource( 17 )]
|
||||
position = Vector2( -56, 8 )
|
||||
debug = true
|
||||
|
||||
[node name="Bonfire" parent="YSort" instance=ExtResource( 10 )]
|
||||
position = Vector2( 288, 104 )
|
||||
|
||||
[node name="Torch" parent="YSort" instance=ExtResource( 7 )]
|
||||
position = Vector2( 264, -40 )
|
||||
position = Vector2( 264, -24 )
|
||||
|
||||
[node name="Barrel" parent="YSort" instance=ExtResource( 8 )]
|
||||
position = Vector2( 40, 8 )
|
||||
|
||||
[node name="Grid" parent="." instance=ExtResource( 18 )]
|
||||
|
||||
|
||||
@@ -148,6 +148,7 @@ attack={
|
||||
2d_physics/layer_5="trap"
|
||||
2d_physics/layer_6="collectable"
|
||||
2d_physics/layer_7="Bonfire"
|
||||
2d_physics/layer_8="SwordRange"
|
||||
|
||||
[rendering]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user