Minor Code Cleanup

This commit is contained in:
2020-04-19 21:58:01 +02:00
parent 7b1d57dfb5
commit 38c5caa868
5 changed files with 61 additions and 48 deletions

View File

@@ -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
@@ -39,7 +41,7 @@ func _physics_process(delta):
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

View File

@@ -2,7 +2,6 @@ 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 = []
@@ -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,6 +62,7 @@ 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):
@@ -70,12 +72,14 @@ func countTargets(table):
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
@@ -87,6 +91,7 @@ func _is_in_grid(grid_coords : Vector2) -> bool:
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):
@@ -104,6 +109,7 @@ func get_nearest(position, kind):
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)
@@ -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

View File

@@ -1,6 +1,5 @@
extends StaticBody2D extends StaticBody2D
func _on_Hurtbox_area_entered(area): func _on_Hurtbox_area_entered(area):
queue_free() queue_free()

View File

@@ -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

View File

@@ -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
@@ -177,8 +181,8 @@ func _on_Hurtbox_area_entered(area):
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