Can you delete this topic rodot?

Understanding the language, error messages, etc.

Can you delete this topic rodot?

Postby STUDIOCRAFTapps » Tue Feb 21, 2017 11:14 pm

Note: Sorry if the title seem clickbait... I've been waiting for soo long and no one is helping me. If you don't understand my question, ask me

I don't know why but this line of code
Code: Select all
V = SMGetPaintValue(x,y);
dosen't return the good value and the game goes crazy. If I remove this line of code everything is fine. Note: The line + drawing enabled (this line of code: gb.display.drawBitmap(CPosX + x*8, CPosY + y*8, splashes[], ROT, FLIP);) crash the game but the line with drawing disabled goes crazy but the game dosen't crash.

Code: Select all
/*
 * (C) Create by STUDIOCRAFTapps
 *
 * You are free to modify this code as long as you keep this message.
 * Do not sell this game. Feel free to copy 'parts' of the game to
 * help you create your.
 *
 * Vous etes libre de modifier ce code aussi longtemps que vous garder
 * ce message. Vous ne devez pas vendre ce jeu. N'hesitez pas à copier
 * des parties de ce jeu pour créer le votre.
 *
 */

#include <Backlight.h>
#include <Battery.h>
#include <Buttons.h>
#include <Display.h>
#include <Gamebuino.h>
#include <Sound.h>
#include <SPI.h>
#include <EEPROM.h>

#include <math.h>

Gamebuino gb;

int CamX = 0;
int CamY = 0;
int Frame = 0;

byte Mode = 0;

byte NbrOfLevel = 2;
byte LevelsUnlock = 0;
byte MapCursor = 0;

byte CurrentLoadedMap = 0;

boolean Found = false;

boolean last = false;
boolean AC = false;
byte ACT = 0;
boolean PistonPressed = false;

long* splashMemory;
byte* V;
byte* S;

/////////////////////////////////////
////Map stuf and sprite drawing V////
/////////////////////////////////////

const byte SpawnCoordX[] PROGMEM = {
  1,
  1
};

const byte SpawnCoordY[] PROGMEM = {
  7,
  9
};

const byte MapSizeX[] PROGMEM = {
  20,
  17
};

const byte MapSizeY[] PROGMEM = {
  9,
  11
};

const byte Logo[] PROGMEM = {64,30,0xAD,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xB5,0x0,0x0,0x0,0x77,0x70,0x0,0x0,0xAD,0x0,0x0,0x0,0x52,0x40,0x0,0x0,0xB5,0x0,0x0,0x0,0x62,0x50,0x0,0x0,0xAD,0x0,0x0,0x0,0x52,0x50,0x0,0x0,0xB5,0x0,0x0,0x0,0x77,0x70,0x0,0x0,0xAD,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xB5,0x0,0x0,0x0,0x74,0x27,0x50,0x0,0xAD,0x0,0x0,0x0,0x54,0x54,0x50,0x0,0xB5,0x0,0x0,0x0,0x64,0x74,0x60,0x0,0xAD,0x0,0x0,0x0,0x54,0x54,0x50,0x0,0xB5,0x0,0x0,0x0,0x77,0x57,0x50,0x0,0xAD,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xB5,0x0,0x0,0x0,0x77,0x50,0x0,0x0,0xAD,0x0,0xF,0xF0,0x55,0x50,0x0,0x0,0xB5,0x0,0xF,0xF0,0x65,0x20,0x20,0x0,0xAD,0x0,0xD,0xD0,0x55,0x50,0x0,0x0,0xB5,0x0,0xD,0xD0,0x77,0x50,0x40,0x0,0xAD,0x0,0xF,0xF0,0x0,0x0,0x20,0x0,0xB5,0x0,0xF,0xF0,0xFF,0x0,0xF0,0x0,0xAD,0x0,0xF,0xF0,0x81,0x0,0x60,0x0,0xB5,0x0,0xF,0xF0,0xBD,0x0,0x60,0x0,0xFF,0xFF,0xFF,0xFF,0xA5,0x0,0xF0,0x0,0xC3,0xA6,0x66,0x65,0xA5,0x1,0xB8,0x0,0xA5,0xB9,0x99,0x9D,0xA5,0x3,0x9C,0x0,0x99,0xA6,0x66,0x65,0xA5,0x3,0xC,0x0,0x99,0xB9,0x99,0x9D,0xA5,0x1,0xF8,0x0,0xA5,0xA6,0x66,0x65,0xA5,0x0,0x0,0x0,0xC3,0xB9,0x99,0x9D,0xA5,0x0,0x0,0x0,0xFF,0xA6,0x66,0x65,0xE7,0x0,0x0,0x0,};

