Pokitto turn based strategy game.

Dependencies:   PokittoLib

Revision:
9:682f31473b25
Parent:
8:976e983ce79a
Child:
10:c1af7a94f3f9
--- a/wars.cpp	Mon Dec 11 02:00:10 2017 +0000
+++ b/wars.cpp	Mon Dec 11 04:39:14 2017 +0000
@@ -17,9 +17,9 @@
 void splashScreen(const uint8_t * bitmap, char * name, uint16_t time) {
     disp.bgcolor = 3;
     disp.clear();
-    disp.drawBitmap(SW/2 -(*bitmap/2), SH/2 - (*bitmap/2), bitmap);
+    disp.drawBitmap(SW/2 -(*bitmap/2), SH/2 - (*bitmap), bitmap);
     disp.setColor(15);
-    disp.print(SW/2- ((strlen(name)*6)/2),88-32,name);
+    disp.print(SW/2- ((strlen(name)*6)/2),88-36,name);
     //game.wait(time);
     for (int i=0;i<16;i++) {disp.palette[i]=0;}
     disp.update();
@@ -136,7 +136,8 @@
 #define TASK_ATTACK 1
 #define TASK_ITEM 2
 #define TASK_WAIT 3
-#define TASK_NONE 4
+#define TASK_SPAWN 4
+#define TASK_NONE 5
 #define TEAM_USER 0
 #define TEAM_CPU 1
 
@@ -249,26 +250,43 @@
 #define ID_SOLDIER 0
 #define ID_HEAVY 1
 #define ID_SNIPER 2
-#define ID_ORC 3
+#define ID_SUPPORT 3
+#define ID_ORC 4
+#define ID_BARBARIAN 5
+#define ID_SORCERER 6
 
 const int sprite_ids[16] {
     0,     //SOLDIER
     2,     //HEAVY
     4,     //SNIPER
+    6,
     9,     //ORC
+    11,    //BARBARIAN
+    13,    //SORCERER
 };
-char id_names[][8] {
+char id_names[][10] {
+    //GI-BROS
     {"SOLDIER"},
     {"HEAVY"},
     {"SNIPER"},
+    {"SUPPORT"},
+
+    //SPACE GRUNKS
     {"ORC"},
+    {"BARBARIAN"},
+    {"SORCERER"},
 };
+
+char Faction[][14] {
+    {"GI-BROS"},
+    {"SPACE GRUNKS"},
+};
+
 char TRAITS[][8] {
     {""},
     {"FAST"},
     {"HULKISH"},
 };
-
 struct Hero {
     unsigned int index, team, id, x, y;
     uint8_t atk, def, hp, max_hp;
@@ -351,12 +369,14 @@
     int x, y, id, team;
     int hp;
     int spawn_points;
+    int faction;
     Base() {};
-    Base(int _x, int _y, int _id, int _team) {
+    Base(int _x, int _y, int _id, int _team, int _faction) {
         x = _x;
         y = _y;
         id = _id;
         team = _team;
+        faction = _faction;
         spawn_points = 10;
     };
 
@@ -399,10 +419,25 @@
 
 void DrawSelectedBaseUI(Base * base, int y) {
     disp.setColor(0);
-    disp.fillRoundRect(1,y,SW-2,88-67,3);
+    disp.fillRoundRect(1,y,SW-20,88-67,3);
     if (!base) return;
     disp.setColor(15);
-    disp.print(4, y, (int)selected_task);
+    printb(3,y-3,id_names[(base->faction*4)+selected_task]);
+
+    printb(16, (-y)+68, "SPAWN");
+    printb(18+(6*5),(-y)+68,Faction[base->faction]);
+
+    disp.invisiblecolor = 13;
+    for (int i=0; i<4; i++) {
+        int spr = (base->faction*9)+(i*2);
+        int x = 2+i*20;
+        disp.setColor(15);
+        if (i==selected_task) {
+            disp.fillRect(x+1,y+3,16,16);
+        }
+        disp.drawBitmap(x,y+3,hero_sprites[spr]);
+        disp.drawRoundRect(x,y+2,18,18, 2);
+    }
 }
 
 void DrawSelectedHeroUI(Hero * h, int y) {
@@ -570,7 +605,7 @@
             //RANGE BOXES
             if (hero && (current_task == TASK_MOVE || current_task == TASK_ATTACK)) {
                 distance = dist(map_x+x, map_y+y, hero->x, hero->y);
-                if (distance<hero->range&&x+map_x<MAP_WIDTH&&y+map_y<MAP_HEIGHT) {
+                if (distance<hero->range&&x+map_x<MAP_WIDTH&&y+map_y<MAP_HEIGHT&&x+map_x>=0&&y+map_y>=0) {
                     disp.setColor(8);
                     if (solids[Map[map_y+y][map_x+x]]) {disp.setColor(6);}
                     disp.drawRoundRect(map_x*16+2, map_y*16+2, 12, 12,3);
@@ -876,8 +911,8 @@
     LevelList level_menu;
     level_menu.init();
 
-    bases[0] = Base(2,2,24,TEAM_USER);
-    bases[1] = Base(10,10,25,TEAM_CPU);
+    bases[0] = Base(2,2,24,TEAM_USER, 0);
+    bases[1] = Base(10,10,25,TEAM_CPU, 1);
 
     heros.push_back(Hero(4,5,ID_SOLDIER, TEAM_USER));
     heros.push_back(Hero(5,6,ID_SNIPER, TEAM_USER));
@@ -889,7 +924,7 @@
     //Hero * cursor_hero = NULL;
     //Hero * current_hero = NULL;
 
-    splashScreen(sprites[0],"TRELEMAR", 1000);
+    //splashScreen(sprites[0],"TRELEMAR", 1000);
 
     while (game.isRunning()) {
         if (game.update()) {
@@ -902,12 +937,12 @@
             tTrans.update();
             itemlist.update();
             //If no current hero or current task is to move our current hero, accept cursor movement.
-            if (!current_hero||current_task==TASK_MOVE||current_task==TASK_ATTACK) {
+            if ((!current_base&&!current_hero)||current_task==TASK_MOVE||current_task==TASK_ATTACK||current_task==TASK_SPAWN) {
                 CursorInput();
                 cursor_hero = getHeroAtCoords(cursor_x,cursor_y, heros);
             }
             //This will call when there is a current hero and not in a current task
-            else if (current_hero) {
+            else if (current_hero||current_base) {
                 //TASK SELECTOR
                 int dir = 0;
                 if (btn.pressed(BTN_RIGHT)) {
@@ -935,6 +970,15 @@
             disp.setColor(15);
 
             if (btn.pressed(BTN_A)) {
+                if (!current_hero&&current_base&&current_task==TASK_SPAWN) {
+                    int8_t id = selected_task + (current_base->faction*4);
+                    heros.push_back(Hero(cursor_x, cursor_y, id, current_team));
+
+                    current_task = TASK_NONE;
+                    current_hero = &heros[heros.size()-1];
+                    selected_task = TASK_MOVE;
+                    current_base=NULL;
+                }
                 if (current_hero&&current_task!=TASK_NONE) {
                     //THIS IS WITHIN A TASK, EX: SELECTING A MOVE LOCATION OR ATTACK TARGET.
                     switch (current_task) {
@@ -1008,6 +1052,9 @@
                         tTrans.enabled = true;
                     }
                 }
+                else if (current_base) {
+                    current_task = TASK_SPAWN;
+                }
                 else if (bases[current_team].x==cursor_x&&bases[current_team].y==cursor_y) {
                     current_base = &bases[current_team];
                     tTrans.enabled = true;
@@ -1017,8 +1064,14 @@
                 if (current_task!=TASK_NONE) {
                         //BACK OUT OF CURRENT TASK.
                         current_task=TASK_NONE;
-                        cursor_x = current_hero->x;
-                        cursor_y = current_hero->y;
+                        if (current_hero) {
+                            cursor_x = current_hero->x;
+                            cursor_y = current_hero->y;
+                        }
+                        if (current_base) {
+                            cursor_x = current_base->x;
+                            cursor_y = current_base->y;
+                        }
                 }
                 else if (current_hero&&current_task==TASK_NONE) {
                         tTrans.enabled=false; current_hero = NULL; //UNSELECT HERO.
@@ -1037,10 +1090,13 @@
             if (cursor_hero&&cursor_hero!=current_hero&&current_task) {
                 DrawCursorHeroUI(cursor_hero, (cursor_hero->x-map_x)*16-4,(cursor_hero->y-map_y)*16-7);
             }
-            if (tTrans.val==tTrans.on_val) {
+            if (tTrans.val==tTrans.on_val&&!current_base) {
                 DrawTraitList(current_hero, itemlist.val);
             }
-            DrawSelectedHeroUI(current_hero, tTrans.val);
+
+            if (!current_base) {
+                DrawSelectedHeroUI(current_hero, tTrans.val);
+            }
             if (!current_hero) {
                 DrawSelectedBaseUI(current_base, tTrans.val);
             }