Forests
This commit is contained in:
147
assets/test.ldtk
147
assets/test.ldtk
@@ -11,7 +11,7 @@
|
||||
"iid": "57508490-fa90-11f0-8c51-0f60a8049179",
|
||||
"jsonVersion": "1.5.3",
|
||||
"appBuildId": 473703,
|
||||
"nextUid": 74,
|
||||
"nextUid": 78,
|
||||
"identifierStyle": "Capitalize",
|
||||
"toc": [],
|
||||
"worldLayout": "Free",
|
||||
@@ -113,6 +113,70 @@
|
||||
"active": true,
|
||||
"isOptional": false,
|
||||
"rules": [
|
||||
{
|
||||
"uid": 74,
|
||||
"active": true,
|
||||
"size": 3,
|
||||
"tileRectsIds": [[32]],
|
||||
"alpha": 1,
|
||||
"chance": 1,
|
||||
"breakOnMatch": true,
|
||||
"pattern": [4,4,0,4,-4,0,0,0,0],
|
||||
"flipX": false,
|
||||
"flipY": false,
|
||||
"xModulo": 1,
|
||||
"yModulo": 1,
|
||||
"xOffset": 0,
|
||||
"yOffset": 0,
|
||||
"tileXOffset": 0,
|
||||
"tileYOffset": 0,
|
||||
"tileRandomXMin": 0,
|
||||
"tileRandomXMax": 0,
|
||||
"tileRandomYMin": 0,
|
||||
"tileRandomYMax": 0,
|
||||
"checker": "None",
|
||||
"tileMode": "Single",
|
||||
"pivotX": 0,
|
||||
"pivotY": 0,
|
||||
"outOfBoundsValue": null,
|
||||
"invalidated": false,
|
||||
"perlinActive": false,
|
||||
"perlinSeed": 4982073,
|
||||
"perlinScale": 0.2,
|
||||
"perlinOctaves": 2
|
||||
},
|
||||
{
|
||||
"uid": 75,
|
||||
"active": true,
|
||||
"size": 3,
|
||||
"tileRectsIds": [[30]],
|
||||
"alpha": 1,
|
||||
"chance": 1,
|
||||
"breakOnMatch": true,
|
||||
"pattern": [0,4,4,0,-4,4,0,0,0],
|
||||
"flipX": false,
|
||||
"flipY": false,
|
||||
"xModulo": 1,
|
||||
"yModulo": 1,
|
||||
"xOffset": 0,
|
||||
"yOffset": 0,
|
||||
"tileXOffset": 0,
|
||||
"tileYOffset": 0,
|
||||
"tileRandomXMin": 0,
|
||||
"tileRandomXMax": 0,
|
||||
"tileRandomYMin": 0,
|
||||
"tileRandomYMax": 0,
|
||||
"checker": "None",
|
||||
"tileMode": "Single",
|
||||
"pivotX": 0,
|
||||
"pivotY": 0,
|
||||
"outOfBoundsValue": null,
|
||||
"invalidated": false,
|
||||
"perlinActive": false,
|
||||
"perlinSeed": 4982073,
|
||||
"perlinScale": 0.2,
|
||||
"perlinOctaves": 2
|
||||
},
|
||||
{
|
||||
"uid": 62,
|
||||
"active": true,
|
||||
@@ -177,6 +241,70 @@
|
||||
"perlinScale": 0.2,
|
||||
"perlinOctaves": 2
|
||||
},
|
||||
{
|
||||
"uid": 76,
|
||||
"active": true,
|
||||
"size": 3,
|
||||
"tileRectsIds": [[18]],
|
||||
"alpha": 1,
|
||||
"chance": 1,
|
||||
"breakOnMatch": true,
|
||||
"pattern": [0,0,0,0,-4,4,0,0,0],
|
||||
"flipX": false,
|
||||
"flipY": false,
|
||||
"xModulo": 1,
|
||||
"yModulo": 1,
|
||||
"xOffset": 0,
|
||||
"yOffset": 0,
|
||||
"tileXOffset": 0,
|
||||
"tileYOffset": 0,
|
||||
"tileRandomXMin": 0,
|
||||
"tileRandomXMax": 0,
|
||||
"tileRandomYMin": 0,
|
||||
"tileRandomYMax": 0,
|
||||
"checker": "None",
|
||||
"tileMode": "Single",
|
||||
"pivotX": 0,
|
||||
"pivotY": 0,
|
||||
"outOfBoundsValue": null,
|
||||
"invalidated": false,
|
||||
"perlinActive": false,
|
||||
"perlinSeed": 7205227,
|
||||
"perlinScale": 0.2,
|
||||
"perlinOctaves": 2
|
||||
},
|
||||
{
|
||||
"uid": 77,
|
||||
"active": true,
|
||||
"size": 3,
|
||||
"tileRectsIds": [[7]],
|
||||
"alpha": 1,
|
||||
"chance": 1,
|
||||
"breakOnMatch": true,
|
||||
"pattern": [0,0,0,0,-4,0,0,4,0],
|
||||
"flipX": false,
|
||||
"flipY": false,
|
||||
"xModulo": 1,
|
||||
"yModulo": 1,
|
||||
"xOffset": 0,
|
||||
"yOffset": 0,
|
||||
"tileXOffset": 0,
|
||||
"tileYOffset": 0,
|
||||
"tileRandomXMin": 0,
|
||||
"tileRandomXMax": 0,
|
||||
"tileRandomYMin": 0,
|
||||
"tileRandomYMax": 0,
|
||||
"checker": "None",
|
||||
"tileMode": "Single",
|
||||
"pivotX": 0,
|
||||
"pivotY": 0,
|
||||
"outOfBoundsValue": null,
|
||||
"invalidated": false,
|
||||
"perlinActive": false,
|
||||
"perlinSeed": 7205227,
|
||||
"perlinScale": 0.2,
|
||||
"perlinOctaves": 2
|
||||
},
|
||||
{
|
||||
"uid": 58,
|
||||
"active": true,
|
||||
@@ -1456,13 +1584,18 @@
|
||||
{ "px": [0,48], "src": [112,16], "f": 0, "t": 19, "d": [58,69], "a": 1 },
|
||||
{ "px": [0,64], "src": [112,16], "f": 0, "t": 19, "d": [58,92], "a": 1 },
|
||||
{ "px": [0,80], "src": [112,16], "f": 0, "t": 19, "d": [58,115], "a": 1 },
|
||||
{ "px": [240,128], "src": [112,16], "f": 0, "t": 19, "d": [58,199], "a": 1 },
|
||||
{ "px": [240,112], "src": [112,0], "f": 0, "t": 7, "d": [77,176], "a": 1 },
|
||||
{ "px": [224,128], "src": [96,16], "f": 0, "t": 18, "d": [76,198], "a": 1 },
|
||||
{ "px": [0,96], "src": [112,32], "f": 0, "t": 31, "d": [60,138], "a": 1 },
|
||||
{ "px": [240,144], "src": [112,32], "f": 0, "t": 31, "d": [60,222], "a": 1 },
|
||||
{ "px": [64,0], "src": [128,16], "f": 0, "t": 20, "d": [62,4], "a": 1 },
|
||||
{ "px": [48,16], "src": [128,16], "f": 0, "t": 20, "d": [62,26], "a": 1 },
|
||||
{ "px": [32,32], "src": [128,16], "f": 0, "t": 20, "d": [62,48], "a": 1 },
|
||||
{ "px": [16,48], "src": [128,16], "f": 0, "t": 20, "d": [62,70], "a": 1 },
|
||||
{ "px": [16,64], "src": [128,16], "f": 0, "t": 20, "d": [62,93], "a": 1 },
|
||||
{ "px": [16,80], "src": [128,16], "f": 0, "t": 20, "d": [62,116], "a": 1 }
|
||||
{ "px": [16,80], "src": [128,16], "f": 0, "t": 20, "d": [62,116], "a": 1 },
|
||||
{ "px": [256,128], "src": [128,16], "f": 0, "t": 20, "d": [62,200], "a": 1 },
|
||||
{ "px": [48,16], "src": [128,32], "f": 0, "t": 32, "d": [74,26], "a": 1 },
|
||||
{ "px": [32,32], "src": [128,32], "f": 0, "t": 32, "d": [74,48], "a": 1 },
|
||||
{ "px": [16,48], "src": [128,32], "f": 0, "t": 32, "d": [74,70], "a": 1 }
|
||||
],
|
||||
"seed": 7565984,
|
||||
"overrideTilesetUid": null,
|
||||
@@ -1493,7 +1626,7 @@
|
||||
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,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,1,1,1,1,1,1,1,1,1,2,2,2,2,1,2,2,2,1,1,1,1,3,1,4,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,
|
||||
2,2,2,2,1,1,1,1,1,3,1,1,1,1,1,1,1,1,1,2,2,2,2,2,1,1,1,1,1,3,3,3,3,1,1,
|
||||
@@ -1720,7 +1853,6 @@
|
||||
{ "px": [176,128], "src": [32,0], "f": 0, "t": 2, "d": [38,195], "a": 1 },
|
||||
{ "px": [192,128], "src": [32,0], "f": 0, "t": 2, "d": [38,196], "a": 1 },
|
||||
{ "px": [224,128], "src": [0,0], "f": 0, "t": 0, "d": [38,198], "a": 1 },
|
||||
{ "px": [240,128], "src": [32,0], "f": 0, "t": 2, "d": [38,199], "a": 1 },
|
||||
{ "px": [256,128], "src": [16,0], "f": 0, "t": 1, "d": [38,200], "a": 1 },
|
||||
{ "px": [272,128], "src": [16,0], "f": 0, "t": 1, "d": [38,201], "a": 1 },
|
||||
{ "px": [288,128], "src": [16,0], "f": 0, "t": 1, "d": [38,202], "a": 1 },
|
||||
@@ -1918,6 +2050,7 @@
|
||||
{ "px": [0,48], "src": [0,0], "f": 0, "t": 0, "d": [56,69], "a": 1 },
|
||||
{ "px": [0,64], "src": [0,0], "f": 0, "t": 0, "d": [56,92], "a": 1 },
|
||||
{ "px": [0,80], "src": [16,0], "f": 0, "t": 1, "d": [56,115], "a": 1 },
|
||||
{ "px": [240,128], "src": [16,0], "f": 0, "t": 1, "d": [56,199], "a": 1 },
|
||||
{ "px": [288,0], "src": [112,48], "f": 0, "t": 43, "d": [73,18], "a": 1 },
|
||||
{ "px": [288,16], "src": [112,48], "f": 0, "t": 43, "d": [73,41], "a": 1 },
|
||||
{ "px": [288,32], "src": [112,48], "f": 0, "t": 43, "d": [73,64], "a": 1 },
|
||||
|
||||
46
src/main.rs
46
src/main.rs
@@ -127,7 +127,12 @@ fn levelload(
|
||||
let mut lyr_dep = 50f32;
|
||||
lvl.layer_instances.iter().for_each(|li| {
|
||||
li.al_tiles.iter().for_each(|t| {
|
||||
commands.spawn((
|
||||
let pos = I64Vec2 {
|
||||
x: t.px_coords.x as i64,
|
||||
y: 256 - t.px_coords.y as i64,
|
||||
};
|
||||
let mut tile = commands.spawn((
|
||||
Transform::from_xyz(pos.x as f32, pos.y as f32, lyr_dep),
|
||||
Sprite::from_atlas_image(
|
||||
tmap_sprite.clone(),
|
||||
TextureAtlas {
|
||||
@@ -135,10 +140,33 @@ fn levelload(
|
||||
index: t.ty as usize,
|
||||
},
|
||||
),
|
||||
Transform::from_xyz(t.px_coords.x as f32, 256. - t.px_coords.y as f32, lyr_dep),
|
||||
));
|
||||
});
|
||||
lyr_dep -= 0.1;
|
||||
|
||||
match t.ty {
|
||||
19 | 22 => {
|
||||
info!("Trees!");
|
||||
tile.insert((
|
||||
Name::from("Trees"),
|
||||
Transform::from_xyz(pos.x as f32, pos.y as f32, 200.),
|
||||
PhysicsBody2D {
|
||||
pos: pos * UNITS_TO_PX_SCALE,
|
||||
immovable: true,
|
||||
..default()
|
||||
},
|
||||
AABBCollider::new(
|
||||
16 * UNITS_TO_PX_SCALE as u32,
|
||||
16 * UNITS_TO_PX_SCALE as u32,
|
||||
),
|
||||
// Sprite::from_color(Color::WHITE, vec2(16., 16.)),
|
||||
));
|
||||
}
|
||||
6..=11 | 18..=23 | 30..=35 => {
|
||||
tile.insert(Transform::from_xyz(pos.x as f32, pos.y as f32, 200.));
|
||||
}
|
||||
_ => (),
|
||||
};
|
||||
lyr_dep -= 0.1;
|
||||
})
|
||||
});
|
||||
|
||||
println!("Total layer depth: {lyr_dep}");
|
||||
@@ -229,12 +257,12 @@ fn gameloop(
|
||||
} else {
|
||||
play_phys.apply_force(dir * UNITS_TO_PX_SCALE, Some(UNITS_TO_PX_SCALE * 10 / 100));
|
||||
}
|
||||
let pos = play_phys.pos.clone();
|
||||
|
||||
*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,
|
||||
100.,
|
||||
);
|
||||
let t = player_sing.1.as_mut();
|
||||
t.translation.x = (pos.x / UNITS_TO_PX_SCALE) as f32;
|
||||
t.translation.y = (pos.y / UNITS_TO_PX_SCALE) as f32;
|
||||
// *player_sing.1 = t;x
|
||||
|
||||
let plyr = player_sing.2.as_mut();
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ fn resolve_aabb_collisions(mut query: Query<(&mut PhysicsBody2D, &AABBCollider)>
|
||||
|
||||
let len = bcs.len();
|
||||
|
||||
let mut updated_bcs: Vec<(usize, PhysicsBody2D)> = Vec::new();
|
||||
let mut corrections: Vec<(usize, I64Vec2)> = Vec::new();
|
||||
|
||||
for i in 0..len {
|
||||
let (b, c) = &bcs[i];
|
||||
@@ -83,71 +83,51 @@ fn resolve_aabb_collisions(mut query: Query<(&mut PhysicsBody2D, &AABBCollider)>
|
||||
let dx = b.pos.x - other_b.pos.x;
|
||||
let dy = b.pos.y - other_b.pos.y;
|
||||
|
||||
if other_b.immovable {
|
||||
// move backwards along dx/dy until we're out
|
||||
let mut corr_vec = I64Vec2::ZERO;
|
||||
|
||||
let (new_x, new_y) = match dx.abs() > dy.abs() {
|
||||
if other_b.immovable {
|
||||
match dx.abs() > dy.abs() {
|
||||
true => {
|
||||
let dist = (c.width + other_c.width) as i64 / 2;
|
||||
let tgt_x = other_b.pos.x
|
||||
+ match dx > 0 {
|
||||
true => dist,
|
||||
false => -dist,
|
||||
};
|
||||
|
||||
match dx > 0 {
|
||||
true => (other_b.pos.x + dist, b.pos.y),
|
||||
false => (other_b.pos.x - dist, b.pos.y),
|
||||
}
|
||||
corr_vec.x = tgt_x - b.pos.x;
|
||||
}
|
||||
false => {
|
||||
let dist = (c.height + other_c.height) as i64 / 2;
|
||||
let tgt_y = other_b.pos.y
|
||||
+ match dy > 0 {
|
||||
true => dist,
|
||||
false => -dist,
|
||||
};
|
||||
|
||||
match dy > 0 {
|
||||
true => (b.pos.x, other_b.pos.y + dist),
|
||||
false => (b.pos.x, other_b.pos.y - dist),
|
||||
}
|
||||
corr_vec.y = tgt_y - b.pos.y;
|
||||
}
|
||||
};
|
||||
|
||||
// let new_x = match dx {
|
||||
// ..0 => other_b.pos.x - (c.width / 2 + other_c.width / 2) as i64,
|
||||
// 0 => b.pos.x,
|
||||
// 1.. => other_b.pos.x + (c.width / 2 + other_c.width / 2) as i64,
|
||||
// };
|
||||
// let new_y = match dy {
|
||||
// ..0 => other_b.pos.y - (c.height / 2 + other_c.height / 2) as i64,
|
||||
// 0 => b.pos.y,
|
||||
// 1.. => other_b.pos.y + (c.height / 2 + other_c.height / 2) as i64,
|
||||
// };
|
||||
|
||||
let updated_b = PhysicsBody2D {
|
||||
pos: I64Vec2 { x: new_x, y: new_y },
|
||||
vel: b.vel,
|
||||
immovable: false,
|
||||
};
|
||||
updated_bcs.push((i, updated_b));
|
||||
corrections.push((i, corr_vec));
|
||||
} else {
|
||||
let updated_b = PhysicsBody2D {
|
||||
pos: b.pos - I64Vec2::new(dx / 2, dy / 2),
|
||||
vel: b.vel,
|
||||
immovable: false,
|
||||
};
|
||||
|
||||
let other_updated_b = PhysicsBody2D {
|
||||
pos: other_b.pos + I64Vec2::new(dx / 2, dy / 2),
|
||||
vel: other_b.vel,
|
||||
immovable: false,
|
||||
};
|
||||
|
||||
updated_bcs.push((i, updated_b));
|
||||
|
||||
updated_bcs.push((i, other_updated_b));
|
||||
todo!("no dynamic handling yet..");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (i, (mut b, c)) in query.iter_mut().enumerate() {
|
||||
let Some((_, updateb)) = updated_bcs.iter().find(|(j, _)| i == *j) else {
|
||||
continue;
|
||||
};
|
||||
let mut summed_corr = I64Vec2::ZERO;
|
||||
|
||||
*b = updateb.clone();
|
||||
for (j, corr) in corrections.iter() {
|
||||
if i != *j {
|
||||
continue;
|
||||
}
|
||||
|
||||
summed_corr += corr;
|
||||
}
|
||||
|
||||
b.pos = b.pos + summed_corr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user