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

Committer:
Nathanj94
Date:
Thu May 04 12:24:04 2017 +0000
Revision:
13:6865b08e82c3
Parent:
12:b142d87160f1

        

Who changed what in which revision?

UserRevisionLine numberNew 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 13:6865b08e82c3 8 /** Basket Class
Nathanj94 13:6865b08e82c3 9 @brief Class that draws a basket on the display and allows it to be moved left
Nathanj94 13:6865b08e82c3 10 @brief or right along the bottom of the screen. If an object comes into contact
Nathanj94 13:6865b08e82c3 11 @brief with the basket, points are scored.
Nathanj94 13:6865b08e82c3 12
Nathanj94 13:6865b08e82c3 13 @author Nathan Johnston
Nathanj94 13:6865b08e82c3 14 @date 14th March 2017
Nathanj94 13:6865b08e82c3 15 */
Nathanj94 0:7e132fca6044 16 class Basket
Nathanj94 0:7e132fca6044 17 {
Nathanj94 12:b142d87160f1 18 public:
Nathanj94 12:b142d87160f1 19
Nathanj94 0:7e132fca6044 20 Basket();
Nathanj94 0:7e132fca6044 21 ~Basket();
Nathanj94 12:b142d87160f1 22
Nathanj94 9:05fd30d491f1 23 //INITILISATION FUNCTION//
Nathanj94 12:b142d87160f1 24
Nathanj94 10:2e441532206e 25 /** Initialise Basket
Nathanj94 12:b142d87160f1 26 *
Nathanj94 12:b142d87160f1 27 * Sets reference points by which basket can be drawn on screen.
Nathanj94 12:b142d87160f1 28 * Sets score equal to zero.
Nathanj94 12:b142d87160f1 29 * @param y - y co-ordinate of the basket (0 to 47)(41 by default)
Nathanj94 12:b142d87160f1 30 * @param width - width of the basket (0 to 83)(12 by default)
Nathanj94 12:b142d87160f1 31 */
Nathanj94 5:32421eb42841 32 void init(int y, int width);
Nathanj94 12:b142d87160f1 33
Nathanj94 12:b142d87160f1 34
Nathanj94 9:05fd30d491f1 35 //UPDATE FUNCTIONS//
Nathanj94 12:b142d87160f1 36
Nathanj94 10:2e441532206e 37 /** Move Basket w/ Joystick
Nathanj94 12:b142d87160f1 38 *
Nathanj94 12:b142d87160f1 39 * Move the basket left/right using the gamepad's joystick.
Nathanj94 12:b142d87160f1 40 * @param d - direction the joystick is pushed towards (N,NE,E,SE,S,SW,W,NW)
Nathanj94 12:b142d87160f1 41 * @param mag - float in range 0.0 to 1.0
Nathanj94 12:b142d87160f1 42 */
Nathanj94 8:48c5adc809e1 43 void move_stick(Direction d, float mag);
Nathanj94 12:b142d87160f1 44
Nathanj94 10:2e441532206e 45 /** Move the basket w/ L and R
Nathanj94 12:b142d87160f1 46 *
Nathanj94 12:b142d87160f1 47 * Move the basket left/right using the gamepad's L and R buttons.
Nathanj94 12:b142d87160f1 48 * @param pad - Gamepad custom library
Nathanj94 12:b142d87160f1 49 */
Nathanj94 8:48c5adc809e1 50 void move_LR(Gamepad &pad);
Nathanj94 12:b142d87160f1 51
Nathanj94 12:b142d87160f1 52
Nathanj94 9:05fd30d491f1 53 //SCORE FUNCTIONS//
Nathanj94 12:b142d87160f1 54
Nathanj94 10:2e441532206e 55 /** Increase Score (1)
Nathanj94 12:b142d87160f1 56 *
Nathanj94 12:b142d87160f1 57 * Adds 1 to overall score.
Nathanj94 12:b142d87160f1 58 */
Nathanj94 6:2aec1ed2a75a 59 void add_score_1();
Nathanj94 12:b142d87160f1 60
Nathanj94 10:2e441532206e 61 /** Increase Score (2)
Nathanj94 12:b142d87160f1 62 *
Nathanj94 12:b142d87160f1 63 * Adds 2 to overall score.
Nathanj94 12:b142d87160f1 64 */
Nathanj94 6:2aec1ed2a75a 65 void add_score_2();
Nathanj94 12:b142d87160f1 66
Nathanj94 10:2e441532206e 67 /** Increase Score (3)
Nathanj94 12:b142d87160f1 68 *
Nathanj94 12:b142d87160f1 69 * Adds 5 to overall score.
Nathanj94 12:b142d87160f1 70 */
Nathanj94 6:2aec1ed2a75a 71 void add_score_5();
Nathanj94 12:b142d87160f1 72
Nathanj94 10:2e441532206e 73 /** Increase Score (4)
Nathanj94 12:b142d87160f1 74 *
Nathanj94 12:b142d87160f1 75 * Adds 10 to overall score.
Nathanj94 12:b142d87160f1 76 */
Nathanj94 6:2aec1ed2a75a 77 void add_score_10();
Nathanj94 12:b142d87160f1 78
Nathanj94 10:2e441532206e 79 /** Get Score
Nathanj94 12:b142d87160f1 80 *
Nathanj94 12:b142d87160f1 81 * Returns value of score.
Nathanj94 12:b142d87160f1 82 */
Nathanj94 5:32421eb42841 83 int get_score();
Nathanj94 12:b142d87160f1 84
Nathanj94 12:b142d87160f1 85
Nathanj94 9:05fd30d491f1 86 //DISPLAY FUNCTIONS//
Nathanj94 12:b142d87160f1 87
Nathanj94 10:2e441532206e 88 /** Draw Basket
Nathanj94 10:2e441532206e 89 *
Nathanj94 12:b142d87160f1 90 * Draw the basket in the screen buffer using
Nathanj94 10:2e441532206e 91 * the reference points set in Basket::init().
Nathanj94 10:2e441532206e 92 * @param lcd - N5110 custom library
Nathanj94 10:2e441532206e 93 */
Nathanj94 9:05fd30d491f1 94 void draw(N5110 &lcd);
Nathanj94 12:b142d87160f1 95
Nathanj94 10:2e441532206e 96 /** Get x
Nathanj94 10:2e441532206e 97 *
Nathanj94 10:2e441532206e 98 * Return value of the x co-ordinate (0 to 71).
Nathanj94 10:2e441532206e 99 */
Nathanj94 5:32421eb42841 100 int get_x();
Nathanj94 12:b142d87160f1 101
Nathanj94 10:2e441532206e 102 /** Get y
Nathanj94 10:2e441532206e 103 *
Nathanj94 10:2e441532206e 104 * Return value of the y co-ordinate (0 to 47).
Nathanj94 10:2e441532206e 105 */
Nathanj94 5:32421eb42841 106 int get_y();
Nathanj94 12:b142d87160f1 107
Nathanj94 12:b142d87160f1 108 private:
Nathanj94 12:b142d87160f1 109
Nathanj94 10:2e441532206e 110 //VARIABLES//
Nathanj94 5:32421eb42841 111 int y_ref;
Nathanj94 5:32421eb42841 112 int x_ref;
Nathanj94 0:7e132fca6044 113 int basket_width;
Nathanj94 5:32421eb42841 114 int stick_speed;
Nathanj94 5:32421eb42841 115 int score;
Nathanj94 12:b142d87160f1 116
Nathanj94 0:7e132fca6044 117 };
Nathanj94 0:7e132fca6044 118 #endif