const PROGMEM byte Empty[] = //ID: 0
{
  8,8,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
};

const PROGMEM byte Grid[] = //ID: 1
{
  8,8,
  B01010101,
  B10101010,
  B01010101,
  B10101010,
  B01010101,
  B10101010,
  B01010101,
  B10101010
};

const PROGMEM byte Wall1[] = //ID: 2
{
  8,8,
  B11111111,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
};

const PROGMEM byte Wall2[] = //ID: 3
{
  8,8,
  B00000001,
  B00000001,
  B00000001,
  B00000001,
  B00000001,
  B00000001,
  B00000001,
  B00000001,
};

const PROGMEM byte Wall3[] = //ID: 4
{
  8,8,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B11111111,
};

const PROGMEM byte Wall4[] = //ID: 5
{
  8,8,
  B10000000,
  B10000000,
  B10000000,
  B10000000,
  B10000000,
  B10000000,
  B10000000,
  B10000000,
};

const PROGMEM byte Corner1[] = //ID: 6
{
  8,8,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B10000000,
};

const PROGMEM byte Corner2[] = //ID: 7
{
  8,8,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B00000001,
};

const PROGMEM byte Corner3[] = //ID: 8 WORKING
{
  8,8,
  B00000001,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
};

const PROGMEM byte Corner4[] = //ID: 9
{
  8,8,
  B10000000,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
};

//SPLASH SPRITES

const PROGMEM byte SWall2[] =
{
  8,8,
  B11111111,
  B11111110,
  B01011100,
  B00101000,
  B01110000,
  B00100000,
  B00000000,
  B00000000,
};

const PROGMEM byte SWall3[] =
{
  8,8,
  B11111111,
  B11111111,
  B01111111,
  B00111010,
  B00010100,
  B00001110,
  B00000100,
  B00000000,
};

const PROGMEM byte SWall4[] =
{
  8,8,
  B11111111,
  B11111111,
  B11111111,
  B11101110,
  B01010100,
  B00111000,
  B00010000,
  B00000000,
};

const PROGMEM byte SWall5[] =
{
  8,8,
  B11111111,
  B11111111,
  B11111111,
  B10111110,
  B00011100,
  B00101000,
  B01110000,
  B00100000,
};

const PROGMEM byte SWall6[] =
{
  8,8,
  B11111111,
  B11111111,
  B11111111,
  B11111111,
  B01111111,
  B00101110,
  B00000100,
  B00000000,
};

const PROGMEM byte SWall1[] =
{
  8,8,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
};

const PROGMEM byte SCorner1[] =
{
  8,8,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
};

const PROGMEM byte SCorner2[] =
{
  8,8,
  B00010111,
  B00111011,
  B00010001,
  B00000000,
  B00000100,
  B00001110,
  B00000100,
  B00000000,
};

const PROGMEM byte SCorner3[] =
{
  8,8,
  B00000111,
  B00001111,
  B00000101,
  B00001010,
  B00011100,
  B00001000,
  B00000000,
  B00000000,
};

const PROGMEM byte SCorner4[] =
{
  8,8,
  B00000111,
  B00101111,
  B01110111,
  B00100010,
  B00010001,
  B00111000,
  B00010000,
  B00000000,
};

const PROGMEM byte SCorner5[] =
{
  8,8,
  B00011111,
  B00001111,
  B00010111,
  B00111010,
  B00010100,
  B00001110,
  B00000100,
  B00000000,
};

const PROGMEM byte SCorner6[] =
{
  8,8,
  B01011111,
  B11101111,
  B01011111,
  B00001011,
  B00010111,
  B00111010,
  B00010000,
  B00000000,
};

const byte Map0[] PROGMEM = {
  1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
  1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,
  1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,
  1,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,1,
  1,1,1,0,0,0,1,0,0,0,0,0,0,1,0,0,0,1,1,1,
  1,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,1,
  1,0,0,1,0,0,0,0,1,1,1,1,0,0,0,0,1,0,0,1,
  1,0,0,1,0,0,0,0,1,1,1,1,0,0,0,0,1,0,0,1,
  1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
};

const byte Map1[] PROGMEM = {
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
};

const byte* GetMap[] {
  Map0,
  Map1
};

//////////////////////////////////////////////
////Var Initi. for physics and grounding V////
//////////////////////////////////////////////

#define LCDWidth 84
#define LCDHeight 48

