Skip to content

Commit da881d6

Browse files
authored
Merge pull request #124 from utilForever/brick
Add BRICK and the Brick Wall level
2 parents 8758d2e + 56c46e5 commit da881d6

8 files changed

Lines changed: 127 additions & 0 deletions

File tree

Extensions/BabaEditor/LevelEditor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ const std::vector<ObjectEntry>& ObjectCatalog()
155155
{ ObjectType::ICON_EMPTY, "EMPTY", "Special", ColorU8(18, 22, 32) },
156156
{ ObjectType::ALGAE, "ALGAE", "Text: Nouns", ColorU8(238, 238, 238) },
157157
{ ObjectType::BABA, "BABA", "Text: Nouns", ColorU8(238, 238, 238) },
158+
{ ObjectType::BRICK, "BRICK", "Text: Nouns", ColorU8(238, 238, 238) },
158159
{ ObjectType::CRAB, "CRAB", "Text: Nouns", ColorU8(238, 238, 238) },
159160
{ ObjectType::FLAG, "FLAG", "Text: Nouns", ColorU8(238, 238, 238) },
160161
{ ObjectType::GRASS, "GRASS", "Text: Nouns", ColorU8(238, 238, 238) },

Extensions/BabaGUI/main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
text_images = {
3333
pyBaba.ObjectType.ALGAE: "ALGAE",
3434
pyBaba.ObjectType.BABA: "BABA",
35+
pyBaba.ObjectType.BRICK: "BRICK",
3536
pyBaba.ObjectType.CRAB: "CRAB",
3637
pyBaba.ObjectType.ICE: "ICE",
3738
pyBaba.ObjectType.JELLY: "JELLY",
2.67 KB
Loading

Resources/Maps/brick_wall.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
15 8
2+
132 111 132 132 132 132 132 132 132 132 132 132 132 111 132
3+
111 132 132 170 170 170 170 170 132 132 132 132 132 132 132
4+
132 132 132 170 4 67 77 170 132 174 174 174 174 174 174
5+
132 132 132 170 170 170 170 170 132 174 121 121 121 174 64
6+
132 114 132 170 170 170 170 170 132 174 121 135 121 174 67
7+
132 132 132 170 25 67 86 170 132 174 121 121 121 174 78
8+
132 132 132 170 170 170 170 170 132 174 174 174 174 174 174
9+
132 132 111 132 132 132 132 132 132 132 132 132 111 132 132

Tests/PythonTests/test_game.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,45 @@ def test_game_pillar_yard_forms_pillar_is_you_and_wins():
488488
assert game.GetPlayState() == pyBaba.PlayState.WON
489489

490490

491+
def test_game_brick_wall_load_and_reset_preserves_bricks():
492+
game = pyBaba.Game("Resources/Maps/brick_wall.txt")
493+
bricks = [
494+
(10, 3),
495+
(11, 3),
496+
(12, 3),
497+
(10, 4),
498+
(12, 4),
499+
(10, 5),
500+
(11, 5),
501+
(12, 5),
502+
]
503+
assert game.GetMap().GetWidth() == 15
504+
assert game.GetMap().GetHeight() == 8
505+
assert game.GetRuleManager().GetNumRules() == 3
506+
assert game.GetMap().At(1, 4).HasType(pyBaba.ObjectType.ICON_BABA)
507+
assert game.GetMap().At(5, 4).HasType(pyBaba.ObjectType.ICON_TILE)
508+
assert game.GetMap().At(11, 4).HasType(pyBaba.ObjectType.ICON_FLAG)
509+
assert not game.GetMap().At(11, 4).HasType(pyBaba.ObjectType.ICON_BRICK)
510+
assert game.GetMap().GetPositions(pyBaba.ObjectType.ICON_BRICK) == bricks
511+
512+
game.MovePlayer(pyBaba.Direction.RIGHT)
513+
game.Reset()
514+
assert game.GetMap().At(1, 4).HasType(pyBaba.ObjectType.ICON_BABA)
515+
assert game.GetMap().GetPositions(pyBaba.ObjectType.ICON_BRICK) == bricks
516+
assert game.GetRuleManager().GetNumRules() == 3
517+
assert game.GetPlayState() == pyBaba.PlayState.PLAYING
518+
519+
520+
def test_game_brick_wall_forms_baba_is_win_and_wins():
521+
game = pyBaba.Game("Resources/Maps/brick_wall.txt")
522+
523+
_move(game, "RRRRRRDDLULDLUUDRRRULL")
524+
assert game.GetRuleManager().HasProperty(
525+
[pyBaba.ObjectType.ICON_BABA], pyBaba.ObjectType.WIN
526+
)
527+
assert game.GetPlayState() == pyBaba.PlayState.WON
528+
529+
491530
def test_game_sink_reparses_destroyed_rule_text():
492531
game = pyBaba.Game("Resources/Maps/sink_rule_reparse.txt")
493532

Tests/PythonTests/test_gui.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ def test_sprite_palettes_keep_colored_pixels_opaque():
9090
"Extensions/BabaGUI/sprites/text/KEKE.gif": (((196, 90, 117),), 1),
9191
"Extensions/BabaGUI/sprites/text/LOVE.gif": (((241, 120, 242),), 1),
9292
"Extensions/BabaGUI/sprites/text/MOVE.gif": (((119, 171, 63),), 1),
93+
"Extensions/BabaGUI/sprites/text/BRICK.gif": (((144, 103, 62),), 1),
9394
"Extensions/BabaGUI/sprites/icon/ALGAE.gif": (((84, 150, 64),), 1),
9495
"Extensions/BabaGUI/sprites/icon/KEKE.gif": (((196, 90, 117),), 2),
9596
"Extensions/BabaGUI/sprites/icon/LOVE.gif": (((241, 120, 242),), 1),

Tests/UnitTests/EditorTests.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,44 @@ TEST_CASE("Editor - Pillar Yard round trip and sprite assets")
221221
}
222222
}
223223

