collab/PineapplePad
git clone https://git.julia.blue/collab/PineapplePad
ca230b6
master
1#include "../inc/game.h" 2#include "../inc/random.h" 3#include "../inc/tm4c123gh6pm.h" 4#include "../inc/ST7735.h" 5#include "../inc/graphics.h" 6#include "../inc/song.h" 7 8#define CUBE_SIZE 20 9#define SPREAD 500 10#define DIST 300 11#define GRACE_PERIOD 500 12 13int vel = 0 ; 14int difficulty = 1 ; 15int speed = 1 ; 16int score = 0 ; 17 18Cube cubes [NUM_CUBES ]; 19 20int bgColor ; 21int cubeColor ; 22int playerColor ; 23bool redraw = false; 24int widthOffset = 0 ; 25int depthOffset = 0 ; 26 27void initField (){ 28for (int i = 0 ;i < NUM_CUBES ;++ i ) { 29cubes [i ]= Cube (Vec3 (Random32 () %SPREAD - SPREAD /2 , 30-50 ,GRACE_PERIOD + (DIST /NUM_CUBES )* i ),CUBE_SIZE ); 31 } 32shuffleColor (Random () %8 ); 33} 34 35void step (){ 36if (redraw ) { 37ST7735_FillRect (0 ,0 ,SCREEN_HEIGHT /2 ,SCREEN_WIDTH ,bgColor ); 38redraw = false; 39 } 40for (int i = 0 ;i < NUM_CUBES ;++ i ) { 41int tempColor = cubes [i ].color ; 42cubes [i ].color = bgColor ; 43cubes [i ].draw (); 44cubes [i ].color = tempColor ; 45cubes [i ].pos .z -= difficulty + speed ; 46cubes [i ].pos .x += vel * (1 + speed /2 + difficulty /2 );// todo: shift and fixed point 47if (cubes [i ].pos .z < -10 ) { 48if (cubes [i ].pos .z < -20 - CUBE_SIZE ) {// moved behind player 49cubes [i ].pos .z = DIST ; 50cubes [i ].pos .x = Random32 () %SPREAD - SPREAD /2 ; 51if ((score + difficulty ) >>9 > score >>9 ) {// next level 52++ speed ; 53shuffleColor (); 54 } 55printScore (score += difficulty ); 56 } 57// collision detection 58else if (cubes [i ].pos .x < 0 && cubes [i ].pos .x + cubes [i ].size > 0 ) { 59cubes [i ].draw (); 60//todo: display endgame graphic 61Song_Play (meme_pitch ,meme_dur ,meme_speed ,sizeof (meme_dur )); 62printScore (score ); 63while (true) ; 64 } 65 } 66cubes [i ].draw (); 67 } 68// widthOffset += vel * (1 + difficulty / 2); 69// depthOffset -= difficulty; 70// drawGround(widthOffset, depthOffset); 71drawPlayer (); 72} 73 74// size being power of 2 allows optimizing mod to bitwise and 75static const int palettes [][2 ]= { 76 {ST7735_BLACK ,1337 }, 77 {ST7735_BLACK ,ST7735_GREEN }, 78 {ST7735_GREEN ,ST7735_BLACK }, 79 {ST7735_WHITE ,ST7735_BLACK }, 80 {ST7735_RED ,ST7735_BLACK }, 81 {ST7735_BLACK ,ST7735_RED }, 82 {ST7735_BLACK ,1337 }, 83 {ST7735_WHITE ,ST7735_BLUE }, 84};// todo: fix backwards colors 85 86void shuffleColor (int x ){ 87static int palette = 0 ; 88palette = x == -1 ? (palette + 1 ) %8 :x ; 89bgColor = palettes [palette ][0 ]; 90cubeColor = palettes [palette ][1 ]; 91for (int i = 0 ;i < NUM_CUBES ;++ i ) { 92if (cubeColor == 1337 ) {// rainbow 93cubes [i ].color = randomColor (); 94 }else { 95cubes [i ].color = cubeColor ; 96 } 97 } 98playerColor = ~bgColor ; 99redraw = true; 100}