more physics systems stuff
This commit is contained in:
BIN
assets/greembyguy.png
Normal file
BIN
assets/greembyguy.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 790 B |
@@ -1416,6 +1416,7 @@
|
||||
{ "px": [193,255], "src": [80,32], "f": 0, "t": 29, "d": [42,380], "a": 1 },
|
||||
{ "px": [175,272], "src": [80,0], "f": 0, "t": 5, "d": [42,402], "a": 1 },
|
||||
{ "px": [112,96], "src": [160,16], "f": 0, "t": 22, "d": [66,145], "a": 1 },
|
||||
{ "px": [112,112], "src": [160,16], "f": 0, "t": 22, "d": [66,168], "a": 1 },
|
||||
{ "px": [0,224], "src": [160,16], "f": 0, "t": 22, "d": [66,322], "a": 1 },
|
||||
{ "px": [16,224], "src": [160,16], "f": 0, "t": 22, "d": [66,323], "a": 1 },
|
||||
{ "px": [32,224], "src": [160,16], "f": 0, "t": 22, "d": [66,324], "a": 1 },
|
||||
@@ -1428,16 +1429,18 @@
|
||||
{ "px": [16,256], "src": [160,16], "f": 0, "t": 22, "d": [66,369], "a": 1 },
|
||||
{ "px": [32,256], "src": [160,16], "f": 0, "t": 22, "d": [66,370], "a": 1 },
|
||||
{ "px": [96,96], "src": [144,16], "f": 0, "t": 21, "d": [69,144], "a": 1 },
|
||||
{ "px": [96,112], "src": [144,16], "f": 0, "t": 21, "d": [69,167], "a": 1 },
|
||||
{ "px": [112,80], "src": [160,0], "f": 0, "t": 10, "d": [68,122], "a": 1 },
|
||||
{ "px": [0,208], "src": [160,0], "f": 0, "t": 10, "d": [68,299], "a": 1 },
|
||||
{ "px": [16,208], "src": [160,0], "f": 0, "t": 10, "d": [68,300], "a": 1 },
|
||||
{ "px": [32,208], "src": [160,0], "f": 0, "t": 10, "d": [68,301], "a": 1 },
|
||||
{ "px": [48,208], "src": [160,0], "f": 0, "t": 10, "d": [68,302], "a": 1 },
|
||||
{ "px": [112,112], "src": [160,32], "f": 0, "t": 34, "d": [65,168], "a": 1 },
|
||||
{ "px": [112,128], "src": [160,32], "f": 0, "t": 34, "d": [65,191], "a": 1 },
|
||||
{ "px": [0,272], "src": [160,32], "f": 0, "t": 34, "d": [65,391], "a": 1 },
|
||||
{ "px": [16,272], "src": [160,32], "f": 0, "t": 34, "d": [65,392], "a": 1 },
|
||||
{ "px": [32,272], "src": [160,32], "f": 0, "t": 34, "d": [65,393], "a": 1 },
|
||||
{ "px": [128,96], "src": [176,16], "f": 0, "t": 23, "d": [70,146], "a": 1 },
|
||||
{ "px": [128,112], "src": [176,16], "f": 0, "t": 23, "d": [70,169], "a": 1 },
|
||||
{ "px": [64,224], "src": [176,16], "f": 0, "t": 23, "d": [70,326], "a": 1 },
|
||||
{ "px": [64,240], "src": [176,16], "f": 0, "t": 23, "d": [70,349], "a": 1 },
|
||||
{ "px": [48,256], "src": [176,16], "f": 0, "t": 23, "d": [70,371], "a": 1 },
|
||||
@@ -1489,7 +1492,7 @@
|
||||
1,1,1,1,1,1,3,1,1,1,1,4,4,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3,1,1,1,1,4,
|
||||
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3,1,1,1,1,4,1,1,1,1,1,2,2,2,1,1,1,1,
|
||||
1,1,1,1,1,3,1,1,1,1,4,1,1,1,1,2,2,2,2,2,2,1,1,1,1,1,1,1,3,1,1,1,1,1,1,
|
||||
1,1,1,2,2,5,2,2,2,1,1,3,3,3,3,3,3,1,1,1,1,1,1,2,2,1,1,2,2,2,1,1,1,1,3,
|
||||
1,1,1,2,2,5,2,2,2,1,1,3,3,3,3,3,3,1,1,1,1,1,1,2,2,1,1,2,5,2,1,1,1,1,3,
|
||||
1,1,1,1,1,1,1,1,1,1,2,2,2,2,1,2,2,2,1,1,1,1,3,1,1,1,1,1,1,1,1,1,1,1,1,
|
||||
1,2,2,2,2,2,1,1,1,1,3,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,1,1,2,2,2,2,1,3,1,
|
||||
1,1,1,1,1,1,1,1,1,1,1,1,2,1,1,1,1,1,1,1,1,3,1,1,1,1,1,1,1,1,1,1,1,1,2,
|
||||
@@ -1501,7 +1504,6 @@
|
||||
],
|
||||
"autoLayerTiles": [
|
||||
{ "px": [112,80], "src": [16,32], "f": 0, "t": 25, "d": [37,122], "a": 1 },
|
||||
{ "px": [112,112], "src": [16,32], "f": 0, "t": 25, "d": [37,168], "a": 1 },
|
||||
{ "px": [112,128], "src": [16,32], "f": 0, "t": 25, "d": [37,191], "a": 1 },
|
||||
{ "px": [96,96], "src": [96,48], "f": 0, "t": 42, "d": [36,144], "a": 1 },
|
||||
{ "px": [128,96], "src": [80,48], "f": 0, "t": 41, "d": [35,146], "a": 1 },
|
||||
@@ -1560,6 +1562,7 @@
|
||||
{ "px": [16,128], "src": [0,16], "f": 0, "t": 12, "d": [25,185], "a": 1 },
|
||||
{ "px": [48,192], "src": [0,16], "f": 0, "t": 12, "d": [25,279], "a": 1 },
|
||||
{ "px": [112,96], "src": [16,32], "f": 0, "t": 25, "d": [67,145], "a": 1 },
|
||||
{ "px": [112,112], "src": [16,32], "f": 0, "t": 25, "d": [67,168], "a": 1 },
|
||||
{ "px": [0,224], "src": [16,32], "f": 0, "t": 25, "d": [67,322], "a": 1 },
|
||||
{ "px": [16,224], "src": [16,32], "f": 0, "t": 25, "d": [67,323], "a": 1 },
|
||||
{ "px": [32,224], "src": [16,32], "f": 0, "t": 25, "d": [67,324], "a": 1 },
|
||||
|
||||
18
src/main.rs
18
src/main.rs
@@ -4,9 +4,12 @@ mod player;
|
||||
|
||||
use bevy::{image::Image, math::I64Vec2, prelude::*};
|
||||
|
||||
use crate::{physics::PhysicsBody2D, player::Player};
|
||||
use crate::{
|
||||
physics::{Physics2DPlugin, PhysicsBody2D},
|
||||
player::Player,
|
||||
};
|
||||
|
||||
const UNITS_TO_PX_SCALE: i64 = 256;
|
||||
const UNITS_TO_PX_SCALE: i64 = 1000;
|
||||
|
||||
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, States)]
|
||||
enum AppState {
|
||||
@@ -37,6 +40,7 @@ fn main() {
|
||||
let mut app = App::new();
|
||||
|
||||
app.add_plugins(DefaultPlugins.set(ImagePlugin::default_nearest()))
|
||||
.add_plugins(Physics2DPlugin::default())
|
||||
.init_state::<AppState>()
|
||||
.insert_resource(LevelData { ldtk_proj })
|
||||
.insert_resource(TilemapStuff::default())
|
||||
@@ -114,8 +118,8 @@ fn levelload(
|
||||
let parsnip = assets.load("parsnip.png");
|
||||
// create map from lvl data
|
||||
|
||||
let flowerguy = assets.load("flowerfriend.png");
|
||||
let fl_ta_layout = TextureAtlasLayout::from_grid(uvec2(16, 16), 5, 1, None, None);
|
||||
let flowerguy = assets.load("greembyguy.png");
|
||||
let fl_ta_layout = TextureAtlasLayout::from_grid(uvec2(16, 16), 8, 1, None, None);
|
||||
let fl_ta_handle = ta_layouts.add(fl_ta_layout);
|
||||
|
||||
let lvl = &lvl.ldtk_proj.levels[0];
|
||||
@@ -218,8 +222,6 @@ fn gameloop(
|
||||
play_phys.add_vel(dir * UNITS_TO_PX_SCALE);
|
||||
}
|
||||
|
||||
play_phys.tick();
|
||||
|
||||
*player_sing.1 = Transform::from_xyz(
|
||||
(play_phys.pos.x / UNITS_TO_PX_SCALE) as f32,
|
||||
(play_phys.pos.y / UNITS_TO_PX_SCALE) as f32,
|
||||
@@ -228,11 +230,11 @@ fn gameloop(
|
||||
|
||||
let plyr = player_sing.2.as_mut();
|
||||
|
||||
if time.elapsed_secs_f64() - plyr.last_frame > 0.1 {
|
||||
if time.elapsed_secs_f64() - plyr.last_frame > 0.01 {
|
||||
plyr.last_frame = time.elapsed_secs_f64();
|
||||
|
||||
if dir.length_squared() > 0 {
|
||||
plyr.anim_index = (plyr.anim_index + 1) % 5;
|
||||
plyr.anim_index = (plyr.anim_index + 1) % 8;
|
||||
} else {
|
||||
plyr.anim_index = 0;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,28 @@
|
||||
use bevy::{ecs::component::Component, math::I64Vec2};
|
||||
/// This module is intended to be used as a fixed-point physics system.
|
||||
/// The hope is that this will make deterministic physics easier,
|
||||
/// and therefore networking a bit less of a pain.
|
||||
use bevy::{
|
||||
app::{Plugin, Update},
|
||||
ecs::{component::Component, system::Query},
|
||||
math::I64Vec2,
|
||||
};
|
||||
|
||||
const MAX_SPEED: i64 = 256;
|
||||
const MAX_SPEED: i64 = 400;
|
||||
|
||||
#[derive(Default, Debug)]
|
||||
pub struct Physics2DPlugin {}
|
||||
|
||||
impl Plugin for Physics2DPlugin {
|
||||
fn build(&self, app: &mut bevy::app::App) {
|
||||
app.add_systems(Update, tick_physics);
|
||||
}
|
||||
}
|
||||
|
||||
fn tick_physics(mut query: Query<&mut PhysicsBody2D>) {
|
||||
query.iter_mut().for_each(|mut pb| {
|
||||
pb.tick();
|
||||
});
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Component)]
|
||||
pub struct PhysicsBody2D {
|
||||
|
||||
Reference in New Issue
Block a user