Commit 5dfcfaa2 authored by tgw3ff's avatar tgw3ff
Browse files

Implement Chest Loot

The player character now had a max_health variable along with their health
variable. Upon opening a chest, the player will either have their health
replenished by a random integer betweeen a pre-defined range, or have their
max_health upgraded by a random integer in the same range.

If the player is at max health when opening a chest, they will never have
their health replenished, but instead will always have their max_health
upgraded.
parent a5f6e34c
61528
C:\Users\Username\Desktop\Godot_v3.2.3-stable_mono_win64\Godot_v3.2.3-stable_mono_win64.exe
......@@ -84,6 +84,25 @@ func harm(damage: float):
# if health <= 0:
# kill()
func heal(replenish: float):
health += replenish
print(">" + self.name + " healed " + String(replenish) + " health.")
if health > max_health:
health = max_health
life_update();
# if health <= 0:
# kill()
func health_upgrade(upgrade: float):
max_health += upgrade
print(">" + self.name + " had their health upgraded by " + String(upgrade) + " points.")
life_update();
# if health <= 0:
# kill()
func life_update():
if health <= 0:
# kill()
......@@ -104,7 +123,7 @@ func _draw():
var font = label.get_font('')
label.queue_free()
draw_string(font, Vector2(OS.window_size.x/5.5, OS.window_size.y/6), 'Dashes: ' + str(dashCharges), Color(1.0, 1.0, 0.0, 1.0))
draw_string(font, Vector2(OS.window_size.x/5.5, OS.window_size.y/5), 'Health: ' + str(health),Color(1.0, 1.0, 0.0, 1.0))
draw_string(font, Vector2(OS.window_size.x/5.5, OS.window_size.y/5), 'Health: ' + str(health) + ' / ' + str(max_health), Color(1.0, 1.0, 0.0, 1.0))
draw_string(font, Vector2(OS.window_size.x/5.5, OS.window_size.y/4), 'Level: ' + str(level),Color(1.0, 1.0, 0.0, 1.0))
# Calculates and returns the coordinate of the player in the map by taking its
......@@ -133,4 +152,8 @@ func _process(_delta):
#Stats
var speed: float = 1 #Controls how frequently the player can act; increases the rate at which delay is gone through
var health: float = 12
var max_health: float = 12
var action_taken: bool = false
# These two constants are used when generating a random amount of points to heal or upgrade total health by
const MAX_HEAL = 4
const MIN_HEAL = 1
......@@ -32,6 +32,8 @@ var distance_wall = 0
var player_spawn = false
# Stores whether or not this cell is an enmey spawn
var enemy_spawn = false
# Stores whether or not the chest has been opened, if the cell houses a chest
var opened = false
func _init(coord, value):
......
......@@ -467,10 +467,11 @@ func spawn_chests():
chest_spawns.append(room.get_random_hole_spawn())
for spawn in chest_spawns:
if !coord_in_what_room(spawn).spawn_room:
print(spawn)
grid[spawn.y][spawn.x].content = CELL.CHEST
grid[spawn.y][spawn.x].elligible_hole = false
if (spawn.x > -1) && (spawn.y > -1):
if !coord_in_what_room(spawn).spawn_room:
print(spawn)
grid[spawn.y][spawn.x].content = CELL.CHEST
grid[spawn.y][spawn.x].elligible_hole = false
# Generates a new map
func generate_map(fill_percent, width, height):
......
......@@ -216,6 +216,18 @@ func update_tile(x, y):
CELL.CHEST:
index = CELL.ROCK_T
autotile = Vector2(0, 1)
# Surrond chests with brick paths
for x_mod in range(-1, 2):
for y_mod in range(-1, 2):
if !(x_mod == 0 && y_mod == 0):
print(x_mod, " ", y_mod)
var content = map_gen.grid[y + y_mod][x + x_mod].content
if content != CELL.WALL && content != CELL.WATER && content != CELL.WATER_T && content != CELL.HOLE:
set_cell(x + x_mod, y + y_mod, CELL.BRICK, false, false, false, Vector2(x_mod + 1, y_mod + 1))
map_gen.grid[y + y_mod][x + x_mod].content = CELL.BRICK
CELL.BRICK:
return
set_cell(x, y, index, false, false, false, autotile)
......@@ -256,14 +268,34 @@ func update_map():
func break_obstacle(x, y):
var index = map_gen.grid[y][x].content
var autotile = null
var player = get_node("../ActorManager/Player")
match index:
CELL.ROCK_T:
player.action_taken = true
autotile = Vector2(1, 0)
CELL.PLANT_T:
player.action_taken = true
autotile = Vector2(1, 0)
CELL.CHEST:
index = CELL.ROCK_T
autotile = Vector2(1, 1)
player.action_taken = true
if !map_gen.grid[y][x].opened:
index = CELL.ROCK_T
autotile = Vector2(1, 1)
randomize()
var outcome = randi() % 3
var heal_amount = randi() % (player.MAX_HEAL - player.MIN_HEAL) + player.MIN_HEAL
map_gen.grid[y][x].opened = true
if outcome < 2:
if player.health < player.max_health:
player.heal(heal_amount)
else:
player.health_upgrade(heal_amount)
else:
player.health_upgrade(heal_amount)
if autotile != null:
set_cell(x, y, index, false, false, false, autotile)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment