ELEC2645 (2018/19) / Mbed 2 deprecated el17dtt

Dependencies:   mbed

Revision:
8:b3738229ba85
Parent:
6:4c55dd4b6d42
Child:
9:dc13042b09f5
--- a/GameEngine/engine.cpp	Sat May 04 00:11:14 2019 +0000
+++ b/GameEngine/engine.cpp	Sat May 04 22:46:31 2019 +0000
@@ -0,0 +1,94 @@
+
+#include "engine.h"
+
+Engine::Engine(){
+    
+    
+}
+
+Engine::~Engine(){
+    
+}
+
+void Engine::init(int screenHeight, int screenWidth, int speed){
+
+    setSpeed(speed);
+    _screen_height = screenHeight;
+    _screen_width = screenWidth;    
+}
+
+void Engine::setSpeed(int speed) {
+    if (speed <= 0) _speed = 0;
+    
+    _speed = speed;
+}
+
+void Engine::update(Gamepad &pad, N5110 &lcd) {
+    
+    clearScreen(lcd);
+    
+    for (int y = 0; y < _screen_height / 2; y++) {
+        for (int x = 0; x < _screen_width; x++) {
+            
+            float fPointCentre = 0.5f;
+            float fRoadSpace = 0.6f;
+            float fSideSpace = fRoadSpace * 0.15f;
+            
+            // for easier calculating the sides
+            fRoadSpace *= 0.5f;
+            
+            int leftGrass = (fPointCentre - fRoadSpace - fSideSpace) * _screen_width;
+            int leftSide = (fPointCentre - fRoadSpace) * _screen_width;
+            int rightGrass = (fPointCentre + fRoadSpace + fSideSpace) * _screen_width;
+            int rightSide = (fPointCentre + fRoadSpace) * _screen_width;
+            
+            int row = _screen_height / 2 + y;
+            
+            if ( x >= 0 && x < leftGrass) {
+                if ( y % 2 == 0 ) 
+                lcd.setPixel(x, row, true);
+            } 
+            if ( x >= leftGrass && x < leftSide) {
+                if ( x % 2 == 0 ) 
+                    lcd.setPixel(x, row, true);
+            }
+            if ( x >= rightSide && x < rightGrass ) {
+                 if ( x % 2 == 0 ) 
+                    lcd.setPixel(x, row, true);
+            } 
+            if ( x >= rightGrass && x < _screen_width) {
+                if ( y % 2 == 0 ) 
+                lcd.setPixel(x, row, true);
+            }        
+        }
+    }
+    lcd.refresh();
+    wait(200);   
+}
+
+int Engine::car1[6*9] = {
+        0,0,0,0,1,0,0,0,0,
+        0,0,0,1,1,1,0,0,0,
+        0,0,0,1,1,1,0,0,0,
+        1,0,1,1,1,1,1,0,1,
+        1,1,1,1,1,1,1,1,1,
+        0,0,0,1,0,1,0,0,0
+    };
+    
+int Engine::car2[6*9] = {
+        0,0,1,0,0,1,1,0,0,
+        0,1,0,0,1,1,1,0,0,
+        0,1,1,1,1,1,0,0,0,
+        1,0,1,1,1,0,0,0,0,
+        0,0,0,1,1,1,1,0,0,
+        0,0,1,0,0,0,0,0,0
+    };
+    
+ int Engine::car3[6*9] = {
+        0,0,1,1,0,0,1,0,0,
+        0,0,1,1,1,0,0,1,0,
+        0,0,0,1,1,1,1,1,0,
+        0,0,0,0,1,1,1,0,1,
+        0,0,1,1,1,1,0,0,0,
+        0,0,0,0,0,0,1,0,0
+     };   
\ No newline at end of file