diff --git a/content/map/11x0.png b/content/map/11x0.png new file mode 100644 index 0000000..1523c1d Binary files /dev/null and b/content/map/11x0.png differ diff --git a/content/map/12x0.png b/content/map/12x0.png new file mode 100644 index 0000000..491b93b Binary files /dev/null and b/content/map/12x0.png differ diff --git a/content/map/13x0.png b/content/map/13x0.png new file mode 100644 index 0000000..33a05d3 Binary files /dev/null and b/content/map/13x0.png differ diff --git a/content/map/3x1.png b/content/map/3x1.png index f405b2a..79bb004 100644 Binary files a/content/map/3x1.png and b/content/map/3x1.png differ diff --git a/content/map/8x0.png b/content/map/8x0.png index ec82f2f..e395514 100644 Binary files a/content/map/8x0.png and b/content/map/8x0.png differ diff --git a/content/map/8x1.png b/content/map/8x1.png index 03ddca3..15fa178 100644 Binary files a/content/map/8x1.png and b/content/map/8x1.png differ diff --git a/content/sprites/blob.ase b/content/sprites/blob.ase index a508084..11d37ce 100644 Binary files a/content/sprites/blob.ase and b/content/sprites/blob.ase differ diff --git a/content/tilesets/jumpthru.ase b/content/tilesets/jumpthru.ase new file mode 100644 index 0000000..683b7dd Binary files /dev/null and b/content/tilesets/jumpthru.ase differ diff --git a/src/components/collider.h b/src/components/collider.h index a22e5ec..0b46348 100644 --- a/src/components/collider.h +++ b/src/components/collider.h @@ -17,7 +17,7 @@ namespace TL Grid }; - uint32_t mask; + uint32_t mask = 0; Collider(); diff --git a/src/components/mover.cpp b/src/components/mover.cpp index 6be1b42..e3e74f1 100644 --- a/src/components/mover.cpp +++ b/src/components/mover.cpp @@ -38,7 +38,16 @@ bool Mover::move_y(int amount) while (amount != 0) { - if (collider->check(Mask::solid, Point(0, sign))) + // if hit solid + bool hit_something = collider->check(Mask::solid, Point(0, sign)); + + // no solid, but we're moving down, check for jumpthru + // but ONLY if we're not already overlapping a jumpthru + if (!hit_something && sign > 0) + hit_something = collider->check(Mask::jumpthru, Point(0, sign)) && !collider->check(Mask::jumpthru, Point(0, 0)); + + // stop movement + if (hit_something) { if (on_hit_y) on_hit_y(this); @@ -82,7 +91,11 @@ bool Mover::on_ground(int dist) const if (!collider) return false; - return collider->check(Mask::solid, Point(0, dist)); + return + // solid + collider->check(Mask::solid, Point(0, dist)) || + // jumpthru + (collider->check(Mask::jumpthru, Point(0, dist)) && !collider->check(Mask::jumpthru, Point(0, 0))); } void Mover::update() diff --git a/src/components/player.h b/src/components/player.h index 8141997..03945af 100644 --- a/src/components/player.h +++ b/src/components/player.h @@ -34,6 +34,6 @@ namespace TL float m_invincible_timer = 0; float m_start_timer = 1; Collider* m_attack_collider = nullptr; - bool m_on_ground; + bool m_on_ground = false; }; } \ No newline at end of file diff --git a/src/content.cpp b/src/content.cpp index 8e2088d..2b3d55b 100644 --- a/src/content.cpp +++ b/src/content.cpp @@ -57,6 +57,7 @@ void Content::load() // load the main font font = SpriteFont(path() + "fonts/dogica.ttf", 8, SpriteFont::ASCII); + font.line_gap = 4; // load sprites Vector sprite_info; diff --git a/src/factory.cpp b/src/factory.cpp index 7bd2a0d..286de16 100644 --- a/src/factory.cpp +++ b/src/factory.cpp @@ -213,26 +213,51 @@ Entity* Factory::mosquito(World* world, Point position) return en; } -Entity* Factory::door(World* world, Point position) + +namespace +{ + void make_door_contents(Entity* en) + { + auto anim = en->add(Animator("door")); + anim->play("idle"); + anim->depth = -1; + + auto hitbox = en->add(Collider::make_rect(RectI(-6, -16, 12, 16))); + hitbox->mask = Mask::solid; + } +} + +Entity* Factory::door(World* world, Point position, bool wait_for_player) { auto en = world->add_entity(position); - auto anim = en->add(Animator("door")); - anim->play("idle"); - anim->depth = -1; - - auto hitbox = en->add(Collider::make_rect(RectI(-6, -16, 12, 16))); - hitbox->mask = Mask::solid; + if (!wait_for_player) + make_door_contents(en); // check if all enemies are dead - en->add(Timer(0.25f, [](Timer* self) + en->add(Timer(0.25f, [waiting = wait_for_player](Timer* self) mutable { self->start(0.25f); + + if (waiting) + { + auto player = self->world()->first(); + if (player->entity()->position.x > self->entity()->position.x + 12) + { + make_door_contents(self->entity()); + Factory::pop(self->world(), self->entity()->position + Point(0, -8)); + waiting = false; + } + else + return; + } + if (!self->world()->first()) { Factory::pop(self->world(), self->entity()->position + Point(0, -8)); self->entity()->destroy(); } + })); return en; diff --git a/src/factory.h b/src/factory.h index c221c9a..fcb49d7 100644 --- a/src/factory.h +++ b/src/factory.h @@ -14,7 +14,7 @@ namespace TL Entity* spitter(World* world, Point position); Entity* bullet(World* world, Point position, int direction); Entity* mosquito(World* world, Point position); - Entity* door(World* world, Point position); + Entity* door(World* world, Point position, bool wait_for_player = false); Entity* blob(World* world, Point position); } } \ No newline at end of file diff --git a/src/game.cpp b/src/game.cpp index a1e4559..64a6d9d 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -29,7 +29,7 @@ void Game::startup() m_draw_colliders = false; // load first room - load_room(Point(10, 0)); + load_room(Point(11, 0)); camera = Vec2(room.x * width, room.y * height); } @@ -47,6 +47,7 @@ void Game::load_room(Point cell, bool is_reload) auto grass = Content::find_tileset("grass"); auto plants = Content::find_tileset("plants"); auto backs = Content::find_tileset("back"); + auto jumpthrus = Content::find_tileset("jumpthru"); // make the floor auto floor = world.add_entity(offset); @@ -93,6 +94,16 @@ void Game::load_room(Point cell, bool is_reload) tilemap->set_cell(x, y, &backs->random_tile()); break; + // jumpthru tiles + case 0xdf7126: + { + tilemap->set_cell(x, y, &jumpthrus->random_tile()); + auto jumpthru_en = world.add_entity(offset + Point(x * tile_width, y * tile_height)); + auto jumpthru_col = jumpthru_en->add(Collider::make_rect(RectI(0, 0, 8, 4))); + jumpthru_col->mask = Mask::jumpthru; + break; + } + // player (only if it doesn't already exist) case 0x6abe30: if (!world.first()) @@ -119,6 +130,11 @@ void Game::load_room(Point cell, bool is_reload) Factory::door(&world, world_position); break; + // closing door + case 0x847e87: + Factory::door(&world, world_position, true); + break; + // blob case 0x3f3f74: Factory::blob(&world, world_position); @@ -164,7 +180,7 @@ void Game::update() if (pos.y < 0) next_room.y--; // see if room exists - if (player->health > 0 && Content::find_room(next_room)) + if (player->health > 0 && Content::find_room(next_room) && next_room.x >= room.x) { Time::pause_for(0.1f); @@ -238,7 +254,7 @@ void Game::update() { auto player = world.first(); if (player) - player->get()->speed = Vec2(100, -200); + player->get()->speed = Vec2(0, -150); } // delete old objects (except player!) @@ -277,6 +293,27 @@ void Game::render() } } + // hacky start / end screen text + if (room == Point(0, 0) || m_last_room == Point(0, 0)) + { + auto w = Content::font.width_of(title); + auto pos = Point((width - w) / 2, 20); + batch.str(Content::font, title, pos + Point(0, 1), Color::black); + batch.str(Content::font, title, pos, Color::white); + + w = Content::font.width_of(controls); + pos.x = (width - w) / 2; + pos.y += 20; + batch.str(Content::font, controls, pos, Color::white * 0.25f); + } + else if (room == Point(13, 0)) + { + auto w = Content::font.width_of(ending); + auto pos = Point(room.x * width + width / 2, room.y * height + 20); + batch.str(Content::font, ending, pos + Point(0, 1), TextAlign::Top, 8, Color::black); + batch.str(Content::font, ending, pos, TextAlign::Top, 8, Color::white); + } + // end camera offset batch.pop_matrix(); diff --git a/src/game.h b/src/game.h index d6a4c1c..fa95c73 100644 --- a/src/game.h +++ b/src/game.h @@ -16,6 +16,10 @@ namespace TL static constexpr int columns = width / tile_width; static constexpr int rows = height / tile_height + 1; + static inline const char* title = "SWORD II: ADVENTURE OF FROG"; + static inline const char* controls = "arrow keys + X / C\nstick + A / X"; + static inline const char* ending = "YOU SAVED POND\nAND YOU ARE\nA REAL HERO"; + World world; FrameBufferRef buffer; Batch batch; diff --git a/src/masks.h b/src/masks.h index c59480b..16e6b24 100644 --- a/src/masks.h +++ b/src/masks.h @@ -6,7 +6,8 @@ namespace TL struct Mask { static constexpr uint32_t solid = 1 << 0; - static constexpr uint32_t player_attack = 1 << 1; - static constexpr uint32_t enemy = 1 << 2; + static constexpr uint32_t jumpthru = 1 << 1; + static constexpr uint32_t player_attack = 1 << 2; + static constexpr uint32_t enemy = 1 << 3; }; } \ No newline at end of file