[WIP] BigBlackBox > Release 16/12/18

Advice on general approaches or feasibility and discussions about game design

Re: [WIP] BigBlackBox > NEED HELP!

Postby STUDIOCRAFTapps » Thu Nov 10, 2016 12:40 am

I'm not sure if i will continue this project if i don't have help... It's hard...
User avatar
STUDIOCRAFTapps
 
Posts: 86
Joined: Sun Oct 02, 2016 11:58 pm
Location: Deep in the web

Re: [WIP] BigBlackBox > NEED HELP!

Postby erico » Thu Nov 10, 2016 2:30 am

Don´t loose determination.
I´m not advanced to help enough, maybe searching the forum can bring some new fronts?
The tutorials I think can get you ahead into making a core base of your game. :)
User avatar
erico
 
Posts: 671
Joined: Thu Mar 27, 2014 9:29 pm
Location: Brazil

Re: [WIP] BigBlackBox > NEED HELP!

Postby naed » Thu Nov 10, 2016 7:32 pm

Why not post what you have here so far?

That way people can see what is involved and contribute if they have the ability to, I found that posting my work in progress and also posting the code I have written has got me more help than trying to keep a project more secretive.

I would gladly help if I had the ability to but the things you are asking for help with seem beyond me, although maybe I could help if I saw the code you had written so far

But I agree that you shouldn't give up with this please
User avatar
naed
 
Posts: 140
Joined: Tue May 31, 2016 3:18 pm

Re: [WIP] BigBlackBox > NEED HELP!

Postby STUDIOCRAFTapps » Thu Nov 10, 2016 10:47 pm

Good idea! I will try my best to continue developping the game but the process may slow down, i have a lot of project going on and trying to fix the gamebuino game take a lot of games, but i will not stop. ;)
User avatar
STUDIOCRAFTapps
 
Posts: 86
Joined: Sun Oct 02, 2016 11:58 pm
Location: Deep in the web

Re: [WIP] BigBlackBox > NEED HELP!

Postby STUDIOCRAFTapps » Thu Nov 10, 2016 10:51 pm

It's hard because the collision and the physic system is a bit weird. The way my physics work is unique and i cannot have help on that. Wall jump is a bit crappy and not working correctly and bounce mess up the player... :|
User avatar
STUDIOCRAFTapps
 
Posts: 86
Joined: Sun Oct 02, 2016 11:58 pm
Location: Deep in the web

Re: [WIP] BigBlackBox > NEED HELP!

Postby STUDIOCRAFTapps » Thu Nov 10, 2016 11:31 pm

Here's a little demo of my problems... I will publish the code later.
Attachments
BigBlackBox.ino.hex.zip
Hex
(15.11 KiB) Downloaded 260 times
User avatar
STUDIOCRAFTapps
 
Posts: 86
Joined: Sun Oct 02, 2016 11:58 pm
Location: Deep in the web

Re: [WIP] BigBlackBox > NEED HELP!

Postby STUDIOCRAFTapps » Sat Nov 12, 2016 9:51 pm

Ok... Here's the dirty code:

Code: Select all
#include <Backlight.h>
#include <Battery.h>
#include <Buttons.h>
#include <Display.h>
#include <Gamebuino.h>
#include <Sound.h>
#include <SPI.h>

#include <math.h>
//#include <string>

Gamebuino gb;

//Todo:

//-Add more boncy physics

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 GroundLeft[] = //ID: 10
{
  8,8,
  B11111111,
  B10111001,
  B10100110,
  B10111001,
  B10100110,
  B10111001,
  B10100110,
  B10111001,
};

const PROGMEM byte GroundRight[] = //ID: 11
{
  8,8,
  B11111111,
  B10011101,
  B01100101,
  B10011101,
  B01100101,
  B10011101,
  B01100101,
  B10011101,
};

const PROGMEM byte GroundMiddle[] = //ID: 12
{
  8,8,
  B11111111,
  B01100110,
  B10011001,
  B01100110,
  B10011001,
  B01100110,
  B10011001,
  B01100110,
};

const PROGMEM byte Brick[] = //ID: 1
{
  8,8,
  B11111111,
  B00100001,
  B11111111,
  B10001000,
  B11111111,
  B00100001,
  B11111111,
  B10001000,
};

