Dinosaur_(duck).hex (36.3 KB)
Its a simple game, click a to jump over the cactus’s (stubs i guess…)
/*
Game License: MIT : https://opensource.org/licenses/MIT
characters/sprites, code: copyrighted to Broskibble.
*/
#include <Arduboy2.h>
Arduboy2 arduboy;
int timeScore = 0;
int distance = 0;
int speed = 5;
int gameIndex = 0;
int gameState = 0;
int playerY = 40;
float playerYVEL = 0;
int cactusSpeed = 1;
int projSpeed = 1;
bool ducking = false;
int cactusX[5] = {138,228,318,408,500};
int projX[5] = {138,228,318,408,500};
int projY[5] = {};
const unsigned char PROGMEM player[] = {
16, 16,
0xc0, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xfd, 0xff, 0xff, 0xbf, 0xbf, 0xbf, 0xbf, 0x3f, 0x3e,
0x07, 0x0f, 0x1e, 0xfc, 0xbe, 0x3f, 0x1f, 0x3f, 0xff, 0x84, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00,
};
const unsigned char PROGMEM playerDuck[] = {
16, 16,
0x00, 0x80, 0x80, 0x00, 0x00, 0x80, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x80,
0x07, 0x0e, 0x1c, 0xfc, 0xbe, 0x3f, 0x3f, 0x7e, 0xff, 0xff, 0x5f, 0x5f, 0x5f, 0x5f, 0x1f, 0x1f,
};
void setup() {
arduboy.begin();
arduboy.clear();
arduboy.initRandomSeed();
arduboy.setFrameRate(50);
}
void game() {
gameIndex+=1;
if(gameIndex % 50 == 0) {
timeScore+=1;
}
if(gameIndex % speed == 0) {
distance += 1;
}
if(gameIndex % 750 == 0) {
cactusSpeed+=random(0,2);
speed=speed - random(1,3);
if(speed < 1) {
speed = random(1, 6);
}
}
arduboy.fillScreen(BLACK);
playerYVEL+=0.2;
playerY += playerYVEL;
if(arduboy.pressed(A_BUTTON) && playerY > 30) {
playerYVEL = -3;
ducking = false;
}
if(!arduboy.pressed(A_BUTTON) && playerY > 34){
ducking = arduboy.pressed(B_BUTTON);
}
if(playerY > 36) {
playerY = 36;
playerYVEL = -0.1;
}
arduboy.fillRect(0,52,129,65,WHITE);
//arduboy.drawRect(15,playerY,10,12,WHITE);
if(!ducking){
Sprites::drawOverwrite(15,playerY,player,0);
}else{
Sprites::drawOverwrite(15,playerY,playerDuck,0);
}
for(int i = 0; i < 5; i++) {
cactusX[i]-=1;
projX[i] -= 1;
if(cactusX[i] <= -10) {
cactusX[i] = 138 * random(1,8);
}
if(projX[i] <= -10) {
projX[i] = 20 * random(40,70);
}
arduboy.fillRect(cactusX[i],45,4,7,WHITE);
arduboy.fillRect(projX[i],projY[i],7,4,WHITE);
if(cactusX[i] > 15 && cactusX[i] < 28 && playerY > 30) {
gameState = 2;
arduboy.display();
delay(1000);
arduboy.fillScreen(BLACK);
return;
}
if(projX[i] > 15 && projX[i] < 30 && !ducking) {
if(playerY + 16 < projY[i]) {
}else {
gameState = 2;
arduboy.display();
delay(1000);
arduboy.fillScreen(BLACK);
return;
}
}
// arduboy.fillRect(cactusX[i],46,4,6,WHITE);
}
arduboy.setCursor(2,2);
arduboy.setTextSize(1);
arduboy.print(String(distance));
arduboy.setCursor(2,10);
arduboy.print(String(timeScore));
arduboy.drawRect(0,0,128,64,WHITE);
arduboy.display();
}
void loop() {
if(!arduboy.nextFrame()) {
return;
}
arduboy.pollButtons();
gameLoop();
}
void gameLoop() {
switch (gameState) {
case 0: //Title
drawCenteredString("Dinosaur", 20, 2, WHITE);
drawCenteredString("A To Start!", 45, 1, WHITE);
drawCenteredString("B For Credits", 55, 1, WHITE);
if(arduboy.justPressed(A_BUTTON)) {
playGame();
}
if(arduboy.justPressed(B_BUTTON)) {
arduboy.fillScreen(BLACK);
gameState = 3;
}
break;
case 1: //Game
game();
break;
case 2: //lose
drawCenteredString("You Died", 25, 2, WHITE);
drawCenteredString("Lived For " + String(timeScore) +" Seconds", 5,1,WHITE);
drawCenteredString("You Ran " + String(distance) + " miles", 15, 1, WHITE);
drawCenteredString("A To Restart", 45,1,WHITE);
drawCenteredString("B For Title", 55,1,WHITE);
if(arduboy.justPressed(B_BUTTON)) {
arduboy.fillScreen(BLACK);
gameState = 0;
return;
}
if(arduboy.justPressed(A_BUTTON)) {
playGame();
}
break;
case 3:
drawCenteredString("CREDITS", 5, 2, WHITE);
drawCenteredString("Griffin Brooks", 30, 1, WHITE);
drawCenteredString("Zoe Brooks", 40, 1, WHITE);
if(arduboy.justPressed(B_BUTTON)) {
arduboy.fillScreen(BLACK);
gameState = 0;
}
break;
}
}
void playGame() {
arduboy.initRandomSeed();
cactusX[0] = 138;
cactusX[1] = 228;
cactusX[2] = 318;
cactusX[3] = 408;
cactusX[4] = 500;
for(int i = 0; i < 5; i++) {
projX[i] = random(10,15) * random(30,130);
projY[i] = random(34,38);
}
timeScore = 0;
gameIndex = 0;
distance = 0;
speed = 5;
gameState = 1;
}
void drawString(String text, int x, int y, int size, uint16_t color, uint16_t BackgroundColour) {
arduboy.setCursor(x, y);
arduboy.setTextColor(color);
arduboy.setTextSize(size);
arduboy.setTextWrap(true);
arduboy.println(text);
arduboy.display();
}
void drawCenteredString(String text, int y, int size, uint16_t color) {
int len = (text.length()) * 6 * size;
int left = (128 - len ) / 2;
if (left < 0) {
left = 0;
}
drawString( text, left, y, size, color, BLACK);
}
thats ill the code, i spent about 3 days working on :DD hope you like it! its my first arduboy game.
edit: took like 4 or 5 now…