[SOLVED]C_Controls example error
Posted: Fri Jan 13, 2017 1:36 am
I've been doing the examples, and just got to the controls one. it compiles perfectly and everything, but when I try to run it on my gamebuino no matter what button I hit, the ball goes completely dow the screen, and then the next button I hit goes to the left corner. When the ball is there, I can move it one pixel to the right and back again. I checked my code, and everything seems in order.
also, I was fiddling around with the code and changed the
to
but that didnt change anything
I know it's just an example, but if i did something wrong I would like to know so that I do not do it again when I am trying to make a real game
- Code: Select all
#include <SPI.h>
#include <Gamebuino.h>
Gamebuino gb;
int ball_x = LCDWIDTH/2;
int ball_y = LCDHEIGHT/2;
int ball_vx = 1;
int ball_vy = 1;
int ball_size = 6;
void setup() {
// put your setup code here, to run once:
gb.begin();
gb.titleScreen(F("Ball Control"));
}
void loop() {
// put your main code here, to run repeatedly:
if(gb.update());{
if(gb.buttons.pressed(BTN_RIGHT)){
ball_x = ball_x = ball_vx;
gb.sound.playTick();
}
if(gb.buttons.pressed(BTN_LEFT)){
ball_x = ball_x - ball_vx;
gb.sound.playTick();
}
if(gb.buttons.pressed(BTN_DOWN)){
ball_y = ball_y + ball_vy;
gb.sound.playTick();
}
if(gb.buttons.pressed(BTN_UP)){
ball_y = ball_y + ball_vy;
gb.sound.playTick();
}
if(gb.buttons.pressed(BTN_A)){
gb.sound.playOK();
}
if(gb.buttons.pressed(BTN_B)){
gb.sound.playCancel();
}
if(gb.buttons.pressed(BTN_C)){
gb.titleScreen(F("Ball Control"));
}
if(ball_x < 0){
ball_x = 0;
}
if((ball_x + ball_size) > LCDWIDTH){
ball_x = LCDWIDTH - ball_size;
}
if(ball_y < 0){
ball_y = 0;
}
if((ball_y + ball_size) > LCDHEIGHT){
ball_y = LCDHEIGHT - ball_size;
}
gb.display.fillRect(ball_x, ball_y, ball_size, ball_size);
}
}
also, I was fiddling around with the code and changed the
- Code: Select all
if(gb.buttons.repeat(BTN_RIGHT,2)){
ball_x = ball_x + ball_vx;
gb.sound.playTick();
}
if(gb.buttons.repeat(BTN_LEFT,2)){
ball_x = ball_x - ball_vx;
gb.sound.playTick();
}
if(gb.buttons.repeat(BTN_DOWN,2)){
ball_y = ball_y + ball_vy;
gb.sound.playTick();
}
if(gb.buttons.repeat(BTN_UP,2)){
ball_y = ball_y - ball_vy;
gb.sound.playTick();
}
to
- Code: Select all
if(gb.buttons.pressed(BTN_RIGHT)){
ball_x = ball_x = ball_vx;
gb.sound.playTick();
}
if(gb.buttons.pressed(BTN_LEFT)){
ball_x = ball_x - ball_vx;
gb.sound.playTick();
}
if(gb.buttons.pressed(BTN_DOWN)){
ball_y = ball_y + ball_vy;
gb.sound.playTick();
}
if(gb.buttons.pressed(BTN_UP)){
ball_y = ball_y + ball_vy;
gb.sound.playTick();
}
but that didnt change anything
I know it's just an example, but if i did something wrong I would like to know so that I do not do it again when I am trying to make a real game