#define BouncyMath1 0.0322580//6452
#define BouncyMath2 -0.0483870f//9677
#define BouncyMath3 -0.0393700f//7874
#define BouncyMath4 0.0236220f//4724

byte MapHeigth = 19;
byte MapWidth = 9;

boolean GoingRight = true;

boolean GroundedDown = false;
boolean GroundedRight = false;
boolean GroundedLeft = false;

boolean IsPlaying = false;

//SM : Splash Memory

byte clamp(byte n, byte lower, byte upper) {
    n = ( n > lower ) * n + !( n > lower ) * lower;
    return ( n < upper ) * n + !( n < upper ) * upper;
}

void SMReset () {
  short num = 0;
  for(byte x = 0; x < MapWidth; x++) {                                  //Draw maps
    for(byte y = 0; y < MapHeigth; y++) {
      if(getTile(x,y) == 1) {
        num++;
      }
    }
  }
 
  splashMemory = new long[num]{0};

  for(short i = 0; i < num; i++) {
    splashMemory[i] = 0;
  }
}

void SMSetPaintValue (byte* Paint, byte setX, byte setY) {
  short num = 0;
  unsigned long V = 0;
  for(byte x = 0; x < MapWidth; x++) {                                  //Draw maps
    for(byte y = 0; y < MapHeigth; y++) {
      if(getTile(x,y) == 1 && setX == x && setY == y) {
        break;
      } else {
        num++;
      }
    }
  }
  if(num != 0) {
    V += Paint[0]*6^0;
    V += Paint[1]*6^1;
    V += Paint[2]*6^2;
    V += Paint[3]*6^3;
    V += Paint[4]*6^4;
    V += Paint[5]*6^5;
    V += Paint[6]*6^6;
    V += Paint[7]*6^7;
    splashMemory[num] = V;
  }
}

long FloorByBounds (long Value, long Bound) {
  return floor((float)Value/Bound) * Bound;
}

long SMGetRaw (byte getX, byte getY) {
  short num = 0;
  for(byte x = 0; x < MapWidth; x++) {
    for(byte y = 0; y < MapHeigth; y++) {
      if(getTile(x,y) == 1 && getX == x && getY == y) {
        break;
      } else {
        num++;
      }
    }
  }
  return splashMemory[num];
}

byte* SMGetPaintValue (byte getX, byte getY) {
  S = new byte[8];
  short num = 0;
  for(byte x = 0; x < MapWidth; x++) {                                  //Draw maps
    for(byte y = 0; y < MapHeigth; y++) {
      if(getTile(x,y) == 1 && getX == x && getY == y) {
        break;
      } else {
        num++;
      }
    }
  }
  if(num != 0) {
    S[0] = FloorByBounds(splashMemory[num], 6^7);
    S[1] = FloorByBounds(splashMemory[num]-S[0], 6^6);
    S[2] = FloorByBounds(splashMemory[num]-S[1], 6^5);
    S[3] = FloorByBounds(splashMemory[num]-S[2], 6^4);
    S[4] = FloorByBounds(splashMemory[num]-S[3], 6^3);
    S[5] = FloorByBounds(splashMemory[num]-S[4], 6^2);
    S[6] = FloorByBounds(splashMemory[num]-S[5], 6^1);
    S[7] = FloorByBounds(splashMemory[num]-S[6], 6^0);
    return S;
  } else {
    return S;
  }
}

void SMAddPaint (byte D, byte setX, byte setY, byte Q) {
  byte* V = new byte[8];
  V = SMGetPaintValue(setX, setY);
  V[D]+=Q;
  V[D] = clamp(V[D],0,5);
  SMSetPaintValue (V,setX,setY);
}

/////////////////////
////Block Setup V////
/////////////////////

const byte* sprites[10] = {
  Empty,
  Grid,
  Wall1,
  Wall2,
  Wall3,
  Wall4,
  Corner1,
  Corner2,
  Corner3,
  Corner4
};

const byte* splashes[12] = {
  SWall1,
  SWall2,
  SWall3,
  SWall4,
  SWall5,
  SWall6,
  SCorner1,
  SCorner2,
  SCorner3,
  SCorner4,
  SCorner5,
  SCorner6
};

const byte* coltype[10] = { //0 = empty 1 = block
  0,
  1,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0
};

//////////////////////////////
////GetTile & Var initi. V////
//////////////////////////////


byte getTile(byte x, byte y){
    return pgm_read_byte(GetMap[MapCursor] + (x+y*MapWidth));
    //return (Maps[CurrentLoadedMap])[x+y*MapWidth];
}

