=UPDATE v1.5= My first game- rolly the dot's adventure!

Btw im making a new post bc i cant edit the old one idk why.

UPDATE v1.5

Added settings, sound, and 2P is in beta.

I will be updating this a lot, so you will probably want to check often for updates.


// cm:esp8266:nibble
// cm:esp8266:nibble
/*=====================================/
//Rolly's adventure v1.5 by 8-bit_noob//
////////////////////////////////////////
menu: 0: In menu
1: Pressed
2: 1P mode
3: 2P mode
4: How 2 play 
5: settings
tones: 155: more bad
220: bad
523: good
587: more good
*/
#include <Arduino.h>
#include <CircuitOS.h>
#include <Nibble.h>

//vars
int setting;
bool sound;
bool guide;
int guidepage;
int menu;
int btnPressed;
int btnPressed2;
int EX;
int EY;
int X;
int Y;
int X2;
int Y2;
int CX;
int CY;
int UX;
int UY;
int Points;
int Points2;
int Speed;
int Selected;
int lives;
int lives2;
int money;
int money2;
bool uexists;

Display* display;
Sprite* sprite;

void initvars(){
  btnPressed = 0;
  btnPressed2 = 0;
  UX = mathRandomInt(10, 120);
  UY = 10;
  CX = mathRandomInt(10, 120);
  CY = 10;
  EX = mathRandomInt(10, 120);
  EY = 10;
  X = 64;
  Y = 110;
  X2 = 20;
  Y2 = 110;
  Points = 0;
  Points2 = 0;
  Speed = 1;
  lives = 3;
  lives2 = 3;
  money = 0;
  money2 = 0;
  guide = false;
  guidepage = 0;
  if(mathRandomInt(1, 3) == 1){
    uexists = true;
  }else{
    uexists = false;
  }
}

//button presses and releases
void BTN_UP_press(){
  if(Selected > 0){
      Selected--;
      if(sound) Piezo.tone(220,500);
  }
  if(setting > 0){
      setting--;
  }
}

void BTN_DOWN_press(){
  if(Selected < 3){
      Selected++;
      if(sound) Piezo.tone(220,500);
  }
  if(setting < 0){
      setting++;
  }
}

void BTN_A_press(){
  if(menu == 0){
      menu = Selected + 2;
      if(sound) Piezo.tone(532,500);
  }else if(menu == 5){
    if(setting == 0){
      if(sound){
          sound = false;
      }else{
          sound = true;
      }
    }
  }else{
      btnPressed2 = -(ceil((Speed / 20)) + 1);
  }
}

void BTN_B_press(){
  if(guide && guidepage < 1){
      guidepage++;
      if(sound) Piezo.tone(220,500);
  }else{
      btnPressed2 = (ceil((Speed / 20)) + 1);
  }
}

void BTN_LEFT_press(){
  btnPressed = -(ceil((Speed / 20)) + 1);
}

void BTN_RIGHT_press(){
  btnPressed = (ceil((Speed / 20)) + 1);
}

void BTN_LEFT_release(){
  btnPressed = 0;

}

void BTN_A_release(){
  btnPressed2 = 0;

}

void BTN_B_release(){
  btnPressed2 = 0;

}

void BTN_C_press(){
  menu = 1;
  if(sound) Piezo.tone(587,500);
}

int mathRandomInt(int min, int max) {
  if (min > max) {
    // Swap min and max to ensure min is smaller.
    int temp = min;
    min = max;
    max = temp;
  }
  return min + (rand() % (max - min + 1));
}

void BTN_RIGHT_release(){
  btnPressed = 0;

}


