I wrote a function for the shooting but when it's time to play the game doesn't render the bullet but a line, why?
(sorry for my english )
- Code: Select all
#include <SPI.h>
#include <Gamebuino.h>
Gamebuino gb;
//game vars
int x=LCDWIDTH/2; //start position
int y=LCDHEIGHT/2;
int vx=1; //velocity
int vy=1;
int size=8; //size of the bitmap
byte rotation=NOROT; //start rotation
byte flip=NOFLIP;
static unsigned char PROGMEM tank[] = {
8,8,
B00010000,
B11010110,
B01111100,
B11010110,
B01010100,
B11000110,
B01111100,
B11111110,
}; //tank bitmap
void setup()
{
gb.begin();
gb.titleScreen(F("Tankduino"));
}
void loop()
{
if(gb.update()){
//move the ball using the buttons
if(gb.buttons.repeat(BTN_RIGHT,2)){
x = x + vx;
rotation = ROTCW;
}
if(gb.buttons.repeat(BTN_LEFT,2)){
x = x - vx;
rotation = ROTCCW;
}
if(gb.buttons.repeat(BTN_DOWN,2)){
y = y + vy;
rotation = ROT180;
}
if(gb.buttons.repeat(BTN_UP,2)){
y = y - vy;
rotation = NOROT;
}
if(gb.buttons.pressed(BTN_A)){
shoot(x,y,rotation);
}
if(gb.buttons.pressed(BTN_C)){
gb.titleScreen(F("GameDuino"));
}
//frame
if(x<0){
x=0;
}
if((x+size)>LCDWIDTH){
x=LCDWIDTH-size;
}
if(y<0){
y=0;
}
if((y+size)>LCDHEIGHT){
y=LCDHEIGHT-size;
}
//draw the tank and the frame
gb.display.drawBitmap(x, y,tank,rotation,flip);
gb.display.drawLine(0, 0, LCDWIDTH, 0);
gb.display.drawLine(0, 0, 0, LCDHEIGHT);
gb.display.drawLine(0, LCDHEIGHT-1, LCDWIDTH, LCDHEIGHT-1);
gb.display.drawLine(LCDWIDTH-1, 0, LCDWIDTH-1, LCDHEIGHT);
}}
void shoot(int x, int y, int rot){
int i=0;
switch(rot){
case NOROT:
while(i< LCDHEIGHT){
gb.display.drawPixel(x+3,y-i);
i++;
}
break;
case ROTCW:
while(i<LCDWIDTH){
gb.display.drawPixel(x+i,y+3);
i++;
}
break;
case ROT180:
while(i<LCDHEIGHT){
gb.display.drawPixel(x+4,y+i);
i++;
}
break;
case ROTCCW:
while(i<LCDWIDTH){
gb.display.drawPixel(x-i,y+4);
i++;
}
break;
}
}