grass_world
This commit is contained in:
parent
cae43e4578
commit
c2c9a2e507
11 changed files with 19 additions and 23 deletions
BIN
assets/arrow.png
Normal file
BIN
assets/arrow.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 735 B |
|
@ -1,9 +1,7 @@
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use gl_matrix::{common::*, vec2::clone};
|
|
||||||
use png::chunk;
|
|
||||||
|
|
||||||
use crate::{systems::WorldGenerator, tools::Sides};
|
use crate::tools::Sides;
|
||||||
|
|
||||||
use super::{block::Block, WPos};
|
use super::{block::Block, WPos};
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use png::chunk;
|
|
||||||
|
|
||||||
use crate::{graphics::Draw, systems::WorldGenerator};
|
use crate::{graphics::Draw, systems::WorldGenerator};
|
||||||
|
|
||||||
use super::{block::Block, chunk::Chunk, BlockType, Sides, WPos};
|
use super::{block::Block, chunk::Chunk, BlockType, Sides, WPos};
|
||||||
|
@ -30,7 +28,7 @@ impl World {
|
||||||
updates: vec![],
|
updates: vec![],
|
||||||
i_updates: vec![],
|
i_updates: vec![],
|
||||||
t_updates: vec![],
|
t_updates: vec![],
|
||||||
gen: Box::new(|world: &mut World, chunk_x: i32, chunk_z: i32| {}),
|
gen: Box::new(|_world: &mut World, _chunk_x: i32, _chunk_z: i32| {}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -114,9 +114,10 @@ pub fn register(ctx: &mut Context, game: &mut Game, graphics: &mut Graphics, def
|
||||||
world.set_gen(Box::new(|world: &mut World, chunk_x: i32, chunk_z: i32| {
|
world.set_gen(Box::new(|world: &mut World, chunk_x: i32, chunk_z: i32| {
|
||||||
for x in chunk_x * 16..chunk_x * 16 + 16 {
|
for x in chunk_x * 16..chunk_x * 16 + 16 {
|
||||||
for z in chunk_z * 16..chunk_z * 16 + 16 {
|
for z in chunk_z * 16..chunk_z * 16 + 16 {
|
||||||
for y in 0..64 {
|
for y in 0..63 {
|
||||||
world.set_block_tex(&[x, y, z], 1, Sides::all(false), false, false);
|
world.set_block_tex(&[x, y, z], 1, Sides::all(false), false, false);
|
||||||
}
|
}
|
||||||
|
world.set_block_tex(&[x, 63, z], 4, Sides::all(false), false, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
|
@ -80,7 +80,7 @@ impl BlockType for DefaultSolidBlock {
|
||||||
fn collision(&self, _world: &World, _block: WPos) -> Vec<(Vec3, Vec3)> {
|
fn collision(&self, _world: &World, _block: WPos) -> Vec<(Vec3, Vec3)> {
|
||||||
vec![([0.,0.,0.], [1.,1.,1.])]
|
vec![([0.,0.,0.], [1.,1.,1.])]
|
||||||
}
|
}
|
||||||
fn interaction(&self, _world: &World, block: &Block, _block: WPos) -> Vec<(Vec3, Vec3)> {
|
fn interaction(&self, _world: &World, _block: &Block, _pos: WPos) -> Vec<(Vec3, Vec3)> {
|
||||||
vec![([0.,0.,0.], [1.,1.,1.])]
|
vec![([0.,0.,0.], [1.,1.,1.])]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ use miniquad::*;
|
||||||
use stage::Stage;
|
use stage::Stage;
|
||||||
|
|
||||||
mod game;
|
mod game;
|
||||||
mod shader;
|
mod render_helper;
|
||||||
mod stage;
|
mod stage;
|
||||||
mod graphics;
|
mod graphics;
|
||||||
mod tools;
|
mod tools;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use std::f64::consts::PI;
|
use std::f64::consts::PI;
|
||||||
|
|
||||||
use gl_matrix::{common::*, *};
|
use gl_matrix::*;
|
||||||
use miniquad::*;
|
use miniquad::*;
|
||||||
|
|
||||||
pub mod post;
|
pub mod post;
|
|
@ -2,7 +2,7 @@
|
||||||
use gl_matrix::{mat4, common::*};
|
use gl_matrix::{mat4, common::*};
|
||||||
use miniquad::*;
|
use miniquad::*;
|
||||||
|
|
||||||
use crate::{game::{Game, chunk::*, world::World}, graphics::{Graphics, DrawType}, jucraft::{*, self}, shader::RenderHelper, tools::*, player::Player};
|
use crate::{game::{Game, chunk::*, world::World}, graphics::{Graphics, DrawType}, jucraft::{*, self}, render_helper::RenderHelper, tools::*, player::Player};
|
||||||
|
|
||||||
const MAX_INSTANT_TICKS: i32 = 50;
|
const MAX_INSTANT_TICKS: i32 = 50;
|
||||||
|
|
||||||
|
@ -103,7 +103,6 @@ impl Stage {
|
||||||
|
|
||||||
0, 1, 2, // back
|
0, 1, 2, // back
|
||||||
3, 2, 1,
|
3, 2, 1,
|
||||||
|
|
||||||
];
|
];
|
||||||
let index_buffer = Buffer::immutable(ctx, BufferType::IndexBuffer, &indices);
|
let index_buffer = Buffer::immutable(ctx, BufferType::IndexBuffer, &indices);
|
||||||
|
|
||||||
|
@ -126,7 +125,7 @@ impl Stage {
|
||||||
&[BufferLayout::default(), BufferLayout {
|
&[BufferLayout::default(), BufferLayout {
|
||||||
step_func: VertexStep::PerInstance,
|
step_func: VertexStep::PerInstance,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},],
|
}],
|
||||||
&[
|
&[
|
||||||
VertexAttribute::with_buffer("pos", VertexFormat::Float3,0),
|
VertexAttribute::with_buffer("pos", VertexFormat::Float3,0),
|
||||||
VertexAttribute::with_buffer("uv", VertexFormat::Float2,0),
|
VertexAttribute::with_buffer("uv", VertexFormat::Float2,0),
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use gl_matrix::common::*;
|
use gl_matrix::common::*;
|
||||||
|
|
||||||
use crate::{game::{world::World, block::Block}, tools::WPos, graphics::{Draw, DrawType}};
|
use crate::{game::{world::World, block::Block, Game}, tools::WPos, graphics::{Draw, DrawType}};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -20,6 +20,6 @@ pub trait BlockType {
|
||||||
fn update(&self, _world: &mut World, _block: WPos, _types: &Vec<Box<dyn BlockType>>, _instant: bool) {}
|
fn update(&self, _world: &mut World, _block: WPos, _types: &Vec<Box<dyn BlockType>>, _instant: bool) {}
|
||||||
fn render(&self, _world: &mut World, _block: WPos) -> Draw { Draw::None() }
|
fn render(&self, _world: &mut World, _block: WPos) -> Draw { Draw::None() }
|
||||||
fn collision(&self, _world: &World, _block: WPos) -> Vec<(Vec3, Vec3)> { vec![] }
|
fn collision(&self, _world: &World, _block: WPos) -> Vec<(Vec3, Vec3)> { vec![] }
|
||||||
fn interaction(&self, _world: &World, block: &Block, _block: WPos) -> Vec<(Vec3, Vec3)> { vec![] }
|
fn interaction(&self, _world: &World, _block: &Block, _pos: WPos) -> Vec<(Vec3, Vec3)> { vec![] }
|
||||||
fn texture(&self) -> &DrawType;
|
fn texture(&self) -> &DrawType;
|
||||||
}
|
}
|
12
src/tools.rs
12
src/tools.rs
|
@ -80,12 +80,12 @@ pub fn block_collision(
|
||||||
direction: Vec3,
|
direction: Vec3,
|
||||||
size2: Vec3,
|
size2: Vec3,
|
||||||
) -> Option<(f32, Side)> {
|
) -> Option<(f32, Side)> {
|
||||||
let mut d_x = (pos2[0] - pos1[0]) / direction[0];
|
let d_x = (pos2[0] - pos1[0]) / direction[0];
|
||||||
let mut d_y = (pos2[1] - pos1[1]) / direction[1];
|
let d_y = (pos2[1] - pos1[1]) / direction[1];
|
||||||
let mut d_z = (pos2[2] - pos1[2]) / direction[2];
|
let d_z = (pos2[2] - pos1[2]) / direction[2];
|
||||||
let mut d_b_x = (pos2[0] + size2[0] - pos1[0]) / direction[0];
|
let d_b_x = (pos2[0] + size2[0] - pos1[0]) / direction[0];
|
||||||
let mut d_b_y = (pos2[1] + size2[1] - pos1[1]) / direction[1];
|
let d_b_y = (pos2[1] + size2[1] - pos1[1]) / direction[1];
|
||||||
let mut d_b_z = (pos2[2] + size2[2] - pos1[2]) / direction[2];
|
let d_b_z = (pos2[2] + size2[2] - pos1[2]) / direction[2];
|
||||||
|
|
||||||
let mut out: Option<(f32, Side)> = None;
|
let mut out: Option<(f32, Side)> = None;
|
||||||
let mut dist = INFINITY;
|
let mut dist = INFINITY;
|
||||||
|
|
Loading…
Reference in a new issue