game developing tutorial for tiny arcade won't work

bobojo · 2 · 8076

bobojo

  • Newbie
  • *
    • Posts: 1
    • View Profile
I did everything it said ,but after trying to upload the file is said "too many initializers for 'ts_sprite'"
here is my code:

//Tiny Arcade Testing
//Initiated Mon. 5/22/17 @  10:05pm
//    Updated Mon. 5/22/17 @  10:06pm

const uint16_t ALPHA = 0x1111;

#include <TinyScreen.h>
#include <Wire.h>
#include <SPI.h>
#include "TinyArcade.h"
#include "GameTutorialSprites.h"

TinyScreen display = TinyScreen(TinyScreenPlus);

typedef struct {
  int x;
  int y;
  int width;
  int height;
  const unsigned int *bitmap;
} ts_sprite;

ts_sprite ball = {44,28,4,4,0,ballBitmap};

int amtSprites = 1;
ts_sprites * spriteList[1] = {&ball};

int backgroundColor = ts_16b_Black;

void setup() {
  arcadeInit();
  display.begin();
  display.setBitDepth(TSBitDepth16);
  display.setBrightness(15);
  display.setFlip(false);

  USBDevice.init();
  USNDevice.attach();
  SerialUSB.begin(9600);
}
void loop() {
  drawBuffer();
}

void drawBuffer(){
  unit8_t lineBuffer[96 * 64 * 2];
  display.startData();
  for(int y = 0; y < 64; y++)  {
    for(int b = 0; b < 96; b++)  {
      lineBuffer[b*2] = backgroundColor >> 8;
      lineBuffer[b*2+1] = backgroundColor;
    }
    for(int spriteIndex = 0; spriteIndex < amtSprites; spriteIndex++){
      ts_sprite *cs = spriteList [spriteIndex];
      if (y >= cs->y && y < cs->y + cs->height)  {
        int endX = cs->x + cs->width;
        if(cs->x <96 && endX > 0)  {
          int xBitmapOffset = 0;
          int xStart = 0;
          if (cs->x < 0) xBitmapOffset -= cs ->x;
          if (cs ->x >0) xStart = cs->x;
          int yBitmapOffset = (y- cs->y) *cs-> width;
          for (int x = xStart; x < endX; x++) {
            unsigned int color = cs->bitmap[xBitmapOffset + yBitmapOffset++];
            if (color != ALPHA)  {
              lineBuffer[(x)*2] = color >> 8;
              lineBuffer[(x) * 2 +1] = color;
            }
          }
        }
      }
    }
    display.writeBuffer(lineBuffer,96 * 2);
  }
  display.endTransfer();
}


bfarmer@tinycircuits.com

  • Newbie
  • *
    • Posts: 3
  • Associate Engineer at TinyCircuits
    • View Profile
Hi bobojo,

Your code contains a very minor error which is easy to correct in one of two manners. It appears that you forgot to add: int collisions; to your typedef struct, as shown below.

typedef struct {
  int x;
  int y;
  int width;
  int height;
  int collisions;
  const unsigned int *bitmap;
} ts_sprite;

ts_sprite ball = {44,28,4,4,0,ballBitmap};

If you don't wish to utilize the collision tracking variable, you could also leave your typedef struct as is and delete the 0 value as shown below:

ts_sprite ball = {44,28,4,4,0,ballBitmap};

Whichever method you choose, the important thing is to keep both consistent to each other.


 

SMF spam blocked by CleanTalk