Labyrinth of the Minotaur A simple roguelike/RPG using a nokia 5110 screen

Dependencies:   N5110 PowerControl mbed

Game.h

Committer:
ThomasBGill
Date:
2015-05-10
Revision:
32:99ca304085e6
Parent:
31:5b4a4d225ab4
Child:
33:4fc26476b2e0

File content as of revision 32:99ca304085e6:

#include "N5110.h"
#include "PowerControl/PowerControl.h"
#include "PowerControl/EthernetPowerControl.h"
#include "WorldBuilder.h"
#include "Graphics.h"

//        vcc sce rst dc  mosi clk  led
N5110 lcd(p7, p8, p9, p10, p11, p13, p26);
InterruptIn Act(p27);
InterruptIn Start(p28);
AnalogIn Noise(p19);
AnalogIn xPot(p15);
AnalogIn yPot(p16);

#define PH_MAX 20

//Joystick stuff
// timer to regularly read the joystick
Ticker pollJoystick;

// change this to alter tolerance of joystick direction
#define DIRECTION_TOLERANCE 0.05

// create enumerated type (0,1,2,3 etc. for direction)
// could be extended for diagonals etc.
enum DirectionName {
    Up,
    Down,
    Left,
    Right,
    Centre,
    Unknown
};
 
// struct for Joystick
typedef struct JoyStick Joystick;
struct JoyStick {
    float x;    // current x value
    float x0;   // 'centred' x value
    float y;    // current y value
    float y0;   // 'centred' y value
    int button; // button state (assume pull-down used, so 1 = pressed, 0 = unpressed)
    DirectionName direction;  // current direction
};
// create struct variable
Joystick joystick;

// function prototypes
void calibrateJoystick();
void updateJoystick();

#define USR_POWERDOWN (0x104)

LocalFileSystem local("local"); // create local filesystem

struct TILES {
    char    Symbol; // Symbol for this tile
    bool   Passable; // Can tile be walked on
};

TILES  TileList[] = {
    { '#', false },  // 0- WALL
    { '.', true },  // 1- FLOOR
    { '+', true }, // 2- ENTER
    { 'x', true },  // 3- EXIT
    { '.', true },  // 4- FLOOR_SEEN
    { '=', true },  // 5- CHEST
    { '/', true },  // 6- CHEST_OPENED
};

struct ITEMS {
    char  ItemName[15]; //Item name
    int ItemValue; //Damage/ armour value
};

ITEMS  ItemList[] = {
    //Weapons
    { "Dagger", 4 },  //0
    { "Axe", 5 },  //1
    { "Mace", 6 },  //2
    { "Sword", 7 },  //3
    { "Warhammer", 8 }, //4
    //Armour
    { "Cloth armour", 0 },  //5
    { "Leather armour", 1 },  //6
    { "Studded armour", 2 },  //7
    { "Chainmail vest", 3 }, //8
    { "Plate armour", 4 }, //9
};

struct ENEMIES {
    char  EName[9]; //Enemy name
    int   EHealth; //Enemy health
    int   EDamage; //Enemy damage
    int   EArmour; //Enemy armour
    int   EDodge; //Enemy dodge chance
    int   EHit; //Enemy hit chance
    int   ESpd; //Enemy speed (used for running away during fights)
    int   EPoints; //How many points the monster is worth
};

ENEMIES  EnemyList[] = {
    //Name          HP Dmg Arm  Dg  Ht  Spd  Pts
    { "Huge Rat",   5,  3,   0,  25, 70, 40,  1  }, //0- Huge Rat
    { "Goblin",     6,  3,   1,  25, 60, 30,  3  }, //1- Goblin
    { "Skeleton",   8,  4,   2,  10, 50, 10,  5  }, //2- Skeleton
    { "Wraith",     5,  4,   0,  40, 60, 50,  10 }, //3- Wraith
    { "Ogre",       10, 7,   3,  10, 35, 15,  15 }, //4- Ogre
    { "Minotaur",   15, 8,   4,  20, 45, 100, 50 }, //5- Minotaur
};

//Variables
int ActFlag = 0;
int StartFlag = 0;
//int DirFlag = 0;

//Space type player is on
int pSpace;

//Player Health
int ph = PH_MAX;

//Player weapon
int pw = 0; //0 to 4

//Player armour
int pa = 5; //5 to 9

//Player score
int score = -100; //100 level, x monster, 10 chest, -2 running away

//High scores
int HScore1;
int HScore2;
int HScore3;
int HScore4;

bool BossFight = false;

//Voids
int semihost_powerdown();

void ActPressed();
void StartPressed();
//void DirPressed();

void writeDataToFile();
void readDataFromFile();
void HighScoreCheck();

void FlashScreen();
void DrawGraphic(int p, int x, int y);

void Intro();
void MainMenu();
void Options();
void LevelScreen();
void GameLoop();
void PlayerCamera();
void PlayerMove();
void Fight();
void MonsterAttack(int m);
void StartMenu();
void Map();
void DrawMap();
void FlashPlayerLocation();
void MapLegend();
void Inventory();
void Chest();
void getItem();
void BoobyTrap();
void RevealMap();
void Potion();
void GameOver();
void ScoreScreen();
void HighScoreScreen();