A WIP Roguelike game by Adekto, VonBednat, Trelemar and Wuuff made for CGAJam in spring 2017

Dependencies:   PokittoLib

Fork of Arcade by Pokitto Community Team

Revision:
10:590a26231903
Parent:
6:7e55f4fd3e4e
Child:
15:67fb7b0c1149
--- a/main.cpp	Wed Oct 18 20:20:53 2017 +0000
+++ b/main.cpp	Thu Oct 19 08:43:47 2017 +0000
@@ -1,975 +1,301 @@
-//#include <iostream>
+#include "Pokitto.h"
+#include <vector>
 #include <string>
-#include <stdlib.h>
-#include "Pokitto.h"
-#include "PokittoFonts.h"
+#include "sprites.h"
+
+#include "mapgen.c"
+#include "classes.cpp"
+
+#define SEED 344 //Change this value for unique map every time. Hoping for RTC on Hardware!
+
+bool solids[255];
 
-//create game object
+char dungeon[MAPSIZE][MAPSIZE];
+int dungeonSize = 16;//Starting dungeon size, which increases each level
+int dungeonDepth = 1;//Which floor the player is on
+
+bool solid(char map[][MAPSIZE],int x, int y){
+    return solids[map[y][x]];
+}
+
+void init_solids(){
+    for( int i = 1; i <= ID_COFFIN_OPEN_BOTTOM; i++ )
+        solids[i]=true;
+}
+
 Pokitto::Core game;
 
-//include textures
-#include <textures.h>
+int playerX = 1;
+int playerY = 2;
+
+
+void Ent::draw(){ //Classes are not implemented yet. This wont work either
+    game.display.drawBitmap(playerX-x*14,playerY-y*14,sprites[id]);
+}
+
+#define MAP_TILES 0
+#define ITEM_TILES (MAP_TILES + 34)
+#define ENTITY_TILES (ITEM_TILES + 36)
+
+#define ID_PLAYER            ENTITY_TILES + 2
 