void setup() {
  Nibble.begin();
  display = Nibble.getDisplay();
  sprite = display->getBaseSprite();
  Input::getInstance()->setBtnPressCallback(BTN_LEFT, BTN_LEFT_press);
  Input::getInstance()->setBtnPressCallback(BTN_RIGHT, BTN_RIGHT_press);
  Input::getInstance()->setBtnReleaseCallback(BTN_LEFT, BTN_LEFT_release);
  Input::getInstance()->setBtnReleaseCallback(BTN_RIGHT, BTN_RIGHT_release);
  Input::getInstance()->setBtnPressCallback(BTN_C, BTN_C_press);
  Input::getInstance()->setBtnPressCallback(BTN_UP, BTN_UP_press);
  Input::getInstance()->setBtnPressCallback(BTN_DOWN, BTN_DOWN_press);
  Input::getInstance()->setBtnPressCallback(BTN_A, BTN_A_press);
  Input::getInstance()->setBtnPressCallback(BTN_B, BTN_B_press);
  Input::getInstance()->setBtnReleaseCallback(BTN_A, BTN_A_release);
  Input::getInstance()->setBtnReleaseCallback(BTN_B, BTN_B_release);

  initvars();
  menu = 0;
  Selected = 0;
  setting = 0;
  sound = true;

  sprite->setTextSize(1);
  sprite->setTextFont(1);
  sprite->setTextColor(TFT_BLACK);


}


