From cdccb14f2efb8f3215c16af83f7982dd04e91568 Mon Sep 17 00:00:00 2001 From: Noel Berry Date: Sun, 3 Jan 2021 18:55:56 -0800 Subject: [PATCH] bunch of stuff --- CMakeLists.txt | 17 ++++-- content/map/10x0.png | Bin 0 -> 265 bytes content/map/4x1.png | Bin 323 -> 309 bytes content/map/5x1.png | Bin 325 -> 334 bytes content/map/6x1.png | Bin 0 -> 285 bytes content/map/7x1.png | Bin 0 -> 270 bytes content/map/8x0.png | Bin 0 -> 254 bytes content/map/8x1.png | Bin 0 -> 195 bytes content/map/9x0.png | Bin 0 -> 284 bytes content/sprites/blob.ase | Bin 0 -> 898 bytes content/sprites/door.ase | Bin 0 -> 707 bytes content/sprites/heart.ase | Bin 0 -> 747 bytes content/sprites/player.ase | Bin 2136 -> 2136 bytes content/tilesets/grass.ase | Bin 697 -> 697 bytes content/tilesets/plants.ase | Bin 609 -> 609 bytes src/components/collider.cpp | 17 +++--- src/components/enemy.h | 10 ++++ src/components/hurtable.cpp | 1 + src/components/mover.cpp | 4 ++ src/components/mover.h | 1 + src/components/player.cpp | 3 ++ src/components/player.h | 3 +- src/factory.cpp | 102 +++++++++++++++++++++++++++++++++++- src/factory.h | 2 + src/game.cpp | 72 +++++++++++++++++++++++-- src/game.h | 2 +- 26 files changed, 214 insertions(+), 20 deletions(-) create mode 100644 content/map/10x0.png create mode 100644 content/map/6x1.png create mode 100644 content/map/7x1.png create mode 100644 content/map/8x0.png create mode 100644 content/map/8x1.png create mode 100644 content/map/9x0.png create mode 100644 content/sprites/blob.ase create mode 100644 content/sprites/door.ase create mode 100644 content/sprites/heart.ase create mode 100644 src/components/enemy.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 18d94bc..1a1b1b0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,8 +17,13 @@ add_executable(game src/game.cpp src/content.h src/content.cpp + src/masks.h + src/factory.h + src/factory.cpp src/assets/sprite.h src/assets/sprite.cpp + src/assets/tileset.h + src/assets/tileset.cpp src/components/animator.h src/components/animator.cpp src/components/collider.h @@ -27,10 +32,14 @@ add_executable(game src/components/player.cpp src/components/mover.h src/components/mover.cpp - src/masks.h - src/factory.h - src/factory.cpp - "src/assets/tileset.h" "src/assets/tileset.cpp" "src/components/tilemap.h" "src/components/tilemap.cpp" "src/components/hurtable.h" "src/components/hurtable.cpp" "src/components/timer.h" "src/components/timer.cpp") + src/components/tilemap.h + src/components/tilemap.cpp + src/components/hurtable.h + src/components/hurtable.cpp + src/components/timer.h + src/components/timer.cpp + src/components/enemy.h +) # Reference blah target_link_libraries(game blah) diff --git a/content/map/10x0.png b/content/map/10x0.png new file mode 100644 index 0000000000000000000000000000000000000000..66309ef51cb84c47a4ccc8405bca12c2c48982a7 GIT binary patch literal 265 zcmV+k0rvihP)Px#!%0LzR7i-u2^Mg|JA z69WSSgR6!OoW1+T5fm|WJ`7MC)N724$kIo)#sB~RXZZjBKSS`@vkbegAI1>J#ou-P zFvG6vhl#h?J5wL4LF59WE#5Ni0>u`>;u~&p);TwZRQDmWr3?%V3@k81r(!dE z8pZaZ0OXWSm3+*=faxQAmNGCfFtALR;f+^ALB>|H9fEEdGN5UZi7ylY?J!l9d7A`f P00000NkvXXu0mjfhxBV2 literal 0 HcmV?d00001 diff --git a/content/map/4x1.png b/content/map/4x1.png index e7fb624f31f1b8e297109e733dc167fdf2fb10c0..a4bee13a2c7f16ad0ee0dad4aed6c4153a98f05b 100644 GIT binary patch delta 74 zcmX@iw3TUsA>;drMn~-`MB~=qJ6f=Oa${rT!p@Ati8pzd_e)B2^e>OqU8hk~)E%}; eY~~Aw`HLB<7^5Q-7iY>b0D-5gpUXO@geCymxE_4~ delta 88 zcmdnWbeL&^A>-ePMn`>kfZ)T9OF5;^ffakJ#1GH)V`F1$Q(MH_o@zeFE-m3e&+`Ae sHy-DPcWZOazq4rSDpxhD1J5-WW@jhdo~y9zBm)q5y85}Sb4q9e09vplU;qFB diff --git a/content/map/5x1.png b/content/map/5x1.png index a625ce5be05f7b0dc4c6e78ca7a9390f2af91ba3..34fd7114f3bb0a59a595e5ae95fc997497dcdfdc 100644 GIT binary patch delta 295 zcmV+?0oeY<0?q=EFn<9ENklNrxh;dnt%|c{HA%_aype6<2@+D0C_kSld1}`)GW-u`_GBO}z zLcWCoeDTc6cM64%ZU-YHBP5Qq_8DNch>)e&EdTw<3`4K0h7H5)wcAl0gDsAcU5X4~ zO3_0F7KgahV*_|owX22=Uf*F;Pb^@>S7f65j8p&%32a3sQK=eVUPaDA$b3Qouf@a^ t4(Mu#E!oJ*#~`FS1{uK5Fn<95Nkl;4PKuORPA_*(T-+aX1qRBZGD9EXaN1h2=&KA4ltpEUnMoTq z%k?m?+XestvN#=0e7;|;*g!1Vt4Z~I3b_fd)sz(ArMPaJVSj{zibJK8b-Ad;E^>~L z9*VjmT0I6Xl{(&c3FL|VjR+Be4xd^Lsm}Ao?QLyxAmX#eyUU6t@{w}neV15!xjeSU z^rRFz)pSMI(3Q_YywzEpit4!hP@vQ@O=V-Do#0w#(5;rhoAhN{uhe)0r~K8s-^g-VE_OC07*qoM6N<$g2aS}wg3PC diff --git a/content/map/6x1.png b/content/map/6x1.png new file mode 100644 index 0000000000000000000000000000000000000000..3e36f98ed8693cd8babf3bec0a7c024415de489b GIT binary patch literal 285 zcmV+&0pk9NP)Px#*GWV{R7i=%l)VwcFbsvCav26X27nR@CgG^)GXy1*&?I*>cn5nMQ_1Hjwy{kT zzA9(Sdise(_s7{naJxL^(d@Kq3yy?if~W1leGf(f0FIk|l@PyY$Xe@4?F*$I)dUa~ zE)gvaBIKjZG5UsVLyiw8TqF1kEfK9M$TR?OeeD);uDc$(>w|ZrzuFyERzdbS;M&pT zI!#4i1NkeH7YSz^ia1pbwr88rnDzP%pdjP9nar^d5sjjjBPTPI)fkM5E|Px#$Vo&&R7i>KlrathArM7B#=~rBwl>*nD=%WKEbM6a0G1xY)&>(By#wB6Y#g#| z0B4a%<4Z_@4D;s$8AU{d3M^`f0)PVGIqsWvR-)_k@$o#z0KhU!C6bKSQ}JmG5O6$3 zl3*_UrIK%4LWnuHt+)RAswJ??@zsiijlBZ^lu{xgs|^648TxcVyW5K11$o12LslDN zLNPqL?%?JU)SL!#JZ*ye`|U-V!cnAw#0pB`9OoPkF?AoyTl`l`4OHvZf8n3;0&x6& U^rdq|7XSbN07*qoM6N<$f(u}6G5`Po literal 0 HcmV?d00001 diff --git a/content/map/8x0.png b/content/map/8x0.png new file mode 100644 index 0000000000000000000000000000000000000000..ec82f2f7ba4427c4f435101b6ccb4a8777db6f6a GIT binary patch literal 254 zcmeAS@N?(olHy`uVBq!ia0vp^azHG|!3HExrOA{7DaPU;cPEB*=VV?2IXgUE978-h zlT#8Bew;U8Xy82df!;xZ`^C)ENjGzY76@{#tdiOV2)}P|>*gCAp4|up3l);J<4R97oU{&}ub4fb@nT`~>7Wub#REV7|F7TCf7c{e zQbI!E;KNmk%@2cvc+^fNxw*NCc&ccwisoVHzMi0{8=C$J=m!Q*S3j3^P6ckZ1dqA`cu3dC5Y?>cU`lzz;=%tTOe{T>#(9o#N1H?$w| zG$hVt++nkK-ma!yOW&<++{GZ!VB^)FxZh{Hzi;?HzIKMIGh|+uPQ6r~^LFm#h!@kW tgO@Groo$yO-m&t0*xN+@>L33;L~8i|?A` z2I?%!4mhlnny_GTzoevO;FA@P9^apT#^6YdY0igN2eUS=ZsT?AJ<%}ry@;dt#iIs6 zrkY|(tJ{y>fA62h6L*23K~*ECp|i2EQ89ZyW0>cApISB$sQxX)24q{v&sJU^{yu3( z+}`eoe(Bs@vo>7IT9an{&)ttPBjFHF{v5rw#-^UNELRhlMb!0@WZHQRzWINbioB}C Ykh#aQhcT6_8R$a>Pgg&ebxsLQ08Zv>oB#j- literal 0 HcmV?d00001 diff --git a/content/sprites/blob.ase b/content/sprites/blob.ase new file mode 100644 index 0000000000000000000000000000000000000000..a5080848ce4f1e934ab8af40ea171d8f8109c1ee GIT binary patch literal 898 zcmb`FO-NKx7>2+3shKHLS5YfZ7U61~8T>70rY0sbD{2IzLY$aJoZDm?7FiM^Lf~ei zf+(Y;Xjh9CQM8aCT1C5}tVJW(q85T-8#7MNz1$fu(z0_o58pZG^1ko6-yQRa6d!q{ znn#ICM3$HdYJ0i1|w~)FdiR*q4XF$ z(LW0_lN$ECn}ct^EJMu@nSAmbj$gS7bA|zrb*12i!~}dCiNKko8Tj$?OIWzIA5NSN zX@d)R&F`)#xCA#KKG_LQY9f=Dup}iW83{-_qLGVGBqENPMQc(J0e{SK#uiTual@*{ zbW*gtJcuAZIdF0~drpO8EH){+Q68(B;Fa8|eAX?_S9sSe#`!Y?%~Z8k+e*hi>CERc zSrsnpQB>R0?6g@|GL>zr^PgQLl+L(f_kuRXXo zb-W=u&=hR^^!`RV);{l(!0A7pPE?i_T-G0DUSW@|>XLv%wUV3LssU4V%V@HGceG{k z`oltBwC~bvK4ColzV$;)UhUZ6?p`H%(3W(|T8CtXtSd?WD`?%w(D2BQ_Qw1Be$9kVKIvqcJj*h$OEpq?CoRP##0sSYe4+ z*jP&JgawL~5~74UzI&M{TjzGZ^FQaFdw<`#_aIv2YAs4^TuP!uq=Wv`STh#Q`#-Dy zS5=b#_GmRzt-LmwZc%3BuaI-98+H~uV5qSaUiRg{v(-*` zf3O7KpImV9whjjO?XYmJ2UZ92VSRNrbh?XSS=j)zdnaH^&o%UgHEcV&frl3#P}4-h zn>%oFdnP!NmMv=96Hl_Qr)>YooE z*~%CzfsSr}Ayt;SjUQ(=i!^ixe17Hlo|}UW8r}G%#+XP~>gy4$YnjC<5o4|+?~w#{ z4lVn<-q+*u+_Cl2g)aBW$ir@WxX3Z)d9fvJzdm0*rEI;}?p&>J@g*6v6*1DZGGqM& DdD5o_ literal 0 HcmV?d00001 diff --git a/content/sprites/heart.ase b/content/sprites/heart.ase new file mode 100644 index 0000000000000000000000000000000000000000..a47a7e5fbdf37e087d05231c680bb6ddf401c78d GIT binary patch literal 747 zcmb`FUr19?9LIlib0cBc)2JYJh>#%AyAkT@(x4&1CLv1GNNBMfY^eQPu@ThBP;iP5 z1}o=-FTJI2BJ|Kp&`U%wN^BCFST6~ZKB{p2+)KH=^bm9|_rtlrbNPKg=ial`AX0tP zAji3s*hJ(GcWqEJi`IIr`u}Flc?V|-VK{kL zGg558VSabTgiWvm^l?WVYn1Ut7E?5FL=ZdF@IneBbW9h+zybyG2`8CYG6^J&D6g5M z?C{S(L0r;(J3I71`GP#0Q2dR*4TmHi4G-I_Gg9|XqYRDQOJ}cAYE&Y2c4HiMX_8}- znUBYEV@A(ZzS%Qod!?W9cDY+~ONH>yU*+j9ZJE{TZpY=^b+=T`FGmJxv$tcjj)Qp! ny8of=l5;}8)_$=ibb9<-=c*R#%ZJ>p&o=D?Ya+8BA5I?v9FeyT literal 0 HcmV?d00001 diff --git a/content/sprites/player.ase b/content/sprites/player.ase index 170ea8371906064ae44b85ba306bd4274e6d2dd6..0bf1e7632cc6506a8c4e1dd1fe9859e4ec704267 100644 GIT binary patch delta 311 zcmca1a6@2&HnVozb?-_E{kDx8IThwBs!lrNB-X#p;+Rg=<-ji?ligQK?XlMh`dBs7 z^>}I5&HmCH$Hg*Hmo>T9^Y)9$sVv4U%E1;dC(mJl>vv^|xbA#!vI47#)b83<$G;dh z^DWvm)3G^r%S)L~2@}KX0wrrCC+D%6v&<@V6P&yf$bi}`Kbe_Lp5=?JW$}BAtvN$zaoW(>+^5R#S3zi?2 zHZE&$oBgFZj*DfYE^BhH=kJWksVv4U9S5u|CeLAk>vv`OFvV4OvI47#RA=pa_HTU6 ze2X^CbZm~@@=~T#!o={pK*>76$$6~iEIKOg(UVsK8Bm+$Co{9jvv^OonlV|8&4k_d z(Yo!-Reh5a*+iMk_cu+hWV2(*Rt^Z7yqnE}d8R+}`_*2v|86iS6w#PuI|!v{jL}5I9a|jN`IAQiZUi^5GD?|@ B5*`2m diff --git a/content/tilesets/plants.ase b/content/tilesets/plants.ase index 53ac4649e84e58fae00b6dab6480607dff9b42e0..e75056a714d19189f97227fa1be3534db42ea155 100644 GIT binary patch delta 21 dcmaFJ@{nbNCKJoU*LVL<)@3qa+2EUW6aZ;f32XoW delta 21 dcmaFJ@{nbNCKJoE;7|W1>oOUzEO-!~2>@hk2@wDQ diff --git a/src/components/collider.cpp b/src/components/collider.cpp index fad9cbd..2d708b6 100644 --- a/src/components/collider.cpp +++ b/src/components/collider.cpp @@ -72,15 +72,18 @@ void Collider::set_cells(int x, int y, int w, int h, bool value) bool Collider::check(uint32_t mask, Point offset) const { - auto other = world()->first(); - while (other) + if (world()) { - if (other != this && - (other->mask & mask) == mask && - overlaps(other, offset)) - return true; + auto other = world()->first(); + while (other) + { + if (other != this && + (other->mask & mask) == mask && + overlaps(other, offset)) + return true; - other = (Collider*)other->next(); + other = (Collider*)other->next(); + } } return false; diff --git a/src/components/enemy.h b/src/components/enemy.h new file mode 100644 index 0000000..23c8ff1 --- /dev/null +++ b/src/components/enemy.h @@ -0,0 +1,10 @@ +#pragma once +#include "../world.h" + +namespace TL +{ + class Enemy : public Component + { + + }; +} \ No newline at end of file diff --git a/src/components/hurtable.cpp b/src/components/hurtable.cpp index 243f64c..7f2bcbe 100644 --- a/src/components/hurtable.cpp +++ b/src/components/hurtable.cpp @@ -9,6 +9,7 @@ void Hurtable::update() { if (collider->check(hurt_by)) { + Time::pause_for(0.1f); stun_timer = 0.5f; flicker_timer = 0.5f; on_hurt(this); diff --git a/src/components/mover.cpp b/src/components/mover.cpp index fad527d..6be1b42 100644 --- a/src/components/mover.cpp +++ b/src/components/mover.cpp @@ -87,6 +87,10 @@ bool Mover::on_ground(int dist) const void Mover::update() { + // apply friction maybe + if (friction > 0 && on_ground()) + speed.x = Calc::approach(speed.x, 0, friction * Time::delta); + // apply gravity if (gravity != 0 && (!collider || !collider->check(Mask::solid, Point(0, 1)))) speed.y += gravity * Time::delta; diff --git a/src/components/mover.h b/src/components/mover.h index e3b6735..110c321 100644 --- a/src/components/mover.h +++ b/src/components/mover.h @@ -17,6 +17,7 @@ namespace TL Collider* collider = nullptr; Vec2 speed; float gravity = 0; + float friction = 0; std::function on_hit_x; std::function on_hit_y; diff --git a/src/components/player.cpp b/src/components/player.cpp index 59e525e..65ba487 100644 --- a/src/components/player.cpp +++ b/src/components/player.cpp @@ -68,6 +68,9 @@ void Player::update() // START if (m_state == st_start) { + while (hitbox->check(Mask::solid)) + entity()->position.y++; + anim->play("sword"); m_start_timer -= Time::delta; if (m_start_timer <= 0) diff --git a/src/components/player.h b/src/components/player.h index 3b3e3ed..8141997 100644 --- a/src/components/player.h +++ b/src/components/player.h @@ -14,8 +14,9 @@ namespace TL static constexpr int st_attack = 1; static constexpr int st_hurt = 2; static constexpr int st_start = 3; + static constexpr int max_health = 3; - int health = 3; + int health = max_health; VirtualStick input_move; VirtualButton input_jump; diff --git a/src/factory.cpp b/src/factory.cpp index a4f833b..7bd2a0d 100644 --- a/src/factory.cpp +++ b/src/factory.cpp @@ -6,6 +6,7 @@ #include "components/player.h" #include "components/hurtable.h" #include "components/timer.h" +#include "components/enemy.h" using namespace TL; @@ -17,7 +18,7 @@ Entity* Factory::player(World* world, Point position) anim->play("idle"); anim->depth = -10; - auto hitbox = en->add(Collider::make_rect(RectI(-4, -8, 8, 8))); + auto hitbox = en->add(Collider::make_rect(RectI(-4, -12, 8, 12))); auto mover = en->add(Mover()); mover->collider = hitbox; @@ -42,7 +43,6 @@ Entity* Factory::bramble(World* world, Point position) hurtable->collider = hitbox; hurtable->on_hurt = [](Hurtable* self) { - Time::pause_for(0.1f); pop(self->world(), self->entity()->position + Point(0, -4)); self->entity()->destroy(); }; @@ -69,6 +69,7 @@ Entity* Factory::pop(World* world, Point position) Entity* Factory::spitter(World* world, Point position) { auto en = world->add_entity(position); + en->add(Enemy()); auto anim = en->add(Animator("spitter")); anim->play("idle"); @@ -193,6 +194,7 @@ Entity* Factory::mosquito(World* world, Point position) { auto en = world->add_entity(position); auto mosquito = en->add(MosquitoBehavior()); + en->add(Enemy()); auto anim = en->add(Animator("mosquito")); anim->play("fly"); @@ -211,3 +213,99 @@ Entity* Factory::mosquito(World* world, Point position) return en; } +Entity* Factory::door(World* world, Point position) +{ + 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; + + // check if all enemies are dead + en->add(Timer(0.25f, [](Timer* self) + { + self->start(0.25f); + if (!self->world()->first()) + { + Factory::pop(self->world(), self->entity()->position + Point(0, -8)); + self->entity()->destroy(); + } + })); + + return en; +} + +Entity* Factory::blob(World* world, Point position) +{ + auto en = world->add_entity(position); + en->add(Enemy()); + + auto anim = en->add(Animator("blob")); + anim->play("idle"); + anim->depth = -5; + + auto hitbox = en->add(Collider::make_rect(RectI(-4, -8, 8, 8))); + hitbox->mask = Mask::enemy; + + auto mover = en->add(Mover()); + mover->collider = hitbox; + mover->gravity = 300; + mover->friction = 400; + mover->on_hit_y = [](Mover* self) + { + self->get()->play("idle"); + self->stop_y(); + }; + + en->add(Timer(2.0f, [](Timer* self) + { + auto mover = self->get(); + if (!mover->on_ground()) + { + self->start(0.05f); + } + else + { + self->get()->play("jump"); + self->start(2.0f); + mover->speed.y = -90; + + auto player = self->world()->first(); + if (player) + { + auto dir = Calc::sign(player->entity()->position.x - self->entity()->position.x); + if (dir == 0) dir = 1; + + self->get()->scale = Vec2(dir, 1); + mover->speed.x = dir * 40; + } + } + })); + + auto hurtable = en->add(Hurtable()); + hurtable->hurt_by = Mask::player_attack; + hurtable->collider = hitbox; + hurtable->on_hurt = [health = 3](Hurtable* self) mutable + { + auto player = self->world()->first(); + if (player) + { + auto mover = self->get(); + auto sign = Calc::sign(self->entity()->position.x - player->entity()->position.x); + mover->speed.x = sign * 120; + } + + health--; + if (health <= 0) + { + pop(self->world(), self->entity()->position + Point(0, -4)); + self->entity()->destroy(); + } + }; + + return en; +} + diff --git a/src/factory.h b/src/factory.h index 8e86303..c221c9a 100644 --- a/src/factory.h +++ b/src/factory.h @@ -14,5 +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* blob(World* world, Point position); } } \ No newline at end of file diff --git a/src/game.cpp b/src/game.cpp index 2e7031d..a1e4559 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -5,6 +5,8 @@ #include "components/collider.h" #include "components/tilemap.h" #include "components/player.h" +#include "components/mover.h" +#include "assets/sprite.h" #include "factory.h" using namespace TL; @@ -27,11 +29,11 @@ void Game::startup() m_draw_colliders = false; // load first room - load_room(Point(0, 0)); + load_room(Point(10, 0)); camera = Vec2(room.x * width, room.y * height); } -void Game::load_room(Point cell) +void Game::load_room(Point cell, bool is_reload) { const Image* grid = Content::find_room(cell); BLAH_ASSERT(grid, "Room doesn't exist!"); @@ -94,7 +96,7 @@ void Game::load_room(Point cell) // player (only if it doesn't already exist) case 0x6abe30: if (!world.first()) - Factory::player(&world, world_position); + Factory::player(&world, world_position + (is_reload ? Point(0, -16) : Point::zero)); break; // brambles @@ -111,6 +113,16 @@ void Game::load_room(Point cell) case 0xfbf236: Factory::mosquito(&world, world_position + Point(0, -8)); break; + + // door + case 0x9badb7: + Factory::door(&world, world_position); + break; + + // blob + case 0x3f3f74: + Factory::blob(&world, world_position); + break; } } } @@ -152,7 +164,7 @@ void Game::update() if (pos.y < 0) next_room.y--; // see if room exists - if (Content::find_room(next_room)) + if (player->health > 0 && Content::find_room(next_room)) { Time::pause_for(0.1f); @@ -185,10 +197,24 @@ void Game::update() if (player->entity()->position.y > bounds.y + bounds.h + 64) { world.clear(); - load_room(room); + load_room(room, true); } } } + + // death ... delete everything except the player + // then when they fall out of the screen, we reset + if (player->health <= 0) + { + Entity* e = world.first_entity(); + while (e) + { + auto next = e->next(); + if (!e->get()) + world.destroy_entity(e); + e = next; + } + } } } // Room Transition routine @@ -207,6 +233,14 @@ void Game::update() // Finish Transition if (m_next_ease >= 1.0f) { + // boost player on vertical up rooms + if (m_next_room.y < m_last_room.y) + { + auto player = world.first(); + if (player) + player->get()->speed = Vec2(100, -200); + } + // delete old objects (except player!) for (auto& it : m_last_entities) { @@ -226,9 +260,13 @@ void Game::render() { buffer->clear(0x150e22); + // push camera offset batch.push_matrix(Mat3x2::create_translation(-camera)); + + // draw gameplay objects world.render(batch); + // draw debug colliders if (m_draw_colliders) { auto collider = world.first(); @@ -239,7 +277,31 @@ void Game::render() } } + // end camera offset batch.pop_matrix(); + + // draw the health + auto player = world.first(); + if (player) + { + auto hearts = Content::find_sprite("heart"); + auto full = hearts->get_animation("full"); + auto empty = hearts->get_animation("empty"); + + Point pos = Point(0, height - 16); + batch.rect(Rect(pos.x, pos.y + 7, 40, 4), Color::black); + + for (int i = 0; i < Player::max_health; i++) + { + if (player->health >= i + 1) + batch.tex(full->frames[0].image, pos); + else + batch.tex(empty->frames[0].image, pos); + pos.x += 12; + } + } + + // draw to the gameplay buffer batch.render(buffer); batch.clear(); } diff --git a/src/game.h b/src/game.h index 6df38a2..d6a4c1c 100644 --- a/src/game.h +++ b/src/game.h @@ -22,7 +22,7 @@ namespace TL Point room; Vec2 camera; - void load_room(Point cell); + void load_room(Point cell, bool is_reload = false); void startup(); void shutdown(); void update();