I'm using the macroquad game engine to make a game, and I'm running into a problem where I'm trying to change the value of a bool inside a function and it's not working and my players movement system which revolves around whether gameover (bool)
is false or true.
use macroquad::prelude::*;
#[macroquad::main("InputKeys")]
async fn main() {
let mut x: f32 = screen_width() / 2.0_f32;
let mut y: f32 = screen_width() / 2.0_f32;
let mut gravity_speed: f32 = 1.0_f32;
let speed: f32 = 3.5_f32;
let gameover: bool = false;
loop {
clear_background(GRAY);
if is_key_down(KeyCode::W) {
if gameover == true {
y -= speed;
}
}
if is_key_down(KeyCode::A) {
if gameover == true {
x -= speed;
}
}
if is_key_down(KeyCode::D) {
if gameover == true {
x += speed;
}
}
gravity(&mut y, &mut gravity_speed/*, &mut gameover */);
draw_circle(x, y, 5.0, YELLOW);
next_frame().await;
}
}
fn gravity(n1: &mut f32, n2: &mut f32/*,thingy: &mut bool*/) {
*n1 += *n2;
//println!("{n1}");
if n1 >= &mut 800.0_f32 {
gameover = true;
}
if n1 <= &mut -1.5_f32 {
gameover = true;
}
}
the terminal just returns this with no errors:
warning: unused variable: `gameover`
--> src\main.rs:42:13
|
42 | let gameover = true;
| ^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_gameover`
|
= note: `#[warn(unused_variables)]` on by default
warning: unused variable: `gameover`
--> src\main.rs:45:13
|
45 | let gameover = true;
| ^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_gameover`