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