285 lines
4.3 KiB
C++
285 lines
4.3 KiB
C++
#include <Backlight.h>
|
|
#include <Battery.h>
|
|
#include <Buttons.h>
|
|
#include <Display.h>
|
|
#include <Gamebuino.h>
|
|
#include <Sound.h>
|
|
#include <SPI.h>
|
|
|
|
#define POPULATION_LIMIT 20
|
|
#define PEASANT_HEALTH 25
|
|
|
|
Gamebuino gb;
|
|
unsigned long int global_timer;
|
|
|
|
class Unit
|
|
{
|
|
public:
|
|
Unit();
|
|
~Unit();
|
|
inline short GetX(void){return _x;}
|
|
inline short GetY(void){return _y;}
|
|
inline const byte * GetSprite(void){return _sprite;}
|
|
|
|
protected:
|
|
unsigned char _health;
|
|
unsigned char _team;
|
|
unsigned char _strength;
|
|
unsigned char _armor;
|
|
bool _walking;
|
|
bool _direction;
|
|
short _x;
|
|
short _y;
|
|
const byte * _sprite;
|
|
};
|
|
|
|
class Peasant: public Unit
|
|
{
|
|
public:
|
|
Peasant(short x, short y);
|
|
~Peasant();
|
|
|
|
private:
|
|
};
|
|
|
|
class Team
|
|
{
|
|
public:
|
|
Team(unsigned char number);
|
|
~Team();
|
|
void IncreasePopulation(void);
|
|
inline bool LimitReached(void){return _limit_reached;}
|
|
template <class T>
|
|
T *createUnit(short x, short y);
|
|
inline int GetPopulation(void){return _unitArrayIterator;}
|
|
Unit * GetUnit(int i){return _unitArray[i];}
|
|
|
|
private:
|
|
Unit * _unitArray[POPULATION_LIMIT];
|
|
unsigned char _team_number;
|
|
int _unitArrayIterator;
|
|
bool _limit_reached;
|
|
|
|
};
|
|
|
|
const byte BarracksSpr[] PROGMEM = {24,24,
|
|
0xE7,0x0,0xE7,
|
|
0xBD,0x0,0xBD,
|
|
0xE7,0xFF,0xE7,
|
|
0xBD,0x0,0xBD,
|
|
0x81,0xFF,0x81,
|
|
0xE7,0x0,0xE7,
|
|
0xA5,0x0,0xA5,
|
|
0xBD,0xFF,0xBD,
|
|
0xA5,0x0,0xA5,
|
|
0xA5,0x0,0xA5,
|
|
0xA5,0x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10,
|
|
0x8,0x10,
|
|
0x8,0x10,
|
|
0x8,0x10,
|
|
0x9,0x90,
|
|
0x9,0x90,
|
|
0x8,0x10,
|
|
0x8,0x10,
|
|
0x8,0x10,
|
|
0x8,0x10,
|
|
0x8,0x10,
|
|
0xB,0xD0,
|
|
0xA,0x50,
|
|
0xA,0x50,
|
|
0xF,0xF0,
|
|
};
|
|
|
|
const byte Peasant_UpDownSpr[] PROGMEM = {8,6,
|
|
0x3C,
|
|
0x42,
|
|
0x99,
|
|
0xA5,
|
|
0x66,
|
|
0x18,
|
|
};
|
|
|
|
const byte Peasant_Walking_UpDownSpr[] PROGMEM = {8,8,
|
|
0x2,
|
|
0x1D,
|
|
0x67,
|
|
0xA5,
|
|
0x99,
|
|
0xC2,
|
|
0xBC,
|
|
0x60,
|
|
};
|
|
|
|
const byte Peasant_LeftRightSpr[] PROGMEM = {8,8,
|
|
0x30,
|
|
0x48,
|
|
0x64,
|
|
0x94,
|
|
0x94,
|
|
0x64,
|
|
0x48,
|
|
0x30,
|
|
};
|
|
|
|
Team::Team(unsigned char number)
|
|
{
|
|
_team_number = number;
|
|
_unitArrayIterator = 0;
|
|
_limit_reached = false;
|
|
}
|
|
|
|
Team::~Team(void)
|
|
{
|
|
|
|
|
|
}
|
|
|
|
Team Player(0);
|
|
|
|
Unit::Unit(void)
|
|
{
|
|
|
|
}
|
|
|
|
Unit::~Unit(void)
|
|
{
|
|
|
|
}
|
|
|
|
void Team::IncreasePopulation(void)
|
|
{
|
|
_unitArrayIterator++;
|
|
|
|
if(_unitArrayIterator >= POPULATION_LIMIT)
|
|
{
|
|
_limit_reached = true;
|
|
}
|
|
}
|
|
|
|
template <class T>
|
|
T* Team::createUnit(short x, short y)
|
|
{
|
|
T* ptr = new T(x,y);
|
|
|
|
_unitArray[_unitArrayIterator] = ptr;
|
|
IncreasePopulation();
|
|
return ptr;
|
|
}
|
|
|
|
Peasant::Peasant(short x, short y)
|
|
{
|
|
_health = PEASANT_HEALTH;
|
|
_armor = 0;
|
|
_x = x;
|
|
_y = y;
|
|
_sprite = Peasant_UpDownSpr;
|
|
}
|
|
|
|
Peasant::~Peasant(void)
|
|
{
|
|
|
|
}
|
|
|
|
void setup()
|
|
{
|
|
// put your setup code here, to run once:
|
|
gb.begin();
|
|
gb.titleScreen(F("Pocket Empires"));
|
|
|
|
global_timer = 0;
|
|
}
|
|
|
|
void loop()
|
|
{
|
|
// put your main code here, to run repeatedly:
|
|
if(gb.update() )
|
|
{
|
|
/*gb.display.drawBitmap(x,y,bitmap,rotation,flip);*/
|
|
gb.display.drawBitmap(7,0,BarracksSpr);
|
|
gb.display.drawBitmap(32,0,TowerSpr);
|
|
|
|
gb.display.setColor(GRAY, WHITE);
|
|
gb.display.drawBitmap(0,0,BarracksShadowSpr);
|
|
gb.display.setColor(BLACK, WHITE);
|
|
|
|
/*if(global_timer & 1)
|
|
{
|
|
gb.display.drawBitmap(0,0,BarracksShadowSpr);
|
|
}*/
|
|
|
|
if(gb.buttons.pressed(BTN_B) == true)
|
|
{
|
|
Player.createUnit<Peasant>(rand() % 20,rand() % 20);
|
|
}
|
|
|
|
for(int i = 0; i < Player.GetPopulation() ; i++)
|
|
{
|
|
gb.display.drawBitmap(Player.GetUnit(i)->GetX(), Player.GetUnit(i)->GetY(),Player.GetUnit(i)->GetSprite() );
|
|
}
|
|
// gb.display.println(F("Hello World!"));
|
|
|
|
global_timer++;
|
|
}
|
|
}
|