-//variable declarations
-short gameMode = -2; //-2 = title, -1 = settings, 0 = menu, 1 = pong, 2 = breakout, 3 = snake, 4 = stacker, 5 = columns
-unsigned int paddleA = 36;
-unsigned int paddleB = 36;
-unsigned int paddleBr = 46;
-int paddleBMotion = 0;
-int ballX = 52;
-int ballY = 42;
-float ballSpeed = 1.0f;
-int bricksHit = 0;
-int ballXR;
-int ballYR;
-short ballDX = 1;
-short ballDY = 1;
-int RNG = rand() % 100 + 1;
-int RNGX = rand() % 25 + 1;
-int RNGY = rand() % 18 + 1;
-int difficulty = 70;
-unsigned int scoreA = 0;
-unsigned int scoreB = 0;
-unsigned int scoreBr = 0;
-unsigned short breakoutGrid [13][5]; //0=air, 1=redWide1, 2=redWide2, 3=yellowWide1, 4=yellowWide2, 5=greenWide, 6=cyanWide, 7=blueWide
-bool secondLevel = false;
-unsigned int lives = 3;
-short gameMap [27][22]; //0 = air, -1 = wall, -2 = food, 1 = snake head, 2 = snake body
-short snakeLength = 3;
-short headX = 13;
-short headY = 10;
-short direction = 0; //0 = up, 1 = right, 2 = down, 3 = left
-bool snakeUpdate = false;
-bool foodPlacementSuccess = false;
-short counter = 0;
-bool snakeInitializing = true;
-int breakoutHS = 0;
-int snakeHS = 0;
-unsigned short blockX = 0;
-unsigned short blockSize = 4;
-short blockDir = 1;
-short blockH = 0;
-short oldBlockData [20][2];
-short blockHOffset = 0;
-short blockLoss = 0;
-short blockMove = 0;
-bool stackLost = false;
-int stackerScore = 0;
-int stackerHS = 0;
-int stackerDelay = 3;
-short menuSelection = 1;
-bool grayscale = false;
-short optionSelection = 1;
-bool bsound = true;
-double timeTime = 0.0;
-/*short currentColumn [3];
-short currentColumnDupe [3];
-short nextColumn [3];
-short columnsMap [9][22];*/
-void resetPongValues() {
-    ballX = 52;
-    ballY = 42;
-    paddleBMotion = 0;
-    paddleA = 36;
-    paddleB = 36;
-    ballDX = 1;
-    ballDY = 1;
-}
-void pongLogic() {
-    //update difficulty
-    difficulty = 70 + 2.5*(scoreA - scoreB);
-    //input, move paddle 1
-    if (game.buttons.repeat(BTN_UP,0) && paddleA > 0) {
-        paddleA -= 2;
-    }
-    if (game.buttons.repeat(BTN_DOWN,0) && paddleA < 66) {
-        paddleA += 2;
+#define ID_STAIRS_DOWN       MAP_TILES + 19
+#define ID_GOBLIN_WARRIOR    ENTITY_TILES + 5
+#define ID_GOBLIN_MAGE       ENTITY_TILES + 6
+#define ID_SKELETON_MAGE     ENTITY_TILES + 7
+#define ID_SKELETON_ARCHER   ENTITY_TILES + 8
+#define ID_SKELETON_WARIOR   ENTITY_TILES + 9
+#define ID_BLOOD_SKELETON    ENTITY_TILES + 10
+#define ID_BLOOD             ENTITY_TILES + 11
+#define ID_RAT               ENTITY_TILES + 4
+#define ID_SCROLL            ITEM_TILES + 3
+#define ID_CHEST             ENTITY_TILES + 12
+#define ID_CHEST_OPEN        ENTITY_TILES + 13
+#define ID_MIMIC             ENTITY_TILES + 14
+#define ID_COIN              ITEM_TILES
+#define ID_COINS             ITEM_TILES + 1
+#define ID_BAG               ITEM_TILES + 2
+
+#define StateGame  0
+#define StateMenu  1
+#define StateIntro 2
+#define StateDead  3
+
+void addDescent(char map[][MAPSIZE]){
+    int x=random(1,dungeonSize-1);
+    int y=random(1,dungeonSize-1);
+    if (!solid(map,x,y) && !solid(map,x-1,y) && !solid(map,x+1,y) && !solid(map,x,y-1) && !solid(map,x,y+1)) {
+        map[y][x] = ID_STAIRS_DOWN;
     }
-    //move paddle 2
-    if (paddleBMotion == 0) {
-        if (ballY < paddleB + 8 && paddleB > 0) {
-            if (RNG < difficulty) {
-                paddleB -= 1;
-                paddleBMotion = -6;
-            } else {
-                paddleB += 1;
-                paddleBMotion = 6;
-            }
-        }
-        if (ballY > paddleB + 8 && paddleB < 66) {
-            if (RNG < difficulty) {
-                paddleB += 1;
-                paddleBMotion = 6;
-            } else {
-                paddleB -= 1;
-                paddleBMotion = -6;
-            }
-        }
-    } else if (paddleBMotion < 0) {
-        paddleBMotion++;
-        if (paddleB > 0)
-        paddleB -= 1;
-    } else if (paddleBMotion > 0) {
-        paddleBMotion--;
-        if (paddleB < 66)
-        paddleB += 1;
-    }
-    //fix paddle locations
-    if (paddleA < 0) {
-        paddleA = 0;
-    }
-    if (paddleB < 0) {
-        paddleB = 0;
-    }
-    if (paddleA > 66) {
-        paddleA = 66;
-    }
-    if (paddleB > 66) {
-        paddleB = 66;
-    }
-    //move ball
-    ballX += ballDX;
-    ballY += ballDY;
-    //bounce off walls
-    if (ballX <= 0) {scoreB++; resetPongValues(); if (bsound) game.sound.playOK();}
-    if (ballX >= 106) {scoreA++; resetPongValues(); if (bsound) game.sound.playOK();}
-    if (ballX <= 4 && ballY >= paddleA && ballY <= paddleA + 16) {
-        ballDX = 1;
-        if (bsound) game.sound.playTick();
-    }
-    if (ballX >= 102 && ballY >= paddleB && ballY <= paddleB + 16) {
-        ballDX = -1;
-        if (bsound) game.sound.playTick();
-    }
-    if (ballY <= 0 || ballY >= 78) {ballDY *= -1; if (bsound) game.sound.playTick();}
-}
-void pongDraw() {
-    //line
-    game.display.color = 2;
-    game.display.drawFastVLine(55,0,82);
-    game.display.color = 13;
-    game.display.drawFastVLine(56,0,82);
-    //paddles & ball
-    game.display.drawBitmap(0,paddleA,paddle1);
-    game.display.drawBitmap(106,paddleB,paddle1);
-    game.display.drawBitmap(ballX,ballY,gray);
-    //score
-    game.display.color = 2;
-    game.display.fillRectangle(0,82,110,6);
-    game.display.setFont(font3x5);
-    game.display.setCursor(50,83);
-    game.display.color = 15;
-    game.display.print(scoreA);
-    game.display.print("-");
-    game.display.print(scoreB);
-}
-void breakoutGridInit() {
-    //build basic grid by row
-    for (int x=0;x<13;x++) {
-        breakoutGrid[x][0] = 1;
-    }
-    for (int x=0;x<13;x++) {
-        breakoutGrid[x][1] = 3;
-    }
-    for (int x=0;x<13;x++) {
-        breakoutGrid[x][2] = 5;
-    }
-    for (int x=0;x<13;x++) {
-        breakoutGrid[x][3] = 6;
-    }
-    for (int x=0;x<13;x++) {
-        breakoutGrid[x][4] = 7;
+    else {
+        addDescent(map);
     }
 }
-void breakoutLogic() {
-    //input
-    if (game.buttons.repeat(BTN_LEFT,0) && paddleBr > 0) {
-        paddleBr -= 2;
-    }
-    if (game.buttons.repeat(BTN_RIGHT,0) && paddleBr < 94) {
-        paddleBr += 2;
-    }
-    //fix paddle position
-    if (paddleBr < 0) paddleBr = 0;
-    if (paddleBr > 94) paddleBr = 94;
-    //move ball, bounce off walls & paddle
-    ballX += ballDX * ballSpeed;
-    ballY += ballDY * ballSpeed;
-    if (ballX <= 0 || ballX >= 106) {ballDX *= -1; if (bsound) game.sound.playTick();}
-    if (ballY <= 0) {ballDY = 1; if (bsound) game.sound.playTick();}
-    if (ballY >= 78) {lives--; ballX = 52; ballY = 42; ballDX = 1; ballDY = 1; paddleBr = 46; if (bsound) game.sound.playCancel();}
-    if (ballY >= 74 && ballX >= paddleBr && ballX <= paddleBr + 16) {ballDY = -1; if (bsound) game.sound.playTick();}
-    //hiscore
-    if (scoreBr > breakoutHS) {
-        breakoutHS = scoreBr;
-    }
-    //reset game if lives out
-    if (lives == 0) {
-        scoreBr = 0; ballX = 52; ballY = 42; ballDX = 1; ballDY = 1; paddleBr = 46; lives = 3;
-        breakoutGridInit();
-    }
-    //check for brick collision
-    if (ballY <= 20) {
-        ballYR = ballY / 4;
-        if (ballYR % 2 == 0) {
-            ballXR = ballX / 8;
-        } else {
-            ballXR = (ballX - 4) / 8;
-        }
-        if (ballYR <= 4) {
-            switch (breakoutGrid[ballXR][ballYR]) {
-            case 0 :
-                break;
-            case 1 :
-                breakoutGrid[ballXR][ballYR] = 2;
-                ballDY *= -1;
-                scoreBr += 4;
-                bricksHit++;
-                if (ballSpeed <= 1.75f) {
-                    ballSpeed = 2.0f;
-                    if (bsound) game.sound.playOK();
-                } else {
-                    if (bsound) game.sound.playTick();
-                }
-                break;
-            case 2 :
-                breakoutGrid[ballXR][ballYR] = 0;
-                ballDY *= -1;
-                scoreBr += 4;
-                bricksHit++;
-                if (bsound) game.sound.playTick();
-                break;
-            case 3 :
-                breakoutGrid[ballXR][ballYR] = 4;
-                ballDY *= -1;
-                scoreBr += 3;
-                bricksHit++;
-                if (ballSpeed <= 1.5f) {
-                    ballSpeed = 1.75f;
-                    if (bsound) game.sound.playOK();
-                } else {
-                    if (bsound) game.sound.playTick();
-                }
-                break;
-            case 4 :
-                breakoutGrid[ballXR][ballYR] = 0;
-                ballDY *= -1;
-                scoreBr += 3;
-                bricksHit++;
-                if (bsound) game.sound.playTick();
-                break;
-            case 5 :
-                breakoutGrid[ballXR][ballYR] = 0;
-                ballDY *= -1;
-                scoreBr += 3;
-                bricksHit++;
-                if (bsound) game.sound.playTick();
-                break;
-            case 6 :
-                breakoutGrid[ballXR][ballYR] = 0;
-                ballDY *= -1;
-                scoreBr += 2;
-                bricksHit++;
-                if (bsound) game.sound.playTick();
-                break;
-            case 7 :
-                breakoutGrid[ballXR][ballYR] = 0;
-                ballDY *= -1;
-                scoreBr += 1;
-                bricksHit++;
-                if (bsound) game.sound.playTick();
-                break;
+
+//globals
+//std::vector<entity> entities(entities_size);
+struct entity{
+    uint8_t x;
+    uint8_t y;
+    int8_t hp;
+    uint8_t id;
+};
+#define ESIZE 2
+std::vector<entity> entities(ESIZE);
+std::vector<std::string> inventory;
+
+void removeEntity(int i){
+
+        using std::swap;
+         std::swap(entities[i], entities.back());
+    entities.pop_back();
+
+}
+
+void spawner(int amount){
+    entities.clear();
+    for(int i = 0; i < amount; i++ ){
+        entity spawn;
+        bool l = true;
+        int sx, sy;
+        while(l){
+            sx = rand()%dungeonSize;
+            sy = rand()%dungeonSize;
+            if(dungeon[sy][sx] == 0){
+                spawn.id = ENTITY_TILES+4+(rand()%16);//rand()%8+ENTITY_TILES+4;//Skip first few entities for now
+                spawn.x = sx;
+                spawn.y = sy;
+                spawn.hp = rand()%20;
+                entities.push_back(spawn);
+                l = false;
             }
         }
     }
-    //second level
-    if (scoreBr == 260 && !secondLevel) {
-        secondLevel = true;
-        paddleBr = 46;
-        ballX = 52;
-        ballY = 42;
-        ballDX = 1;
-        ballDY = 1;
-        breakoutGridInit();
-    }
-    //change speeds
-    if (ballSpeed == 1.0f && bricksHit == 4) {
-        ballSpeed = 1.25f;
-        if (bsound) game.sound.playOK();
-    } else if (ballSpeed <= 1.25f && bricksHit == 12) {
-        ballSpeed == 1.5f;
-        if (bsound) game.sound.playOK();
-    }
 }
-void breakoutDraw() {
-    //draw bricks
-    for(int y=0;y<5;y++) {
-        for(int x=0;x<13;x++) {
-            switch (breakoutGrid[x][y]) {
-            case 0 :
-                break;
-            case 1 :
-                if (y%2==0) {
-                game.display.drawBitmap(x*8 + 1,y*4,redWide1);
-                } else {
-                game.display.drawBitmap(x*8 + 5,y*4,redWide1);
-                }
-                break;
-            case 2 :
-                if (y%2==0) {
-                game.display.drawBitmap(x*8 + 1,y*4,redWide2);
-                } else {
-                game.display.drawBitmap(x*8 + 5,y*4,redWide2);
-                }
-                break;
-            case 3 :
-                if (y%2==0) {
-                    game.display.drawBitmap(x*8 + 1,y*4,yellowWide1);
-                } else {
-                    game.display.drawBitmap(x*8 + 5,y*4,yellowWide1);
-                }
-                break;
-            case 4 :
-                if (y%2==0) {
-                    game.display.drawBitmap(x*8 + 1,y*4,yellowWide2);
-                } else {
-                    game.display.drawBitmap(x*8 + 5,y*4,yellowWide2);
-                }
-                break;
-            case 5 :
-                if (y%2==0) {
-                    game.display.drawBitmap(x*8 + 1,y*4,greenWide);
-                } else {
-                    game.display.drawBitmap(x*8 + 5,y*4,greenWide);
-                }
-                break;
-            case 6 :
-                if (y%2==0) {
-                    game.display.drawBitmap(x*8 + 1,y*4,cyanWide);
-                } else {
-                    game.display.drawBitmap(x*8 + 5,y*4,cyanWide);
-                }
-                break;
-            case 7 :
-                if (y%2==0) {
-                    game.display.drawBitmap(x*8 + 1,y*4,blueWide);
-                } else {
-                    game.display.drawBitmap(x*8 + 5,y*4,blueWide);
-                }
-                break;
+
+
+char printer[40] = "";
+int playerGold = 0;
+int playerHP = 100;
+uint8_t GameState = StateIntro;
+uint8_t MenuSelector = 0;
+#include "gui.h"
+#include "crapai.h"
+using namespace std;
+int main () {
+init_solids();
+srand(SEED);
+mapinit(dungeon,dungeonSize,dungeonSize);
+mapgen(dungeon,dungeonSize,dungeonSize,0,0,dungeonSize-1,dungeonSize-1);
+mappretty(dungeon,dungeonSize,dungeonSize);
+addDescent(dungeon);
+std::vector<Ent> ents;
+inventory.push_back("adekto");
+inventory.push_back("trelemar");
+inventory.push_back("VonBednar");
+inventory.push_back("wuuff");
+Ent Etemp(3,3);
+ents.push_back(Etemp);
+game.begin();
+game.display.setFont(font5x7);
+game.sound.playMusicStream("COFFINS.SND");
+//mapgen(0,0,0,20,20);
+
+game.display.loadRGBPalette(paletteCGA);
+//game.display.setFont(fontAdventurer);
+//game.display.persistence = true;
+game.display.setInvisibleColor(0);
+
+spawner(ESIZE);
+/*entities[0].id = 12;
+entities[0].x = 5;
+entities[0].y = 5;
+entities[0].hp = rand()%20;*/
+
+uint8_t introspinner=0xFF;
+
+while (game.isRunning()) {
+
+    if (game.update()) {
+
+        if( GameState == StateIntro){
+            if (introspinner<85) {
+                game.display.setFont(fontAdventurer);
+                game.display.setCursor(game.display.getWidth()/4-16,36);
+                game.display.print("Columns & Coffins \n \n         A Pokitto Roguelike \n \n          PRESS A(z)");
+                game.display.setFont(font5x7);
+            } else if (introspinner>160) {
+                game.display.load565Palette(cnctitle_pal);
+                game.display.drawBitmap(0,0,cnctitle);
+            } else {
+                game.display.loadRGBPalette(paletteCGA);
+                game.display.drawBitmap(33,70,pokitteam);
+            }
+            if( game.buttons.held(BTN_A,0) ){
+                game.display.loadRGBPalette(paletteCGA);
+                GameState = StateGame;
+            }
+            introspinner--;
+            continue;
+        }
+
+        if( GameState == StateDead){
+            game.display.setFont(fontAdventurer);
+            game.display.setCursor(game.display.getWidth()/4,32);
+            char over[60];
+
+            sprintf(over,"Game Over \n \n   You died on floor %i \n \n   with %i gold",dungeonDepth,playerGold);
+            game.display.print(over);
+            //game.display.print(dungeonDepth);
+            //game.display.print("\n \n   You made it to year: ");
+            //game.display.print("ERR");//Not implemented
+            game.display.print("\n \n   PRESS A");
+            if( game.buttons.held(BTN_A,0) ){
+                GameState = StateIntro;
+                dungeonSize = 16;
+                dungeonDepth = 1;
+                playerHP = 100;
+                playerX = 1;
+                playerY = 2;
+                mapinit(dungeon,dungeonSize,dungeonSize);
+                mapgen(dungeon,dungeonSize,dungeonSize,0,0,dungeonSize-1,dungeonSize-1);
+                mappretty(dungeon,dungeonSize,dungeonSize);
+                addDescent(dungeon);
+                spawner(ESIZE);
+            }
+            game.display.setFont(font5x7);
+            continue;
+        }
+
+        //If the player is standing on stairs down, generate a new bigger map
+        if( dungeon[playerY][playerX] == ID_STAIRS_DOWN ){
+            if( dungeonSize + 2 < MAPSIZE ){ //As long as we aren't at maximum size
+                dungeonSize += 2;//Increase map x and y by 2
+            }
+            dungeonDepth++;
+            playerX = 1;
+            playerY = 2;
+            mapinit(dungeon,dungeonSize,dungeonSize);
+            mapgen(dungeon,dungeonSize,dungeonSize,0,0,dungeonSize-1,dungeonSize-1);
+            mappretty(dungeon,dungeonSize,dungeonSize);
+            addDescent(dungeon);
+            spawner(ESIZE);
+        }
+
+        if (game.buttons.held(BTN_C,0)){
+            //doing it this way since more context may happen
+            if(GameState == StateGame){
+                //game.display.rotatePalette(1);
+                GameState = StateMenu;
+            }
+            else if(GameState == StateMenu){
+              //game.display.rotatePalette(-1);
+              GameState = StateGame;
+              MenuSelector = 0;
+              isInventory = false;
             }
         }
-    }
-    //draw paddle & ball
-    game.display.drawBitmap(paddleBr,78,paddle2);
-    game.display.drawBitmap(ballX,ballY,gray);
-    //draw score
-    game.display.color = 2;
-    game.display.fillRectangle(0,82,110,6);
-    game.display.setFont(font3x5);
-    game.display.setCursor(1,83);
-    game.display.color = 15;
-    game.display.print("SCORE ");
-    game.display.print(scoreBr);
-    game.display.setCursor(37,83);
-    game.display.color = 15;
-    game.display.print("HISCORE ");
-    game.display.print(breakoutHS);
-    //draw HP
-    game.display.drawBitmap(97,84,gray);
-    game.display.setCursor(102,83);
-    game.display.print("x");
-    game.display.print(lives);
-}
-void snakePlaceFood() {
-    foodPlacementSuccess = false;
-    while (!foodPlacementSuccess) {
-        RNGX = rand() % 25 + 1;
-        RNGY = rand() % 18 + 1;
-        if (gameMap [RNGX][RNGY] == 0) {
-            gameMap [RNGX][RNGY] = -2;
-            foodPlacementSuccess = true;
-        }
-    }
-}
-void snakeGridInit() {
-    for (int y=0;y<20;y++) {
-        for (int x=0;x<27;x++) {
-            gameMap [x][y] = 0;
-        }
-    }
-    for (int y=0;y<22;y++) {
-        gameMap [0][y] = -1;
-        gameMap [26][y] = -1;
-    }
-    for (int x=0;x<27;x++) {
-        gameMap [x][0] = -1;
-        gameMap [x][19] = -1;
-    }
-    for (int i=0;i<snakeLength;i++) {
-    gameMap [13][10 + i] = 1 + i;
-    }
-    snakePlaceFood();
-    snakeInitializing = false;
-}
-void snakeInput() {
-    //input
-    if (game.buttons.held(BTN_UP,1) && direction != 2) {
-        direction = 0;
-    }
-    if (game.buttons.held(BTN_DOWN,1) && direction != 0) {
-        direction = 2;
-    }
-    if (game.buttons.held(BTN_RIGHT,1) && direction != 3) {
-        direction = 1;
-    }
-    if (game.buttons.held(BTN_LEFT,1) && direction != 1) {
-        direction = 3;
-    }
-}
-void snakeLogic() {
-    if (counter == 0) {
-        counter = 2;
-        //move
-        snakeUpdate = false;
-        gameMap [headX][headY] = 2;
-        if (direction == 0 && gameMap [headX][headY - 1] != -1 && gameMap [headX][headY - 1] < 2) {
-            headY--;
-            snakeUpdate = true;
-        } else if (direction == 1 && gameMap [headX + 1][headY] != -1 && gameMap [headX + 1][headY] < 2) {
-            headX++;
-            snakeUpdate = true;
-        } else if (direction == 2 && gameMap [headX][headY + 1] != -1 && gameMap [headX][headY + 1] < 2) {
-            headY++;
-            snakeUpdate = true;
-        } else if (direction == 3 && gameMap [headX - 1][headY] != -1 && gameMap [headX - 1][headY] < 2) {
-            headX--;
-            snakeUpdate = true;
-        }
-        //collision w/ food
-        if (gameMap [headX][headY] == -2) {
-            snakeLength += 1;
-            snakePlaceFood();
-            if (bsound) game.sound.playOK();
-        }
-        gameMap [headX][headY] = 1;
-        //destroy old snake bricks
-        for (int y=0;y<20;y++) {
-            for (int x=0;x<27;x++) {
-                if (snakeUpdate) {
-                    if (gameMap [x][y] >= snakeLength + 1) {
-                        gameMap [x][y] = 0;
-                    } else if (gameMap [x][y] >= 2) {
-                        gameMap [x][y] += 1;
-                    }
+        if(GameState == StateGame){
+            if( playerHP <= 0){
+                GameState = StateDead;
+                continue;
+            }
+
+            if (game.buttons.repeat(BTN_UP,4)){
+                if (!solids[dungeon[playerY-1][playerX]]){
+                    if(entitiesLogic( playerX, playerY-1)) playerY --;
                 }
-                if (gameMap [x][y] == 1 && !(x == headX && y == headY)) {
-                    gameMap [x][y] = 0;
+            }
+            if (game.buttons.repeat(BTN_DOWN,4)){
+                if (!solids[dungeon[playerY+1][playerX]]){
+                    if(entitiesLogic( playerX, playerY+1)) playerY ++;
+                }
+            }
+            if (game.buttons.repeat(BTN_LEFT,4)){
+                if (!solids[dungeon[playerY][playerX-1]]){
+                    if(entitiesLogic( playerX-1, playerY))playerX --;
+                }
+            }
+            if (game.buttons.repeat(BTN_RIGHT,4)){
+                if (!solids[dungeon[playerY][playerX+1]]){
+                    if(entitiesLogic( playerX+1, playerY))playerX ++;
                 }
             }
         }
-        if (snakeLength - 3 > snakeHS) {
-            snakeHS = snakeLength - 3;
-        }
-        //death
-        if (!snakeUpdate) {
-            snakeLength = 3;
-            headX = 13;
-            headY = 10;
-            snakeInitializing = true;
-            snakeGridInit;
-            if (bsound) game.sound.playCancel();
-        }
-    } else {
-        counter--;
-    }
-}
-void snakeDraw() {
-    //draw BG
-    game.display.color = 14;
-    game.display.fillRectangle(4,4,100,72);
-    //draw map
-    for (int y=0;y<20;y++) {
-        for (int x=0;x<27;x++) {
-            switch (gameMap[x][y]) {
-            case -2 :
-                game.display.drawBitmap(x*4,y*4,pink);
-                break;
-            case -1 :
-                game.display.drawBitmap(x*4,y*4,red);
-                break;
-            case 0 :
-                //game.display.drawBitmap(x*4,y*4,yellow);
-                break;
-            case 1 :
-                game.display.drawBitmap(x*4,y*4,cyan);
-                break;
-            default :
-                if (gameMap[x][y] % 2 == 1) {
-                    game.display.drawBitmap(x*4,y*4,blue);
-                } else {
-                    game.display.drawBitmap(x*4,y*4,green);
-                }
-                break;
-            }
-        }
+
 
-    }
-    //draw score
-    game.display.color = 2;
-    game.display.fillRectangle(0,80,110,8);
-    game.display.setFont(font3x5);
-    game.display.setCursor(1,82);
-    game.display.color = 15;
-    game.display.print("SCORE ");
-    game.display.print(snakeLength - 3);
-    game.display.setCursor(65,82);
-    game.display.color = 15;
-    game.display.print("HISCORE ");
-    game.display.print(snakeHS);
-}
-void stackerDataInit() {
-    //initialize data list
-    for (int y=0;y<2;y++) {
-        for (int x=0;x<20;x++) {
-            oldBlockData[x][y] = 0;
-        }
-    }
-}
-void stackerInput() {
-    if (game.buttons.held(BTN_A,1)) {
-            if (bsound) game.sound.playTick();
-            if (blockH >= 0) {
-                //place old blocks
-                oldBlockData[blockH - blockHOffset][0] = blockX;
-                oldBlockData[blockH - blockHOffset][1] = blockSize;
-                blockH += 1;
-                if (blockH > 1) {
-                    stackLost = false;
-                    //basic block reduction algorithm
-                    switch (blockX - oldBlockData[blockH - blockHOffset - 2][0]) {
-                    case -3 :
-                        blockLoss = 3;
-                        blockMove = 3;
-                        break;
-                    case -2 :
-                        blockLoss = 2;
-                        blockMove = 2;
-                        break;
-                    case -1 :
-                        blockLoss = 1;
-                        blockMove = 1;
-                        break;
-                    case 0 :
-                        blockLoss = 0;
-                        blockMove = 0;
-                        break;
-                    case 1 :
-                        blockLoss = 1;
-                        blockMove = 0;
-                        break;
-                    case 2 :
-                        blockLoss = 2;
-                        blockMove = 0;
-                        break;
-                    case 3 :
-                        blockLoss = 3;
-                        blockMove = 0;
-                        break;
-                    default :
-                        blockLoss = 4;
-                        stackLost = true;
-
-                    }
-                    //score
-                    stackerScore += (4-blockLoss);
-                    //block reduction in action!
-                    if (!stackLost) {
-                        blockSize -= blockLoss;
-                        blockX += blockMove;
-                        oldBlockData[blockH - blockHOffset - 1][1] -= blockLoss;
-                        oldBlockData[blockH - blockHOffset - 1][0] += blockMove;
-                    }
-                } else {
-                    stackerScore += 4;
-                }
-                //scroll through blocks
-                if (blockH >= 13) {
-                    blockHOffset += 1;
-                    for (int y=0;y<15;y++) {
-                        oldBlockData[y][0] = oldBlockData[y+1][0];
-                        oldBlockData[y][1] = oldBlockData[y+1][1];
-                    }
+        for(int x =playerX-7; x<playerX+8; x++){ //7
+            for(int y =playerY-6; y<playerY+6; y++){
+                if(x >= 0 && y >= 0 && x < dungeonSize && y < dungeonSize){
+                    game.display.drawBitmap(14*(x-playerX+7),14*(y-playerY+6),sprites[dungeon[y][x]]);
                 }
             }
         }
-}
-void stackerLogic() {
-    if (counter == 0) {
-        counter = stackerDelay;
-        //loss
-        if (stackLost || blockSize <= 0) {
-            if (bsound) game.sound.playCancel();
-            stackerDataInit();
-            blockSize = 4;
-            blockDir = 1;
-            blockH = 0;
-            blockX = 0;
-            blockHOffset = 0;
-            stackerScore = 0;
-            stackLost = false;
-        }
-        //move blocks
-        blockX += blockDir;
-        if (blockX == 0) {
-            blockDir = 1;
-        } else if (blockX == 27 - blockSize) {
-            blockDir = -1;
-        }
-        //hiscore
-        if (stackerScore > stackerHS) {
-            stackerHS = stackerScore;
-        }
-        //speed up
-        if (blockH >= 15) {
-            if (bsound && stackerDelay == 1) game.sound.playOK();
-            stackerDelay = 0;
-        } else if (blockH >= 10) {
-            if (bsound && stackerDelay == 2) game.sound.playOK();
-            stackerDelay = 1;
-        } else if (blockH >= 5) {
-            if (bsound && stackerDelay == 3) game.sound.playOK();
-            stackerDelay = 2;
-        } else {
-            stackerDelay = 3;
-        }
-    } else {
-        counter--;
-    }
-}
-void stackerDraw() {
-    //draw old blocks
-    for (int indx=0;indx<22;indx++) {
-        for (int a=0;a<oldBlockData[indx][1];a++) {
-            switch ((blockHOffset + indx) % 6) {
-            case 0 :
-                game.display.drawBitmap((oldBlockData[indx][0] + a) * 4,80 - (indx + 1) * 4,red);
-                break;
-            case 1 :
-                game.display.drawBitmap((oldBlockData[indx][0] + a) * 4,80 - (indx + 1) * 4,yellow);
-                break;
-            case 2 :
-                game.display.drawBitmap((oldBlockData[indx][0] + a) * 4,80 - (indx + 1) * 4,green);
-                break;
-            case 3 :
-                game.display.drawBitmap((oldBlockData[indx][0] + a) * 4,80 - (indx + 1) * 4,cyan);
-                break;
-            case 4 :
-                game.display.drawBitmap((oldBlockData[indx][0] + a) * 4,80 - (indx + 1) * 4,blue);
-                break;
-            case 5 :
-                game.display.drawBitmap((oldBlockData[indx][0] + a) * 4,80 - (indx + 1) * 4,pink);
-                break;
-            }
 
+        for(int i=0; i<entities.size(); ++i){
+            game.display.color = 0; //remove before release
+            game.display.fillRect(14*(entities[i].x-playerX+7),14*(entities[i].y-playerY+6),14,14);//remove and fix before release
+            game.display.drawBitmap(14*(entities[i].x-playerX+7),14*(entities[i].y-playerY+6),sprites[entities[i].id]);
         }
-    }
-    //draw current blocks
-    for (int a=0;a<blockSize;a++) {
-            switch (blockH % 6) {
-            case 0 :
-                game.display.drawBitmap((blockX + a) * 4,80 - ((blockH - blockHOffset) + 1) * 4,red);
-                break;
-            case 1 :
-                game.display.drawBitmap((blockX + a) * 4,80 - ((blockH - blockHOffset) + 1) * 4,yellow);
-                break;
-            case 2 :
-                game.display.drawBitmap((blockX + a) * 4,80 - ((blockH - blockHOffset) + 1) * 4,green);
-                break;
-            case 3 :
-                game.display.drawBitmap((blockX + a) * 4,80 - ((blockH - blockHOffset) + 1) * 4,cyan);
-                break;
-            case 4 :
-                game.display.drawBitmap((blockX + a) * 4,80 - ((blockH - blockHOffset) + 1) * 4,blue);
-                break;
-            case 5 :
-                game.display.drawBitmap((blockX + a) * 4,80 - ((blockH - blockHOffset) + 1) * 4,pink);
-                break;
-            }
+
+        game.display.setCursor(0,168);
+        game.display.color = 1;
+        game.display.print(printer);
+
+
 
-    }
-    //score
-    game.display.color = 2;
-    game.display.fillRectangle(0,80,110,8);
-    game.display.setFont(font3x5);
-    game.display.setCursor(1,82);
-    game.display.color = 15;
-    game.display.print("SCORE ");
-    game.display.print(stackerScore);
-    game.display.setCursor(65,82);
-    game.display.color = 15;
-    game.display.print("HISCORE ");
-    game.display.print(stackerHS);
-}
-void menuLogic() {
-    if (game.buttons.held(BTN_RIGHT,1)) {
-        menuSelection++;
-        if (bsound) game.sound.playTick();
-        if (menuSelection == 5) {
-            menuSelection = 1;
-        }
-    }
-    if (game.buttons.held(BTN_LEFT,1)) {
-        menuSelection--;
-        if (bsound) game.sound.playTick();
-        if (menuSelection == 0) {
-            menuSelection = 4;
-        }
-    }
-    if (game.buttons.held(BTN_A,1)) {
-        if (bsound) game.sound.playOK();
-        switch (menuSelection) {
-        case 1 :
-            scoreA = 0;
-            scoreB = 0;
-            resetPongValues();
-            gameMode = 1;
-            break;
-        case 2 :
-            scoreBr = 0;
-            secondLevel = false;
-            lives = 3;
-            resetPongValues();
-            ballSpeed = 1.0f;
-            breakoutGridInit();
-            gameMode = 2;
-            break;
-        case 3 :
-            snakeLength = 3;
-            headX = 13;
-            headY = 10;
-            direction = 0;
-            snakeUpdate = false;
-            foodPlacementSuccess = false;
-            snakeInitializing = true;
-            snakeGridInit();
-            gameMode = 3;
-            break;
-        case 4 :
-            blockX = 0;
-            blockSize = 4;
-            blockDir = 1;
-            blockH = 0;
-            blockHOffset = 0;
-            blockLoss = 0;
-            blockMove = 0;
-            stackLost = false;
-            stackerScore = 0;
-            stackerDelay = 3;
-            stackerDataInit();
-            gameMode = 4;
-            break;
+        drawHP( playerHP);
+        ents[0].draw();
+
+        game.display.drawBitmap(14*(7),14*(6),sprites[ID_PLAYER]);
+
+        if(GameState == StateMenu){
+            drawMenu( 1,1, MenuSelector,1);
         }
     }
-    if (game.buttons.held(BTN_B,1)) {
-        gameMode = -1;
-    }
-}
-void menuDraw() {
-    game.display.drawBitmap(30,10,logo);
-    switch (menuSelection) {
-    case 1 :
-        game.display.drawBitmap(28,30,pongSS);
-        game.display.color = 15;
-        game.display.setCursor(40,70);
-        game.display.setFont(font3x5);
-        game.display.print("Pong \n");
-        break;
-    case 2 :
-        game.display.drawBitmap(28,30,breakoutSS);
-        game.display.color = 15;
-        game.display.setCursor(40,70);
-        game.display.setFont(font3x5);
-        game.display.print("Breakout \n");
-        break;
-    case 3 :
-        game.display.drawBitmap(28,30,snakeSS);
-        game.display.color = 15;
-        game.display.setCursor(40,70);
-        game.display.setFont(font3x5);
-        game.display.print("Snake \n");
-        break;
-    case 4 :
-        game.display.drawBitmap(28,30,stackerSS);
-        game.display.color = 15;
-        game.display.setCursor(40,70);
-        game.display.setFont(font3x5);
-        game.display.print("Stacker \n");
-        break;
-    }
-    game.display.print("A: Play \n");
-    game.display.print("B: Settings \n");
 
 }
-void optionsLogic() {
-    if (game.buttons.held(BTN_UP,1)) {
-        optionSelection--;
-        if (bsound) game.sound.playTick();
-        if (optionSelection == 0) {
-            optionSelection = 3;
-        }
-    }
-    if (game.buttons.held(BTN_DOWN,1)) {
-        optionSelection++;
-        if (bsound) game.sound.playTick();
-        if (optionSelection == 4) {
-            optionSelection = 1;
-        }
-    }
-    if (game.buttons.held(BTN_A,1)) {
-        if (bsound) game.sound.playOK();
-        switch (optionSelection) {
-        case 1 :
-            if (grayscale) {
-                grayscale = false;
-                game.display.load565Palette(color_pal);
-            } else {
-                grayscale = true;
-                game.display.load565Palette(grayscale_pal);
-            }
-            break;
-        case 2 :
-            bsound = !bsound;
-            break;
-        case 3 :
-            gameMode = 0;
-            break;
-        }
-    }
-}
-void optionsDraw() {
-    game.display.setCursor(0,30);
-    game.display.setFont(font5x7);
-    game.display.color = 15;
-    game.display.print("OPTIONS \n");
-    game.display.setFont(font3x5);
-    if (optionSelection == 1) {
-        if (grayscale) {
-            game.display.color = 2;
-        } else {
-            game.display.color = 11;
-        }
-    } else {
-        game.display.color = 15;
-    }
-    if (grayscale) {
-        game.display.print("GRAYSCALE \n");
-    } else {
-        game.display.print("COLOR \n");
-    }
-    if (optionSelection == 2) {
-        if (grayscale) {
-            game.display.color = 2;
-        } else {
-            game.display.color = 11;
-        }
-    } else {
-        game.display.color = 15;
-    }
-    if (bsound) {
-        game.display.print("SOUND \n");
-    } else {
-        game.display.print("MUTE \n");
-    }
-    if (optionSelection == 3) {
-        if (grayscale) {
-            game.display.color = 2;
-        } else {
-            game.display.color = 11;
-        }
-    } else {
-        game.display.color = 15;
-    }
-    game.display.print("BACK TO MENU \n");
+
+return 1;
 }
-void gameTitle() {
-    timeTime++;
-    game.display.drawBitmap(30,25+5*sin(timeTime/15),logo);
-    game.display.color = 15;
-    game.display.setCursor(25,45+5*sin(timeTime/15));
-    game.display.setFont(font3x5);
-    game.display.print("Press A to begin");
-    if (game.buttons.held(BTN_A,1)) {
-        gameMode = 0;
-        if (bsound) game.sound.playOK();
-    }
-}
-int main() {
-    //initialization
-    game.begin();
-    game.display.load565Palette(color_pal);
-    game.display.width = 110;
-    game.display.height = 88;
-    breakoutGridInit();
-    snakeGridInit();
-    stackerDataInit();
-    game.sound.playMusicStream("MENU.SND");
-    //game.sound.playMusicStream("Menu.snd");
-//    columnsGridInit();
-    //main game loop
-    while (game.isRunning) {
-        if (game.update()) {
-                //update RNG
-                RNG = rand() % 100 + 1;
-                switch (gameMode) {
-                case -2 :
-                    //Title
-                    gameTitle();
-                    break;
-                case -1 :
-                    //Options
-                    optionsLogic();
-                    optionsDraw();
-                    break;
-                case 0 :
-                    //Menu
-                    menuLogic();
-                    menuDraw();
-                    break;
-                case 1 :
-                    //Pong
-                    pongLogic();
-                    pongDraw();
-                    break;
-                case 2 :
-                    //Breakout
-                    breakoutLogic();
-                    breakoutDraw();
-                    break;
-                case 3 :
-                    //Snake
-                    snakeInput();
-                    snakeLogic();
-                    snakeDraw();
-                    break;
-                case 4 :
-                    //Stacker
-                    stackerInput();
-                    stackerLogic();
-                    stackerDraw();
-                    break;
-                case 5 :
-                    //Columns
-//                    columnsLogic();
-//                    columnsDraw();
-                    break;
-                }
-                if (game.buttons.held(BTN_C,1)) {
-                    if (gameMode > 0) {
-                        game.sound.playCancel();
-                        gameMode = 0;
-                    }
-                }
-        }
-    }
-}
+