#include <Backlight.h>
#include <Battery.h>
#include <Buttons.h>
#include <Display.h>
#include <Gamebuino.h>
#include <Sound.h>
#include <SPI.h>
#include <math.h>
Gamebuino gb;
const PROGMEM byte Empty[] = //ID: 0
{
8,8,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
};
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,
B00000000,
B01111110,
B00100100,
B00100100,
B01000010,
B00011000,
B01111110,
B00000000,
};
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: 8
{
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
byte MapHeigth = 9;
byte MapWidth = 13;
byte SpawnX = 8;
byte SpawnY = 7;
const byte* sprites[10] = {
Empty,
Brick,
SharpBrick,
TowerBrick,
Piston,
Holder,
Teleporter0,
Teleporter1,
Wall,
Ennemie
};
byte getTile(byte x, byte y){
/*if(x & 1)//odd
return pgm_read_byte(Map + y*(13) + x/2) & B00001111;
else //even
return (pgm_read_byte(Map + y*(9) + x/2) >> 4);*/
return pgm_read_byte(Map + (x+y*13));
}
int CPosX = 0;
int CPosY = 0;
int PPosX = 0;
int PPosY = 0;
byte SquiseVertical = 8;
byte SquiseHorizontal = 8;
void setup() {
// put your setup code here, to run once:
gb.begin();
gb.titleScreen(F("BIGBLACKBOX Testing"));
PPosX = 0;
PPosY = 8;
}
void DrawPlayer () {
gb.display.fillRect((PPosX - round(SquiseHorizontal/2.0) + LCDWIDTH/2) - CPosX, (PPosY - round(SquiseVertical/2.0) + LCDHEIGHT/2) - CPosY, SquiseHorizontal, SquiseVertical);
}
void ClampCamera () {
/*CPosX = PPosX + (LCDWidth/2);
CPosY = PPosY + (LCDHeight/2);
if(PPosX + (LCDWidth/2) < 0) {
CPosX = (LCDWidth/2);
} else {
//CPosX = PPosX - (LCDWidth/2);
}
if(PPosY + (LCDHeight/2) < 0) {
CPosY = (LCDHeight/2);
} else {
CPosY = PPosY - (LCDHeight/2);
}
if(PPosX - (LCDWidth/2) >= MapWidth) {
CPosX = MapWidth - (LCDWidth/2);
} else {
//CPosX = PPosX - (LCDWidth/2);
}
if(PPosY - (LCDHeight/2) >= MapHeigth) {
CPosY = MapWidth - (LCDHeight/2);
} else {
//CPosY = PPosY - (LCDHeight/2);
}
*/
//Minimum: 0,8
//Maximum: 8*MapWidth-LCDWidth,8*MapHeight-LCDHeight
CPosX = ClampInt(-(8*MapWidth-LCDWidth),0,PPosX);
CPosY = ClampInt(-(8*MapHeigth-LCDHeight),-8,PPosY);
//CPosX = -(8*MapWidth-LCDWidth);
//CPosY = -(8*MapHeigth-LCDHeight);
}
int ClampInt (int minv, int maxv, int value) {
if(value < minv)
return minv;
else if(value >= maxv)
return maxv;
else
return value;
}
void loop() {
// put your main code here, to run repeatedly:
if(gb.update()) {
if(gb.buttons.pressed(BTN_UP))
PPosY++;
if(gb.buttons.pressed(BTN_DOWN))
PPosY--;
if(gb.buttons.pressed(BTN_RIGHT))
PPosX--;
if(gb.buttons.pressed(BTN_LEFT))
PPosX++;
//CPosX = PPosX;
//CPosY = PPosY;
DrawPlayer();
ClampCamera();
for(byte x = 0; x < 13; x++) {
for(byte y = 0; y < 9; y++) {
byte Id;
Id = getTile(x,y);
gb.display.drawBitmap(CPosX + x*8, CPosY + y*8, sprites[Id]);
}
}
//gb.display.print(PPosX+", "+PPosY);
}
}
Const byte bitmap[] PROGMEM = { B00000000, B101010 etc
const byte *spritesheet[] = {brick, stone, etc }
Return to Programming Questions
Users browsing this forum: No registered users and 8 guests