From cc8991f1960cc0bf0ef95d00176111b37988f810 Mon Sep 17 00:00:00 2001 From: Helio Frota <00hf11@gmail.com> Date: Sat, 19 Oct 2024 07:18:46 -0300 Subject: [PATCH] updates --- README.md | 8 +++++- src/main.rs | 76 ++++++++++++++++++++++++++++------------------------ status2.png | Bin 0 -> 5243 bytes 3 files changed, 48 insertions(+), 36 deletions(-) create mode 100644 status2.png diff --git a/README.md b/README.md index e273e9e..cbd6c81 100644 --- a/README.md +++ b/README.md @@ -8,4 +8,10 @@ Rust version of [a game I made years ago](https://github.com/helio-frota/ecstasy cargo run ``` -![current status](./status.png) +> hyprland + +![status](./status.png) + +> X11 with xfce + +![status2](./status2.png) diff --git a/src/main.rs b/src/main.rs index 91d53d8..8a0d75e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,5 @@ use color_eyre::Result; -use macroquad::{audio, prelude::*, time}; +use macroquad::{audio, prelude::*}; use player::Player; extern crate rand; @@ -7,6 +7,7 @@ use rand::Rng; mod player; +// Util functions fn rand_gold_position() -> u32 { let mut rng = rand::thread_rng(); rng.gen_range(0..=3) @@ -14,29 +15,35 @@ fn rand_gold_position() -> u32 { #[macroquad::main("rgold")] async fn main() -> Result<()> { + // Window set_fullscreen(false); let width = 800.; let height = 600.; request_new_screen_size(width, height); + + // Assets set_pc_assets_folder("resources"); let font = load_ttf_font("fonts/OpenSans-Regular.ttf").await?; let gold_sound = audio::load_sound("sounds/gold.wav").await?; + let font_size = 20.0; + // The colors let blue = Color::from_rgba(38, 139, 210, 255); let dark_green = Color::from_rgba(0, 43, 54, 255); let yellow = Color::from_rgba(181, 137, 0, 255); - let mut player = Player::new((width / 2.0) - 20.0, height / 2.0); + // Time and speed initial settings + let mut last_update = get_time(); + let mut nav_lock = false; + let speed = 0.1; + let mut counter = get_time(); + let mut count: f64 = 10.0; + // Player and gold initial settings + let mut p = Player::new((width / 2.0) - 20.0, height / 2.0); let move_length = 20.0; let mut gold_position = rand_gold_position(); - let mut last_update = get_time(); - let mut navigation_lock = false; - let speed = 0.1; - - let mut counter = get_time(); - let mut count: f64 = 60.0; let mut game_over = false; loop { @@ -44,7 +51,7 @@ async fn main() -> Result<()> { clear_background(dark_green); draw_text_ex( - format!("SCORE: {}", player.score).as_str(), + format!("SCORE: {}", p.score).as_str(), 10.0, 20.0, TextParams { @@ -56,7 +63,7 @@ async fn main() -> Result<()> { ); draw_text_ex( - format!("STEPS: {}", player.steps).as_str(), + format!("STEPS: {}", p.steps).as_str(), (width / 2.0) - 60.0, 20.0, TextParams { @@ -102,8 +109,8 @@ async fn main() -> Result<()> { draw_text_ex( "X", - player.x, - player.y, + p.x, + p.y, TextParams { font_size: 40, font: Some(&font), @@ -132,41 +139,38 @@ async fn main() -> Result<()> { _ => warn!(":D"), } - if is_key_down(KeyCode::H) && player.x > 18.0 && !navigation_lock { - player.steps += 1; - player.x -= move_length; - navigation_lock = true; + if is_key_down(KeyCode::H) && p.x > 18.0 && !nav_lock { + p.steps += 1; + p.x -= move_length; + nav_lock = true; audio::play_sound_once(&gold_sound); // gold_position = rand_gold_position(); } else if is_key_down(KeyCode::L) - && player.x < (width - 38.0) - && !navigation_lock + && p.x < (width - 38.0) + && !nav_lock { - player.steps += 1; - player.x += move_length; - navigation_lock = true; + p.steps += 1; + p.x += move_length; + nav_lock = true; // gold_position = rand_gold_position(); } else if is_key_down(KeyCode::J) - && player.y < (height - 10.0) - && !navigation_lock + && p.y < (height - 10.0) + && !nav_lock { - player.steps += 1; - player.y += move_length; - navigation_lock = true; + p.steps += 1; + p.y += move_length; + nav_lock = true; // gold_position = rand_gold_position(); - } else if is_key_down(KeyCode::K) - && player.y > 60.0 - && !navigation_lock - { - player.steps += 1; - player.y -= move_length; - navigation_lock = true; + } else if is_key_down(KeyCode::K) && p.y > 60.0 && !nav_lock { + p.steps += 1; + p.y -= move_length; + nav_lock = true; // gold_position = rand_gold_position(); } if get_time() - last_update > speed { last_update = get_time(); - navigation_lock = false; + nav_lock = false; } if get_time() - counter > 1.0 { @@ -177,9 +181,11 @@ async fn main() -> Result<()> { } } } else { + let text_size = + measure_text("GAME OVER", None, font_size as _, 1.0); draw_text( "GAME OVER", - width / 2.0, + width / 2.0 - text_size.width, height / 2.0, 50.0, DARKGRAY, diff --git a/status2.png b/status2.png new file mode 100644 index 0000000000000000000000000000000000000000..feb079fda10baf7236f582aff22f7c39bd9c6f22 GIT binary patch literal 5243 zcmeHL`Bzid7Cwk&6etdbGOF|ysWKH*1O$=M7D1%}gfc{A6bPac1rk785t)=(nQT#p zFjmBfAprqFK%k0@frOzTgCP>gcoXR1y|>WJX$Wu95f10C03hGKd5L8olvf2{x9%w$tDmkH zFeaKYKYhH}Ib~#dNb*PDeTROuS(18o(njX&#YZKVt&>RsN`MF{GXHR0o5XE595wU^6;3N(OWQ`p_*NZ#4S-YGK0fOE z%7KLs#NL2PPV1pS{Phr$^%S%xegXuToV}DBS8~ zhh?}qZ|+qpfnecf>@N+}%$h|U>VbS5cLJ;VT!i*ULBrUXBstH#jmeHwRRxWztIfg2 zDihh^T^&!JoV5_NWp{)c3oHYgJH^0VZResUCZ{cM!=k%v?Yrg)4?Gu7mm<~krk&XR zi%t#Co;`cOw z7^lI@=xa7sNu9f+=`xgf%`IG55|TyT(1>=m!UP{y`4N{oi16^$&*_)MKw6S%lbuc- zf$;LU-Q7B~Wc{z0!qvX%Wb#s*gi7A $qD37}@pHW*15$h9R>b+ynXPWCx$bd0Wu z!DQAK1E6isG_9kt(bj6QQGc;mtUDzk0CaZKtSU;%A5yY;xTQ6&i(M-xwT|ZV$X$57 z+46E8isL#j4(u_MTkoxA@ad6xiRVA{ODa^>kkdWW6+lW*^T980RSbny!Wd$k$3}w|!{H#~w5v#4 z6T!{Pw@q)-OAUW|-!vwaO!Cf-HDcp7=_j6?%hj-6s#gBrY|2 zbUy$VzhmuMEk0qt2VkThuWh0tEe@o&YFCXoLZhB!OvQh z)wgfoR(ldH1Xjwk>JsZZ2_*sFz{=X2Uv<#7g;SV@RRI1Da5&XR*O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