Skip to content

Commit f6f61a0

Browse files
committed
Implement Crab Critters
1 parent 2d88881 commit f6f61a0

File tree

11 files changed

+376
-25
lines changed

11 files changed

+376
-25
lines changed

assets/maps/test_level.json

Lines changed: 65 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -784,14 +784,71 @@
784784
"id": "decorations",
785785
"kind": "object_layer",
786786
"has_collision": false,
787-
"objects": [],
787+
"objects": [
788+
{
789+
"id": "anemones",
790+
"kind": "decoration",
791+
"position": {
792+
"x": 313.01,
793+
"y": 269.10092
794+
}
795+
},
796+
{
797+
"id": "seaweed",
798+
"kind": "decoration",
799+
"position": {
800+
"x": 637.80585,
801+
"y": 269.37476
802+
}
803+
}
804+
],
788805
"is_visible": true
789806
},
790807
{
791808
"id": "items",
792809
"kind": "object_layer",
793810
"has_collision": false,
794811
"objects": [
812+
{
813+
"id": "crab",
814+
"kind": "environment",
815+
"position": {
816+
"x": 486.8546,
817+
"y": 178.04547
818+
}
819+
},
820+
{
821+
"id": "crab",
822+
"kind": "environment",
823+
"position": {
824+
"x": 640.52356,
825+
"y": 432.3415
826+
}
827+
},
828+
{
829+
"id": "crab",
830+
"kind": "environment",
831+
"position": {
832+
"x": 414.69,
833+
"y": 305.67166
834+
}
835+
},
836+
{
837+
"id": "crab",
838+
"kind": "environment",
839+
"position": {
840+
"x": 610.0421,
841+
"y": 302.41638
842+
}
843+
},
844+
{
845+
"id": "crab",
846+
"kind": "environment",
847+
"position": {
848+
"x": 530.3602,
849+
"y": 677.60126
850+
}
851+
},
795852
{
796853
"id": "trident",
797854
"kind": "item",
@@ -804,8 +861,8 @@
804861
"id": "crown_hat",
805862
"kind": "item",
806863
"position": {
807-
"x": 524.5,
808-
"y": 408.0
864+
"x": 519.0186,
865+
"y": 405.68817
809866
}
810867
},
811868
{
@@ -892,8 +949,8 @@
892949
"id": "jellyfish",
893950
"kind": "item",
894951
"position": {
895-
"x": 700.0,
896-
"y": 650.0
952+
"x": 696.2978,
953+
"y": 647.9329
897954
}
898955
},
899956
{
@@ -1742,13 +1799,13 @@
17421799
false
17431800
],
17441801
"tile_attributes": {
1745-
"56": [
1802+
"58": [
17461803
"jumpthrough"
17471804
],
1748-
"60": [
1805+
"56": [
17491806
"jumpthrough"
17501807
],
1751-
"58": [
1808+
"60": [
17521809
"jumpthrough"
17531810
]
17541811
}

assets/textures.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,15 @@
427427
"y": 20
428428
}
429429
},
430+
{
431+
"id": "crab",
432+
"path": "textures/items/Crab(15x8).png",
433+
"type": "spritesheet",
434+
"sprite_size": {
435+
"x": 15,
436+
"y": 8
437+
}
438+
},
430439
{
431440
"id": "sword",
432441
"path": "textures/items/Sword(65x93).png",

assets/textures/items/Crab(15x8).png

215 Bytes
Loading

src/editor/gui/windows/create_object.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ impl Window for CreateObjectWindow {
132132
.keys()
133133
.map(|k| k.as_str())
134134
.collect::<Vec<&str>>(),
135-
MapObjectKind::Environment => vec!["sproinger"],
135+
MapObjectKind::Environment => vec!["sproinger", "crab"],
136136
MapObjectKind::Decoration => resources
137137
.decoration
138138
.keys()

src/editor/mod.rs

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::any::TypeId;
22
use std::path::Path;
33

4-
use crate::{exit_to_main_menu, quit_to_desktop, Resources};
4+
use crate::{exit_to_main_menu, map::CRAB_TEXTURE_ID, quit_to_desktop, Resources};
55

66
mod camera;
77

@@ -1449,8 +1449,8 @@ impl Node for Editor {
14491449
label = Some("INVALID OBJECT ID".to_string());
14501450
}
14511451
}
1452-
MapObjectKind::Environment => {
1453-
if &object.id == "sproinger" {
1452+
MapObjectKind::Environment => match object.id.as_str() {
1453+
"sproinger" => {
14541454
let texture_res =
14551455
resources.textures.get("sproinger").unwrap();
14561456

@@ -1476,10 +1476,22 @@ impl Node for Editor {
14761476
..Default::default()
14771477
},
14781478
);
1479-
} else {
1479+
}
1480+
"crab" => {
1481+
let texture_res =
1482+
resources.textures.get(CRAB_TEXTURE_ID).unwrap();
1483+
1484+
draw_texture(
1485+
texture_res.texture,
1486+
object_position.x,
1487+
object_position.y,
1488+
color::WHITE,
1489+
);
1490+
}
1491+
_ => {
14801492
label = Some("INVALID OBJECT ID".to_string());
14811493
}
1482-
}
1494+
},
14831495
}
14841496

14851497
let size = get_object_size(object);
@@ -1603,14 +1615,17 @@ fn get_object_size(object: &MapObject) -> Vec2 {
16031615
label = Some("INVALID OBJECT ID".to_string())
16041616
}
16051617
}
1606-
MapObjectKind::Environment => {
1607-
if &object.id == "sproinger" {
1618+
MapObjectKind::Environment => match object.id.as_str() {
1619+
"sproinger" => {
16081620
let texture_res = resources.textures.get("sproinger").unwrap();
16091621
res = texture_res.meta.frame_size;
1610-
} else {
1611-
label = Some("INVALID OBJECT ID".to_string())
16121622
}
1613-
}
1623+
"crab" => {
1624+
let texture_res = resources.textures.get(CRAB_TEXTURE_ID).unwrap();
1625+
res = texture_res.meta.frame_size;
1626+
}
1627+
_ => label = Some("INVALID OBJECT ID".to_string()),
1628+
},
16141629
}
16151630

16161631
if let Some(label) = &label {

src/game/mod.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ use crate::effects::active::debug_draw_active_effects;
3434
use crate::effects::active::projectiles::fixed_update_projectiles;
3535
use crate::effects::active::triggered::fixed_update_triggered_effects;
3636
use crate::items::spawn_item;
37-
use crate::map::{fixed_update_sproingers, spawn_decoration, spawn_sproinger};
37+
use crate::map::{
38+
fixed_update_sproingers, spawn_crab, spawn_decoration, spawn_sproinger, update_crabs,
39+
};
3840
use crate::network::{
3941
fixed_update_network_client, fixed_update_network_host, update_network_client,
4042
update_network_host,
@@ -118,7 +120,8 @@ impl Game {
118120
.add_system(update_player_states)
119121
.add_system(update_player_inventory)
120122
.add_system(update_player_passive_effects)
121-
.add_system(update_player_events);
123+
.add_system(update_player_events)
124+
.add_system(update_crabs);
122125

123126
fixed_updates_builder
124127
.add_system(fixed_update_physics_bodies)
@@ -258,15 +261,20 @@ pub fn spawn_map_objects(world: &mut World, map: &Map) -> Result<Vec<Entity>> {
258261
println!("WARNING: Invalid item id '{}'", &map_object.id)
259262
}
260263
}
261-
MapObjectKind::Environment => {
262-
if map_object.id == "sproinger" {
264+
MapObjectKind::Environment => match map_object.id.as_str() {
265+
"sproinger" => {
263266
let sproinger = spawn_sproinger(world, map_object.position)?;
264267
objects.push(sproinger);
265-
} else {
268+
}
269+
"crab" => {
270+
let crab = spawn_crab(world, map_object.position)?;
271+
objects.push(crab);
272+
}
273+
_ => {
266274
#[cfg(debug_assertions)]
267275
println!("WARNING: Invalid environment item id '{}'", &map_object.id)
268276
}
269-
}
277+
},
270278
}
271279
}
272280
}

src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub mod particles;
2121
pub mod physics;
2222
pub mod player;
2323
pub mod resources;
24+
pub mod utils;
2425

2526
pub mod drawables;
2627

0 commit comments

Comments
 (0)