///////Sound////////

const int soundfx[8][8] = {
  {1,27,90,2,7,7,3,7}, //jump <
  {1,27,112,1,1,1,6,4}, // walljump <
  {0,27,57,1,1,1,6,4}, // unlockdoor <
  {0,9,57,1,6,8,7,8}, // land
  {0,46,57,1,0,18,7,47}, // getkey <
  {0,38,79,3,6,7,7,20}, // finish <
  {0,30,68,3,0,0,7,5}, // click <
  {0,30,55,1,7,0,7,15} //Death <
};

void sfx(int fxno, int channel) {
  gb.sound.command(0, soundfx[fxno][6], 0, channel); // set volume
  gb.sound.command(1, soundfx[fxno][0], 0, channel); // set waveform
  gb.sound.command(2, soundfx[fxno][5], -soundfx[fxno][4], channel); // set volume slide
  gb.sound.command(3, soundfx[fxno][3], soundfx[fxno][2] - 58, channel); // set pitch slide
  gb.sound.playNote(soundfx[fxno][1], soundfx[fxno][7], channel); // play note
  //WAVEFORM, PITCH, PMD, PMT, VMD, VMT, VOL, LENGTH
}

int CPosX = 0; //Cam Position
int CPosY = 0;

float PPosX = 0; //Player Position
float PPosY = 0;

byte SquisheVertical = 8;      //Player squishness :)
byte SquisheHorizontal = 8;

char VelocityX;    //Velocity (used for physics)
char VelocityY;

///////////////////////////////
////Setup & PlayerDrawing V////
///////////////////////////////

void setup() {
  // put your setup code here, to run once:
  gb.begin();
  gb.titleScreen(F("v1.0"),Logo);
  gb.battery.show = false;
  gb.setFrameRate(20);
  PrepareMap();
}

void DrawPlayer () {  //Draw player based on squisness
  if(GoingRight == true) {
    gb.display.fillRect(CPosX - (PPosX + SquisheHorizontal/2.0) + 8, CPosY - (PPosY + SquisheVertical/2.0) + 8, SquisheHorizontal, SquisheVertical);
    gb.display.setColor(WHITE,WHITE);
    gb.display.drawFastVLine(CPosX - (PPosX + SquisheHorizontal/2.0) + 6 + SquisheHorizontal, CPosY - (PPosY + SquisheVertical/2.0) + 10, 2);
    gb.display.drawFastVLine(CPosX - (PPosX + SquisheHorizontal/2.0) + 3 + SquisheHorizontal, CPosY - (PPosY + SquisheVertical/2.0) + 10, 2);
    gb.display.setColor(BLACK,WHITE);
  } else {
    gb.display.fillRect(CPosX - (PPosX + SquisheHorizontal/2.0) + 8, CPosY - (PPosY + SquisheVertical/2.0) + 8, SquisheHorizontal, SquisheVertical);
    gb.display.setColor(WHITE,WHITE);
    gb.display.drawFastVLine(CPosX - (PPosX + SquisheHorizontal/2.0) + 9, CPosY - (PPosY + SquisheVertical/2.0) + 10, 2);
    gb.display.drawFastVLine(CPosX - (PPosX + SquisheHorizontal/2.0) + 12, CPosY - (PPosY + SquisheVertical/2.0) + 10, 2);
    gb.display.setColor(BLACK,WHITE);
  }
}

////////////////
////Camera V////
////////////////

void ClampCamera () { //Clamp the camera in the world
  if(MapWidth < 11) {
    CPosX = (LCDWIDTH - MapWidth*8)/2;
  } else {
    CPosX = ClampInt(-(8*MapWidth-LCDWidth),0,PPosX+(LCDWIDTH/2)-8);
  }
  CPosY = ClampInt(-(8*MapHeigth-LCDHeight),0,PPosY+(LCDHEIGHT/2));
}

int ClampInt (int minv, int maxv, int value) {
  if(value < minv)
    return minv;
  else if(value >= maxv)
    return maxv;
  else
    return value;
}

///////////////////
////Colliding V////
///////////////////

