Advice on general approaches or feasibility and discussions about game design
by STUDIOCRAFTapps » Sun Nov 13, 2016 8:03 pm
naed wrote: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
I hope you will enjoy it when it will be finish! I'm keeping up the developpement of this game but as i said, it will maybe slow down later because i have many other projects.
-
STUDIOCRAFTapps
-
- Posts: 86
- Joined: Sun Oct 02, 2016 11:58 pm
- Location: Deep in the web
by STUDIOCRAFTapps » Thu Nov 17, 2016 5:31 pm
I'm happy to say that BigBlackBox will be out around December 10th! I've though that i will be out after Chrismas but the game's development go really fast!
-
STUDIOCRAFTapps
-
- Posts: 86
- Joined: Sun Oct 02, 2016 11:58 pm
- Location: Deep in the web
by wuuff » Thu Nov 24, 2016 11:38 am
I played your current demo, and it's pretty cool! The player animation and level sprites look very good.
The game seems to run a bit slow. Is this intentional or do you plan to make it move more smoothly? I noticed you have the player's velocity set to a much higher value for precision that you scale down when you change the player's position, which seems like a good way to do physics. I have just now been working on a project with simple physics that I did similarly.
I might suggest that you could make the player position a one or 2-byte int and not a float, and then only convert the player position to an on-screen pixel position when you draw it. This avoids the need to use floats at all.
-
wuuff
-
- Posts: 61
- Joined: Sun Aug 28, 2016 6:05 am
by STUDIOCRAFTapps » Thu Nov 24, 2016 12:48 pm
Nice! Once the game will be finish i'll make a huge cleaning to the game's code. I wasn't able to see the fps drop because i don't have a gamebuino yet. Today, i'm going to publish a new developpement version, i've added ennemie and they probably eat my fps
. Thanks for testing the game!
-
STUDIOCRAFTapps
-
- Posts: 86
- Joined: Sun Oct 02, 2016 11:58 pm
- Location: Deep in the web
by STUDIOCRAFTapps » Thu Nov 24, 2016 1:07 pm
Hey, everyone! I've published a new testing version of my game, here's the new stuff:
- Enemies AI and spikes!
- Pistons and switch-walls!
- A cool new fresh map loader!
- Better wall jumping and sliding.
- Bounce effect when you're stuck in ground!
- Arrow and decoration stuff!
The 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;
byte Mode = 0;
byte NbrOfLevel = 3;
byte LevelsUnlock = 0;
byte MapCursor = 0;
byte EnnemieCount;
byte CurrentLoadedMap = 0;
byte Scroll = 0;
boolean PistonPressed = false;
/////////////////////////////////////
////Map stuf and sprite drawing V////
/////////////////////////////////////
const byte Map0Preview[] PROGMEM = {
2,0,0,
3,0,9,
2,1,1
};
const byte Map1Preview[] PROGMEM = {
2,0,0,
3,0,2,
0,0,3
};
const byte Map2Preview[] PROGMEM = {
0,0,2,
19,0,20,
10,12,11
};
const byte* MapsPreviews[3] = {
Map0Preview,
Map1Preview,
Map2Preview
};
const byte SpawnCoordX[] PROGMEM = {
9
};
const byte SpawnCoordY[] PROGMEM = {
2
};
const byte MapSizeX[] PROGMEM = {
13
};
const byte MapSizeY[] PROGMEM = {
9
};
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 EArrow1[]
{
8,8,
B00000000,
B01000000,
B01100000,
B01110000,
B01110000,
B01100000,
B01000000,
B00000000,
};
const PROGMEM byte EArrow2[]
{
8,8,
B00000000,
B00000010,
B00000110,
B00001110,
B00001110,
B00000110,
B00000010,
B00000000,
};
const PROGMEM byte ELocked[]
{
8,8,
B00000000,
B00110000,
B01001000,
B01111000,
B01111000,
B01111000,
B00000000,
B00000000,
};
const PROGMEM byte EUnLocked[]
{
8,8,
B00000000,
B00000110,
B00001001,
B01111000,
B01111000,
B01111000,
B00000000,
B00000000,
};
const PROGMEM byte Key[] = //ID: 19
{
8,8,
B00000000,
B00000110,
B00001111,
B11111101,
B10101111,
B00000110,
B00000000,
B00000000,
};
const PROGMEM byte LockedBlock[] = //ID: 20
{
8,8,
B01111110,
B11011111,
B10100011,
B10100011,
B11110111,
B10110111,
B11110111,
B01111110,
};
const PROGMEM byte Empty[] = //ID: 0
{
8,8,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
};
const PROGMEM byte Missing[]
{
8,8,
B10101010,
B00000001,
B10000000,
B00000001,
B10000000,
B00000001,
B10000000,
B01010101,
};
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,
B10011001,
B01100110,
B10011001,
B01100110,
B10011001,
B01100110,
B10011001,
};
const PROGMEM byte Window[] = //ID: 13
{
8,8,
B11111111,
B10000001,
B10000001,
B10000001,
B10000001,
B10000001,
B10000001,
B11111111,
};
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,
B00111100,
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,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
};
const PROGMEM byte EnnemieSprite[]=
{
8,8,
B11111111,
B10000001,
B10010011,
B10010011,
B10000001,
B10000001,
B10000001,
B11111111,
};
const PROGMEM byte EnnemieSprite1[]=
{
8,8,
B11111111,
B10000001,
B11001001,
B11001001,
B10000001,
B10000001,
B10000001,
B11111111,
};
const PROGMEM byte Table[] = //ID: 14
{
8,8,
B11111111,
B10000001,
B10111101,
B10100101,
B10100101,
B10100101,
B10100101,
B11100111,
};
const PROGMEM byte PistonExtension[] = //ID: 15
{
8,8,
B11100111,
B10011001,
B11100111,
B10011001,
B11100111,
B10011001,
B11100111,
B10011001,
};
const PROGMEM byte Arrow1[]= //ID: 16
{
8,8,
B11111110,
B10010100,
B10111000,
B11111100,
B10111110,
B11011111,
B10001111,
B00000110,
};
const PROGMEM byte Arrow2[]= //ID: 17
{
8,8,
B01111111,
B00101111,
B00010111,
B00101111,
B01011111,
B10111011,
B11110001,
B01100000,
};
const PROGMEM byte PlantPot[] = //ID: 18
{
8,8,
B00000000,
B00101000,
B00010100,
B00001000,
B00010000,
B00111100,
B00111100,
B00011000,
};
const PROGMEM byte Spike[] = //ID: 21
{
8,8,
B00000000,
B00100010,
B00100010,
B01010101,
B01010101,
B10001000,
B10101010,
B10101010,
};
const byte Map0[] PROGMEM = {
0,0,0,0,0,0,0,0,0,0,0,0,2,
2,1,2,5,5,0,0,0,0,0,0,0,6,
3,0,0,0,0,0,4,5,2,0,0,0,2,
3,0,2,0,16,0,15,0,0,0,0,0,3,
2,0,8,0,0,0,15,18,0,0,0,0,3,
3,0,8,0,17,0,15,14,0,0,0,0,3,
3,0,8,0,0,0,2,5,5,0,5,5,2,
3,0,8,0,9,0,3,0,9,0,0,0,6,
2,21,2,1,1,1,2,1,1,1,1,1,2,
};
const byte* Maps[1] = {
Map0
};
//////////////////////////////////////////////
////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 = 9;
byte MapWidth = 13;
boolean GoingRight = true;
boolean GroundedDown = false;
boolean GroundedRight = false;
boolean GroundedLeft = false;
boolean IsPlaying = false;
/////////////////////
////Block Setup V////
/////////////////////
const byte* sprites[22] = {
Empty,
Brick,
SharpBrick,
TowerBrick,
Piston,
Holder,
Teleporter0,
Teleporter1,
Wall,
Ennemie,
GroundLeft,
GroundRight,
GroundMiddle,
Window,
Table,
PistonExtension,
Arrow1,
Arrow2,
PlantPot,
Key,
LockedBlock,
Spike
};
const byte* coltype[22] = { //0 = empty 1 = block
0,
1,
1,
1,
9,
2, //2
3,
4,
5, //5
0,
1,
1,
1,
0,
0,
6,
0,
0,
0,
7,
8,
10
};
//////////////////////////////
////GetTile & Var initi. V////
//////////////////////////////
byte getTile(byte x, byte y){
return pgm_read_byte(Maps[CurrentLoadedMap] + (x+y*MapWidth));
}
byte getPreviewTile(byte x, byte y){
return pgm_read_byte(MapsPreviews[MapCursor] + (x+y*3));
//return MapsPreviews[MapCursor][(x+y*MapWidth)];
}
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;
///////////////////
////EnnemieAi V////
///////////////////
class EnnemieAI {
private:
byte PosX;
byte PosY;
byte Progress = 0;
boolean GoRight = true;
boolean Pre = false;
void ChangeDirection () {
GoRight = !GoRight;
}
bool SimplePixInColl (byte PIMX, byte PIMY) { //PIM = Pos in map (0-255), PIC = Pos in cube (0-8)
byte GlobalColiderType = coltype[getTile(PIMX,PIMY)];
if(GlobalColiderType == 0) {
return false;
} else if(GlobalColiderType == 1) {
return true;
} else {
return true;
}
}
public:
void DefinePos (byte PositionX, byte PositionY) {
PosX = PositionX;
PosY = PositionY;
}
byte GetPosX () {
return PosX;
}
byte GetPosY () {
return PosY;
}
boolean GetDirection () {
return GoRight;
}
void update () {
if(Progress > 3) {
Progress = 0;
} else {
Progress++;
if(GoRight) {
if(!SimplePixInColl((floor((PosX + 5) / 8.0)) , (floor((PosY + 3) / 8.0)))) {
PosX++;
} else {
ChangeDirection();
}
}
if(!GoRight) {
if(!SimplePixInColl((floor((PosX - 4) / 8.0)) , (floor((PosY + 3) / 8.0)))) {
PosX--;
} else {
ChangeDirection();
}
}
}
Pre = false;
byte ColY[8];
for(int yd; yd < 8; yd++) { //yd = Y Down
ColY[yd] = SimplePixInColl((floor((PosX - 3 + yd) / 8.0)) , (floor((PosY + /*4*/4 + 0) / 8.0)));
}
for(int yd; yd < 8; yd++) {
if(ColY[yd] == 1) {
Pre = true;
break;
}
}
if(!Pre) {
PosY++;
}
}
};
EnnemieAI* ennemieArray;
///////////////////////////////
////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;
PPosX = -(8*SpawnCoordX[CurrentLoadedMap])-4; //Convert Spawnpos to Worldpos
PPosY = -(8*SpawnCoordY[CurrentLoadedMap])-8;
}
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
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;
}
///////////////////
////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;
case 2:
x1 = 1;
y1 = 0;
x2 = 6;
y2 = 3;
break;
case 3:
Value = 3;
break;
case 4:
Value = 4;
case 5:
x1 = 0;
y1 = 0;
x2 = 4;
y2 = 7;
break;
case 6:
if(PistonPressed) {
x1 = 0;
y1 = 0;
x2 = 7;
y2 = 7;
} else {
Value = 1;
}
break;
case 9:
x1 = 0;
y1 = 0;
x2 = 7;
y2 = 7;
PistonPressed = true;
break;
case 10:
x1 = 0;
y1 = 0;
x2 = 7;
y2 = 7;
Die();
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;
}
}
}
//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/*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])-4;
PPosY = -(8*SpawnCoordY[CurrentLoadedMap])-8;
VelocityX = 0;
VelocityY = 0;
PistonPressed = false;
IsPlaying = true;
MapWidth = MapSizeX[CurrentLoadedMap];
MapHeigth = MapSizeY[CurrentLoadedMap];
byte EnnemieC = 0;
for(byte x = 0; x < MapWidth; x++) { //Draw maps
for(byte y = 0; y < MapHeigth; y++) {
if(getTile(x,y)==9) {
EnnemieC++;
}
}
}
EnnemieCount = EnnemieC;
ennemieArray = new EnnemieAI[EnnemieCount];
int i = 0;
for(byte x = 0; x < MapWidth; x++) { //Draw maps
for(byte y = 0; y < MapHeigth; y++) {
if(getTile(x,y)==9) {
ennemieArray[i].DefinePos(x*8+0,y*8+0);
i++;
}
}
}
}
//////////////////
////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) || inRay(r,r+8,v+8);
}
void loop() {
// put your main code here, to run repeatedly:
if(gb.update()) {
if(IsPlaying) {
GroundedDown = false;
GroundedRight = false;
GroundedLeft = false;
if(!(gb.buttons.timeHeld(BTN_RIGHT) > 0) && !(gb.buttons.timeHeld(BTN_LEFT) > 0)) {
VelocityX = VelocityX * 0.6f;
}
VelocityY = VelocityY - 3;
if(gb.buttons.timeHeld(BTN_RIGHT) > 0) {
if(VelocityX - 4 > -30) {
VelocityX -= 4;
}
GoingRight = true;
}
if(gb.buttons.timeHeld(BTN_LEFT) > 0) {
if(VelocityX + 4 < 30) {
VelocityX += 4;
}
GoingRight = false;
}
CheckForCollider();
if(gb.buttons.pressed(BTN_A) && GroundedDown)
VelocityY = 66;
if(gb.buttons.pressed(BTN_A) && GroundedRight && !GroundedDown) {
VelocityX = 60;
VelocityY = 56;
}
if(gb.buttons.pressed(BTN_A) && GroundedLeft && !GroundedDown) {
VelocityX = -60;
VelocityY = 56;
}
if(gb.buttons.pressed(BTN_C)) {
IsPlaying = false;
SelectMap();
}
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 c = 0; c < EnnemieCount; c++) {
ennemieArray[c].update();
if(ennemieArray[c].GetDirection()) {
gb.display.drawBitmap(CPosX + ennemieArray[c].GetPosX() - 4, CPosY + ennemieArray[c].GetPosY() - 4, EnnemieSprite);
} else {
gb.display.drawBitmap(CPosX + ennemieArray[c].GetPosX() - 4, CPosY + ennemieArray[c].GetPosY() - 4, EnnemieSprite1);
}
if(inRange(ennemieArray[c].GetPosX() - 4, -PPosX) && inRange(ennemieArray[c].GetPosY() - 4, -PPosY)) {
Die();
}
}
for(byte x = 0; x < MapWidth; x++) { //Draw maps
for(byte y = 0; y < MapHeigth; y++) {
if(getTile(x,y) == 15) {
if(PistonPressed) {
gb.display.drawBitmap(CPosX + x*8, CPosY + y*8, sprites[15]);
} else {
gb.display.drawBitmap(CPosX + x*8, CPosY + y*8, Missing);
}
} else {
gb.display.drawBitmap(CPosX + x*8, CPosY + y*8, sprites[getTile(x,y)]);
}
}
}
} else {
if(Mode == 0) {
SelectMap();
} else if(Mode == 1) {
for(byte x = 0; x < 3; x++) {
for(byte y = 0; y < 3; y++) {
if(getPreviewTile(x,y) == 9) {
gb.display.drawBitmap(30 + x*8, 12 + y*8, EnnemieSprite);
} else {
gb.display.drawBitmap(30 + x*8, 12 + y*8, sprites[getPreviewTile(x,y)]);
}
}
}
if(MapCursor <= LevelsUnlock) {
gb.display.drawBitmap(0,0,EUnLocked);
if(gb.buttons.pressed(BTN_A)) {
CurrentLoadedMap = MapCursor;
IsPlaying = true;
PrepareMap();
}
} else {
gb.display.drawBitmap(0,0,ELocked);
}
if(MapCursor - 1 >= 0) {
gb.display.drawBitmap(0,20,EArrow2);
if(gb.buttons.pressed(BTN_LEFT)) {
MapCursor--;
}
}
if(MapCursor + 1 < NbrOfLevel) {
gb.display.drawBitmap(76,20,EArrow1);
if(gb.buttons.pressed(BTN_RIGHT)) {
MapCursor++;
}
}
if(gb.buttons.pressed(BTN_C)) {
IsPlaying = false;
gb.begin();
gb.titleScreen(F("v1.0"),Logo);
gb.battery.show = false;
}
} else if(Mode == 2) {
if(Scroll < 13) {
Scroll++;
}
gb.display.fontSize = 2;
gb.display.cursorX = 2;
gb.display.cursorY = (-10+Scroll);
gb.display.print(F("Blackout!"));
gb.display.fontSize = 1;
gb.display.cursorX = 2;
gb.display.cursorY = (18+(Scroll*0.5f));
gb.display.print(F("Press A to continue"));
if(gb.buttons.pressed(BTN_A)) {
SelectMap();
}
}
}
}
}
void SelectMap () {
IsPlaying = false;
Mode = 1;
}
void Die () {
IsPlaying = false;
Mode = 2;
Scroll = 0;
}
'Hope you like it! I've not added the end of the level yet, it's the spike for now.
- Attachments
-
- BIGBBOX.HEX.zip
- BIG BLACK BOX
- (18.17 KiB) Downloaded 300 times
-
STUDIOCRAFTapps
-
- Posts: 86
- Joined: Sun Oct 02, 2016 11:58 pm
- Location: Deep in the web
-
STUDIOCRAFTapps
-
- Posts: 86
- Joined: Sun Oct 02, 2016 11:58 pm
- Location: Deep in the web
Return to Project Guidance & Game development
Who is online
Users browsing this forum: No registered users and 8 guests