const PROGMEM byte SharpBrick[]= //ID: 2
{
  8,8,
  B11111111,
  B11000011,
  B10100101,
  B10011001,
  B10011001,
  B10100101,
  B11000011,
  B11111111,
};
const PROGMEM byte TowerBrick[]= //ID: 3
{
  8,8,
  B10101101,
  B10110101,
  B10101101,
  B10110101,
  B10101101,
  B10110101,
  B10101101,
  B10110101,
};

const PROGMEM byte Piston[]= //ID: 4
{
  8,8,
  B11111111,
  B10000001,
  B11011011,
  B11011011,
  B10111101,
  B11100111,
  B10000001,
  B11111111,
};

const PROGMEM byte Holder[]= //ID: 5
{
  8,8,
  B11111111,
  B10100101,
  B11111111,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
};

const PROGMEM byte  Teleporter1[]= //ID: 6
{
  8,8,
  B11111111,
  B10101011,
  B11010110,
  B10101100,
  B10101100,
  B11010110,
  B10101011,
  B11111111,
};

const PROGMEM byte Teleporter0[]= //ID: 7
{
  8,8,
  B11111111,
  B11010101,
  B01101011,
  B00110101,
  B00110101,
  B01101011,
  B11010101,
  B11111111,
};

const PROGMEM byte Wall[]= //ID: 8
{
  8,8,
  B11110000,
  B10010000,
  B10010000,
  B10010000,
  B10010000,
  B10010000,
  B10010000,
  B11110000,
};

const PROGMEM byte Ennemie[]= //ID: 9
{
  8,8,
  B11111111,
  B10000001,
  B10010011,
  B10010011,
  B10000001,
  B10000001,
  B10000001,
  B11111111,
};

const byte Map[] PROGMEM = {
0,0,0,0,0,0,0,0,0,0,0,0,2,
2,1,2,5,5,8,0,0,0,0,0,0,6,
3,0,0,0,0,8,0,0,0,0,0,0,2,
3,0,0,0,0,0,4,5,2,0,0,0,3,
2,0,2,0,0,0,0,0,0,0,0,0,3,
3,0,3,0,0,0,0,0,0,0,0,0,3,
3,0,3,0,0,0,2,5,5,0,5,5,2,
3,0,3,0,9,0,3,0,9,0,0,0,6,
2,0,2,1,1,1,2,1,1,1,1,1,2,
};

#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 = 9;
byte MapWidth = 13;

byte SpawnX = 9;
byte SpawnY = 2;

boolean GoingRight = true;

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

const byte* sprites[10] = {
  Empty,
  Brick,
  SharpBrick,
  TowerBrick,
  Piston,
  Holder,
  Teleporter0,
  Teleporter1,
  Wall,
  Ennemie
};

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

byte getTile(byte x, byte y){
    return pgm_read_byte(Map + (x+y*MapWidth));
} //< Need to be improved (Not adapted for multiples maps)

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;

void setup() {
  // put your setup code here, to run once:
  gb.begin();
  gb.titleScreen(F("Developpement"),Logo);
  gb.battery.show = false;
 
  PPosX = -(8*SpawnX)-4;                      //Convert Spawnpos to Worldpos
  PPosY = -(8*SpawnY)-8;

  //VelocityY = 45;
}

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);
  }
}

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

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

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;
      case 2:
        x1 = 0;
        y1 = 0;
        x2 = 7;
        y2 = 3;
        break;
      case 3:
        Value = 3;
        break;
      case 4:
        Value = 4;
      case 5:
        x1 = 0;
        y1 = 0;
        x2 = 4;
        y2 = 7;
        break;
      default:
        Value = 1;
  }

  if(Value == 0) {
    if(PICY == 0) {
      gb.popup(F("Code: 0"), 20);
    } else if(PICY == 1) {
      gb.popup(F("Code: 1"), 20);
    } else if(PICY == 2) {
      gb.popup(F("Code: 2"), 20);
    } else if(PICY == 3) {
      gb.popup(F("Code: 3"), 20);
    } else if(PICY == 4) {
      gb.popup(F("Code: 4"), 20);
    } else if(PICY == 5) {
      gb.popup(F("Code: 5"), 20);
    } else if(PICY == 6) {
      gb.popup(F("Code: 6"), 20);
    } else if(PICY == 7) {
      gb.popup(F("Code: 7"), 20);
    } else if(PICY == 8) {
      gb.popup(F("Code: 8"), 20);
    } else if(PICY == 9) {
      gb.popup(F("Code: 9"), 20);
    } else if(PICY == 10) {
      gb.popup(F("Code: 10"), 20);
    } else {
      if(PICY > 255) {
        gb.popup(F("else > 255"), 20);
      } else {
        gb.popup(F("else < 255"), 20);
      }
    }
    /*if(PICY >= 0) {
      gb.popup(F("True"), 20);
    } else {
      gb.popup(F("False"), 20);
    }*/
    if(-PICX>= x1 && -PICX <= x2 && -PICY>= y1 && -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 + 0) - (-(floor((PPosX + 5 + 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;
       }
     }
   }

   
    //working stuff V

   
   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 + 0) - (-(floor((PPosY + 5 + 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 + yd) - (-(floor((PPosX - 3 + yd) / 8.0)))*8, -(PPosY - 4 + 0) - (-(floor((PPosY - 4 + 0) / 8.0)))*8);
        }
        for(int yd; yd < 8; yd++) {
          if(ColY[yd] == 1) {
            VelocityY = 0;
            GroundedDown = true;
          }
        }
      }
    }
}

