Post by henriqueasb on Aug 10, 2017 5:13:49 GMT -8
I am doing a project of a simple game a maze using the gameduino one and an arduino one use a simulator in the simulator the project is ready porem when I was portar to the plate did not work it compiles normal but when recording does not work
The problem is not hardware posi other projects work normally would like help to finish this
the cod is here sory de notes in portuguese i am brazilian
The problem is not hardware posi other projects work normally would like help to finish this
the cod is here sory de notes in portuguese i am brazilian
#include <Keypad.h>
#include <SPI.h>
#include <GD.h>
#include "image.h"
#include "sprite.h"
#define SOUNDCYCLE(state) ((state) = v ? ((state) + 1) : 0)
#define P1_LEFT bitMap[0]&1
#define P1_UP bitMap[0]&2
#define P1_DOWN bitMap[0]&4
#define P1_RIGHT bitMap[0]&8
#define P2_LEFT bitMap[1]&1
#define P2_DOWN bitMap[1]&2
#define P2_UP bitMap[1]&4
#define P2_RIGHT bitMap[1]&8
#define P1_B4 bitMap[2]&1
#define P1_B1 bitMap[2]&2
#define P1_B3 bitMap[2]&4
#define P1_B2 bitMap[2]&8
#define P2_B4 bitMap[3]&1
#define P2_B1 bitMap[3]&2
#define P2_B3 bitMap[3]&4
#define P2_B2 bitMap[3]&8
//PINOS NO ARDUINO
#define ROW0 0 //FIO VERDE
#define ROW1 1 //FIO VERMELHO
#define ROW2 2 //FIO ROXO
#define ROW3 3 //FIO OU MARRINZA
#define COL0 4 //FIO VERDE - JOYSTICK LEFT
#define COL1 5 //FIO AMARELO - JOYSTICK UP
#define COL2 6 //FIO PRETO - JOYSTICK DOWN
#define COL3 7 // FIO LARANJA - JOYSTICK RIGHT
char previousPressedKey;
boolean hasReleasedKey = false;
const byte ROWS = 4 ; // Four rows
const byte COLS = 4; // Three columns
byte rowPins[ROWS] = {ROW0,ROW1,ROW2, ROW3};
byte colPins[COLS] = {COL0, COL1, COL2, COL3};
char keys[ROWS][COLS]={
{'0','1','2','3'},
{'4','5','6','7'},
{'8','9','A','B'},
{'C','D','E','F'},
};
Keypad player = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
// -----------------------------> Colis�o <------------------------
void readn(byte *dst, unsigned int addr, int c)
{
GD.__start(addr);
while (c--)
*dst++ = SPI.transfer(0);
GD.__end();
}
static byte coll[256];
static void load_coll()
{
readn(coll, COLLISION, sizeof(coll));
}
long lastAnimTime = 0;
int animTime = 250;
// -----------------------------> Biblioteca de Controles de Teclado <------------------------
static void controller_init() {
// Configure input pins with internal pullups
byte i;
for (i = 2; i < 7; i++) {
pinMode(i, INPUT);
digitalWrite(i, HIGH);
}
// Drive pin 7 low
pinMode(7, OUTPUT);
digitalWrite(7, 0);
}
#define CONTROL_LEFT 1
#define CONTROL_RIGHT 2
#define CONTROL_UP 4
#define CONTROL_DOWN 8
#define CONTROL_SPACE 32
static byte controller_sense() {
byte r = 0;
if (!digitalRead(2))
r |= CONTROL_SPACE;
if (!digitalRead(3))
r |= CONTROL_RIGHT;
if (!digitalRead(5))
r |= CONTROL_DOWN;
if (!digitalRead(4))
r |= CONTROL_UP;
if (!digitalRead(6))
r |= CONTROL_LEFT;
return r;
}
// -----------------------------> Declara��o das sprites <------------------------
class Time2 {
public:
int x, y, rot, anim;
Time2();
};
class Bola {
public:
int x, y, rot, anim;
Bola();
};
Time2::Time2()
{
this->x = 343;
this->y = 150;
this->anim = 1;
this->rot = 2;
}
Bola::Bola()
{
this->x = 390; //200
this->y = 290; //150
this->anim = 0;
this->rot = 0;
}
// Declara��o dos parametros das sprites
Time2 time2;
Bola bola;
/* ###########-----------------------> void setup <------------------------########### */
void setup()
{
controller_init();
GD.ascii();
GD.begin();
// -----------------------------> Declara��o das sprites <--------------------------
GD.copy(RAM_SPRPAL, sprite_sprpal, sizeof(sprite_sprpal));
GD.copy(RAM_SPRIMG, sprite_sprimg, sizeof(sprite_sprimg));
// -----------------------------> Declara��o do background <------------------------
for (byte y = 0; y < 3; y++)
GD.copy(RAM_PIC + y * 64, image_pic + y * 3, 3);
GD.uncompress(RAM_CHR, image_chr);
GD.uncompress(RAM_PAL, image_pal);
}
boolean checaColisao()
{
for (int k = 0; k < 255; k++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0,1,1,1,1,1,0,0 },
{ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0 },
};
for (int i = 0; i<18; i++) {
for (int j = 0; j<24; j++)
if (m[j]) {
draw_sprites(j+(j*16), i+(i * 16), time2.anim, time2.rot);
}
}
GD.__end();
}
/* ###########-----------------------> void loop <------------------------########### */
void loop()
{
char key = player.getKey();
//byte player = controller_sense();
//if (player & CONTROL_RIGHT) {
if (player.P1_RIGHT) {
bola.x++;
}
//if (player & CONTROL_LEFT) {
if (player.P1_LEFT) {
bola.x--;
}
if (player.P1_DOWN) {
bola.y++;
}
if (player.P1_UP) {
bola.y--;
}
load_coll();
mostraSprite();
}
#include <SPI.h>
#include <GD.h>
#include "image.h"
#include "sprite.h"
#define SOUNDCYCLE(state) ((state) = v ? ((state) + 1) : 0)
#define P1_LEFT bitMap[0]&1
#define P1_UP bitMap[0]&2
#define P1_DOWN bitMap[0]&4
#define P1_RIGHT bitMap[0]&8
#define P2_LEFT bitMap[1]&1
#define P2_DOWN bitMap[1]&2
#define P2_UP bitMap[1]&4
#define P2_RIGHT bitMap[1]&8
#define P1_B4 bitMap[2]&1
#define P1_B1 bitMap[2]&2
#define P1_B3 bitMap[2]&4
#define P1_B2 bitMap[2]&8
#define P2_B4 bitMap[3]&1
#define P2_B1 bitMap[3]&2
#define P2_B3 bitMap[3]&4
#define P2_B2 bitMap[3]&8
//PINOS NO ARDUINO
#define ROW0 0 //FIO VERDE
#define ROW1 1 //FIO VERMELHO
#define ROW2 2 //FIO ROXO
#define ROW3 3 //FIO OU MARRINZA
#define COL0 4 //FIO VERDE - JOYSTICK LEFT
#define COL1 5 //FIO AMARELO - JOYSTICK UP
#define COL2 6 //FIO PRETO - JOYSTICK DOWN
#define COL3 7 // FIO LARANJA - JOYSTICK RIGHT
char previousPressedKey;
boolean hasReleasedKey = false;
const byte ROWS = 4 ; // Four rows
const byte COLS = 4; // Three columns
byte rowPins[ROWS] = {ROW0,ROW1,ROW2, ROW3};
byte colPins[COLS] = {COL0, COL1, COL2, COL3};
char keys[ROWS][COLS]={
{'0','1','2','3'},
{'4','5','6','7'},
{'8','9','A','B'},
{'C','D','E','F'},
};
Keypad player = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
// -----------------------------> Colis�o <------------------------
void readn(byte *dst, unsigned int addr, int c)
{
GD.__start(addr);
while (c--)
*dst++ = SPI.transfer(0);
GD.__end();
}
static byte coll[256];
static void load_coll()
{
readn(coll, COLLISION, sizeof(coll));
}
long lastAnimTime = 0;
int animTime = 250;
// -----------------------------> Biblioteca de Controles de Teclado <------------------------
static void controller_init() {
// Configure input pins with internal pullups
byte i;
for (i = 2; i < 7; i++) {
pinMode(i, INPUT);
digitalWrite(i, HIGH);
}
// Drive pin 7 low
pinMode(7, OUTPUT);
digitalWrite(7, 0);
}
#define CONTROL_LEFT 1
#define CONTROL_RIGHT 2
#define CONTROL_UP 4
#define CONTROL_DOWN 8
#define CONTROL_SPACE 32
static byte controller_sense() {
byte r = 0;
if (!digitalRead(2))
r |= CONTROL_SPACE;
if (!digitalRead(3))
r |= CONTROL_RIGHT;
if (!digitalRead(5))
r |= CONTROL_DOWN;
if (!digitalRead(4))
r |= CONTROL_UP;
if (!digitalRead(6))
r |= CONTROL_LEFT;
return r;
}
// -----------------------------> Declara��o das sprites <------------------------
class Time2 {
public:
int x, y, rot, anim;
Time2();
};
class Bola {
public:
int x, y, rot, anim;
Bola();
};
Time2::Time2()
{
this->x = 343;
this->y = 150;
this->anim = 1;
this->rot = 2;
}
Bola::Bola()
{
this->x = 390; //200
this->y = 290; //150
this->anim = 0;
this->rot = 0;
}
// Declara��o dos parametros das sprites
Time2 time2;
Bola bola;
/* ###########-----------------------> void setup <------------------------########### */
void setup()
{
controller_init();
GD.ascii();
GD.begin();
// -----------------------------> Declara��o das sprites <--------------------------
GD.copy(RAM_SPRPAL, sprite_sprpal, sizeof(sprite_sprpal));
GD.copy(RAM_SPRIMG, sprite_sprimg, sizeof(sprite_sprimg));
// -----------------------------> Declara��o do background <------------------------
for (byte y = 0; y < 3; y++)
GD.copy(RAM_PIC + y * 64, image_pic + y * 3, 3);
GD.uncompress(RAM_CHR, image_chr);
GD.uncompress(RAM_PAL, image_pal);
}
boolean checaColisao()
{
for (int k = 0; k < 255; k++)
{
if (coll[k] != 0xFF)
{
return true;
}
}
return false;
}
void mostraSprite()
{
GD.waitvblank();
GD.__wstartspr(0);
if (checaColisao()) {
bola.x = 10;
bola.y = 10;
}
draw_sprites(bola.x , bola.y, bola.anim, bola.rot);
int m[18][24] =
{
{ 0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 },
{ 0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,1,0,0,0,0,0,0,0,1 },
{ 1,0,1,1,0,1,1,1,1,0,0,0,0,1,1,1,0,1,1,0,1,1,1,1 },
{ 1,0,1,0,0,1,0,1,1,1,1,1,1,1,0,0,0,0,1,0,1,1,0,1 },
{ 1,0,1,0,1,1,0,1,1,0,1,1,1,0,0,1,1,0,1,0,0,1,0,1 },
{ 1,0,1,0,0,1,0,0,0,0,0,0,1,0,1,1,0,0,1,1,0,1,0,1 },
{ 1,0,1,1,0,1,1,1,1,0,1,0,1,0,1,0,0,0,0,1,0,1,0,1 },
{ 1,0,0,0,0,1,0,0,0,0,1,0,1,0,1,0,1,1,0,1,0,1,0,1 },
{ 1,0,1,1,1,1,0,1,1,0,1,0,1,0,1,0,1,1,0,1,0,0,0,1 },
{ 1,0,0,0,1,1,0,0,1,0,1,0,1,0,1,0,1,1,0,1,0,1,0,1 },
{ 1,1,1,0,1,1,0,0,1,0,1,0,1,0,1,0,1,1,0,1,0,1,0,1 },
{ 1,0,1,0,1,1,0,0,1,0,1,0,1,0,1,0,1,1,0,1,0,1,0,1 },
{ 1,0,1,0,1,1,0,0,1,0,1,0,1,0,1,0,1,1,0,1,0,1,0,1 },
{ 1,0,1,0,0,1,0,0,1,0,1,0,1,0,1,0,1,1,0,1,0,1,0,1 },
{ 1,0,1,1,0,1,0,0,1,0,1,0,0,0,1,0,1,0,0,1,1,1,0,1 },
{ 1,0,0,1,0,1,1,1,1,0,1,1,1,1,1,0,1,0,0,0,0,1,0,1 },
{ 1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0 },
{ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0 },
};
for (int i = 0; i<18; i++) {
for (int j = 0; j<24; j++)
if (m[j]) {
draw_sprites(j+(j*16), i+(i * 16), time2.anim, time2.rot);
}
}
GD.__end();
}
/* ###########-----------------------> void loop <------------------------########### */
void loop()
{
char key = player.getKey();
//byte player = controller_sense();
//if (player & CONTROL_RIGHT) {
if (player.P1_RIGHT) {
bola.x++;
}
//if (player & CONTROL_LEFT) {
if (player.P1_LEFT) {
bola.x--;
}
if (player.P1_DOWN) {
bola.y++;
}
if (player.P1_UP) {
bola.y--;
}
load_coll();
mostraSprite();
}