Dependencies:   4DGL-uLCD-SE Motor SparkfunAnalogJoystick mbed

Fork of Fire_Mbed_2_0 by Jake Ramey

Committer:
rpgjake
Date:
Wed May 03 08:07:49 2017 +0000
Revision:
7:4c8ad4f91c8b
Parent:
6:b17d76960330
fdfdfd

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rpgjake 0:b7a07b6cf5d0 1 #include "mbed.h"
rpgjake 0:b7a07b6cf5d0 2 #include "SparkfunAnalogJoystick.h"
rpgjake 0:b7a07b6cf5d0 3 #include "uLCD_4DGL.h"
rpgjake 0:b7a07b6cf5d0 4 #include "FEmain.h"
rpgjake 0:b7a07b6cf5d0 5 #define MapSecA 123
rpgjake 0:b7a07b6cf5d0 6 #define MapSecB 123
rpgjake 0:b7a07b6cf5d0 7
rpgjake 0:b7a07b6cf5d0 8 #include "Motor.h"
rpgjake 5:c920ad0bc875 9 int units_received = 0;
rpgjake 4:47c4ac917fd1 10
rpgjake 0:b7a07b6cf5d0 11 Motor m(p21, p24, p25); // pwm, fwd, rev
rpgjake 0:b7a07b6cf5d0 12
rpgjake 0:b7a07b6cf5d0 13 #define FORTRESS 0
rpgjake 0:b7a07b6cf5d0 14 #define HOUSE 1
rpgjake 0:b7a07b6cf5d0 15 #define KEEP 2
rpgjake 0:b7a07b6cf5d0 16 #define GRASS 3
rpgjake 0:b7a07b6cf5d0 17 #define TREES 4
rpgjake 0:b7a07b6cf5d0 18 #define COMP 2
rpgjake 0:b7a07b6cf5d0 19 #define USER 1
rpgjake 0:b7a07b6cf5d0 20
rpgjake 0:b7a07b6cf5d0 21
rpgjake 0:b7a07b6cf5d0 22 DigitalOut myled(LED1);
rpgjake 0:b7a07b6cf5d0 23 uLCD_4DGL uLCD(p9,p10,p11);
rpgjake 0:b7a07b6cf5d0 24 DigitalIn pb5(p5);
rpgjake 0:b7a07b6cf5d0 25 DigitalIn pb6(p6);
rpgjake 0:b7a07b6cf5d0 26 DigitalIn pb7(p7);
rpgjake 0:b7a07b6cf5d0 27 DigitalIn pb8(p8);
rpgjake 3:275705c872e0 28 DigitalOut led1(LED1);
rpgjake 3:275705c872e0 29 DigitalOut led2(LED2);
rpgjake 3:275705c872e0 30 DigitalOut led3(LED3);
rpgjake 3:275705c872e0 31 DigitalOut led4(LED4);
rpgjake 0:b7a07b6cf5d0 32 #define M_PI 3.14159265358979323846
rpgjake 0:b7a07b6cf5d0 33 Serial pc(USBTX, USBRX);
rpgjake 2:ccfe87a5ccba 34 Serial Julio_Mbed(p28,p27);
rpgjake 0:b7a07b6cf5d0 35 SparkfunAnalogJoystick joysttick(p18, p19, p20);
rpgjake 0:b7a07b6cf5d0 36 #define x_sector 0x003B
rpgjake 0:b7a07b6cf5d0 37 int analog2Keypad(SparkfunAnalogJoystick *joystick);
rpgjake 0:b7a07b6cf5d0 38 int player_turn;
rpgjake 2:ccfe87a5ccba 39 char stagenumber = 0;
rpgjake 0:b7a07b6cf5d0 40
rpgjake 2:ccfe87a5ccba 41 struct tiles {
rpgjake 0:b7a07b6cf5d0 42 char v;
rpgjake 0:b7a07b6cf5d0 43 int x;
rpgjake 0:b7a07b6cf5d0 44 int y;
rpgjake 1:3a9ef60cbbfc 45 char passable;
rpgjake 1:3a9ef60cbbfc 46 tiles(char v1 =0, int x1=0, int y1=0, char p1=0) : v(v1), x(x1), y(y1), passable(p1){}}; //fortress_t,house_t,keep_t,grass_t,trees_t;
rpgjake 6:b17d76960330 47 const tiles fortress_t(0,x_sector,0x5009,0);
rpgjake 6:b17d76960330 48 const tiles house_t(1,x_sector,0x5021,1);
rpgjake 6:b17d76960330 49 const tiles keep_t(2,x_sector,0x501B,1);
rpgjake 6:b17d76960330 50 const tiles grass_t(3,x_sector,0x501D,1);
rpgjake 6:b17d76960330 51 const tiles trees_t(4,x_sector,0x5019,1);
rpgjake 6:b17d76960330 52 const tiles hill_t(5,x_sector,0x501F,1);
rpgjake 1:3a9ef60cbbfc 53
rpgjake 6:b17d76960330 54 tiles tile_array[6] = {fortress_t,house_t,keep_t,grass_t,trees_t,hill_t};
rpgjake 0:b7a07b6cf5d0 55
rpgjake 0:b7a07b6cf5d0 56
rpgjake 0:b7a07b6cf5d0 57 typedef struct units {
rpgjake 0:b7a07b6cf5d0 58 job_t job;
rpgjake 2:ccfe87a5ccba 59 char v;
rpgjake 0:b7a07b6cf5d0 60 int FoF;//1 = USER // 2= COMP
rpgjake 0:b7a07b6cf5d0 61 int xloc;
rpgjake 0:b7a07b6cf5d0 62 int yloc;
rpgjake 0:b7a07b6cf5d0 63 int xlast;
rpgjake 0:b7a07b6cf5d0 64 int ylast;
rpgjake 2:ccfe87a5ccba 65 char remain_moves;
rpgjake 2:ccfe87a5ccba 66 char health;
rpgjake 5:c920ad0bc875 67 char status;
rpgjake 0:b7a07b6cf5d0 68 } person_t;
rpgjake 0:b7a07b6cf5d0 69
rpgjake 0:b7a07b6cf5d0 70
rpgjake 0:b7a07b6cf5d0 71 static person_t Mc;
rpgjake 0:b7a07b6cf5d0 72 static person_t Ak;
rpgjake 0:b7a07b6cf5d0 73 static person_t Ap;
rpgjake 0:b7a07b6cf5d0 74 static person_t Healer;
rpgjake 0:b7a07b6cf5d0 75 static person_t Brigand;
rpgjake 0:b7a07b6cf5d0 76 static person_t Thief;
rpgjake 0:b7a07b6cf5d0 77 static person_t Soldier;
rpgjake 0:b7a07b6cf5d0 78 static person_t Wolf;
rpgjake 0:b7a07b6cf5d0 79 static person_t Wolfa;
rpgjake 0:b7a07b6cf5d0 80 static person_t Wolfb;
rpgjake 0:b7a07b6cf5d0 81 static person_t Wolfc;
rpgjake 0:b7a07b6cf5d0 82
rpgjake 3:275705c872e0 83 static person_t p_Princess;
rpgjake 3:275705c872e0 84 static person_t p_Thief;
rpgjake 3:275705c872e0 85 static person_t p_WhiteMage;
rpgjake 3:275705c872e0 86 static person_t p_Pirate;
rpgjake 3:275705c872e0 87 static person_t p_Lancer;
rpgjake 3:275705c872e0 88 static person_t p_Archer;
rpgjake 3:275705c872e0 89 static person_t p_Dragon;
rpgjake 3:275705c872e0 90 static person_t p_Sage;
rpgjake 3:275705c872e0 91 static person_t p_Caster;
rpgjake 3:275705c872e0 92 static person_t p_Assassin;
rpgjake 3:275705c872e0 93 static person_t p_Medic;
rpgjake 3:275705c872e0 94 static person_t p_Brigand;
rpgjake 3:275705c872e0 95 static person_t p_Wolf_a;
rpgjake 3:275705c872e0 96 static person_t p_Wolf_b;
rpgjake 3:275705c872e0 97 static person_t p_Wolf_c;
rpgjake 3:275705c872e0 98 static person_t p_Assassin_e;
rpgjake 6:b17d76960330 99 static person_t p_Fighter_a;
rpgjake 6:b17d76960330 100 static person_t p_Fighter_b;
rpgjake 6:b17d76960330 101 static person_t p_Fighter_c;
rpgjake 3:275705c872e0 102 static person_t p_RedSpider;
rpgjake 3:275705c872e0 103 static person_t p_Spider_a;
rpgjake 3:275705c872e0 104 static person_t p_Spider_b;
rpgjake 3:275705c872e0 105 static person_t p_Spider_c;
rpgjake 3:275705c872e0 106 static person_t p_FallenHero;
rpgjake 3:275705c872e0 107 static person_t p_Mage_4a;
rpgjake 3:275705c872e0 108 static person_t p_Mage_4b;
rpgjake 3:275705c872e0 109 static person_t p_Mage_4c;
rpgjake 3:275705c872e0 110 static person_t p_TrueAssassin;
rpgjake 3:275705c872e0 111 static person_t p_Zombie_5a;
rpgjake 3:275705c872e0 112 static person_t p_Zombie_5b;
rpgjake 3:275705c872e0 113 static person_t p_Zombie_5c;
rpgjake 3:275705c872e0 114 static person_t p_General;
rpgjake 3:275705c872e0 115 static person_t p_Zombie_6a;
rpgjake 3:275705c872e0 116 static person_t p_Zombie_6b;
rpgjake 3:275705c872e0 117 static person_t p_Mage_6a;
rpgjake 3:275705c872e0 118 static person_t p_Mage_6b;
rpgjake 3:275705c872e0 119 static person_t p_Summoner;
rpgjake 3:275705c872e0 120 static person_t p_Zombie_7a;
rpgjake 3:275705c872e0 121 static person_t p_Zombie_7b;
rpgjake 3:275705c872e0 122 static person_t p_Zombie_7c;
rpgjake 3:275705c872e0 123 static person_t p_Zombie_7d;
rpgjake 0:b7a07b6cf5d0 124
rpgjake 5:c920ad0bc875 125 person_t* person_array[42] = {NULL, &p_Princess, &p_Thief, &p_WhiteMage, &p_Pirate, &p_Lancer, &p_Archer, &p_Dragon, &p_Sage, &p_Caster, &p_Assassin, &p_Medic,
rpgjake 5:c920ad0bc875 126 &p_Brigand, &p_Wolf_a, &p_Wolf_b, &p_Wolf_c,
rpgjake 6:b17d76960330 127 &p_Assassin_e, &p_Fighter_a, &p_Fighter_b, &p_Fighter_c,
rpgjake 5:c920ad0bc875 128 &p_RedSpider, &p_Spider_a, &p_Spider_b, &p_Spider_c,
rpgjake 5:c920ad0bc875 129 &p_FallenHero, &p_Mage_4a, &p_Mage_4b, &p_Mage_4c,
rpgjake 5:c920ad0bc875 130 &p_TrueAssassin, &p_Zombie_5a, &p_Zombie_5b, &p_Zombie_5c,
rpgjake 5:c920ad0bc875 131 &p_General, &p_Zombie_6a, &p_Zombie_6b, &p_Mage_6a, &p_Mage_6b,
rpgjake 5:c920ad0bc875 132 &p_Summoner, &p_Zombie_7a, &p_Zombie_7b, &p_Zombie_7c, &p_Zombie_7d};
rpgjake 0:b7a07b6cf5d0 133
rpgjake 1:3a9ef60cbbfc 134 char Map1_1[8][8] = {
rpgjake 0:b7a07b6cf5d0 135 {FORTRESS, FORTRESS, FORTRESS, GRASS, GRASS, GRASS, HOUSE, GRASS},
rpgjake 0:b7a07b6cf5d0 136 {FORTRESS, FORTRESS, FORTRESS, GRASS, GRASS, GRASS, GRASS, GRASS},
rpgjake 0:b7a07b6cf5d0 137 {FORTRESS, FORTRESS, FORTRESS, GRASS, TREES, GRASS, GRASS, GRASS},
rpgjake 0:b7a07b6cf5d0 138 {GRASS, GRASS, GRASS, GRASS, GRASS, GRASS, GRASS, GRASS},
rpgjake 0:b7a07b6cf5d0 139 {GRASS, GRASS, GRASS, GRASS, GRASS, GRASS, GRASS, GRASS},
rpgjake 0:b7a07b6cf5d0 140 {GRASS, GRASS, GRASS, GRASS, TREES, TREES, TREES, GRASS},
rpgjake 0:b7a07b6cf5d0 141 {GRASS, GRASS, HOUSE, TREES, GRASS, KEEP, GRASS, GRASS},
rpgjake 0:b7a07b6cf5d0 142 {GRASS, GRASS, GRASS, GRASS, GRASS, GRASS, GRASS, GRASS} };
rpgjake 0:b7a07b6cf5d0 143
rpgjake 1:3a9ef60cbbfc 144 char unitsMap1_1[8][8] = {
rpgjake 0:b7a07b6cf5d0 145 {0, 0, 0, 0, 0, 0, 0, 0},
rpgjake 0:b7a07b6cf5d0 146 {0, 0, 0, 0, 0, 0, 0, 0},
rpgjake 0:b7a07b6cf5d0 147 {0, 0, 0, 0, 0, 0, 0, 0},
rpgjake 0:b7a07b6cf5d0 148 {0, 0, 0, 0, 0, 0, 0, 0},
rpgjake 0:b7a07b6cf5d0 149 {0, 0, 0, 0, 0, 0, 0, 0},
rpgjake 0:b7a07b6cf5d0 150 {0, 0, 0, 0, 0, 0, 0, 0},
rpgjake 0:b7a07b6cf5d0 151 {0, 0, 0, 0, 0, 0, 0, 0},
rpgjake 0:b7a07b6cf5d0 152 {0, 0, 0, 0, 0, 0, 0, 0} };
rpgjake 0:b7a07b6cf5d0 153
rpgjake 0:b7a07b6cf5d0 154
rpgjake 0:b7a07b6cf5d0 155
rpgjake 0:b7a07b6cf5d0 156
rpgjake 0:b7a07b6cf5d0 157 void initialize(void);
rpgjake 5:c920ad0bc875 158 //void load_game_state
rpgjake 0:b7a07b6cf5d0 159 int user_selecting(void);//return selection
rpgjake 0:b7a07b6cf5d0 160 int user_action(int selection);
rpgjake 0:b7a07b6cf5d0 161 int display_status(int selection);
rpgjake 0:b7a07b6cf5d0 162 int user_movement(int selection);
rpgjake 0:b7a07b6cf5d0 163 int combat(person_t* attacker, person_t* defender);
rpgjake 1:3a9ef60cbbfc 164 int heal(person_t* attacker, person_t* defender);
rpgjake 1:3a9ef60cbbfc 165 void find_player(person_t* ai_pred);
rpgjake 1:3a9ef60cbbfc 166 void hunt_player(person_t* predator, person_t* prey, int prey_x, int prey_y, int predator_x, int predator_y);
rpgjake 1:3a9ef60cbbfc 167 void ai_movement(void);
rpgjake 1:3a9ef60cbbfc 168 void ask_nextstage(void);
rpgjake 1:3a9ef60cbbfc 169 void load_units_map(void);
rpgjake 5:c920ad0bc875 170 void combatPhase(char a, char d);
rpgjake 3:275705c872e0 171 void sendMap(void);
rpgjake 3:275705c872e0 172 void sendUnits (void);
rpgjake 3:275705c872e0 173 void receiveMap (void);
rpgjake 3:275705c872e0 174 void receiveUnits (void);
rpgjake 3:275705c872e0 175 void waitForAck (void);
rpgjake 0:b7a07b6cf5d0 176 int state;
rpgjake 0:b7a07b6cf5d0 177 int cursor_x;
rpgjake 0:b7a07b6cf5d0 178 int cursor_y;
rpgjake 0:b7a07b6cf5d0 179 void kill_unit(person_t* dead_unit);
rpgjake 0:b7a07b6cf5d0 180
rpgjake 0:b7a07b6cf5d0 181 int main() {
rpgjake 0:b7a07b6cf5d0 182 uLCD.media_init();
rpgjake 0:b7a07b6cf5d0 183 pb5.mode(PullUp);
rpgjake 0:b7a07b6cf5d0 184 pb6.mode(PullUp);
rpgjake 0:b7a07b6cf5d0 185 pb7.mode(PullUp);
rpgjake 0:b7a07b6cf5d0 186 pb8.mode(PullUp);
rpgjake 0:b7a07b6cf5d0 187 initialize();
rpgjake 0:b7a07b6cf5d0 188 int selection;
rpgjake 0:b7a07b6cf5d0 189 int action;
rpgjake 0:b7a07b6cf5d0 190 player_turn =1;
rpgjake 0:b7a07b6cf5d0 191 cursor_x = 0;
rpgjake 0:b7a07b6cf5d0 192 cursor_y = 0;
rpgjake 0:b7a07b6cf5d0 193 state = 0;
rpgjake 0:b7a07b6cf5d0 194 person_t* temp_persona;
rpgjake 0:b7a07b6cf5d0 195 while(1) {
rpgjake 0:b7a07b6cf5d0 196 if (state == 0){
rpgjake 0:b7a07b6cf5d0 197 selection = user_selecting();}
rpgjake 0:b7a07b6cf5d0 198 //else if (state ==1)
rpgjake 0:b7a07b6cf5d0 199 //ret_val = display_status(selection);
rpgjake 0:b7a07b6cf5d0 200 else if (state == 2){
rpgjake 0:b7a07b6cf5d0 201 action = user_movement(selection);}
rpgjake 0:b7a07b6cf5d0 202 else if (state == 3){
rpgjake 0:b7a07b6cf5d0 203 if (player_turn ==1){
rpgjake 0:b7a07b6cf5d0 204 player_turn = 2;
rpgjake 1:3a9ef60cbbfc 205 ai_movement();
rpgjake 0:b7a07b6cf5d0 206 }
rpgjake 0:b7a07b6cf5d0 207 else {
rpgjake 0:b7a07b6cf5d0 208 player_turn =1;
rpgjake 0:b7a07b6cf5d0 209 }
rpgjake 5:c920ad0bc875 210 for(int i=1; i<42;i++){
rpgjake 0:b7a07b6cf5d0 211 temp_persona = person_array[i];
rpgjake 0:b7a07b6cf5d0 212 temp_persona->remain_moves = temp_persona->job.movement;
rpgjake 0:b7a07b6cf5d0 213 }
rpgjake 0:b7a07b6cf5d0 214 state = 0;
rpgjake 0:b7a07b6cf5d0 215 }
rpgjake 0:b7a07b6cf5d0 216 //else if (state == 4)
rpgjake 0:b7a07b6cf5d0 217 }
rpgjake 0:b7a07b6cf5d0 218 }
rpgjake 0:b7a07b6cf5d0 219 //cleric - lord - ax
rpgjake 0:b7a07b6cf5d0 220 //noth - spear
rpgjake 0:b7a07b6cf5d0 221
rpgjake 0:b7a07b6cf5d0 222
rpgjake 0:b7a07b6cf5d0 223
rpgjake 0:b7a07b6cf5d0 224 void initialize(void){
rpgjake 2:ccfe87a5ccba 225 init_jobs();
rpgjake 1:3a9ef60cbbfc 226 // keep_t.x = x_sector;
rpgjake 1:3a9ef60cbbfc 227 // house_t.x = x_sector;
rpgjake 1:3a9ef60cbbfc 228 // grass_t.x = x_sector;
rpgjake 1:3a9ef60cbbfc 229 // trees_t.x = x_sector;
rpgjake 1:3a9ef60cbbfc 230 // fortress_t.x = x_sector;
rpgjake 1:3a9ef60cbbfc 231 // fortress_t.y = 0x5042;
rpgjake 1:3a9ef60cbbfc 232 // trees_t.y = 0x5052;
rpgjake 1:3a9ef60cbbfc 233 // keep_t.y = 0x5054;
rpgjake 1:3a9ef60cbbfc 234 // grass_t.y = 0x5056;
rpgjake 1:3a9ef60cbbfc 235 // house_t.y = 0x5058;
rpgjake 1:3a9ef60cbbfc 236 //wait for ack function
rpgjake 1:3a9ef60cbbfc 237 /*while(!pc.readable()){
rpgjake 1:3a9ef60cbbfc 238 wait(.001);
rpgjake 1:3a9ef60cbbfc 239 }
rpgjake 1:3a9ef60cbbfc 240 for (int y_num = 0; y_num < 8; y_num ++){
rpgjake 1:3a9ef60cbbfc 241 for(int x_num = 0; x_num<8; x_num ++){
rpgjake 1:3a9ef60cbbfc 242 Map1_1[y_num][x_num] = pc.getc();
rpgjake 1:3a9ef60cbbfc 243 }
rpgjake 1:3a9ef60cbbfc 244 }
rpgjake 1:3a9ef60cbbfc 245 tiles tile_draw;
rpgjake 1:3a9ef60cbbfc 246 int castledrawn = 0;
rpgjake 1:3a9ef60cbbfc 247 int drawn;
rpgjake 1:3a9ef60cbbfc 248 for (int y_num = 0; y_num < 8; y_num ++){
rpgjake 1:3a9ef60cbbfc 249 for(int x_num = 0; x_num<8; x_num ++){
rpgjake 1:3a9ef60cbbfc 250 drawn = Map1_1[y_num][x_num];
rpgjake 1:3a9ef60cbbfc 251 if (! ((drawn == CASTLE) && (castledrawn == 1))){
rpgjake 1:3a9ef60cbbfc 252 tile_draw = tile_array[Map1_1[y_num][x_num]];
rpgjake 1:3a9ef60cbbfc 253 uLCD.set_sector_address(tile_draw.x,tile_draw.y);
rpgjake 1:3a9ef60cbbfc 254 uLCD.display_image((16*x_num),(16*y_num));
rpgjake 1:3a9ef60cbbfc 255 }
rpgjake 1:3a9ef60cbbfc 256 if (drawn == CASTLE)
rpgjake 1:3a9ef60cbbfc 257 castledrawn = 1;
rpgjake 1:3a9ef60cbbfc 258 }
rpgjake 1:3a9ef60cbbfc 259 }*/
rpgjake 3:275705c872e0 260 //uLCD.set_sector_address(Mapx, Mapy);
rpgjake 3:275705c872e0 261 //uLCD.display_image(0,0);
rpgjake 6:b17d76960330 262 p_Princess.job = j_Erika;
rpgjake 7:4c8ad4f91c8b 263 p_Thief.job = j_Thief;
rpgjake 7:4c8ad4f91c8b 264 p_WhiteMage.job = j_Cleric;
rpgjake 7:4c8ad4f91c8b 265 p_Pirate.job = j_Pirate;
rpgjake 7:4c8ad4f91c8b 266 p_Lancer.job = j_Knight;
rpgjake 7:4c8ad4f91c8b 267 p_Archer.job = j_Archer;
rpgjake 7:4c8ad4f91c8b 268 p_Dragon.job = j_Myrrh;
rpgjake 7:4c8ad4f91c8b 269 p_Sage.job = j_Sage_M;
rpgjake 7:4c8ad4f91c8b 270 p_Caster.job = j_Sage_F;
rpgjake 7:4c8ad4f91c8b 271 p_Assassin.job = j_Assassin_F;
rpgjake 7:4c8ad4f91c8b 272 p_Medic.job = j_Bard;
rpgjake 7:4c8ad4f91c8b 273 p_Brigand.job = j_Brigand;
rpgjake 7:4c8ad4f91c8b 274 p_Wolf_a.job = j_Wolf;
rpgjake 7:4c8ad4f91c8b 275 p_Wolf_b.job = j_Wolf;
rpgjake 7:4c8ad4f91c8b 276 p_Wolf_c.job = j_Wolf;
rpgjake 7:4c8ad4f91c8b 277 p_Assassin_e.job = j_Boss_Assassin_F;
rpgjake 7:4c8ad4f91c8b 278 p_Fighter_a.job = j_Fighter;
rpgjake 7:4c8ad4f91c8b 279 p_Fighter_b.job = j_Fighter;
rpgjake 7:4c8ad4f91c8b 280 p_Fighter_c.job = j_Fighter;
rpgjake 7:4c8ad4f91c8b 281 p_RedSpider.job = j_RedSpider;
rpgjake 7:4c8ad4f91c8b 282 p_Spider_a.job = j_Spider;
rpgjake 7:4c8ad4f91c8b 283 p_Spider_b.job = j_Spider;
rpgjake 7:4c8ad4f91c8b 284 p_Spider_c.job = j_Spider;
rpgjake 7:4c8ad4f91c8b 285 p_FallenHero.job = j_Hero;
rpgjake 7:4c8ad4f91c8b 286 p_Mage_4a.job = j_Mage;
rpgjake 7:4c8ad4f91c8b 287 p_Mage_4b.job = j_Mage;
rpgjake 7:4c8ad4f91c8b 288 p_Mage_4c.job = j_Mage;
rpgjake 7:4c8ad4f91c8b 289 p_TrueAssassin.job = j_Assassin_M;
rpgjake 7:4c8ad4f91c8b 290 p_Zombie_5a.job = j_Zombie;
rpgjake 7:4c8ad4f91c8b 291 p_Zombie_5b.job = j_Zombie;
rpgjake 7:4c8ad4f91c8b 292 p_Zombie_5c.job = j_Zombie;
rpgjake 7:4c8ad4f91c8b 293 p_General.job = j_General;
rpgjake 7:4c8ad4f91c8b 294 p_Zombie_6a.job = j_Zombie;
rpgjake 7:4c8ad4f91c8b 295 p_Zombie_6b.job = j_Zombie;
rpgjake 7:4c8ad4f91c8b 296 p_Mage_6a.job = j_Mage;
rpgjake 7:4c8ad4f91c8b 297 p_Mage_6b.job = j_Mage;
rpgjake 7:4c8ad4f91c8b 298 p_Summoner.job = j_Summoner;
rpgjake 7:4c8ad4f91c8b 299 p_Zombie_7a.job = j_Zombie;
rpgjake 7:4c8ad4f91c8b 300 p_Zombie_7b.job = j_Zombie;
rpgjake 7:4c8ad4f91c8b 301 p_Zombie_7c.job = j_Zombie;
rpgjake 7:4c8ad4f91c8b 302 p_Zombie_7d.job = j_Zombie;
rpgjake 6:b17d76960330 303
rpgjake 6:b17d76960330 304
rpgjake 6:b17d76960330 305
rpgjake 6:b17d76960330 306
rpgjake 5:c920ad0bc875 307 person_t* temp_person_init;
rpgjake 5:c920ad0bc875 308 for( char i = 1; i<42; i++){
rpgjake 5:c920ad0bc875 309 temp_person_init = person_array[i];
rpgjake 5:c920ad0bc875 310 temp_person_init->v = i;
rpgjake 5:c920ad0bc875 311 temp_person_init->status = 1;
rpgjake 6:b17d76960330 312 Mc.remain_moves = Mc.job.movement;
rpgjake 7:4c8ad4f91c8b 313 temp_person_init->remain_moves = temp_person_init->job.movement;
rpgjake 7:4c8ad4f91c8b 314 temp_person_init->health = temp_person_init->job.maxHealth;
rpgjake 5:c920ad0bc875 315 if (i<=11)
rpgjake 5:c920ad0bc875 316 temp_person_init->FoF = USER;
rpgjake 5:c920ad0bc875 317 else
rpgjake 5:c920ad0bc875 318 temp_person_init->FoF = COMP;
rpgjake 5:c920ad0bc875 319 }
rpgjake 0:b7a07b6cf5d0 320 Mc.job = Lord;
rpgjake 0:b7a07b6cf5d0 321 Mc.v = 1;
rpgjake 0:b7a07b6cf5d0 322 Mc.FoF = USER;
rpgjake 0:b7a07b6cf5d0 323 Mc.xlast = 1;
rpgjake 0:b7a07b6cf5d0 324 Mc.xloc = 1;
rpgjake 0:b7a07b6cf5d0 325 Mc.ylast = 3;
rpgjake 0:b7a07b6cf5d0 326 Mc.yloc = 3;
rpgjake 0:b7a07b6cf5d0 327 Mc.remain_moves = Mc.job.movement;
rpgjake 0:b7a07b6cf5d0 328 Mc.health = Mc.job.maxHealth;
rpgjake 3:275705c872e0 329 //uLCD.set_sector_address(Mc.job.x, Mc.job.y);
rpgjake 3:275705c872e0 330 //uLCD.display_image((Mc.xloc*16),(Mc.yloc*16));
rpgjake 0:b7a07b6cf5d0 331
rpgjake 0:b7a07b6cf5d0 332 Ak.job = Armor;
rpgjake 0:b7a07b6cf5d0 333 Ak.v = 2;
rpgjake 0:b7a07b6cf5d0 334 Ak.FoF = USER;
rpgjake 0:b7a07b6cf5d0 335 Ak.xlast = 1;
rpgjake 0:b7a07b6cf5d0 336 Ak.xloc = 1;
rpgjake 0:b7a07b6cf5d0 337 Ak.ylast = 4;
rpgjake 0:b7a07b6cf5d0 338 Ak.yloc = 4;
rpgjake 0:b7a07b6cf5d0 339 Ak.remain_moves = Ak.job.movement;
rpgjake 0:b7a07b6cf5d0 340 Ak.health = Ak.job.maxHealth;
rpgjake 0:b7a07b6cf5d0 341
rpgjake 3:275705c872e0 342 //uLCD.set_sector_address(Ak.job.x, Ak.job.y);
rpgjake 3:275705c872e0 343 //uLCD.display_image((Ak.xloc*16),(Ak.yloc*16));
rpgjake 0:b7a07b6cf5d0 344
rpgjake 3:275705c872e0 345 Ap.job = j_Pirate;
rpgjake 0:b7a07b6cf5d0 346 Ap.v = 3;
rpgjake 0:b7a07b6cf5d0 347 Ap.FoF = USER;
rpgjake 0:b7a07b6cf5d0 348 Ap.xlast = 2;
rpgjake 0:b7a07b6cf5d0 349 Ap.xloc = 2;
rpgjake 0:b7a07b6cf5d0 350 Ap.ylast = 3;
rpgjake 0:b7a07b6cf5d0 351 Ap.yloc = 3;
rpgjake 0:b7a07b6cf5d0 352 Ap.remain_moves = Ap.job.movement;
rpgjake 0:b7a07b6cf5d0 353 Ap.health = Ap.job.maxHealth;
rpgjake 0:b7a07b6cf5d0 354
rpgjake 3:275705c872e0 355 //uLCD.set_sector_address(Ap.job.x, Ap.job.y);
rpgjake 3:275705c872e0 356 //uLCD.display_image((Ap.xloc*16),(Ap.yloc*16));
rpgjake 0:b7a07b6cf5d0 357
rpgjake 6:b17d76960330 358 // Healer.job = j_Cleric;
rpgjake 6:b17d76960330 359 // Healer.v = 4;
rpgjake 6:b17d76960330 360 // Healer.FoF = USER;
rpgjake 6:b17d76960330 361 // Healer.xlast = 0;
rpgjake 6:b17d76960330 362 // Healer.xloc = 0;
rpgjake 6:b17d76960330 363 // Healer.ylast = 3;
rpgjake 6:b17d76960330 364 // Healer.yloc = 3;
rpgjake 6:b17d76960330 365 // Healer.remain_moves = Healer.job.movement;
rpgjake 6:b17d76960330 366 // Healer.health = Healer.job.maxHealth;
rpgjake 6:b17d76960330 367 //
rpgjake 3:275705c872e0 368 //uLCD.set_sector_address(Healer.job.x, Healer.job.y);
rpgjake 3:275705c872e0 369 //uLCD.display_image((Healer.xloc*16),(Healer.yloc*16));
rpgjake 0:b7a07b6cf5d0 370
rpgjake 0:b7a07b6cf5d0 371 Wolf.job = Beast;
rpgjake 0:b7a07b6cf5d0 372 Wolf.v = 8;
rpgjake 0:b7a07b6cf5d0 373 Wolf.FoF = COMP;
rpgjake 0:b7a07b6cf5d0 374 Wolf.xlast = 7;
rpgjake 0:b7a07b6cf5d0 375 Wolf.xloc = 7;
rpgjake 0:b7a07b6cf5d0 376 Wolf.ylast = 4;
rpgjake 0:b7a07b6cf5d0 377 Wolf.yloc = 4;
rpgjake 0:b7a07b6cf5d0 378 Wolf.remain_moves = Wolf.job.movement;
rpgjake 0:b7a07b6cf5d0 379 Wolf.health = Wolf.job.maxHealth;
rpgjake 0:b7a07b6cf5d0 380
rpgjake 3:275705c872e0 381 //uLCD.set_sector_address(Wolf.job.x, Wolf.job.y);
rpgjake 3:275705c872e0 382 //uLCD.display_image((Wolf.xloc*16),(Wolf.yloc*16));
rpgjake 3:275705c872e0 383 //unitsMap1_1[Wolf.yloc][Wolf.xloc] = Wolf.v;
rpgjake 0:b7a07b6cf5d0 384
rpgjake 0:b7a07b6cf5d0 385 Wolfa.job = Beast;
rpgjake 0:b7a07b6cf5d0 386 Wolfa.v = 9;
rpgjake 0:b7a07b6cf5d0 387 Wolfa.FoF = COMP;
rpgjake 0:b7a07b6cf5d0 388 Wolfa.xlast = 7;
rpgjake 0:b7a07b6cf5d0 389 Wolfa.xloc = 7;
rpgjake 0:b7a07b6cf5d0 390 Wolfa.ylast = 5;
rpgjake 0:b7a07b6cf5d0 391 Wolfa.yloc = 5;
rpgjake 0:b7a07b6cf5d0 392 Wolfa.remain_moves = Wolfa.job.movement;
rpgjake 0:b7a07b6cf5d0 393 Wolfa.health = Wolfa.job.maxHealth;
rpgjake 0:b7a07b6cf5d0 394
rpgjake 3:275705c872e0 395 //uLCD.set_sector_address(Wolfa.job.x, Wolfa.job.y);
rpgjake 3:275705c872e0 396 //uLCD.display_image((Wolfa.xloc*16),(Wolfa.yloc*16));
rpgjake 3:275705c872e0 397 //unitsMap1_1[Wolfa.yloc][Wolfa.xloc] = Wolfa.v;
rpgjake 0:b7a07b6cf5d0 398
rpgjake 0:b7a07b6cf5d0 399 Wolfb.job = Beast;
rpgjake 0:b7a07b6cf5d0 400 Wolfb.v = 10;
rpgjake 0:b7a07b6cf5d0 401 Wolfb.FoF = COMP;
rpgjake 0:b7a07b6cf5d0 402 Wolfb.xlast = 6;
rpgjake 0:b7a07b6cf5d0 403 Wolfb.xloc = 6;
rpgjake 0:b7a07b6cf5d0 404 Wolfb.ylast = 4;
rpgjake 0:b7a07b6cf5d0 405 Wolfb.yloc = 4;
rpgjake 0:b7a07b6cf5d0 406 Wolfb.remain_moves = Wolfb.job.movement;
rpgjake 0:b7a07b6cf5d0 407 Wolfb.health = Wolfb.job.maxHealth;
rpgjake 0:b7a07b6cf5d0 408
rpgjake 3:275705c872e0 409 //uLCD.set_sector_address(Wolfb.job.x, Wolfb.job.y);
rpgjake 3:275705c872e0 410 //uLCD.display_image((Wolfb.xloc*16),(Wolfb.yloc*16));
rpgjake 3:275705c872e0 411 //unitsMap1_1[Wolfb.yloc][Wolfb.xloc] = Wolfb.v;
rpgjake 0:b7a07b6cf5d0 412
rpgjake 0:b7a07b6cf5d0 413
rpgjake 0:b7a07b6cf5d0 414 Wolfc.job = Beast;
rpgjake 0:b7a07b6cf5d0 415 Wolfc.v = 11;
rpgjake 0:b7a07b6cf5d0 416 Wolfc.FoF = COMP;
rpgjake 0:b7a07b6cf5d0 417 Wolfc.xlast = 7;
rpgjake 0:b7a07b6cf5d0 418 Wolfc.xloc = 7;
rpgjake 0:b7a07b6cf5d0 419 Wolfc.ylast = 3;
rpgjake 0:b7a07b6cf5d0 420 Wolfc.yloc = 3;
rpgjake 0:b7a07b6cf5d0 421 Wolfc.remain_moves = Wolfc.job.movement;
rpgjake 0:b7a07b6cf5d0 422 Wolfc.health = Wolfc.job.maxHealth;
rpgjake 0:b7a07b6cf5d0 423
rpgjake 3:275705c872e0 424 //uLCD.set_sector_address(Wolfc.job.x, Wolfc.job.y);
rpgjake 3:275705c872e0 425 //uLCD.display_image((Wolfc.xloc*16),(Wolfc.yloc*16));
rpgjake 3:275705c872e0 426 //unitsMap1_1[Wolfc.yloc][Wolfc.xloc] = Wolfc.v;
rpgjake 3:275705c872e0 427
rpgjake 3:275705c872e0 428 //unitsMap1_1[Mc.yloc][Mc.xloc] = Mc.v;
rpgjake 3:275705c872e0 429 //unitsMap1_1[Ak.yloc][Ak.xloc] = Ak.v;
rpgjake 3:275705c872e0 430 //unitsMap1_1[Ap.yloc][Ap.xloc] = Ap.v;
rpgjake 3:275705c872e0 431 //unitsMap1_1[Healer.yloc][Healer.xloc] = Healer.v;
rpgjake 0:b7a07b6cf5d0 432
rpgjake 3:275705c872e0 433 //get map
rpgjake 3:275705c872e0 434 //get units
rpgjake 3:275705c872e0 435 //send julio the char[2] {255, map/track number}
rpgjake 3:275705c872e0 436 uLCD.printf("Load Map\r\n");
rpgjake 3:275705c872e0 437 //put read from gui map code here
rpgjake 3:275705c872e0 438 uLCD.printf("Load Units\r\n");
rpgjake 3:275705c872e0 439 //put read units from gui code here
rpgjake 3:275705c872e0 440 uLCD.printf("New Game\r\n");
rpgjake 3:275705c872e0 441 uLCD.printf("Or Continue\r\n");
rpgjake 5:c920ad0bc875 442 while(units_received == 0){
rpgjake 4:47c4ac917fd1 443 waitForAck();}
rpgjake 6:b17d76960330 444 load_floor(stagenumber);
rpgjake 3:275705c872e0 445 load_units_map();
rpgjake 0:b7a07b6cf5d0 446 return;
rpgjake 0:b7a07b6cf5d0 447 }
rpgjake 0:b7a07b6cf5d0 448 int user_selecting(void){
rpgjake 0:b7a07b6cf5d0 449 int xlast;
rpgjake 0:b7a07b6cf5d0 450 int ylast;
rpgjake 0:b7a07b6cf5d0 451 int action = 0;
rpgjake 0:b7a07b6cf5d0 452 int person_index = 0;
rpgjake 0:b7a07b6cf5d0 453 int tile_index = 0;
rpgjake 0:b7a07b6cf5d0 454 int keypad = 5;
rpgjake 0:b7a07b6cf5d0 455 person_t* temp_person;
rpgjake 1:3a9ef60cbbfc 456 tiles tile_erased;
rpgjake 0:b7a07b6cf5d0 457 int j = pb5;
rpgjake 0:b7a07b6cf5d0 458 int y = pb8;
rpgjake 0:b7a07b6cf5d0 459 while(action == 0){
rpgjake 0:b7a07b6cf5d0 460 keypad = 5;
rpgjake 0:b7a07b6cf5d0 461 xlast = cursor_x;
rpgjake 0:b7a07b6cf5d0 462 ylast = cursor_y;
rpgjake 0:b7a07b6cf5d0 463 while((keypad == 5)&&(j ==1)){
rpgjake 0:b7a07b6cf5d0 464 wait(1);
rpgjake 0:b7a07b6cf5d0 465 j = pb5;
rpgjake 0:b7a07b6cf5d0 466 y = pb8;
rpgjake 0:b7a07b6cf5d0 467 keypad = analog2Keypad(&joysttick);
rpgjake 0:b7a07b6cf5d0 468 if (y==0){
rpgjake 0:b7a07b6cf5d0 469 state = 3;
rpgjake 0:b7a07b6cf5d0 470 return 0;
rpgjake 0:b7a07b6cf5d0 471 }
rpgjake 0:b7a07b6cf5d0 472 }
rpgjake 0:b7a07b6cf5d0 473 switch (keypad)
rpgjake 0:b7a07b6cf5d0 474 {
rpgjake 0:b7a07b6cf5d0 475 case 1:
rpgjake 0:b7a07b6cf5d0 476 {
rpgjake 0:b7a07b6cf5d0 477 cursor_x = cursor_x -1;
rpgjake 0:b7a07b6cf5d0 478 cursor_y = cursor_y +1;
rpgjake 0:b7a07b6cf5d0 479 }
rpgjake 0:b7a07b6cf5d0 480 break;
rpgjake 0:b7a07b6cf5d0 481 case 2:
rpgjake 0:b7a07b6cf5d0 482 {
rpgjake 0:b7a07b6cf5d0 483 cursor_y = cursor_y +1;
rpgjake 0:b7a07b6cf5d0 484 }
rpgjake 0:b7a07b6cf5d0 485 break;
rpgjake 0:b7a07b6cf5d0 486 case 3:
rpgjake 0:b7a07b6cf5d0 487 {
rpgjake 0:b7a07b6cf5d0 488 cursor_x = cursor_x +1;
rpgjake 0:b7a07b6cf5d0 489 cursor_y = cursor_y +1;
rpgjake 0:b7a07b6cf5d0 490 }
rpgjake 0:b7a07b6cf5d0 491 break;
rpgjake 0:b7a07b6cf5d0 492 case 4:
rpgjake 0:b7a07b6cf5d0 493 {
rpgjake 0:b7a07b6cf5d0 494 cursor_x = cursor_x -1;
rpgjake 0:b7a07b6cf5d0 495 }
rpgjake 0:b7a07b6cf5d0 496 break;
rpgjake 0:b7a07b6cf5d0 497 case 5:
rpgjake 0:b7a07b6cf5d0 498 break;
rpgjake 0:b7a07b6cf5d0 499 case 6:
rpgjake 0:b7a07b6cf5d0 500 {
rpgjake 0:b7a07b6cf5d0 501 cursor_x = cursor_x +1;
rpgjake 0:b7a07b6cf5d0 502 }
rpgjake 0:b7a07b6cf5d0 503 break;
rpgjake 0:b7a07b6cf5d0 504 case 7:
rpgjake 0:b7a07b6cf5d0 505 {
rpgjake 0:b7a07b6cf5d0 506 cursor_x = cursor_x -1;
rpgjake 0:b7a07b6cf5d0 507 cursor_y = cursor_y -1;
rpgjake 0:b7a07b6cf5d0 508 }
rpgjake 0:b7a07b6cf5d0 509 break;
rpgjake 0:b7a07b6cf5d0 510 case 8:
rpgjake 0:b7a07b6cf5d0 511 {
rpgjake 0:b7a07b6cf5d0 512 cursor_y = cursor_y -1;
rpgjake 0:b7a07b6cf5d0 513 }
rpgjake 0:b7a07b6cf5d0 514 break;
rpgjake 0:b7a07b6cf5d0 515 case 9:
rpgjake 0:b7a07b6cf5d0 516 {
rpgjake 0:b7a07b6cf5d0 517 cursor_x = cursor_x + 1;
rpgjake 0:b7a07b6cf5d0 518 cursor_y = cursor_y - 1;
rpgjake 0:b7a07b6cf5d0 519 }
rpgjake 0:b7a07b6cf5d0 520 break;
rpgjake 0:b7a07b6cf5d0 521 }
rpgjake 0:b7a07b6cf5d0 522 if (cursor_y <0)
rpgjake 0:b7a07b6cf5d0 523 cursor_y = 0;
rpgjake 0:b7a07b6cf5d0 524 if (cursor_x <0)
rpgjake 0:b7a07b6cf5d0 525 cursor_x = 0;
rpgjake 0:b7a07b6cf5d0 526 if (cursor_y >7)
rpgjake 0:b7a07b6cf5d0 527 cursor_y = 7;
rpgjake 0:b7a07b6cf5d0 528 if (cursor_x >7)
rpgjake 0:b7a07b6cf5d0 529 cursor_x = 7;
rpgjake 0:b7a07b6cf5d0 530
rpgjake 0:b7a07b6cf5d0 531
rpgjake 0:b7a07b6cf5d0 532 if((xlast != cursor_x) || (ylast != cursor_y)){
rpgjake 0:b7a07b6cf5d0 533 person_index = unitsMap1_1[ylast][xlast];
rpgjake 0:b7a07b6cf5d0 534 tile_index = Map1_1[ylast][xlast];
rpgjake 0:b7a07b6cf5d0 535 if (person_index != 0){
rpgjake 0:b7a07b6cf5d0 536 temp_person = person_array[person_index];
rpgjake 0:b7a07b6cf5d0 537 uLCD.set_sector_address(temp_person->job.x, temp_person->job.y);
rpgjake 0:b7a07b6cf5d0 538 uLCD.display_image((xlast*16), (ylast*16));
rpgjake 0:b7a07b6cf5d0 539 }
rpgjake 0:b7a07b6cf5d0 540 else{
rpgjake 0:b7a07b6cf5d0 541 tile_erased = tile_array[tile_index];
rpgjake 0:b7a07b6cf5d0 542 if (tile_index == 0){
rpgjake 1:3a9ef60cbbfc 543 uLCD.set_sector_address(tile_erased.x, tile_erased.y);
rpgjake 0:b7a07b6cf5d0 544 uLCD.display_image(0, 0);
rpgjake 0:b7a07b6cf5d0 545 }
rpgjake 0:b7a07b6cf5d0 546 else{
rpgjake 1:3a9ef60cbbfc 547 uLCD.set_sector_address(tile_erased.x, tile_erased.y);
rpgjake 0:b7a07b6cf5d0 548 uLCD.display_image(xlast*16, ylast*16);
rpgjake 0:b7a07b6cf5d0 549 }
rpgjake 0:b7a07b6cf5d0 550 }
rpgjake 0:b7a07b6cf5d0 551 uLCD.rectangle((cursor_x*16), (cursor_y*16), ((cursor_x*16)+15), ((cursor_y*16)+15), 0x000000);
rpgjake 0:b7a07b6cf5d0 552 }
rpgjake 0:b7a07b6cf5d0 553 int a = pb5;
rpgjake 0:b7a07b6cf5d0 554 //int b = pb6;
rpgjake 0:b7a07b6cf5d0 555 int c = pb7;
rpgjake 0:b7a07b6cf5d0 556 int d = pb8;
rpgjake 0:b7a07b6cf5d0 557 if (pb5 == 0){
rpgjake 0:b7a07b6cf5d0 558 state = 2;
rpgjake 0:b7a07b6cf5d0 559 action = 1;
rpgjake 0:b7a07b6cf5d0 560 }
rpgjake 0:b7a07b6cf5d0 561 //else if (pb6 == 0){
rpgjake 0:b7a07b6cf5d0 562 //state = 3;
rpgjake 0:b7a07b6cf5d0 563 //action = 2;
rpgjake 0:b7a07b6cf5d0 564 //}
rpgjake 0:b7a07b6cf5d0 565 else if (pb7 == 0){
rpgjake 0:b7a07b6cf5d0 566 action = 3;
rpgjake 0:b7a07b6cf5d0 567 }
rpgjake 0:b7a07b6cf5d0 568 else if (pb8 == 0){
rpgjake 0:b7a07b6cf5d0 569 action = 4;
rpgjake 0:b7a07b6cf5d0 570 }
rpgjake 0:b7a07b6cf5d0 571 }
rpgjake 0:b7a07b6cf5d0 572 if (pb5 == 0){
rpgjake 0:b7a07b6cf5d0 573 state = 2;
rpgjake 0:b7a07b6cf5d0 574 action = 1;
rpgjake 0:b7a07b6cf5d0 575 }
rpgjake 0:b7a07b6cf5d0 576 return action;
rpgjake 0:b7a07b6cf5d0 577 }
rpgjake 0:b7a07b6cf5d0 578
rpgjake 0:b7a07b6cf5d0 579
rpgjake 0:b7a07b6cf5d0 580 int user_movement(int selection){
rpgjake 0:b7a07b6cf5d0 581 int Index_j;
rpgjake 0:b7a07b6cf5d0 582 Index_j = unitsMap1_1[cursor_y][cursor_x];
rpgjake 0:b7a07b6cf5d0 583 person_t* User_person;
rpgjake 0:b7a07b6cf5d0 584 if (Index_j == 0){
rpgjake 0:b7a07b6cf5d0 585 state = 4;
rpgjake 0:b7a07b6cf5d0 586 return 69;
rpgjake 0:b7a07b6cf5d0 587 }
rpgjake 0:b7a07b6cf5d0 588 User_person = person_array[Index_j];
rpgjake 0:b7a07b6cf5d0 589 if ((User_person->remain_moves) == 0)
rpgjake 0:b7a07b6cf5d0 590 {
rpgjake 0:b7a07b6cf5d0 591 state = 0;
rpgjake 0:b7a07b6cf5d0 592 return 0;
rpgjake 0:b7a07b6cf5d0 593 }
rpgjake 0:b7a07b6cf5d0 594 if ((User_person->FoF) != player_turn)
rpgjake 0:b7a07b6cf5d0 595 {
rpgjake 0:b7a07b6cf5d0 596 state = 0;
rpgjake 0:b7a07b6cf5d0 597 return 0;
rpgjake 0:b7a07b6cf5d0 598 }
rpgjake 2:ccfe87a5ccba 599 Julio_Mbed.putc(1);
rpgjake 2:ccfe87a5ccba 600 Julio_Mbed.putc(User_person->v);
rpgjake 2:ccfe87a5ccba 601 Julio_Mbed.putc(User_person->health);
rpgjake 2:ccfe87a5ccba 602 Julio_Mbed.putc(User_person->job.maxHealth);
rpgjake 0:b7a07b6cf5d0 603 int j = pb7;
rpgjake 0:b7a07b6cf5d0 604 int xloc_u = 1;
rpgjake 0:b7a07b6cf5d0 605 int yloc_u = 1;
rpgjake 0:b7a07b6cf5d0 606 int xlast = 1;
rpgjake 0:b7a07b6cf5d0 607 int ylast = 1;
rpgjake 0:b7a07b6cf5d0 608 while(j==1){
rpgjake 0:b7a07b6cf5d0 609 j = pb7;
rpgjake 0:b7a07b6cf5d0 610 xloc_u = (User_person->xloc);
rpgjake 0:b7a07b6cf5d0 611 yloc_u = User_person->yloc;
rpgjake 0:b7a07b6cf5d0 612 xlast = User_person->xlast;
rpgjake 0:b7a07b6cf5d0 613 ylast = User_person->ylast;
rpgjake 0:b7a07b6cf5d0 614 int keypad = 5;
rpgjake 0:b7a07b6cf5d0 615 while((keypad == 5)&&(j==1)){
rpgjake 0:b7a07b6cf5d0 616 wait(1);
rpgjake 0:b7a07b6cf5d0 617 j = pb7;
rpgjake 0:b7a07b6cf5d0 618 keypad = analog2Keypad(&joysttick);
rpgjake 0:b7a07b6cf5d0 619 }
rpgjake 0:b7a07b6cf5d0 620 switch (keypad)
rpgjake 0:b7a07b6cf5d0 621 {
rpgjake 0:b7a07b6cf5d0 622 case 1:
rpgjake 0:b7a07b6cf5d0 623 xloc_u = xloc_u -1;
rpgjake 0:b7a07b6cf5d0 624 yloc_u = yloc_u +1;
rpgjake 0:b7a07b6cf5d0 625 break;
rpgjake 0:b7a07b6cf5d0 626 case 2:
rpgjake 0:b7a07b6cf5d0 627 yloc_u = yloc_u +1;
rpgjake 0:b7a07b6cf5d0 628 break;
rpgjake 0:b7a07b6cf5d0 629 case 3:
rpgjake 0:b7a07b6cf5d0 630 xloc_u = xloc_u +1;
rpgjake 0:b7a07b6cf5d0 631 yloc_u = yloc_u +1;
rpgjake 0:b7a07b6cf5d0 632 break;
rpgjake 0:b7a07b6cf5d0 633 case 4:
rpgjake 0:b7a07b6cf5d0 634 xloc_u = xloc_u -1;
rpgjake 0:b7a07b6cf5d0 635 break;
rpgjake 0:b7a07b6cf5d0 636 case 5:
rpgjake 0:b7a07b6cf5d0 637 break;
rpgjake 0:b7a07b6cf5d0 638 case 6:
rpgjake 0:b7a07b6cf5d0 639 xloc_u = xloc_u +1;
rpgjake 0:b7a07b6cf5d0 640 break;
rpgjake 0:b7a07b6cf5d0 641 case 7:
rpgjake 0:b7a07b6cf5d0 642 xloc_u = xloc_u -1;
rpgjake 0:b7a07b6cf5d0 643 yloc_u = yloc_u -1;
rpgjake 0:b7a07b6cf5d0 644 break;
rpgjake 0:b7a07b6cf5d0 645 case 8:
rpgjake 0:b7a07b6cf5d0 646 yloc_u = yloc_u -1;
rpgjake 0:b7a07b6cf5d0 647 break;
rpgjake 0:b7a07b6cf5d0 648 case 9:
rpgjake 0:b7a07b6cf5d0 649 xloc_u = xloc_u + 1;
rpgjake 0:b7a07b6cf5d0 650 yloc_u = yloc_u - 1;
rpgjake 0:b7a07b6cf5d0 651 break;
rpgjake 0:b7a07b6cf5d0 652 }
rpgjake 0:b7a07b6cf5d0 653 if (yloc_u <0)
rpgjake 0:b7a07b6cf5d0 654 yloc_u = 0;
rpgjake 0:b7a07b6cf5d0 655 if (xloc_u <0)
rpgjake 0:b7a07b6cf5d0 656 xloc_u = 0;
rpgjake 0:b7a07b6cf5d0 657 if (yloc_u >7)
rpgjake 0:b7a07b6cf5d0 658 yloc_u = 7;
rpgjake 0:b7a07b6cf5d0 659 if (xloc_u >7)
rpgjake 0:b7a07b6cf5d0 660 xloc_u = 7;
rpgjake 0:b7a07b6cf5d0 661 int x_change = 0;
rpgjake 0:b7a07b6cf5d0 662 if (xloc_u != xlast)
rpgjake 0:b7a07b6cf5d0 663 x_change = 1;
rpgjake 0:b7a07b6cf5d0 664 int y_change = 0;
rpgjake 0:b7a07b6cf5d0 665 if (yloc_u != ylast)
rpgjake 0:b7a07b6cf5d0 666 y_change = 1;
rpgjake 0:b7a07b6cf5d0 667 if (((User_person->remain_moves)-(y_change+x_change))<0){
rpgjake 0:b7a07b6cf5d0 668 xloc_u = xlast;
rpgjake 0:b7a07b6cf5d0 669 yloc_u = ylast;
rpgjake 0:b7a07b6cf5d0 670 x_change = 0;
rpgjake 0:b7a07b6cf5d0 671 y_change = 0;
rpgjake 0:b7a07b6cf5d0 672 }
rpgjake 0:b7a07b6cf5d0 673
rpgjake 0:b7a07b6cf5d0 674
rpgjake 1:3a9ef60cbbfc 675 int unit_index = unitsMap1_1[yloc_u][xloc_u];
rpgjake 1:3a9ef60cbbfc 676 int unit_index_R = 0;
rpgjake 1:3a9ef60cbbfc 677 int alliance = 3;
rpgjake 1:3a9ef60cbbfc 678 if ((User_person->job.rng == 2)&&((xloc_u!=xlast)||(yloc_u!=ylast))){
rpgjake 1:3a9ef60cbbfc 679 int yloc_R = yloc_u + (yloc_u - ylast);
rpgjake 1:3a9ef60cbbfc 680 int xloc_R = xloc_u + (xloc_u - xlast);
rpgjake 1:3a9ef60cbbfc 681 if ((xloc_R <=7)&&(xloc_R>=0)&&(yloc_R>=0)&&(yloc_R <=7)){
rpgjake 1:3a9ef60cbbfc 682 unit_index_R = unitsMap1_1[yloc_u][xloc_u];
rpgjake 1:3a9ef60cbbfc 683 if (unit_index_R != 0){
rpgjake 1:3a9ef60cbbfc 684 person_t* target_R;
rpgjake 1:3a9ef60cbbfc 685 target_R = person_array[unit_index_R];
rpgjake 1:3a9ef60cbbfc 686 alliance = target_R->FoF;
rpgjake 1:3a9ef60cbbfc 687 if(((xloc_u!=xlast)||(yloc_u!=ylast))&& (alliance != (User_person-> FoF)))
rpgjake 1:3a9ef60cbbfc 688 {
rpgjake 1:3a9ef60cbbfc 689 combat(User_person, target_R);
rpgjake 1:3a9ef60cbbfc 690 User_person->remain_moves = 0;
rpgjake 1:3a9ef60cbbfc 691 state = 0;
rpgjake 1:3a9ef60cbbfc 692 return 0;
rpgjake 1:3a9ef60cbbfc 693 }
rpgjake 1:3a9ef60cbbfc 694 }
rpgjake 1:3a9ef60cbbfc 695 }
rpgjake 1:3a9ef60cbbfc 696 }
rpgjake 0:b7a07b6cf5d0 697 if (unit_index != 0){
rpgjake 0:b7a07b6cf5d0 698 person_t* target;
rpgjake 0:b7a07b6cf5d0 699 target = person_array[unit_index];
rpgjake 1:3a9ef60cbbfc 700 alliance = target->FoF;
rpgjake 1:3a9ef60cbbfc 701 if (User_person->job.rng == 2){
rpgjake 1:3a9ef60cbbfc 702 m.speed(1.0);
rpgjake 1:3a9ef60cbbfc 703 xloc_u = xlast;
rpgjake 1:3a9ef60cbbfc 704 yloc_u = ylast;
rpgjake 1:3a9ef60cbbfc 705 x_change = 0;
rpgjake 1:3a9ef60cbbfc 706 y_change = 0;
rpgjake 1:3a9ef60cbbfc 707 wait(1.0);
rpgjake 1:3a9ef60cbbfc 708 m.speed(0.0);
rpgjake 1:3a9ef60cbbfc 709 }
rpgjake 1:3a9ef60cbbfc 710 else if ((alliance ==player_turn)&&(User_person->job.attack != staff)){
rpgjake 0:b7a07b6cf5d0 711 m.speed(1.0);
rpgjake 0:b7a07b6cf5d0 712 xloc_u = xlast;
rpgjake 0:b7a07b6cf5d0 713 yloc_u = ylast;
rpgjake 0:b7a07b6cf5d0 714 x_change = 0;
rpgjake 0:b7a07b6cf5d0 715 y_change = 0;
rpgjake 0:b7a07b6cf5d0 716 wait(1.0);
rpgjake 0:b7a07b6cf5d0 717 m.speed(0.0);
rpgjake 0:b7a07b6cf5d0 718 }
rpgjake 0:b7a07b6cf5d0 719 else if(((xloc_u!=xlast)||(yloc_u!=ylast))&& (alliance != (User_person-> FoF)))
rpgjake 0:b7a07b6cf5d0 720 {
rpgjake 0:b7a07b6cf5d0 721 combat(User_person, target);
rpgjake 0:b7a07b6cf5d0 722 User_person->remain_moves = 0;
rpgjake 0:b7a07b6cf5d0 723 state = 0;
rpgjake 0:b7a07b6cf5d0 724 return 0;
rpgjake 0:b7a07b6cf5d0 725 }
rpgjake 1:3a9ef60cbbfc 726 else if(((xloc_u!=xlast)||(yloc_u!=ylast))&& ((User_person->job.attack == staff)&&(alliance == (User_person->FoF))))
rpgjake 1:3a9ef60cbbfc 727 {
rpgjake 1:3a9ef60cbbfc 728 heal(User_person, target);
rpgjake 1:3a9ef60cbbfc 729 User_person->remain_moves = 0;
rpgjake 1:3a9ef60cbbfc 730 state = 0;
rpgjake 1:3a9ef60cbbfc 731 return 0;
rpgjake 1:3a9ef60cbbfc 732 }
rpgjake 0:b7a07b6cf5d0 733 }
rpgjake 0:b7a07b6cf5d0 734 int tile_index = Map1_1[yloc_u][xloc_u];
rpgjake 1:3a9ef60cbbfc 735 tiles check_passable = tile_array[tile_index];
rpgjake 1:3a9ef60cbbfc 736 if ((check_passable.passable) == 1){
rpgjake 0:b7a07b6cf5d0 737 m.speed(1.0);
rpgjake 0:b7a07b6cf5d0 738 xloc_u = xlast;
rpgjake 0:b7a07b6cf5d0 739 yloc_u = ylast;
rpgjake 0:b7a07b6cf5d0 740 x_change = 0;
rpgjake 0:b7a07b6cf5d0 741 y_change = 0;
rpgjake 0:b7a07b6cf5d0 742 wait(1.0);
rpgjake 0:b7a07b6cf5d0 743 m.speed(0.0);
rpgjake 0:b7a07b6cf5d0 744 }
rpgjake 0:b7a07b6cf5d0 745
rpgjake 0:b7a07b6cf5d0 746 if((xlast != xloc_u) || (ylast != yloc_u)){
rpgjake 0:b7a07b6cf5d0 747 tile_index = Map1_1[ylast][xlast];
rpgjake 0:b7a07b6cf5d0 748 unitsMap1_1[ylast][xlast] = 0;
rpgjake 0:b7a07b6cf5d0 749 unitsMap1_1[yloc_u][xloc_u] = User_person->v;
rpgjake 1:3a9ef60cbbfc 750 tiles tile_erased = tile_array[tile_index];
rpgjake 0:b7a07b6cf5d0 751 if (tile_index == 0){
rpgjake 1:3a9ef60cbbfc 752 uLCD.set_sector_address(tile_erased.x, tile_erased.y);
rpgjake 0:b7a07b6cf5d0 753 uLCD.display_image(0, 0);
rpgjake 0:b7a07b6cf5d0 754 }
rpgjake 0:b7a07b6cf5d0 755 else{
rpgjake 1:3a9ef60cbbfc 756 uLCD.set_sector_address(tile_erased.x, tile_erased.y);
rpgjake 0:b7a07b6cf5d0 757 uLCD.display_image(xlast*16, ylast*16);
rpgjake 0:b7a07b6cf5d0 758 }
rpgjake 0:b7a07b6cf5d0 759 uLCD.set_sector_address(User_person->job.x,User_person->job.y);
rpgjake 0:b7a07b6cf5d0 760 User_person->xloc = xloc_u;
rpgjake 0:b7a07b6cf5d0 761 User_person->yloc = yloc_u;
rpgjake 0:b7a07b6cf5d0 762 User_person->xlast = xloc_u;
rpgjake 0:b7a07b6cf5d0 763 User_person->ylast = yloc_u;
rpgjake 0:b7a07b6cf5d0 764 User_person->remain_moves = (User_person->remain_moves) - x_change - y_change;
rpgjake 0:b7a07b6cf5d0 765 uLCD.display_image(((User_person->xloc)*16), ((User_person->yloc)*16));
rpgjake 0:b7a07b6cf5d0 766 }
rpgjake 0:b7a07b6cf5d0 767 }
rpgjake 0:b7a07b6cf5d0 768 state = 0;
rpgjake 0:b7a07b6cf5d0 769 return 0;
rpgjake 0:b7a07b6cf5d0 770 }
rpgjake 0:b7a07b6cf5d0 771
rpgjake 0:b7a07b6cf5d0 772 int analog2Keypad(SparkfunAnalogJoystick *joystick) {
rpgjake 0:b7a07b6cf5d0 773 if (joystick->distance() > .1) { //not in deadzone, accept input
rpgjake 0:b7a07b6cf5d0 774 if ((joystick->angle() > 0.0 && joystick->angle() < 22.5) ||(joystick->angle() > 337.5 && joystick->angle() < 360.0)) {
rpgjake 0:b7a07b6cf5d0 775 return 6;
rpgjake 0:b7a07b6cf5d0 776 } else if (joystick->angle() >= 22.5 && joystick->angle() < 67.5) {
rpgjake 0:b7a07b6cf5d0 777 return 9;
rpgjake 0:b7a07b6cf5d0 778 } else if (joystick->angle() >= 67.5 && joystick->angle() < 112.5) {
rpgjake 0:b7a07b6cf5d0 779 return 8;
rpgjake 0:b7a07b6cf5d0 780 } else if (joystick->angle() >= 112.5 && joystick->angle() < 157.5) {
rpgjake 0:b7a07b6cf5d0 781 return 7;
rpgjake 0:b7a07b6cf5d0 782 } else if (joystick->angle() >= 157.5 && joystick->angle() < 202.5) {
rpgjake 0:b7a07b6cf5d0 783 return 4;
rpgjake 0:b7a07b6cf5d0 784 } else if (joystick->angle() >= 202.5 && joystick->angle() < 247.5) {
rpgjake 0:b7a07b6cf5d0 785 return 1;
rpgjake 0:b7a07b6cf5d0 786 } else if (joystick->angle() >= 247.5 && joystick->angle() < 292.5) {
rpgjake 0:b7a07b6cf5d0 787 return 2;
rpgjake 0:b7a07b6cf5d0 788 } else if (joystick->angle() >= 292.5 && joystick->angle() < 337.5) {
rpgjake 0:b7a07b6cf5d0 789 return 3;
rpgjake 0:b7a07b6cf5d0 790 }
rpgjake 0:b7a07b6cf5d0 791 } else {
rpgjake 0:b7a07b6cf5d0 792 return 5;
rpgjake 0:b7a07b6cf5d0 793 }
rpgjake 0:b7a07b6cf5d0 794 }
rpgjake 0:b7a07b6cf5d0 795
rpgjake 0:b7a07b6cf5d0 796 int combat(person_t* attacker, person_t* defender){
rpgjake 1:3a9ef60cbbfc 797 int d_health;
rpgjake 1:3a9ef60cbbfc 798 if (attacker->job.attack == magic){
rpgjake 6:b17d76960330 799 d_health = (defender->health)-((attacker->job.damage)-(defender->job.defence));
rpgjake 6:b17d76960330 800 }
rpgjake 6:b17d76960330 801 else if (attacker->job.attack == dagger){
rpgjake 6:b17d76960330 802 d_health = (defender->health)-((attacker->job.damage)-((defender->job.defence)/2));
rpgjake 6:b17d76960330 803 }
rpgjake 1:3a9ef60cbbfc 804 else{
rpgjake 6:b17d76960330 805 d_health = (defender->health)-((attacker->job.damage)-(defender->job.res));
rpgjake 6:b17d76960330 806 }
rpgjake 0:b7a07b6cf5d0 807 int a_health;
rpgjake 0:b7a07b6cf5d0 808 if (d_health < (defender->health))
rpgjake 0:b7a07b6cf5d0 809 defender->health = d_health;
rpgjake 1:3a9ef60cbbfc 810 if (((defender->health)>0)&&(attacker->job.rng==1)){
rpgjake 0:b7a07b6cf5d0 811 a_health = (defender->health)-(((attacker->job.damage)-(defender->job.defence))/2);
rpgjake 0:b7a07b6cf5d0 812 attacker->health = a_health;
rpgjake 0:b7a07b6cf5d0 813 }
rpgjake 5:c920ad0bc875 814 //pc.printf("attacker health %d \n",attacker->health);
rpgjake 5:c920ad0bc875 815 //pc.printf("defender health %d \n",defender->health);
rpgjake 5:c920ad0bc875 816 combatPhase(attacker->v, defender->v);
rpgjake 0:b7a07b6cf5d0 817 if ((defender->health)<=0)
rpgjake 0:b7a07b6cf5d0 818 kill_unit(defender);
rpgjake 0:b7a07b6cf5d0 819 if ((attacker->health)<=0)
rpgjake 0:b7a07b6cf5d0 820 kill_unit(attacker);
rpgjake 0:b7a07b6cf5d0 821
rpgjake 0:b7a07b6cf5d0 822
rpgjake 0:b7a07b6cf5d0 823 return 0;
rpgjake 1:3a9ef60cbbfc 824 }
rpgjake 1:3a9ef60cbbfc 825
rpgjake 1:3a9ef60cbbfc 826
rpgjake 1:3a9ef60cbbfc 827 int heal(person_t* attacker, person_t* defender){
rpgjake 1:3a9ef60cbbfc 828 int d_health = (defender->health)+(attacker->job.damage);
rpgjake 1:3a9ef60cbbfc 829 if (d_health > defender->job.maxHealth)
rpgjake 1:3a9ef60cbbfc 830 d_health = defender->job.maxHealth;
rpgjake 1:3a9ef60cbbfc 831 if (d_health != (defender->health))
rpgjake 1:3a9ef60cbbfc 832 defender->health = d_health;
rpgjake 1:3a9ef60cbbfc 833 pc.printf("attacker health %d \n",attacker->health);
rpgjake 1:3a9ef60cbbfc 834 pc.printf("defender health %d \n",defender->health);
rpgjake 1:3a9ef60cbbfc 835
rpgjake 1:3a9ef60cbbfc 836
rpgjake 1:3a9ef60cbbfc 837 return 0;
rpgjake 1:3a9ef60cbbfc 838 }
rpgjake 0:b7a07b6cf5d0 839
rpgjake 0:b7a07b6cf5d0 840 void kill_unit(person_t* dead_unit){
rpgjake 0:b7a07b6cf5d0 841 int xloc = dead_unit->xloc;
rpgjake 0:b7a07b6cf5d0 842 int yloc = dead_unit->yloc;
rpgjake 0:b7a07b6cf5d0 843 unitsMap1_1[yloc][xloc] = 0;
rpgjake 0:b7a07b6cf5d0 844 int tile_index = Map1_1[yloc][xloc];
rpgjake 1:3a9ef60cbbfc 845 tiles tile_dead_spot;
rpgjake 0:b7a07b6cf5d0 846 tile_dead_spot = tile_array[tile_index];
rpgjake 1:3a9ef60cbbfc 847 uLCD.set_sector_address(tile_dead_spot.x,tile_dead_spot.y);
rpgjake 0:b7a07b6cf5d0 848 uLCD.display_image(((dead_unit->xloc)*16), ((dead_unit->yloc)*16));
rpgjake 1:3a9ef60cbbfc 849 dead_unit->status = 0;
rpgjake 0:b7a07b6cf5d0 850 return;
rpgjake 0:b7a07b6cf5d0 851 }
rpgjake 1:3a9ef60cbbfc 852
rpgjake 1:3a9ef60cbbfc 853
rpgjake 1:3a9ef60cbbfc 854 void ai_movement(){
rpgjake 1:3a9ef60cbbfc 855 int ai_r;
rpgjake 1:3a9ef60cbbfc 856 int ai_col;
rpgjake 1:3a9ef60cbbfc 857 int notdead;
rpgjake 1:3a9ef60cbbfc 858 notdead = 0;
rpgjake 1:3a9ef60cbbfc 859 person_t* ai_unit;
rpgjake 3:275705c872e0 860 for( ai_r = 0; ai_r<8; ai_r++){
rpgjake 3:275705c872e0 861 for( ai_col = 0; ai_col<8; ai_col++){
rpgjake 1:3a9ef60cbbfc 862 if (unitsMap1_1[ai_r][ai_col] > 10){
rpgjake 1:3a9ef60cbbfc 863 notdead = 1;
rpgjake 1:3a9ef60cbbfc 864 ai_unit = person_array[unitsMap1_1[ai_r][ai_col]];
rpgjake 1:3a9ef60cbbfc 865 //find enemy
rpgjake 1:3a9ef60cbbfc 866 //move to enemy
rpgjake 1:3a9ef60cbbfc 867 find_player(ai_unit);
rpgjake 1:3a9ef60cbbfc 868
rpgjake 1:3a9ef60cbbfc 869
rpgjake 1:3a9ef60cbbfc 870 }
rpgjake 1:3a9ef60cbbfc 871 }
rpgjake 1:3a9ef60cbbfc 872 }
rpgjake 1:3a9ef60cbbfc 873 if(notdead == 0)
rpgjake 1:3a9ef60cbbfc 874 ask_nextstage();
rpgjake 1:3a9ef60cbbfc 875 }
rpgjake 0:b7a07b6cf5d0 876
rpgjake 1:3a9ef60cbbfc 877 void find_player(person_t* ai_pred){
rpgjake 1:3a9ef60cbbfc 878 int xloc = ai_pred->xloc;
rpgjake 1:3a9ef60cbbfc 879 int yloc = ai_pred->yloc;
rpgjake 1:3a9ef60cbbfc 880 person_t* ai_target;
rpgjake 1:3a9ef60cbbfc 881 int movement = ai_pred->remain_moves;
rpgjake 1:3a9ef60cbbfc 882 int movement_vert;
rpgjake 1:3a9ef60cbbfc 883 int movement_horiz;
rpgjake 1:3a9ef60cbbfc 884 int y;
rpgjake 1:3a9ef60cbbfc 885 int x;
rpgjake 1:3a9ef60cbbfc 886 int negy;
rpgjake 1:3a9ef60cbbfc 887 int negx;
rpgjake 1:3a9ef60cbbfc 888 //parse unit array near me for enemy
rpgjake 1:3a9ef60cbbfc 889 for(movement_vert = 0; movement_vert < movement; movement_vert++){
rpgjake 1:3a9ef60cbbfc 890 for(movement_horiz = 0; movement_horiz < (movement -movement_vert); movement_horiz++){
rpgjake 1:3a9ef60cbbfc 891 y = movement_vert + yloc;
rpgjake 1:3a9ef60cbbfc 892 if(y<0)
rpgjake 1:3a9ef60cbbfc 893 y = 0;
rpgjake 1:3a9ef60cbbfc 894 if(y>7)
rpgjake 1:3a9ef60cbbfc 895 y=7;
rpgjake 1:3a9ef60cbbfc 896 x = movement_horiz + xloc;
rpgjake 1:3a9ef60cbbfc 897 if(x<0)
rpgjake 1:3a9ef60cbbfc 898 x = 0;
rpgjake 1:3a9ef60cbbfc 899 if(x>7)
rpgjake 1:3a9ef60cbbfc 900 x=7;
rpgjake 1:3a9ef60cbbfc 901 negx = xloc - movement_horiz;
rpgjake 1:3a9ef60cbbfc 902 if(negx<0)
rpgjake 1:3a9ef60cbbfc 903 negx = 0;
rpgjake 1:3a9ef60cbbfc 904 if(negx>7)
rpgjake 1:3a9ef60cbbfc 905 negx=7;
rpgjake 1:3a9ef60cbbfc 906 negy = yloc - movement_vert;
rpgjake 1:3a9ef60cbbfc 907 if(negy<0)
rpgjake 1:3a9ef60cbbfc 908 negy = 0;
rpgjake 1:3a9ef60cbbfc 909 if(negy>7)
rpgjake 1:3a9ef60cbbfc 910 negy=7;
rpgjake 1:3a9ef60cbbfc 911 if((unitsMap1_1[y][x]<10) && (unitsMap1_1[y][x] !=0)){
rpgjake 1:3a9ef60cbbfc 912 ai_target = person_array[unitsMap1_1[y][x]];
rpgjake 1:3a9ef60cbbfc 913 hunt_player(ai_pred, ai_target, x, y, xloc, yloc);
rpgjake 1:3a9ef60cbbfc 914 }
rpgjake 1:3a9ef60cbbfc 915 else if((unitsMap1_1[y][negx]<10) && (unitsMap1_1[y][negx] !=0)){
rpgjake 1:3a9ef60cbbfc 916 ai_target = person_array[unitsMap1_1[y][negx]];
rpgjake 1:3a9ef60cbbfc 917 hunt_player(ai_pred, ai_target, negx, y, xloc, yloc);
rpgjake 1:3a9ef60cbbfc 918 }
rpgjake 1:3a9ef60cbbfc 919 else if((unitsMap1_1[negy][x]<10) && (unitsMap1_1[negy][x] !=0)){
rpgjake 1:3a9ef60cbbfc 920 ai_target = person_array[unitsMap1_1[negy][x]];
rpgjake 1:3a9ef60cbbfc 921 hunt_player(ai_pred, ai_target, x, negy, xloc, yloc);
rpgjake 1:3a9ef60cbbfc 922 }
rpgjake 1:3a9ef60cbbfc 923 else if((unitsMap1_1[negy][negx]<10) && (unitsMap1_1[negy][negx] !=0)){
rpgjake 1:3a9ef60cbbfc 924 ai_target = person_array[unitsMap1_1[negy][negx]];
rpgjake 1:3a9ef60cbbfc 925 hunt_player(ai_pred, ai_target, negx, negy, xloc, yloc);
rpgjake 1:3a9ef60cbbfc 926 }
rpgjake 1:3a9ef60cbbfc 927 }
rpgjake 1:3a9ef60cbbfc 928 }
rpgjake 1:3a9ef60cbbfc 929 }
rpgjake 1:3a9ef60cbbfc 930
rpgjake 1:3a9ef60cbbfc 931
rpgjake 1:3a9ef60cbbfc 932 //move to prey
rpgjake 1:3a9ef60cbbfc 933 void hunt_player(person_t* predator, person_t* prey, int prey_x, int prey_y, int predator_x, int predator_y){
rpgjake 1:3a9ef60cbbfc 934 int keypad;
rpgjake 1:3a9ef60cbbfc 935 int count = 0;
rpgjake 1:3a9ef60cbbfc 936 while (count <12){
rpgjake 1:3a9ef60cbbfc 937 count++;
rpgjake 1:3a9ef60cbbfc 938 if ((predator_y - prey_y) >0)
rpgjake 1:3a9ef60cbbfc 939 keypad = 2;
rpgjake 1:3a9ef60cbbfc 940 else if ((predator_y - prey_y) <0)
rpgjake 1:3a9ef60cbbfc 941 keypad = 8;
rpgjake 1:3a9ef60cbbfc 942 if ((predator_x - prey_x) >0)
rpgjake 1:3a9ef60cbbfc 943 keypad = 4;
rpgjake 1:3a9ef60cbbfc 944 else if ((predator_x - prey_x) <0)
rpgjake 1:3a9ef60cbbfc 945 keypad = 6;
rpgjake 1:3a9ef60cbbfc 946 if ( count%2 !=0){
rpgjake 1:3a9ef60cbbfc 947 if ((predator_y - prey_y) >0)
rpgjake 1:3a9ef60cbbfc 948 keypad = 2;
rpgjake 1:3a9ef60cbbfc 949 else if ((predator_y - prey_y) <0)
rpgjake 1:3a9ef60cbbfc 950 keypad = 8;
rpgjake 1:3a9ef60cbbfc 951 }
rpgjake 1:3a9ef60cbbfc 952 person_t* User_person;
rpgjake 1:3a9ef60cbbfc 953 User_person = predator;
rpgjake 1:3a9ef60cbbfc 954 if ((User_person->remain_moves) == 0)
rpgjake 1:3a9ef60cbbfc 955 {
rpgjake 1:3a9ef60cbbfc 956 return;
rpgjake 1:3a9ef60cbbfc 957 }
rpgjake 1:3a9ef60cbbfc 958 if ((User_person->FoF) != player_turn)
rpgjake 1:3a9ef60cbbfc 959 {
rpgjake 1:3a9ef60cbbfc 960 return;
rpgjake 1:3a9ef60cbbfc 961 }
rpgjake 1:3a9ef60cbbfc 962 int xloc_u = 1;
rpgjake 1:3a9ef60cbbfc 963 int yloc_u = 1;
rpgjake 1:3a9ef60cbbfc 964 int xlast = 1;
rpgjake 1:3a9ef60cbbfc 965 int ylast = 1;
rpgjake 1:3a9ef60cbbfc 966 xloc_u = (User_person->xloc);
rpgjake 1:3a9ef60cbbfc 967 yloc_u = User_person->yloc;
rpgjake 1:3a9ef60cbbfc 968 xlast = User_person->xlast;
rpgjake 1:3a9ef60cbbfc 969 ylast = User_person->ylast;
rpgjake 1:3a9ef60cbbfc 970 switch (keypad)
rpgjake 1:3a9ef60cbbfc 971 {
rpgjake 1:3a9ef60cbbfc 972 case 1:
rpgjake 1:3a9ef60cbbfc 973 xloc_u = xloc_u -1;
rpgjake 1:3a9ef60cbbfc 974 yloc_u = yloc_u +1;
rpgjake 1:3a9ef60cbbfc 975 break;
rpgjake 1:3a9ef60cbbfc 976 case 2:
rpgjake 1:3a9ef60cbbfc 977 yloc_u = yloc_u +1;
rpgjake 1:3a9ef60cbbfc 978 break;
rpgjake 1:3a9ef60cbbfc 979 case 3:
rpgjake 1:3a9ef60cbbfc 980 xloc_u = xloc_u +1;
rpgjake 1:3a9ef60cbbfc 981 yloc_u = yloc_u +1;
rpgjake 1:3a9ef60cbbfc 982 break;
rpgjake 1:3a9ef60cbbfc 983 case 4:
rpgjake 1:3a9ef60cbbfc 984 xloc_u = xloc_u -1;
rpgjake 1:3a9ef60cbbfc 985 break;
rpgjake 1:3a9ef60cbbfc 986 case 5:
rpgjake 1:3a9ef60cbbfc 987 break;
rpgjake 1:3a9ef60cbbfc 988 case 6:
rpgjake 1:3a9ef60cbbfc 989 xloc_u = xloc_u +1;
rpgjake 1:3a9ef60cbbfc 990 break;
rpgjake 1:3a9ef60cbbfc 991 case 7:
rpgjake 1:3a9ef60cbbfc 992 xloc_u = xloc_u -1;
rpgjake 1:3a9ef60cbbfc 993 yloc_u = yloc_u -1;
rpgjake 1:3a9ef60cbbfc 994 break;
rpgjake 1:3a9ef60cbbfc 995 case 8:
rpgjake 1:3a9ef60cbbfc 996 yloc_u = yloc_u -1;
rpgjake 1:3a9ef60cbbfc 997 break;
rpgjake 1:3a9ef60cbbfc 998 case 9:
rpgjake 1:3a9ef60cbbfc 999 xloc_u = xloc_u + 1;
rpgjake 1:3a9ef60cbbfc 1000 yloc_u = yloc_u - 1;
rpgjake 1:3a9ef60cbbfc 1001 break;
rpgjake 1:3a9ef60cbbfc 1002 }
rpgjake 1:3a9ef60cbbfc 1003 if (yloc_u <0)
rpgjake 1:3a9ef60cbbfc 1004 yloc_u = 0;
rpgjake 1:3a9ef60cbbfc 1005 if (xloc_u <0)
rpgjake 1:3a9ef60cbbfc 1006 xloc_u = 0;
rpgjake 1:3a9ef60cbbfc 1007 if (yloc_u >7)
rpgjake 1:3a9ef60cbbfc 1008 yloc_u = 7;
rpgjake 1:3a9ef60cbbfc 1009 if (xloc_u >7)
rpgjake 1:3a9ef60cbbfc 1010 xloc_u = 7;
rpgjake 1:3a9ef60cbbfc 1011 int x_change = 0;
rpgjake 1:3a9ef60cbbfc 1012 if (xloc_u != xlast)
rpgjake 1:3a9ef60cbbfc 1013 x_change = 1;
rpgjake 1:3a9ef60cbbfc 1014 int y_change = 0;
rpgjake 1:3a9ef60cbbfc 1015 if (yloc_u != ylast)
rpgjake 1:3a9ef60cbbfc 1016 y_change = 1;
rpgjake 1:3a9ef60cbbfc 1017 if (((User_person->remain_moves)-(y_change+x_change))<0){
rpgjake 1:3a9ef60cbbfc 1018 xloc_u = xlast;
rpgjake 1:3a9ef60cbbfc 1019 yloc_u = ylast;
rpgjake 1:3a9ef60cbbfc 1020 x_change = 0;
rpgjake 1:3a9ef60cbbfc 1021 y_change = 0;
rpgjake 1:3a9ef60cbbfc 1022 }
rpgjake 1:3a9ef60cbbfc 1023
rpgjake 1:3a9ef60cbbfc 1024
rpgjake 1:3a9ef60cbbfc 1025 int unit_index = unitsMap1_1[yloc_u][xloc_u];
rpgjake 1:3a9ef60cbbfc 1026 int unit_index_R = 0;
rpgjake 1:3a9ef60cbbfc 1027 int alliance = 3;
rpgjake 1:3a9ef60cbbfc 1028 if ((User_person->job.rng == 2)&&((xloc_u!=xlast)||(yloc_u!=ylast))){
rpgjake 1:3a9ef60cbbfc 1029 int yloc_R = yloc_u + (yloc_u - ylast);
rpgjake 1:3a9ef60cbbfc 1030 int xloc_R = xloc_u + (xloc_u - xlast);
rpgjake 1:3a9ef60cbbfc 1031 if ((xloc_R <=7)&&(xloc_R>=0)&&(yloc_R>=0)&&(yloc_R <=7)){
rpgjake 1:3a9ef60cbbfc 1032 unit_index_R = unitsMap1_1[yloc_u][xloc_u];
rpgjake 1:3a9ef60cbbfc 1033 if (unit_index_R != 0){
rpgjake 1:3a9ef60cbbfc 1034 person_t* target_R;
rpgjake 1:3a9ef60cbbfc 1035 target_R = person_array[unit_index_R];
rpgjake 1:3a9ef60cbbfc 1036 alliance = target_R->FoF;
rpgjake 1:3a9ef60cbbfc 1037 if(((xloc_u!=xlast)||(yloc_u!=ylast))&& (alliance != (User_person-> FoF)))
rpgjake 1:3a9ef60cbbfc 1038 {
rpgjake 1:3a9ef60cbbfc 1039 combat(User_person, target_R);
rpgjake 1:3a9ef60cbbfc 1040 User_person->remain_moves = 0;
rpgjake 1:3a9ef60cbbfc 1041 return;
rpgjake 1:3a9ef60cbbfc 1042 }
rpgjake 1:3a9ef60cbbfc 1043 }
rpgjake 1:3a9ef60cbbfc 1044 }
rpgjake 1:3a9ef60cbbfc 1045 }
rpgjake 1:3a9ef60cbbfc 1046 if (unit_index != 0){
rpgjake 1:3a9ef60cbbfc 1047 person_t* target;
rpgjake 1:3a9ef60cbbfc 1048 target = person_array[unit_index];
rpgjake 1:3a9ef60cbbfc 1049 alliance = target->FoF;
rpgjake 1:3a9ef60cbbfc 1050 if (User_person->job.rng == 2){
rpgjake 1:3a9ef60cbbfc 1051 m.speed(1.0);
rpgjake 1:3a9ef60cbbfc 1052 xloc_u = xlast;
rpgjake 1:3a9ef60cbbfc 1053 yloc_u = ylast;
rpgjake 1:3a9ef60cbbfc 1054 x_change = 0;
rpgjake 1:3a9ef60cbbfc 1055 y_change = 0;
rpgjake 1:3a9ef60cbbfc 1056 wait(1.0);
rpgjake 1:3a9ef60cbbfc 1057 m.speed(0.0);
rpgjake 1:3a9ef60cbbfc 1058 }
rpgjake 1:3a9ef60cbbfc 1059 else if ((alliance ==player_turn)&&(User_person->job.attack != staff)){
rpgjake 1:3a9ef60cbbfc 1060 m.speed(1.0);
rpgjake 1:3a9ef60cbbfc 1061 xloc_u = xlast;
rpgjake 1:3a9ef60cbbfc 1062 yloc_u = ylast;
rpgjake 1:3a9ef60cbbfc 1063 x_change = 0;
rpgjake 1:3a9ef60cbbfc 1064 y_change = 0;
rpgjake 1:3a9ef60cbbfc 1065 wait(1.0);
rpgjake 1:3a9ef60cbbfc 1066 m.speed(0.0);
rpgjake 1:3a9ef60cbbfc 1067 }
rpgjake 1:3a9ef60cbbfc 1068 else if(((xloc_u!=xlast)||(yloc_u!=ylast))&& (alliance != (User_person-> FoF)))
rpgjake 1:3a9ef60cbbfc 1069 {
rpgjake 1:3a9ef60cbbfc 1070 combat(User_person, target);
rpgjake 1:3a9ef60cbbfc 1071 User_person->remain_moves = 0;
rpgjake 1:3a9ef60cbbfc 1072 return;
rpgjake 1:3a9ef60cbbfc 1073 }
rpgjake 1:3a9ef60cbbfc 1074 else if(((xloc_u!=xlast)||(yloc_u!=ylast))&& ((User_person->job.attack == staff)&&(alliance == (User_person->FoF))))
rpgjake 1:3a9ef60cbbfc 1075 {
rpgjake 1:3a9ef60cbbfc 1076 heal(User_person, target);
rpgjake 1:3a9ef60cbbfc 1077 User_person->remain_moves = 0;
rpgjake 1:3a9ef60cbbfc 1078 return;
rpgjake 1:3a9ef60cbbfc 1079 }
rpgjake 1:3a9ef60cbbfc 1080 }
rpgjake 1:3a9ef60cbbfc 1081 int tile_index = Map1_1[yloc_u][xloc_u];
rpgjake 1:3a9ef60cbbfc 1082 if (tile_index == 0){
rpgjake 1:3a9ef60cbbfc 1083 xloc_u = xlast;
rpgjake 1:3a9ef60cbbfc 1084 yloc_u = ylast;
rpgjake 1:3a9ef60cbbfc 1085 x_change = 0;
rpgjake 1:3a9ef60cbbfc 1086 y_change = 0;
rpgjake 1:3a9ef60cbbfc 1087 }
rpgjake 1:3a9ef60cbbfc 1088
rpgjake 1:3a9ef60cbbfc 1089 if((xlast != xloc_u) || (ylast != yloc_u)){
rpgjake 1:3a9ef60cbbfc 1090 tile_index = Map1_1[ylast][xlast];
rpgjake 1:3a9ef60cbbfc 1091 unitsMap1_1[ylast][xlast] = 0;
rpgjake 1:3a9ef60cbbfc 1092 unitsMap1_1[yloc_u][xloc_u] = User_person->v;
rpgjake 1:3a9ef60cbbfc 1093 tiles tile_erased = tile_array[tile_index];
rpgjake 1:3a9ef60cbbfc 1094 if (tile_index == 0){
rpgjake 1:3a9ef60cbbfc 1095 uLCD.set_sector_address(tile_erased.x, tile_erased.y);
rpgjake 1:3a9ef60cbbfc 1096 uLCD.display_image(0, 0);
rpgjake 1:3a9ef60cbbfc 1097 }
rpgjake 1:3a9ef60cbbfc 1098 else{
rpgjake 1:3a9ef60cbbfc 1099 uLCD.set_sector_address(tile_erased.x, tile_erased.y);
rpgjake 1:3a9ef60cbbfc 1100 uLCD.display_image(xlast*16, ylast*16);
rpgjake 1:3a9ef60cbbfc 1101 }
rpgjake 1:3a9ef60cbbfc 1102 uLCD.set_sector_address(User_person->job.x,User_person->job.y);
rpgjake 1:3a9ef60cbbfc 1103 User_person->xloc = xloc_u;
rpgjake 1:3a9ef60cbbfc 1104 User_person->yloc = yloc_u;
rpgjake 1:3a9ef60cbbfc 1105 User_person->xlast = xloc_u;
rpgjake 1:3a9ef60cbbfc 1106 User_person->ylast = yloc_u;
rpgjake 1:3a9ef60cbbfc 1107 User_person->remain_moves = (User_person->remain_moves) - x_change - y_change;
rpgjake 1:3a9ef60cbbfc 1108 uLCD.display_image(((User_person->xloc)*16), ((User_person->yloc)*16));
rpgjake 1:3a9ef60cbbfc 1109 }
rpgjake 1:3a9ef60cbbfc 1110 }
rpgjake 1:3a9ef60cbbfc 1111 return;
rpgjake 1:3a9ef60cbbfc 1112 }
rpgjake 1:3a9ef60cbbfc 1113
rpgjake 1:3a9ef60cbbfc 1114
rpgjake 1:3a9ef60cbbfc 1115
rpgjake 1:3a9ef60cbbfc 1116
rpgjake 1:3a9ef60cbbfc 1117 void ask_nextstage(){
rpgjake 5:c920ad0bc875 1118 pc.putc(0);
rpgjake 5:c920ad0bc875 1119 pc.putc(12);
rpgjake 5:c920ad0bc875 1120 pc.putc(1);
rpgjake 5:c920ad0bc875 1121 wait(.2);
rpgjake 5:c920ad0bc875 1122 pc.putc(stagenumber);
rpgjake 5:c920ad0bc875 1123 person_t* save_send_person;
rpgjake 5:c920ad0bc875 1124 for(int i = 1; i<12; i++)
rpgjake 5:c920ad0bc875 1125 {
rpgjake 5:c920ad0bc875 1126 save_send_person = person_array[i];
rpgjake 5:c920ad0bc875 1127 pc.putc(save_send_person->status);
rpgjake 5:c920ad0bc875 1128 }
rpgjake 1:3a9ef60cbbfc 1129 player_turn = 1;
rpgjake 1:3a9ef60cbbfc 1130 state = 0;
rpgjake 1:3a9ef60cbbfc 1131 //load next map
rpgjake 1:3a9ef60cbbfc 1132 //init new map
rpgjake 5:c920ad0bc875 1133 while (units_received == 0){
rpgjake 5:c920ad0bc875 1134 waitForAck();
rpgjake 5:c920ad0bc875 1135 }
rpgjake 7:4c8ad4f91c8b 1136 load_floor(stagenumber);
rpgjake 1:3a9ef60cbbfc 1137 load_units_map();
rpgjake 1:3a9ef60cbbfc 1138
rpgjake 1:3a9ef60cbbfc 1139
rpgjake 1:3a9ef60cbbfc 1140 return;
rpgjake 1:3a9ef60cbbfc 1141 }
rpgjake 1:3a9ef60cbbfc 1142
rpgjake 1:3a9ef60cbbfc 1143 void load_units_map(){
rpgjake 1:3a9ef60cbbfc 1144 int y_num;
rpgjake 1:3a9ef60cbbfc 1145 int x_num;
rpgjake 5:c920ad0bc875 1146 int castle_drawn;
rpgjake 5:c920ad0bc875 1147 castle_drawn = 0;
rpgjake 2:ccfe87a5ccba 1148 Julio_Mbed.putc(2);
rpgjake 2:ccfe87a5ccba 1149 Julio_Mbed.putc(stagenumber);
rpgjake 1:3a9ef60cbbfc 1150 tiles tile_draw;
rpgjake 1:3a9ef60cbbfc 1151 person_t* draw_unit;
rpgjake 1:3a9ef60cbbfc 1152 //draw map
rpgjake 3:275705c872e0 1153 for( y_num = 0; y_num<8; y_num++){
rpgjake 3:275705c872e0 1154 for( x_num = 0; x_num<8; x_num++){
rpgjake 1:3a9ef60cbbfc 1155 tile_draw = tile_array[Map1_1[y_num][x_num]];
rpgjake 5:c920ad0bc875 1156 if(Map1_1[y_num][x_num]!=0){
rpgjake 1:3a9ef60cbbfc 1157 uLCD.set_sector_address(tile_draw.x,tile_draw.y);
rpgjake 1:3a9ef60cbbfc 1158 uLCD.display_image((16*x_num),(16*y_num));
rpgjake 5:c920ad0bc875 1159 }
rpgjake 5:c920ad0bc875 1160 else if((Map1_1[y_num][x_num]==0)&&(castle_drawn==0)){
rpgjake 5:c920ad0bc875 1161 uLCD.set_sector_address(tile_draw.x,tile_draw.y);
rpgjake 5:c920ad0bc875 1162 uLCD.display_image((16*x_num),(16*y_num));
rpgjake 5:c920ad0bc875 1163 castle_drawn = 1;
rpgjake 5:c920ad0bc875 1164 }
rpgjake 1:3a9ef60cbbfc 1165 }
rpgjake 1:3a9ef60cbbfc 1166 }
rpgjake 1:3a9ef60cbbfc 1167 //load and draw units on the map
rpgjake 3:275705c872e0 1168 for( y_num = 0; y_num<8; y_num++){
rpgjake 3:275705c872e0 1169 for( x_num = 0; x_num<8; x_num++){
rpgjake 1:3a9ef60cbbfc 1170 if(unitsMap1_1[y_num][x_num] != 0){
rpgjake 1:3a9ef60cbbfc 1171 draw_unit = person_array[unitsMap1_1[y_num][x_num]];
rpgjake 1:3a9ef60cbbfc 1172 draw_unit->xloc = x_num;
rpgjake 1:3a9ef60cbbfc 1173 draw_unit->yloc = y_num;
rpgjake 1:3a9ef60cbbfc 1174 draw_unit->xlast = x_num;
rpgjake 1:3a9ef60cbbfc 1175 draw_unit->ylast = y_num;
rpgjake 1:3a9ef60cbbfc 1176 draw_unit->health = draw_unit->job.maxHealth;
rpgjake 1:3a9ef60cbbfc 1177 draw_unit->remain_moves = draw_unit->job.movement;
rpgjake 1:3a9ef60cbbfc 1178 draw_unit->status = 1;
rpgjake 1:3a9ef60cbbfc 1179 uLCD.set_sector_address(draw_unit->job.x,draw_unit->job.y);
rpgjake 1:3a9ef60cbbfc 1180 uLCD.display_image((16*x_num),(16*y_num));
rpgjake 1:3a9ef60cbbfc 1181 }
rpgjake 1:3a9ef60cbbfc 1182 }
rpgjake 1:3a9ef60cbbfc 1183 }
rpgjake 1:3a9ef60cbbfc 1184
rpgjake 1:3a9ef60cbbfc 1185
rpgjake 1:3a9ef60cbbfc 1186
rpgjake 5:c920ad0bc875 1187 units_received=0;
rpgjake 1:3a9ef60cbbfc 1188 return;
rpgjake 3:275705c872e0 1189 }
rpgjake 3:275705c872e0 1190
rpgjake 3:275705c872e0 1191
rpgjake 3:275705c872e0 1192
rpgjake 3:275705c872e0 1193 void sendMap()
rpgjake 3:275705c872e0 1194 {
rpgjake 3:275705c872e0 1195 for(int i = 0; i < 8; i++)
rpgjake 3:275705c872e0 1196 {
rpgjake 3:275705c872e0 1197 for(int j = 0; j < 8; j++)
rpgjake 3:275705c872e0 1198 {
rpgjake 3:275705c872e0 1199 pc.putc(Map1_1[i][j]);
rpgjake 3:275705c872e0 1200 }
rpgjake 3:275705c872e0 1201 }
rpgjake 3:275705c872e0 1202 }
rpgjake 3:275705c872e0 1203
rpgjake 3:275705c872e0 1204 void sendUnits()
rpgjake 3:275705c872e0 1205 {
rpgjake 3:275705c872e0 1206 for(int a = 0; a < 8; a++)
rpgjake 3:275705c872e0 1207 {
rpgjake 3:275705c872e0 1208 for(int b = 0; b < 8; b++)
rpgjake 3:275705c872e0 1209 {
rpgjake 3:275705c872e0 1210 pc.putc(unitsMap1_1[a][b]);
rpgjake 3:275705c872e0 1211 }
rpgjake 3:275705c872e0 1212 }
rpgjake 3:275705c872e0 1213 }
rpgjake 3:275705c872e0 1214
rpgjake 3:275705c872e0 1215 void receiveMap()
rpgjake 3:275705c872e0 1216 {
rpgjake 3:275705c872e0 1217 for(int c = 0; c < 8; c++)
rpgjake 3:275705c872e0 1218 {
rpgjake 3:275705c872e0 1219 for(int d = 0; d < 8; d++)
rpgjake 3:275705c872e0 1220 {
rpgjake 3:275705c872e0 1221 while(!pc.readable()){}
rpgjake 3:275705c872e0 1222 Map1_1[c][d] = pc.getc();
rpgjake 3:275705c872e0 1223 }
rpgjake 3:275705c872e0 1224 }
rpgjake 3:275705c872e0 1225 }
rpgjake 3:275705c872e0 1226
rpgjake 3:275705c872e0 1227 void receiveUnits()
rpgjake 3:275705c872e0 1228 {
rpgjake 3:275705c872e0 1229 for(int c = 0; c < 8; c++)
rpgjake 3:275705c872e0 1230 {
rpgjake 3:275705c872e0 1231 for(int d = 0; d < 8; d++)
rpgjake 3:275705c872e0 1232 {
rpgjake 3:275705c872e0 1233 while(!pc.readable()){}
rpgjake 3:275705c872e0 1234 unitsMap1_1[c][d] = pc.getc();
rpgjake 3:275705c872e0 1235 }
rpgjake 3:275705c872e0 1236 }
rpgjake 5:c920ad0bc875 1237 units_received = 1;
rpgjake 3:275705c872e0 1238 for(int q = 0; q < 8; q++)
rpgjake 3:275705c872e0 1239 {
rpgjake 3:275705c872e0 1240 for(int w = 0; w < 8; w++)
rpgjake 3:275705c872e0 1241 {
rpgjake 3:275705c872e0 1242 uLCD.printf("%d", Map1_1[q][w]);
rpgjake 3:275705c872e0 1243 }
rpgjake 3:275705c872e0 1244 }
rpgjake 3:275705c872e0 1245 }
rpgjake 3:275705c872e0 1246
rpgjake 3:275705c872e0 1247 void waitForAck()
rpgjake 3:275705c872e0 1248 {
rpgjake 3:275705c872e0 1249 char command[2];
rpgjake 3:275705c872e0 1250 command[0] = '0';
rpgjake 3:275705c872e0 1251 led3=!led3;
rpgjake 3:275705c872e0 1252 while(pc.readable())
rpgjake 3:275705c872e0 1253 {
rpgjake 3:275705c872e0 1254 led4=!led4;
rpgjake 3:275705c872e0 1255 command[0] = pc.getc();
rpgjake 4:47c4ac917fd1 1256 if(command[0] == 'm')
rpgjake 3:275705c872e0 1257 {
rpgjake 4:47c4ac917fd1 1258 led1 = !led1;
rpgjake 3:275705c872e0 1259 sendMap();
rpgjake 3:275705c872e0 1260 }
rpgjake 4:47c4ac917fd1 1261 if(command[0] == 'u')
rpgjake 3:275705c872e0 1262 {
rpgjake 3:275705c872e0 1263 sendUnits();
rpgjake 3:275705c872e0 1264 led1 = !led1;
rpgjake 3:275705c872e0 1265
rpgjake 5:c920ad0bc875 1266 //uLCD.printf("enter combat phase");
rpgjake 5:c920ad0bc875 1267 //combatPhase();
rpgjake 3:275705c872e0 1268 }
rpgjake 4:47c4ac917fd1 1269 if(command[0] == 's')
rpgjake 3:275705c872e0 1270 {
rpgjake 3:275705c872e0 1271 receiveMap();
rpgjake 3:275705c872e0 1272 led2 = !led2;
rpgjake 3:275705c872e0 1273 }
rpgjake 4:47c4ac917fd1 1274 if(command[0] == 'z')
rpgjake 3:275705c872e0 1275 {
rpgjake 3:275705c872e0 1276 receiveUnits();
rpgjake 3:275705c872e0 1277 led2 = !led2;
rpgjake 3:275705c872e0 1278 }
rpgjake 5:c920ad0bc875 1279 if(command[0] == 'f'){
rpgjake 5:c920ad0bc875 1280 //loadFile();
rpgjake 5:c920ad0bc875 1281 led3 = !led3;
rpgjake 5:c920ad0bc875 1282 }
rpgjake 3:275705c872e0 1283 }
rpgjake 3:275705c872e0 1284 }
rpgjake 3:275705c872e0 1285
rpgjake 7:4c8ad4f91c8b 1286
rpgjake 5:c920ad0bc875 1287 void combatPhase(char a, char d)
rpgjake 3:275705c872e0 1288 {
rpgjake 3:275705c872e0 1289 pc.putc('1');
rpgjake 5:c920ad0bc875 1290 pc.putc(a);
rpgjake 5:c920ad0bc875 1291 pc.putc(d);
rpgjake 3:275705c872e0 1292 led4 = 1;
rpgjake 5:c920ad0bc875 1293 return;
rpgjake 1:3a9ef60cbbfc 1294 }