-
Notifications
You must be signed in to change notification settings - Fork 1
/
Level.lua
124 lines (104 loc) · 3.9 KB
/
Level.lua
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
Level = class('Level')
function Level:initialize(opts)
-- Possible enemies to spawn and possible chest items
self.enemies = opts.enemies ; assert(self.enemies and self.enemies:length() > 0)
self.chest_items = opts.chest_items ; assert(self.chest_items and self.chest_items:length() > 0)
-- If an enemy rate is 0.1, then we draw an enemy every 10 cells
-- There's a separate rate for halls and rooms
self.hall_enemy_rate = opts.hall_enemy_rate ; assert(self.hall_enemy_rate)
self.room_enemy_rate = opts.room_enemy_rate ; assert(self.room_enemy_rate)
-- Odds that we'll put a chest in a room, from 0 to 1
self.chest_chance = opts.chest_chance ; assert(self.chest_chance)
-- Never place a chest in rooms with fewer than this many enemies
self.chest_guards = opts.chest_guards or 0
-- Min and max for gold pile sizes
self.gold_range = opts.gold_range ; assert(type(self.gold_range) == 'table' and #self.gold_range == 2)
-- Max health a player can have here (health is increased in proportion,
-- e.g., if you have 10 / 20, then going to the next level will give you
-- 15 / 30)
self.max_health = opts.max_health ; assert(self.max_health)
end
-- Returns a randomly-filled chest
function Level:chest()
local c1 = self.chest_items:random()
local c2 = self.chest_items:random()
-- Make sure we give 'em a choice...
if c1 == c2 then return self:chest() end
-- Most items don't take any args, but gold takes an amount
local i1 = c1(math.random(unpack(self.gold_range)))
local i2 = c2(math.random(unpack(self.gold_range)))
return Chest(i1, i2)
end
--------------------------------------------------
local HP = HealthPotion ; local G = Gold
local A1, A2, A3 = Leather, Chainmail, Plate
Level.static.LEVELS = {
-- 1 --------------------
Level{
enemies = List{Orc},
chest_items = List{HP, HP, G, ShortSword, Hammer, A1, A1, Mirror, AmuletStrength, AmuletSpeed},
gold_range = {50, 100},
hall_enemy_rate = 0,
room_enemy_rate = 0.1,
chest_chance = 0.5,
chest_guards = 0,
max_health = 20
},
-- 2 --------------------
Level{
enemies = List{Orc, Skeleton},
chest_items = List{HP, HP, G, Axe, Longsword, A1, Mirror, AmuletStrength, AmuletSpeed},
gold_range = {100, 150},
hall_enemy_rate = 0,
room_enemy_rate = 0.15,
chest_chance = 0.5,
chest_guards = 1,
max_health = 30
},
-- 3 --------------------
Level{
enemies = List{Orc, Skeleton, Skeleton},
chest_items = List{HP, G, Axe, Longsword, A2, Mirror, Shoes, AmuletStrength, AmuletSpeed},
gold_range = {75, 150},
hall_enemy_rate = 0.1,
room_enemy_rate = 0.2,
chest_chance = 0.5,
chest_guards = 2,
max_health = 45
},
-- 4 --------------------
Level{
enemies = List{Orc, Skeleton, Skeleton, Troll},
chest_items = List{HP, G, Spear, Mace, A2, Mirror, Shoes, AmuletStrength, AmuletSpeed},
gold_range = {200, 320},
hall_enemy_rate = 0.1,
room_enemy_rate = 0.2,
chest_chance = 0.5,
chest_guards = 2,
max_health = 60,
},
-- 5 --------------------
Level{
enemies = List{Skeleton, Skeleton, Troll},
chest_items = List{HP, G, G, A3, Shoes, Mirror, AmuletStrength, AmuletSpeed},
gold_range = {250, 500},
hall_enemy_rate = 0.15,
room_enemy_rate = 0.2,
chest_chance = 0.5,
chest_guards = 2,
max_health = 80,
},
-- 6 --------------------
Level{
enemies = List{Skeleton, Troll},
chest_items = List{HP, G, G},
gold_range = {300, 800},
hall_enemy_rate = 0.15,
room_enemy_rate = 0.2,
chest_chance = 0.5,
chest_guards = 2,
max_health = 100,
},
}
--------------------------------------------------
return Level