@@ 3,31 3,7 @@ use rand::Rng;
use raylib::Color;
use std::time;
-const LIGHTYELLOW: raylib::Color = raylib::Color {
- r: 255,
- g: 251,
- b: 83,
- a: 255,
-};
-const LIGHTBLUE: raylib::Color = raylib::Color {
- r: 62,
- g: 157,
- b: 255,
- a: 255,
-};
-const LIGHTRED: raylib::Color = raylib::Color {
- r: 252,
- g: 64,
- b: 78,
- a: 255,
-};
-const LIGHTGREEN: raylib::Color = raylib::Color {
- r: 45,
- g: 255,
- b: 87,
- a: 255,
-};
-
+#[derive(PartialEq)]
enum SimonColor {
Yellow,
Blue,
@@ 43,11 19,11 @@ enum GameState {
fn main() {
let rl = raylib::init().size(640, 480).title("Simon Says").build();
- rl.set_target_fps(60);
let mut state = GameState::WelcomeScreen;
let mut colors: Vec<SimonColor> = vec![];
- for _ in 0..50 {
+ let mut userinputs: Vec<SimonColor> = vec![];
+ for _ in 0..=5 {
add_color(&mut colors); // add the first color already
}
let mut pos_in_seq = 0;
@@ 74,14 50,27 @@ fn main() {
pos_in_seq += 1;
starttime = time::Instant::now();
} else {
- //state = GameState::UserInput;
+ state = GameState::UserInput;
println!("End of sequence reached.");
}
+ } else if time::Instant::now() + time::Duration::from_secs(1) - starttime
+ >= wait_dura
+ {
+ draw_buttons(&rl);
} else {
continue;
}
}
- _ => break,
+ GameState::UserInput => {
+ if rl.is_mouse_button_pressed(0) {
+ userinputs.push(button_lookup(rl.get_mouse_position()));
+ for i in 0..colors.len() {
+ if colors[i] != userinputs[i] {
+ rl.draw_text(" - WRONG -", 150, 40, 60, Color::RED);
+ }
+ }
+ }
+ }
}
rl.end_drawing();
}
@@ 141,9 130,9 @@ fn playbutton_pressed(v: raylib::Vector2
fn flash_button(rl: &raylib::RaylibHandle, c: &SimonColor) {
match c {
- SimonColor::Yellow => rl.draw_rectangle(10, 10, 305, 225, LIGHTYELLOW),
- SimonColor::Blue => rl.draw_rectangle(325, 10, 305, 225, LIGHTBLUE),
- SimonColor::Red => rl.draw_rectangle(10, 245, 305, 225, LIGHTRED),
- SimonColor::Green => rl.draw_rectangle(325, 245, 305, 225, LIGHTGREEN),
+ SimonColor::Yellow => rl.draw_rectangle(86, 63, 153, 123, Color::ORANGE),
+ SimonColor::Blue => rl.draw_rectangle(406, 63, 153, 123, Color::DARKBLUE),
+ SimonColor::Red => rl.draw_rectangle(86, 300, 153, 123, Color::PINK),
+ SimonColor::Green => rl.draw_rectangle(406, 300, 153, 123, Color::LIME),
}
}