mirror of
https://github.com/creyD/ludum_dare_46.git
synced 2026-06-20 17:10:20 +02:00
Minor Code Cleanup
This commit is contained in:
@@ -1,8 +1,10 @@
|
|||||||
extends KinematicBody2D
|
extends KinematicBody2D
|
||||||
class_name Boss
|
class_name Boss
|
||||||
|
|
||||||
"""
|
"""
|
||||||
This is an example player controller script created by Paul
|
This is an example player controller script created by Paul
|
||||||
"""
|
"""
|
||||||
|
|
||||||
var velocity := Vector2.ZERO
|
var velocity := Vector2.ZERO
|
||||||
# This is how you export variables with ranges to the editor window
|
# This is how you export variables with ranges to the editor window
|
||||||
export(bool) var debug := false
|
export(bool) var debug := false
|
||||||
@@ -30,16 +32,16 @@ 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()
|
||||||
if debug == true:
|
if debug:
|
||||||
match movementState:
|
match movementState:
|
||||||
moveState.MOVE:
|
moveState.MOVE:
|
||||||
movement_move(delta)
|
movement_move(delta)
|
||||||
@@ -48,12 +50,14 @@ func _physics_process(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
|
||||||
# Godots physics system does that internally
|
# Godots physics system does that internally
|
||||||
# In move_and_collide(...) you have to multiply by delta.
|
# In move_and_collide(...) you have to multiply by delta.
|
||||||
func move():
|
func move():
|
||||||
move_and_slide(velocity)
|
move_and_slide(velocity)
|
||||||
|
|
||||||
|
|
||||||
func movement_move(delta):
|
func movement_move(delta):
|
||||||
var input_vector = Vector2.ZERO
|
var input_vector = Vector2.ZERO
|
||||||
# This is a clever way to handle directional input
|
# This is a clever way to handle directional input
|
||||||
@@ -75,20 +79,23 @@ func movement_move(delta):
|
|||||||
elif Input.is_action_just_pressed("attack"):
|
elif Input.is_action_just_pressed("attack"):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
func movement_hit():
|
func movement_hit():
|
||||||
velocity = Vector2.ZERO
|
velocity = Vector2.ZERO
|
||||||
|
|
||||||
|
|
||||||
func hit_finished():
|
func hit_finished():
|
||||||
movementState = moveState.MOVE
|
movementState = moveState.MOVE
|
||||||
|
|
||||||
|
|
||||||
func _on_Stats_no_health():
|
func _on_Stats_no_health():
|
||||||
queue_free()
|
queue_free()
|
||||||
|
|
||||||
|
|
||||||
func _on_Hurtbox_area_entered(area):
|
func _on_Hurtbox_area_entered(area):
|
||||||
player_stats.health-=area.damage
|
player_stats.health -= area.damage
|
||||||
damage_per_second = damage_per_second + area.damage
|
damage_per_second += area.damage
|
||||||
|
|
||||||
|
|
||||||
func _on_Hurtbox_area_exited(area):
|
func _on_Hurtbox_area_exited(area):
|
||||||
damage_per_second = damage_per_second - area.damage
|
damage_per_second -= area.damage
|
||||||
|
|||||||
@@ -2,13 +2,12 @@ extends Node
|
|||||||
|
|
||||||
const Kind = preload("res://Overlap/Kind.gd") # Relative path
|
const Kind = preload("res://Overlap/Kind.gd") # Relative path
|
||||||
|
|
||||||
|
|
||||||
var object_grid : Array = []
|
var object_grid : Array = []
|
||||||
var prio_grid : Array = []
|
var prio_grid : Array = []
|
||||||
var used_grid : Array = []
|
var used_grid : Array = []
|
||||||
var time_passed := 0.0
|
var time_passed := 0.0
|
||||||
var offset
|
var offset
|
||||||
export(float,0,42.0) var refresh_rate = 1
|
export(float, 0, 42.0) var refresh_rate = 1
|
||||||
|
|
||||||
|
|
||||||
func _draw_object_grid():
|
func _draw_object_grid():
|
||||||
@@ -19,6 +18,7 @@ func _draw_object_grid():
|
|||||||
print(stri)
|
print(stri)
|
||||||
print()
|
print()
|
||||||
|
|
||||||
|
|
||||||
func _draw_prio_grid():
|
func _draw_prio_grid():
|
||||||
for y in range(7):
|
for y in range(7):
|
||||||
var stri = ""
|
var stri = ""
|
||||||
@@ -27,15 +27,16 @@ func _draw_prio_grid():
|
|||||||
print(stri)
|
print(stri)
|
||||||
print()
|
print()
|
||||||
|
|
||||||
|
|
||||||
func _reset_grids():
|
func _reset_grids():
|
||||||
for x in range(14):
|
for x in range(14):
|
||||||
for y in range(7):
|
for y in range(7):
|
||||||
var lulul = object_grid[x][y].back()
|
while (object_grid[x][y].size() != 1):
|
||||||
while (object_grid[x][y].size()!=1):
|
|
||||||
object_grid[x][y].pop_back()
|
object_grid[x][y].pop_back()
|
||||||
while (prio_grid[x][y].size()!=1):
|
while (prio_grid[x][y].size() != 1):
|
||||||
prio_grid[x][y].pop_back()
|
prio_grid[x][y].pop_back()
|
||||||
|
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
var walls = get_tree().current_scene.get_child(1)
|
var walls = get_tree().current_scene.get_child(1)
|
||||||
offset = walls.global_position
|
offset = walls.global_position
|
||||||
@@ -61,49 +62,54 @@ func reset_history():
|
|||||||
for y in range(7):
|
for y in range(7):
|
||||||
used_grid[x][y] = false
|
used_grid[x][y] = false
|
||||||
|
|
||||||
|
|
||||||
func countTargets(table):
|
func countTargets(table):
|
||||||
for x in range(14):
|
for x in range(14):
|
||||||
for y in range(7):
|
for y in range(7):
|
||||||
for i in prio_grid[x][y]:
|
for i in prio_grid[x][y]:
|
||||||
if i == Kind.TERMINAL_SYMBOL:
|
if i == Kind.TERMINAL_SYMBOL:
|
||||||
continue
|
continue
|
||||||
table[i]+=1
|
table[i] += 1
|
||||||
return table
|
return table
|
||||||
|
|
||||||
|
|
||||||
func _pixel_to_grid_coords(pixel : Vector2) -> Vector2:
|
func _pixel_to_grid_coords(pixel : Vector2) -> Vector2:
|
||||||
var new_coords : Vector2
|
var new_coords : Vector2
|
||||||
new_coords.x = floor((pixel.x-offset.x)/32.0)
|
new_coords.x = floor((pixel.x-offset.x) / 32.0)
|
||||||
new_coords.y = floor((pixel.y-offset.y)/32.0)
|
new_coords.y = floor((pixel.y-offset.y) / 32.0)
|
||||||
return new_coords
|
return new_coords
|
||||||
|
|
||||||
|
|
||||||
func _is_in_grid(grid_coords : Vector2) -> bool:
|
func _is_in_grid(grid_coords : Vector2) -> bool:
|
||||||
if(grid_coords.x<0):
|
if(grid_coords.x < 0):
|
||||||
return false
|
return false
|
||||||
if(grid_coords.x>13):
|
if(grid_coords.x > 13):
|
||||||
return false
|
return false
|
||||||
if(grid_coords.y<0):
|
if(grid_coords.y < 0):
|
||||||
return false
|
return false
|
||||||
if(grid_coords.y>6):
|
if(grid_coords.y > 6):
|
||||||
return false
|
return false
|
||||||
return true
|
return true
|
||||||
|
|
||||||
|
|
||||||
func get_nearest(position, kind):
|
func get_nearest(position, kind):
|
||||||
var list = []
|
var list = []
|
||||||
for x in range(14):
|
for x in range(14):
|
||||||
for y in range(7):
|
for y in range(7):
|
||||||
for i in prio_grid[x][y]:
|
for i in prio_grid[x][y]:
|
||||||
if(i == kind):
|
if(i == kind):
|
||||||
list.append([x,y])
|
list.append([x, y])
|
||||||
var dist = []
|
var dist = []
|
||||||
for field in list:
|
for field in list:
|
||||||
var tmp = sqrt(pow(position[0]-field[0],2)+pow(position[1]-field[1],2))
|
var tmp = sqrt(pow(position[0] - field[0], 2) + pow(position[1] - field[1], 2))
|
||||||
dist.append(tmp)
|
dist.append(tmp)
|
||||||
var mini = 0
|
var mini = 0
|
||||||
for i in range(1, dist.size()):
|
for i in range(1, dist.size()):
|
||||||
if(dist[i]<dist[mini]):
|
if(dist[i] < dist[mini]):
|
||||||
mini = i
|
mini = i
|
||||||
return list[mini]
|
return list[mini]
|
||||||
|
|
||||||
|
|
||||||
func _update_grid():
|
func _update_grid():
|
||||||
_reset_grids()
|
_reset_grids()
|
||||||
var world = get_tree().current_scene.get_child(2)
|
var world = get_tree().current_scene.get_child(2)
|
||||||
@@ -111,7 +117,7 @@ func _update_grid():
|
|||||||
var node_kind = node.get_child(0)
|
var node_kind = node.get_child(0)
|
||||||
var grid_corrds = _pixel_to_grid_coords(node.global_position)
|
var grid_corrds = _pixel_to_grid_coords(node.global_position)
|
||||||
if (_is_in_grid(grid_corrds)):
|
if (_is_in_grid(grid_corrds)):
|
||||||
if(node_kind.general!=Kind.FIELD and node_kind.general!=Kind.WALL):
|
if(node_kind.general != Kind.FIELD and node_kind.general != Kind.WALL):
|
||||||
object_grid[grid_corrds.x][grid_corrds.y].push_back(node_kind.general)
|
object_grid[grid_corrds.x][grid_corrds.y].push_back(node_kind.general)
|
||||||
prio_grid[grid_corrds.x][grid_corrds.y].push_back(node_kind.kind)
|
prio_grid[grid_corrds.x][grid_corrds.y].push_back(node_kind.kind)
|
||||||
|
|
||||||
@@ -121,4 +127,3 @@ func _physics_process(delta):
|
|||||||
time_passed -= refresh_rate
|
time_passed -= refresh_rate
|
||||||
_update_grid()
|
_update_grid()
|
||||||
time_passed += delta
|
time_passed += delta
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
extends StaticBody2D
|
extends StaticBody2D
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func _on_Hurtbox_area_entered(area):
|
func _on_Hurtbox_area_entered(area):
|
||||||
queue_free()
|
queue_free()
|
||||||
|
|||||||
@@ -24,5 +24,3 @@ enum{
|
|||||||
|
|
||||||
export(int, "DAMAGE","HEALING","SLOW","WALL","FIELD") var general = DAMAGE
|
export(int, "DAMAGE","HEALING","SLOW","WALL","FIELD") var general = DAMAGE
|
||||||
export(int,"BOSS","PLAYER","TORCH","MINION","RED","BLUE","GREEN","HEART","BONFIRE","BARREL","TERMINAL_SYMBOL") var kind = BOSS
|
export(int,"BOSS","PLAYER","TORCH","MINION","RED","BLUE","GREEN","HEART","BONFIRE","BARREL","TERMINAL_SYMBOL") var kind = BOSS
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ enum moveState{
|
|||||||
IDLE
|
IDLE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var movementState = moveState.MOVE
|
var movementState = moveState.MOVE
|
||||||
|
|
||||||
var damage_per_second := 0.0
|
var damage_per_second := 0.0
|
||||||
@@ -44,21 +43,23 @@ var experience := 0.0
|
|||||||
func _debug_update():
|
func _debug_update():
|
||||||
debug_label.text = str(player_stats.health) + "/" + str(player_stats.max_health) + " HP\n" + str(currency) + " €"
|
debug_label.text = str(player_stats.health) + "/" + str(player_stats.max_health) + " HP\n" + str(currency) + " €"
|
||||||
|
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
grid = get_tree().current_scene.get_node("Grid")
|
grid = get_tree().current_scene.get_node("Grid")
|
||||||
|
|
||||||
|
|
||||||
func _physics_process(delta):
|
func _physics_process(delta):
|
||||||
totaldamage+=(damage_per_second - heal_per_second)*delta
|
totaldamage += (damage_per_second - heal_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
|
||||||
adjustPrio(player_stats.health, player_stats.max_health)
|
adjustPrio(player_stats.health, player_stats.max_health)
|
||||||
_debug_update()
|
_debug_update()
|
||||||
if debug == true:
|
if debug:
|
||||||
match movementState:
|
match movementState:
|
||||||
moveState.MOVE:
|
moveState.MOVE:
|
||||||
movement_move(delta)
|
movement_move(delta)
|
||||||
@@ -81,6 +82,7 @@ func _physics_process(delta):
|
|||||||
move()
|
move()
|
||||||
$"Effects/HealEffect".emitting = heal_per_second > 0
|
$"Effects/HealEffect".emitting = heal_per_second > 0
|
||||||
|
|
||||||
|
|
||||||
# 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
|
||||||
# Godots physics system does that internally
|
# Godots physics system does that internally
|
||||||
# In move_and_collide(...) you have to multiply by delta.
|
# In move_and_collide(...) you have to multiply by delta.
|
||||||
@@ -144,6 +146,7 @@ func movement_hit():
|
|||||||
velocity = Vector2.ZERO
|
velocity = Vector2.ZERO
|
||||||
animation_state.change_state("attack")
|
animation_state.change_state("attack")
|
||||||
|
|
||||||
|
|
||||||
func hit_finished():
|
func hit_finished():
|
||||||
movementState = moveState.IDLE
|
movementState = moveState.IDLE
|
||||||
ExecutionState = AI_MOVE
|
ExecutionState = AI_MOVE
|
||||||
@@ -163,6 +166,7 @@ func movement_roll():
|
|||||||
"""
|
"""
|
||||||
ExecutionState = EXECUTING
|
ExecutionState = EXECUTING
|
||||||
|
|
||||||
|
|
||||||
func roll_finished():
|
func roll_finished():
|
||||||
movementState = moveState.IDLE
|
movementState = moveState.IDLE
|
||||||
ai_movement_state = STEP
|
ai_movement_state = STEP
|
||||||
@@ -170,15 +174,15 @@ func roll_finished():
|
|||||||
|
|
||||||
|
|
||||||
func _on_Hurtbox_area_entered(area):
|
func _on_Hurtbox_area_entered(area):
|
||||||
player_stats.health-=area.damage
|
player_stats.health -= area.damage
|
||||||
|
|
||||||
if area.damage > 0:
|
if area.damage > 0:
|
||||||
damage_per_second += area.damage
|
damage_per_second += area.damage
|
||||||
else:
|
else:
|
||||||
heal_per_second += abs(area.damage)
|
heal_per_second += abs(area.damage)
|
||||||
|
|
||||||
func _on_Hurtbox_area_exited(area):
|
|
||||||
|
|
||||||
|
func _on_Hurtbox_area_exited(area):
|
||||||
if area.damage > 0:
|
if area.damage > 0:
|
||||||
damage_per_second -= area.damage
|
damage_per_second -= area.damage
|
||||||
else:
|
else:
|
||||||
@@ -192,7 +196,7 @@ func _on_Stats_no_health():
|
|||||||
|
|
||||||
func _on_Hitbox_area_entered(area):
|
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 += area.health_value
|
||||||
player_stats.speed -= area.slowdown_value
|
player_stats.speed -= area.slowdown_value
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user