Pokitto turn based strategy game.

Dependencies:   PokittoLib

Committer:
trelemar
Date:
Tue Mar 06 12:57:47 2018 +0000
Revision:
13:8a3620166b57
Parent:
12:52184eaf74f4
Open Source

Who changed what in which revision?

UserRevisionLine numberNew contents of line
trelemar 4:e77580278416 1 #include "Pokitto.h"
trelemar 4:e77580278416 2 #include "warsprites.h"
trelemar 8:976e983ce79a 3 #include "hero_sprites.h"
trelemar 8:976e983ce79a 4 #include "ui_sprites.h"
trelemar 4:e77580278416 5 uint16_t dark_pal[16];
trelemar 4:e77580278416 6 #include "warfont.cpp"
trelemar 4:e77580278416 7 #include <vector>
trelemar 4:e77580278416 8 #include <stdint.h>
trelemar 4:e77580278416 9
trelemar 11:4c61319450c8 10 const uint16_t sprite_pal[] = {
trelemar 11:4c61319450c8 11 4195,16678,12717,19017,33382,13092,53801,29580,23545,54245,33972,27973,54611,28185,57003,57210,
trelemar 11:4c61319450c8 12 };
trelemar 11:4c61319450c8 13
trelemar 4:e77580278416 14 Pokitto::Core game;
trelemar 4:e77580278416 15 Pokitto::Display disp;
trelemar 4:e77580278416 16 Pokitto::Buttons btn;
trelemar 4:e77580278416 17
trelemar 8:976e983ce79a 18 #define SW disp.width
trelemar 8:976e983ce79a 19 #define SH disp.height
trelemar 8:976e983ce79a 20
trelemar 11:4c61319450c8 21 void splashScreen(int id, char * name, int bg_color, int text_color) {
trelemar 11:4c61319450c8 22 disp.bgcolor = bg_color;
trelemar 7:91365e9ad8c6 23 disp.clear();
trelemar 11:4c61319450c8 24 disp.drawBitmap((SW/2)-16,(SH/2)-16-8, ui_sprites[id]);
trelemar 11:4c61319450c8 25 disp.drawBitmap(SW/2, (SH/2)-16-8, ui_sprites[id+1]);
trelemar 11:4c61319450c8 26 disp.drawBitmap((SW/2)-16, (SH/2)-8, ui_sprites[id+8]);
trelemar 11:4c61319450c8 27 disp.drawBitmap(SW/2,(SH/2)-8, ui_sprites[id+9]);
trelemar 11:4c61319450c8 28 disp.setColor(text_color);
trelemar 11:4c61319450c8 29 disp.print(SW/2- ((strlen(name)*6)/2),SH-26,name);
trelemar 7:91365e9ad8c6 30 //game.wait(time);
trelemar 11:4c61319450c8 31 for (int c=0; c<16;c++) {
trelemar 11:4c61319450c8 32 disp.palette[c] = sprite_pal[0];
trelemar 11:4c61319450c8 33 }
trelemar 7:91365e9ad8c6 34 disp.update();
trelemar 11:4c61319450c8 35
trelemar 12:52184eaf74f4 36 int frame = 0;
trelemar 12:52184eaf74f4 37
trelemar 12:52184eaf74f4 38 while (frame<180&&!btn.cBtn()) {
trelemar 11:4c61319450c8 39 if (frame<60) {
trelemar 11:4c61319450c8 40 for (int c = 0; c<16; c++) {
trelemar 11:4c61319450c8 41 disp.palette[c] = disp.interpolateColor(disp.palette[c], sprite_pal[c], (255/60)*frame);
trelemar 11:4c61319450c8 42 }
trelemar 11:4c61319450c8 43 }
trelemar 11:4c61319450c8 44 else if (frame<120) {
trelemar 11:4c61319450c8 45 disp.load565Palette(sprite_pal);
trelemar 11:4c61319450c8 46 }
trelemar 11:4c61319450c8 47 else {
trelemar 11:4c61319450c8 48 for (int c = 0; c<16; c++) {
trelemar 11:4c61319450c8 49 disp.palette[c] = disp.interpolateColor(disp.palette[c], sprite_pal[0], (255/60)*(frame-120));
trelemar 11:4c61319450c8 50 }
trelemar 7:91365e9ad8c6 51 }
trelemar 7:91365e9ad8c6 52 disp.update();
trelemar 11:4c61319450c8 53 //game.wait(2);
trelemar 12:52184eaf74f4 54 frame++;
trelemar 7:91365e9ad8c6 55 }
trelemar 11:4c61319450c8 56
trelemar 8:976e983ce79a 57 disp.load565Palette(sprite_pal);
trelemar 7:91365e9ad8c6 58 }
trelemar 7:91365e9ad8c6 59
trelemar 4:e77580278416 60 void init_dark_palette() {
trelemar 4:e77580278416 61 for (uint8_t c=1;c<15;c++) {
trelemar 4:e77580278416 62 dark_pal[c] = disp.interpolateColor(sprite_pal[c], sprite_pal[0], 100);
trelemar 4:e77580278416 63 }
trelemar 4:e77580278416 64 }
trelemar 4:e77580278416 65
trelemar 4:e77580278416 66 bool loading;
trelemar 4:e77580278416 67 int solids[64] {
trelemar 4:e77580278416 68 0,1,1,1,1,0,0,0,
trelemar 4:e77580278416 69 0,0,1,0,1,0,0,0,
trelemar 4:e77580278416 70 0,0,1,1,1,0,0,0,
trelemar 4:e77580278416 71 0,0,0,0,0,0,0,0,
trelemar 4:e77580278416 72 0,0,0,0,0,0,0,0,
trelemar 4:e77580278416 73 0,0,0,0,0,0,0,0,
trelemar 4:e77580278416 74 0,0,0,0,0,0,0,0,
trelemar 4:e77580278416 75 0,0,0,0,0,0,0,0,
trelemar 4:e77580278416 76 };
trelemar 4:e77580278416 77 //Sprite sheet:2x1
trelemar 4:e77580278416 78 const uint8_t cursor_sprites [][244] ={
trelemar 4:e77580278416 79 //[0] cell:0x0
trelemar 4:e77580278416 80 {
trelemar 4:e77580278416 81 22,22,
trelemar 4:e77580278416 82 204,0,12,204,204,204,204,204,192,0,204,
trelemar 4:e77580278416 83 192,255,240,204,204,204,204,204,15,255,12,
trelemar 4:e77580278416 84 15,160,12,204,204,204,204,204,192,10,240,
trelemar 4:e77580278416 85 15,12,204,204,204,204,204,204,204,192,240,
trelemar 4:e77580278416 86 15,12,204,204,204,204,204,204,204,192,240,
trelemar 4:e77580278416 87 192,204,204,204,204,204,204,204,204,204,12,
trelemar 4:e77580278416 88 204,204,204,204,204,204,204,204,204,204,204,
trelemar 4:e77580278416 89 204,204,204,204,204,204,204,204,204,204,204,
trelemar 4:e77580278416 90 204,204,204,204,204,204,204,204,204,204,204,
trelemar 4:e77580278416 91 204,204,204,204,204,204,204,204,204,204,204,
trelemar 4:e77580278416 92 204,204,204,204,204,204,204,204,204,204,204,
trelemar 4:e77580278416 93 204,204,204,204,204,204,204,204,204,204,204,
trelemar 4:e77580278416 94 204,204,204,204,204,204,204,204,204,204,204,
trelemar 4:e77580278416 95 204,204,204,204,204,204,204,204,204,204,204,
trelemar 4:e77580278416 96 204,204,204,204,204,204,204,204,204,204,204,
trelemar 4:e77580278416 97 204,204,204,204,204,204,204,204,204,204,204,
trelemar 4:e77580278416 98 192,204,204,204,204,204,204,204,204,204,12,
trelemar 4:e77580278416 99 15,12,204,204,204,204,204,204,204,192,240,
trelemar 4:e77580278416 100 15,12,204,204,204,204,204,204,204,192,240,
trelemar 4:e77580278416 101 15,160,12,204,204,204,204,204,192,10,240,
trelemar 4:e77580278416 102 192,255,240,204,204,204,204,204,15,255,12,
trelemar 4:e77580278416 103 204,0,12,204,204,204,204,204,192,0,204,
trelemar 4:e77580278416 104 },
trelemar 4:e77580278416 105 //[1] cell:1x0
trelemar 4:e77580278416 106 {
trelemar 4:e77580278416 107 22,22,
trelemar 4:e77580278416 108 204,204,204,204,204,204,204,204,204,204,204,
trelemar 4:e77580278416 109 204,192,0,204,204,204,204,204,0,12,204,
trelemar 4:e77580278416 110 204,15,255,12,204,204,204,192,255,240,204,
trelemar 4:e77580278416 111 192,250,0,204,204,204,204,204,0,175,12,
trelemar 4:e77580278416 112 192,240,204,204,204,204,204,204,204,15,12,
trelemar 4:e77580278416 113 192,240,204,204,204,204,204,204,204,15,12,
trelemar 4:e77580278416 114 204,12,204,204,204,204,204,204,204,192,204,
trelemar 4:e77580278416 115 204,204,204,204,204,204,204,204,204,204,204,
trelemar 4:e77580278416 116 204,204,204,204,204,204,204,204,204,204,204,
trelemar 4:e77580278416 117 204,204,204,204,204,204,204,204,204,204,204,
trelemar 4:e77580278416 118 204,204,204,204,204,204,204,204,204,204,204,
trelemar 4:e77580278416 119 204,204,204,204,204,204,204,204,204,204,204,
trelemar 4:e77580278416 120 204,204,204,204,204,204,204,204,204,204,204,
trelemar 4:e77580278416 121 204,204,204,204,204,204,204,204,204,204,204,
trelemar 4:e77580278416 122 204,204,204,204,204,204,204,204,204,204,204,
trelemar 4:e77580278416 123 204,12,204,204,204,204,204,204,204,192,204,
trelemar 4:e77580278416 124 192,240,204,204,204,204,204,204,204,15,12,
trelemar 4:e77580278416 125 192,240,204,204,204,204,204,204,204,15,12,
trelemar 4:e77580278416 126 192,250,0,204,204,204,204,204,0,175,12,
trelemar 4:e77580278416 127 204,15,255,12,204,204,204,192,255,240,204,
trelemar 4:e77580278416 128 204,192,0,204,204,204,204,204,0,12,204,
trelemar 4:e77580278416 129 204,204,204,204,204,204,204,204,204,204,204,
trelemar 4:e77580278416 130 },
trelemar 4:e77580278416 131 };
trelemar 4:e77580278416 132
trelemar 4:e77580278416 133 using namespace std;
trelemar 4:e77580278416 134
trelemar 4:e77580278416 135 int clamp(int low, int n, int high) {return min(max(low, n), high);}
trelemar 4:e77580278416 136
trelemar 4:e77580278416 137 float dist(int x1, int y1, int x2, int y2) {
trelemar 4:e77580278416 138 int x = x1 - x2;
trelemar 4:e77580278416 139 int y = y1 - y2;
trelemar 4:e77580278416 140 float dist;
trelemar 4:e77580278416 141 dist = pow((float)x,2)+pow((float)y,2);
trelemar 4:e77580278416 142 dist = sqrt((float)dist);
trelemar 4:e77580278416 143 return dist;
trelemar 4:e77580278416 144 }
trelemar 4:e77580278416 145
trelemar 4:e77580278416 146 int lerp(int a, int b, float t) {
trelemar 4:e77580278416 147 return (1-t)*a + t*b;
trelemar 4:e77580278416 148 }
trelemar 4:e77580278416 149
trelemar 4:e77580278416 150 float lerp(float a, float b, float t) {
trelemar 4:e77580278416 151 return (1-t)*a + t*b;
trelemar 4:e77580278416 152 }
trelemar 4:e77580278416 153
trelemar 4:e77580278416 154 enum GameState {MAIN, PAUSE, MENU} State = MENU;
trelemar 4:e77580278416 155
trelemar 4:e77580278416 156 #define KEY_REPEAT 5
trelemar 4:e77580278416 157
trelemar 4:e77580278416 158 #define TASK_MOVE 0
trelemar 8:976e983ce79a 159 #define TASK_ATTACK 1
trelemar 4:e77580278416 160 #define TASK_ITEM 2
trelemar 4:e77580278416 161 #define TASK_WAIT 3
trelemar 9:682f31473b25 162 #define TASK_SPAWN 4
trelemar 9:682f31473b25 163 #define TASK_NONE 5
trelemar 4:e77580278416 164 #define TEAM_USER 0
trelemar 4:e77580278416 165 #define TEAM_CPU 1
trelemar 4:e77580278416 166
trelemar 4:e77580278416 167 int current_team = TEAM_USER;
trelemar 4:e77580278416 168 uint8_t selected_task = 0;
trelemar 4:e77580278416 169 uint8_t current_task = TASK_NONE;
trelemar 11:4c61319450c8 170 uint8_t game_turn = 1;
trelemar 4:e77580278416 171
trelemar 4:e77580278416 172 static char task_names[4][7] {
trelemar 4:e77580278416 173 {"MOVE"},
trelemar 4:e77580278416 174 {"ATTACK"},
trelemar 4:e77580278416 175 {"TRAIT"},
trelemar 4:e77580278416 176 {"WAIT"},
trelemar 4:e77580278416 177 };
trelemar 4:e77580278416 178 int task_colors[4] {
trelemar 4:e77580278416 179 11,9,6,8
trelemar 4:e77580278416 180 };
trelemar 4:e77580278416 181
trelemar 4:e77580278416 182 int map_x, map_y, cursor_x, cursor_y;
trelemar 4:e77580278416 183
trelemar 4:e77580278416 184 bool center_cursor = true;
trelemar 4:e77580278416 185
trelemar 4:e77580278416 186 void centerCursor() {
trelemar 4:e77580278416 187 map_x = cursor_x - 3;
trelemar 4:e77580278416 188 map_y = cursor_y - 2;
trelemar 4:e77580278416 189 }
trelemar 4:e77580278416 190
trelemar 7:91365e9ad8c6 191 static void print(char text[], uint8_t color) {
trelemar 7:91365e9ad8c6 192 disp.setColor(color);
trelemar 7:91365e9ad8c6 193 disp.print(text);
trelemar 7:91365e9ad8c6 194 }
trelemar 7:91365e9ad8c6 195
trelemar 4:e77580278416 196 static void printb(int x, int y, int text) {
trelemar 4:e77580278416 197 disp.setColor(0);
trelemar 4:e77580278416 198 disp.print(x,y-1,text);
trelemar 4:e77580278416 199 disp.print(x,y+1,text);
trelemar 4:e77580278416 200 disp.print(x+1,y,text);
trelemar 4:e77580278416 201 disp.print(x-1,y,text);
trelemar 4:e77580278416 202 disp.setColor(15);
trelemar 4:e77580278416 203 disp.print(x,y,text);
trelemar 4:e77580278416 204 }
trelemar 4:e77580278416 205 static void printb(int x, int y, char text[]) {
trelemar 4:e77580278416 206 disp.setColor(0);
trelemar 4:e77580278416 207 disp.print(x,y-1,text);
trelemar 4:e77580278416 208 disp.print(x,y+1,text);
trelemar 4:e77580278416 209 disp.print(x+1,y,text);
trelemar 4:e77580278416 210 disp.print(x-1,y,text);
trelemar 4:e77580278416 211 disp.setColor(15);
trelemar 4:e77580278416 212 disp.print(x,y,text);
trelemar 4:e77580278416 213 }
trelemar 4:e77580278416 214
trelemar 4:e77580278416 215 struct Dialog {
trelemar 4:e77580278416 216 char text[20];
trelemar 4:e77580278416 217 int start_time;
trelemar 4:e77580278416 218 int position;
trelemar 4:e77580278416 219 Dialog(char _text[20]) {
trelemar 4:e77580278416 220 strcpy(text, _text);
trelemar 4:e77580278416 221 position = 0;
trelemar 4:e77580278416 222 start_time = game.frameCount;
trelemar 4:e77580278416 223 };
trelemar 4:e77580278416 224 void update() {
trelemar 4:e77580278416 225 position = min(position + 1, 19);
trelemar 4:e77580278416 226 };
trelemar 4:e77580278416 227 void draw(int x, int y) {
trelemar 4:e77580278416 228 disp.setCursor(x, y);
trelemar 4:e77580278416 229 for (int p=0;p<position;p++) {
trelemar 4:e77580278416 230 disp.print(text[p]);
trelemar 4:e77580278416 231 }
trelemar 4:e77580278416 232 };
trelemar 4:e77580278416 233 };
trelemar 4:e77580278416 234
trelemar 4:e77580278416 235 struct Transition {
trelemar 4:e77580278416 236 int on_val, off_val, val;
trelemar 4:e77580278416 237 bool enabled;
trelemar 4:e77580278416 238 Transition() {};
trelemar 4:e77580278416 239 Transition(int _onv, int _offv, bool _enabled) {
trelemar 4:e77580278416 240 on_val = _onv;
trelemar 4:e77580278416 241 off_val = _offv;
trelemar 4:e77580278416 242 enabled = _enabled;
trelemar 4:e77580278416 243 if (enabled) val=on_val;
trelemar 4:e77580278416 244 else val = off_val;
trelemar 4:e77580278416 245 };
trelemar 4:e77580278416 246 void toggle() {enabled=!enabled;};
trelemar 4:e77580278416 247 void update() {
trelemar 4:e77580278416 248 if (enabled) val = lerp(val, on_val, 0.2);
trelemar 4:e77580278416 249 else val = lerp(val, off_val, 0.2);
trelemar 4:e77580278416 250 };
trelemar 4:e77580278416 251 };
trelemar 4:e77580278416 252
trelemar 4:e77580278416 253 struct Vec2 {
trelemar 4:e77580278416 254 int x, y;
trelemar 4:e77580278416 255 Vec2(int _x, int _y) {x=_x; y=_y;};
trelemar 4:e77580278416 256 };
trelemar 4:e77580278416 257
trelemar 4:e77580278416 258 struct Item {
trelemar 4:e77580278416 259 int id, x, y;
trelemar 4:e77580278416 260 Item(int _id, int _x, int _y) {
trelemar 4:e77580278416 261 id = _id;
trelemar 4:e77580278416 262 x = _x;
trelemar 4:e77580278416 263 y = _y;
trelemar 4:e77580278416 264 };
trelemar 4:e77580278416 265 void Draw() {
trelemar 4:e77580278416 266 int dx = (x-map_x)*16;
trelemar 4:e77580278416 267 int dy = (y-map_y)*16;
trelemar 4:e77580278416 268 //disp.setColor(1);
trelemar 4:e77580278416 269 //disp.fillRectangle(dx+4,dy+12,8,3);
trelemar 4:e77580278416 270 //disp.drawBitmap(dx, dy+(sin(game.frameCount/4))*2, sprites[id]);
trelemar 4:e77580278416 271 };
trelemar 4:e77580278416 272 };
trelemar 4:e77580278416 273
trelemar 4:e77580278416 274 #define ID_SOLDIER 0
trelemar 8:976e983ce79a 275 #define ID_HEAVY 1
trelemar 8:976e983ce79a 276 #define ID_SNIPER 2
trelemar 9:682f31473b25 277 #define ID_SUPPORT 3
trelemar 11:4c61319450c8 278 #define ID_HUNTER 4
trelemar 11:4c61319450c8 279 #define ID_WARRIOR 5
trelemar 11:4c61319450c8 280 #define ID_SHAMAN 6
trelemar 4:e77580278416 281
trelemar 4:e77580278416 282 const int sprite_ids[16] {
trelemar 8:976e983ce79a 283 0, //SOLDIER
trelemar 8:976e983ce79a 284 2, //HEAVY
trelemar 8:976e983ce79a 285 4, //SNIPER
trelemar 9:682f31473b25 286 6,
trelemar 11:4c61319450c8 287 9, //HUNTER
trelemar 11:4c61319450c8 288 11, //WARRIOR
trelemar 11:4c61319450c8 289 13, //SHAMAN
trelemar 11:4c61319450c8 290 15, //SPIDER
trelemar 11:4c61319450c8 291 18,
trelemar 11:4c61319450c8 292 20,
trelemar 11:4c61319450c8 293 22,
trelemar 11:4c61319450c8 294 24,
trelemar 4:e77580278416 295 };
trelemar 9:682f31473b25 296 char id_names[][10] {
trelemar 9:682f31473b25 297 //GI-BROS
trelemar 4:e77580278416 298 {"SOLDIER"},
trelemar 8:976e983ce79a 299 {"HEAVY"},
trelemar 8:976e983ce79a 300 {"SNIPER"},
trelemar 9:682f31473b25 301 {"SUPPORT"},
trelemar 9:682f31473b25 302
trelemar 9:682f31473b25 303 //SPACE GRUNKS
trelemar 11:4c61319450c8 304 {"HUNTER"},
trelemar 11:4c61319450c8 305 {"WARRIOR"},
trelemar 11:4c61319450c8 306 {"SHAMAN"},
trelemar 11:4c61319450c8 307 {"SPIDER"},
trelemar 11:4c61319450c8 308
trelemar 11:4c61319450c8 309 //TEAM GLOOM
trelemar 11:4c61319450c8 310 {"BONES"},
trelemar 11:4c61319450c8 311 {"SLIME"},
trelemar 11:4c61319450c8 312 {"KNIGHT"},
trelemar 11:4c61319450c8 313 {"FLYER"},
trelemar 4:e77580278416 314 };
trelemar 9:682f31473b25 315
trelemar 9:682f31473b25 316 char Faction[][14] {
trelemar 9:682f31473b25 317 {"GI-BROS"},
trelemar 12:52184eaf74f4 318 {"SPIDERLINGS"},
trelemar 11:4c61319450c8 319 {"TEAM GLOOM"}
trelemar 9:682f31473b25 320 };
trelemar 9:682f31473b25 321
trelemar 12:52184eaf74f4 322 int Faction_colors[] {
trelemar 12:52184eaf74f4 323 11,
trelemar 12:52184eaf74f4 324 6,
trelemar 12:52184eaf74f4 325 };
trelemar 12:52184eaf74f4 326
trelemar 4:e77580278416 327 char TRAITS[][8] {
trelemar 4:e77580278416 328 {""},
trelemar 4:e77580278416 329 {"FAST"},
trelemar 5:ef209f39269a 330 {"HULKISH"},
trelemar 4:e77580278416 331 };
trelemar 12:52184eaf74f4 332
trelemar 4:e77580278416 333 struct Hero {
trelemar 4:e77580278416 334 unsigned int index, team, id, x, y;
trelemar 4:e77580278416 335 uint8_t atk, def, hp, max_hp;
trelemar 4:e77580278416 336 float range;
trelemar 4:e77580278416 337 int spr;
trelemar 4:e77580278416 338 int hurt_time;
trelemar 4:e77580278416 339 bool tasks[4], flip;
trelemar 4:e77580278416 340 char * traits;
trelemar 4:e77580278416 341 Hero(int _x, int _y, int _id, int _team) {
trelemar 4:e77580278416 342 hurt_time = 0;
trelemar 4:e77580278416 343 x = _x; y = _y; flip = false;
trelemar 4:e77580278416 344 id = _id; team = _team;
trelemar 4:e77580278416 345 if (_team == TEAM_USER) {
trelemar 4:e77580278416 346 }
trelemar 4:e77580278416 347 else {flip=true;}
trelemar 4:e77580278416 348 spr = sprite_ids[id];
trelemar 4:e77580278416 349 max_hp = 10;
trelemar 4:e77580278416 350 atk = 5;
trelemar 4:e77580278416 351 def = 2;
trelemar 4:e77580278416 352 range = 2.1;
trelemar 4:e77580278416 353 if (id == ID_HEAVY) {atk+=3; def++; range-=.5; max_hp+=2;}
trelemar 6:2b8e70d68247 354 if (id == ID_SNIPER) {def--; atk--; range+=1.5; max_hp-=2;}
trelemar 4:e77580278416 355 hp = max_hp;
trelemar 4:e77580278416 356 NewTurn();
trelemar 4:e77580278416 357 };
trelemar 4:e77580278416 358 void NewTurn() {
trelemar 4:e77580278416 359 for (int i=0;i<4;i++) {tasks[i]=true;}
trelemar 4:e77580278416 360 };
trelemar 4:e77580278416 361 void update(int i) {
trelemar 4:e77580278416 362 index = i;
trelemar 4:e77580278416 363 };
trelemar 4:e77580278416 364 void Draw() {
trelemar 4:e77580278416 365 int ox = 0;
trelemar 4:e77580278416 366 int oy = 0;
trelemar 4:e77580278416 367 int dx = (x-map_x)*16;
trelemar 4:e77580278416 368 int dy = (y-map_y)*16;
trelemar 4:e77580278416 369 bool draw = true;
trelemar 4:e77580278416 370 if (game.frameCount-hurt_time<10) {
trelemar 4:e77580278416 371 ox = random(-2,2);
trelemar 4:e77580278416 372 oy = random(-2,2);
trelemar 4:e77580278416 373 if (game.frameCount%2==0) {draw=false;}
trelemar 4:e77580278416 374 }
trelemar 4:e77580278416 375 int spr_id = spr + (game.frameCount/10)%2;
trelemar 4:e77580278416 376 disp.invisiblecolor = 13;
trelemar 8:976e983ce79a 377 if (draw) disp.drawBitmap((dx)+ox,(dy)+oy,hero_sprites[spr_id], 0, flip);
trelemar 4:e77580278416 378 disp.invisiblecolor = 12;
trelemar 5:ef209f39269a 379 if (id==ID_SNIPER&&team==TEAM_USER) {
trelemar 5:ef209f39269a 380 int lx = dx+ox+16;
trelemar 5:ef209f39269a 381 int ly = dy+oy+5;
trelemar 5:ef209f39269a 382 if (game.frameCount/10%2==1) ly++;
trelemar 5:ef209f39269a 383 if (flip) lx-=18;
trelemar 5:ef209f39269a 384
trelemar 5:ef209f39269a 385 disp.setColor(0);
trelemar 5:ef209f39269a 386 disp.drawLine(lx,ly,lx+1,ly);
trelemar 5:ef209f39269a 387 }
trelemar 4:e77580278416 388 };
trelemar 4:e77580278416 389 bool inRange(Hero * enemy) {
trelemar 4:e77580278416 390 return (dist(x, y, enemy->x, enemy->y)<=range);
trelemar 4:e77580278416 391 };
trelemar 4:e77580278416 392 bool inRange(int dx, int dy) {
trelemar 4:e77580278416 393 return (dist(x, y, dx, dy)<=range);
trelemar 4:e77580278416 394 };
trelemar 4:e77580278416 395 void AIhandle(int &ai_index, vector<Hero> &heros) {
trelemar 4:e77580278416 396 Hero * target=NULL;
trelemar 4:e77580278416 397 for (int i=0; i<heros.size(); i++) {
trelemar 4:e77580278416 398 if (inRange(&heros[i])&&tasks[TASK_ATTACK]) {
trelemar 4:e77580278416 399 target = &heros[i];
trelemar 4:e77580278416 400 break;
trelemar 4:e77580278416 401 }
trelemar 4:e77580278416 402 }
trelemar 4:e77580278416 403 if (target!=NULL&&tasks[TASK_ATTACK]) {
trelemar 4:e77580278416 404 target->hurt_time=game.frameCount;
trelemar 4:e77580278416 405 target->hp-= (atk-target->def);
trelemar 4:e77580278416 406 tasks[TASK_ATTACK] = 0;
trelemar 4:e77580278416 407 }
trelemar 4:e77580278416 408 };
trelemar 4:e77580278416 409 };
trelemar 4:e77580278416 410
trelemar 4:e77580278416 411 struct Base {
trelemar 4:e77580278416 412 int x, y, id, team;
trelemar 4:e77580278416 413 int hp;
trelemar 4:e77580278416 414 int spawn_points;
trelemar 9:682f31473b25 415 int faction;
trelemar 4:e77580278416 416 Base() {};
trelemar 9:682f31473b25 417 Base(int _x, int _y, int _id, int _team, int _faction) {
trelemar 4:e77580278416 418 x = _x;
trelemar 4:e77580278416 419 y = _y;
trelemar 4:e77580278416 420 id = _id;
trelemar 4:e77580278416 421 team = _team;
trelemar 9:682f31473b25 422 faction = _faction;
trelemar 5:ef209f39269a 423 spawn_points = 10;
trelemar 4:e77580278416 424 };
trelemar 4:e77580278416 425
trelemar 4:e77580278416 426 void Draw() {
trelemar 4:e77580278416 427 int dx = (x-map_x)*16;
trelemar 4:e77580278416 428 int dy = (y-map_y)*16;
trelemar 4:e77580278416 429 disp.drawBitmap(dx, dy, sprites[id]);
trelemar 11:4c61319450c8 430
trelemar 4:e77580278416 431 };
trelemar 4:e77580278416 432
trelemar 4:e77580278416 433 void Spawn(int x, int y, int id, vector<Hero> &heros) {
trelemar 4:e77580278416 434
trelemar 4:e77580278416 435 };
trelemar 4:e77580278416 436 };
trelemar 4:e77580278416 437
trelemar 4:e77580278416 438 Hero * cursor_hero = NULL;
trelemar 4:e77580278416 439 Hero * current_hero = NULL;
trelemar 4:e77580278416 440 vector<Hero> * hptr;
trelemar 4:e77580278416 441 Base bases[2];
trelemar 4:e77580278416 442 Base * current_base = NULL;
trelemar 4:e77580278416 443
trelemar 11:4c61319450c8 444 void DrawCursorBaseUI(Base * b, int x, int y) {
trelemar 11:4c61319450c8 445
trelemar 11:4c61319450c8 446 }
trelemar 11:4c61319450c8 447
trelemar 4:e77580278416 448 void DrawCursorHeroUI (Hero * h, int x, int y) {
trelemar 4:e77580278416 449 float bw = 24;
trelemar 4:e77580278416 450 float hw = (bw/h->max_hp) * h->hp;
trelemar 4:e77580278416 451 disp.setColor(0);
trelemar 4:e77580278416 452 disp.drawRoundRect(x-1,y-1,bw+2,5,2); //HEALTH BAR
trelemar 4:e77580278416 453 disp.fillRoundRect(x-1, y+26,bw+2,7,2); //TEXT BG BOX
trelemar 4:e77580278416 454 disp.setColor(6);
trelemar 4:e77580278416 455 disp.fillRect(x, y, bw, 2);
trelemar 4:e77580278416 456 disp.setColor(11);
trelemar 4:e77580278416 457 disp.fillRect(x, y, hw, 2);
trelemar 4:e77580278416 458 disp.setColor(11);
trelemar 4:e77580278416 459 disp.print(x,y+27,"^");
trelemar 4:e77580278416 460 disp.setColor(15);
trelemar 4:e77580278416 461 disp.print((int)h->atk);
trelemar 4:e77580278416 462 disp.setColor(6);
trelemar 4:e77580278416 463 disp.print("n");
trelemar 4:e77580278416 464 disp.setColor(15);
trelemar 4:e77580278416 465 disp.print((int)h->def);
trelemar 4:e77580278416 466 }
trelemar 11:4c61319450c8 467 //COLORS FOR EACH TEIR OF HERO
trelemar 11:4c61319450c8 468 int prog_colors[4] {
trelemar 11:4c61319450c8 469 14,9,11,8
trelemar 11:4c61319450c8 470 };
trelemar 4:e77580278416 471
trelemar 4:e77580278416 472 void DrawSelectedBaseUI(Base * base, int y) {
trelemar 4:e77580278416 473 disp.setColor(0);
trelemar 11:4c61319450c8 474 disp.fillRoundRect(1,y-5,SW-28,88-68+6,3);
trelemar 4:e77580278416 475 if (!base) return;
trelemar 7:91365e9ad8c6 476 disp.setColor(15);
trelemar 11:4c61319450c8 477
trelemar 11:4c61319450c8 478 disp.print(3,y-4,id_names[(base->faction*4)+selected_task]);
trelemar 9:682f31473b25 479
trelemar 11:4c61319450c8 480 disp.setCursor(SW-28-(6*4), y-4);
trelemar 11:4c61319450c8 481 disp.setColor(prog_colors[selected_task]);
trelemar 11:4c61319450c8 482 disp.print(2+(selected_task*2));
trelemar 11:4c61319450c8 483 disp.print(" SP");
trelemar 9:682f31473b25 484
trelemar 11:4c61319450c8 485 disp.setColor(15);
trelemar 11:4c61319450c8 486 printb(18,(-y)+68,Faction[base->faction]);
trelemar 11:4c61319450c8 487 printb(18,(-y)+75, "BASE");
trelemar 11:4c61319450c8 488
trelemar 9:682f31473b25 489 for (int i=0; i<4; i++) {
trelemar 11:4c61319450c8 490 disp.invisiblecolor = 13;
trelemar 9:682f31473b25 491 int spr = (base->faction*9)+(i*2);
trelemar 10:c1af7a94f3f9 492 int x = 3+i*20;
trelemar 9:682f31473b25 493 disp.setColor(15);
trelemar 9:682f31473b25 494 if (i==selected_task) {
trelemar 11:4c61319450c8 495 disp.fillRect(x+1,y+3,16,15);
trelemar 9:682f31473b25 496 }
trelemar 9:682f31473b25 497 disp.drawBitmap(x,y+3,hero_sprites[spr]);
trelemar 11:4c61319450c8 498 disp.setColor(prog_colors[i]);
trelemar 11:4c61319450c8 499 disp.drawRoundRect(x,y+2,18,18, 3);
trelemar 9:682f31473b25 500 }
trelemar 4:e77580278416 501 }
trelemar 4:e77580278416 502
trelemar 4:e77580278416 503 void DrawSelectedHeroUI(Hero * h, int y) {
trelemar 4:e77580278416 504 disp.setColor(0);
trelemar 4:e77580278416 505 //disp.fillRect(0,66,SW,88-66);
trelemar 4:e77580278416 506 disp.fillRoundRect(1,y,SW-2,88-67,3);
trelemar 4:e77580278416 507 //disp.setColor(15);
trelemar 4:e77580278416 508 if (!h) return;
trelemar 4:e77580278416 509 disp.setColor(8);
trelemar 4:e77580278416 510 disp.print(3,y+3,">");
trelemar 4:e77580278416 511 disp.setColor(15);
trelemar 4:e77580278416 512 disp.print((int)h->atk);
trelemar 4:e77580278416 513 disp.print(" ATK");
trelemar 4:e77580278416 514 disp.setColor(6);
trelemar 4:e77580278416 515 disp.print(3,y+9,"n");
trelemar 4:e77580278416 516 disp.setColor(15);
trelemar 4:e77580278416 517 disp.print((int)h->def);
trelemar 4:e77580278416 518 disp.print(" DEF");
trelemar 4:e77580278416 519 disp.setColor(11);
trelemar 4:e77580278416 520 disp.print(3,y+15,"^");
trelemar 4:e77580278416 521 disp.setColor(15);
trelemar 4:e77580278416 522 disp.print((int)h->range);
trelemar 4:e77580278416 523 disp.print(" RNG");
trelemar 11:4c61319450c8 524 printb(18,(-y)+68,task_names[selected_task]);
trelemar 4:e77580278416 525
trelemar 4:e77580278416 526 for (int i=0;i<4;i++) {
trelemar 8:976e983ce79a 527 int spr = i+8;
trelemar 4:e77580278416 528 if (!h->tasks[i]) spr-=8;
trelemar 4:e77580278416 529 else if (selected_task==i) spr+=8;
trelemar 8:976e983ce79a 530 disp.drawBitmap(44+(i*16), y+4, ui_sprites[spr]);
trelemar 4:e77580278416 531 }
trelemar 4:e77580278416 532 int bw = 62;
trelemar 4:e77580278416 533 int hw = (bw/h->max_hp) * h->hp;
trelemar 4:e77580278416 534 disp.setColor(0);
trelemar 4:e77580278416 535 disp.drawRoundRect(44,y-4,bw+2,7,3);
trelemar 4:e77580278416 536 disp.setColor(6);
trelemar 4:e77580278416 537 disp.fillRoundRect(45,y-3,bw,5,2);
trelemar 4:e77580278416 538 disp.setColor(11);
trelemar 4:e77580278416 539 disp.fillRoundRect(45,y-3,hw+2,5,2);
trelemar 4:e77580278416 540 disp.setColor(15);
trelemar 4:e77580278416 541 printb(50+(bw/2)-10,y-3,(int)h->hp);
trelemar 11:4c61319450c8 542
trelemar 11:4c61319450c8 543 printb(3,y-3,id_names[h->id]);
trelemar 4:e77580278416 544 }
trelemar 4:e77580278416 545
trelemar 4:e77580278416 546 void DrawTraitList(Hero * h, int x) {
trelemar 4:e77580278416 547 //disp.setColor(0);
trelemar 4:e77580278416 548 //disp.fillRoundRect(32,y,SW-63,12,3);
trelemar 4:e77580278416 549 //disp.setColor(15);
trelemar 4:e77580278416 550 //for (int i = 0; i<4; i++) {
trelemar 4:e77580278416 551 //disp.drawRoundRect(34+(i*11),y+1,10,10,2);
trelemar 4:e77580278416 552 //}
trelemar 4:e77580278416 553 int y = 17;
trelemar 4:e77580278416 554 disp.setColor(0);
trelemar 4:e77580278416 555 disp.fillRoundRect(x, y-1, 12, 45, 3);
trelemar 4:e77580278416 556 disp.setColor(15);
trelemar 4:e77580278416 557 for (int i=0; i<4; i++) {
trelemar 4:e77580278416 558 disp.drawRoundRect(x+1,y+(i*11), 10, 10, 2);
trelemar 4:e77580278416 559 }
trelemar 4:e77580278416 560 disp.print(x+4,y+2, "f");
trelemar 4:e77580278416 561 if (selected_task!=TASK_ITEM) return;
trelemar 4:e77580278416 562 disp.setColor(0);
trelemar 4:e77580278416 563
trelemar 4:e77580278416 564 disp.fillRoundRect(x+13, y-1+6, 64, 6*3+1, 3);
trelemar 4:e77580278416 565 disp.setColor(15);
trelemar 4:e77580278416 566 //disp.print(x+28,y,"~WIMP~");
trelemar 4:e77580278416 567 printb(x+14,y,"< ~HULKISH~");
trelemar 4:e77580278416 568 disp.setColor(7);
trelemar 4:e77580278416 569 disp.print(x+15, y+6, "MOVEMENT");
trelemar 4:e77580278416 570 disp.setColor(6);
trelemar 4:e77580278416 571 disp.print("nn");
trelemar 4:e77580278416 572 disp.setColor(7);
trelemar 4:e77580278416 573 disp.print(x+15, y+12, "MAX HP");
trelemar 4:e77580278416 574 disp.setColor(11);
trelemar 4:e77580278416 575 disp.print("^^");
trelemar 4:e77580278416 576 disp.setColor(7);
trelemar 4:e77580278416 577 disp.print(x+15, y+18, "^ATK ^DEF");
trelemar 4:e77580278416 578 }
trelemar 4:e77580278416 579
trelemar 4:e77580278416 580 void DrawTurnCounter(vector<Hero> &_heros) {
trelemar 4:e77580278416 581 disp.invisiblecolor = 13;
trelemar 11:4c61319450c8 582 int spr = 32+bases[current_team].faction;
trelemar 8:976e983ce79a 583 disp.drawBitmap(0, 0, ui_sprites[spr]);
trelemar 4:e77580278416 584 disp.invisiblecolor = 12;
trelemar 4:e77580278416 585 int count = 0;
trelemar 4:e77580278416 586 for (int i=0; i<_heros.size();i++) {
trelemar 4:e77580278416 587 if (_heros[i].team == current_team) count++;
trelemar 4:e77580278416 588 }
trelemar 4:e77580278416 589 printb(11,10,(int)count);
trelemar 11:4c61319450c8 590
trelemar 4:e77580278416 591 }
trelemar 4:e77580278416 592
trelemar 11:4c61319450c8 593
trelemar 4:e77580278416 594 #define MAP_WIDTH 12
trelemar 4:e77580278416 595 #define MAP_HEIGHT 12
trelemar 6:2b8e70d68247 596 int Map[MAP_HEIGHT][MAP_WIDTH] {
trelemar 6:2b8e70d68247 597 {0,8,0,5,10,8,8,1,8,8,0,8},
trelemar 6:2b8e70d68247 598 {1,0,0,21,15,14,8,0,8,0,1,0},
trelemar 6:2b8e70d68247 599 {0,8,0,8,10,5,8,8,0,9,8,8},
trelemar 6:2b8e70d68247 600 {0,1,8,0,10,5,1,8,8,8,0,8},
trelemar 6:2b8e70d68247 601 {8,0,9,0,18,7,3,3,3,4,8,1},
trelemar 6:2b8e70d68247 602 {0,8,8,0,0,5,0,0,0,12,8,13},
trelemar 6:2b8e70d68247 603 {0,0,1,8,8,5,8,1,8,11,0,5},
trelemar 6:2b8e70d68247 604 {8,0,8,0,8,5,8,0,0,10,0,5},
trelemar 6:2b8e70d68247 605 {8,8,0,8,1,21,6,30,6,15,6,22},
trelemar 6:2b8e70d68247 606 {8,0,0,8,8,0,0,5,8,12,0,0},
trelemar 6:2b8e70d68247 607 {0,1,8,9,0,8,1,5,8,18,3,3},
trelemar 6:2b8e70d68247 608 {0,0,8,8,8,8,0,5,8,0,8,0},
trelemar 6:2b8e70d68247 609 };
trelemar 4:e77580278416 610
trelemar 4:e77580278416 611 void loadTileMap(char * filename) {
trelemar 7:91365e9ad8c6 612 disp.enableDirectPrinting(true);
trelemar 4:e77580278416 613 disp.fillLCD(disp.palette[0]);
trelemar 8:976e983ce79a 614 disp.directBitmap(110-16,176/2-16,ui_sprites[7],4,2);
trelemar 7:91365e9ad8c6 615 disp.directbgcolor = disp.palette[0];
trelemar 7:91365e9ad8c6 616 disp.fontSize = 2;
trelemar 7:91365e9ad8c6 617 disp.directcolor = disp.palette[15];
trelemar 8:976e983ce79a 618 disp.print(24,164,"LOADING CONTENT");
trelemar 4:e77580278416 619 int inc = 220/144;
trelemar 4:e77580278416 620 #ifdef POK_SIM
trelemar 4:e77580278416 621 game.wait(20);
trelemar 4:e77580278416 622 #endif
trelemar 6:2b8e70d68247 623
trelemar 4:e77580278416 624 pokInitSD();
trelemar 6:2b8e70d68247 625 int success = fileOpen(filename,FILE_MODE_BINARY);
trelemar 7:91365e9ad8c6 626 if (!isThisFileOpen(filename)) {
trelemar 7:91365e9ad8c6 627 disp.directcolor = disp.palette[6];
trelemar 7:91365e9ad8c6 628 disp.print(0,16,"SD LOADING ERROR");
trelemar 7:91365e9ad8c6 629 while (!btn.aBtn()) {
trelemar 7:91365e9ad8c6 630 game.wait(100);
trelemar 7:91365e9ad8c6 631 }
trelemar 7:91365e9ad8c6 632 }
trelemar 4:e77580278416 633 for (int i = 0; i<144; i++) {
trelemar 4:e77580278416 634 int x = i%MAP_WIDTH;
trelemar 4:e77580278416 635 int y = (i-x)/MAP_WIDTH;
trelemar 4:e77580278416 636 //fileSetPosition(i);
trelemar 4:e77580278416 637 Map[y][x] = (int)filePeek(i);
trelemar 4:e77580278416 638 #ifdef POK_SIM
trelemar 4:e77580278416 639 game.wait(10);
trelemar 4:e77580278416 640 #endif // POK_SIM
trelemar 4:e77580278416 641 disp.directRectangle(inc*(i*2),0,inc,8,disp.palette[15]);
trelemar 4:e77580278416 642 }
trelemar 4:e77580278416 643 fileClose();
trelemar 7:91365e9ad8c6 644 disp.enableDirectPrinting(false);
trelemar 4:e77580278416 645 }
trelemar 4:e77580278416 646
trelemar 4:e77580278416 647 void saveTileMap() {
trelemar 4:e77580278416 648
trelemar 4:e77580278416 649 }
trelemar 4:e77580278416 650
trelemar 4:e77580278416 651 void DrawTileMap(int8_t x, int8_t y, Hero * hero) {
trelemar 4:e77580278416 652 disp.setColor(15);
trelemar 4:e77580278416 653 for (int map_x=0; map_x<7; map_x++) {
trelemar 4:e77580278416 654 for (int map_y=0; map_y<6; map_y++) {
trelemar 4:e77580278416 655 int spr;
trelemar 4:e77580278416 656 if (map_x+x<0||x+map_x>MAP_WIDTH-1||y+map_y<0||y+map_y>MAP_HEIGHT-1) {
trelemar 4:e77580278416 657 spr = 9;
trelemar 4:e77580278416 658 }
trelemar 4:e77580278416 659 else {
trelemar 4:e77580278416 660 spr = Map[map_y+y][map_x+x];
trelemar 4:e77580278416 661 }
trelemar 4:e77580278416 662
trelemar 4:e77580278416 663 float distance;
trelemar 4:e77580278416 664
trelemar 4:e77580278416 665 disp.drawBitmap((map_x*16), (map_y*16),sprites[spr]);
trelemar 4:e77580278416 666
trelemar 4:e77580278416 667 //RANGE BOXES
trelemar 4:e77580278416 668 if (hero && (current_task == TASK_MOVE || current_task == TASK_ATTACK)) {
trelemar 4:e77580278416 669 distance = dist(map_x+x, map_y+y, hero->x, hero->y);
trelemar 9:682f31473b25 670 if (distance<hero->range&&x+map_x<MAP_WIDTH&&y+map_y<MAP_HEIGHT&&x+map_x>=0&&y+map_y>=0) {
trelemar 4:e77580278416 671 disp.setColor(8);
trelemar 4:e77580278416 672 if (solids[Map[map_y+y][map_x+x]]) {disp.setColor(6);}
trelemar 4:e77580278416 673 disp.drawRoundRect(map_x*16+2, map_y*16+2, 12, 12,3);
trelemar 4:e77580278416 674 //disp.print(map_x*16,map_y*16,(float)distance);
trelemar 4:e77580278416 675 }
trelemar 4:e77580278416 676 }
trelemar 4:e77580278416 677 }
trelemar 4:e77580278416 678 }
trelemar 4:e77580278416 679 }
trelemar 4:e77580278416 680
trelemar 11:4c61319450c8 681 void showRoundScreen() {
trelemar 11:4c61319450c8 682 disp.clear();
trelemar 11:4c61319450c8 683 DrawTileMap(map_x, map_y, current_hero);
trelemar 12:52184eaf74f4 684 disp.load565Palette(sprite_pal);
trelemar 11:4c61319450c8 685 disp.update();
trelemar 12:52184eaf74f4 686 disp.textWrap = false;
trelemar 12:52184eaf74f4 687 disp.enableDirectPrinting(false);
trelemar 11:4c61319450c8 688
trelemar 12:52184eaf74f4 689 for (int frame = 0; frame< 140; frame++) {
trelemar 12:52184eaf74f4 690 disp.setColor(0);
trelemar 12:52184eaf74f4 691 if (frame<6) {
trelemar 12:52184eaf74f4 692 disp.drawLine(0,SH/2+frame, SW, SH/2+frame);
trelemar 12:52184eaf74f4 693 disp.drawLine(0,SH/2-frame, SW, SH/2-frame);
trelemar 11:4c61319450c8 694 }
trelemar 12:52184eaf74f4 695 else if (frame>=6) {
trelemar 12:52184eaf74f4 696 disp.setColor(0);
trelemar 12:52184eaf74f4 697 disp.fillRect(0,SH/2-6, SW, 12);
trelemar 12:52184eaf74f4 698 disp.setColor(15);
trelemar 12:52184eaf74f4 699 disp.setCursor(frame-6-(6*7), (SH/2)-5);
trelemar 12:52184eaf74f4 700 disp.setColor(10);
trelemar 12:52184eaf74f4 701 disp.print("> ROUND ");
trelemar 12:52184eaf74f4 702 disp.setColor(15);
trelemar 12:52184eaf74f4 703 disp.print((int)game_turn/2);
trelemar 12:52184eaf74f4 704 disp.setCursor(SW+6-frame, (SH/2)+1);
trelemar 12:52184eaf74f4 705 disp.setColor(Faction_colors[current_team]);
trelemar 12:52184eaf74f4 706 disp.print(Faction[current_team]);
trelemar 12:52184eaf74f4 707 disp.setColor(10);
trelemar 12:52184eaf74f4 708 disp.print(" TURN <");
trelemar 12:52184eaf74f4 709 }
trelemar 12:52184eaf74f4 710
trelemar 11:4c61319450c8 711 disp.update();
trelemar 11:4c61319450c8 712 //game.wait(2);
trelemar 11:4c61319450c8 713 }
trelemar 11:4c61319450c8 714
trelemar 12:52184eaf74f4 715 disp.textWrap = true;
trelemar 11:4c61319450c8 716 }
trelemar 11:4c61319450c8 717
trelemar 4:e77580278416 718 void DrawCursor(int x, int y) {
trelemar 4:e77580278416 719 //uint8_t spr = 52 + (game.frameCount/12)%2;
trelemar 4:e77580278416 720 disp.drawBitmap(x*16-3, y*16-3,cursor_sprites[(game.frameCount/4)%2]);
trelemar 4:e77580278416 721 }
trelemar 4:e77580278416 722
trelemar 4:e77580278416 723 Hero * getHeroAtCoords(int x, int y, vector<Hero> &herovect) {
trelemar 4:e77580278416 724 Hero *h = NULL;
trelemar 4:e77580278416 725 bool found = false;
trelemar 4:e77580278416 726 for (int i=0;i<herovect.size();i++) {
trelemar 4:e77580278416 727 if (herovect[i].x==x&&herovect[i].y==y) {
trelemar 4:e77580278416 728 h = &herovect[i];
trelemar 4:e77580278416 729 break;
trelemar 4:e77580278416 730 }
trelemar 4:e77580278416 731 }
trelemar 4:e77580278416 732 return h;
trelemar 4:e77580278416 733 }
trelemar 4:e77580278416 734
trelemar 4:e77580278416 735
trelemar 4:e77580278416 736
trelemar 4:e77580278416 737 void CursorInput() {
trelemar 4:e77580278416 738 int last_x=cursor_x;
trelemar 4:e77580278416 739 int last_y=cursor_y;
trelemar 4:e77580278416 740 if (btn.repeat(BTN_UP,KEY_REPEAT)) {
trelemar 4:e77580278416 741 if (cursor_y-map_y<=0) {
trelemar 4:e77580278416 742 map_y=max(map_y-1,0);
trelemar 4:e77580278416 743 }
trelemar 4:e77580278416 744 cursor_y=max(cursor_y-1,0);
trelemar 4:e77580278416 745 }
trelemar 4:e77580278416 746 if (btn.repeat(BTN_DOWN,KEY_REPEAT)) {
trelemar 4:e77580278416 747 if (cursor_y-map_y>=4) {
trelemar 4:e77580278416 748 map_y=min(map_y+1,MAP_HEIGHT-6);
trelemar 4:e77580278416 749 }
trelemar 4:e77580278416 750 cursor_y=min(cursor_y+1,MAP_HEIGHT-1);
trelemar 4:e77580278416 751
trelemar 4:e77580278416 752 }
trelemar 4:e77580278416 753 if (btn.repeat(BTN_LEFT,KEY_REPEAT)) {
trelemar 4:e77580278416 754 if (cursor_x-map_x<=0) {
trelemar 4:e77580278416 755 map_x=max(map_x-1,0);
trelemar 4:e77580278416 756 }
trelemar 4:e77580278416 757 cursor_x=max(cursor_x-1,0);
trelemar 4:e77580278416 758 }
trelemar 4:e77580278416 759 if (btn.repeat(BTN_RIGHT,KEY_REPEAT)) {
trelemar 4:e77580278416 760 if (cursor_x-map_x>=6) {
trelemar 4:e77580278416 761 map_x=min(map_x+1,MAP_WIDTH-7);
trelemar 4:e77580278416 762 }
trelemar 4:e77580278416 763 cursor_x=min(cursor_x+1,MAP_WIDTH-1);
trelemar 4:e77580278416 764 }
trelemar 4:e77580278416 765
trelemar 4:e77580278416 766 if (center_cursor) {
trelemar 4:e77580278416 767 centerCursor();
trelemar 4:e77580278416 768 }
trelemar 4:e77580278416 769 }
trelemar 4:e77580278416 770
trelemar 4:e77580278416 771 struct PauseMenu {
trelemar 4:e77580278416 772 char items[3][12];
trelemar 4:e77580278416 773 unsigned int selected_item;
trelemar 4:e77580278416 774 Transition lb; //letterbox
trelemar 4:e77580278416 775 PauseMenu() {
trelemar 4:e77580278416 776 lb.off_val=0;
trelemar 4:e77580278416 777 lb.on_val=16;
trelemar 4:e77580278416 778 lb.enabled=true;
trelemar 4:e77580278416 779 lb.val = lb.off_val;
trelemar 4:e77580278416 780 selected_item = 0;
trelemar 4:e77580278416 781 strcpy(items[0], "RESUME");
trelemar 4:e77580278416 782 strcpy(items[1], "END TURN");
trelemar 4:e77580278416 783 strcpy(items[2], "QUIT GAME");
trelemar 4:e77580278416 784 };
trelemar 4:e77580278416 785 void endTurn(vector<Hero> * _heros) {
trelemar 4:e77580278416 786 for (int i=0; i<0+_heros->size(); i++) {
trelemar 4:e77580278416 787 _heros->at(i).NewTurn();
trelemar 4:e77580278416 788 }
trelemar 11:4c61319450c8 789 game_turn++;
trelemar 4:e77580278416 790 };
trelemar 4:e77580278416 791 void update() {
trelemar 4:e77580278416 792 lb.update();
trelemar 4:e77580278416 793 for (int i = 1; i<15; i++) {
trelemar 4:e77580278416 794 disp.palette[i] = disp.interpolateColor(disp.palette[i],dark_pal[i], 80);
trelemar 4:e77580278416 795 }
trelemar 4:e77580278416 796 if (btn.pressed(BTN_DOWN)) {
trelemar 4:e77580278416 797 selected_item++;
trelemar 4:e77580278416 798 selected_item%=3;
trelemar 4:e77580278416 799 }
trelemar 4:e77580278416 800 else if (btn.pressed(BTN_UP)) {
trelemar 4:e77580278416 801 selected_item--;
trelemar 4:e77580278416 802 selected_item%=3;
trelemar 4:e77580278416 803 }
trelemar 4:e77580278416 804
trelemar 4:e77580278416 805 if (btn.pressed(BTN_A)) {
trelemar 4:e77580278416 806 lb.val = lb.off_val;
trelemar 11:4c61319450c8 807 //disp.load565Palette(sprite_pal);
trelemar 4:e77580278416 808 switch (selected_item) {
trelemar 4:e77580278416 809 case 0:
trelemar 4:e77580278416 810 State = MAIN;
trelemar 4:e77580278416 811 break;
trelemar 4:e77580278416 812 case 1:
trelemar 4:e77580278416 813 current_team=(current_team+1) % 2;
trelemar 4:e77580278416 814 endTurn(hptr);
trelemar 4:e77580278416 815 State = MAIN;
trelemar 11:4c61319450c8 816 showRoundScreen();
trelemar 4:e77580278416 817 break;
trelemar 4:e77580278416 818 case 2:
trelemar 4:e77580278416 819 State = MENU;
trelemar 4:e77580278416 820 break;
trelemar 4:e77580278416 821 }
trelemar 4:e77580278416 822 }
trelemar 4:e77580278416 823 };
trelemar 4:e77580278416 824 void draw() {
trelemar 4:e77580278416 825 //disp.fillRoundRect()
trelemar 4:e77580278416 826 DrawTileMap(map_x, map_y, current_hero);
trelemar 4:e77580278416 827 disp.setColor(0);
trelemar 4:e77580278416 828 disp.fillRect(0,0,SW,lb.val);
trelemar 4:e77580278416 829 disp.fillRect(0,SH-lb.val,SW,lb.on_val);
trelemar 4:e77580278416 830 disp.setColor(15);
trelemar 4:e77580278416 831 disp.setCursor(0,lb.val+2);
trelemar 4:e77580278416 832 disp.println("PAUSED");
trelemar 4:e77580278416 833 disp.print("CURRENT TEAM ");
trelemar 4:e77580278416 834 disp.println(current_team);
trelemar 4:e77580278416 835 disp.println(selected_item);
trelemar 4:e77580278416 836 for (int i=0;i<3; i++) {
trelemar 4:e77580278416 837 int color = 3;
trelemar 4:e77580278416 838 if (selected_item==i) {
trelemar 4:e77580278416 839 color = 15;
trelemar 4:e77580278416 840 }
trelemar 4:e77580278416 841 disp.setColor(0);
trelemar 4:e77580278416 842 disp.print(32, 33+ (i*6), items[i]);
trelemar 4:e77580278416 843 disp.setColor(color);
trelemar 4:e77580278416 844 disp.print(32, 32+ (i*6), items[i]);
trelemar 4:e77580278416 845 }
trelemar 4:e77580278416 846 };
trelemar 4:e77580278416 847 };
trelemar 4:e77580278416 848
trelemar 4:e77580278416 849 struct LevelList {
trelemar 4:e77580278416 850 int pos;
trelemar 4:e77580278416 851 int files;
trelemar 4:e77580278416 852 char * fname;
trelemar 4:e77580278416 853 void init() {
trelemar 4:e77580278416 854 pokInitSD();
trelemar 4:e77580278416 855 pos = 0;
trelemar 4:e77580278416 856 files = 0;
trelemar 4:e77580278416 857 fname = getFirstFile("war");
trelemar 4:e77580278416 858 files++;
trelemar 4:e77580278416 859 while(fname!=NULL) {
trelemar 4:e77580278416 860 fname = getNextFile("war");
trelemar 4:e77580278416 861 files++;
trelemar 4:e77580278416 862 }
trelemar 4:e77580278416 863 fname = getFirstFile("war");
trelemar 4:e77580278416 864 };
trelemar 4:e77580278416 865
trelemar 4:e77580278416 866 void update() {
trelemar 4:e77580278416 867 if (btn.pressed(BTN_DOWN)) {
trelemar 4:e77580278416 868 fname = getNextFile("war");
trelemar 4:e77580278416 869 if (fname==NULL) {
trelemar 4:e77580278416 870 fname = getFirstFile("war");
trelemar 4:e77580278416 871 }
trelemar 4:e77580278416 872 }
trelemar 4:e77580278416 873 if (btn.pressed(BTN_A)&&fname!=NULL) {
trelemar 4:e77580278416 874 loadTileMap(fname);
trelemar 4:e77580278416 875 }
trelemar 4:e77580278416 876 };
trelemar 4:e77580278416 877 void draw() {
trelemar 4:e77580278416 878 disp.setFont(font5x7);
trelemar 4:e77580278416 879 disp.bgcolor=0;
trelemar 4:e77580278416 880 disp.clear();
trelemar 4:e77580278416 881 disp.setColor(15);
trelemar 4:e77580278416 882 disp.setCursor(2,2);
trelemar 4:e77580278416 883 disp.print((int)files);
trelemar 4:e77580278416 884 disp.print(" MAPS FOUND");
trelemar 4:e77580278416 885 disp.print(2,SH/2-3, fname);
trelemar 4:e77580278416 886 disp.setFont(fontWAR);
trelemar 4:e77580278416 887
trelemar 4:e77580278416 888 disp.bgcolor = 12;
trelemar 4:e77580278416 889 };
trelemar 4:e77580278416 890
trelemar 4:e77580278416 891 };
trelemar 4:e77580278416 892 #define MENU_STATE_MAIN 0
trelemar 4:e77580278416 893 #define MENU_STATE_LEVEL 1
trelemar 4:e77580278416 894 struct MainMenu {
trelemar 4:e77580278416 895 int state;
trelemar 4:e77580278416 896 struct Transition trans;
trelemar 4:e77580278416 897 char items[3][10];
trelemar 4:e77580278416 898 int selected_item;
trelemar 4:e77580278416 899 int box_x;
trelemar 4:e77580278416 900 int box_target;
trelemar 4:e77580278416 901 MainMenu() {
trelemar 4:e77580278416 902 state = MENU_STATE_MAIN;
trelemar 4:e77580278416 903 box_x = 0;
trelemar 4:e77580278416 904 box_target = 0;
trelemar 4:e77580278416 905 trans.off_val=SH+16;
trelemar 4:e77580278416 906 trans.on_val = SH-12;
trelemar 4:e77580278416 907 trans.val=trans.off_val;
trelemar 4:e77580278416 908 trans.enabled=true;
trelemar 4:e77580278416 909 strcpy(items[0], "CAMPAIGN");
trelemar 4:e77580278416 910 strcpy(items[1], "SKIRMISH");
trelemar 4:e77580278416 911 strcpy(items[2], "OPTIONS");
trelemar 11:4c61319450c8 912 selected_item = 1;
trelemar 4:e77580278416 913 };
trelemar 4:e77580278416 914 void update(LevelList *l) {
trelemar 4:e77580278416 915 switch (state) {
trelemar 4:e77580278416 916 case MENU_STATE_MAIN:
trelemar 4:e77580278416 917 box_x = lerp(box_x, box_target, 0.50);
trelemar 4:e77580278416 918 trans.update();
trelemar 4:e77580278416 919 if (btn.pressed(BTN_RIGHT)) {
trelemar 4:e77580278416 920 selected_item = min(selected_item + 1, 2);
trelemar 4:e77580278416 921 trans.val=trans.off_val;
trelemar 4:e77580278416 922 }
trelemar 4:e77580278416 923 if (btn.pressed(BTN_LEFT)) {
trelemar 4:e77580278416 924 selected_item = max(selected_item - 1, 0);
trelemar 4:e77580278416 925 trans.val=trans.off_val;
trelemar 4:e77580278416 926 }
trelemar 4:e77580278416 927
trelemar 4:e77580278416 928 if (btn.pressed(BTN_A)) {
trelemar 4:e77580278416 929 switch (selected_item){
trelemar 4:e77580278416 930 case (0): //CAMPAIGN
trelemar 4:e77580278416 931 break;
trelemar 4:e77580278416 932 case (1): //SKIRMISH
trelemar 4:e77580278416 933 disp.clear();
trelemar 4:e77580278416 934 disp.print("LOADING");
trelemar 4:e77580278416 935 pokInitSD();
trelemar 7:91365e9ad8c6 936 loadTileMap("file_out.war");
trelemar 4:e77580278416 937 State = MAIN;
trelemar 4:e77580278416 938 break;
trelemar 4:e77580278416 939 case (2): //OPTIONS
trelemar 4:e77580278416 940 state = MENU_STATE_LEVEL;
trelemar 4:e77580278416 941 break;
trelemar 4:e77580278416 942 }
trelemar 4:e77580278416 943 }
trelemar 4:e77580278416 944 break;
trelemar 4:e77580278416 945 case (MENU_STATE_LEVEL):
trelemar 4:e77580278416 946 if (btn.pressed(BTN_B)) {
trelemar 4:e77580278416 947 state = MENU_STATE_MAIN;
trelemar 4:e77580278416 948 }
trelemar 4:e77580278416 949 l->update();
trelemar 4:e77580278416 950 break;
trelemar 4:e77580278416 951 }//SWITCH
trelemar 4:e77580278416 952 };
trelemar 4:e77580278416 953 void draw(LevelList *l) {
trelemar 4:e77580278416 954 switch (state) {
trelemar 4:e77580278416 955 case (MENU_STATE_MAIN):
trelemar 4:e77580278416 956 disp.bgcolor=0;
trelemar 4:e77580278416 957 disp.clear();
trelemar 4:e77580278416 958 disp.setColor(15);
trelemar 4:e77580278416 959 disp.print(2,2,"POKIT WARS");
trelemar 4:e77580278416 960 disp.setColor(15);
trelemar 4:e77580278416 961 disp.print(SW/2-(strlen(items[selected_item])*6/2),trans.val, items[selected_item]);
trelemar 4:e77580278416 962 disp.fillRoundRect(box_x, SH/2, 16, 16,2);
trelemar 4:e77580278416 963 for (int i=0; i<3; i++) {
trelemar 4:e77580278416 964 int x = (SW/4)*(i+1)-8;
trelemar 8:976e983ce79a 965 int spr = 4+i;
trelemar 4:e77580278416 966 if (i==selected_item) {
trelemar 4:e77580278416 967 box_target = x;
trelemar 4:e77580278416 968 if (box_x-2<x&&box_x+2>x) {
trelemar 4:e77580278416 969 box_x = x;
trelemar 4:e77580278416 970 }
trelemar 4:e77580278416 971 }
trelemar 8:976e983ce79a 972 disp.drawBitmap(x, SH/2, ui_sprites[spr]);
trelemar 4:e77580278416 973 }
trelemar 4:e77580278416 974 disp.bgcolor=12;
trelemar 4:e77580278416 975 break;
trelemar 4:e77580278416 976 case (MENU_STATE_LEVEL):
trelemar 4:e77580278416 977 l->draw();
trelemar 4:e77580278416 978 break;
trelemar 4:e77580278416 979 }//SWITCH
trelemar 4:e77580278416 980 };
trelemar 4:e77580278416 981 };
trelemar 4:e77580278416 982
trelemar 4:e77580278416 983 int main() {
trelemar 4:e77580278416 984 MainMenu main_menu;
trelemar 4:e77580278416 985 PauseMenu pause_menu;
trelemar 4:e77580278416 986 Transition tTrans(66,96,false);
trelemar 4:e77580278416 987 Transition itemlist(1,-16,false);
trelemar 4:e77580278416 988 game.begin();
trelemar 4:e77580278416 989 game.initClock();
trelemar 4:e77580278416 990 game.initRandom();
trelemar 4:e77580278416 991 game.setFrameRate(30);
trelemar 4:e77580278416 992 disp.invisiblecolor = 12;
trelemar 4:e77580278416 993 disp.bgcolor=12;
trelemar 4:e77580278416 994 disp.persistence = 1;
trelemar 4:e77580278416 995 disp.directbgcolor = disp.palette[0];
trelemar 4:e77580278416 996 disp.directcolor = disp.palette[15];
trelemar 4:e77580278416 997 disp.load565Palette(sprite_pal);
trelemar 4:e77580278416 998 disp.textWrap=false;
trelemar 4:e77580278416 999 init_dark_palette();
trelemar 4:e77580278416 1000 disp.setFont(fontWAR);
trelemar 4:e77580278416 1001 map_x=0;
trelemar 4:e77580278416 1002 map_y=0;
trelemar 4:e77580278416 1003 cursor_x=4;
trelemar 4:e77580278416 1004 cursor_y=6;
trelemar 4:e77580278416 1005 vector<Hero> heros;
trelemar 4:e77580278416 1006 hptr = &heros;
trelemar 4:e77580278416 1007 pokInitSD();
trelemar 4:e77580278416 1008
trelemar 4:e77580278416 1009 char dir[3];
trelemar 4:e77580278416 1010 strcpy(dir, "War");
trelemar 4:e77580278416 1011
trelemar 4:e77580278416 1012 LevelList level_menu;
trelemar 4:e77580278416 1013 level_menu.init();
trelemar 4:e77580278416 1014
trelemar 9:682f31473b25 1015 bases[0] = Base(2,2,24,TEAM_USER, 0);
trelemar 9:682f31473b25 1016 bases[1] = Base(10,10,25,TEAM_CPU, 1);
trelemar 4:e77580278416 1017
trelemar 4:e77580278416 1018 heros.push_back(Hero(4,5,ID_SOLDIER, TEAM_USER));
trelemar 4:e77580278416 1019 heros.push_back(Hero(5,6,ID_SNIPER, TEAM_USER));
trelemar 4:e77580278416 1020 heros.push_back(Hero(3,8,ID_HEAVY, TEAM_USER));
trelemar 11:4c61319450c8 1021 heros.push_back(Hero(8,5,ID_HUNTER, TEAM_CPU));
trelemar 11:4c61319450c8 1022 heros.push_back(Hero(8,7,ID_HUNTER, TEAM_CPU));
trelemar 11:4c61319450c8 1023 heros.push_back(Hero(5,9,ID_HUNTER, TEAM_CPU));
trelemar 4:e77580278416 1024
trelemar 4:e77580278416 1025 //Hero * cursor_hero = NULL;
trelemar 4:e77580278416 1026 //Hero * current_hero = NULL;
trelemar 11:4c61319450c8 1027 game.wait(10);
trelemar 11:4c61319450c8 1028 splashScreen(48,"TRELEMAR", 7, 15);
trelemar 11:4c61319450c8 1029 splashScreen(50,"VONBEDNAR", 15, 0);
trelemar 7:91365e9ad8c6 1030
trelemar 4:e77580278416 1031 while (game.isRunning()) {
trelemar 4:e77580278416 1032 if (game.update()) {
trelemar 4:e77580278416 1033 switch (State) {
trelemar 4:e77580278416 1034 case MENU:
trelemar 4:e77580278416 1035 main_menu.update(&level_menu);
trelemar 4:e77580278416 1036 main_menu.draw(&level_menu);
trelemar 4:e77580278416 1037 break;
trelemar 4:e77580278416 1038 case MAIN:
trelemar 4:e77580278416 1039 tTrans.update();
trelemar 4:e77580278416 1040 itemlist.update();
trelemar 4:e77580278416 1041 //If no current hero or current task is to move our current hero, accept cursor movement.
trelemar 9:682f31473b25 1042 if ((!current_base&&!current_hero)||current_task==TASK_MOVE||current_task==TASK_ATTACK||current_task==TASK_SPAWN) {
trelemar 4:e77580278416 1043 CursorInput();
trelemar 4:e77580278416 1044 cursor_hero = getHeroAtCoords(cursor_x,cursor_y, heros);
trelemar 4:e77580278416 1045 }
trelemar 4:e77580278416 1046 //This will call when there is a current hero and not in a current task
trelemar 9:682f31473b25 1047 else if (current_hero||current_base) {
trelemar 4:e77580278416 1048 //TASK SELECTOR
trelemar 4:e77580278416 1049 int dir = 0;
trelemar 4:e77580278416 1050 if (btn.pressed(BTN_RIGHT)) {
trelemar 4:e77580278416 1051 selected_task=min(selected_task+1,3);
trelemar 4:e77580278416 1052 }
trelemar 4:e77580278416 1053 if (btn.pressed(BTN_LEFT)) {
trelemar 4:e77580278416 1054 selected_task=max(selected_task-1,0);
trelemar 4:e77580278416 1055 }
trelemar 4:e77580278416 1056 if (selected_task==TASK_ITEM) {
trelemar 4:e77580278416 1057 itemlist.enabled = true;
trelemar 4:e77580278416 1058 }
trelemar 4:e77580278416 1059 else itemlist.enabled = false;
trelemar 4:e77580278416 1060 //selected_task=selected_task%4;
trelemar 4:e77580278416 1061 }
trelemar 4:e77580278416 1062
trelemar 4:e77580278416 1063 DrawTileMap(map_x, map_y, current_hero);
trelemar 4:e77580278416 1064 for (int i = 0; i<heros.size(); i++) {
trelemar 4:e77580278416 1065 heros[i].Draw();
trelemar 4:e77580278416 1066 heros[i].update(i);
trelemar 4:e77580278416 1067 }
trelemar 4:e77580278416 1068 for (int i=0; i<2; i++) {
trelemar 4:e77580278416 1069 bases[i].Draw();
trelemar 4:e77580278416 1070 }
trelemar 4:e77580278416 1071 DrawCursor(cursor_x-map_x,cursor_y-map_y);
trelemar 4:e77580278416 1072 disp.setColor(15);
trelemar 4:e77580278416 1073
trelemar 4:e77580278416 1074 if (btn.pressed(BTN_A)) {
trelemar 9:682f31473b25 1075 if (!current_hero&&current_base&&current_task==TASK_SPAWN) {
trelemar 9:682f31473b25 1076 int8_t id = selected_task + (current_base->faction*4);
trelemar 10:c1af7a94f3f9 1077 selected_task = TASK_MOVE;
trelemar 9:682f31473b25 1078 heros.push_back(Hero(cursor_x, cursor_y, id, current_team));
trelemar 9:682f31473b25 1079 current_task = TASK_NONE;
trelemar 9:682f31473b25 1080 current_hero = &heros[heros.size()-1];
trelemar 9:682f31473b25 1081 current_base=NULL;
trelemar 9:682f31473b25 1082 }
trelemar 4:e77580278416 1083 if (current_hero&&current_task!=TASK_NONE) {
trelemar 4:e77580278416 1084 //THIS IS WITHIN A TASK, EX: SELECTING A MOVE LOCATION OR ATTACK TARGET.
trelemar 4:e77580278416 1085 switch (current_task) {
trelemar 4:e77580278416 1086 case TASK_MOVE:
trelemar 4:e77580278416 1087 //MOVE HERO TO CURSOR, NO COLISSIONS YET.
trelemar 4:e77580278416 1088 //ONLY IF IN RANGE AND NOT SOLID
trelemar 4:e77580278416 1089 //FIX STACKABLE HEROS
trelemar 4:e77580278416 1090 if (current_hero->inRange(cursor_x, cursor_y)&&!getHeroAtCoords(cursor_x, cursor_y, heros)&&!solids[Map[cursor_y][cursor_x]]) {
trelemar 4:e77580278416 1091 if (cursor_x<current_hero->x) current_hero->flip=true;
trelemar 4:e77580278416 1092 else if (cursor_x>current_hero->x) current_hero->flip=false;
trelemar 4:e77580278416 1093 current_hero->x = cursor_x;
trelemar 4:e77580278416 1094 current_hero->y = cursor_y;
trelemar 4:e77580278416 1095
trelemar 4:e77580278416 1096 current_task = TASK_NONE;
trelemar 4:e77580278416 1097 current_hero->tasks[TASK_MOVE] = false;
trelemar 4:e77580278416 1098 }
trelemar 4:e77580278416 1099 break;
trelemar 4:e77580278416 1100 case TASK_ATTACK:
trelemar 4:e77580278416 1101 if (cursor_hero&&current_hero->inRange(cursor_hero)) {
trelemar 4:e77580278416 1102 //FOUND TARGET AT CURSOR.
trelemar 4:e77580278416 1103 cursor_x = current_hero->x;
trelemar 4:e77580278416 1104 cursor_y = current_hero->y;
trelemar 4:e77580278416 1105 int8_t result = cursor_hero->hp - (current_hero->atk-cursor_hero->def);
trelemar 4:e77580278416 1106 cursor_hero->hp = result;
trelemar 4:e77580278416 1107 cursor_hero->hurt_time=game.frameCount;
trelemar 4:e77580278416 1108 if (result<=0) {
trelemar 4:e77580278416 1109 heros.erase(heros.begin()+cursor_hero->index);
trelemar 4:e77580278416 1110 cursor_hero = NULL;
trelemar 4:e77580278416 1111 }
trelemar 4:e77580278416 1112
trelemar 4:e77580278416 1113 current_task = TASK_NONE;
trelemar 4:e77580278416 1114 current_hero->tasks[TASK_ATTACK] = false;
trelemar 4:e77580278416 1115 }
trelemar 4:e77580278416 1116 else {
trelemar 4:e77580278416 1117 //NO TARGET FOUND, ERROR SOUND SHOULD PLAY.
trelemar 4:e77580278416 1118 }
trelemar 4:e77580278416 1119 break;
trelemar 4:e77580278416 1120
trelemar 4:e77580278416 1121 //DUMMY CODE, THESE ARE CALLED BELOW. NOT HERE.
trelemar 4:e77580278416 1122 case TASK_ITEM:
trelemar 4:e77580278416 1123 current_task = TASK_NONE;
trelemar 4:e77580278416 1124 current_hero->tasks[TASK_ITEM] = false;
trelemar 4:e77580278416 1125 break;
trelemar 4:e77580278416 1126 case TASK_WAIT:
trelemar 4:e77580278416 1127 current_task = TASK_NONE;
trelemar 4:e77580278416 1128 current_hero->tasks[TASK_WAIT] = false;
trelemar 4:e77580278416 1129 break;
trelemar 4:e77580278416 1130 }
trelemar 4:e77580278416 1131 }
trelemar 4:e77580278416 1132 else if (current_hero&&current_hero->tasks[selected_task]==true) {
trelemar 4:e77580278416 1133 //TASK SWITCH HERE
trelemar 4:e77580278416 1134 //THIS HAPPENS DIRECTLY AFTER PRESSING BTN_A ON A NEW TASK.
trelemar 4:e77580278416 1135 current_task=selected_task;
trelemar 4:e77580278416 1136
trelemar 4:e77580278416 1137 switch (selected_task) {
trelemar 4:e77580278416 1138 case TASK_ITEM:
trelemar 4:e77580278416 1139 current_task = TASK_NONE;
trelemar 4:e77580278416 1140 current_hero->tasks[TASK_ITEM] = false;
trelemar 4:e77580278416 1141 break;
trelemar 4:e77580278416 1142 case TASK_WAIT:
trelemar 4:e77580278416 1143 current_task = TASK_NONE;
trelemar 4:e77580278416 1144 current_hero->tasks[TASK_WAIT] = false;
trelemar 4:e77580278416 1145 break;
trelemar 4:e77580278416 1146 }
trelemar 4:e77580278416 1147 }
trelemar 4:e77580278416 1148 else if (cursor_hero) {
trelemar 4:e77580278416 1149 //NO CURRENT HERO, SELECT A HERO ONLY IF IN CURSOR HERE.
trelemar 4:e77580278416 1150 if (cursor_hero->team == current_team) {
trelemar 4:e77580278416 1151 current_hero = cursor_hero;
trelemar 4:e77580278416 1152 selected_task = TASK_MOVE;
trelemar 4:e77580278416 1153 tTrans.enabled = true;
trelemar 4:e77580278416 1154 }
trelemar 4:e77580278416 1155 }
trelemar 9:682f31473b25 1156 else if (current_base) {
trelemar 9:682f31473b25 1157 current_task = TASK_SPAWN;
trelemar 9:682f31473b25 1158 }
trelemar 4:e77580278416 1159 else if (bases[current_team].x==cursor_x&&bases[current_team].y==cursor_y) {
trelemar 4:e77580278416 1160 current_base = &bases[current_team];
trelemar 4:e77580278416 1161 tTrans.enabled = true;
trelemar 4:e77580278416 1162 }
trelemar 4:e77580278416 1163 }
trelemar 4:e77580278416 1164 if (btn.pressed(BTN_B)) {
trelemar 4:e77580278416 1165 if (current_task!=TASK_NONE) {
trelemar 4:e77580278416 1166 //BACK OUT OF CURRENT TASK.
trelemar 4:e77580278416 1167 current_task=TASK_NONE;
trelemar 9:682f31473b25 1168 if (current_hero) {
trelemar 9:682f31473b25 1169 cursor_x = current_hero->x;
trelemar 9:682f31473b25 1170 cursor_y = current_hero->y;
trelemar 9:682f31473b25 1171 }
trelemar 9:682f31473b25 1172 if (current_base) {
trelemar 9:682f31473b25 1173 cursor_x = current_base->x;
trelemar 9:682f31473b25 1174 cursor_y = current_base->y;
trelemar 9:682f31473b25 1175 }
trelemar 4:e77580278416 1176 }
trelemar 4:e77580278416 1177 else if (current_hero&&current_task==TASK_NONE) {
trelemar 4:e77580278416 1178 tTrans.enabled=false; current_hero = NULL; //UNSELECT HERO.
trelemar 4:e77580278416 1179 }
trelemar 7:91365e9ad8c6 1180 else if (current_base&&current_task==TASK_NONE) {
trelemar 7:91365e9ad8c6 1181 tTrans.enabled=false; current_base = NULL; //UNSELECT BASE
trelemar 7:91365e9ad8c6 1182 }
trelemar 4:e77580278416 1183 }
trelemar 4:e77580278416 1184 if (btn.pressed(BTN_C)&& !current_hero) {
trelemar 4:e77580278416 1185 //heros.push_back(Hero(cursor_x,cursor_y,0,0));
trelemar 4:e77580278416 1186 //for (int i=0;i<heros.size();i++) heros[i].NewTurn();
trelemar 4:e77580278416 1187 State = PAUSE;
trelemar 4:e77580278416 1188 //disp.print("PAUSED");
trelemar 4:e77580278416 1189 //tTrans.toggle();
trelemar 4:e77580278416 1190 }
trelemar 4:e77580278416 1191 if (cursor_hero&&cursor_hero!=current_hero&&current_task) {
trelemar 4:e77580278416 1192 DrawCursorHeroUI(cursor_hero, (cursor_hero->x-map_x)*16-4,(cursor_hero->y-map_y)*16-7);
trelemar 4:e77580278416 1193 }
trelemar 9:682f31473b25 1194 if (tTrans.val==tTrans.on_val&&!current_base) {
trelemar 4:e77580278416 1195 DrawTraitList(current_hero, itemlist.val);
trelemar 4:e77580278416 1196 }
trelemar 9:682f31473b25 1197
trelemar 9:682f31473b25 1198 if (!current_base) {
trelemar 9:682f31473b25 1199 DrawSelectedHeroUI(current_hero, tTrans.val);
trelemar 9:682f31473b25 1200 }
trelemar 11:4c61319450c8 1201 else if (!current_hero) {
trelemar 4:e77580278416 1202 DrawSelectedBaseUI(current_base, tTrans.val);
trelemar 4:e77580278416 1203 }
trelemar 4:e77580278416 1204 disp.setCursor(0,0);
trelemar 4:e77580278416 1205 DrawTurnCounter(heros);
trelemar 4:e77580278416 1206 //disp.print(0,32,dtest.text);
trelemar 4:e77580278416 1207 //disp.print(1,SH-6,(int)game.battery.level);
trelemar 4:e77580278416 1208 //disp.print(" ");
trelemar 4:e77580278416 1209 break;
trelemar 4:e77580278416 1210 case PAUSE:
trelemar 4:e77580278416 1211 pause_menu.update();
trelemar 4:e77580278416 1212 pause_menu.draw();
trelemar 4:e77580278416 1213 break;
trelemar 4:e77580278416 1214 }//GAME STATE SWITCH
trelemar 4:e77580278416 1215
trelemar 4:e77580278416 1216 }//UPDATE
trelemar 4:e77580278416 1217 }//IS RUNNING
trelemar 4:e77580278416 1218 return 1;
trelemar 4:e77580278416 1219 }