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