int PixelInCollider (byte PIMX, byte PIMY, byte PICX, byte PICY) { //PIM = Pos in map (0-255), PIC = Pos in cube (0-8)
 
  byte GlobalColiderType = coltype[getTile(PIMX,PIMY)];
 
  byte x1;
  byte y1;
  byte x2;
  byte y2;
 
  byte Value = 0;
  switch (GlobalColiderType) {
    case 0:
      Value = 1;
      break;
    case 1:
      Value = 2;
      break;
    default:
      Value = 1;
      break;
  }

  if(Value == 0) {
    if(7-PICX >= x1 && 7-PICX <= x2 && 7-PICY>= y1 && 7-PICY<= y2) {
      Value = 2;
    } else {
      Value = 1;
    }
  }
  return Value - 1;
}

void CheckForCollider () { //Based on current velocity        //Need improvement to support BigWhiteBox
  if(VelocityX != 0) {
    byte ColX[8];
    if(VelocityX > 0) {
      for(int xd; xd < 8; xd++) { //yd = Y Down
          ColX[xd] = PixelInCollider( (-(floor((PPosX + 5 + 0) / 8.0))) , (-(floor((PPosY - 3 + xd) / 8.0))) , -(-(PPosX + 5/*e5<4*/ + 0) - (-(floor((PPosX + 5/*e5<4*/ + 0) / 8.0)))*8) , -(-(PPosY - 3 + xd) - (-(floor((PPosY - 3 + xd) / 8.0)))*8) );
      }
      for(int xd; xd < 8; xd++) {
         if(ColX[xd] == 1) {
           //gb.popup(F("A wall has been detected"), 20);
           VelocityX = 0;
           GroundedLeft = true;
         }
       }
     }
     
     if(VelocityX < 0) {
      for(int xd; xd < 8; xd++) { //yd = Y Down
         ColX[xd] = PixelInCollider( (-(floor((PPosX - 4 + 0) / 8.0))) , (-(floor((PPosY - 3 + xd) / 8.0))) , -(-(PPosX - 4 + 0) - (-(floor((PPosX - 4 + 0) / 8.0)))*8) , -(-(PPosY - 3 + xd) - (-(floor((PPosY - 3 + xd) / 8.0)))*8) );
       }
     }
     for(int xd; xd < 8; xd++) {
       if(ColX[xd] == 1) {
         //gb.popup(F("A wall has been detected"), 20);
         VelocityX = 0;
         GroundedRight = true;
       }
     }
   }
   
   if(VelocityY != 0) {
     byte ColY[8];
     if(VelocityY > 0) {
        for(int yd; yd < 8; yd++) { //yd = Y Down
          ColY[yd] = PixelInCollider((-(floor((PPosX - 3 + yd) / 8.0))) , (-(floor((PPosY + 5 + 0) / 8.0))) , -(-(PPosX - 3 + yd) - (-(floor((PPosX - 3 + yd) / 8.0)))*8) , -(-(PPosY + 5/*e5*/ + 0) - (-(floor((PPosY + 5/*e5*/ + 0) / 8.0)))*8));
        }
        for(int yd; yd < 8; yd++) {
          if(ColY[yd] == 1) {
            VelocityY = 0;
          }
        }
      }
      if(VelocityY < 0) {
        for(int yd; yd < 8; yd++) { //yd = Y Down
          ColY[yd] = PixelInCollider((-(floor((PPosX - 3 + yd) / 8.0))) , (-(floor((PPosY - 4 + 0) / 8.0))) , -(-(PPosX - 3/*e3*/ + yd) - (-(floor((PPosX - 3/*e3*/ + yd) / 8.0)))*8) , -(-(PPosY - 4/*e4*/ + 0) - (-(floor((PPosY - 4/*e4*/ + 0) / 8.0)))*8));
        }
        for(int yd; yd < 8; yd++) {
          if(ColY[yd] == 1) {
            VelocityY = 0;
            GroundedDown = true;
          }
        }
      }
    }

    byte ColG[6];

    for(int yd; yd < 6; yd++) { //yd = Y Down
      ColG[yd] = PixelInCollider((-(floor((PPosX - 2 + yd) / 8.0))) , (-(floor((PPosY - 3 + 0) / 8.0))) , -(-(PPosX - 2/*e3*/ + yd) - (-(floor((PPosX - 2/*e3*/ + yd) / 8.0)))*8) , -(-(PPosY - 3/*e4*/ + 0) - (-(floor((PPosY - 3/*e4*/ + 0) / 8.0)))*8));
    }
    for(int yd; yd < 6; yd++) {
      if(ColG[yd] == 1) {
        VelocityY = 30;
      }
    }
}

//////////////////////
////PreparingMap V////
//////////////////////

