Skip to content

Commit

Permalink
tests/pong: Make player and ball graphics handling more generic
Browse files Browse the repository at this point in the history
  • Loading branch information
JPTIZ committed Jan 6, 2024
1 parent 434211c commit 58e18ff
Show file tree
Hide file tree
Showing 7 changed files with 231 additions and 163 deletions.
4 changes: 2 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ SpaceAroundPointerQualifiers: Default
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeCtorInitializerColon: false
SpaceBeforeInheritanceColon: false
SpaceBeforeParens: ControlStatements
SpaceBeforeParensOptions:
AfterControlStatements: true
Expand Down
1 change: 1 addition & 0 deletions .clangd
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ CompileFlags:
-I/opt/devkitpro/devkitARM/arm-none-eabi/include,
-I/opt/devkitpro/devkitARM/arm-none-eabi/include/c++/13.2.0/arm-none-eabi/,
]
Remove: [-mthumb-interwork]
36 changes: 15 additions & 21 deletions libgba-cpp/engine/graphics/bitmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,23 @@

#include <libgba-cpp/engine/graphics/tilemap.h>


namespace gba::graphics {


class PalettedBitmap {
public:
PalettedBitmap(
int width,
int height,
const Palette& palette);
PalettedBitmap(int width, int height, const Palette& palette);

PalettedBitmap(
int width,
int height,
const Palette& palette,
uint8_t data[]
int width,
int height,
const Palette& palette,
uint8_t data[]
):
width_{width},
height_{height},
palette_{palette},
data_{data}
{}
data_{data} {
}

auto width() const {
return width_;
Expand All @@ -51,19 +46,19 @@ class PalettedBitmap {
const uint8_t* data_;
};


class TiledBitmap {
public:
TiledBitmap(
int width,
int height,
const Tileset& tileset,
const Tilemap& tilemap):
int width,
int height,
const Tileset& tileset,
const Tilemap& tilemap
):
width_{width},
height_{height},
tileset_{tileset},
tilemap_{tilemap}
{}
tilemap_{tilemap} {
}

auto tileset() const {
return tileset_;
Expand All @@ -88,7 +83,6 @@ class TiledBitmap {
const Tilemap& tilemap_;
};


}
} // namespace gba::graphics

#endif
47 changes: 47 additions & 0 deletions libgba-cpp/engine/map/objects.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#ifndef LIBGBA_ENGINE_MAPOBJECTS_H
#define LIBGBA_ENGINE_MAPOBJECTS_H

#include "libgba-cpp/utils/geometry.h"
namespace gba::map {

/**
* For bitmaps with a custom drawing routine.
*/
class BitmapModeObject {
using DrawFunction =
void (*)(BitmapModeObject const&);

public:
BitmapModeObject(gba::geometry::Point const& position, gba::geometry::Size size, DrawFunction draw_function):
_position{position},
_size{size},
draw_function{draw_function} {
}

auto draw() const -> void {
draw_function(*this);
}

auto position() -> gba::geometry::Point& {
return _position;
}

auto position() const -> gba::geometry::Point const& {
return _position;
}

auto size() const -> gba::geometry::Size const& {
return _size;
}

private:
gba::geometry::Point _position;
gba::geometry::Size _size;

DrawFunction draw_function;
};


}

#endif
9 changes: 9 additions & 0 deletions libgba-cpp/utils/general.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define GBA_UTILS_GENERAL_H

#include <type_traits>
#include <random>

/**
* General C++ Utilities.
Expand All @@ -17,6 +18,14 @@ constexpr auto value_of(Enum e)
return static_cast<std::underlying_type_t<Enum>>(e);
}

inline auto random() -> int {
static auto gen = std::mt19937{std::random_device{}()};
static auto distrib = std::uniform_int_distribution<>{1, 1500};

return distrib(gen);
}


}

#endif
Loading

0 comments on commit 58e18ff

Please sign in to comment.