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 DebounceIn PinDetect SDFileSystem mbed-rtos mbed wave_player
orb_public.cpp
00001 #include "orb_public.h" 00002 00003 00004 orb_public::orb_public() {} 00005 orb_public::orb_public(int x, int y) { x_pos = x; y_pos = y;} 00006 int orb_public::get_posX() {return x_pos;} 00007 int orb_public::get_posY() { return y_pos;} 00008 void orb_public::set_posX(int x) {x_pos = x;} 00009 void orb_public::set_posY(int y) {y_pos = y;} 00010 bool orb_public::get_b() {return b;} 00011 ORB_STATUS orb_public::get_status() {return status;} 00012 00013 00014 00015 00016 //ORB orb_record[MAX_NUM_ORB]; 00017 //int orb_tick=0; 00018 //int orb_interval = 10; 00019 //int score = 0; 00020 //uLCD_4DGL uLCD(p9,p10,p20); 00021 00022 00023 /*void orb_public::orb_setup(void) { 00024 stdio_mutex.lock(); 00025 uLCD.color(0xFFFFFF); 00026 uLCD.locate(SIZE_X - 5, 0); 00027 uLCD.printf("Score:"); 00028 uLCD.color(0xFFFFFF); 00029 uLCD.locate(SIZE_X - 2, 1); 00030 uLCD.printf("%d", score); 00031 stdio_mutex.unlock(); 00032 } 00033 void orb_public::orb_generator(void){ 00034 orb_tick++; 00035 // only fire the missile at certain ticks 00036 if((orb_tick % orb_interval)==1 || orb_tick==0){ 00037 orb_create(); 00038 } 00039 00040 // update the missiles and draw them 00041 orb_update_position(); 00042 } 00043 void orb_public::orb_create(void){ 00044 int i; 00045 for(i=0;i<MAX_NUM_ORB;i++){ 00046 if(orb_record[i].status == ORB_DEACTIVE && (rand() % 2 == 0)){ 00047 orb_record[i].y = SIZE_Y; 00048 //each missile has its own tick 00049 orb_record[i].tick = 0; 00050 //the missile starts at its source 00051 orb_record[i].x = SIZE_X / 2; 00052 orb_record[i].status = ORB_ACTIVE; 00053 orb_record[i].b = true; 00054 break; 00055 } 00056 } 00057 } 00058 void orb_public::orb_update_position(void) { 00059 int i; 00060 for(i=0;i<MAX_NUM_ORB;i++){ 00061 if(orb_record[i].status == ORB_ACTIVE){ 00062 // update missile position 00063 stdio_mutex.lock(); 00064 uLCD.circle(SIZE_X / 2, SIZE_Y / 2, 8, WHITE); 00065 uLCD.filled_circle(orb_record[i].x, orb_record[i].y, 8, RED); 00066 uLCD.filled_circle(orb_record[i].x, orb_record[i].y, 8, BLACK); 00067 stdio_mutex.unlock(); 00068 orb_record[i].y = orb_record[i].y - 5; 00069 //update missile's internal tick 00070 orb_record[i].tick++; 00071 00072 if (ain > 0.6f && (orb_record[i].y < (SIZE_Y/2) + 5 && orb_record[i].y > (SIZE_Y/2) - 10)) { 00073 stdio_mutex.lock(); 00074 uLCD.filled_circle(SIZE_X / 2, SIZE_Y / 2, 8, BLUE); 00075 stdio_mutex.unlock(); 00076 if(orb_record[i].b) { 00077 orb_record[i].b = false; 00078 score = score + 1; 00079 stdio_mutex.lock(); 00080 uLCD.color(0xFFFFFF); 00081 uLCD.text_width(1); 00082 uLCD.text_height(1); 00083 uLCD.locate(SIZE_X - 2, 1); 00084 uLCD.printf("%d", score); 00085 stdio_mutex.unlock(); 00086 } 00087 00088 } else if (ain > 0.6f && !(orb_record[i].y < (SIZE_Y/2) + 5 && orb_record[i].y > (SIZE_Y/2) - 10)) { 00089 orb_record[i].b = true; 00090 stdio_mutex.lock(); 00091 uLCD.filled_circle(SIZE_X / 2, SIZE_Y / 2, 8, BLACK); 00092 stdio_mutex.unlock(); 00093 } 00094 00095 if (orb_record[i].y <= -5) { 00096 orb_record[i].y = SIZE_Y; 00097 orb_record[i].status = ORB_DEACTIVE; 00098 } 00099 } 00100 } 00101 }*/
Generated on Tue Jul 19 2022 01:26:10 by
1.7.2