void loop() {
  Input::getInstance()->loop(0);
  if(menu==2){
    if(lives<1){
      menu = 0;
      if(sound) Piezo.tone(155,200);
    }
    if(money > 19){
        money = 0;
        lives++;
        if(sound) Piezo.tone(523,200);
    }
    //this is the 1P mode
    sprite->setTextColor(TFT_BLACK);
    //wraparound
    if(X<5){
        X=120;
    }else if(X>125){
        X=10;
    }
    //move
    X += btnPressed;
    
    //drawing
    sprite->clear(TFT_CYAN);
    sprite->drawString("v1.5", 100, 110);
    sprite->drawString((String("Points: ") + String(Points)), 5, 5);
    sprite->drawString((String("$") + String(money)), 94, 5);
    sprite->drawString((String("Lives:") + String(lives)), 5, 17);
    sprite->fillRect(0, 120, 128, 8, TFT_GREEN);
    //rolly!
    sprite->fillCircle(X, 110, 10, TFT_YELLOW);
    sprite->fillCircle((X - 3), 105, 2, TFT_BLACK);
    sprite->fillCircle((X + 3), 105, 2, TFT_BLACK);
    //evil dude
    sprite->fillCircle(EX, EY, 10, TFT_RED);
    sprite->fillCircle((EX - 3), (EY - 5), 2, TFT_BLACK);
    sprite->fillCircle((EX + 3), (EY - 5), 2, TFT_BLACK);
    //coin
    sprite->fillCircle(CX, CY, 10, TFT_DARKCYAN);
    sprite->fillCircle(CX, CY, 5, TFT_DARKGREEN);
    
    //evil dude coll
    //rolly hit evil dude?
    if ((X-EX)*(X-EX)+(Y-EY)*(Y-EY)<400) {
        EX = mathRandomInt(10, 120);
        EY = 10;
        Points -= ceil((Speed / 7)) + 1;
        lives--;
        if(sound) Piezo.tone(220,200);
    }else if (EY < 120) {  //enemy still allowed to move?
        EY += (ceil((Speed / 15)) + 1);
    } else {  //enemy hit bottom.
        Speed += 1;
        EX = mathRandomInt(10, 120);
        EY = 10;
        Points += ceil((Speed / 7)) + 1;
        if(sound) Piezo.tone(523,200);
    }

    //coin coll
    //rolly hit coin?
    if ((X-CX)*(X-CX)+(Y-CY)*(Y-CY)<400) {
        CX = mathRandomInt(10, 120);
        CY = 10;
        Points += ceil((Speed / 4)) + 2;
        money++;
        if(sound) Piezo.tone(523,200);
    }else if (CY < 120) {  //coin still allowed to move?
        CY += (ceil((Speed / 20)) + 1);
    } else {  //coin hit bottom.
        CX = mathRandomInt(10, 120);
        CY = 10;
        Points -= ceil((Speed / 9)) + 1;
        if(sound) Piezo.tone(220,200);
    }
  }else if(menu == 3){
    if(lives<1 || lives2<1){
      menu = 0;
      if(sound) Piezo.tone(155,200);
    }
    if(money > 19){
        money = 0;
        lives++;
        if(sound) Piezo.tone(523,200);
    }
    if(money2 > 19){
        money2 = 0;
        lives2++;
        if(sound) Piezo.tone(523,200);
    }
    //this is the 2P mode
    sprite->setTextColor(TFT_BLACK);
    //wraparound
    if(X<5){
        X=120;
    }else if(X>125){
        X=10;
    }
    if(X2<5){
        X2=120;
    }else if(X2>125){
        X2=10;
    }
    //move
    X += btnPressed;
    X2 += btnPressed2;
    //drawing
    sprite->clear(TFT_CYAN);
    sprite->drawString("v1.5", 100, 110);
    sprite->drawString((String("1Pts:") + String(Points)), 5, 5);
    sprite->drawString((String("1$") + String(money)), 5, 15);
    sprite->drawString((String("1Life:") + String(lives)), 5, 25);
    sprite->drawString((String("2Pts:") + String(Points2)), 65, 5);
    sprite->drawString((String("2$") + String(money2)), 65, 15);
    sprite->drawString((String("2Life:") + String(lives2)), 65, 25);
    sprite->fillRect(0, 120, 128, 8, TFT_GREEN);
    //rolly!
    sprite->fillCircle(X, 110, 10, TFT_YELLOW);
    sprite->fillCircle((X - 3), 105, 2, TFT_BLACK);
    sprite->fillCircle((X + 3), 105, 2, TFT_BLACK);
    //rolly2!
    sprite->fillCircle(X2, 110, 10, TFT_ORANGE);
    sprite->fillCircle((X2 - 3), 105, 2, TFT_BLACK);
    sprite->fillCircle((X2 + 3), 105, 2, TFT_BLACK);
    //evil dude
    sprite->fillCircle(EX, EY, 10, TFT_RED);
    sprite->fillCircle((EX - 3), (EY - 5), 2, TFT_BLACK);
    sprite->fillCircle((EX + 3), (EY - 5), 2, TFT_BLACK);
    //coin
    sprite->fillCircle(CX, CY, 10, TFT_DARKCYAN);
    sprite->fillCircle(CX, CY, 5, TFT_DARKGREEN);
    //ultra-coin
    if(uexists){
      sprite->fillCircle(UX, UY, 10, TFT_PINK);
      sprite->fillCircle(UX, UY, 5, TFT_PURPLE);
    }
    
    //evil dude coll
    //rolly hit evil dude?
    if ((X-EX)*(X-EX)+(Y-EY)*(Y-EY)<400) {
        EX = mathRandomInt(10, 120);
        EY = 10;
        Points -= ceil((Speed / 7)) + 1;
        lives--;
        if(sound) Piezo.tone(220,200);
    }else if((X2-EX)*(X2-EX)+(Y2-EY)*(Y2-EY)<400){ //rolly2 hit evil dude?
        EX = mathRandomInt(10, 120);
        EY = 10;
        Points2 -= ceil((Speed / 7)) + 1;
        lives2--;
        if(sound) Piezo.tone(220,200);
    }else if (EY < 120) {  //enemy still allowed to move?
        EY += (ceil((Speed / 15)) + 1);
    } else {  //enemy hit bottom.
        Speed += 1;
        EX = mathRandomInt(10, 120);
        EY = 10;
        Points += ceil((Speed / 7)) + 1;
        if(mathRandomInt(1, 4) == 1){
          uexists = true;
        }else{
          uexists = false;
        }
        if(sound) Piezo.tone(523,200);
    }

    //coin coll
    //rolly hit coin?
    if ((X-CX)*(X-CX)+(Y-CY)*(Y-CY)<400) {
        CX = mathRandomInt(10, 120);
        CY = 10;
        Points += ceil((Speed / 4)) + 2;
        money++;
        if(sound) Piezo.tone(523,200);
    }else if((X2-CX)*(X2-CX)+(Y2-CY)*(Y2-CY)<400){ //rolly2 hit coin?
        CX = mathRandomInt(10, 120);
        CY = 10;
        Points2 += ceil((Speed / 4)) + 2;
        money2++;
        if(sound) Piezo.tone(523,200);
    }else if (CY < 120) {  //coin still allowed to move?
        CY += (ceil((Speed / 20)) + 1);
    } else {  //coin hit bottom.
        CX = mathRandomInt(10, 120);
        CY = 10;
    }

    //coin coll
    //rolly hit ULTRAcoin?
    if ((X-UX)*(X-UX)+(Y-UY)*(Y-UY)<400 && uexists) {
        UX = mathRandomInt(10, 120);
        UY = 10;
        Points += ceil(Speed) + 2;
        money += 8;
        if(sound) Piezo.tone(587,200);
    }else if((X2-UX)*(X2-UX)+(Y2-UY)*(Y2-UY)<400 && uexists){ //rolly2 hit ULTRAcoin?
        UX = mathRandomInt(10, 120);
        UY = 10;
        Points2 += ceil(Speed) + 2;
        money2 += 8;
        if(sound) Piezo.tone(587,200);
    }else if (UY < 120 && uexists) {  //ULTRAcoin still allowed to move?
        UY += (ceil((Speed / 20)) + 1);
    }else if (uexists){  //ULTRAcoin hit bottom.
        UX = mathRandomInt(10, 120);
        UY = 10;
        uexists = false;
    }

  }else if(menu == 4){
    //this is controls
    guide = true;
    sprite->clear(TFT_BLACK);
    sprite->drawString("<- MENU        B ->", 5, 110);
    if(guidepage == 0){
        sprite->drawString("In 1P mode, you are", 0, 5);
        sprite->drawString("the yellow circle and", 0, 15);
        sprite->drawString("want to get the dark", 0, 25);
        sprite->drawString("blue coins and avoid", 0, 35);
        sprite->drawString("the red circles! Use", 0, 45);
        sprite->drawString("left and right buttons", 0, 55);
        sprite->drawString("to move. If you get", 0, 65);
        sprite->drawString("hit by the red circle", 0, 75);
        sprite->drawString("you lose a life. Lose", 0, 85);
        sprite->drawString("all and game over.", 0, 95);
    }else if(guidepage == 1){
        sprite->drawString("Gain $1 by getting a", 0, 5);
        sprite->drawString("coin. Get $20 for an", 0, 15);
        sprite->drawString("extra life. Press", 0, 25);
        sprite->drawString("MENU to exit. 2P mode", 0, 35);
        sprite->drawString("is just 1P mode with", 0, 45);
        sprite->drawString("the player 2 as an", 0, 55);
        sprite->drawString("orange circle and move", 0, 65);
        sprite->drawString("with A and B. There is", 0, 75);
        sprite->drawString("also a pink coin that", 0, 85);
        sprite->drawString("is worth $8.", 0, 95);
    }
  }else if(menu == 5){
    //settings
    initvars();
    sprite->setTextColor(TFT_WHITE);
    sprite->clear(TFT_BLACK);
    sprite->drawString("Settings", 0, 5);
    //draw arrows
    if(setting > 0){
      sprite->fillTriangle(50, 50, 60, 40, 70, 50, TFT_GREEN);
    }
    if(setting < 0){
      sprite->fillTriangle(50, 70, 60, 80, 70, 70, TFT_GREEN);
    }
    //modes
    if(setting == 0){
      sprite->drawString("Sound:", 5, 54);
      if(sound){
          sprite->drawString("On", 0, 100);
      }else{
          sprite->drawString("Off", 0, 100);
      }
    }
  }else{
    //this is the menu
    initvars();
    menu = 0;
    sprite->setTextColor(TFT_WHITE);
    sprite->clear(TFT_BLACK);
    sprite->drawString("Rolly adventure 1", 0, 5);
    sprite->drawString("By 8-bit_noob", 0, 100);
    //draw arrows
    if(Selected > 0){
      sprite->fillTriangle(50, 50, 60, 40, 70, 50, TFT_GREEN);
    }
    if(Selected < 3){
      sprite->fillTriangle(50, 70, 60, 80, 70, 70, TFT_GREEN);
    }
    //modes
    if(Selected == 0){
      sprite->drawString("A to play 1P", 5, 54);
    }else if(Selected == 1){
      sprite->drawString("2P (beta)", 5, 54);
    }else if(Selected == 2){
      sprite->drawString("How to play?", 5, 54);
    }else{
      sprite->drawString("Settings", 5, 54);
    }
  }
  display->commit();

}
//you have reached the end!

Copy-paste into circuitblocks and compile.
It might be bad though :woozy_face:

2 Likes
3 Likes

I want to give you the info, that you forgot to change the version number.
Also your game it’s fun, keep up the good work. :+1:

1 Like

Yes I forgot to change the version # but I have the updated one in arduino

1 Like

The game looks fun, well done! :slight_smile: