Browse Source

first commit

main
cynthia 3 years ago
commit
5d165532de
  1. 1
      .gitignore
  2. 10
      Cargo.toml
  3. 131
      src/main.rs

1
.gitignore

@ -0,0 +1 @@
/target

10
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"

131
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<Animation>,
}
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<Fish>,
player: Vec2,
caught_fish: Vec<String>,
}
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);
}
Loading…
Cancel
Save