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.cpp@4:4ce558075c32, 2017-03-21 (annotated)
- Committer:
- Nathanj94
- Date:
- Tue Mar 21 11:08:39 2017 +0000
- Revision:
- 4:4ce558075c32
- Parent:
- 3:d8deea6454df
- Child:
- 5:32421eb42841
functions added to get x and y coords for collision functions
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Nathanj94 | 0:7e132fca6044 | 1 | #include "Basket.h" |
Nathanj94 | 0:7e132fca6044 | 2 | |
Nathanj94 | 0:7e132fca6044 | 3 | Basket::Basket() |
Nathanj94 | 0:7e132fca6044 | 4 | { |
Nathanj94 | 0:7e132fca6044 | 5 | |
Nathanj94 | 0:7e132fca6044 | 6 | } |
Nathanj94 | 0:7e132fca6044 | 7 | |
Nathanj94 | 0:7e132fca6044 | 8 | Basket::~Basket() |
Nathanj94 | 0:7e132fca6044 | 9 | { |
Nathanj94 | 0:7e132fca6044 | 10 | |
Nathanj94 | 0:7e132fca6044 | 11 | } |
Nathanj94 | 2:5d4f2c3f3c0a | 12 | |
Nathanj94 | 0:7e132fca6044 | 13 | void Basket::Basket_init(int y, int width) |
Nathanj94 | 0:7e132fca6044 | 14 | { |
Nathanj94 | 0:7e132fca6044 | 15 | basket_y = y; |
Nathanj94 | 0:7e132fca6044 | 16 | basket_x = WIDTH/2 - width/2; |
Nathanj94 | 0:7e132fca6044 | 17 | basket_width = width; |
Nathanj94 | 0:7e132fca6044 | 18 | basket_speed = 1; |
Nathanj94 | 0:7e132fca6044 | 19 | basket_score = 0; |
Nathanj94 | 0:7e132fca6044 | 20 | } |
Nathanj94 | 0:7e132fca6044 | 21 | |
Nathanj94 | 0:7e132fca6044 | 22 | void Basket::Basket_draw(N5110 &lcd) |
Nathanj94 | 0:7e132fca6044 | 23 | { |
Nathanj94 | 0:7e132fca6044 | 24 | lcd.drawRect(basket_x,basket_y, 1, 2, 0); |
Nathanj94 | 0:7e132fca6044 | 25 | lcd.drawRect(basket_x + 1, basket_y + 2,1,2,0); |
Nathanj94 | 0:7e132fca6044 | 26 | lcd.setPixel(basket_x + 2, basket_y + 4); |
Nathanj94 | 0:7e132fca6044 | 27 | lcd.drawRect(basket_x + 2, basket_y + 5, basket_width - 4, 1, 0); |
Nathanj94 | 0:7e132fca6044 | 28 | lcd.setPixel(basket_x + 9, basket_y + 4); |
Nathanj94 | 0:7e132fca6044 | 29 | lcd.drawRect(basket_x + 10, basket_y + 2, 1, 2, 0); |
Nathanj94 | 0:7e132fca6044 | 30 | lcd.drawRect(basket_x + 11, basket_y, 1, 2, 0); |
Nathanj94 | 0:7e132fca6044 | 31 | } |
Nathanj94 | 0:7e132fca6044 | 32 | |
Nathanj94 | 2:5d4f2c3f3c0a | 33 | void Basket::Basket_move(Direction d, float mag) |
Nathanj94 | 0:7e132fca6044 | 34 | { |
Nathanj94 | 2:5d4f2c3f3c0a | 35 | basket_speed = int(mag*8.0f); |
Nathanj94 | 0:7e132fca6044 | 36 | |
Nathanj94 | 2:5d4f2c3f3c0a | 37 | if (d == E) { |
Nathanj94 | 0:7e132fca6044 | 38 | basket_x += basket_speed; |
Nathanj94 | 2:5d4f2c3f3c0a | 39 | } else if (d == W) { |
Nathanj94 | 0:7e132fca6044 | 40 | basket_x -= basket_speed; |
Nathanj94 | 0:7e132fca6044 | 41 | } |
Nathanj94 | 0:7e132fca6044 | 42 | |
Nathanj94 | 0:7e132fca6044 | 43 | if (basket_x < 1) { |
Nathanj94 | 0:7e132fca6044 | 44 | basket_x = 1; |
Nathanj94 | 0:7e132fca6044 | 45 | } |
Nathanj94 | 0:7e132fca6044 | 46 | if (basket_x > WIDTH - basket_width - 1) { |
Nathanj94 | 0:7e132fca6044 | 47 | basket_x = WIDTH - basket_width - 1; |
Nathanj94 | 0:7e132fca6044 | 48 | } |
Nathanj94 | 0:7e132fca6044 | 49 | } |
Nathanj94 | 0:7e132fca6044 | 50 | |
Nathanj94 | 0:7e132fca6044 | 51 | void Basket::Basket_score() |
Nathanj94 | 0:7e132fca6044 | 52 | { |
Nathanj94 | 0:7e132fca6044 | 53 | basket_score++; |
Nathanj94 | 0:7e132fca6044 | 54 | } |
Nathanj94 | 0:7e132fca6044 | 55 | |
Nathanj94 | 0:7e132fca6044 | 56 | int Basket::get_Basket_score() |
Nathanj94 | 0:7e132fca6044 | 57 | { |
Nathanj94 | 0:7e132fca6044 | 58 | return basket_score; |
Nathanj94 | 3:d8deea6454df | 59 | } |
Nathanj94 | 3:d8deea6454df | 60 | |
Nathanj94 | 4:4ce558075c32 | 61 | int Basket::get_Basket_x() |
Nathanj94 | 4:4ce558075c32 | 62 | { |
Nathanj94 | 4:4ce558075c32 | 63 | return basket_x; |
Nathanj94 | 4:4ce558075c32 | 64 | } |
Nathanj94 | 4:4ce558075c32 | 65 | |
Nathanj94 | 4:4ce558075c32 | 66 | int Basket::get_Basket_y() |
Nathanj94 | 3:d8deea6454df | 67 | { |
Nathanj94 | 3:d8deea6454df | 68 | return basket_y; |
Nathanj94 | 2:5d4f2c3f3c0a | 69 | } |