Skip to content

Commit

Permalink
Refine transform and scaling paramters.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramirisu committed Oct 8, 2024
1 parent 0c10fe5 commit 56c26d5
Show file tree
Hide file tree
Showing 11 changed files with 258 additions and 231 deletions.
6 changes: 3 additions & 3 deletions src/game/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ use super::{

#[derive(Resource)]
pub struct SquareImageAssets {
normal: Vec<Handle<Image>>,
standard: Vec<Handle<Image>>,
small: Vec<Handle<Image>>,
}

impl SquareImageAssets {
pub fn new(image_assets: &mut Assets<Image>, level: usize) -> Self {
Self {
normal: Piece::iter()
standard: Piece::iter()
.map(|piece| {
image_assets.add(get_square_image(SquareImageSize::Standard, *piece, level))
})
Expand All @@ -29,7 +29,7 @@ impl SquareImageAssets {

pub fn get_image(&self, size: SquareImageSize, piece: Piece) -> Handle<Image> {
match size {
SquareImageSize::Standard => self.normal[piece.variant_index()].clone(),
SquareImageSize::Standard => self.standard[piece.variant_index()].clone(),
SquareImageSize::Small => self.small[piece.variant_index()].clone(),
}
}
Expand Down
36 changes: 13 additions & 23 deletions src/game/board.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ pub struct Board {
next_pieces: VecDeque<Piece>,
lines: usize,
score: usize,
single: usize,
double: usize,
triple: usize,
tetris: usize,
lines_clear: [usize; 4],
drought: usize,
max_drought: usize,
piece_count: [usize; Piece::variant_len()],
Expand Down Expand Up @@ -48,10 +45,7 @@ impl Board {
next_pieces,
lines: 0,
score: 0,
single: 0,
double: 0,
triple: 0,
tetris: 0,
lines_clear: [0; 4],
drought: 0,
max_drought: 0,
piece_count: [0; Piece::variant_len()],
Expand All @@ -75,30 +69,30 @@ impl Board {
}

pub fn burned_lines(&self) -> usize {
self.lines - self.tetris * 4
self.lines - self.tetris_clear() * 4
}

pub fn single(&self) -> usize {
self.single
pub fn single_clear(&self) -> usize {
self.lines_clear[0]
}

pub fn double(&self) -> usize {
self.double
pub fn double_clear(&self) -> usize {
self.lines_clear[1]
}

pub fn triple(&self) -> usize {
self.triple
pub fn triple_clear(&self) -> usize {
self.lines_clear[2]
}

pub fn tetris(&self) -> usize {
self.tetris
pub fn tetris_clear(&self) -> usize {
self.lines_clear[3]
}

pub fn tetris_rate(&self) -> f32 {
if self.lines == 0 {
0.0
} else {
self.tetris as f32 * 4.0 / self.lines as f32
self.tetris_clear() as f32 * 4.0 / self.lines as f32
}
}

Expand Down Expand Up @@ -144,10 +138,7 @@ impl Board {
self.score += Self::get_score(rows.len(), self.level());
self.lines += rows.len();
match rows.len() {
1 => self.single += 1,
2 => self.double += 1,
3 => self.triple += 1,
4 => self.tetris += 1,
1..=4 => self.lines_clear[rows.len() - 1] += 1,
_ => (),
}
self.squares
Expand Down Expand Up @@ -276,7 +267,6 @@ impl Board {
fn get_score(lines: usize, level: usize) -> usize {
(level + 1)
* match lines {
0 => 0,
1 => 40,
2 => 100,
3 => 300,
Expand Down
6 changes: 3 additions & 3 deletions src/game/palette.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,18 +157,18 @@ impl SquareImagePattern {
pattern: &[[u8; W]; H],
colors: &[Srgba; 4],
) -> Rgb32FImage {
let mut image = Rgb32FImage::new(W as u32, H as u32);
let mut img = Rgb32FImage::new(W as u32, H as u32);
for y in 0..H {
for x in 0..W {
image.put_pixel(
img.put_pixel(
x as u32,
y as u32,
image::Rgb(colors[pattern[y][x] as usize].to_f32_array_no_alpha()),
);
}
}

image
img
}

const STANDARD_X: &'static [[u8; 18]; 18] = &[
Expand Down
Loading

0 comments on commit 56c26d5

Please sign in to comment.