-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial Commit. Figuring out the engine a little.
Created player and enemy healthbars. Capable of making more enemies and players. Next commit should be moving the healthbars.
- Loading branch information
0 parents
commit 5d4549e
Showing
1 changed file
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
local function debugPrint(...) | ||
print(...) | ||
end | ||
|
||
--TODO: Make healthbar change based on health% | ||
|
||
--HEALTHBAR SIZES | ||
local WIDTH = 150 | ||
local HEIGHT = 75 | ||
|
||
|
||
local enemies = {} | ||
local player = {basehealth = 300, baseatk = 10} | ||
|
||
function drawLevel() | ||
love.graphics.clear() | ||
clearEnemies() | ||
drawEnemy(1) | ||
drawPlayer() | ||
love.graphics.present() | ||
end | ||
|
||
function clearEnemies() | ||
enemies = {} | ||
return enemies or nil | ||
end | ||
|
||
function drawEnemy(numEnemy) | ||
local x = 50 | ||
local y = ((numEnemy-1)*(HEIGHT+1)) | ||
love.graphics.setColor(255, 0, 0) | ||
love.graphics.rectangle("fill", x, y, WIDTH, HEIGHT) | ||
love.graphics.setColor(255,255,255) | ||
love.graphics.rectangle("line", x, y, WIDTH+1, HEIGHT+1) | ||
createEnemy(numEnemy) | ||
local healthText = createEnemyHealthText(numEnemy) | ||
local font = love.graphics.getFont() | ||
love.graphics.setColor(0,0,0) | ||
love.graphics.printf(healthText, font, x, y+30, 150, "center") | ||
end | ||
|
||
function createEnemy(numEnemy) | ||
local enemy = {} | ||
enemy.basehealth = 100 | ||
enemy.baseatk = 10 | ||
table.insert(enemies, enemy) | ||
return enemies[numEnemy] or nil | ||
end | ||
|
||
function createEnemyHealthText(numEnemy) | ||
local healthText = enemies[numEnemy].basehealth | ||
return healthText or nil | ||
end | ||
|
||
function drawPlayer() | ||
local x = 0 | ||
local y = 300 | ||
love.graphics.setColor(0, 255, 0) | ||
love.graphics.rectangle("fill", x, y, WIDTH, HEIGHT) | ||
love.graphics.setColor(255,255,255) | ||
love.graphics.rectangle("line", x, y, WIDTH+1, HEIGHT+1) | ||
local healthText = createPlayerHealthText() | ||
local font = love.graphics.getFont() | ||
love.graphics.setColor(0,0,0) | ||
love.graphics.printf(healthText, font, x, y+30, 150, "center") | ||
end | ||
|
||
function createPlayerHealthText() | ||
local healthText = player.basehealth | ||
return healthText or nil | ||
end | ||
|
||
function love.draw() | ||
drawLevel() | ||
end |