-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenemyBuild.lua
More file actions
49 lines (47 loc) · 1.75 KB
/
enemyBuild.lua
File metadata and controls
49 lines (47 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
local enemyStats = require (data_directory .. ".enemyStats")
require (data_directory .. ".enemyStrategies")
function spawnEnemy()
enemy = display.newGroup()
math.randomseed( os.time( ) )
g_enemy = math.random(g_total_players)
print("new enemy: "..g_enemy)
enemyGraphic = display.newImageRect(enemy, (enemies_gfx_directory .. "enemy"..g_enemy .. ".png"), 170, 170 )
enemy.x = dcw - 300
enemy.y = dch - 300
enemy.stats = enemyStats[g_enemy].stats
enemy.stats.health = enemy.stats.maxHealth
local roll = math.random(#strategies[g_enemy])
enemy.strategy = strategies[g_enemy][roll]
enemy.currentAttack = 1
return enemy
end
-- Function to make a health bar.
-- If input is 0, it makes a health bar for the player, if input is 1 it makes an enemy health bar
function makeHealthBar( playerOrEnemy, name )
healthBar = display.newGroup()
healthBar.anchorX = playerOrEnemy
hb_bg = display.newImageRect( healthBar, (gfx_directory .. "/action/healthbar" .. playerOrEnemy .. ".png"), 340, 200 )
hb_bg.anchorX = playerOrEnemy
options = {}
name = display.newText( healthBar, name, 0, -20, 200, 50, "Pixeled Regular", 14, "left" )
name.anchorX = playerOrEnemy
healthBar.bar = display.newRect( healthBar, 0, 0, 300, 29 )
healthBar.bar:setFillColor( 0, 1, 0 )
healthBar.bar.anchorX = playerOrEnemy
healthBar.power = display.newRect( healthBar, 0, 0, 300, 17 )
healthBar.power:setFillColor( 0.2, 0.7, 1 )
healthBar.power.anchorX = playerOrEnemy
if (playerOrEnemy == 1) then
name.align = "right"
healthBar.bar.x, name.x, healthBar.power.x = -20, -20, -20
healthBar.x = dcw - 50
else
healthBar.bar.x, healthBar.power.x, name.x = 20, 20, 20
healthBar.x = 50
end
healthBar.bar.y = -2
healthBar.power.y = 32
healthBar.y = dch - 100
healthBar.anchorY = 1
return healthBar
end