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.
Board/Board.cpp
- Committer:
- MatisRequis
- Date:
- 2020-05-21
- Revision:
- 3:54132cf073d7
- Parent:
- 2:d59a92e65bd9
- Child:
- 4:8e3ba8d6d915
File content as of revision 3:54132cf073d7:
#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, drawcolumn[0]); drawpath(42, 3, 41, 16, drawcolumn[1]); drawpath(55, 3, 46, 16, drawcolumn[2]); drawpath(62, 10, 49, 19, drawcolumn[3]); drawpath(62, 24, 49, 23, drawcolumn[4]); drawpath(62, 37, 49, 28, drawcolumn[5]); drawpath(55, 44, 46, 31, drawcolumn[6]); drawpath(41, 44, 42, 31, drawcolumn[7]); drawpath(28, 44, 37, 31, drawcolumn[8]); drawpath(21, 10, 34, 19, drawcolumn[9]); drawpath(21, 23, 34, 24, drawcolumn[10]); drawpath(21, 37, 34, 28, drawcolumn[11]); } void Board::drawpath(int x0, int y0, int x1, int y1, Vector2D array[15]) { 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 xx = start; xx<= stop ; xx++) { // do linear interpolation int const dx = static_cast<int>(xx)-static_cast<int>(x0); unsigned int const yy = 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 (xx <= y_range) { array[dx].y = yy; } array[dx].x = xx; } } 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 yy = start; yy<= stop ; yy++) { // do linear interpolation int const dy = static_cast<int>(yy)-static_cast<int>(y0); unsigned int const xx = 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 (yy <= x_range) { array[dy].x = xx; } array[dy].y = yy; } } }