Skip to content

Commit 450b6f5

Browse files
author
Tomasz Sterna
committed
Making the level-up more dramatic
1 parent c20d5c2 commit 450b6f5

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

src/damage_system.rs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use super::{
2-
gamelog::GameLog, mana_at_level, player_hp_at_level, Attributes, Equipped, InBackpack,
3-
LootTable, Map, Name, Player, Pools, Position, RunState, SufferDamage,
2+
gamelog::GameLog, mana_at_level, particle_system::ParticleBuilder, player_hp_at_level,
3+
Attributes, Equipped, InBackpack, LootTable, Map, Name, Player, Point, Pools, Position,
4+
RunState, SufferDamage,
45
};
56
use crate::prefabs::{get_item_drop, spawn_named_item, SpawnType, PREFABS};
67
use legion::prelude::*;
@@ -12,9 +13,15 @@ pub fn build() -> Box<(dyn Schedulable + 'static)> {
1213
.read_component::<Position>()
1314
.write_resource::<Map>()
1415
.read_resource::<Entity>()
16+
.write_resource::<GameLog>()
1517
.read_component::<Attributes>()
18+
.write_resource::<ParticleBuilder>()
19+
.read_resource::<Point>()
1620
.build(
17-
|command_buffer, world, (map, player_entity), query| unsafe {
21+
|command_buffer,
22+
world,
23+
(map, player_entity, log, particles, player_pos),
24+
query| unsafe {
1825
let mut xp_gain = 0;
1926
for (entity, mut damage) in query.iter_entities_unchecked(world) {
2027
if let Some(mut stats) = world.get_component_mut_unchecked::<Pools>(entity) {
@@ -45,6 +52,10 @@ pub fn build() -> Box<(dyn Schedulable + 'static)> {
4552
if player_stats.experience >= player_stats.level * 1000 {
4653
// We've gone up a level!
4754
player_stats.level = player_stats.experience / 1000 + 1;
55+
log.entries.push(format!(
56+
"Congratulations, you are now level {}",
57+
player_stats.level
58+
));
4859
player_stats.hit_points.max = player_hp_at_level(
4960
player_attributes.fitness.base + player_attributes.fitness.modifiers,
5061
player_stats.level,
@@ -56,6 +67,19 @@ pub fn build() -> Box<(dyn Schedulable + 'static)> {
5667
player_stats.level,
5768
);
5869
player_stats.mana.current = player_stats.mana.max;
70+
71+
for i in 0..10 {
72+
if player_pos.y - i > 1 {
73+
particles.request(
74+
player_pos.x,
75+
player_pos.y - i,
76+
rltk::RGB::named(rltk::GOLD),
77+
rltk::RGB::named(rltk::BLACK),
78+
rltk::to_cp437('░'),
79+
400.0,
80+
);
81+
}
82+
}
5983
}
6084
}
6185
},

src/monster_ai_system.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use super::{
2-
a_star_search, particle_system::ParticleBuilder, Confusion, Map, Monster, Position, RunState,
3-
Viewshed, WantsToMelee,
2+
a_star_search, particle_system::ParticleBuilder, Confusion, Map, Monster, Point, Position,
3+
RunState, Viewshed, WantsToMelee,
44
};
55
use legion::prelude::*;
6-
use rltk::Point;
76

87
pub fn build() -> Box<(dyn Schedulable + 'static)> {
98
SystemBuilder::new("monster_ai")

0 commit comments

Comments
 (0)