Pokitto turn based strategy game.
Diff: wars.cpp
- Revision:
- 11:4c61319450c8
- Parent:
- 10:c1af7a94f3f9
- Child:
- 12:52184eaf74f4
--- a/wars.cpp Mon Dec 11 04:50:57 2017 +0000 +++ b/wars.cpp Tue Dec 12 03:38:33 2017 +0000 @@ -7,6 +7,10 @@ #include <vector> #include <stdint.h> +const uint16_t sprite_pal[] = { +4195,16678,12717,19017,33382,13092,53801,29580,23545,54245,33972,27973,54611,28185,57003,57210, +}; + Pokitto::Core game; Pokitto::Display disp; Pokitto::Buttons btn; @@ -14,23 +18,39 @@ #define SW disp.width #define SH disp.height -void splashScreen(const uint8_t * bitmap, char * name, uint16_t time) { - disp.bgcolor = 3; +void splashScreen(int id, char * name, int bg_color, int text_color) { + disp.bgcolor = bg_color; disp.clear(); - disp.drawBitmap(SW/2 -(*bitmap/2), SH/2 - (*bitmap), bitmap); - disp.setColor(15); - disp.print(SW/2- ((strlen(name)*6)/2),88-36,name); + disp.drawBitmap((SW/2)-16,(SH/2)-16-8, ui_sprites[id]); + disp.drawBitmap(SW/2, (SH/2)-16-8, ui_sprites[id+1]); + disp.drawBitmap((SW/2)-16, (SH/2)-8, ui_sprites[id+8]); + disp.drawBitmap(SW/2,(SH/2)-8, ui_sprites[id+9]); + disp.setColor(text_color); + disp.print(SW/2- ((strlen(name)*6)/2),SH-26,name); //game.wait(time); - for (int i=0;i<16;i++) {disp.palette[i]=0;} + for (int c=0; c<16;c++) { + disp.palette[c] = sprite_pal[0]; + } disp.update(); - for (int i=0;i<80;i++) { - for (int c = 0;c<16;c++) { - disp.palette[c]=disp.interpolateColor(disp.palette[c],sprite_pal[c],80); + + for (int frame = 0; frame < 180; frame++) { + if (frame<60) { + for (int c = 0; c<16; c++) { + disp.palette[c] = disp.interpolateColor(disp.palette[c], sprite_pal[c], (255/60)*frame); + } + } + else if (frame<120) { + disp.load565Palette(sprite_pal); + } + else { + for (int c = 0; c<16; c++) { + disp.palette[c] = disp.interpolateColor(disp.palette[c], sprite_pal[0], (255/60)*(frame-120)); + } } disp.update(); - game.wait(10); - if (btn.pressed(BTN_A)) break; + //game.wait(2); } + disp.load565Palette(sprite_pal); } @@ -144,6 +164,7 @@ int current_team = TEAM_USER; uint8_t selected_task = 0; uint8_t current_task = TASK_NONE; +uint8_t game_turn = 1; static char task_names[4][7] { {"MOVE"}, @@ -251,18 +272,23 @@ #define ID_HEAVY 1 #define ID_SNIPER 2 #define ID_SUPPORT 3 -#define ID_ORC 4 -#define ID_BARBARIAN 5 -#define ID_SORCERER 6 +#define ID_HUNTER 4 +#define ID_WARRIOR 5 +#define ID_SHAMAN 6 const int sprite_ids[16] { 0, //SOLDIER 2, //HEAVY 4, //SNIPER 6, - 9, //ORC - 11, //BARBARIAN - 13, //SORCERER + 9, //HUNTER + 11, //WARRIOR + 13, //SHAMAN + 15, //SPIDER + 18, + 20, + 22, + 24, }; char id_names[][10] { //GI-BROS @@ -272,14 +298,22 @@ {"SUPPORT"}, //SPACE GRUNKS - {"ORC"}, - {"BARBARIAN"}, - {"SORCERER"}, + {"HUNTER"}, + {"WARRIOR"}, + {"SHAMAN"}, + {"SPIDER"}, + + //TEAM GLOOM + {"BONES"}, + {"SLIME"}, + {"KNIGHT"}, + {"FLYER"}, }; char Faction[][14] { {"GI-BROS"}, {"SPACE GRUNKS"}, + {"TEAM GLOOM"} }; char TRAITS[][8] { @@ -384,6 +418,7 @@ int dx = (x-map_x)*16; int dy = (y-map_y)*16; disp.drawBitmap(dx, dy, sprites[id]); + }; void Spawn(int x, int y, int id, vector<Hero> &heros) { @@ -397,6 +432,10 @@ Base bases[2]; Base * current_base = NULL; +void DrawCursorBaseUI(Base * b, int x, int y) { + +} + void DrawCursorHeroUI (Hero * h, int x, int y) { float bw = 24; float hw = (bw/h->max_hp) * h->hp; @@ -416,27 +455,39 @@ disp.setColor(15); disp.print((int)h->def); } +//COLORS FOR EACH TEIR OF HERO +int prog_colors[4] { + 14,9,11,8 +}; void DrawSelectedBaseUI(Base * base, int y) { disp.setColor(0); - disp.fillRoundRect(1,y,SW-27,88-67,3); + disp.fillRoundRect(1,y-5,SW-28,88-68+6,3); if (!base) return; disp.setColor(15); - printb(3,y-6,id_names[(base->faction*4)+selected_task]); + + disp.print(3,y-4,id_names[(base->faction*4)+selected_task]); - printb(16, (-y)+68, "SPAWN"); - printb(18+(6*5),(-y)+68,Faction[base->faction]); + disp.setCursor(SW-28-(6*4), y-4); + disp.setColor(prog_colors[selected_task]); + disp.print(2+(selected_task*2)); + disp.print(" SP"); - disp.invisiblecolor = 13; + disp.setColor(15); + printb(18,(-y)+68,Faction[base->faction]); + printb(18,(-y)+75, "BASE"); + for (int i=0; i<4; i++) { + disp.invisiblecolor = 13; int spr = (base->faction*9)+(i*2); int x = 3+i*20; disp.setColor(15); if (i==selected_task) { - disp.fillRect(x+1,y+3,16,16); + disp.fillRect(x+1,y+3,16,15); } disp.drawBitmap(x,y+3,hero_sprites[spr]); - disp.drawRoundRect(x,y+2,18,18, 2); + disp.setColor(prog_colors[i]); + disp.drawRoundRect(x,y+2,18,18, 3); } } @@ -446,7 +497,6 @@ disp.fillRoundRect(1,y,SW-2,88-67,3); //disp.setColor(15); if (!h) return; - printb(3,y-3,id_names[h->id]); disp.setColor(8); disp.print(3,y+3,">"); disp.setColor(15); @@ -462,7 +512,7 @@ disp.setColor(15); disp.print((int)h->range); disp.print(" RNG"); - printb(16,(-y)+68,task_names[selected_task]); + printb(18,(-y)+68,task_names[selected_task]); for (int i=0;i<4;i++) { int spr = i+8; @@ -480,6 +530,8 @@ disp.fillRoundRect(45,y-3,hw+2,5,2); disp.setColor(15); printb(50+(bw/2)-10,y-3,(int)h->hp); + + printb(3,y-3,id_names[h->id]); } void DrawTraitList(Hero * h, int x) { @@ -518,8 +570,7 @@ void DrawTurnCounter(vector<Hero> &_heros) { disp.invisiblecolor = 13; - int spr = 32; - if (current_team==TEAM_CPU) spr = 33; + int spr = 32+bases[current_team].faction; disp.drawBitmap(0, 0, ui_sprites[spr]); disp.invisiblecolor = 12; int count = 0; @@ -527,8 +578,10 @@ if (_heros[i].team == current_team) count++; } printb(11,10,(int)count); + } + #define MAP_WIDTH 12 #define MAP_HEIGHT 12 int Map[MAP_HEIGHT][MAP_WIDTH] { @@ -616,6 +669,27 @@ } } +void showRoundScreen() { + disp.clear(); + DrawTileMap(map_x, map_y, current_hero); + disp.setCursor((SW/2)-((6*7)/2),(SH/2)-3); + disp.print("ROUND "); + disp.print((int)game_turn/2); + disp.print("\nTURN "); + disp.print((int)(game_turn%2)+1); + disp.update(); + + for (int frame = 0; frame < 50; frame++) { + for (int i=0; i<16; i++) { + disp.palette[i] = disp.interpolateColor(disp.palette[i], sprite_pal[i], (255/50)*frame); + } + disp.update(); + //game.wait(2); + } + + disp.load565Palette(sprite_pal); +} + void DrawCursor(int x, int y) { //uint8_t spr = 52 + (game.frameCount/12)%2; disp.drawBitmap(x*16-3, y*16-3,cursor_sprites[(game.frameCount/4)%2]); @@ -687,6 +761,7 @@ for (int i=0; i<0+_heros->size(); i++) { _heros->at(i).NewTurn(); } + game_turn++; }; void update() { lb.update(); @@ -704,7 +779,7 @@ if (btn.pressed(BTN_A)) { lb.val = lb.off_val; - disp.load565Palette(sprite_pal); + //disp.load565Palette(sprite_pal); switch (selected_item) { case 0: State = MAIN; @@ -713,6 +788,7 @@ current_team=(current_team+1) % 2; endTurn(hptr); State = MAIN; + showRoundScreen(); break; case 2: State = MENU; @@ -808,7 +884,7 @@ strcpy(items[0], "CAMPAIGN"); strcpy(items[1], "SKIRMISH"); strcpy(items[2], "OPTIONS"); - selected_item = 0; + selected_item = 1; }; void update(LevelList *l) { switch (state) { @@ -917,14 +993,15 @@ heros.push_back(Hero(4,5,ID_SOLDIER, TEAM_USER)); heros.push_back(Hero(5,6,ID_SNIPER, TEAM_USER)); heros.push_back(Hero(3,8,ID_HEAVY, TEAM_USER)); - heros.push_back(Hero(8,5,ID_ORC, TEAM_CPU)); - heros.push_back(Hero(8,7,ID_ORC, TEAM_CPU)); - heros.push_back(Hero(5,9,ID_ORC, TEAM_CPU)); + heros.push_back(Hero(8,5,ID_HUNTER, TEAM_CPU)); + heros.push_back(Hero(8,7,ID_HUNTER, TEAM_CPU)); + heros.push_back(Hero(5,9,ID_HUNTER, TEAM_CPU)); //Hero * cursor_hero = NULL; //Hero * current_hero = NULL; - - //splashScreen(sprites[0],"TRELEMAR", 1000); + game.wait(10); + splashScreen(48,"TRELEMAR", 7, 15); + splashScreen(50,"VONBEDNAR", 15, 0); while (game.isRunning()) { if (game.update()) { @@ -1096,7 +1173,7 @@ if (!current_base) { DrawSelectedHeroUI(current_hero, tTrans.val); } - if (!current_hero) { + else if (!current_hero) { DrawSelectedBaseUI(current_base, tTrans.val); } disp.setCursor(0,0);