From 0d01334e0a8b4c42d99a91949c945aab2fa07c76 Mon Sep 17 00:00:00 2001 From: Noel Berry Date: Sun, 3 Jan 2021 19:47:16 -0800 Subject: [PATCH] everything except boss --- content/map/11x0.png | Bin 0 -> 207 bytes content/map/12x0.png | Bin 0 -> 243 bytes content/map/13x0.png | Bin 0 -> 194 bytes content/map/3x1.png | Bin 338 -> 368 bytes content/map/8x0.png | Bin 254 -> 252 bytes content/map/8x1.png | Bin 195 -> 214 bytes content/sprites/blob.ase | Bin 898 -> 897 bytes content/tilesets/jumpthru.ase | Bin 0 -> 574 bytes src/components/collider.h | 2 +- src/components/mover.cpp | 17 ++++++++++++-- src/components/player.h | 2 +- src/content.cpp | 1 + src/factory.cpp | 41 +++++++++++++++++++++++++------- src/factory.h | 2 +- src/game.cpp | 43 +++++++++++++++++++++++++++++++--- src/game.h | 4 ++++ src/masks.h | 5 ++-- 17 files changed, 99 insertions(+), 18 deletions(-) create mode 100644 content/map/11x0.png create mode 100644 content/map/12x0.png create mode 100644 content/map/13x0.png create mode 100644 content/tilesets/jumpthru.ase diff --git a/content/map/11x0.png b/content/map/11x0.png new file mode 100644 index 0000000000000000000000000000000000000000..1523c1d070309597184c8ea7d4129c4dcf7dfcd7 GIT binary patch literal 207 zcmeAS@N?(olHy`uVBq!ia0vp^azHG|!3HExrOA{7DaPU;cPEB*=VV?2Ih~#^jv*eM z$$$R;|6kw6$l$}A_;STj<-gTe~DWM4fxf)0b literal 0 HcmV?d00001 diff --git a/content/map/12x0.png b/content/map/12x0.png new file mode 100644 index 0000000000000000000000000000000000000000..491b93b292833a72f5ebe088d5983cb21e6f84dd GIT binary patch literal 243 zcmeAS@N?(olHy`uVBq!ia0vp^azHG|!3HExrOA{7DaPU;cPEB*=VV?2Icqϒ-h zlmGnx|G&PCk->*KQIi=6xOX+oUZ(4JboV;>W2@MvTbP*|9O#g_^1~#ESs~gk!O{1^ zqr2vP25o!(s46u5Hd46;PkrUDC-OfAb4|l&&&Le>t44@u9DU^m}GrcciHM( z4~E4I3soKb{3Yzd=6-9FVdQ&MBb@01-@EiU0rr literal 0 HcmV?d00001 diff --git a/content/map/13x0.png b/content/map/13x0.png new file mode 100644 index 0000000000000000000000000000000000000000..33a05d3358f274218ed3a384fd28bbd8bf78eedd GIT binary patch literal 194 zcmeAS@N?(olHy`uVBq!ia0vp^azHG|!3HExrOA{7DaPU;cPEB*=VV?2IW?Xxjv*eM z$$$R;|6k9hk&u#-vOqjx(QMzvV*ODzSszy%y~3oEH)|VnvLQ1wbMvb$`aIh=S9n}{ zF?Xf^#G^eYrm|R71T5i8*Zy)hB>@O#7#yCh#GTl{I)6#he_e~;_41)_4(A(gdo>XV p7S`_)zpA6A87iKZw|Lf328)H_&Ufz}od9$PgQu&X%Q~loCIF)RNrwOc literal 0 HcmV?d00001 diff --git a/content/map/3x1.png b/content/map/3x1.png index f405b2a2f93d39271aba9ec71cd690755cc45cd0..79bb0047d627eed1337507ae9f12f0906cd25b53 100644 GIT binary patch delta 328 zcmV-O0k{6r0`LNmF@GvaL_t(YiM5rnP69y?hQBr1TH0Gkju)`P@<@R9FxWv&i#1ka zd<_F6M+ub`-CbzxEse3USPQ&k4)$(uH^*OXW_IVFe`a=9O{QHCcx*?*K1r-90Xx!`_r^}pJd z6T6~Ha<83F=roMJll2&Os`twGg9k#fPkCh^$WN^eR>gzS+VV9OF?@r2@VHK`kYGr`*q93<-5y~tnbaoHp^s<*4mxeM4EniHXQc8GI1Rr ahr}NyPF${(C}}qU00000eyMW0t}%Pm$47uX6Kq)@;`LI*W1)KCEz zfg+SpQPCymKy(z|V&!NOVjNrHm*Zsq|1&?1TJOf17BNc>0E~KrqLyZ705 zRN|Ch_}MtKQh z!g0uWWg{r3)&-~IS#o$Gs3W!2Y{EW1>fms>#;25eso4T0ClcgXHZUaFA|+d-K-r~D zMDXV%5l4NZWek8`*5ANNsgj5w$3E$m;v^b7cHL}d*OH(bEP3WN>gWBJ@9x#-m16I` w)reDmL2K<#Tq8$net9lbci)(}jUR`^A7*M+Xhf@=jsO4v07*qoM6N<$f(Ss3-2eap diff --git a/content/map/8x0.png b/content/map/8x0.png index ec82f2f7ba4427c4f435101b6ccb4a8777db6f6a..e39551493e65282ef2e0244516ee3fa4581f8064 100644 GIT binary patch delta 60 zcmeyz_=j+1*Mzaj$MOH5M(E4)sNG9jf2G*I2Z`5 QZ!iFXr>mdKI;Vst04k9gZ2$lO delta 62 zcmeyv_>XadA>)pTMzf6Wn&e7KNGKe9xGJ&vVQ>(S+Q}q0H#ZSa70p%AJPh5}6BKnr R(?2l)fv2mV%Q~loCIInM7Cis} diff --git a/content/map/8x1.png b/content/map/8x1.png index 03ddca30917d7daac6199b02d6bc9748a5a3e106..15fa17824560cb7d4ae522a6b8fb5e403c03b0da 100644 GIT binary patch delta 173 zcmX@ic#Uy_Vf_S87sn8f&g4J;|NpON(@023NpWEF2nu1>;Q@lYS=&Gq&pIhHp56H} zi96!BDfBR#UvbUpMz8xR2|zHz;PC8MV#bCB1_mi_jT3IvKIVuC*!W+p zIqARds^~VJh=h+8Q_C)PiW*$JZpD&tP|c&;;^>AMYI4&On3=_{EEemJvdQ{*VY>u_ Xt%!o^XX8Uv3_#%N>gTe~DWM4fuZ2Yz delta 154 zcmV;L0A>Hy0mA{1F@JqYL_t(YiS5z734kyVK;frk80{QDOKsf56Nk72(|w@*!1z7B@~ z)tDUXb(PY0Z0()XSm>5JQ>LMfn?7I{h^fz3?O_jl`2X+*NE6~6a+C(CiU0rr07*qo IM6N<$f=fd~uK)l5 diff --git a/content/sprites/blob.ase b/content/sprites/blob.ase index a5080848ce4f1e934ab8af40ea171d8f8109c1ee..11d37ce6fd05230bfec1874be8d3d545eda5fedd 100644 GIT binary patch delta 82 zcmV-Y0ImOm2Z09xfsp}!0a3Am3jzT}lZ^s24k&zF>aeM&rkh}D0U=Y9&;mycQTT+^ oW79{9eE`@ZlOqF17#L!>_}J8wYCaL_$q65PafPB502I6~;NjmOJ^%m! delta 83 zcmV-Z0IdIk2Z9Fyf{_7#0aCGn3jzT~lZ^s24{$avHQ3aXU_MFi2LK6clg|Q24B>1- pYO(1f)jj~gI+G#;M;Iu4ba{O0Nj0BH_2h&PzPLhB3jqAZF5s%qAGiPj diff --git a/content/tilesets/jumpthru.ase b/content/tilesets/jumpthru.ase new file mode 100644 index 0000000000000000000000000000000000000000..683b7dd37b36ee63bef3b3621a0dd5657f561f2c GIT binary patch literal 574 zcmcJN&nts*9LGPyY&Q-f7yBm3MYbnDTGm#|#T?cSlN?54wWmxZk&>j;F1si(2ep*K z#YItTwIj|N2NYMuK|+1Ko{j7u@cH(A^?APEdfumlcmHaB9rXD;>LyPgU8&aZ_rwNUQ3GgB?B?_j+JD(hu)u+hK7p z4xbA<@bk47Za;;fnRCOw%_Iyax?nii1`VGV1_JZYJ-!CVk`FMJ(J*@T2rq8Gpr%AJ z$ER?8WdkNm6OKm0aA6AAM`G}L`3$DFhG1&OtxX1~vA(;aVF)HbA9uvDMj2mZ zF+~$c1hGR6FQhO+$8ymc3lzvFoMd9jB#<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