commit 5d165532dee48a1c2dc4541ef822481c04278cb6 Author: cynthia <7065188-licynthiax@users.noreply.gitlab.com> Date: Sun Jul 25 19:59:17 2021 -0700 first commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..731eac1 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "fishing-minigame" +version = "0.1.0" +authors = ["cynthia <7065188-licynthiax@users.noreply.gitlab.com>"] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +macroquad = "0.3" diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..56f2e36 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,131 @@ +#![allow(clippy::upper_case_acronyms)] +#![allow(clippy::new_without_default)] +#![allow(unused)] +use macroquad::prelude::*; + +const FISH_PARTS_RIGHT: (&str, &str) = ("><", ">"); +const FISH_PARTS_LEFT: (&str, &str) = ("<", "><"); +const WATER_LEVEL: i32 = 100; +const WIDTH: i32 = 780; +const FISH_ZONE: i32 = 500; +const FONT_SIZE: f32 = 20.0; +const ANIM_CHANGE: u32 = 150; // in milliseconds + +fn window_conf() -> Conf { + Conf { + window_title: "fishing minigame".to_owned(), + window_width: WIDTH, + window_height: FISH_ZONE, + fullscreen: false, + ..Default::default() + } +} + +struct Fish { + length: u8, + pos: Vec2, +} + +struct Game { + state: State, + draw: Draw, +} + +impl Game { + fn new() -> Self { + Self { + state: State::new(), + draw: Draw::new(), + } + } +} + +struct Draw { + // only two frames of animation + first_frame: bool, + frame_counter: usize, + animations: Vec, +} + +impl Draw { + fn new() -> Self { + Self { + first_frame: true, + frame_counter: 0, + animations: Vec::new(), + } + } +} + +struct Animation { + width: usize, + height: usize, + color: Color, + frames: [String; 2], +} + +impl Animation { + fn new(width: usize, height: usize, color: Color, frames: [String; 2]) -> Self { + assert_eq!(width * height, frames[0].len()); + assert_eq!(width * height, frames[1].len()); + Self { + width, + height, + color, + frames, + } + } + + fn draw(&self, pos: Vec2) { + draw_rectangle( + pos.x, + pos.y, + self.width as f32 * FONT_SIZE, + self.height as f32 * FONT_SIZE, + self.color, + ); + } +} + +struct State { + fish: Vec, + player: Vec2, + caught_fish: Vec, +} + +impl State { + fn new() -> Self { + State { + fish: Vec::new(), + player: Vec2::new(FISH_ZONE as f32 / 2.0, WATER_LEVEL as f32), + caught_fish: Vec::new(), + } + } +} + +#[macroquad::main(window_conf)] +async fn main() { + let mut game = Game::new(); + loop { + if is_key_down(KeyCode::Escape) { + break; + } + draw(&game); + next_frame().await; + } +} + +fn draw(game: &Game) { + const FZ: f32 = FISH_ZONE as f32; + const WL: f32 = WATER_LEVEL as f32; + clear_background(SKYBLUE); + // sky + draw_rectangle(0.0, 0.0, FZ, WL, WHITE); + // ground + draw_rectangle(0.0, FZ - 30.0, FZ, 30.0, BEIGE); + // static sprites + // animated stuff + // fish + // sidebar + draw_rectangle(FZ, 0.0, WIDTH as f32 - FZ, FZ, LIGHTGRAY); +}