void PrepareMap () {
  //PPosX = (8*SpawnCoordX[CurrentLoadedMap]);
  //PPosY = (8*SpawnCoordY[CurrentLoadedMap]);
  CurrentLoadedMap = 0;
  PPosX = -(8*pgm_read_byte(SpawnCoordX + CurrentLoadedMap)) + 4;                      //Convert Spawnpos to Worldpos
  PPosY = -(8*pgm_read_byte(SpawnCoordY + CurrentLoadedMap)) + 4;
 
  VelocityX = 0;
  VelocityY = 0;
  IsPlaying = true;
  MapWidth = pgm_read_byte(MapSizeX + CurrentLoadedMap);
  MapHeigth = pgm_read_byte(MapSizeY + CurrentLoadedMap);

  SMReset();
}

//////////////////
////Updating V////
//////////////////

boolean inRay (byte Min, byte Max, byte Value) {
  return Value <= Max && Value >= Min;
}

boolean inRange (byte r, byte v) {
  return inRay(r,r+8,v+2) || inRay(r,r+8,v+6);
}

void loop() {
  // put your main code here, to run repeatedly:
  if(gb.update()) {
      if(IsPlaying) {
        GroundedDown = false;
        GroundedRight = false;
        GroundedLeft = false;

        if(last == false && GroundedDown == true) {
          sfx(3, 3);
        }

        last = GroundedDown;

        //SlowDown
        if(!(gb.buttons.timeHeld(BTN_RIGHT) > 0) && !(gb.buttons.timeHeld(BTN_LEFT) > 0)) {
          VelocityX = VelocityX * 0.6f;
        }

        //Gravity
        if(VelocityY - 3 > -127) {
          VelocityY = VelocityY - 3;
        } else {
          VelocityY = -127;
        }

        //Mouvement
        if(gb.buttons.timeHeld(BTN_RIGHT) > 0) {
          if(VelocityX - 6 > -50) {
            VelocityX -= 6;
          }
          GoingRight = true;
        }
        if(gb.buttons.timeHeld(BTN_LEFT) > 0) {
          if(VelocityX + 6 < 50) {
            VelocityX += 6;
          }
          GoingRight = false;
        }

        ACT = 3;

        CheckForCollider();

        if(gb.buttons.pressed(BTN_A) && GroundedDown) {
          sfx(0, 0);
          VelocityY = 66;
        }

        if(gb.buttons.pressed(BTN_A) && GroundedRight && !GroundedDown) {
          VelocityX = 60;
          VelocityY = 56;
          sfx(1, 0);
        }

        if(gb.buttons.pressed(BTN_A) && GroundedLeft && !GroundedDown) {
          VelocityX = -60;
          VelocityY = 56;
          sfx(1, 0);
        }


        if(AC == true) {
          VelocityX = -63;
          AC = false;
        }
        if(ACT == 0) {
          VelocityX = -23;
        } else if(ACT == 1){
          VelocityX = 23;
        } else if (ACT == 2 && gb.buttons.pressed(BTN_A)) {
          VelocityY = 110;
        }
     
        PPosX += VelocityX / 127.0F * 3;
        PPosY += VelocityY / 127.0F * 3;

        if(VelocityY > 0) {
          //ex: 62 to 0 is flat to normal
          if(VelocityY > 62) {
            SquisheVertical = 5;
            SquisheHorizontal = 10;
          } else {
            SquisheVertical = 8+(VelocityY*BouncyMath2);
            SquisheHorizontal = 8+(VelocityY*BouncyMath1);
          }
        }
        if(VelocityY < 0) {
          //ex: 0 to -127 is normal to verticaly flat
          SquisheVertical = 8+(VelocityY*BouncyMath3);
            SquisheHorizontal = 8+(VelocityY*BouncyMath4);
        }
        if(VelocityY == 0) {
          SquisheVertical = 8;
          SquisheHorizontal = 8;
        }

        DrawPlayer();
        ClampCamera();

        if(gb.buttons.pressed(BTN_B)) {
          for(char x1 = -1; x1 < 2; x1++) {
            for(char y1 = -1; y1 < 2; y1++) {
              if(!((PPosX/8)+x1<0 || (PPosX/8)+x1>=MapWidth || (PPosY/8)+y1<0 || (PPosY/8)+y1>=MapHeigth)) {
                if(getTile((PPosX/8)+x1,(PPosY/8)+y1)==0) {
                 
                  for(char x2 = -1; x2 < 2; x2++) {
                    for(char y2 = -1; y2 < 2; y2++) {
                      if(!((PPosX/8)+x1+x2<0 || (PPosX/8)+x1+x2>=MapWidth || (PPosY/8)+y1+y2<0 || (PPosY/8)+y1+y2>=MapHeigth)) {
                        if(getTile((PPosX/8)+x1+x2,(PPosY/8)+y1+y2)==0) {
                          if(x2<0) {
                            if(y2<0) {
                              SMAddPaint(6,(PPosX/8),(PPosY/8),1);
                            } else if(y2>0) {
                              SMAddPaint(0,(PPosX/8),(PPosY/8),1);
                            } else if(y2==0) {
                              SMAddPaint(7,(PPosX/8),(PPosY/8),1);
                            }
                          }
                          if(x2>0) {
                            if(y2<0) {
                              SMAddPaint(4,(PPosX/8),(PPosY/8),1);
                            } else if(y2>0) {
                              SMAddPaint(2,(PPosX/8),(PPosY/8),1);
                            } else if(y2==0) {
                              SMAddPaint(3,(PPosX/8),(PPosY/8),1);
                            }
                          }
                          if(x2==0) {
                            if(y2<0) {
                              SMAddPaint(1,(PPosX/8),(PPosY/8),1);
                            } else if(y2>0) {
                              SMAddPaint(5,(PPosX/8),(PPosY/8),1);
                            }
                          }
                        }
                      }
                    }
                  }
                 
                }       
              }
            }
          }
        }

        gb.display.setColor(BLACK);
        for(byte x = 0; x < MapWidth; x++) {                                  //Draw maps
          for(byte y = 0; y < MapHeigth; y++) {
            gb.display.drawBitmap(CPosX + x*8, CPosY + y*8, sprites[getTile(x,y)]);
            if(getTile(x,y) == 1) {
              //V = new byte[8]{0};
              V = SMGetPaintValue(x,y);
              //Was blocked here
              for(char x1 = -1; x1 < 2; x1++) {
                for(char y1 = -1; y1 < 2; y1++) {
                  if(!(x+x1<0 || x+x1>=MapWidth || y+y1<0 || y+y1>=MapHeigth)) {
                    if(getTile(x+x1,y+y1)==0) {
                      if(x1<0) {
                        if(y1<0) {
                          //gb.display.drawBitmap(CPosX + x*8, CPosY + y*8, splashes[6+V[6]], ROT180, NOFLIP);
                          gb.display.drawBitmap(CPosX + x*8, CPosY + y*8, sprites[2+4+3]);
                        } else if(y1>0) {
                          //gb.display.drawBitmap(CPosX + x*8, CPosY + y*8, splashes[6+V[0]], ROTCCW, NOFLIP);
                          gb.display.drawBitmap(CPosX + x*8, CPosY + y*8, sprites[2+4+0]);
                        } else if(y1==0) {
                          //gb.display.drawBitmap(CPosX + x*8, CPosY + y*8, splashes[V[7]], ROTCCW, NOFLIP);
                          gb.display.drawBitmap(CPosX + x*8, CPosY + y*8, sprites[2+3]);
                        }
                      }
                      if(x1>0) {
                        if(y1<0) {
                          //gb.display.drawBitmap(CPosX + x*8, CPosY + y*8, splashes[6+V[4]], ROTCW, NOFLIP);
                          gb.display.drawBitmap(CPosX + x*8, CPosY + y*8, sprites[2+4+2]);
                        } else if(y1>0) {
                          //gb.display.drawBitmap(CPosX + x*8, CPosY + y*8, splashes[6+V[2]], NOROT, NOFLIP);
                          gb.display.drawBitmap(CPosX + x*8, CPosY + y*8, sprites[2+4+1]);
                        } else if(y1==0) {
                          //gb.display.drawBitmap(CPosX + x*8, CPosY + y*8, splashes[V[3]], ROTCW, NOFLIP);
                          gb.display.drawBitmap(CPosX + x*8, CPosY + y*8, sprites[2+1]);
                        }
                      }
                      if(x1==0) {
                        if(y1<0) {
                          //gb.display.drawBitmap(CPosX + x*8, CPosY + y*8, splashes[V[1]], NOROT, NOFLIP);
                          gb.display.drawBitmap(CPosX + x*8, CPosY + y*8, sprites[2+0]);
                        } else if(y1>0) {
                          //gb.display.drawBitmap(CPosX + x*8, CPosY + y*8, splashes[V[5]], ROT180, NOFLIP);
                          gb.display.drawBitmap(CPosX + x*8, CPosY + y*8, sprites[2+2]);
                        }
                      }
                    }
                  }
                }
              } //Was blocked here
            }
          }
        }
      }
   }
}
Last edited by STUDIOCRAFTapps on Thu Mar 30, 2017 1:13 am, edited 7 times in total.
User avatar
STUDIOCRAFTapps
 
