Joe Body 201215898
Embed:
(wiki syntax)
Show/hide line numbers
Aim.cpp
00001 #include "Aim.h" 00002 00003 const int boi [5][5] = 00004 { 00005 {0,0,1,0,0}, 00006 {0,0,1,0,0}, 00007 {1,1,0,1,1}, 00008 {0,0,1,0,0}, 00009 {0,0,1,0,0}, 00010 }; 00011 00012 const int bang [5][5] = 00013 { 00014 {1,0,0,0,1}, 00015 {0,1,0,1,0}, 00016 {0,0,1,0,0}, 00017 {0,1,0,1,0}, 00018 {1,0,0,0,1}, 00019 }; 00020 00021 00022 Aim::Aim() 00023 { 00024 00025 } 00026 00027 Aim::~Aim() 00028 { 00029 00030 } 00031 00032 00033 00034 00035 void Aim::init() 00036 { 00037 _y = 5; // y value on screen is fixed 00038 _x = 42; // cant be past edge of screen 00039 _height = 5; 00040 _width = 5; 00041 //_state = 0; 00042 00043 } 00044 00045 void Aim::draw(N5110 &lcd, int state) 00046 { 00047 // draw basket 00048 bool _state = state; 00049 00050 if (_state == 0){ 00051 lcd.drawSprite(_x,_y,5,5,(int*)boi); 00052 } 00053 if (_state == 1){ 00054 lcd.drawSprite(_x,_y,5,5,(int*)bang); 00055 } 00056 } 00057 00058 void Aim::update(Gamepad &pad) 00059 { 00060 Direction d = pad.get_direction(); 00061 mag = pad.get_mag(); 00062 00063 _speed = int(mag*8.0f); // scale is arbitrary, could be changed in future 00064 00065 // update x value depending on direction of movement 00066 // North is decrement as origin is at the top-left so decreasing moves up 00067 if (d == N) { 00068 _y-=_speed; 00069 } else if (d == NE) { 00070 _x+=_speed; 00071 _y-=_speed; 00072 } else if (d == E) { 00073 _x+=_speed; 00074 } else if (d == SE) { 00075 _x+=_speed; 00076 _y+=_speed; 00077 } else if (d == S) { 00078 _y+=_speed; 00079 } else if (d == SW) { 00080 _x-=_speed; 00081 _y+=_speed; 00082 } else if (d == W) { 00083 _x-=_speed; 00084 } else if (d == NW) { 00085 _x-=_speed; 00086 _y-=_speed; 00087 } 00088 00089 // check the x origin to ensure that the paddle doesn't go off screen 00090 if (_x < 1) { 00091 _x = 1; 00092 } 00093 if (_x > 84 - _width - 1) { 00094 _x = 84 - _width - 1; 00095 } 00096 // check the y origin to ensure that the sprite doesn't go off screen 00097 if (_y < 1) { 00098 _y = 1; 00099 } 00100 if (_y > 48 - _height - 1) { 00101 _y = 48 - _height - 1; 00102 } 00103 } 00104 00105 Vector2D Aim::get_pos() { 00106 Vector2D p = {(_x+2),(_y+2)}; 00107 return p; 00108 } 00109 00110
Generated on Wed Jul 13 2022 05:56:35 by
1.7.2