Matis Requis 201241242

Dependencies:   mbed

Tempest Game

Game Screen

https://os.mbed.com/media/uploads/MatisRequis/tempest_board_wiki.png The board is made of 12 columns. The Hero stays at the top of the column

Game Controls

https://os.mbed.com/media/uploads/MatisRequis/gamepad_buttons.png

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.

Revision:
9:759b419fec3b
Child:
10:2ae9d4145410
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Alien/Alien.cpp	Tue May 26 07:26:13 2020 +0000
@@ -0,0 +1,80 @@
+#include "Alien.h"
+
+Alien::Alien() {
+    
+}
+
+Alien::~Alien() {
+    
+}
+
+void Alien::init(int column, int speed) {
+    _currentpos = 14;
+    srand(time(NULL)); //makes pseudo rando number generator have different seed every time based on the current time
+    _column = column;
+    _board.path();
+    _alienspeed = speed;
+    _movcount = 1;
+    
+}
+
+void Alien::draw(N5110 &lcd) {
+    getxy();
+    if (_column < 3 && _column >= 0) {
+        lcd.drawLine(_x-1, _y, _x+1, _y, 1);
+        lcd.drawLine(_x-2, _y+1, _x+2, _y+1, 1);
+        
+    } else if (_column < 6 && _column > 2) {
+        lcd.drawLine(_x, _y-1, _x, _y+1, 1);
+        lcd.drawLine(_x-1, _y-2, _x-1, _y+2, 1);
+        
+    } else if (_column < 9 && _column > 5) {
+        lcd.drawLine(_x-1, _y, _x+1, _y, 1);
+        lcd.drawLine(_x-2, _y-1, _x+2, _y-1, 1);
+              
+    } else if (_column < 12 && _column > 8) {
+        lcd.drawLine(_x, _y-1, _x, _y+1, 1);
+        lcd.drawLine(_x+1, _y-2, _x+1, _y+2, 1);
+    }
+}
+
+void Alien::update() {
+    //advances the alien every x update
+    if (_movcount <= 0) {
+        
+        //random movement can move the alien +1 column, -1 column or not move
+        _rand = (rand() % 3)-1;
+        _column += _rand;
+        
+        _currentpos--;
+        _movcount = _alienspeed;
+    } else {
+        _movcount--;
+    }
+        
+}
+
+int Alien::checkdelete() {
+    if (_currentpos < 1) {
+        _loss = 1;  
+        return 1;
+    } else {
+        return 0;
+    }
+}
+
+int Alien::checkobjective() {
+    if (_loss) {
+        return 1;
+    } else { 
+    return 0; 
+    }
+}
+
+Vector2D Alien::getxy() {
+    _x = _board.drawcolumn[_column][_currentpos].x;
+    _y = _board.drawcolumn[_column][_currentpos].y;
+    
+    Vector2D p = {_board.drawcolumn[_column][_currentpos].x, _board.drawcolumn[_column][_currentpos].y};
+    return p;
+}  
\ No newline at end of file