You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 lines
2.6 KiB

3 years ago
  1. #![allow(clippy::upper_case_acronyms)]
  2. #![allow(clippy::new_without_default)]
  3. #![allow(unused)]
  4. use macroquad::prelude::*;
  5. const FISH_PARTS_RIGHT: (&str, &str) = ("><", ">");
  6. const FISH_PARTS_LEFT: (&str, &str) = ("<", "><");
  7. const WATER_LEVEL: i32 = 100;
  8. const WIDTH: i32 = 780;
  9. const FISH_ZONE: i32 = 500;
  10. const FONT_SIZE: f32 = 20.0;
  11. const ANIM_CHANGE: u32 = 150; // in milliseconds
  12. fn window_conf() -> Conf {
  13. Conf {
  14. window_title: "fishing minigame".to_owned(),
  15. window_width: WIDTH,
  16. window_height: FISH_ZONE,
  17. fullscreen: false,
  18. ..Default::default()
  19. }
  20. }
  21. struct Fish {
  22. length: u8,
  23. pos: Vec2,
  24. }
  25. struct Game {
  26. state: State,
  27. draw: Draw,
  28. }
  29. impl Game {
  30. fn new() -> Self {
  31. Self {
  32. state: State::new(),
  33. draw: Draw::new(),
  34. }
  35. }
  36. }
  37. struct Draw {
  38. // only two frames of animation
  39. first_frame: bool,
  40. frame_counter: usize,
  41. animations: Vec<Animation>,
  42. }
  43. impl Draw {
  44. fn new() -> Self {
  45. Self {
  46. first_frame: true,
  47. frame_counter: 0,
  48. animations: Vec::new(),
  49. }
  50. }
  51. }
  52. struct Animation {
  53. width: usize,
  54. height: usize,
  55. color: Color,
  56. frames: [String; 2],
  57. }
  58. impl Animation {
  59. fn new(width: usize, height: usize, color: Color, frames: [String; 2]) -> Self {
  60. assert_eq!(width * height, frames[0].len());
  61. assert_eq!(width * height, frames[1].len());
  62. Self {
  63. width,
  64. height,
  65. color,
  66. frames,
  67. }
  68. }
  69. fn draw(&self, pos: Vec2) {
  70. draw_rectangle(
  71. pos.x,
  72. pos.y,
  73. self.width as f32 * FONT_SIZE,
  74. self.height as f32 * FONT_SIZE,
  75. self.color,
  76. );
  77. }
  78. }
  79. struct State {
  80. fish: Vec<Fish>,
  81. player: Vec2,
  82. caught_fish: Vec<String>,
  83. }
  84. impl State {
  85. fn new() -> Self {
  86. State {
  87. fish: Vec::new(),
  88. player: Vec2::new(FISH_ZONE as f32 / 2.0, WATER_LEVEL as f32),
  89. caught_fish: Vec::new(),
  90. }
  91. }
  92. }
  93. #[macroquad::main(window_conf)]
  94. async fn main() {
  95. let mut game = Game::new();
  96. loop {
  97. if is_key_down(KeyCode::Escape) {
  98. break;
  99. }
  100. draw(&game);
  101. next_frame().await;
  102. }
  103. }
  104. fn draw(game: &Game) {
  105. const FZ: f32 = FISH_ZONE as f32;
  106. const WL: f32 = WATER_LEVEL as f32;
  107. clear_background(SKYBLUE);
  108. // sky
  109. draw_rectangle(0.0, 0.0, FZ, WL, WHITE);
  110. // ground
  111. draw_rectangle(0.0, FZ - 30.0, FZ, 30.0, BEIGE);
  112. // static sprites
  113. // animated stuff
  114. // fish
  115. // sidebar
  116. draw_rectangle(FZ, 0.0, WIDTH as f32 - FZ, FZ, LIGHTGRAY);
  117. }