void loop() {
  // put your main code here, to run repeatedly:
  if(gb.update()) {
      GroundedDown = false;
      GroundedRight = false;
      GroundedLeft = false;
   
      VelocityY = VelocityY - 3;
      VelocityX = VelocityX * 0.6f;

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

      CheckForCollider();

      if(gb.buttons.pressed(BTN_A) && GroundedDown)
        VelocityY = 66;

      if(gb.buttons.pressed(BTN_A) && GroundedRight) {
        VelocityX += 60;
        VelocityY = 56;
      }

      if(gb.buttons.pressed(BTN_A) && GroundedLeft) {
        VelocityX -= 60;
        VelocityY = 56;
      }
     
      PPosX += (float)VelocityX / (float)127 * 3;
      PPosY += (float)VelocityY / (float)127 * 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();
     
      for(byte x = 0; x < MapWidth; x++) {                                  //Draw maps
        for(byte y = 0; y < MapHeigth; y++) {                                           //< GetTile sould get the map based the current one loaded and not the first
          gb.display.drawBitmap(CPosX + x*8, CPosY + y*8, sprites[getTile(x,y)]);
        }
      }
  }
}


Edit: I didn't progress since five day.
User avatar
STUDIOCRAFTapps
 
Posts: 86
Joined: Sun Oct 02, 2016 11:58 pm
Location: Deep in the web

Re: [WIP] BigBlackBox > NEED HELP!

Postby STUDIOCRAFTapps » Sun Nov 13, 2016 2:53 pm

For people that want to see the progress:

https://youtu.be/-LQRfixaamg

The colliding system, "ColS", can detect the full block but cannot detect correctly the custom colliders block, "CusCB".

The Y axis of a "CusCB" can be easily detected by the "ColS":
'This is the working part of code'

Code: Select all
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))) , -(-(PPosY - 3 + yd) - (-(floor((PPosX - 3 + yd) / 8.0)))*8) , -(-(PPosY + 5 + 0) - (-(floor((PPosY + 5 + 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))) , -(-(PPosY - 3 + 0) - (-(floor((PPosX - 3 + yd) / 8.0)))*8) , -(-(PPosY - 4 + 0) - (-(floor((PPosY - 4 + 0) / 8.0)))*8));
        }
        for(int yd; yd < 8; yd++) {
          if(ColY[yd] == 1) {
            VelocityY = 0;
            GroundedDown = true;
          }
        }
      }
    }


But the x-axis return a weird random number. The number is the one that the pop-up show in the video.
This problem come from these line of code:

Code: Select all
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))) , [u]-(-(PPosX + 5 + 0) - (-(floor((PPosX + 5 + 0) / 8.0)))*8) , -(-(PPosY - 3 + xd) - (-(floor((PPosY - 3 + xd) / 8.0)))*8)[/u]);
      }
      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))) , [u]-(-(PPosX - 4 + 0) - (-(floor((PPosX - 4 + 0) / 8.0)))*8) , -(-(PPosY - 3 + xd) - (-(floor((PPosY - 3 + xd) / 8.0)))*8)[/u]);
       }
     }
     for(int xd; xd < 8; xd++) {
       if(ColX[xd] == 1) {
         //gb.popup(F("A wall has been detected"), 20);
         VelocityX = 0;
         GroundedRight = true;
       }
     }
   }


I'm trying to fix this. Here's the complet code:

Code: Select all
#include <Backlight.h>
#include <Battery.h>
#include <Buttons.h>
#include <Display.h>
#include <Gamebuino.h>
#include <Sound.h>
#include <SPI.h>

#include <math.h>
//#include <string>

Gamebuino gb;

