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: mbed
Spikes.cpp
00001 #include "Spikes.h" 00002 00003 const int spike [5][5] = 00004 { 00005 {0,0,1,0,0}, 00006 {0,0,1,0,0}, 00007 {1,1,1,1,1}, 00008 {0,1,1,1,0}, 00009 {0,0,1,0,0}, 00010 }; 00011 00012 const int spike2 [5][5] = 00013 { 00014 {0,0,1,0,0}, 00015 {0,0,1,1,0}, 00016 {1,1,1,1,1}, 00017 {0,0,1,1,0}, 00018 {0,0,1,0,0}, 00019 }; 00020 00021 const int spike3 [5][5] = 00022 { 00023 {0,0,1,0,0}, 00024 {0,1,1,0,0}, 00025 {1,1,1,1,1}, 00026 {0,1,1,0,0}, 00027 {0,0,1,0,0}, 00028 }; 00029 00030 Spikes::Spikes() 00031 { 00032 00033 } 00034 00035 Spikes::~Spikes() 00036 { 00037 00038 } 00039 00040 void Spikes::init(){ 00041 _x = 0; 00042 _y = 0; 00043 _height = 5; 00044 _width = 5; 00045 00046 _speed = 3; 00047 } 00048 00049 00050 void Spikes::draw(N5110 &lcd) 00051 { 00052 // draw spike 00053 lcd.drawSprite(_x,_y,5,5,(int*)spike); 00054 00055 } 00056 void Spikes::draw2(N5110 &lcd) 00057 { 00058 // draw spike 00059 lcd.drawSprite(_x,_y,5,5,(int*)spike2); 00060 00061 } 00062 void Spikes::draw3(N5110 &lcd) 00063 { 00064 // draw spike 00065 lcd.drawSprite(_x,_y,5,5,(int*)spike3); 00066 00067 } 00068 00069 void Spikes::position(int x) 00070 { 00071 if (x == 1){ 00072 _x = rand() % 37 + 1; 00073 _y = 1; 00074 } 00075 if (x == 2){ 00076 _x = rand() % 37 + 42; 00077 _y = 1; 00078 } 00079 if (x == 3){ 00080 _y = rand() % 19 + 1; 00081 _x = 84; 00082 } 00083 if (x == 4){ 00084 _y = rand() % 19 + 24; 00085 _x = 1; 00086 } 00087 //printf("x of spike = %d\n", _x); 00088 //printf("y of spike = %d\n", _y); 00089 } 00090 00091 void Spikes::updatey() 00092 { 00093 _y = _y + 3; 00094 } 00095 00096 void Spikes::updatex() 00097 { 00098 _x = _x + 3; 00099 } 00100 00101 void Spikes::updatexn() 00102 { 00103 _x = _x - 3; 00104 } 00105 00106 00107 Vector2D Spikes::get_pos() { 00108 Vector2D p = {_x,_y}; 00109 return p; 00110 } 00111 00112 void Spikes::hit(Gamepad &pad) 00113 { 00114 pad.led(1,1); 00115 pad.led(4,1);//red flash 00116 wait(0.2); 00117 pad.leds_off(); 00118 } 00119 00120 00121 void Spikes::set_pos(int x, int y) { 00122 _x = x; 00123 _y = y; 00124 } 00125 00126
Generated on Tue Jul 12 2022 18:29:13 by
1.7.2