Skip to content

Commit 13171a9

Browse files
committed
improve representation
1 parent 42be3ea commit 13171a9

File tree

5 files changed

+56
-40
lines changed

5 files changed

+56
-40
lines changed

assets/elf_char.png

1.09 MB
Loading

src/gamestate/gameover.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,20 @@ use super::GameState;
44

55
pub fn process(gs: &mut GameState) {
66
clear_background(BLACK);
7+
8+
super::draw_elf_message(gs);
9+
710
draw_text(
811
"GAME OVER",
912
screen_width() / 2.0 - 80.0,
10-
screen_height() / 2.0,
13+
screen_height() / 2.0 + 160.,
1114
40.0,
1215
RED,
1316
);
1417
draw_text(
1518
"Press Return to Restart",
16-
screen_width() / 2.0 - 120.0,
17-
screen_height() / 2.0 + 50.0,
19+
screen_width() / 2.0 - 100.0,
20+
screen_height() / 2.0 + 250.0,
1821
20.0,
1922
DARKGRAY,
2023
);

src/gamestate/mod.rs

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -502,10 +502,11 @@ I told you did I?
502502
}
503503
GameStateEnum::GameOver => {
504504
let tmp = r##"
505-
Ohh no! We lost, you wanna cheat to win?.-.
506-
Just change the `main<dot>roto` - you can.
507-
change the wave composition or even.
508-
reduce the number of waves.
505+
Ohh no! We lost, want an easier experience?.-.
506+
Just change the `scripts/main,roto`!.-.
507+
YOU can change the wave composition or even.
508+
reduce the number of waves.-.
509+
Just save the file and Press Return here!
509510
"##;
510511
tmp
511512
}
@@ -514,8 +515,9 @@ reduce the number of waves.
514515
We did it! Why that sad face?.-.
515516
The evil forces won't affect xmas!.-.
516517
Okay too easy!? My suggestions:.
517-
1- Change Number of waves in main<dot>roto
518-
2- Don't use the weapon you think is best.
518+
1: Change Number of waves in scripts/main,roto.
519+
2: Don't use the weapon you think is best.-.-
520+
Just save the file and Press Return here!
519521
"##;
520522
tmp
521523
}
@@ -584,3 +586,33 @@ Okay too easy!? My suggestions:.
584586
}
585587
}
586588
}
589+
590+
pub fn draw_elf_message(gs: &GameState) -> bool {
591+
if let Some(msg) = &gs.message_from_elf {
592+
let texture = &gs.visual_config.char_tex.as_ref().unwrap();
593+
594+
let mut params = DrawTextureParams::default();
595+
let (w, h, s) = (texture.width(), texture.height(), 0.33);
596+
let x = 0.;
597+
let y = 0.;
598+
params.dest_size = Some(Vec2::new(w * s, h * s));
599+
600+
draw_texture_ex(texture, x, y, WHITE, params);
601+
602+
let x = 300.;
603+
let y = 60.;
604+
draw_text("The Guardian:", x, y, 32., YELLOW);
605+
606+
let y = 100.;
607+
msg.split('.')
608+
.filter(|sentence| !sentence.is_empty())
609+
.enumerate()
610+
.for_each(|(i, sentence)| {
611+
let line = sentence.trim();
612+
draw_text(line, x, y + i as f32 * 22., 20., WHITE);
613+
});
614+
true
615+
} else {
616+
false
617+
}
618+
}

src/gamestate/weapon_selection.rs

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -45,30 +45,9 @@ pub fn draw(gs: &GameState) {
4545
// Draw the playing state underneath (frozen)
4646
clear_background(BLACK);
4747

48-
if let Some(msg) = &gs.message_from_elf {
49-
let texture = &gs.visual_config.char_tex.as_ref().unwrap();
50-
51-
let mut params = DrawTextureParams::default();
52-
let (w, h, s) = (texture.width(), texture.height(), 0.33);
53-
let x = 0.;
54-
let y = 0.;
55-
params.dest_size = Some(Vec2::new(w * s, h * s));
56-
57-
draw_texture_ex(texture, x, y, WHITE, params);
58-
59-
let x = 300.;
60-
let y = 60.;
61-
draw_text("The Guardian:", x, y, 32., YELLOW);
62-
63-
let y = 100.;
64-
msg.split('.')
65-
.filter(|sentence| !sentence.is_empty())
66-
.enumerate()
67-
.for_each(|(i, sentence)| {
68-
let line = sentence.trim();
69-
draw_text(line, x, y + i as f32 * 22., 20., WHITE);
70-
});
71-
} else {
48+
let has_been_drawn = super::draw_elf_message(gs);
49+
50+
if !has_been_drawn {
7251
crate::gamestate::playing::draw(gs);
7352
// Draw semi-transparent overlay
7453
draw_rectangle(

src/gamestate/won.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ use super::GameState;
55
pub fn process(gs: &mut GameState) {
66
clear_background(BLACK);
77

8+
super::draw_elf_message(gs);
9+
810
// Draw victory message
911
draw_text(
1012
"VICTORY!",
1113
screen_width() / 2.0 - 100.0,
12-
screen_height() / 2.0 - 80.0,
14+
screen_height() / 2.0 + 80.0,
1315
60.0,
1416
GOLD,
1517
);
@@ -20,7 +22,7 @@ pub fn process(gs: &mut GameState) {
2022
draw_text(
2123
&congrats_text,
2224
screen_width() / 2.0 - congrats_width / 2.0,
23-
screen_height() / 2.0 - 20.0,
25+
screen_height() / 2.0 + 140.0,
2426
24.0,
2527
YELLOW,
2628
);
@@ -30,7 +32,7 @@ pub fn process(gs: &mut GameState) {
3032
draw_text(
3133
&level_text,
3234
screen_width() / 2.0 - 80.0,
33-
screen_height() / 2.0 + 30.0,
35+
screen_height() / 2.0 + 170.0,
3436
20.0,
3537
LIGHTGRAY,
3638
);
@@ -39,7 +41,7 @@ pub fn process(gs: &mut GameState) {
3941
draw_text(
4042
&xp_text,
4143
screen_width() / 2.0 - 70.0,
42-
screen_height() / 2.0 + 60.0,
44+
screen_height() / 2.0 + 200.0,
4345
20.0,
4446
LIGHTGRAY,
4547
);
@@ -50,7 +52,7 @@ pub fn process(gs: &mut GameState) {
5052
draw_text(
5153
"Weapons:",
5254
screen_width() / 2.0 - 50.0,
53-
screen_height() / 2.0 + 100.0,
55+
screen_height() / 2.0 + 240.0,
5456
18.0,
5557
LIGHTGRAY,
5658
);
@@ -60,7 +62,7 @@ pub fn process(gs: &mut GameState) {
6062
draw_text(
6163
&weapon_text,
6264
screen_width() / 2.0 - 60.0,
63-
screen_height() / 2.0 + 125.0 + (i as f32 * 22.0),
65+
screen_height() / 2.0 + 265.0 + (i as f32 * 22.0),
6466
16.0,
6567
GRAY,
6668
);
@@ -71,7 +73,7 @@ pub fn process(gs: &mut GameState) {
7173
draw_text(
7274
"Press Return to Play Again",
7375
screen_width() / 2.0 - 140.0,
74-
screen_height() / 2.0 + 200.0,
76+
screen_height() / 2.0 + 340.0,
7577
22.0,
7678
WHITE,
7779
);

0 commit comments

Comments
 (0)