Posts: 86
Joined: Sun Oct 02, 2016 11:58 pm
Location: Deep in the web

Re: I'll stop working on SplashBox if i don't get an answers

Postby wuuff » Tue Feb 28, 2017 8:51 pm

I actually thought that this topic had vanished for a while because it wasn't at the top of the category any more. I guess you deleted your own replies to this topic.

I have been planning to try to help with this, but I have been busy and hadn't gotten around to it, and I didn't want to post until I had an actual answer.

I think it might be a bit much to threaten to cancel working on your game, since there's barely anyone who seems to be on the forums right now who is able or willing to help. I understand your frustration, though. I have been dealing with the same thing with the question I asked recently, and I really wish this forum was more active.

I'll try to get to taking a look at this soon, but I'm still a bit busy. This is something that can't easily be solved by just looking at the code, so I'll have to download the code and experiment with it. I just wanted to let you know that somebody is listening.
wuuff
 
Posts: 61
Joined: Sun Aug 28, 2016 6:05 am

Re: I'll stop working on SplashBox if i don't get an answers

Postby STUDIOCRAFTapps » Tue Feb 28, 2017 9:54 pm

This is not the first time i get a very... Weird glitchy bug with a Gambuino but this time, i've maybe find the answers by thinking differently, and not by trying to fix the actual bug, replace 2 long array by 8 unsigned char array... It's easier that fixing the bug...
User avatar
STUDIOCRAFTapps
 