224+
TEST_CASE("Editor - Brick Wall round trip and sprite assets")
225+
{
226+
namespace fs = std::filesystem;
227+
228+
LevelFile brickWall;
229+
REQUIRE(LoadLevelFile(MAPS_DIR "brick_wall.txt", brickWall));
230+
CHECK(brickWall.width == 15);
231+
CHECK(brickWall.height == 8);
232+
CHECK(brickWall.tiles[4 * brickWall.width + 10][0] ==
233+
ObjectType::ICON_BRICK);
234+
CHECK(brickWall.tiles[4 * brickWall.width + 11][0] ==
235+
ObjectType::ICON_FLAG);
236+
CHECK(brickWall.tiles[4 * brickWall.width + 11][1] ==
237+
ObjectType::ICON_EMPTY);
238+
239+
const fs::path path =
240+
fs::current_path() / "baba-is-auto-brick-wall-round-trip.txt";
241+
std::error_code error;
242+
CHECK(SaveLevelFile(path, brickWall));
243+
244+
LevelFile loaded;
245+
REQUIRE(LoadLevelFile(path, loaded));
246+
CHECK(loaded.tiles == brickWall.tiles);
247+
CHECK(loaded.directions == brickWall.directions);
248+
249+
fs::remove(path, error);
250+
251+
const fs::path root = (fs::path(MAPS_DIR) / "../..").lexically_normal();
252+
253+
for (const char* asset : {
254+
"Extensions/BabaGUI/sprites/text/BRICK.gif",
255+
"Extensions/BabaGUI/sprites/icon/BRICK.gif",
256+
})
257+
{
258+
CHECK(fs::is_regular_file(root / asset));
259+
}
260+
}
261+
224262
TEST_CASE("Editor - Layer tile direction updates")
225263
{
226264
LevelFile::LayerTile tiles{ ObjectType::ICON_EMPTY, ObjectType::ICON_EMPTY,

Tests/UnitTests/GameTests.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <algorithm>
2121
#include <array>
2222
#include <string_view>
23+
#include <vector>
2324

2425
using namespace baba_is_auto;
2526

@@ -364,6 +365,43 @@ TEST_CASE("Game - Pillar Yard")
364365
}
365366
}
366367

368+
TEST_CASE("Game - Brick Wall")
369+
{
370+
SUBCASE("Loads and resets the brick layout")
371+
{
372+
Game game(MAPS_DIR "brick_wall.txt");
373+
const std::vector<Position> bricks = {
374+
{ 10, 3 }, { 11, 3 }, { 12, 3 }, { 10, 4 },
375+
{ 12, 4 }, { 10, 5 }, { 11, 5 }, { 12, 5 },
376+
};
377+
CHECK(game.GetMap().GetWidth() == 15);
378+
CHECK(game.GetMap().GetHeight() == 8);
379+
CHECK(game.GetRuleManager().GetNumRules() == 3);
380+
CHECK(game.GetMap().At(1, 4).HasType(ObjectType::ICON_BABA));
381+
CHECK(game.GetMap().At(5, 4).HasType(ObjectType::ICON_TILE));
382+
CHECK(game.GetMap().At(11, 4).HasType(ObjectType::ICON_FLAG));
383+
CHECK_FALSE(game.GetMap().At(11, 4).HasType(ObjectType::ICON_BRICK));
384+
CHECK(game.GetMap().GetPositions(ObjectType::ICON_BRICK) == bricks);
385+
386+
game.MovePlayer(Direction::RIGHT);
387+
game.Reset();
388+
CHECK(game.GetMap().At(1, 4).HasType(ObjectType::ICON_BABA));
389+
CHECK(game.GetMap().GetPositions(ObjectType::ICON_BRICK) == bricks);
390+
CHECK(game.GetRuleManager().GetNumRules() == 3);
391+
CHECK(game.GetPlayState() == PlayState::PLAYING);
392+
}
393+
394+
SUBCASE("Forms BABA IS WIN and wins")
395+
{
396+
Game game(MAPS_DIR "brick_wall.txt");
397+
398+
Move(game, "RRRRRRDDLULDLUUDRRRULL");
399+
CHECK(game.GetRuleManager().HasProperty({ ObjectType::ICON_BABA },
400+
ObjectType::WIN));
401+
CHECK(game.GetPlayState() == PlayState::WON);
402+
}
403+
}
404+
367405
TEST_CASE("Game - Editor Smoke Map")
368406
{
369407
Game game(MAPS_DIR "editor_smoke.txt");

0 commit comments

Comments
 (0)