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
CrossHairs.h
00001 #ifndef CROSSHAIRS_H 00002 #define CROSSHAIRS_H 00003 00004 #include "mbed.h" 00005 #include "N5110.h" 00006 #include "Gamepad.h" 00007 00008 /** CrossHairs Class 00009 @author Adam Jones, University of Leeds 00010 @brief Interacts with the Cross Hairs which the user uses to aim in the game 00011 @date April 2019 00012 @brief Revision 1.0 00013 00014 @code 00015 #include "N5110.h" 00016 00017 int crossHairsSprite[7][7] = { 00018 { 0,0,1,1,1,0,0 }, 00019 { 0,1,0,0,0,1,0 }, 00020 { 1,0,0,1,0,0,1 }, 00021 { 1,0,1,1,1,0,1 }, 00022 { 1,0,0,1,0,0,1 }, 00023 { 0,1,0,0,0,1,0 }, 00024 { 0,0,1,1,1,0,0 }, 00025 }; 00026 00027 00028 int main() 00029 { 00030 // first need to initialise display 00031 lcd.init(); 00032 00033 //make object of cross hairs class 00034 CrossHairs _crossHairs; 00035 00036 //initialise cross hairs object 00037 _crossHairs.init(CrossHairsSpeed); 00038 00039 float _angle = 180.0 // degrees 00040 float _mag = 1.0 // magnitude 0.0 to 1.0 00041 //update position of cross hairs 00042 _crossHairs.update(_angle,_mag); 00043 00044 //call to add cross hairs to screen 00045 _crossHairs.draw(lcd); 00046 00047 //returns Vector2D position 00048 Vector2D crossHairsLoc = _crossHairs.get_pos(); 00049 00050 00051 Vector2d newPos = = {10,20}; //{x,y}; 00052 //set cross hairs position 00053 _crossHairs.setPos(newPos); 00054 } 00055 @endcode 00056 00057 00058 */ 00059 00060 00061 00062 00063 00064 class CrossHairs 00065 { 00066 00067 public: 00068 CrossHairs(); 00069 ~CrossHairs(); 00070 /** 00071 * @brief Initialises the cross hairs at center position 00072 * @param speed @details Speed of cross hairs in pixels per frame (integer) 00073 */ 00074 void init(int speed); 00075 /** 00076 * @brief Draws the cross hairs on the lcd 00077 * @param lcd @details the N5110 object 00078 */ 00079 void draw(N5110 &lcd); 00080 /** 00081 * @brief Updates the position of the cross hairs based on user input 00082 * @param angle @details angle in degrees 00083 * @param magnitude @details magnitude from 0.0 to 1.0 to allow user to control speed of motion 00084 */ 00085 void update(float angle,float mag); 00086 00087 /// accessors and mutators 00088 /** 00089 * @brief gets the position of the cross hairs 00090 * @returns a Vector2D value of the coordinates 00091 */ 00092 Vector2D get_pos(); 00093 /** 00094 * @brief sets the position of the cross hairs 00095 * @param position @details Vector2D coordinate value 00096 */ 00097 void set_pos(Vector2D p); 00098 00099 private: 00100 00101 float _x; 00102 float _y; 00103 int _speed; 00104 00105 }; 00106 #endif
Generated on Mon Nov 11 2024 22:48:00 by
