...
 
Commits (6)
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
/*
MicroTD - Tower Defense Game for Arduboy
/**
@file microtd.ino
@author Miloslav Ciz
@brief tower defense game for Arduboy
MicroTD - Tower Defense Game for Arduboy
version: 1.1
version: 1.2
Miloslav "drummyfish" Ciz, 2018, license: CC0 (public domain)
Miloslav "drummyfish" Ciz, 2018, license: CC0 (public domain)
This file can be compiled both with Arduino IDE for the final release, or
with gcc (or maybe even other compiler) for quick debug/tests on the PC.
This file can be compiled both with Arduino IDE for the final release, or
with gcc (or maybe even other compiler) for quick debug/tests on the PC.
*/
#ifdef ARDUINO
......@@ -123,6 +127,9 @@
#define UPGRADE_DAMAGE_FRACTION_INCREASE 2 /**< Fractional increase (+ 1/x) of
damage by upgrade. */
#define CHEAT_NONE 0
#define CHEAT_MONEY 1
#define STATE_MENU 0 ///< In main menu.
#define STATE_PLAYING_MENU 1 ///< In game, game menu open.
#define STATE_PLAYING_BUILDING 2 ///< In game, building stage.
......@@ -853,7 +860,7 @@ protected:
if (!canAttack(c->getTypeIndex()))
return;
if (c->hit(getDamage() / (splash ? 2 : 1), getTypeIndex() == TOWER_ICE ||
if (c->hit(getDamage() / (splash ? 2 : 1), (getTypeIndex() == TOWER_ICE) ||
(hasUpgraded(UPGRADE_SHOCK) && (rand() % 3) == 0)))
{
*money += c->getType().mReward;
......@@ -1430,6 +1437,7 @@ struct Game
Spawner3 mSpawner3;
Spawner4 mSpawner4;
byte mCheat;
byte mMapNumber;
PlayGround mPlayground;
......@@ -1457,6 +1465,7 @@ struct Game
mFrame = 0;
mCreepCount = 0;
mSelectedMenuItem = 0;
mCheat = CHEAT_NONE;
mSound = false;
......@@ -1575,6 +1584,7 @@ struct Game
mCursor.mX = 8;
mCursor.mY = 4;
mSelectedMenuItem = 0;
srand(0); // make the game deterministic
mState = STATE_PLAYING_BUILDING;
}
......@@ -1649,7 +1659,7 @@ struct Game
Tile *tile = mPlayground.getTile(mCursor);
byte cost = tile->mTower.getType().getUpgrageCost();
if (mMoney >= cost)
if (mMoney >= cost || mCheat == CHEAT_MONEY)
{
mPlayground.getTile(mCursor)->mTower.upgrade(
(mSelectedMenuItem == GAME_MENU_UPGRADE1) ? 0 : 1);
......@@ -1692,7 +1702,7 @@ struct Game
TowerType tt = towerTypes[mSelectedMenuItem];
if (tt.mPrice > mMoney)
if (tt.mPrice > mMoney && mCheat != CHEAT_MONEY)
return false; // not enough money
// build the tower
......@@ -1835,7 +1845,7 @@ struct Game
)
result.mState = ITEM_STATE_UNAVAILABLE; // no upgrade 2 for big towers
if (result.mPrice > mMoney)
if (result.mPrice > mMoney && mCheat != CHEAT_MONEY)
result.mState = ITEM_STATE_UNAVAILABLE;
byte pos = 0;
......@@ -2259,6 +2269,12 @@ void drawMenu()
arduboy.setTextBackground(WHITE);
arduboy.setCursor(2,55);
arduboy.print(item.mSubText);
if (game.mCheat != CHEAT_NONE && (game.mFrame / 4) % 2 == 0)
{
arduboy.setCursor(47,26);
arduboy.print(F("cheat!"));
}
}
void drawGameOver()
......@@ -2512,7 +2528,15 @@ void drawMap()
arduboy.setCursor(1,y);
arduboy.write('$');
arduboy.print(game.mMoney);
if (game.mCheat == CHEAT_MONEY)
{
arduboy.write('!');
arduboy.write('!');
arduboy.write('!');
}
else
arduboy.print(game.mMoney);
arduboy.setCursor(1 + 5 * 8,y);
arduboy.write('L');
......@@ -2649,9 +2673,14 @@ void handleInputs()
checkButton(DOWN_BUTTON);
#undef checkButton
// cheat
if (arduboy.pressed(UP_BUTTON) && arduboy.pressed(B_BUTTON))
game.mCheat = arduboy.pressed(DOWN_BUTTON) ? CHEAT_MONEY : CHEAT_NONE;
}
bool recordWritten; ///< Helper for detecting records and writing to EEPROM.
bool recordWritten = false; ///< For detecting records and writing to EEPROM.
void setup()
{
......@@ -2663,8 +2692,6 @@ void setup()
arduboy.clear();
arduboy.setFrameRate(FRAMERATE);
recordWritten = false;
if (EEPROM.read(EEPROM_START) != EEPROM_VALID_VALUE)
{
// EEPROM not valid => initialize it
......