Skip to content

Commit

Permalink
add dashers, refactor some stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
evanbowman committed Jul 19, 2019
1 parent ac4dacc commit dcc28fc
Show file tree
Hide file tree
Showing 17 changed files with 865 additions and 258 deletions.
12 changes: 6 additions & 6 deletions source/bgr_spritesheet.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

//======================================================================
//
// bgr_spritesheet, 1088x32@4,
// bgr_spritesheet, 2048x32@4,
// Transparent color : FF,00,FF
// + palette 256 entries, not compressed
// + 544 tiles Metatiled by 2x4 not compressed
// Total size: 512 + 17408 = 17920
// + 1024 tiles Metatiled by 2x4 not compressed
// Total size: 512 + 32768 = 33280
//
// Time-stamp: 2019-07-18, 19:43:05
// Time-stamp: 2019-07-19, 07:11:16
// Exported by Cearn's GBA Image Transmogrifier, v0.8.15
// ( http://www.coranac.com/projects/#grit )
//
Expand All @@ -18,8 +18,8 @@
#ifndef GRIT_BGR_SPRITESHEET_H
#define GRIT_BGR_SPRITESHEET_H

#define bgr_spritesheetTilesLen 17408
extern const unsigned int bgr_spritesheetTiles[4352];
#define bgr_spritesheetTilesLen 32768
extern const unsigned int bgr_spritesheetTiles[8192];

#define bgr_spritesheetPalLen 512
extern const unsigned short bgr_spritesheetPal[256];
Expand Down
950 changes: 745 additions & 205 deletions source/bgr_spritesheet.s

Large diffs are not rendered by default.

11 changes: 5 additions & 6 deletions source/collision.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@

