Skip to content

Commit 8d33a67

Browse files
committed
Monsters and items Progression
1 parent 950490a commit 8d33a67

File tree

1 file changed

+43
-20
lines changed

1 file changed

+43
-20
lines changed

roguebasin.py

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,17 @@
2929
MAX_ROOMS = 30
3030

3131
# Game
32-
# Monsters
33-
MAX_ROOM_MONSTERS = 3
34-
# chances: 80% orc, 20% troll
35-
monster_chances = {'orc': 80, 'troll': 20}
36-
# Items
37-
MAX_ROOM_ITEMS = 2
38-
# chances: 70% healing potion, 10% lightning bolt scroll, 10% fireball scroll, 10% confusion scroll
39-
item_chances = {'heal': 70, 'lightning': 10, 'fireball': 10, 'confuse': 10}
40-
# Healing potion
41-
HEAL_AMOUNT = 4
42-
# Lightning bolt scroll
43-
LIGHTNING_DAMAGE = 20
32+
# Healing potion
33+
HEAL_AMOUNT = 40
34+
# Lightning bolt scroll
35+
LIGHTNING_DAMAGE = 40
4436
LIGHTNING_RANGE = 5
45-
# Confusion
37+
# Confusion
4638
CONFUSE_NUM_TURNS = 10
4739
CONFUSE_RANGE = 8
48-
# Fireball
40+
# Fireball
4941
FIREBALL_RADIUS = 3
50-
FIREBALL_DAMAGE = 12
42+
FIREBALL_DAMAGE = 25
5143
# Experience and level-ups
5244
LEVEL_UP_BASE = 200
5345
LEVEL_UP_FACTOR = 150
@@ -333,6 +325,16 @@ def random_choice(chances_dict):
333325

334326
return strings[random_choice_index(chances)]
335327

328+
# Returns a value that depends on level. The table specifies what
329+
# value occurs after each level, default is 0.
330+
def from_dungeon_level(table):
331+
global dungeon_level
332+
333+
for (value, level) in reversed(table):
334+
if dungeon_level >= level:
335+
return value
336+
return 0
337+
336338
# Fighters
337339
# Handle player death
338340
def player_death(player):
@@ -500,9 +502,30 @@ def closest_monster(max_range):
500502
# Place objects in some room
501503
def place_objects(room):
502504
global objects
505+
506+
# maximum number of monsters per room
507+
max_monsters = from_dungeon_level([[2,1], [3,4], [5,6]])
508+
509+
# chance for each monster
510+
monster_chances = {}
511+
monster_chances['orc'] = 80 # orc always shows up, even if all
512+
# other monsters have 0 chance
513+
monster_chances['troll'] = from_dungeon_level([[15,3], [30,5], [60,7]])
514+
515+
# maximum number of items per room
516+
max_items = from_dungeon_level([[1,1], [2,4]])
517+
518+
# chance of each item (by default they have a chance of 0 at level
519+
# 1, which then goes up)
520+
item_chances = {}
521+
item_chances['heal'] = 35 # healing potion always shows up, even
522+
# if all other items have 0 chance
523+
item_chances['lightning'] = from_dungeon_level([[25,4]])
524+
item_chances['fireball'] = from_dungeon_level([[25,6]])
525+
item_chances['confuse'] = from_dungeon_level([[10,2]])
503526

504527
# choose random number of monsters
505-
num_monsters = libtcod.random_get_int(0, 0, MAX_ROOM_MONSTERS)
528+
num_monsters = libtcod.random_get_int(0, 0, max_monsters)
506529

507530
for i in range(num_monsters):
508531
# choose random spot for this monster
@@ -514,21 +537,21 @@ def place_objects(room):
514537
choice = random_choice(monster_chances)
515538
if choice == 'orc':
516539
# create an orc
517-
fighter_component = Fighter(hp=10, defense=0, power=3, xp=35, death_function=monster_death)
540+
fighter_component = Fighter(hp=20, defense=0, power=4, xp=35, death_function=monster_death)
518541
ai_component = BasicMonster()
519542
monster = Object(x, y, 'o', 'orc', libtcod.desaturated_green,
520543
blocks=True, fighter=fighter_component, ai=ai_component)
521544
elif choice == 'troll':
522545
# create a troll
523-
fighter_component = Fighter(hp=16, defense=1, power=4, xp=100, death_function=monster_death)
546+
fighter_component = Fighter(hp=30, defense=2, power=8, xp=100, death_function=monster_death)
524547
ai_component = BasicMonster()
525548
monster = Object(x, y, 'T', 'troll', libtcod.darker_green,
526549
blocks=True, fighter=fighter_component, ai=ai_component)
527550

528551
objects.append(monster)
529552

530553
# choose random number of items
531-
num_items = libtcod.random_get_int(0, 0, MAX_ROOM_ITEMS)
554+
num_items = libtcod.random_get_int(0, 0, max_items)
532555

533556
for i in range(num_items):
534557
# choose random spot for this item
@@ -982,7 +1005,7 @@ def new_game():
9821005

9831006
# Player init
9841007
# create object representing the player
985-
fighter_component = Fighter(hp=30, defense=2, power=5, xp=0, death_function=player_death)
1008+
fighter_component = Fighter(hp=100, defense=1, power=4, xp=0, death_function=player_death)
9861009
player = Object(0, 0, '@', 'player', libtcod.white, blocks=True, fighter=fighter_component)
9871010
player.level = 1
9881011

0 commit comments

Comments
 (0)