grass_world

This commit is contained in:
jusax23 2023-04-20 13:09:31 +02:00
parent cae43e4578
commit c2c9a2e507
Signed by: jusax23
GPG key ID: 499E2AA870C1CD41
11 changed files with 19 additions and 23 deletions

BIN
assets/arrow.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 735 B

View file

@ -1,9 +1,7 @@
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};

View file

@ -1,7 +1,5 @@
use std::collections::HashMap;
use png::chunk;
use crate::{graphics::Draw, systems::WorldGenerator};
use super::{block::Block, chunk::Chunk, BlockType, Sides, WPos};
@ -30,7 +28,7 @@ impl World {
updates: vec![],
i_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| {}),
}
}

View file

@ -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| {
for x in chunk_x * 16..chunk_x * 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, 63, z], 4, Sides::all(false), false, false);
}
}
}));

View file

@ -80,7 +80,7 @@ impl BlockType for DefaultSolidBlock {
fn collision(&self, _world: &World, _block: WPos) -> Vec<(Vec3, Vec3)> {
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.])]
}
}

View file

@ -2,7 +2,7 @@ use miniquad::*;
use stage::Stage;
mod game;
mod shader;
mod render_helper;
mod stage;
mod graphics;
mod tools;

View file

@ -1,6 +1,6 @@
use std::f64::consts::PI;
use gl_matrix::{common::*, *};
use gl_matrix::*;
use miniquad::*;
pub mod post;

View file

@ -2,7 +2,7 @@
use gl_matrix::{mat4, common::*};
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;
@ -103,7 +103,6 @@ impl Stage {
0, 1, 2, // back
3, 2, 1,
];
let index_buffer = Buffer::immutable(ctx, BufferType::IndexBuffer, &indices);
@ -126,7 +125,7 @@ impl Stage {
&[BufferLayout::default(), BufferLayout {
step_func: VertexStep::PerInstance,
..Default::default()
},],
}],
&[
VertexAttribute::with_buffer("pos", VertexFormat::Float3,0),
VertexAttribute::with_buffer("uv", VertexFormat::Float2,0),

View file

@ -1,6 +1,6 @@
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 render(&self, _world: &mut World, _block: WPos) -> Draw { Draw::None() }
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;
}

View file

@ -80,12 +80,12 @@ pub fn block_collision(
direction: Vec3,
size2: Vec3,
) -> Option<(f32, Side)> {
let mut d_x = (pos2[0] - pos1[0]) / direction[0];
let mut d_y = (pos2[1] - pos1[1]) / direction[1];
let mut d_z = (pos2[2] - pos1[2]) / direction[2];
let mut 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 mut d_b_z = (pos2[2] + size2[2] - pos1[2]) / direction[2];
let d_x = (pos2[0] - pos1[0]) / direction[0];
let d_y = (pos2[1] - pos1[1]) / direction[1];
let d_z = (pos2[2] - pos1[2]) / direction[2];
let d_b_x = (pos2[0] + size2[0] - pos1[0]) / direction[0];
let d_b_y = (pos2[1] + size2[1] - pos1[1]) / direction[1];
let d_b_z = (pos2[2] + size2[2] - pos1[2]) / direction[2];
let mut out: Option<(f32, Side)> = None;
let mut dist = INFINITY;