mirror of
https://github.com/Noratrieb/game-wip-dontplay.git
synced 2026-01-17 04:45:02 +01:00
Adjust code to new 100,000 block limit
This commit is contained in:
parent
30dbddeaff
commit
462eede90f
3 changed files with 29 additions and 15 deletions
21
src/app.rs
21
src/app.rs
|
|
@ -15,7 +15,7 @@ use crate::{
|
||||||
input::Input,
|
input::Input,
|
||||||
math::{px_per_frame_to_km_h, WorldPos, M_PER_PX, TILE_SIZE},
|
math::{px_per_frame_to_km_h, WorldPos, M_PER_PX, TILE_SIZE},
|
||||||
res::Res,
|
res::Res,
|
||||||
world::Tile,
|
world::{Tile, TilePosScalar, CHUNK_EXTENT},
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Application level state (includes game and ui state, etc.)
|
/// Application level state (includes game and ui state, etc.)
|
||||||
|
|
@ -142,8 +142,10 @@ impl App {
|
||||||
});
|
});
|
||||||
self.game.player.vspeed += self.game.gravity;
|
self.game.player.vspeed += self.game.gravity;
|
||||||
let (x, y, _w, _h) = self.game.player.col_en.en.xywh();
|
let (x, y, _w, _h) = self.game.player.col_en.en.xywh();
|
||||||
self.game.camera_offset.x = (x - NATIVE_RESOLUTION.w as i32 / 2) as u32;
|
self.game.camera_offset.x =
|
||||||
self.game.camera_offset.y = (y - NATIVE_RESOLUTION.h as i32 / 2) as u32;
|
(x - NATIVE_RESOLUTION.w as i32 / 2).try_into().unwrap_or(0);
|
||||||
|
self.game.camera_offset.y =
|
||||||
|
(y - NATIVE_RESOLUTION.h as i32 / 2).try_into().unwrap_or(0);
|
||||||
}
|
}
|
||||||
let loc = self.input.mouse_down_loc;
|
let loc = self.input.mouse_down_loc;
|
||||||
let mut wpos = self.game.camera_offset;
|
let mut wpos = self.game.camera_offset;
|
||||||
|
|
@ -151,6 +153,11 @@ impl App {
|
||||||
wpos.y = wpos.y.saturating_add_signed(loc.y.into());
|
wpos.y = wpos.y.saturating_add_signed(loc.y.into());
|
||||||
let mouse_tpos = wpos.tile_pos();
|
let mouse_tpos = wpos.tile_pos();
|
||||||
imm!("Mouse @ tile {}, {}", mouse_tpos.x, mouse_tpos.y);
|
imm!("Mouse @ tile {}, {}", mouse_tpos.x, mouse_tpos.y);
|
||||||
|
imm!(
|
||||||
|
"@ chunk {}, {}",
|
||||||
|
mouse_tpos.x / CHUNK_EXTENT as TilePosScalar,
|
||||||
|
mouse_tpos.y / CHUNK_EXTENT as TilePosScalar
|
||||||
|
);
|
||||||
if self.debug.freecam && self.input.pressed(Key::P) {
|
if self.debug.freecam && self.input.pressed(Key::P) {
|
||||||
self.game.player.col_en.en.pos.x = wpos.x as i32;
|
self.game.player.col_en.en.pos.x = wpos.x as i32;
|
||||||
self.game.player.col_en.en.pos.y = wpos.y as i32;
|
self.game.player.col_en.en.pos.y = wpos.y as i32;
|
||||||
|
|
@ -167,7 +174,7 @@ impl App {
|
||||||
t.bg = self.game.tile_to_place;
|
t.bg = self.game.tile_to_place;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if self.game.camera_offset.y > 163800 {
|
if self.game.camera_offset.y > 134217712 {
|
||||||
self.game.current_biome = Biome::Underground;
|
self.game.current_biome = Biome::Underground;
|
||||||
} else {
|
} else {
|
||||||
self.game.current_biome = Biome::Surface;
|
self.game.current_biome = Biome::Surface;
|
||||||
|
|
@ -301,7 +308,11 @@ impl fmt::Display for LengthDisp {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
let meters = self.0 * M_PER_PX;
|
let meters = self.0 * M_PER_PX;
|
||||||
if meters.abs() > 1000. {
|
if meters.abs() > 1000. {
|
||||||
let km = (meters / 1000.).floor();
|
let km = if meters.is_sign_negative() {
|
||||||
|
(meters / 1000.).ceil()
|
||||||
|
} else {
|
||||||
|
(meters / 1000.).floor()
|
||||||
|
};
|
||||||
let m = meters % 1000.;
|
let m = meters % 1000.;
|
||||||
write!(f, "{km} km, {m} m")
|
write!(f, "{km} km, {m} m")
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
11
src/math.rs
11
src/math.rs
|
|
@ -25,6 +25,9 @@ pub fn px_per_frame_to_km_h(px_per_frame: f32) -> f32 {
|
||||||
px_per_frame_to_m_per_s(px_per_frame) * 3.6
|
px_per_frame_to_m_per_s(px_per_frame) * 3.6
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// World extent in tiles. Roughly 50km*50km.
|
||||||
|
pub const WORLD_EXTENT: TilePosScalar = 100_000;
|
||||||
|
|
||||||
impl WorldPos {
|
impl WorldPos {
|
||||||
pub fn tile_pos(&self) -> TilePos {
|
pub fn tile_pos(&self) -> TilePos {
|
||||||
TilePos {
|
TilePos {
|
||||||
|
|
@ -33,10 +36,10 @@ impl WorldPos {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Horizontal center of the world
|
/// Horizontal center of the world
|
||||||
pub const CENTER: WorldPosScalar =
|
pub const CENTER: WorldPosScalar = (WORLD_EXTENT / 2) * TILE_SIZE as WorldPosScalar;
|
||||||
(TilePosScalar::MAX / 2) as WorldPosScalar * TILE_SIZE as WorldPosScalar;
|
/// Vertical surface level.
|
||||||
/// Vertical surface level. You can build 5,000 blocks upwards
|
/// You can build 10 km high.
|
||||||
pub const SURFACE: WorldPosScalar = 5000 * TILE_SIZE as WorldPosScalar;
|
pub const SURFACE: WorldPosScalar = 20_000 * TILE_SIZE as WorldPosScalar;
|
||||||
pub const SURFACE_CENTER: Self = Self {
|
pub const SURFACE_CENTER: Self = Self {
|
||||||
x: Self::CENTER,
|
x: Self::CENTER,
|
||||||
y: Self::SURFACE,
|
y: Self::SURFACE,
|
||||||
|
|
|
||||||
12
src/world.rs
12
src/world.rs
|
|
@ -1,7 +1,7 @@
|
||||||
use fnv::FnvHashMap;
|
use fnv::FnvHashMap;
|
||||||
use rand::{thread_rng, Rng};
|
use rand::{thread_rng, Rng};
|
||||||
|
|
||||||
type ChunkPosScalar = u16;
|
pub type ChunkPosScalar = u16;
|
||||||
|
|
||||||
#[derive(Hash, PartialEq, Eq, Debug, Clone, Copy)]
|
#[derive(Hash, PartialEq, Eq, Debug, Clone, Copy)]
|
||||||
pub struct ChunkPos {
|
pub struct ChunkPos {
|
||||||
|
|
@ -88,9 +88,9 @@ fn test_to_chunk_and_local() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Need to support at least 4 million tiles long
|
// Need to support at least 4 million tiles long
|
||||||
pub type TilePosScalar = u16;
|
pub type TilePosScalar = u32;
|
||||||
|
|
||||||
const CHUNK_EXTENT: u16 = 128;
|
pub const CHUNK_EXTENT: u16 = 128;
|
||||||
const CHUNK_N_TILES: usize = CHUNK_EXTENT as usize * CHUNK_EXTENT as usize;
|
const CHUNK_N_TILES: usize = CHUNK_EXTENT as usize * CHUNK_EXTENT as usize;
|
||||||
|
|
||||||
type ChunkTiles = [Tile; CHUNK_N_TILES];
|
type ChunkTiles = [Tile; CHUNK_N_TILES];
|
||||||
|
|
@ -107,7 +107,7 @@ impl Chunk {
|
||||||
mid: 0,
|
mid: 0,
|
||||||
fg: 0,
|
fg: 0,
|
||||||
}; CHUNK_N_TILES];
|
}; CHUNK_N_TILES];
|
||||||
if pos.y == 39 {
|
if pos.y == 157 {
|
||||||
for (i, b) in tiles.iter_mut().enumerate() {
|
for (i, b) in tiles.iter_mut().enumerate() {
|
||||||
if i / CHUNK_EXTENT as usize == 0 {
|
if i / CHUNK_EXTENT as usize == 0 {
|
||||||
b.fg = 8;
|
b.fg = 8;
|
||||||
|
|
@ -116,7 +116,7 @@ impl Chunk {
|
||||||
b.bg = 9;
|
b.bg = 9;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if pos.y > 39 {
|
if pos.y > 157 {
|
||||||
for b in &mut tiles {
|
for b in &mut tiles {
|
||||||
b.bg = 7;
|
b.bg = 7;
|
||||||
b.mid = 1;
|
b.mid = 1;
|
||||||
|
|
@ -126,7 +126,7 @@ impl Chunk {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Unbreakable layer at bottom
|
// Unbreakable layer at bottom
|
||||||
if pos.y > 510 {
|
if pos.y > 780 {
|
||||||
for b in &mut tiles {
|
for b in &mut tiles {
|
||||||
b.mid = Tile::UNBREAKANIUM;
|
b.mid = Tile::UNBREAKANIUM;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue