Fixed map issues and added a debug map for testing the different textures

This commit is contained in:
2022-05-17 16:44:42 +02:00
parent 0750939096
commit 0a88fc7924

View File

@@ -7,8 +7,8 @@ use sdl2::rect::Point;
use sdl2::rect::Rect;
use rand::Rng;
const WINDOW_HEIGHT:i32 = 1000;
const WINDOW_WIDTH:i32 = 800;
const WINDOW_HEIGHT:i32 = 1000;
const BALL_SPEED:f32 = 3.0;
const MAX_SPEED:f32 = 60.0;
const DEBUG_FX_SIZE_RATIO:i32 = 2;
@@ -21,60 +21,65 @@ const DEFAULT_START_BALL_LOCATION_Y:i32 = (WINDOW_HEIGHT / 5) * 4 - DEFAULT_BALL
const DEFAULT_MAP_WIDTH:i32 = 40;
const DEFAULT_MAP_HEIGHT:i32 = 50;
const DEFAULT_TEST_MAP:&[i32] = &[
0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0, 0,0,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0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,1,2,1,0,2,
3,2,3,2,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,1,2,1,2,
3,3,2,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,1,2,2,
3,3,3,3,3,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,2,2,2,2,2,
];
pub struct Map{
@@ -94,7 +99,7 @@ impl Map{
let mut rng = rand::thread_rng();
for x in 0..self.size.x{
for y in 0..self.size.y{
let index = (x * self.size.y) + y;
let index = x + self.size.x * y;
self.grid[index as usize] = rng.gen_range(0..6);
}
}
@@ -105,22 +110,23 @@ impl Map{
for x in 0..self.size.x{
for y in 0..self.size.y{
let rect = Rect::new(x * width,y * height,width as u32,height as u32);
let index = (x * height) + y;
let index = x + self.size.x * y;
let tile_color:Color = Color::RGB(0xFF, 0xFF, 0xFF);
let tile_bg:Color;
match self.grid[index as usize]{
0 => {
//Ground
tile_bg = Color::RGB(0x6A,0x9A,0x1D);
}
1 =>{
//Water
tile_bg = Color::RGB(0x59, 0xA5, 0xD8);
}
2 =>{
//Wall
tile_bg = Color::RGB(0x17, 0x2A, 0x33);
}
2 =>{
//Water
tile_bg = Color::RGB(0x59, 0xA5, 0xD8);
}
3 =>{
//Sand
tile_bg = Color::RGB(0xCA, 0x89, 0x5F);