void check_collisions(CollisionSpace& input)
{
for (auto c : input) {
for (auto o : input) {
if (o not_eq c) {
// TODO: if overlapping...
// c->initiate_collision(*o);
}
const auto count = input.size();
for (u32 i = 0; i < count; ++i) {
for (u32 j = i + 1; j < count; ++j) {
// ...
}
}

}
1 change: 0 additions & 1 deletion source/collision.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "buffer.hpp"


class ItemChest;
class Critter;
class Turret;
class Player;
Expand Down
37 changes: 37 additions & 0 deletions source/dasher.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include "dasher.hpp"
#include "game.hpp"


Dasher::Dasher(const Vec2<Float>& position)
{
position_ = position;

sprite_.set_texture_index(TextureMap::dasher_idle);
sprite_.set_size(Sprite::Size::w16_h32);
sprite_.set_origin({8, 16});

head_.set_texture_index(TextureMap::dasher_head);
head_.set_size(Sprite::Size::w16_h32);
head_.set_origin({8, 32});

shadow_.set_texture_index(TextureMap::drop_shadow);
shadow_.set_size(Sprite::Size::w16_h32);
shadow_.set_origin({8, -9});
shadow_.set_alpha(Sprite::Alpha::translucent);
}


void Dasher::update(Platform&, Game& game, Microseconds dt)
{
sprite_.set_position(position_);
shadow_.set_position(position_);
head_.set_position({position_.x, position_.y - 9});

if (game.get_player().get_position().x > position_.x) {
sprite_.set_flip({1, 0});
head_.set_flip({1, 0});
} else {
sprite_.set_flip({0, 0});
head_.set_flip({0, 0});
}
}
24 changes: 17 additions & 7 deletions source/dasher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,28 @@
#include "sprite.hpp"


class Game;
class Platform;


class Dasher : public Entity<Dasher, 20>, public CollidableTemplate<Dasher> {
public:
Dasher()
Dasher(const Vec2<Float>& position);

void update(Platform&, Game&, Microseconds);

const Sprite& get_shadow() const
{
sprite_.set_texture_index(0); // FIXME
return shadow_;
}

void update(Platform&, Game&, Microseconds)
static constexpr bool multiface_sprite = true;

std::array<const Sprite*, 2> get_sprites() const
{
std::array<const Sprite*, 2> ret;
ret[0] = &sprite_;
ret[1] = &head_;
return ret;
}

private:
Sprite shadow_;
Sprite head_;
};
9 changes: 9 additions & 0 deletions source/entity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#include "sprite.hpp"


class Platform;
class Game;

class EntityBase {
public:
using Health = s32;
Expand All @@ -18,6 +21,10 @@ class EntityBase {

EntityBase(EntityBase&) = delete;

void update(Platform&, Game&, Microseconds)
{
}

Health get_health() const
{
return health_;
Expand All @@ -43,6 +50,8 @@ class EntityBase {
return position_;
}

static constexpr bool multiface_sprite = false;

protected:
void debit_health(Health amount)
{
Expand Down
33 changes: 25 additions & 8 deletions source/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,22 @@ void Game::update(Platform& pfrm, Microseconds delta)

enemies_.transform([&](auto& entity_buf) {
for (auto& entity : entity_buf) {
const auto& spr = entity->get_sprite();
if (within_view_frustum(pfrm.screen(), spr)) {
display_buffer.push_back(&spr);
shadows_buffer.push_back(&entity->get_shadow());
camera_.push_ballast(entity->get_position());
if constexpr (std::remove_reference<decltype(*entity)>::type::multiface_sprite) {
const auto sprs = entity->get_sprites();
if (within_view_frustum(pfrm.screen(), *sprs[0])) {
for (const auto& spr : sprs) {
display_buffer.push_back(spr);
}
shadows_buffer.push_back(&entity->get_shadow());
camera_.push_ballast(entity->get_position());
}
} else {
const auto& spr = entity->get_sprite();
if (within_view_frustum(pfrm.screen(), spr)) {
display_buffer.push_back(&spr);
shadows_buffer.push_back(&entity->get_shadow());
camera_.push_ballast(entity->get_position());
}
}
}
});
Expand Down Expand Up @@ -396,7 +407,7 @@ bool Game::respawn_entities(Platform& pfrm)
};

auto pos = [&](const MapCoord* c) {
return Vec2<Float>{static_cast<Float>(c->x * 32),
return Vec2<Float>{static_cast<Float>(c->x * 32) + 16,
static_cast<Float>(c->y * 24)};
};

Expand All @@ -416,7 +427,7 @@ bool Game::respawn_entities(Platform& pfrm)
}
}
const auto target = pos(farthest);
transporter_.set_position({target.x + 16, target.y + 16});
transporter_.set_position({target.x, target.y + 16});
free_spots.erase(farthest);
} else {
return false;
Expand All @@ -431,7 +442,13 @@ bool Game::respawn_entities(Platform& pfrm)
}

if (const auto c = select_coord()) {
enemies_.get<0>().push_back(make_entity<Turret>(pos(c)));
enemies_.get<1>().push_back(make_entity<Dasher>(pos(c)));
}

for (int i = 0; i < 2; ++i) {
if (const auto c = select_coord()) {
enemies_.get<0>().push_back(make_entity<Turret>(pos(c)));
}
}

return true;
Expand Down
2 changes: 1 addition & 1 deletion source/game.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Game {
return tiles_;
}

using EnemyGroup = EntityGroup<Turret>;
using EnemyGroup = EntityGroup<Turret, Dasher>;
using DetailGroup = EntityGroup<ItemChest>;
using EffectGroup = EntityGroup<>;

Expand Down
2 changes: 1 addition & 1 deletion source/itemChest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
ItemChest::ItemChest(const Vec2<Float>& pos) : state_(State::closed)
{
sprite_.set_size(Sprite::Size::w16_h32);
sprite_.set_position({pos.x + 16, pos.y});
sprite_.set_position({pos.x, pos.y});
sprite_.set_origin({8, 16});
animation_.bind(sprite_);
}
Expand Down
4 changes: 0 additions & 4 deletions source/itemChest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
#include "entity.hpp"


class Game;
class Platform;


class ItemChest : public Entity<ItemChest, 4> {
public:
ItemChest(const Vec2<Float>& pos);
Expand Down
3 changes: 2 additions & 1 deletion source/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ Player::Player()
sprite_.set_size(Sprite::Size::w16_h32);
sprite_.set_origin({8, 16});
shadow_.set_origin({8, -9});
shadow_.set_texture_index(33);
shadow_.set_texture_index(TextureMap::drop_shadow);
shadow_.set_size(Sprite::Size::w16_h32);
shadow_.set_alpha(Sprite::Alpha::translucent);
}

Expand Down
8 changes: 4 additions & 4 deletions source/player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ class Player : public Entity<Player, 0>, public CollidableTemplate<Player> {
u32 frame_;
ResourceLoc frame_base_;
Microseconds anim_timer_;
float l_speed_;
float r_speed_;
float u_speed_;
float d_speed_;
Float l_speed_;
Float r_speed_;
Float u_speed_;
Float d_speed_;
Sprite shadow_;
u16 health_;
};
16 changes: 12 additions & 4 deletions source/sprite.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,19 @@ enum TextureMap : TextureIndex {
player_walk_down = 1,
player_walk_up = 6,
player_still_up = 11,
player_walk_left = 12,
player_still_left = 18,
player_walk_right = 19,
player_still_right = 25,
player_walk_left = 16,
player_still_left = 22,
player_walk_right = 23,
player_still_right = 29,
transporter = 15,
item_chest = 12,
turret = 18,
turret_shadow = 23,
dasher_idle = 24,
dasher_crouch = dasher_idle + 1,
dasher_dash = dasher_crouch + 1,
dasher_weapon1 = dasher_dash + 1,
dasher_weapon2 = dasher_weapon1 + 1,
dasher_head = dasher_weapon2 + 1,
drop_shadow = 60,
};
7 changes: 1 addition & 6 deletions source/transporter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Transporter : public Entity<Transporter, 0> {
public:
Transporter()
{
sprite_.set_texture_index(32);
sprite_.set_texture_index(TextureMap::transporter);
sprite_.set_origin({16, 22});
}

Expand All @@ -21,9 +21,4 @@ class Transporter : public Entity<Transporter, 0> {
Entity::set_position(new_pos);
sprite_.set_position(new_pos);
}

void update(Platform&, Game&, Microseconds)
{
// ...
}
};
4 changes: 0 additions & 4 deletions source/turret.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
#include "entity.hpp"


class Game;
class Platform;


class Turret : public Entity<Turret, 6>, public CollidableTemplate<Turret> {
public:
Turret(const Vec2<Float>& pos);
Expand Down
Binary file modified spritesheet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit dcc28fc

Please sign in to comment.