Skip to content

Commit

Permalink
Port the Old Jumpy Physics
Browse files Browse the repository at this point in the history
  • Loading branch information
zicklag committed Oct 9, 2022
1 parent 54b9651 commit cab3c46
Show file tree
Hide file tree
Showing 11 changed files with 637 additions and 673 deletions.
314 changes: 0 additions & 314 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ bevy-parallax = "0.2.0"
bevy_egui = "0.16.1"
egui_extras = "0.19.0"
bevy_kira_audio = { version = "0.12.0", features = ["mp3"] }
bevy_rapier2d = { version = "0.17.0", features = ["debug-render"] }
iyes_loopless = "0.7.0"
serde = { version = "1.0.137", features = ["derive"] }
serde_yaml = "0.9.2"
Expand All @@ -54,7 +53,6 @@ bevy_prototype_lyon = "0.6.0"

# Debug tools
bevy-inspector-egui = { version = "0.13.0" }
bevy-inspector-egui-rapier = { version = "0.6.0", features = ["rapier2d"] }
base64 = "0.13.0"

[target.'cfg(target_arch = "wasm32")'.dependencies]
Expand Down
3 changes: 1 addition & 2 deletions assets/default.game.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
camera_height: 448
clear_color: 27233B
physics:
gravity: 2.5
terminal_velocity: 10000.0
terminal_velocity: 10
friction_lerp: 0.96
stop_threshold: 1.0

Expand Down
16 changes: 6 additions & 10 deletions assets/maps/elements/environment/crab/crab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ export default {
y: 12,
},
velocity: {
x: 0.0,
y: 600.0,
x: 5,
y: 10,
},
gravity: 900.0,
bouncyness: 0.8,
gravity: 1,
bouncyness: 0.5,
has_friction: true,
has_mass: true,
})
Expand All @@ -98,14 +98,10 @@ export default {

update() {
const state = ScriptInfo.state(initState);
const query = world.query(KinematicBody);
const query = world.query(KinematicBody, Transform);

for (const crab of state.crabs) {
const [kinematicBody] = query.get(crab);

kinematicBody.velocity.x += 1;
kinematicBody.velocity.y -= 1;
kinematicBody.is_on_ground = false;
const [kinematicBody, transform] = query.get(crab);
}
},
};
21 changes: 13 additions & 8 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ use bevy_ecs_tilemap::prelude::*;
use bevy_mod_js_scripting::{ActiveScripts, JsScript};
use bevy_parallax::ParallaxResource;
use bevy_prototype_lyon::{prelude::*, shapes::Rectangle};
use bevy_rapier2d::prelude::{Collider, RigidBody};

use crate::{
camera::GameRenderLayers,
metadata::{MapElementMeta, MapLayerKind, MapLayerMeta, MapMeta},
physics::collisions::{CollisionLayerTag, TileCollision},
prelude::*,
};

Expand Down Expand Up @@ -142,8 +142,6 @@ pub fn spawn_map(params: &mut SpawnMapParams, source: &MapSpawnSource) {
texture: TileTexture(tile.idx),
..default()
})
.insert(RigidBody::Fixed)
.insert(Collider::cuboid(half_tile_x, half_tile_y))
.insert_bundle(TransformBundle {
local: Transform::from_xyz(
half_tile_x + map.tile_size.x as f32 * tile_pos.x as f32,
Expand All @@ -152,6 +150,8 @@ pub fn spawn_map(params: &mut SpawnMapParams, source: &MapSpawnSource) {
),
..default()
})
// TODO: Jump through tiles
.insert(TileCollision::Solid)
.id();

// TODO: Add platform tile component to tiles that are platforms
Expand All @@ -161,9 +161,9 @@ pub fn spawn_map(params: &mut SpawnMapParams, source: &MapSpawnSource) {
tile_entities.push(tile_entity);
}

let tile_layer = params
.commands
.entity(layer_entity)
let mut layer_commands = params.commands.entity(layer_entity);

layer_commands
.insert_bundle(TilemapBundle {
grid_size: TilemapGridSize {
x: map.grid_size.x as f32,
Expand All @@ -178,8 +178,13 @@ pub fn spawn_map(params: &mut SpawnMapParams, source: &MapSpawnSource) {
transform: Transform::from_xyz(0.0, 0.0, -100.0 + i as f32),
..default()
})
.push_children(&tile_entities)
.id();
.push_children(&tile_entities);

if tile_layer.has_collision {
layer_commands.insert(CollisionLayerTag::default());
}

let tile_layer = layer_commands.id();

map_children.push(tile_layer);
}
Expand Down
1 change: 0 additions & 1 deletion src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ pub struct GameMeta {
#[derive(HasLoadProgress, Deserialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
pub struct PhysicsMeta {
pub gravity: f32,
pub terminal_velocity: f32,
pub friction_lerp: f32,
pub stop_threshold: f32,
Expand Down
Loading

0 comments on commit cab3c46

Please sign in to comment.