asdf

Dependencies:   mbed 4DGL-uLCD-SE MMA8452

Files at this revision

API Documentation at this revision

Comitter:
cx872
Date:
Thu Dec 10 19:53:39 2020 +0000
Commit message:
uint32_t Q:1 ERROR

Changed in this revision

4DGL-uLCD-SE.lib Show annotated file Show diff for this revision Revisions of this file
AbstractAsteroid.h Show annotated file Show diff for this revision Revisions of this file
ConcreteAsteroid1.cpp Show annotated file Show diff for this revision Revisions of this file
ConcreteAsteroid1.h Show annotated file Show diff for this revision Revisions of this file
MMA8452.lib Show annotated file Show diff for this revision Revisions of this file
ScreenObject.h Show annotated file Show diff for this revision Revisions of this file
SpaceShipEarth.cpp Show annotated file Show diff for this revision Revisions of this file
SpaceShipEarth.h Show annotated file Show diff for this revision Revisions of this file
game.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
utils.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r f39fc06d19be 4DGL-uLCD-SE.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/4DGL-uLCD-SE.lib	Thu Dec 10 19:53:39 2020 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/4180_1/code/4DGL-uLCD-SE/#e39a44de229a
diff -r 000000000000 -r f39fc06d19be AbstractAsteroid.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/AbstractAsteroid.h	Thu Dec 10 19:53:39 2020 +0000
@@ -0,0 +1,11 @@
+#include "ScreenObject.h"
+
+
+
+class AbstractAsteroid : public ScreenObject {
+    public:
+        virtual void draw() = 0;
+        virtual void update(int, int) = 0;
+    protected:
+        int deltaX, deltaY;   
+};
\ No newline at end of file
diff -r 000000000000 -r f39fc06d19be ConcreteAsteroid1.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ConcreteAsteroid1.cpp	Thu Dec 10 19:53:39 2020 +0000
@@ -0,0 +1,16 @@
+#include "ConcreteAsteroid1.h"
+#include "utils.cpp"
+extern uLCD_4DGL lcd;
+extern Serial pc;
+
+void ConcreteAsteroid1::draw() {
+    lcd.BLIT(this->x, this->y, ASTEROID_HEIGHT, ASTEROID_WIDTH, asteroid_sprite_1);
+}
+
+void ConcreteAsteroid1::update(int _x, int _y) {
+    lcd.BLIT(this->x, this->y, ASTEROID_HEIGHT, ASTEROID_WIDTH, black_asteriod);
+    this->x = _x;
+    this->y = _y;
+    this->draw();
+}
+
diff -r 000000000000 -r f39fc06d19be ConcreteAsteroid1.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ConcreteAsteroid1.h	Thu Dec 10 19:53:39 2020 +0000
@@ -0,0 +1,11 @@
+#include "AbstractAsteroid.h"
+#include "uLCD_4DGL.h"
+
+
+
+
+class ConcreteAsteroid1 : public AbstractAsteroid {
+    public:
+        void draw();
+        void update(int, int);
+};
\ No newline at end of file
diff -r 000000000000 -r f39fc06d19be MMA8452.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MMA8452.lib	Thu Dec 10 19:53:39 2020 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/ece2035ta/code/MMA8452/#53030e47347a
diff -r 000000000000 -r f39fc06d19be ScreenObject.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ScreenObject.h	Thu Dec 10 19:53:39 2020 +0000
@@ -0,0 +1,16 @@
+#ifndef SCREENOBJECT_H
+#define SCREENOBJECT_H
+#include "utils.cpp"
+
+class ScreenObject {
+    
+    public:
+        // Pure virtual functions
+        virtual void draw() = 0;
+        virtual void update(int, int) = 0;
+    
+    protected:
+        int x, y;  
+};
+
+#endif
\ No newline at end of file
diff -r 000000000000 -r f39fc06d19be SpaceShipEarth.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SpaceShipEarth.cpp	Thu Dec 10 19:53:39 2020 +0000
@@ -0,0 +1,25 @@
+#include "SpaceShipEarth.h"
+#include "uLCD_4DGL.h"
+//#include "utils.cpp"
+
+extern uLCD_4DGL lcd;
+extern Serial pc;
+
+SpaceShipEarth::SpaceShipEarth() {
+    this->x = SCREEN_CENTER;
+    this->y = SCREEN_CENTER;
+    this->dx = 0;
+    this->dy = 0;   
+    pc.printf("created SpaceShipEarth\n");    
+}
+
+void SpaceShipEarth::draw() {
+    lcd.BLIT(this->x, this->y, EARTH_HEIGHT, EARTH_WIDTH, spaceship_earth1);
+}
+
+void SpaceShipEarth::update(int _x, int _y) {
+    lcd.BLIT(this->x, this->y, EARTH_HEIGHT, EARTH_WIDTH, black_earth);
+    this->x = _x;
+    this->y = _y;
+    this->draw();
+}
\ No newline at end of file
diff -r 000000000000 -r f39fc06d19be SpaceShipEarth.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SpaceShipEarth.h	Thu Dec 10 19:53:39 2020 +0000
@@ -0,0 +1,16 @@
+#ifndef SPACESHIPEARTH_H
+#define SPACESHIPEARTH_H
+#include "ScreenObject.h"
+
+
+class SpaceShipEarth : public ScreenObject {
+    public:
+        SpaceShipEarth();
+        void draw();
+        void update(int, int);
+        
+    private:
+        int dx, dy;   
+};
+
+#endif
\ No newline at end of file
diff -r 000000000000 -r f39fc06d19be game.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/game.cpp	Thu Dec 10 19:53:39 2020 +0000
@@ -0,0 +1,38 @@
+#include "mbed.h"
+#include "MMA8452.h"
+#include "uLCD_4DGL.h"
+
+
+#include "ScreenObject.h"
+#include "SpaceShipEarth.h"
+
+#define SCREEN_CENTER 59
+
+double ax, ay, az;                  // accelerometer readings 
+
+Serial pc(USBTX, USBRX, 9600);
+MMA8452 acc(p28, p27, 100000);
+uLCD_4DGL lcd(p9, p10, p11);
+
+bool overlap(ScreenObject & objectA, ScreenObject & objectB);
+
+
+bool overlap(ScreenObject & objectA, ScreenObject & objectB) {
+    return true;
+}
+
+int main() {
+    lcd.baudrate(300000);
+    srand(time(NULL));
+    SpaceShipEarth spe;
+    ScreenObject* earth = &spe;
+    while (1) {
+        acc.readXYZGravity(&ay, &ax, &az);
+        int newy = (int) SCREEN_CENTER + 70 * ay;
+        int newx = (int) SCREEN_CENTER + 70 * ax;
+//        pc.printf("%d, %d\n", newx, newy);
+        earth->update(newx, newy);
+        wait(0.08);
+    }
+}
+
diff -r 000000000000 -r f39fc06d19be mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Dec 10 19:53:39 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file
diff -r 000000000000 -r f39fc06d19be utils.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/utils.cpp	Thu Dec 10 19:53:39 2020 +0000
@@ -0,0 +1,154 @@
+#ifndef UTILS_H
+#define UTILS_H
+
+
+// Global Variables 
+#define ASTEROID_HEIGHT 15
+#define ASTEROID_WIDTH 15
+#define SPRITE_MAX 15
+#define EARTH_WIDTH 10
+#define EARTH_HEIGHT 10
+#define EXPLOSION1_WIDTH 20
+#define SCREEN_MAX 125
+#define SCREEN_MIN 1
+#define NUM_ASTEROIDS 4
+#define SCREEN_CENTER 59
+
+
+#define Q 0x808000 //OLIVE
+#define I 0x008000 //GREEN
+#define S 0xC0C0C0 //SILVER
+#define C 0x17202A //UFO GLASS
+#define D 0x797D7F //DARK GREY
+#define L 0x00FF00 //LIME
+#define P 0xFF00FF //PINK
+#define R 0xF1C40F //YELLOW
+#define O 0xF39C12 //ORANGE
+#define G 0xAAB7B8 //GREY
+#define _ 0x000000 //BLACK
+#define X 0xFFFFFF //WHITE
+
+
+int asteroid_sprite_1[ASTEROID_HEIGHT * ASTEROID_WIDTH] = {
+    _,_,_,_,_,_,_,_,_,_,_,_,_,_,_,
+    _,_,_,_,_,X,X,X,X,X,X,X,_,_,_,
+    _,_,_,_,X,_,_,_,_,_,_,_,X,_,_,
+    _,_,_,X,_,_,_,_,_,_,_,_,X,_,_,
+    _,_,X,_,_,_,_,_,_,_,_,_,X,_,_,
+    _,X,_,_,_,_,_,_,_,_,_,_,X,_,_,
+    X,X,X,X,_,_,_,_,_,_,_,_,_,X,_,
+    _,_,_,X,_,_,_,_,_,_,_,_,_,X,_,
+    _,_,X,_,_,_,_,_,_,_,_,_,_,X,_,
+    _,X,_,_,_,_,_,X,_,_,_,_,_,X,_,
+    X,_,_,_,_,_,X,X,_,_,_,_,X,_,_,
+    _,X,_,_,_,X,_,X,_,_,_,_,X,_,_,
+    _,_,X,_,X,_,_,X,_,_,_,X,_,_,_,
+    _,_,_,X,_,_,_,X,X,X,X,_,_,_,_,
+    _,_,_,_,_,_,_,_,_,_,_,_,_,_,_
+
+
+};
+
+
+int asteroid_sprite_2[ASTEROID_HEIGHT * ASTEROID_WIDTH] = {
+    _,_,_,_,_,_,_,_,_,_,_,_,_,_,_,
+    _,_,_,_,_,X,X,X,X,X,X,_,_,_,_,
+    _,_,_,_,X,_,_,_,_,_,_,X,X,_,_,
+    _,_,_,_,X,_,_,_,_,_,_,_,_,X,X,
+    _,_,_,_,_,X,_,_,_,_,_,_,_,_,X,
+    X,X,X,X,X,X,_,_,_,_,_,_,X,X,X,
+    X,_,_,_,_,_,_,_,_,_,X,X,_,_,_,
+    X,_,_,_,_,_,_,_,X,X,_,_,_,_,_,
+    X,_,_,_,_,_,_,_,_,_,X,X,_,_,_,
+    X,_,_,_,_,_,_,_,_,_,_,_,X,X,X,
+    _,X,_,_,_,_,_,_,_,_,_,_,_,_,X,
+    _,X,_,_,_,_,_,_,_,X,_,_,_,X,_,
+    _,_,X,_,_,_,X,X,X,_,X,_,X,_,_,
+    _,_,_,X,X,X,_,_,_,_,_,X,_,_,_,
+    _,_,_,_,_,_,_,_,_,_,_,_,_,_,_   
+};
+
+int asteroid_sprite_3[ASTEROID_HEIGHT * ASTEROID_WIDTH] = {
+    _,_,_,_,_,X,_,_,_,_,X,_,_,_,_,
+    _,_,_,_,X,_,X,_,_,X,_,X,_,_,_,
+    _,_,_,X,_,_,_,X,X,_,_,_,X,_,_,
+    _,_,X,_,_,_,_,_,_,_,_,_,_,X,_,
+    _,X,_,_,_,_,_,_,_,_,_,_,_,_,X,
+    X,_,_,_,_,_,_,_,_,_,_,_,_,X,_,
+    X,_,_,_,_,_,_,_,_,_,_,_,_,X,_,
+    X,_,_,_,_,_,_,_,_,_,_,_,X,_,_,
+    X,_,_,_,_,_,_,_,_,_,_,_,_,X,_,
+    X,_,_,_,_,_,_,_,_,_,_,_,_,_,X,
+    X,_,_,_,_,_,_,_,_,_,_,_,_,X,_,
+    _,X,_,_,_,_,_,_,_,_,_,_,X,_,_,
+    _,_,X,_,_,_,_,_,_,_,_,X,_,_,_,
+    _,_,_,X,_,_,_,_,_,_,X,_,_,_,_,
+    _,_,_,_,X,X,X,X,X,X,_,_,_,_,_
+
+};
+
+int asteroid_sprite_4[ASTEROID_HEIGHT * ASTEROID_WIDTH] = {
+    _,_,X,_,_,_,_,_,_,_,_,X,_,_,_,
+    _,X,_,X,X,_,_,_,_,X,X,_,X,_,_,
+    X,_,_,_,_,X,_,X,X,_,_,_,_,X,_,
+    _,X,_,_,_,_,X,_,_,_,_,_,_,_,X,
+    _,X,_,_,_,_,_,_,_,_,_,_,_,X,_,
+    _,_,X,_,_,_,_,_,_,_,_,_,X,_,_,
+    _,_,X,_,_,_,_,_,_,_,_,X,_,_,_,
+    _,X,_,_,_,_,_,_,_,_,_,_,X,_,_,
+    _,X,_,_,_,_,_,_,_,_,_,_,X,_,_,
+    X,_,_,_,_,_,_,_,_,_,_,_,_,X,_,
+    _,X,_,_,_,_,_,_,_,_,_,_,_,X,_,
+    _,_,X,_,_,_,_,_,_,_,_,_,_,_,X,
+    _,_,_,X,_,X,_,_,_,_,_,_,_,X,_,
+    _,_,_,_,X,_,X,X,X,_,_,_,X,_,_,
+    _,_,_,_,_,_,_,_,_,X,X,X,_,_,_
+
+};
+
+int spaceship_earth1[EARTH_WIDTH *EARTH_HEIGHT] = {
+     _,_,S,S,S,S,S,S,_,_,
+     _,S,I,I,I,I,I,I,S,_,
+     S,I,I,I,I,I,I,I,I,S,
+     S,I,I,I,I,I,I,I,I,S,
+     S,I,I,I,I,I,I,I,I,S,
+     S,I,I,I,I,I,I,I,I,S,
+     S,I,I,I,I,I,I,I,I,S,
+     S,I,I,I,I,I,I,I,I,S,
+     S,I,I,I,I,I,I,I,S,_,
+     _,S,S,S,S,S,S,S,_,_
+};
+
+
+int black_earth[EARTH_WIDTH *EARTH_HEIGHT] = {
+    _,_,_,_,_,_,_,_,_,_,
+    _,_,_,_,_,_,_,_,_,_,
+    _,_,_,_,_,_,_,_,_,_,
+    _,_,_,_,_,_,_,_,_,_,
+    _,_,_,_,_,_,_,_,_,_,
+    _,_,_,_,_,_,_,_,_,_,
+    _,_,_,_,_,_,_,_,_,_,
+    _,_,_,_,_,_,_,_,_,_,
+    _,_,_,_,_,_,_,_,_,_,
+    _,_,_,_,_,_,_,_,_,_
+};
+
+int black_asteriod[ASTEROID_HEIGHT * ASTEROID_WIDTH] = {
+    _,_,_,_,_,_,_,_,_,_,_,_,_,_,_,
+    _,_,_,_,_,_,_,_,_,_,_,_,_,_,_,
+    _,_,_,_,_,_,_,_,_,_,_,_,_,_,_,
+    _,_,_,_,_,_,_,_,_,_,_,_,_,_,_,
+    _,_,_,_,_,_,_,_,_,_,_,_,_,_,_,
+    _,_,_,_,_,_,_,_,_,_,_,_,_,_,_,
+    _,_,_,_,_,_,_,_,_,_,_,_,_,_,_,
+    _,_,_,_,_,_,_,_,_,_,_,_,_,_,_,
+    _,_,_,_,_,_,_,_,_,_,_,_,_,_,_,
+    _,_,_,_,_,_,_,_,_,_,_,_,_,_,_,
+    _,_,_,_,_,_,_,_,_,_,_,_,_,_,_,
+    _,_,_,_,_,_,_,_,_,_,_,_,_,_,_,
+    _,_,_,_,_,_,_,_,_,_,_,_,_,_,_,
+    _,_,_,_,_,_,_,_,_,_,_,_,_,_,_,
+    _,_,_,_,_,_,_,_,_,_,_,_,_,_,_
+};
+    
+#endif
\ No newline at end of file