Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: 4DGL-uLCD-SE Motor SparkfunAnalogJoystick mbed
Fork of Fire_Mbed_2_0 by
Diff: main.cpp
- Revision:
- 3:275705c872e0
- Parent:
- 2:ccfe87a5ccba
- Child:
- 4:47c4ac917fd1
diff -r ccfe87a5ccba -r 275705c872e0 main.cpp
--- a/main.cpp Tue May 02 03:37:35 2017 +0000
+++ b/main.cpp Tue May 02 20:55:30 2017 +0000
@@ -6,7 +6,8 @@
#define MapSecB 123
#include "Motor.h"
-
+int units_recieved = 0;
+Ticker flipper;
Motor m(p21, p24, p25); // pwm, fwd, rev
#define FORTRESS 0
@@ -24,6 +25,10 @@
DigitalIn pb6(p6);
DigitalIn pb7(p7);
DigitalIn pb8(p8);
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+DigitalOut led3(LED3);
+DigitalOut led4(LED4);
#define M_PI 3.14159265358979323846
Serial pc(USBTX, USBRX);
Serial Julio_Mbed(p28,p27);
@@ -74,8 +79,47 @@
static person_t Wolfb;
static person_t Wolfc;
-
-
+static person_t p_Princess;
+static person_t p_Thief;
+static person_t p_WhiteMage;
+static person_t p_Pirate;
+static person_t p_Lancer;
+static person_t p_Archer;
+static person_t p_Dragon;
+static person_t p_Sage;
+static person_t p_Caster;
+static person_t p_Assassin;
+static person_t p_Medic;
+static person_t p_Brigand;
+static person_t p_Wolf_a;
+static person_t p_Wolf_b;
+static person_t p_Wolf_c;
+static person_t p_Assassin_e;
+static person_t p_Thief_a;
+static person_t p_Thief_b;
+static person_t p_Thief_c;
+static person_t p_RedSpider;
+static person_t p_Spider_a;
+static person_t p_Spider_b;
+static person_t p_Spider_c;
+static person_t p_FallenHero;
+static person_t p_Mage_4a;
+static person_t p_Mage_4b;
+static person_t p_Mage_4c;
+static person_t p_TrueAssassin;
+static person_t p_Zombie_5a;
+static person_t p_Zombie_5b;
+static person_t p_Zombie_5c;
+static person_t p_General;
+static person_t p_Zombie_6a;
+static person_t p_Zombie_6b;
+static person_t p_Mage_6a;
+static person_t p_Mage_6b;
+static person_t p_Summoner;
+static person_t p_Zombie_7a;
+static person_t p_Zombie_7b;
+static person_t p_Zombie_7c;
+static person_t p_Zombie_7d;
person_t* person_array[12] = {NULL,&Mc,&Ak,&Ap,&Healer,&Brigand,&Thief,&Soldier,&Wolf,&Wolfa,&Wolfb,&Wolfc};
@@ -114,6 +158,12 @@
void ai_movement(void);
void ask_nextstage(void);
void load_units_map(void);
+void combatPhase(void);
+void sendMap(void);
+void sendUnits (void);
+void receiveMap (void);
+void receiveUnits (void);
+void waitForAck (void);
int state;
int cursor_x;
int cursor_y;
@@ -133,6 +183,7 @@
cursor_y = 0;
state = 0;
person_t* temp_persona;
+ flipper.attach(&waitForAck, 1);
while(1) {
if (state == 0){
selection = user_selecting();}
@@ -198,17 +249,8 @@
castledrawn = 1;
}
}*/
- //get map
- //get units
- //send julio the char[2] {255, map/track number}
- uLCD.printf("Load Map\r\n");
- //put read from gui map code here
- uLCD.printf("Load Units\r\n");
- //put read units from gui code here
- uLCD.printf("New Game\r\n");
- uLCD.printf("Or Continue\r\n");
- uLCD.set_sector_address(Mapx, Mapy);
- uLCD.display_image(0,0);
+ //uLCD.set_sector_address(Mapx, Mapy);
+ //uLCD.display_image(0,0);
Mc.job = Lord;
Mc.v = 1;
Mc.FoF = USER;
@@ -218,8 +260,8 @@
Mc.yloc = 3;
Mc.remain_moves = Mc.job.movement;
Mc.health = Mc.job.maxHealth;
- uLCD.set_sector_address(Mc.job.x, Mc.job.y);
- uLCD.display_image((Mc.xloc*16),(Mc.yloc*16));
+ //uLCD.set_sector_address(Mc.job.x, Mc.job.y);
+ //uLCD.display_image((Mc.xloc*16),(Mc.yloc*16));
Ak.job = Armor;
Ak.v = 2;
@@ -231,10 +273,10 @@
Ak.remain_moves = Ak.job.movement;
Ak.health = Ak.job.maxHealth;
- uLCD.set_sector_address(Ak.job.x, Ak.job.y);
- uLCD.display_image((Ak.xloc*16),(Ak.yloc*16));
+ //uLCD.set_sector_address(Ak.job.x, Ak.job.y);
+ //uLCD.display_image((Ak.xloc*16),(Ak.yloc*16));
- Ap.job = Pirate;
+ Ap.job = j_Pirate;
Ap.v = 3;
Ap.FoF = USER;
Ap.xlast = 2;
@@ -244,10 +286,10 @@
Ap.remain_moves = Ap.job.movement;
Ap.health = Ap.job.maxHealth;
- uLCD.set_sector_address(Ap.job.x, Ap.job.y);
- uLCD.display_image((Ap.xloc*16),(Ap.yloc*16));
+ //uLCD.set_sector_address(Ap.job.x, Ap.job.y);
+ //uLCD.display_image((Ap.xloc*16),(Ap.yloc*16));
- Healer.job = Cleric;
+ Healer.job = j_Cleric;
Healer.v = 4;
Healer.FoF = USER;
Healer.xlast = 0;
@@ -257,8 +299,8 @@
Healer.remain_moves = Healer.job.movement;
Healer.health = Healer.job.maxHealth;
- uLCD.set_sector_address(Healer.job.x, Healer.job.y);
- uLCD.display_image((Healer.xloc*16),(Healer.yloc*16));
+ //uLCD.set_sector_address(Healer.job.x, Healer.job.y);
+ //uLCD.display_image((Healer.xloc*16),(Healer.yloc*16));
Wolf.job = Beast;
Wolf.v = 8;
@@ -270,9 +312,9 @@
Wolf.remain_moves = Wolf.job.movement;
Wolf.health = Wolf.job.maxHealth;
- uLCD.set_sector_address(Wolf.job.x, Wolf.job.y);
- uLCD.display_image((Wolf.xloc*16),(Wolf.yloc*16));
- unitsMap1_1[Wolf.yloc][Wolf.xloc] = Wolf.v;
+ //uLCD.set_sector_address(Wolf.job.x, Wolf.job.y);
+ //uLCD.display_image((Wolf.xloc*16),(Wolf.yloc*16));
+ //unitsMap1_1[Wolf.yloc][Wolf.xloc] = Wolf.v;
Wolfa.job = Beast;
Wolfa.v = 9;
@@ -284,9 +326,9 @@
Wolfa.remain_moves = Wolfa.job.movement;
Wolfa.health = Wolfa.job.maxHealth;
- uLCD.set_sector_address(Wolfa.job.x, Wolfa.job.y);
- uLCD.display_image((Wolfa.xloc*16),(Wolfa.yloc*16));
- unitsMap1_1[Wolfa.yloc][Wolfa.xloc] = Wolfa.v;
+ //uLCD.set_sector_address(Wolfa.job.x, Wolfa.job.y);
+ //uLCD.display_image((Wolfa.xloc*16),(Wolfa.yloc*16));
+ //unitsMap1_1[Wolfa.yloc][Wolfa.xloc] = Wolfa.v;
Wolfb.job = Beast;
Wolfb.v = 10;
@@ -298,9 +340,9 @@
Wolfb.remain_moves = Wolfb.job.movement;
Wolfb.health = Wolfb.job.maxHealth;
- uLCD.set_sector_address(Wolfb.job.x, Wolfb.job.y);
- uLCD.display_image((Wolfb.xloc*16),(Wolfb.yloc*16));
- unitsMap1_1[Wolfb.yloc][Wolfb.xloc] = Wolfb.v;
+ //uLCD.set_sector_address(Wolfb.job.x, Wolfb.job.y);
+ //uLCD.display_image((Wolfb.xloc*16),(Wolfb.yloc*16));
+ //unitsMap1_1[Wolfb.yloc][Wolfb.xloc] = Wolfb.v;
Wolfc.job = Beast;
@@ -313,15 +355,27 @@
Wolfc.remain_moves = Wolfc.job.movement;
Wolfc.health = Wolfc.job.maxHealth;
- uLCD.set_sector_address(Wolfc.job.x, Wolfc.job.y);
- uLCD.display_image((Wolfc.xloc*16),(Wolfc.yloc*16));
- unitsMap1_1[Wolfc.yloc][Wolfc.xloc] = Wolfc.v;
+ //uLCD.set_sector_address(Wolfc.job.x, Wolfc.job.y);
+ //uLCD.display_image((Wolfc.xloc*16),(Wolfc.yloc*16));
+ //unitsMap1_1[Wolfc.yloc][Wolfc.xloc] = Wolfc.v;
+
+ //unitsMap1_1[Mc.yloc][Mc.xloc] = Mc.v;
+ //unitsMap1_1[Ak.yloc][Ak.xloc] = Ak.v;
+ //unitsMap1_1[Ap.yloc][Ap.xloc] = Ap.v;
+ //unitsMap1_1[Healer.yloc][Healer.xloc] = Healer.v;
- unitsMap1_1[Mc.yloc][Mc.xloc] = Mc.v;
- unitsMap1_1[Ak.yloc][Ak.xloc] = Ak.v;
- unitsMap1_1[Ap.yloc][Ap.xloc] = Ap.v;
- unitsMap1_1[Healer.yloc][Healer.xloc] = Healer.v;
-
+ //get map
+ //get units
+ //send julio the char[2] {255, map/track number}
+ uLCD.printf("Load Map\r\n");
+ //put read from gui map code here
+ uLCD.printf("Load Units\r\n");
+ //put read units from gui code here
+ uLCD.printf("New Game\r\n");
+ uLCD.printf("Or Continue\r\n");
+ while(units_recieved == 0){
+ wait(.5);}
+ load_units_map();
return;
}
int user_selecting(void){
@@ -736,8 +790,8 @@
int notdead;
notdead = 0;
person_t* ai_unit;
- for( ai_r = 0; ai_r<7; ai_r++){
- for( ai_col = 0; ai_col<7; ai_col++){
+ for( ai_r = 0; ai_r<8; ai_r++){
+ for( ai_col = 0; ai_col<8; ai_col++){
if (unitsMap1_1[ai_r][ai_col] > 10){
notdead = 1;
ai_unit = person_array[unitsMap1_1[ai_r][ai_col]];
@@ -1013,16 +1067,16 @@
tiles tile_draw;
person_t* draw_unit;
//draw map
- for( y_num = 0; y_num<7; y_num++){
- for( x_num = 0; x_num<7; x_num++){
+ for( y_num = 0; y_num<8; y_num++){
+ for( x_num = 0; x_num<8; x_num++){
tile_draw = tile_array[Map1_1[y_num][x_num]];
uLCD.set_sector_address(tile_draw.x,tile_draw.y);
uLCD.display_image((16*x_num),(16*y_num));
}
}
//load and draw units on the map
- for( y_num = 0; y_num<7; y_num++){
- for( x_num = 0; x_num<7; x_num++){
+ for( y_num = 0; y_num<8; y_num++){
+ for( x_num = 0; x_num<8; x_num++){
if(unitsMap1_1[y_num][x_num] != 0){
draw_unit = person_array[unitsMap1_1[y_num][x_num]];
draw_unit->xloc = x_num;
@@ -1040,6 +1094,106 @@
-
+ units_recieved=0;
return;
+}
+
+
+
+void sendMap()
+{
+ for(int i = 0; i < 8; i++)
+ {
+ for(int j = 0; j < 8; j++)
+ {
+ pc.putc(Map1_1[i][j]);
+ }
+ }
+}
+
+void sendUnits()
+{
+ for(int a = 0; a < 8; a++)
+ {
+ for(int b = 0; b < 8; b++)
+ {
+ pc.putc(unitsMap1_1[a][b]);
+ }
+ }
+}
+
+void receiveMap()
+{
+ for(int c = 0; c < 8; c++)
+ {
+ for(int d = 0; d < 8; d++)
+ {
+ while(!pc.readable()){}
+ Map1_1[c][d] = pc.getc();
+ }
+ }
+}
+
+void receiveUnits()
+{
+ for(int c = 0; c < 8; c++)
+ {
+ for(int d = 0; d < 8; d++)
+ {
+ while(!pc.readable()){}
+ unitsMap1_1[c][d] = pc.getc();
+ }
+ }
+ units_recieved = 1;
+ for(int q = 0; q < 8; q++)
+ {
+ for(int w = 0; w < 8; w++)
+ {
+ uLCD.printf("%d", Map1_1[q][w]);
+ }
+ }
+}
+
+void waitForAck()
+{
+ char command[2];
+ command[0] = '0';
+ led3=!led3;
+ while(pc.readable())
+ {
+ led4=!led4;
+ command[0] = pc.getc();
+ command[1] = pc.getc();
+ if(strcmp(command, "rm")==0)
+ {
+ sendMap();
+ led1 = !led1;
+ }
+ if(strcmp(command, "ru")==0)
+ {
+ sendUnits();
+ led1 = !led1;
+
+ uLCD.printf("enter combat phase");
+ combatPhase();
+ }
+ if(strcmp(command, "sm")==0)
+ {
+ receiveMap();
+ led2 = !led2;
+ }
+ if(strcmp(command, "su")==0)
+ {
+ receiveUnits();
+ led2 = !led2;
+ }
+ }
+}
+
+void combatPhase()
+{
+ pc.putc('1');
+ wait(5);
+ pc.putc('2');
+ led4 = 1;
}
\ No newline at end of file