Posts: 86
Joined: Sun Oct 02, 2016 11:58 pm
Location: Deep in the web

Re: Wierd memory bug?

Postby wuuff » Wed Mar 01, 2017 2:48 am

So have you solved your issue by changing the implementation? Have you solved the problem, or are you still asking for help?
wuuff
 
Posts: 61
Joined: Sun Aug 28, 2016 6:05 am

Re: Wierd memory bug?

Postby STUDIOCRAFTapps » Wed Mar 01, 2017 2:21 pm

wuuff wrote:So have you solved your issue by changing the implementation? Have you solved the problem, or are you still asking for help?


I've found a solution but i've not tried it yet.
User avatar
STUDIOCRAFTapps
 
Posts: 86
Joined: Sun Oct 02, 2016 11:58 pm
Location: Deep in the web

Re: Wierd memory bug?

Postby STUDIOCRAFTapps » Wed Mar 01, 2017 3:02 pm

The technique that i use take 8 byte per block. A small 20x9 map use 1 440 bytes which is 70% of all the SRAM of Gamebuino. I need bigger map and a lot of bytes for weapons, projectiles... I've tried to same some byte by not using empty block. Now, the 20x9 map use 688 byte, that represent 33% of the total SRAM. Not bad but i'm sure that i'm going to need more.
User avatar
STUDIOCRAFTapps
 
Posts: 86
Joined: Sun Oct 02, 2016 11:58 pm
Location: Deep in the web

Re: Wierd memory bug?

Postby Sorunome » Wed Mar 01, 2017 6:49 pm

Keep in mind in your calculations that you can't use 100% for buffers as local variables, the callstack and thelike also take up memory. As soon as you run into extremely weird bugs you basically know that you used too much. (That is, if you know already that your code should be working and that you are very high on memory usage. Else it's just a normal weird bug :P)
User avatar
Sorunome
 
Posts: 629
Joined: Sun Mar 01, 2015 1:58 pm

Re: Wierd memory bug?

Postby Duhjoker » Thu Mar 09, 2017 11:01 pm

Starting to look like we are bleeding out here.
User avatar
Duhjoker
 
Posts: 446
Joined: Sat Jul 02, 2016 4:57 am
Location: Where Palm trees grow

Re: Wierd memory bug?

Postby STUDIOCRAFTapps » Sat Mar 25, 2017 4:47 pm

Why do splashes returns "SCorner6": splashes[1] returns

const byte* splashes[12] = {
SWall1,
SWall2,
SWall3,
SWall4,
SWall5,
SWall6,
SCorner1,
SCorner2,
SCorner3,
SCorner4,
SCorner5,
SCorner6
};
User avatar
STUDIOCRAFTapps
 
Posts: 86
Joined: Sun Oct 02, 2016 11:58 pm
Location: Deep in the web


Return to Programming Questions

Who is online

Users browsing this forum: No registered users and 4 guests

cron