//Todo:

//-Add more boncy physics

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 GroundLeft[] = //ID: 10
{
  8,8,
  B11111111,
  B10111001,
  B10100110,
  B10111001,
  B10100110,
  B10111001,
  B10100110,
  B10111001,
};

const PROGMEM byte GroundRight[] = //ID: 11
{
  8,8,
  B11111111,
  B10011101,
  B01100101,
  B10011101,
  B01100101,
  B10011101,
  B01100101,
  B10011101,
};

const PROGMEM byte GroundMiddle[] = //ID: 12
{
  8,8,
  B11111111,
  B01100110,
  B10011001,
  B01100110,
  B10011001,
  B01100110,
  B10011001,
  B01100110,
};

const PROGMEM byte Brick[] = //ID: 1
{
  8,8,
  B11111111,
  B00100001,
  B11111111,
  B10001000,
  B11111111,
  B00100001,
  B11111111,
  B10001000,
};

const PROGMEM byte SharpBrick[]= //ID: 2
{
  8,8,
  B11111111,
  B11000011,
  B10100101,
  B10011001,
  B10011001,
  B10100101,
  B11000011,
  B11111111,
};
const PROGMEM byte TowerBrick[]= //ID: 3
{
  8,8,
  B10101101,
  B10110101,
  B10101101,
  B10110101,
  B10101101,
  B10110101,
  B10101101,
  B10110101,
};

const PROGMEM byte Piston[]= //ID: 4
{
  8,8,
  B11111111,
  B10000001,
  B11011011,
  B11011011,
  B10111101,
  B11100111,
  B10000001,
  B11111111,
};

const PROGMEM byte Holder[]= //ID: 5
{
  8,8,
  B11111111,
  B10100101,
  B11111111,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
};

const PROGMEM byte  Teleporter1[]= //ID: 6
{
  8,8,
  B11111111,
  B10101011,
  B11010110,
  B10101100,
  B10101100,
  B11010110,
  B10101011,
  B11111111,
};

const PROGMEM byte Teleporter0[]= //ID: 7
{
  8,8,
  B11111111,
  B11010101,
  B01101011,
  B00110101,
  B00110101,
  B01101011,
  B11010101,
  B11111111,
};

const PROGMEM byte Wall[]= //ID: 8
{
  8,8,
  B11110000,
  B10010000,
  B10010000,
  B10010000,
  B10010000,
  B10010000,
  B10010000,
  B11110000,
};

const PROGMEM byte Ennemie[]= //ID: 9
{
  8,8,
  B11111111,
  B10000001,
  B10010011,
  B10010011,
  B10000001,
  B10000001,
  B10000001,
  B11111111,
};

const byte Map[] PROGMEM = {
0,0,0,0,0,0,0,0,0,0,0,0,2,
2,1,2,5,5,8,0,0,0,0,0,0,6,
3,0,0,0,0,8,0,0,0,0,0,0,2,
3,0,0,0,0,0,4,5,2,0,0,0,3,
2,0,2,0,0,0,0,0,0,0,0,0,3,
3,0,3,0,0,0,0,0,0,0,0,0,3,
3,0,3,0,0,0,2,5,5,0,5,5,2,
3,0,3,0,9,0,3,0,9,0,0,0,6,
2,0,2,1,1,1,2,1,1,1,1,1,2,
};

#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 = 9;
byte MapWidth = 13;

byte SpawnX = 9;
byte SpawnY = 2;

boolean GoingRight = true;

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

const byte* sprites[10] = {
  Empty,
  Brick,
  SharpBrick,
  TowerBrick,
  Piston,
  Holder,
  Teleporter0,
  Teleporter1,
  Wall,
  Ennemie
};

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

byte getTile(byte x, byte y){
    return pgm_read_byte(Map + (x+y*MapWidth));
} //< Need to be improved (Not adapted for multiples maps)

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;

