1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
#include <stdint.h>
#include <stdlib.h>
#include "gba.h"
// A class with variables for the characters.
class CHARBOX
{
public:
int init_;
int str_;
int health_;
int posx_;
int posy_;
int width_;
int height_;
int colour_;
public:
// Constructor.
CHARBOX(int posx, int posy, int width, int height, int colour)
: init_(0), str_(0), health_(0), posx_(posx), posy_(posy),
width_(width), height_(height), colour_(colour)
{
DrawBox();
}
// Drawing functions.
void DrawBox()
{
for (int x = posx_; x < posx_ + width_; x++)
{
for (int y = posy_; y < posy_ + height_; y++)
{
PlotPixel8(x, y, colour_);
}
}
}
};
// The entry point for the game.
int main()
{
// Put the display into bitmap mode 4, and enable background 2.
REG_DISPCNT = MODE4 | BG2_ENABLE;
// Defining some colour palettes.
SetPaletteBG(1, RGB(90,0,0));
SetPaletteBG(2, RGB(0,90,0));
SetPaletteBG(3, RGB(0,0,90));
SetPaletteBG(4, RGB(90,90,0));
SetPaletteBG(5, RGB(90,0,90));
// Draw the player dude-box at a starting location.
CHARBOX player(10, 24, 6, 8, 1);
// Draw the enemy dude-box at a starting location.
CHARBOX enemy(80, 24, 6, 8, 2);
while (true);
{
// Flip buffers to smoothen the drawing.
void FlipBuffers(); // This is just a default GBA function.
// Clear screen and paint background.
ClearScreen8(1); // And so is this.
// Redraw the player dude-box.
if ((REG_KEYINPUT & KEY_LEFT) == 0)
{
player.posx_--;
player.DrawBox();
}
if ((REG_KEYINPUT & KEY_RIGHT) == 0)
{
player.posx_++;
player.DrawBox();
}
if ((REG_KEYINPUT & KEY_UP) == 0)
{
player.posy_--;
player.DrawBox();
}
if ((REG_KEYINPUT & KEY_DOWN) == 0)
{
player.posy_++;
player.DrawBox();
}
WaitVSync();
}
return 0;
}
|