
mbed version of the Dance Maniax game
Dependencies: 4DGL-uLCD-SE DebounceIn PinDetect SDFileSystem mbed-rtos mbed wave_player
orb/orb_public.cpp@0:43fc00aa360a, 2017-03-13 (annotated)
- Committer:
- jbald9312
- Date:
- Mon Mar 13 23:20:26 2017 +0000
- Revision:
- 0:43fc00aa360a
Added program Dance Maniax
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jbald9312 | 0:43fc00aa360a | 1 | #include "orb_public.h" |
jbald9312 | 0:43fc00aa360a | 2 | |
jbald9312 | 0:43fc00aa360a | 3 | |
jbald9312 | 0:43fc00aa360a | 4 | orb_public::orb_public() {} |
jbald9312 | 0:43fc00aa360a | 5 | orb_public::orb_public(int x, int y) { x_pos = x; y_pos = y;} |
jbald9312 | 0:43fc00aa360a | 6 | int orb_public::get_posX() {return x_pos;} |
jbald9312 | 0:43fc00aa360a | 7 | int orb_public::get_posY() { return y_pos;} |
jbald9312 | 0:43fc00aa360a | 8 | void orb_public::set_posX(int x) {x_pos = x;} |
jbald9312 | 0:43fc00aa360a | 9 | void orb_public::set_posY(int y) {y_pos = y;} |
jbald9312 | 0:43fc00aa360a | 10 | bool orb_public::get_b() {return b;} |
jbald9312 | 0:43fc00aa360a | 11 | ORB_STATUS orb_public::get_status() {return status;} |
jbald9312 | 0:43fc00aa360a | 12 | |
jbald9312 | 0:43fc00aa360a | 13 | |
jbald9312 | 0:43fc00aa360a | 14 | |
jbald9312 | 0:43fc00aa360a | 15 | |
jbald9312 | 0:43fc00aa360a | 16 | //ORB orb_record[MAX_NUM_ORB]; |
jbald9312 | 0:43fc00aa360a | 17 | //int orb_tick=0; |
jbald9312 | 0:43fc00aa360a | 18 | //int orb_interval = 10; |
jbald9312 | 0:43fc00aa360a | 19 | //int score = 0; |
jbald9312 | 0:43fc00aa360a | 20 | //uLCD_4DGL uLCD(p9,p10,p20); |
jbald9312 | 0:43fc00aa360a | 21 | |
jbald9312 | 0:43fc00aa360a | 22 | |
jbald9312 | 0:43fc00aa360a | 23 | /*void orb_public::orb_setup(void) { |
jbald9312 | 0:43fc00aa360a | 24 | stdio_mutex.lock(); |
jbald9312 | 0:43fc00aa360a | 25 | uLCD.color(0xFFFFFF); |
jbald9312 | 0:43fc00aa360a | 26 | uLCD.locate(SIZE_X - 5, 0); |
jbald9312 | 0:43fc00aa360a | 27 | uLCD.printf("Score:"); |
jbald9312 | 0:43fc00aa360a | 28 | uLCD.color(0xFFFFFF); |
jbald9312 | 0:43fc00aa360a | 29 | uLCD.locate(SIZE_X - 2, 1); |
jbald9312 | 0:43fc00aa360a | 30 | uLCD.printf("%d", score); |
jbald9312 | 0:43fc00aa360a | 31 | stdio_mutex.unlock(); |
jbald9312 | 0:43fc00aa360a | 32 | } |
jbald9312 | 0:43fc00aa360a | 33 | void orb_public::orb_generator(void){ |
jbald9312 | 0:43fc00aa360a | 34 | orb_tick++; |
jbald9312 | 0:43fc00aa360a | 35 | // only fire the missile at certain ticks |
jbald9312 | 0:43fc00aa360a | 36 | if((orb_tick % orb_interval)==1 || orb_tick==0){ |
jbald9312 | 0:43fc00aa360a | 37 | orb_create(); |
jbald9312 | 0:43fc00aa360a | 38 | } |
jbald9312 | 0:43fc00aa360a | 39 | |
jbald9312 | 0:43fc00aa360a | 40 | // update the missiles and draw them |
jbald9312 | 0:43fc00aa360a | 41 | orb_update_position(); |
jbald9312 | 0:43fc00aa360a | 42 | } |
jbald9312 | 0:43fc00aa360a | 43 | void orb_public::orb_create(void){ |
jbald9312 | 0:43fc00aa360a | 44 | int i; |
jbald9312 | 0:43fc00aa360a | 45 | for(i=0;i<MAX_NUM_ORB;i++){ |
jbald9312 | 0:43fc00aa360a | 46 | if(orb_record[i].status == ORB_DEACTIVE && (rand() % 2 == 0)){ |
jbald9312 | 0:43fc00aa360a | 47 | orb_record[i].y = SIZE_Y; |
jbald9312 | 0:43fc00aa360a | 48 | //each missile has its own tick |
jbald9312 | 0:43fc00aa360a | 49 | orb_record[i].tick = 0; |
jbald9312 | 0:43fc00aa360a | 50 | //the missile starts at its source |
jbald9312 | 0:43fc00aa360a | 51 | orb_record[i].x = SIZE_X / 2; |
jbald9312 | 0:43fc00aa360a | 52 | orb_record[i].status = ORB_ACTIVE; |
jbald9312 | 0:43fc00aa360a | 53 | orb_record[i].b = true; |
jbald9312 | 0:43fc00aa360a | 54 | break; |
jbald9312 | 0:43fc00aa360a | 55 | } |
jbald9312 | 0:43fc00aa360a | 56 | } |
jbald9312 | 0:43fc00aa360a | 57 | } |
jbald9312 | 0:43fc00aa360a | 58 | void orb_public::orb_update_position(void) { |
jbald9312 | 0:43fc00aa360a | 59 | int i; |
jbald9312 | 0:43fc00aa360a | 60 | for(i=0;i<MAX_NUM_ORB;i++){ |
jbald9312 | 0:43fc00aa360a | 61 | if(orb_record[i].status == ORB_ACTIVE){ |
jbald9312 | 0:43fc00aa360a | 62 | // update missile position |
jbald9312 | 0:43fc00aa360a | 63 | stdio_mutex.lock(); |
jbald9312 | 0:43fc00aa360a | 64 | uLCD.circle(SIZE_X / 2, SIZE_Y / 2, 8, WHITE); |
jbald9312 | 0:43fc00aa360a | 65 | uLCD.filled_circle(orb_record[i].x, orb_record[i].y, 8, RED); |
jbald9312 | 0:43fc00aa360a | 66 | uLCD.filled_circle(orb_record[i].x, orb_record[i].y, 8, BLACK); |
jbald9312 | 0:43fc00aa360a | 67 | stdio_mutex.unlock(); |
jbald9312 | 0:43fc00aa360a | 68 | orb_record[i].y = orb_record[i].y - 5; |
jbald9312 | 0:43fc00aa360a | 69 | //update missile's internal tick |
jbald9312 | 0:43fc00aa360a | 70 | orb_record[i].tick++; |
jbald9312 | 0:43fc00aa360a | 71 | |
jbald9312 | 0:43fc00aa360a | 72 | if (ain > 0.6f && (orb_record[i].y < (SIZE_Y/2) + 5 && orb_record[i].y > (SIZE_Y/2) - 10)) { |
jbald9312 | 0:43fc00aa360a | 73 | stdio_mutex.lock(); |
jbald9312 | 0:43fc00aa360a | 74 | uLCD.filled_circle(SIZE_X / 2, SIZE_Y / 2, 8, BLUE); |
jbald9312 | 0:43fc00aa360a | 75 | stdio_mutex.unlock(); |
jbald9312 | 0:43fc00aa360a | 76 | if(orb_record[i].b) { |
jbald9312 | 0:43fc00aa360a | 77 | orb_record[i].b = false; |
jbald9312 | 0:43fc00aa360a | 78 | score = score + 1; |
jbald9312 | 0:43fc00aa360a | 79 | stdio_mutex.lock(); |
jbald9312 | 0:43fc00aa360a | 80 | uLCD.color(0xFFFFFF); |
jbald9312 | 0:43fc00aa360a | 81 | uLCD.text_width(1); |
jbald9312 | 0:43fc00aa360a | 82 | uLCD.text_height(1); |
jbald9312 | 0:43fc00aa360a | 83 | uLCD.locate(SIZE_X - 2, 1); |
jbald9312 | 0:43fc00aa360a | 84 | uLCD.printf("%d", score); |
jbald9312 | 0:43fc00aa360a | 85 | stdio_mutex.unlock(); |
jbald9312 | 0:43fc00aa360a | 86 | } |
jbald9312 | 0:43fc00aa360a | 87 | |
jbald9312 | 0:43fc00aa360a | 88 | } else if (ain > 0.6f && !(orb_record[i].y < (SIZE_Y/2) + 5 && orb_record[i].y > (SIZE_Y/2) - 10)) { |
jbald9312 | 0:43fc00aa360a | 89 | orb_record[i].b = true; |
jbald9312 | 0:43fc00aa360a | 90 | stdio_mutex.lock(); |
jbald9312 | 0:43fc00aa360a | 91 | uLCD.filled_circle(SIZE_X / 2, SIZE_Y / 2, 8, BLACK); |
jbald9312 | 0:43fc00aa360a | 92 | stdio_mutex.unlock(); |
jbald9312 | 0:43fc00aa360a | 93 | } |
jbald9312 | 0:43fc00aa360a | 94 | |
jbald9312 | 0:43fc00aa360a | 95 | if (orb_record[i].y <= -5) { |
jbald9312 | 0:43fc00aa360a | 96 | orb_record[i].y = SIZE_Y; |
jbald9312 | 0:43fc00aa360a | 97 | orb_record[i].status = ORB_DEACTIVE; |
jbald9312 | 0:43fc00aa360a | 98 | } |
jbald9312 | 0:43fc00aa360a | 99 | } |
jbald9312 | 0:43fc00aa360a | 100 | } |
jbald9312 | 0:43fc00aa360a | 101 | }*/ |