draw the grid
This commit is contained in:
parent
47ebc63acc
commit
12d4439037
3 changed files with 69 additions and 14 deletions
62
src/game/grid.rs
Normal file
62
src/game/grid.rs
Normal file
|
@ -0,0 +1,62 @@
|
|||
use anyhow::Result;
|
||||
use ggez::{
|
||||
graphics::{self, Color, DrawMode, DrawParam, Mesh, StrokeOptions},
|
||||
nalgebra::Point2,
|
||||
Context,
|
||||
};
|
||||
|
||||
use super::{Game, PLAYFIELD_BOUNDS as BOUNDS};
|
||||
|
||||
pub const GRID_HEAVY: Color = Color::new(1.0, 1.0, 1.0, 0.25);
|
||||
pub const GRID_LIGHT: Color = Color::new(1.0, 1.0, 1.0, 0.05);
|
||||
|
||||
impl Game {
|
||||
pub(super) fn draw_grid(&self, ctx: &mut Context) -> Result<()> {
|
||||
let playfield = Mesh::new_rectangle(
|
||||
ctx,
|
||||
DrawMode::Stroke(StrokeOptions::default()),
|
||||
BOUNDS,
|
||||
Color::new(1.0, 1.0, 1.0, 0.5),
|
||||
)?;
|
||||
graphics::draw(ctx, &playfield, DrawParam::default())?;
|
||||
|
||||
let min_x = BOUNDS.x;
|
||||
let min_y = BOUNDS.y;
|
||||
let max_x = min_x + BOUNDS.w;
|
||||
let max_y = min_y + BOUNDS.h;
|
||||
|
||||
let grid_size = self.beatmap.inner.grid_size;
|
||||
|
||||
for x in (0..512).step_by(grid_size as usize) {
|
||||
let (weight, color) = match x {
|
||||
x if x == 0 || x == 256 || x == 512 => (2.0, GRID_HEAVY),
|
||||
_ => (1.0, GRID_LIGHT),
|
||||
};
|
||||
let x = BOUNDS.x + x as f32 * BOUNDS.w / 512.0;
|
||||
let line = Mesh::new_line(
|
||||
ctx,
|
||||
&[Point2::new(x, min_y), Point2::new(x, max_y)],
|
||||
weight,
|
||||
color,
|
||||
)?;
|
||||
graphics::draw(ctx, &line, DrawParam::default())?;
|
||||
}
|
||||
|
||||
for y in (0..384).step_by(grid_size as usize) {
|
||||
let (weight, color) = match y {
|
||||
y if y == 0 || y == 192 || y == 384 => (2.0, GRID_HEAVY),
|
||||
_ => (1.0, GRID_LIGHT),
|
||||
};
|
||||
let y = BOUNDS.y + y as f32 * BOUNDS.h / 384.0;
|
||||
let line = Mesh::new_line(
|
||||
ctx,
|
||||
&[Point2::new(min_x, y), Point2::new(max_x, y)],
|
||||
weight,
|
||||
color,
|
||||
)?;
|
||||
graphics::draw(ctx, &line, DrawParam::default())?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
mod grid;
|
||||
mod sliders;
|
||||
mod timeline;
|
||||
|
||||
|
@ -10,13 +11,11 @@ use anyhow::Result;
|
|||
use ggez::{
|
||||
event::{EventHandler, KeyCode, KeyMods},
|
||||
graphics::{
|
||||
self, Color, DrawMode, DrawParam, FillOptions, FilterMode, Mesh, Rect, StrokeOptions, Text,
|
||||
WHITE,
|
||||
self, Color, DrawMode, DrawParam, FilterMode, Mesh, Rect, StrokeOptions, Text, WHITE,
|
||||
},
|
||||
nalgebra::Point2,
|
||||
Context, GameError, GameResult,
|
||||
};
|
||||
use libosu::{Beatmap, HitObject, HitObjectKind, Point, SpinnerInfo, Spline};
|
||||
use libosu::{Beatmap, HitObjectKind, Point, SpinnerInfo, Spline};
|
||||
|
||||
use crate::audio::{AudioEngine, Sound};
|
||||
use crate::beatmap::{BeatmapExt, STACK_DISTANCE};
|
||||
|
@ -25,6 +24,9 @@ use crate::skin::Skin;
|
|||
|
||||
use self::sliders::render_slider;
|
||||
|
||||
pub const PLAYFIELD_BOUNDS: Rect = Rect::new(112.0, 112.0, 800.0, 600.0);
|
||||
pub const SEEKER_BOUNDS: Rect = Rect::new(46.0, 722.0, 932.0, 36.0);
|
||||
|
||||
pub type SliderCache = HashMap<Vec<Point<i32>>, Spline>;
|
||||
|
||||
pub struct Game {
|
||||
|
@ -89,18 +91,10 @@ impl Game {
|
|||
|
||||
fn priv_draw(&mut self, ctx: &mut Context) -> Result<()> {
|
||||
// TODO: lol
|
||||
const PLAYFIELD_BOUNDS: Rect = Rect::new(112.0, 112.0, 800.0, 600.0);
|
||||
const SEEKER_BOUNDS: Rect = Rect::new(46.0, 722.0, 932.0, 36.0);
|
||||
|
||||
graphics::clear(ctx, [0.0, 0.0, 0.0, 1.0].into());
|
||||
|
||||
let playfield = Mesh::new_rectangle(
|
||||
ctx,
|
||||
DrawMode::Stroke(StrokeOptions::default()),
|
||||
PLAYFIELD_BOUNDS,
|
||||
Color::new(1.0, 1.0, 1.0, 0.5),
|
||||
)?;
|
||||
graphics::draw(ctx, &playfield, DrawParam::default())?;
|
||||
self.draw_grid(ctx)?;
|
||||
|
||||
let time = self.song.as_ref().unwrap().position()?;
|
||||
let text = Text::new(format!("time: {}", time).as_ref());
|
||||
|
|
1
todo.txt
1
todo.txt
|
@ -1,4 +1,3 @@
|
|||
- stacking
|
||||
- don't draw overlaps between slider segments
|
||||
- use skin components
|
||||
- timeline
|
||||
|
|
Loading…
Add table
Reference in a new issue