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@10:2e441532206e, 2017-04-27 (annotated)
- Committer:
- Nathanj94
- Date:
- Thu Apr 27 12:39:16 2017 +0000
- Revision:
- 10:2e441532206e
- Parent:
- 9:05fd30d491f1
- Child:
- 12:b142d87160f1
All documentation added
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 | 0:7e132fca6044 | 10 | public: |
Nathanj94 | 2:5d4f2c3f3c0a | 11 | |
Nathanj94 | 0:7e132fca6044 | 12 | Basket(); |
Nathanj94 | 0:7e132fca6044 | 13 | ~Basket(); |
Nathanj94 | 9:05fd30d491f1 | 14 | |
Nathanj94 | 9:05fd30d491f1 | 15 | //INITILISATION FUNCTION// |
Nathanj94 | 10:2e441532206e | 16 | |
Nathanj94 | 10:2e441532206e | 17 | /** Initialise Basket |
Nathanj94 | 10:2e441532206e | 18 | * |
Nathanj94 | 10:2e441532206e | 19 | * Sets reference points by which basket can be drawn on screen. |
Nathanj94 | 10:2e441532206e | 20 | * Sets score equal to zero. |
Nathanj94 | 10:2e441532206e | 21 | * @param y - y co-ordinate of the basket (0 to 47)(41 by default) |
Nathanj94 | 10:2e441532206e | 22 | * @param width - width of the basket (0 to 83)(12 by default) |
Nathanj94 | 10:2e441532206e | 23 | */ |
Nathanj94 | 5:32421eb42841 | 24 | void init(int y, int width); |
Nathanj94 | 9:05fd30d491f1 | 25 | |
Nathanj94 | 10:2e441532206e | 26 | |
Nathanj94 | 9:05fd30d491f1 | 27 | //UPDATE FUNCTIONS// |
Nathanj94 | 10:2e441532206e | 28 | |
Nathanj94 | 10:2e441532206e | 29 | /** Move Basket w/ Joystick |
Nathanj94 | 10:2e441532206e | 30 | * |
Nathanj94 | 10:2e441532206e | 31 | * Move the basket left/right using the gamepad's joystick. |
Nathanj94 | 10:2e441532206e | 32 | * @param d - direction the joystick is pushed towards (N,NE,E,SE,S,SW,W,NW) |
Nathanj94 | 10:2e441532206e | 33 | * @param mag - float in range 0.0 to 1.0 |
Nathanj94 | 10:2e441532206e | 34 | */ |
Nathanj94 | 8:48c5adc809e1 | 35 | void move_stick(Direction d, float mag); |
Nathanj94 | 10:2e441532206e | 36 | |
Nathanj94 | 10:2e441532206e | 37 | /** Move the basket w/ L and R |
Nathanj94 | 10:2e441532206e | 38 | * |
Nathanj94 | 10:2e441532206e | 39 | * Move the basket left/right using the gamepad's L and R buttons. |
Nathanj94 | 10:2e441532206e | 40 | * @param pad - Gamepad custom library |
Nathanj94 | 10:2e441532206e | 41 | */ |
Nathanj94 | 8:48c5adc809e1 | 42 | void move_LR(Gamepad &pad); |
Nathanj94 | 9:05fd30d491f1 | 43 | |
Nathanj94 | 10:2e441532206e | 44 | |
Nathanj94 | 9:05fd30d491f1 | 45 | //SCORE FUNCTIONS// |
Nathanj94 | 10:2e441532206e | 46 | |
Nathanj94 | 10:2e441532206e | 47 | /** Increase Score (1) |
Nathanj94 | 10:2e441532206e | 48 | * |
Nathanj94 | 10:2e441532206e | 49 | * Adds 1 to overall score. |
Nathanj94 | 10:2e441532206e | 50 | */ |
Nathanj94 | 6:2aec1ed2a75a | 51 | void add_score_1(); |
Nathanj94 | 10:2e441532206e | 52 | |
Nathanj94 | 10:2e441532206e | 53 | /** Increase Score (2) |
Nathanj94 | 10:2e441532206e | 54 | * |
Nathanj94 | 10:2e441532206e | 55 | * Adds 2 to overall score. |
Nathanj94 | 10:2e441532206e | 56 | */ |
Nathanj94 | 6:2aec1ed2a75a | 57 | void add_score_2(); |
Nathanj94 | 10:2e441532206e | 58 | |
Nathanj94 | 10:2e441532206e | 59 | /** Increase Score (3) |
Nathanj94 | 10:2e441532206e | 60 | * |
Nathanj94 | 10:2e441532206e | 61 | * Adds 5 to overall score. |
Nathanj94 | 10:2e441532206e | 62 | */ |
Nathanj94 | 6:2aec1ed2a75a | 63 | void add_score_5(); |
Nathanj94 | 10:2e441532206e | 64 | |
Nathanj94 | 10:2e441532206e | 65 | /** Increase Score (4) |
Nathanj94 | 10:2e441532206e | 66 | * |
Nathanj94 | 10:2e441532206e | 67 | * Adds 10 to overall score. |
Nathanj94 | 10:2e441532206e | 68 | */ |
Nathanj94 | 6:2aec1ed2a75a | 69 | void add_score_10(); |
Nathanj94 | 10:2e441532206e | 70 | |
Nathanj94 | 10:2e441532206e | 71 | /** Get Score |
Nathanj94 | 10:2e441532206e | 72 | * |
Nathanj94 | 10:2e441532206e | 73 | * Returns value of score. |
Nathanj94 | 10:2e441532206e | 74 | */ |
Nathanj94 | 5:32421eb42841 | 75 | int get_score(); |
Nathanj94 | 9:05fd30d491f1 | 76 | |
Nathanj94 | 10:2e441532206e | 77 | |
Nathanj94 | 9:05fd30d491f1 | 78 | //DISPLAY FUNCTIONS// |
Nathanj94 | 10:2e441532206e | 79 | |
Nathanj94 | 10:2e441532206e | 80 | /** Draw Basket |
Nathanj94 | 10:2e441532206e | 81 | * |
Nathanj94 | 10:2e441532206e | 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 | 10:2e441532206e | 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 | 10:2e441532206e | 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 | 0:7e132fca6044 | 99 | |
Nathanj94 | 0:7e132fca6044 | 100 | private: |
Nathanj94 | 2:5d4f2c3f3c0a | 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 | 0:7e132fca6044 | 108 | |
Nathanj94 | 0:7e132fca6044 | 109 | }; |
Nathanj94 | 0:7e132fca6044 | 110 | #endif |
Nathanj94 | 0:7e132fca6044 | 111 |