Library that draws a basket on a Nokia N5110 LCD display and allows it to be moved left/right on the display using buttons or a joystick.
Dependents: Game_Controller_Project
Basket.h@12:b142d87160f1, 2017-05-04 (annotated)
- Committer:
- Nathanj94
- Date:
- Thu May 04 11:16:07 2017 +0000
- Revision:
- 12:b142d87160f1
- Parent:
- 10:2e441532206e
- Child:
- 13:6865b08e82c3
Doxygen updated
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Nathanj94 | 0:7e132fca6044 | 1 | #ifndef BASKET_H |
Nathanj94 | 0:7e132fca6044 | 2 | #define BASKET_H |
Nathanj94 | 0:7e132fca6044 | 3 | |
Nathanj94 | 0:7e132fca6044 | 4 | #include "mbed.h" |
Nathanj94 | 0:7e132fca6044 | 5 | #include "N5110.h" |
Nathanj94 | 0:7e132fca6044 | 6 | #include "Gamepad.h" |
Nathanj94 | 0:7e132fca6044 | 7 | |
Nathanj94 | 0:7e132fca6044 | 8 | class Basket |
Nathanj94 | 0:7e132fca6044 | 9 | { |
Nathanj94 | 12:b142d87160f1 | 10 | public: |
Nathanj94 | 12:b142d87160f1 | 11 | |
Nathanj94 | 0:7e132fca6044 | 12 | Basket(); |
Nathanj94 | 0:7e132fca6044 | 13 | ~Basket(); |
Nathanj94 | 12:b142d87160f1 | 14 | |
Nathanj94 | 9:05fd30d491f1 | 15 | //INITILISATION FUNCTION// |
Nathanj94 | 12:b142d87160f1 | 16 | |
Nathanj94 | 10:2e441532206e | 17 | /** Initialise Basket |
Nathanj94 | 12:b142d87160f1 | 18 | * |
Nathanj94 | 12:b142d87160f1 | 19 | * Sets reference points by which basket can be drawn on screen. |
Nathanj94 | 12:b142d87160f1 | 20 | * Sets score equal to zero. |
Nathanj94 | 12:b142d87160f1 | 21 | * @param y - y co-ordinate of the basket (0 to 47)(41 by default) |
Nathanj94 | 12:b142d87160f1 | 22 | * @param width - width of the basket (0 to 83)(12 by default) |
Nathanj94 | 12:b142d87160f1 | 23 | */ |
Nathanj94 | 5:32421eb42841 | 24 | void init(int y, int width); |
Nathanj94 | 12:b142d87160f1 | 25 | |
Nathanj94 | 12:b142d87160f1 | 26 | |
Nathanj94 | 9:05fd30d491f1 | 27 | //UPDATE FUNCTIONS// |
Nathanj94 | 12:b142d87160f1 | 28 | |
Nathanj94 | 10:2e441532206e | 29 | /** Move Basket w/ Joystick |
Nathanj94 | 12:b142d87160f1 | 30 | * |
Nathanj94 | 12:b142d87160f1 | 31 | * Move the basket left/right using the gamepad's joystick. |
Nathanj94 | 12:b142d87160f1 | 32 | * @param d - direction the joystick is pushed towards (N,NE,E,SE,S,SW,W,NW) |
Nathanj94 | 12:b142d87160f1 | 33 | * @param mag - float in range 0.0 to 1.0 |
Nathanj94 | 12:b142d87160f1 | 34 | */ |
Nathanj94 | 8:48c5adc809e1 | 35 | void move_stick(Direction d, float mag); |
Nathanj94 | 12:b142d87160f1 | 36 | |
Nathanj94 | 10:2e441532206e | 37 | /** Move the basket w/ L and R |
Nathanj94 | 12:b142d87160f1 | 38 | * |
Nathanj94 | 12:b142d87160f1 | 39 | * Move the basket left/right using the gamepad's L and R buttons. |
Nathanj94 | 12:b142d87160f1 | 40 | * @param pad - Gamepad custom library |
Nathanj94 | 12:b142d87160f1 | 41 | */ |
Nathanj94 | 8:48c5adc809e1 | 42 | void move_LR(Gamepad &pad); |
Nathanj94 | 12:b142d87160f1 | 43 | |
Nathanj94 | 12:b142d87160f1 | 44 | |
Nathanj94 | 9:05fd30d491f1 | 45 | //SCORE FUNCTIONS// |
Nathanj94 | 12:b142d87160f1 | 46 | |
Nathanj94 | 10:2e441532206e | 47 | /** Increase Score (1) |
Nathanj94 | 12:b142d87160f1 | 48 | * |
Nathanj94 | 12:b142d87160f1 | 49 | * Adds 1 to overall score. |
Nathanj94 | 12:b142d87160f1 | 50 | */ |
Nathanj94 | 6:2aec1ed2a75a | 51 | void add_score_1(); |
Nathanj94 | 12:b142d87160f1 | 52 | |
Nathanj94 | 10:2e441532206e | 53 | /** Increase Score (2) |
Nathanj94 | 12:b142d87160f1 | 54 | * |
Nathanj94 | 12:b142d87160f1 | 55 | * Adds 2 to overall score. |
Nathanj94 | 12:b142d87160f1 | 56 | */ |
Nathanj94 | 6:2aec1ed2a75a | 57 | void add_score_2(); |
Nathanj94 | 12:b142d87160f1 | 58 | |
Nathanj94 | 10:2e441532206e | 59 | /** Increase Score (3) |
Nathanj94 | 12:b142d87160f1 | 60 | * |
Nathanj94 | 12:b142d87160f1 | 61 | * Adds 5 to overall score. |
Nathanj94 | 12:b142d87160f1 | 62 | */ |
Nathanj94 | 6:2aec1ed2a75a | 63 | void add_score_5(); |
Nathanj94 | 12:b142d87160f1 | 64 | |
Nathanj94 | 10:2e441532206e | 65 | /** Increase Score (4) |
Nathanj94 | 12:b142d87160f1 | 66 | * |
Nathanj94 | 12:b142d87160f1 | 67 | * Adds 10 to overall score. |
Nathanj94 | 12:b142d87160f1 | 68 | */ |
Nathanj94 | 6:2aec1ed2a75a | 69 | void add_score_10(); |
Nathanj94 | 12:b142d87160f1 | 70 | |
Nathanj94 | 10:2e441532206e | 71 | /** Get Score |
Nathanj94 | 12:b142d87160f1 | 72 | * |
Nathanj94 | 12:b142d87160f1 | 73 | * Returns value of score. |
Nathanj94 | 12:b142d87160f1 | 74 | */ |
Nathanj94 | 5:32421eb42841 | 75 | int get_score(); |
Nathanj94 | 12:b142d87160f1 | 76 | |
Nathanj94 | 12:b142d87160f1 | 77 | |
Nathanj94 | 9:05fd30d491f1 | 78 | //DISPLAY FUNCTIONS// |
Nathanj94 | 12:b142d87160f1 | 79 | |
Nathanj94 | 10:2e441532206e | 80 | /** Draw Basket |
Nathanj94 | 10:2e441532206e | 81 | * |
Nathanj94 | 12:b142d87160f1 | 82 | * Draw the basket in the screen buffer using |
Nathanj94 | 10:2e441532206e | 83 | * the reference points set in Basket::init(). |
Nathanj94 | 10:2e441532206e | 84 | * @param lcd - N5110 custom library |
Nathanj94 | 10:2e441532206e | 85 | */ |
Nathanj94 | 9:05fd30d491f1 | 86 | void draw(N5110 &lcd); |
Nathanj94 | 12:b142d87160f1 | 87 | |
Nathanj94 | 10:2e441532206e | 88 | /** Get x |
Nathanj94 | 10:2e441532206e | 89 | * |
Nathanj94 | 10:2e441532206e | 90 | * Return value of the x co-ordinate (0 to 71). |
Nathanj94 | 10:2e441532206e | 91 | */ |
Nathanj94 | 5:32421eb42841 | 92 | int get_x(); |
Nathanj94 | 12:b142d87160f1 | 93 | |
Nathanj94 | 10:2e441532206e | 94 | /** Get y |
Nathanj94 | 10:2e441532206e | 95 | * |
Nathanj94 | 10:2e441532206e | 96 | * Return value of the y co-ordinate (0 to 47). |
Nathanj94 | 10:2e441532206e | 97 | */ |
Nathanj94 | 5:32421eb42841 | 98 | int get_y(); |
Nathanj94 | 12:b142d87160f1 | 99 | |
Nathanj94 | 12:b142d87160f1 | 100 | private: |
Nathanj94 | 12:b142d87160f1 | 101 | |
Nathanj94 | 10:2e441532206e | 102 | //VARIABLES// |
Nathanj94 | 5:32421eb42841 | 103 | int y_ref; |
Nathanj94 | 5:32421eb42841 | 104 | int x_ref; |
Nathanj94 | 0:7e132fca6044 | 105 | int basket_width; |
Nathanj94 | 5:32421eb42841 | 106 | int stick_speed; |
Nathanj94 | 5:32421eb42841 | 107 | int score; |
Nathanj94 | 12:b142d87160f1 | 108 | |
Nathanj94 | 0:7e132fca6044 | 109 | }; |
Nathanj94 | 0:7e132fca6044 | 110 | #endif |