University project - accelerometer controlled Arkanoid

Dependencies:   KS0108 MMA8451Q mbed

Files at this revision

API Documentation at this revision

Comitter:
JSindelar
Date:
Sun Jan 18 19:28:22 2015 +0000
Parent:
0:9515d58c3408
Commit message:
University project - accelerometer controlled Arkanoid

Changed in this revision

backup.cpp Show diff for this revision Revisions of this file
backup2.cpp Show diff for this revision Revisions of this file
backup3_non_functional_ptrs2struct_2Darray.cpp Show diff for this revision Revisions of this file
diff -r 9515d58c3408 -r d08d63a7c50d backup.cpp
--- a/backup.cpp	Sun Jan 18 19:27:16 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,22 +0,0 @@
-/*
-unsigned char MovePad(void){
-    static unsigned char PaddlePos = (unsigned char)(0.5*(minX+maxX));
-    unsigned char PaddleDif;
-    //static unsigned int PaddlePos = 82;
-    if ((abs(acc.getAccY()))>AccTres1){
-        display.FullRectangle(PaddlePos, PadY, PaddlePos+PadLength ,PadY+2,WHITE);
-        if ((abs(acc.getAccY()))>AccTres2){
-            PaddleDif = 6;
-        }else{
-            PaddleDif = 2;
-        }
-        if ((acc.getAccY() > 0)&&((PaddlePos+PadLength) < (minX - 3))){
-            PaddlePos += PaddleDif;   
-        }
-        if ((acc.getAccY() < 0)&&(PaddlePos > (maxX + 1))){
-            PaddlePos -= PaddleDif;   
-        }
-    }
-    display.FullRectangle(PaddlePos, PadY, PaddlePos+PadLength ,PadY+2,BLACK);
-    return PaddlePos;
-}*/
\ No newline at end of file
diff -r 9515d58c3408 -r d08d63a7c50d backup2.cpp
--- a/backup2.cpp	Sun Jan 18 19:27:16 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,195 +0,0 @@
-/*
-#include    "mbed.h"
-#include    "KS0108.h"
-#include    "Arial12.h"
-#include    "SystemFont5x7.h"
-#include    "stdbool.h"
-#include    "MMA8451Q.h"
- 
-#define step        (4)
-#define minX        (125)
-#define maxX        (39)
-#define minY        (2)
-#define maxY        (62)
-#define PadLength   (10)
-#define PadY        (59)
-#define LowSpeed    (2)
-#define HighSpeed   (4)
-#define XPadInit    ((unsigned char)(0.5*(minX+maxX-PadLength)))
-#define XBallInit   ((unsigned char)(XPadInit+0.5*PadLength))
-#define BallD       (1)
-#define YBallInit   ((unsigned char)(PadY-BallD))
-
-#define BrickH      (4)
-#define BrickW      (20)
-
-#define AccTres1    (0.12)
-#define AccTres2    (0.25)
-
-#define MMA8451_I2C_ADDRESS (0x1d<<1)
- 
-KS0108 display (PTE22,PTE23, PTE29, PTE30, PTE20, PTE21, PTC7, PTC0, PTC3, PTC4, PTC5, PTC6, PTC10, PTC11);
-
-void DrawBorder();
-void DrawBall(unsigned char* X, unsigned char* Y, char* dx, char* dy, unsigned char D, unsigned char PaddlePos, bool* Start, unsigned char* lives);
-//unsigned char MovePad(void);
-void MovePad(unsigned char* Pad_ptr, bool Start);
-void DrawLogo(void);
-void DrawTable(char sc, char liv);
-void reset(unsigned char* XBall, unsigned char* YBall, char* dxBall, char* dyBall, unsigned char* XPaddle, bool* Start, unsigned char score, unsigned char lives);
-void DrawBricks(void);
-
-MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS);
-
-int main() {
-                                
-    display.ClearScreen();  
-
-    unsigned char score = 0;
-    unsigned char lives = 3;
-    DrawLogo();
-    DrawTable(score,lives);
-    DrawBorder();
-    DrawBricks();
-    
-    unsigned char XBall = XBallInit;
-    unsigned char YBall = YBallInit;
-    char Balldx = 2;
-    char Balldy = -2;
-  
-    unsigned char PadPos = XPadInit;
-    bool StartFlag = true;  
-
-       
-    while(1) { 
-        display.TurnOn();
-        if (StartFlag){
-            reset(&XBall, &YBall, &Balldx, &Balldy, &PadPos, &StartFlag, score, lives);
-        }else{
-            display.FullCircle(2,2,2,WHITE);
-        }  
-        DrawBall(&XBall, &YBall, &Balldx, &Balldy, BallD, PadPos, &StartFlag, &lives);
-        MovePad(&PadPos, StartFlag); 
-        wait(0.05);       
-    }
- 
-}
-
-void DrawLogo(void){
-    display.SelectFont(Arial12,BLACK,ReadData);   
-    display.GotoXY(8,8);
-    display.PrintString("ARM"); 
-    display.GotoXY(4,24);
-    display.PrintString("kanoid"); 
-}
-
-void DrawTable(char sc, char liv){
-    static char score[5];
-    static char lives[5];
-    display.EmptyRectangle(4,38, (maxX-6),56, BLACK);
-    display.FullRectangle(20,39,(maxX-7), 55, WHITE);
-    display.SelectFont(System5x7,BLACK,ReadData);  
-    sprintf(score,"S:%2d",sc);
-    sprintf(lives,"L:%2d",liv);
-    display.GotoXY(8,40);
-    display.PrintString(score);
-    display.GotoXY(8,48);
-    display.PrintString(lives);
-}
-    
-void DrawBorder(void){
-    display.HLine(maxX-2, 127,0,BLACK);
-    display.VLine(maxX-2, 0,63,BLACK);
-    display.VLine(minX+2, 0,63,BLACK);
-}
-
-void DrawBall(unsigned char* X, unsigned char* Y, char* dx, char* dy, unsigned char D, unsigned char PaddlePos, bool* Start, unsigned char* lives){
-    
-    display.FullCircle(*X, *Y, D, WHITE);
-    
-    (*X) += (*dx);
-    (*Y) += (*dy);
-    display.FullCircle(*X, *Y, D, BLACK);
-    //if (!(*Start)){
-        if ((((unsigned char)(*X+D)) >= minX)||(((char)(*X-D)) <= maxX)){
-            *dx = -(*dx);
-        }
-    
-        if (((unsigned char)(*Y-D)) <= minY){
-            *dy = -(*dy);
-        }
-        if (((char)(*Y+D)) >= PadY){
-            if ((((unsigned char)(*X+D)) <= (PaddlePos+PadLength+2))&&(((unsigned char)(*X-D)) >= (PaddlePos-2))){
-                *dy = -(*dy);
-            }else{
-                if (*lives > 1){
-                    (*lives)--;
-                    *Start = true;
-                }else{
-                //doplnit kod na game over
-                }    
-            }
-        }
-    /*}else{
-        display.FullCircle(*X, *Y, D, WHITE);  
-    }
-}
-
-void MovePad(unsigned char* Pad_ptr, bool Start){
-    unsigned char PaddleDif;
-    if ((abs(acc.getAccY()))>AccTres1){
-    display.FullRectangle(*Pad_ptr, PadY, *Pad_ptr+PadLength ,PadY+2,WHITE);
-    if(Start){
-        *Pad_ptr = XPadInit;
-    }else{
-        if ((abs(acc.getAccY()))>AccTres2){
-            PaddleDif = HighSpeed;
-            }else{
-                PaddleDif = LowSpeed;
-            }
-            if ((acc.getAccY() > 0)&&((*Pad_ptr+PadLength) < (minX - 3))){
-                *Pad_ptr += PaddleDif;   
-            }
-            if ((acc.getAccY() < 0)&&(*Pad_ptr > (maxX + 1))){
-            *Pad_ptr -= PaddleDif;   
-            }
-        }
-    }
-    display.FullRectangle(*Pad_ptr, PadY, *Pad_ptr+PadLength ,PadY+2,BLACK);
-}
-
-void reset(unsigned char* XBall, unsigned char* YBall, char* dxBall, char* dyBall, unsigned char* XPaddle, bool* Start, unsigned char score, unsigned char lives){
-    display.FullCircle(*XBall, *YBall, BallD, WHITE);
-    *XBall = XBallInit;
-    *YBall = YBallInit;
-    display.FullRectangle(*XPaddle, PadY, *XPaddle+PadLength ,PadY+2,WHITE);
-    *XPaddle = XPadInit;
-    wait(1);
-    display.FullCircle(*XBall, *YBall, BallD, BLACK);
-    display.FullRectangle(*XPaddle, PadY, *XPaddle+PadLength ,PadY+2,BLACK);
-    DrawTable(score, lives);
-    *dxBall = 2;
-    *dyBall = -2;
-    *Start = false;
-    wait(1);
-}
-
-void DrawBricks(void){
-    struct brick {
-        unsigned char Xbrick;
-        unsigned char Ybrick;
-        bool exists;
-    }BrickArray[4][3], cihla;
-    
-    char i;
-    char j;
-    for (j = 0; j < 3; j++){
-        for (i = 0; i < 4; i++){
-            cihla.Xbrick = maxX + i*(BrickW + 2);
-            cihla.Ybrick = minY + j*(BrickH + 2);
-            cihla.exists = true;
-            BrickArray[i][j] = cihla;
-            display.EmptyRectangle(cihla.Xbrick,cihla.Ybrick, (cihla.Xbrick + BrickW), (cihla.Ybrick + BrickH) ,((cihla.exists)? BLACK:WHITE));
-        }
-    }
-}*/
\ No newline at end of file
diff -r 9515d58c3408 -r d08d63a7c50d backup3_non_functional_ptrs2struct_2Darray.cpp
--- a/backup3_non_functional_ptrs2struct_2Darray.cpp	Sun Jan 18 19:27:16 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,242 +0,0 @@
-/*
-#include    "mbed.h"
-#include    "KS0108.h"
-#include    "Arial12.h"
-#include    "SystemFont5x7.h"
-#include    "stdbool.h"
-#include    "MMA8451Q.h"
- 
-#define step        (4)
-#define minX        (125)
-#define maxX        (39)
-#define minY        (2)
-#define maxY        (62)
-#define PadLength   (10)
-#define PadY        (59)
-#define LowSpeed    (2)
-#define HighSpeed   (4)
-#define XPadInit    ((unsigned char)(0.5*(minX+maxX-PadLength)))
-#define XBallInit   ((unsigned char)(XPadInit+0.5*PadLength))
-#define BallD       (1)
-#define YBallInit   ((unsigned char)(PadY-BallD))
-
-#define BrickH      (4)
-#define BrickW      (20)
-#define columns     (4)
-#define rows        (3)
-
-#define AccTres1    (0.12)
-#define AccTres2    (0.25)
-
-#define MMA8451_I2C_ADDRESS (0x1d<<1)
- 
-KS0108 display (PTE22,PTE23, PTE29, PTE30, PTE20, PTE21, PTC7, PTC0, PTC3, PTC4, PTC5, PTC6, PTC10, PTC11);
-
-//prototypes of functions
-void DrawBorder();
-void DrawBall(unsigned char* X, unsigned char* Y, char* dx, char* dy, unsigned char D, unsigned char PaddlePos, bool* Start, unsigned char* lifes);
-void MovePad(unsigned char* Pad_ptr, bool Start);
-void DrawLogo(void);
-void DrawTable(char sc, char liv);
-void reset(unsigned char* XBall, unsigned char* YBall, char* dxBall, char* dyBall, unsigned char* XPaddle, bool* Start, unsigned char score, unsigned char lifes);
-void CreateGrid(unsigned char* col, unsigned char* ro);
-void DrawBricks(unsigned char col[columns], unsigned char ro[rows]);
-
-MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS);
-
-//main program
-int main() {
-                                
-    display.ClearScreen();  
-
-    unsigned char score = 0;                //initial score and number of lifes
-    unsigned char lifes = 3;
-    DrawLogo();                             //drawing ARM-kanoid title
-    DrawTable(score,lifes);                 //drawing table with score and number of lifes
-    DrawBorder();                           //drawing border of the playing area
-    
-    unsigned char XBall = XBallInit;
-    unsigned char YBall = YBallInit;
-    char Balldx = 2;
-    char Balldy = -2;
-  
-    unsigned char PadPos = XPadInit;        //initializing position of the paddle
-    bool StartFlag = true;  
-
-    unsigned char column[columns];
-    unsigned char row[rows];
-    
-    struct brick {                          //structure for arkanoid bricks description (along with constants brickH and brickW)
-        unsigned char Xbrick;
-        unsigned char Ybrick;
-        bool exists;
-    }BrickArray[rows][columns], cihla;      //array of bricks, single brick
-    
-    //struct brick (*BrickArr_ptr)[rows][columns] = &BrickArray;      //pointer to array of bricks
-    
-    struct brick (*BrickArr_ptr)[rows][columns];
-    BrickArr_ptr = BrickArray;
-    CreateGrid(&(column[0]),  &(row[0]));                           //creating grid for bricks
-    DrawBricks(column, row);                                        //drawing bricks
-    
-    while(1) { 
-        display.TurnOn();
-        if (StartFlag){
-            reset(&XBall, &YBall, &Balldx, &Balldy, &PadPos, &StartFlag, score, lifes);
-        }
-        DrawBall(&XBall, &YBall, &Balldx, &Balldy, BallD, PadPos, &StartFlag, &lifes);      //function for drawing the ball, computing its movement, bounces etc.
-        MovePad(&PadPos, StartFlag);                //function for paddle drawing and its control by accelerometer
-        wait(0.05);       
-    }
- 
-}
-
-void DrawLogo(void){
-    display.SelectFont(Arial12,BLACK,ReadData);   
-    display.GotoXY(8,8);
-    display.PrintString("ARM"); 
-    display.GotoXY(4,24);
-    display.PrintString("kanoid"); 
-}
-
-void DrawTable(char sc, char liv){
-    static char score[5];
-    static char lifes[5];
-    display.EmptyRectangle(4,38, (maxX-6),56, BLACK);
-    display.FullRectangle(20,39,(maxX-7), 55, WHITE);
-    display.SelectFont(System5x7,BLACK,ReadData);  
-    sprintf(score,"S:%2d",sc);
-    sprintf(lifes,"L:%2d",liv);
-    display.GotoXY(8,40);
-    display.PrintString(score);
-    display.GotoXY(8,48);
-    display.PrintString(lifes);
-}
-    
-void DrawBorder(void){
-    display.HLine(maxX-2, 127,0,BLACK);
-    display.VLine(maxX-2, 0,63,BLACK);
-    display.VLine(minX+2, 0,63,BLACK);
-}
-
-void DrawBall(unsigned char* X, unsigned char* Y, char* dx, char* dy, unsigned char D, unsigned char PaddlePos, bool* Start, unsigned char* lifes){
-    
-    display.FullCircle(*X, *Y, D, WHITE);
-    
-    (*X) += (*dx);
-    (*Y) += (*dy);
-    display.FullCircle(*X, *Y, D, BLACK);
-    //if (!(*Start)){
-        if ((((unsigned char)(*X+D)) >= minX)||(((char)(*X-D)) <= maxX)){
-            *dx = -(*dx);
-        }
-    
-        if (((unsigned char)(*Y-D)) <= minY){
-            *dy = -(*dy);
-        }
-        if (((char)(*Y+D)) >= PadY){
-            if ((((unsigned char)(*X+D)) <= (PaddlePos+PadLength+2))&&(((unsigned char)(*X-D)) >= (PaddlePos-2))){
-                *dy = -(*dy);
-            }else{
-                if (*lifes > 1){
-                    (*lifes)--;
-                    *Start = true;
-                }else{
-                //doplnit kod na game over
-                }    
-            }
-        }
-
-}
-
-void MovePad(unsigned char* Pad_ptr, bool Start){
-    unsigned char PaddleDif;
-    if ((abs(acc.getAccY()))>AccTres1){
-    display.FullRectangle(*Pad_ptr, PadY, *Pad_ptr+PadLength ,PadY+2,WHITE);
-    if(Start){
-        *Pad_ptr = XPadInit;
-    }else{
-        if ((abs(acc.getAccY()))>AccTres2){
-            PaddleDif = HighSpeed;
-            }else{
-                PaddleDif = LowSpeed;
-            }
-            if ((acc.getAccY() > 0)&&((*Pad_ptr+PadLength) < (minX - 3))){
-                *Pad_ptr += PaddleDif;   
-            }
-            if ((acc.getAccY() < 0)&&(*Pad_ptr > (maxX + 1))){
-            *Pad_ptr -= PaddleDif;   
-            }
-        }
-    }
-    display.FullRectangle(*Pad_ptr, PadY, *Pad_ptr+PadLength ,PadY+2,BLACK);
-}
-
-void reset(unsigned char* XBall, unsigned char* YBall, char* dxBall, char* dyBall, unsigned char* XPaddle, bool* Start, unsigned char score, unsigned char lifes){
-    display.FullCircle(*XBall, *YBall, BallD, WHITE);
-    *XBall = XBallInit;
-    *YBall = YBallInit;
-    display.FullRectangle(*XPaddle, PadY, *XPaddle+PadLength ,PadY+2,WHITE);
-    *XPaddle = XPadInit;
-    wait(1);
-    display.FullCircle(*XBall, *YBall, BallD, BLACK);
-    display.FullRectangle(*XPaddle, PadY, *XPaddle+PadLength ,PadY+2,BLACK);
-    DrawTable(score, lifes);
-    *dxBall = 2;
-    *dyBall = -2;
-    *Start = false;
-    wait(1);
-}
-
-void CreateGrid(unsigned char* col, unsigned char* ro){
-    char i;
-    for (i = 0; i < columns; i++){
-        *(col+i) = maxX + i*(BrickW + 2);
-    }
-    for (i = 0; i < columns; i++){
-        *(ro+i) = minY + i*(BrickH + 2);
-        }
-    }
-
-void DrawBricks(unsigned char col[columns], unsigned char ro[rows]){
-    struct brick {
-        unsigned char Xbrick;
-        unsigned char Ybrick;
-        bool exists;
-    }BrickArray[rows][columns], cihla;
-    
-    char i;
-    char j;
-    for (j = 0; j < rows; j++){
-        for (i = 0; i < columns; i++){
-            cihla.Xbrick = col[i];
-            cihla.Ybrick = ro[j];
-            cihla.exists = true;
-            BrickArray[j][i] = cihla;
-            display.FullRectangle(cihla.Xbrick,cihla.Ybrick, (cihla.Xbrick + BrickW), (cihla.Ybrick + BrickH) ,((cihla.exists)? BLACK:WHITE));
-        }
-    }
-}
-
-void BounceBricks(unsigned char* XBall, unsigned char* YBall, char* dxBall, char* dyBall, struct brick* ArrayOfBricks, struct brick* ExBrick, unsigned char ro[rows], unsigned char col[columns], char* dx, char* dy, unsigned char* score){
-    if (*YBall <= ro[rows-1]){
-        char i, j;
-        for (i = columns - 1; i >= 0; i--){
-            if (*XBall >= col[i]){
-                break;
-            }
-        }
-        for (j = rows - 1; j >= 0; j--){
-            if (*YBall >= ro[j]){
-                break;
-            }
-        }
-        
-        if ((*ArrayOfBricks)[i][j].exists){
-            (ArrayOfBricks)[i][j].exists = false;
-            *score++;
-            *dy = -(*dy);
-        }
-    }
-}
-*/
\ No newline at end of file