Matis Requis 201241242
Dependencies: mbed
Tempest Game
Game Screen
The board is made of 12 columns. The Hero stays at the top of the column
Game Controls
To control the hero spaceship point the joystick to the column you want the hero to go to.
Press the A button to shoot a bullet in the column you are currently in.
Diff: Board/Board.cpp
- Revision:
- 2:d59a92e65bd9
- Child:
- 3:54132cf073d7
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Board/Board.cpp Tue May 19 10:18:06 2020 +0000 @@ -0,0 +1,107 @@ +#include "Board.h" + +Board::Board() { + +} + +Board::~Board() { + +} + + +void Board::draw(N5110 &lcd) { + //outer rectangle + lcd.drawRect(21, 3, 42, 42, FILL_TRANSPARENT); + + //inner rectangle + lcd.drawRect(34,16,16, 16, FILL_TRANSPARENT); + + + + //Draw lane Lines + + lcd.drawLine(21, 3, 34, 16, 1); + + lcd.drawLine(35, 3, 39, 16, 1); + lcd.drawLine(48,3,44,16,1); + + lcd.drawLine(62,3,49,16,1); + + lcd.drawLine(62,17,49,21,1); + lcd.drawLine(62,30,49,26,1); + + lcd.drawLine(62,44,49,31,1); + + lcd.drawLine(48,44,44,31, 1); + lcd.drawLine(45,44,39,31, 1); + + lcd.drawLine(21,44,34,31,1); + + lcd.drawLine(21,30,34,26,1); + lcd.drawLine(21,17,34,21,1); +} + +void Board::path() { + /*drawpath(28, 3, 37, 16, column0[]); + drawpath(42, 3, 41, 16, column1[]); + drawpath(55, 3, 46, 16, column2[]); + + drawpath(62, 10, 49, 19, column3[]); + drawpath(62, 24, 49, 23, column4[]); + drawpath(62, 37, 49, 28, column5[]); + + drawpath(55, 44, 46, 31, column6[]); + drawpath(41, 44, 42, 31, column7[]); + drawpath(28, 44, 37, 31, column8[]); + + drawpath(21, 10, 34, 19, column9[]); + drawpath(21, 23, 34, 24, column10[]); + drawpath(21, 37, 34, 28, column11[]);*/ + +} + +void Board::drawpath(int x0, int y0, int x1, int y1, Vector2D array[]) { + + int const y_range = static_cast<int>(y1) - static_cast<int>(y0); + int const x_range = static_cast<int>(x1) - static_cast<int>(x0); + + if ( abs(x_range) > abs(y_range) ) { + + // ensure we loop from smallest to largest or else for-loop won't run as expected + unsigned int const start = x_range > 0 ? x0:x1; + unsigned int const stop = x_range > 0 ? x1:x0; + + // loop between x pixels + for (unsigned int x = start; x<= stop ; x++) { + // do linear interpolation + int const dx = static_cast<int>(x)-static_cast<int>(x0); + unsigned int const y = y0 + y_range * dx / x_range; + + // If the line type is '0', this will clear the pixel + // If it is '1' or '2', the pixel will be set + if (dx <= y_range) { + array[dx].y = y; + } + array[dx].x = x; + + } + } else { + + // ensure we loop from smallest to largest or else for-loop won't run as expected + unsigned int const start = y_range > 0 ? y0:y1; + unsigned int const stop = y_range > 0 ? y1:y0; + + for (unsigned int y = start; y<= stop ; y++) { + // do linear interpolation + int const dy = static_cast<int>(y)-static_cast<int>(y0); + unsigned int const x = x0 + x_range * dy / y_range; + + // If the line type is '0', this will clear the pixel + // If it is '1' or '2', the pixel will be set + if (dy <= x_range) { + array[dy].x = x; + } + array[dy].y = y; + } + } +} \ No newline at end of file