Forum Dyskusyjne arhn.eu -- Kiedyś mieliśmy tu recki grema™

Pełna wersja: GAMEBUINO kod źródłowy dla zuchwałych
Aktualnie przeglądasz uproszczoną wersję forum. Kliknij tutaj, by zobaczyć wersję z pełnym formatowaniem.
Hej,
Pod wpływem ostatniego stream'a napisałem krótki kod do wyskakujących okienek
Postanowiłem go tutaj udostępnić i prawdę powiedziawszy pogrzebać, może się komuś przyda ale nie zamierzam go bardziej rozwijać, ponieważ mnogość opcji i wymagań dla poszczególnych zastosowań jest zbyt duża dla optymalnego działania.

Cytat://imports the Gamebuino library and the gb object
#include <Gamebuino-Meta.h>
//Define your var for fps counter
unsigned long fps;
unsigned long fpsdec;
bool bfirstCycle = false;
uint32_t startTime;
uint32_t endTime;
// variables for popup windows
byte temp = 0 ;
bool anim = false;
bool animRS = false;
bool goup = true;
byte timer = 0;
//other variables
String Tekst1;
byte score;
byte i;
// the setup routine runs once when Gamebuino starts up
void setup() {
  // initialize the Gamebuino object
  gb.begin();
  //comment out display mode to see if popups still works Winking
  gb.display.init(160, 128, ColorMode::index);
}
//popup function
void drawPopup(bool goback, int textsize, String popUpText, byte radius, byte offset, byte sizer, bool align, int timing) {
// determinate if windows should go down by itself or by pressign button or other bool variable
  if ((goback and (temp >= ((gb.display.height() / sizer) + radius ))) or animRS) {
    timer ++;
    animRS = true;
  }
  gb.display.setColor(GRAY);
  gb.display.fillRoundRect(offset, (gb.display.height() - (gb.display.height() / sizer)) + offset + (((gb.display.height() / sizer) + radius) - temp), gb.display.width() - (2 * offset), (gb.display.height() / sizer) - (2 * offset), radius);
  gb.display.setColor(BEIGE);
  gb.display.fillRoundRect(offset + 2, (gb.display.height() - (gb.display.height() / sizer)) + offset + 2 + (((gb.display.height() / sizer) + radius) - temp), gb.display.width() - (2 * offset + 4), (gb.display.height() / sizer) - (2 * offset + 4), radius);
  gb.display.setFontSize(textsize);
  gb.display.setColor(WHITE);

  if (align) {
    gb.display.setCursor(offset + (6), (gb.display.height() - (gb.display.height() / sizer)) + offset + (((gb.display.height() / sizer) + radius) - temp) + (4));
  }
  else if (!align) {
    gb.display.setCursor(gb.display.width() - (offset + (6)) - (popUpText.length() * 4 * textsize), (gb.display.height() - (gb.display.height() / sizer)) + offset + (((gb.display.height() / sizer) + radius) - temp) + (4));
  }
  if ((((gb.display.height() / sizer) + radius) - temp) <= (gb.display.height() / sizer) - radius - (5 * textsize)) {
    gb.display.print(popUpText);
  }
  gb.display.setFontSize(1);

  if (temp < ((gb.display.height() / sizer) + radius) and goup) {
    temp++ ;
  }
  else if (temp >= ((gb.display.height() / sizer) + radius) and goup) {
    temp = ((gb.display.height() / sizer) + radius);
    goup = false;
  }
  else if (temp <= ((gb.display.height() / sizer) + radius) and (timer > (timing /40)) and !goup) {
    temp -- ;
    if (temp <= 0) {
      anim = false;
      goup = true;
      animRS = false;
      temp = 0;
      timer = 0;
      return;
    }
  }

}
void screenBenchmark() {
  //Screen update benchmark
  if (! bfirstCycle) {
    startTime = millis();
    bfirstCycle = true;
  }
  gb.display.setFontSize(2);
  gb.display.setColor(WHITE);
  endTime = millis();
  fps = (1000 * gb.frameCount) / (endTime - startTime);
  fpsdec = (100000 * gb.frameCount) / (endTime - startTime) - ((1000 * gb.frameCount) / (endTime - startTime) * 100);
  gb.display.setCursor(100, 1);
  gb.display.print(fps);
  gb.display.print(".");
  gb.display.print(fpsdec);
  gb.display.setColor(GREEN);
  gb.display.setFontSize(1);
  gb.display.setCursorY(6);
  gb.display.println(" FPS");
  gb.display.setColor(WHITE);
}

// the loop routine runs over and over again forever
void loop() {
  // wait until the gamebuino is ready to update at stable 25 FPS
  // this also updates sounds, button presses... everything!
  while (!gb.update());
  // clear the previous screen
  gb.display.clear();
  gb.display.setCursor(1, 15);
  gb.display.setColor(WHITE);
  gb.display.print("Press ");
  gb.display.setColor(GREEN);
  gb.display.print("A ");
  gb.display.setColor(WHITE);
  gb.display.println("button to show popup window");
  gb.display.setCursorX(1);
  gb.display.print("Press ");
  gb.display.setColor(GREEN);
  gb.display.print("B ");
  gb.display.setColor(WHITE);
  gb.display.println("button to change popup window");
  gb.display.setCursorX(1);
  gb.display.print("Press ");
  gb.display.setColor(GREEN);
  gb.display.print("MENU ");
  gb.display.setColor(WHITE);
  gb.display.println("button to close popup window");
  score = random(100, 100000);
  Tekst1 = "Twoj wynik to ";
  Tekst1.concat(score);
  Tekst1.concat(" punktow");
  // gb.display.drawImage(0, 12, tlo, tlo.width(), tlo.height()-8);
  //  gb.display.drawImage(0, 12, tlo);
  if (gb.buttons.pressed(BUTTON_A)) {
    anim = true;
  }
  if (gb.buttons.pressed(BUTTON_B)) {
    i++;
  }
  switch (i) {
    case 0:
      if (anim) {
        //function(ackgonwalge messagem, font size, text in string, radius, offset, 1/x scale of screen, align left ?, delay in ms to go down)
        drawPopup(true, 1, Tekst1, 2, 1, 5, false, 0);
      }
      break;
    case 1:
      if (anim) {
        //function(ackgonwalge messagem, font size, text in string, radius, offset, 1/x scale of screen, align left ?, delay in ms to go down)
        drawPopup(true, 1, Tekst1, 4, 2, 8, false, 2000);
      }
      break;
    case 2:
      if (anim) {
        //function(ackgonwalge messagem, font size, text in string, radius, offset, 1/x scale of screen, align left ?, delay in ms to go down)
        drawPopup(gb.buttons.pressed(BUTTON_MENU), 1, Tekst1, 6, 3, 3, false, 0);
      }
      break;
    case 3:
      if (anim) {
        //function(ackgonwalge messagem, font size, text in string, radius, offset, 1/x scale of screen, align left ?, delay in ms to go down)
        drawPopup(gb.buttons.pressed(BUTTON_MENU), 1, Tekst1, 8, 4, 3, false, 1000);
      }
      break;
  }
  if (i > 3) {
    i = 0;
  }
  screenBenchmark();
}