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

Committer:
Pokitto
Date:
Mon May 21 18:04:18 2018 +0000
Revision:
15:67fb7b0c1149
Parent:
10:590a26231903
Compilation working now. Get music from: https://talk.pokitto.com/t/game-columns-coffins-roguelike-updated/482

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Pokitto 10:590a26231903 1 #include "Pokitto.h"
Pokitto 10:590a26231903 2 #include <vector>
Pokitto 6:7e55f4fd3e4e 3 #include <string>
Pokitto 10:590a26231903 4 #include "sprites.h"
Pokitto 10:590a26231903 5
Pokitto 10:590a26231903 6 #include "mapgen.c"
Pokitto 10:590a26231903 7 #include "classes.cpp"
Pokitto 10:590a26231903 8
Pokitto 10:590a26231903 9 #define SEED 344 //Change this value for unique map every time. Hoping for RTC on Hardware!
Pokitto 10:590a26231903 10
Pokitto 10:590a26231903 11 bool solids[255];
Pokitto 0:2d2a3994d55d 12
Pokitto 10:590a26231903 13 char dungeon[MAPSIZE][MAPSIZE];
Pokitto 10:590a26231903 14 int dungeonSize = 16;//Starting dungeon size, which increases each level
Pokitto 10:590a26231903 15 int dungeonDepth = 1;//Which floor the player is on
Pokitto 10:590a26231903 16
Pokitto 10:590a26231903 17 bool solid(char map[][MAPSIZE],int x, int y){
Pokitto 10:590a26231903 18 return solids[map[y][x]];
Pokitto 10:590a26231903 19 }
Pokitto 10:590a26231903 20
Pokitto 10:590a26231903 21 void init_solids(){
Pokitto 10:590a26231903 22 for( int i = 1; i <= ID_COFFIN_OPEN_BOTTOM; i++ )
Pokitto 10:590a26231903 23 solids[i]=true;
Pokitto 10:590a26231903 24 }
Pokitto 10:590a26231903 25
Pokitto 6:7e55f4fd3e4e 26 Pokitto::Core game;
Pokitto 6:7e55f4fd3e4e 27
Pokitto 10:590a26231903 28 int playerX = 1;
Pokitto 10:590a26231903 29 int playerY = 2;
Pokitto 10:590a26231903 30
Pokitto 10:590a26231903 31
Pokitto 10:590a26231903 32 void Ent::draw(){ //Classes are not implemented yet. This wont work either
Pokitto 10:590a26231903 33 game.display.drawBitmap(playerX-x*14,playerY-y*14,sprites[id]);
Pokitto 10:590a26231903 34 }
Pokitto 10:590a26231903 35
Pokitto 10:590a26231903 36 #define MAP_TILES 0
Pokitto 10:590a26231903 37 #define ITEM_TILES (MAP_TILES + 34)
Pokitto 10:590a26231903 38 #define ENTITY_TILES (ITEM_TILES + 36)
Pokitto 10:590a26231903 39
Pokitto 10:590a26231903 40 #define ID_PLAYER ENTITY_TILES + 2
Pokitto 0:2d2a3994d55d 41
Pokitto 10:590a26231903 42 #define ID_STAIRS_DOWN MAP_TILES + 19
Pokitto 10:590a26231903 43 #define ID_GOBLIN_WARRIOR ENTITY_TILES + 5
Pokitto 10:590a26231903 44 #define ID_GOBLIN_MAGE ENTITY_TILES + 6
Pokitto 10:590a26231903 45 #define ID_SKELETON_MAGE ENTITY_TILES + 7
Pokitto 10:590a26231903 46 #define ID_SKELETON_ARCHER ENTITY_TILES + 8
Pokitto 10:590a26231903 47 #define ID_SKELETON_WARIOR ENTITY_TILES + 9
Pokitto 10:590a26231903 48 #define ID_BLOOD_SKELETON ENTITY_TILES + 10
Pokitto 10:590a26231903 49 #define ID_BLOOD ENTITY_TILES + 11
Pokitto 10:590a26231903 50 #define ID_RAT ENTITY_TILES + 4
Pokitto 10:590a26231903 51 #define ID_SCROLL ITEM_TILES + 3
Pokitto 10:590a26231903 52 #define ID_CHEST ENTITY_TILES + 12
Pokitto 10:590a26231903 53 #define ID_CHEST_OPEN ENTITY_TILES + 13
Pokitto 10:590a26231903 54 #define ID_MIMIC ENTITY_TILES + 14
Pokitto 10:590a26231903 55 #define ID_COIN ITEM_TILES
Pokitto 10:590a26231903 56 #define ID_COINS ITEM_TILES + 1
Pokitto 10:590a26231903 57 #define ID_BAG ITEM_TILES + 2
Pokitto 10:590a26231903 58
Pokitto 10:590a26231903 59 #define StateGame 0
Pokitto 10:590a26231903 60 #define StateMenu 1
Pokitto 10:590a26231903 61 #define StateIntro 2
Pokitto 10:590a26231903 62 #define StateDead 3
Pokitto 10:590a26231903 63
Pokitto 10:590a26231903 64 void addDescent(char map[][MAPSIZE]){
Pokitto 10:590a26231903 65 int x=random(1,dungeonSize-1);
Pokitto 10:590a26231903 66 int y=random(1,dungeonSize-1);
Pokitto 10:590a26231903 67 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)) {
Pokitto 10:590a26231903 68 map[y][x] = ID_STAIRS_DOWN;
Pokitto 6:7e55f4fd3e4e 69 }
Pokitto 10:590a26231903 70 else {
Pokitto 10:590a26231903 71 addDescent(map);
Pokitto 6:7e55f4fd3e4e 72 }
Pokitto 6:7e55f4fd3e4e 73 }
Pokitto 10:590a26231903 74
Pokitto 10:590a26231903 75 //globals
Pokitto 10:590a26231903 76 //std::vector<entity> entities(entities_size);
Pokitto 10:590a26231903 77 struct entity{
Pokitto 10:590a26231903 78 uint8_t x;
Pokitto 10:590a26231903 79 uint8_t y;
Pokitto 10:590a26231903 80 int8_t hp;
Pokitto 10:590a26231903 81 uint8_t id;
Pokitto 10:590a26231903 82 };
Pokitto 10:590a26231903 83 #define ESIZE 2
Pokitto 10:590a26231903 84 std::vector<entity> entities(ESIZE);
Pokitto 10:590a26231903 85 std::vector<std::string> inventory;
Pokitto 10:590a26231903 86
Pokitto 10:590a26231903 87 void removeEntity(int i){
Pokitto 10:590a26231903 88
Pokitto 10:590a26231903 89 using std::swap;
Pokitto 10:590a26231903 90 std::swap(entities[i], entities.back());
Pokitto 10:590a26231903 91 entities.pop_back();
Pokitto 10:590a26231903 92
Pokitto 10:590a26231903 93 }
Pokitto 10:590a26231903 94
Pokitto 10:590a26231903 95 void spawner(int amount){
Pokitto 10:590a26231903 96 entities.clear();
Pokitto 10:590a26231903 97 for(int i = 0; i < amount; i++ ){
Pokitto 10:590a26231903 98 entity spawn;
Pokitto 10:590a26231903 99 bool l = true;
Pokitto 10:590a26231903 100 int sx, sy;
Pokitto 10:590a26231903 101 while(l){
Pokitto 10:590a26231903 102 sx = rand()%dungeonSize;
Pokitto 10:590a26231903 103 sy = rand()%dungeonSize;
Pokitto 10:590a26231903 104 if(dungeon[sy][sx] == 0){
Pokitto 10:590a26231903 105 spawn.id = ENTITY_TILES+4+(rand()%16);//rand()%8+ENTITY_TILES+4;//Skip first few entities for now
Pokitto 10:590a26231903 106 spawn.x = sx;
Pokitto 10:590a26231903 107 spawn.y = sy;
Pokitto 10:590a26231903 108 spawn.hp = rand()%20;
Pokitto 10:590a26231903 109 entities.push_back(spawn);
Pokitto 10:590a26231903 110 l = false;
Pokitto 6:7e55f4fd3e4e 111 }
Pokitto 6:7e55f4fd3e4e 112 }
Pokitto 6:7e55f4fd3e4e 113 }
Pokitto 6:7e55f4fd3e4e 114 }
Pokitto 10:590a26231903 115
Pokitto 10:590a26231903 116
Pokitto 10:590a26231903 117 char printer[40] = "";
Pokitto 10:590a26231903 118 int playerGold = 0;
Pokitto 10:590a26231903 119 int playerHP = 100;
Pokitto 10:590a26231903 120 uint8_t GameState = StateIntro;
Pokitto 10:590a26231903 121 uint8_t MenuSelector = 0;
Pokitto 10:590a26231903 122 #include "gui.h"
Pokitto 10:590a26231903 123 #include "crapai.h"
Pokitto 10:590a26231903 124 using namespace std;
Pokitto 15:67fb7b0c1149 125
Pokitto 15:67fb7b0c1149 126
Pokitto 10:590a26231903 127 int main () {
Pokitto 10:590a26231903 128 init_solids();
Pokitto 10:590a26231903 129 srand(SEED);
Pokitto 10:590a26231903 130 mapinit(dungeon,dungeonSize,dungeonSize);
Pokitto 10:590a26231903 131 mapgen(dungeon,dungeonSize,dungeonSize,0,0,dungeonSize-1,dungeonSize-1);
Pokitto 10:590a26231903 132 mappretty(dungeon,dungeonSize,dungeonSize);
Pokitto 10:590a26231903 133 addDescent(dungeon);
Pokitto 10:590a26231903 134 std::vector<Ent> ents;
Pokitto 10:590a26231903 135 inventory.push_back("adekto");
Pokitto 10:590a26231903 136 inventory.push_back("trelemar");
Pokitto 10:590a26231903 137 inventory.push_back("VonBednar");
Pokitto 10:590a26231903 138 inventory.push_back("wuuff");
Pokitto 10:590a26231903 139 Ent Etemp(3,3);
Pokitto 10:590a26231903 140 ents.push_back(Etemp);
Pokitto 15:67fb7b0c1149 141 pokInitSD(); // before game.begin if streaming
Pokitto 15:67fb7b0c1149 142 game.sound.playMusicStream("coffins/coffins.snd"); // before game.begin if streaming
Pokitto 10:590a26231903 143 game.begin();
Pokitto 15:67fb7b0c1149 144 game.sound.playMusicStream(); //after game.begin so that sound buffer is ready
Pokitto 10:590a26231903 145 game.display.setFont(font5x7);
Pokitto 15:67fb7b0c1149 146
Pokitto 10:590a26231903 147 //mapgen(0,0,0,20,20);
Pokitto 10:590a26231903 148
Pokitto 10:590a26231903 149 game.display.loadRGBPalette(paletteCGA);
Pokitto 10:590a26231903 150 //game.display.setFont(fontAdventurer);
Pokitto 10:590a26231903 151 //game.display.persistence = true;
Pokitto 10:590a26231903 152 game.display.setInvisibleColor(0);
Pokitto 10:590a26231903 153
Pokitto 10:590a26231903 154 spawner(ESIZE);
Pokitto 10:590a26231903 155 /*entities[0].id = 12;
Pokitto 10:590a26231903 156 entities[0].x = 5;
Pokitto 10:590a26231903 157 entities[0].y = 5;
Pokitto 10:590a26231903 158 entities[0].hp = rand()%20;*/
Pokitto 10:590a26231903 159
Pokitto 10:590a26231903 160 uint8_t introspinner=0xFF;
Pokitto 10:590a26231903 161
Pokitto 10:590a26231903 162 while (game.isRunning()) {
Pokitto 10:590a26231903 163
Pokitto 10:590a26231903 164 if (game.update()) {
Pokitto 10:590a26231903 165
Pokitto 10:590a26231903 166 if( GameState == StateIntro){
Pokitto 10:590a26231903 167 if (introspinner<85) {
Pokitto 10:590a26231903 168 game.display.setFont(fontAdventurer);
Pokitto 10:590a26231903 169 game.display.setCursor(game.display.getWidth()/4-16,36);
Pokitto 10:590a26231903 170 game.display.print("Columns & Coffins \n \n A Pokitto Roguelike \n \n PRESS A(z)");
Pokitto 10:590a26231903 171 game.display.setFont(font5x7);
Pokitto 10:590a26231903 172 } else if (introspinner>160) {
Pokitto 10:590a26231903 173 game.display.load565Palette(cnctitle_pal);
Pokitto 10:590a26231903 174 game.display.drawBitmap(0,0,cnctitle);
Pokitto 10:590a26231903 175 } else {
Pokitto 10:590a26231903 176 game.display.loadRGBPalette(paletteCGA);
Pokitto 10:590a26231903 177 game.display.drawBitmap(33,70,pokitteam);
Pokitto 10:590a26231903 178 }
Pokitto 10:590a26231903 179 if( game.buttons.held(BTN_A,0) ){
Pokitto 10:590a26231903 180 game.display.loadRGBPalette(paletteCGA);
Pokitto 10:590a26231903 181 GameState = StateGame;
Pokitto 10:590a26231903 182 }
Pokitto 10:590a26231903 183 introspinner--;
Pokitto 10:590a26231903 184 continue;
Pokitto 10:590a26231903 185 }
Pokitto 10:590a26231903 186
Pokitto 10:590a26231903 187 if( GameState == StateDead){
Pokitto 10:590a26231903 188 game.display.setFont(fontAdventurer);
Pokitto 10:590a26231903 189 game.display.setCursor(game.display.getWidth()/4,32);
Pokitto 10:590a26231903 190 char over[60];
Pokitto 10:590a26231903 191
Pokitto 10:590a26231903 192 sprintf(over,"Game Over \n \n You died on floor %i \n \n with %i gold",dungeonDepth,playerGold);
Pokitto 10:590a26231903 193 game.display.print(over);
Pokitto 10:590a26231903 194 //game.display.print(dungeonDepth);
Pokitto 10:590a26231903 195 //game.display.print("\n \n You made it to year: ");
Pokitto 10:590a26231903 196 //game.display.print("ERR");//Not implemented
Pokitto 10:590a26231903 197 game.display.print("\n \n PRESS A");
Pokitto 10:590a26231903 198 if( game.buttons.held(BTN_A,0) ){
Pokitto 10:590a26231903 199 GameState = StateIntro;
Pokitto 10:590a26231903 200 dungeonSize = 16;
Pokitto 10:590a26231903 201 dungeonDepth = 1;
Pokitto 10:590a26231903 202 playerHP = 100;
Pokitto 10:590a26231903 203 playerX = 1;
Pokitto 10:590a26231903 204 playerY = 2;
Pokitto 10:590a26231903 205 mapinit(dungeon,dungeonSize,dungeonSize);
Pokitto 10:590a26231903 206 mapgen(dungeon,dungeonSize,dungeonSize,0,0,dungeonSize-1,dungeonSize-1);
Pokitto 10:590a26231903 207 mappretty(dungeon,dungeonSize,dungeonSize);
Pokitto 10:590a26231903 208 addDescent(dungeon);
Pokitto 10:590a26231903 209 spawner(ESIZE);
Pokitto 10:590a26231903 210 }
Pokitto 10:590a26231903 211 game.display.setFont(font5x7);
Pokitto 10:590a26231903 212 continue;
Pokitto 10:590a26231903 213 }
Pokitto 10:590a26231903 214
Pokitto 10:590a26231903 215 //If the player is standing on stairs down, generate a new bigger map
Pokitto 10:590a26231903 216 if( dungeon[playerY][playerX] == ID_STAIRS_DOWN ){
Pokitto 10:590a26231903 217 if( dungeonSize + 2 < MAPSIZE ){ //As long as we aren't at maximum size
Pokitto 10:590a26231903 218 dungeonSize += 2;//Increase map x and y by 2
Pokitto 10:590a26231903 219 }
Pokitto 10:590a26231903 220 dungeonDepth++;
Pokitto 10:590a26231903 221 playerX = 1;
Pokitto 10:590a26231903 222 playerY = 2;
Pokitto 10:590a26231903 223 mapinit(dungeon,dungeonSize,dungeonSize);
Pokitto 10:590a26231903 224 mapgen(dungeon,dungeonSize,dungeonSize,0,0,dungeonSize-1,dungeonSize-1);
Pokitto 10:590a26231903 225 mappretty(dungeon,dungeonSize,dungeonSize);
Pokitto 10:590a26231903 226 addDescent(dungeon);
Pokitto 10:590a26231903 227 spawner(ESIZE);
Pokitto 10:590a26231903 228 }
Pokitto 10:590a26231903 229
Pokitto 10:590a26231903 230 if (game.buttons.held(BTN_C,0)){
Pokitto 10:590a26231903 231 //doing it this way since more context may happen
Pokitto 10:590a26231903 232 if(GameState == StateGame){
Pokitto 10:590a26231903 233 //game.display.rotatePalette(1);
Pokitto 10:590a26231903 234 GameState = StateMenu;
Pokitto 10:590a26231903 235 }
Pokitto 10:590a26231903 236 else if(GameState == StateMenu){
Pokitto 10:590a26231903 237 //game.display.rotatePalette(-1);
Pokitto 10:590a26231903 238 GameState = StateGame;
Pokitto 10:590a26231903 239 MenuSelector = 0;
Pokitto 10:590a26231903 240 isInventory = false;
Pokitto 6:7e55f4fd3e4e 241 }
Pokitto 6:7e55f4fd3e4e 242 }
Pokitto 10:590a26231903 243 if(GameState == StateGame){
Pokitto 10:590a26231903 244 if( playerHP <= 0){
Pokitto 10:590a26231903 245 GameState = StateDead;
Pokitto 10:590a26231903 246 continue;
Pokitto 10:590a26231903 247 }
Pokitto 10:590a26231903 248
Pokitto 10:590a26231903 249 if (game.buttons.repeat(BTN_UP,4)){
Pokitto 10:590a26231903 250 if (!solids[dungeon[playerY-1][playerX]]){
Pokitto 10:590a26231903 251 if(entitiesLogic( playerX, playerY-1)) playerY --;
Pokitto 6:7e55f4fd3e4e 252 }
Pokitto 10:590a26231903 253 }
Pokitto 10:590a26231903 254 if (game.buttons.repeat(BTN_DOWN,4)){
Pokitto 10:590a26231903 255 if (!solids[dungeon[playerY+1][playerX]]){
Pokitto 10:590a26231903 256 if(entitiesLogic( playerX, playerY+1)) playerY ++;
Pokitto 10:590a26231903 257 }
Pokitto 10:590a26231903 258 }
Pokitto 10:590a26231903 259 if (game.buttons.repeat(BTN_LEFT,4)){
Pokitto 10:590a26231903 260 if (!solids[dungeon[playerY][playerX-1]]){
Pokitto 10:590a26231903 261 if(entitiesLogic( playerX-1, playerY))playerX --;
Pokitto 10:590a26231903 262 }
Pokitto 10:590a26231903 263 }
Pokitto 10:590a26231903 264 if (game.buttons.repeat(BTN_RIGHT,4)){
Pokitto 10:590a26231903 265 if (!solids[dungeon[playerY][playerX+1]]){
Pokitto 10:590a26231903 266 if(entitiesLogic( playerX+1, playerY))playerX ++;
Pokitto 6:7e55f4fd3e4e 267 }
Pokitto 6:7e55f4fd3e4e 268 }
Pokitto 6:7e55f4fd3e4e 269 }
Pokitto 10:590a26231903 270
Pokitto 6:7e55f4fd3e4e 271
Pokitto 10:590a26231903 272 for(int x =playerX-7; x<playerX+8; x++){ //7
Pokitto 10:590a26231903 273 for(int y =playerY-6; y<playerY+6; y++){
Pokitto 10:590a26231903 274 if(x >= 0 && y >= 0 && x < dungeonSize && y < dungeonSize){
Pokitto 10:590a26231903 275 game.display.drawBitmap(14*(x-playerX+7),14*(y-playerY+6),sprites[dungeon[y][x]]);
Pokitto 6:7e55f4fd3e4e 276 }
Pokitto 6:7e55f4fd3e4e 277 }
Pokitto 6:7e55f4fd3e4e 278 }
Pokitto 6:7e55f4fd3e4e 279
Pokitto 10:590a26231903 280 for(int i=0; i<entities.size(); ++i){
Pokitto 10:590a26231903 281 game.display.color = 0; //remove before release
Pokitto 10:590a26231903 282 game.display.fillRect(14*(entities[i].x-playerX+7),14*(entities[i].y-playerY+6),14,14);//remove and fix before release
Pokitto 10:590a26231903 283 game.display.drawBitmap(14*(entities[i].x-playerX+7),14*(entities[i].y-playerY+6),sprites[entities[i].id]);
Pokitto 6:7e55f4fd3e4e 284 }
Pokitto 10:590a26231903 285
Pokitto 10:590a26231903 286 game.display.setCursor(0,168);
Pokitto 10:590a26231903 287 game.display.color = 1;
Pokitto 10:590a26231903 288 game.display.print(printer);
Pokitto 10:590a26231903 289
Pokitto 10:590a26231903 290
Pokitto 6:7e55f4fd3e4e 291
Pokitto 10:590a26231903 292 drawHP( playerHP);
Pokitto 15:67fb7b0c1149 293 //ents[0].draw();
Pokitto 10:590a26231903 294
Pokitto 10:590a26231903 295 game.display.drawBitmap(14*(7),14*(6),sprites[ID_PLAYER]);
Pokitto 10:590a26231903 296
Pokitto 10:590a26231903 297 if(GameState == StateMenu){
Pokitto 10:590a26231903 298 drawMenu( 1,1, MenuSelector,1);
Pokitto 6:7e55f4fd3e4e 299 }
Pokitto 6:7e55f4fd3e4e 300 }
Pokitto 6:7e55f4fd3e4e 301
Pokitto 6:7e55f4fd3e4e 302 }
Pokitto 10:590a26231903 303
Pokitto 10:590a26231903 304 return 1;
Pokitto 6:7e55f4fd3e4e 305 }
Pokitto 10:590a26231903 306
Pokitto 15:67fb7b0c1149 307