void setup() {
  // put your setup code here, to run once:
  gb.begin();
  gb.titleScreen(F("Developpement"),Logo);
  gb.battery.show = false;
 
  PPosX = -(8*SpawnX)-4;                      //Convert Spawnpos to Worldpos
  PPosY = -(8*SpawnY)-8;

  //VelocityY = 45;
}

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);
  }
}

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

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

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;
      case 2:
        x1 = 0;
        y1 = 0;
        x2 = 7;
        y2 = 3;
        break;
      case 3:
        Value = 3;
        break;
      case 4:
        Value = 4;
      case 5:
        x1 = 0;
        y1 = 0;
        x2 = 4;
        y2 = 7;
        break;
      default:
        Value = 1;
  }

  if(Value == 0) {
    if(PICX == 0) {
      gb.popup(F("Code: 0"), 20);
    } else if(PICX == 1) {
      gb.popup(F("Code: 1"), 20);
    } else if(PICX == 2) {
      gb.popup(F("Code: 2"), 20);
    } else if(PICX == 3) {
      gb.popup(F("Code: 3"), 20);
    } else if(PICX == 4) {
      gb.popup(F("Code: 4"), 20);
    } else if(PICX == 5) {
      gb.popup(F("Code: 5"), 20);
    } else if(PICX == 6) {
      gb.popup(F("Code: 6"), 20);
    } else if(PICX == 7) {
      gb.popup(F("Code: 7"), 20);
    } else if(PICX == 8) {
      gb.popup(F("Code: 8"), 20);
    } else if(PICX == 9) {
      gb.popup(F("Code: 9"), 20);
    } else if(PICX == 10) {
      gb.popup(F("Code: 10"), 20);
    } else {
      if(PICY > 254) {
        gb.popup(F("else > 254"), 20);
      } else {
        gb.popup(F("else < 254"), 20);
      }
    }
    /*if(PICY >= 0) {
      gb.popup(F("True"), 20);
    } else {
      gb.popup(F("False"), 20);
    }*/
    if(-PICX>= x1 && -PICX <= x2 && -PICY>= y1 && -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 + 0) - (-(floor((PPosX + 5 + 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;
       }
     }
   }

   
    //working stuff V

   
   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))) , -(-(PPosY - 3 + yd) - (-(floor((PPosX - 3 + yd) / 8.0)))*8) , -(-(PPosY + 5 + 0) - (-(floor((PPosY + 5 + 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))) , -(-(PPosY - 3 + 0) - (-(floor((PPosX - 3 + yd) / 8.0)))*8) , -(-(PPosY - 4 + 0) - (-(floor((PPosY - 4 + 0) / 8.0)))*8));
        }
        for(int yd; yd < 8; yd++) {
          if(ColY[yd] == 1) {
            VelocityY = 0;
            GroundedDown = true;
          }
        }
      }
    }
}

void loop() {
  // put your main code here, to run repeatedly:
  if(gb.update()) {
      GroundedDown = false;
      GroundedRight = false;
      GroundedLeft = false;
   
      VelocityY = VelocityY - 3;
      VelocityX = VelocityX * 0.6f;

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

      CheckForCollider();

      if(gb.buttons.pressed(BTN_A) && GroundedDown)
        VelocityY = 66;

      if(gb.buttons.pressed(BTN_A) && GroundedRight) {
        VelocityX += 60;
        VelocityY = 56;
      }

      if(gb.buttons.pressed(BTN_A) && GroundedLeft) {
        VelocityX -= 60;
        VelocityY = 56;
      }
     
      PPosX += (float)VelocityX / (float)127 * 3;
      PPosY += (float)VelocityY / (float)127 * 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();
     
      for(byte x = 0; x < MapWidth; x++) {                                  //Draw maps
        for(byte y = 0; y < MapHeigth; y++) {                                           //< GetTile sould get the map based the current one loaded and not the first
          gb.display.drawBitmap(CPosX + x*8, CPosY + y*8, sprites[getTile(x,y)]);
        }
      }
  }
}
User avatar
STUDIOCRAFTapps
 
Posts: 86
Joined: Sun Oct 02, 2016 11:58 pm
Location: Deep in the web

Re: [WIP] BigBlackBox > Demo video

Postby naed » Sun Nov 13, 2016 7:52 pm

I tried your game and think the progress so far is very good...

Your code is a little advanced for me but I may take a look and see if I can help in any way at all

Keep up the good work
User avatar
naed
 
Posts: 140
Joined: Tue May 31, 2016 3:18 pm

Re: [WIP] BigBlackBox > Demo video

Postby STUDIOCRAFTapps » Sun Nov 13, 2016 7:58 pm

I've fixed the wall jumping and sliding stuff. When 'custom' colliding stuff will be fixed, all the colliding stuff and physics stuff will be done. That's a lot of stuff! ;)
User avatar
STUDIOCRAFTapps
 
Posts: 86
Joined: Sun Oct 02, 2016 11:58 pm
Location: Deep in the web

PreviousNext

Return to Project Guidance & Game development

Who is online

Users browsing this forum: No registered users and 17 guests

cron