[FR] probleme de position

Understanding the language, error messages, etc.

[FR] probleme de position

Postby Flix » Sat Jan 31, 2015 10:58 pm

bonjour

je suis en train de faire un jeux qui ressemble a (le jeux le plus dur au monde) et j'ai un probleme avec mais variable. Dans mon code j'ai fais un "void initGame(){position des variables}"

pour une raison inconu, les variable que jai donner du x y sont pas respecté. celon moi, le problem et du au fait que la varible n'est pas a jour ou
que le "void intiGame" n'est pas dans le "void loop" ou un truc du jar. Mais je suis presque sur que le problem et trés simple mais je n'arrive pas a le trouver. :D


Code: Select all
#include <SPI.h>
#include <Gamebuino.h>
Gamebuino gb;

//declare all the variables needed for the game :
int ball_x = LCDWIDTH/2; //set the horizontal position to the middle of the screen
int ball_y = LCDHEIGHT/2; //vertical position
int ball_vx = 1; //horizontal velocity
int ball_vy = 1; //vertical velocity
int ball_size = 3;

static unsigned char PROGMEM carre[] =
{
  8, 6,
  B00000000,
  B00111100,
  B00100100,
  B00100100,
  B00111100,
  B00000000,
};

int carre_x, carre_y;


// the setup
void setup(){
  gb.begin();
  gb.titleScreen(F("Hard Cube"));
  gb.popup(F("Test"),100);
}


void loop(){
  if(gb.update()){
       
    skyNet();
   
    drawcarre();
   
    if(gb.collideRectRect(ball_x, ball_y, 7, 7, 0, 0, 8, 48)){
      ball_x = ball_x + 1;
    }
   
    if(gb.collideRectRect(ball_x, ball_y, 0, 0, 63, 10, 2, 36)){
      ball_x = ball_x + 1;
    }
     if(gb.collideRectRect(ball_x, ball_y, 0, 0, 30, 10, 2, 36)){
      ball_x = ball_x - 1;
    }
     if(gb.collideRectRect(ball_x, ball_y, 0, 0, 30, 9, 35, 2)){
      ball_y = ball_y - 1;
    }
           
    //move the ball using the buttons
    if(gb.buttons.repeat(BTN_RIGHT,1)){ //every 2 frames when the right button is held down
      ball_x = ball_x + ball_vx; //increase the horizontal position by the ball's velocity
      //gb.sound.playTick(); //play a preset "tick" sound every time the button is pressed
    }
    if(gb.buttons.repeat(BTN_LEFT,1)){
      ball_x = ball_x - ball_vx;
    }
    if(gb.buttons.repeat(BTN_DOWN,1)){
      ball_y = ball_y + ball_vy;
    }
    if(gb.buttons.repeat(BTN_UP,1)){
      ball_y = ball_y - ball_vy;
    }
    //bonus : play a preset sound when A and B are pressed
    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("Hard Cube"));
    }
   
    //check that the ball is not going out of the screen
    //if the ball is touching the left side of the screen
    if(ball_x < 0){
      //bring it back in the screen
      ball_x = 0;
    }
    //if the ball is touching the right side
    if((ball_x + ball_size) > LCDWIDTH){
      ball_x = LCDWIDTH - ball_size;
    }
    //if the ball is touching the top side
    if(ball_y < 0){
      ball_y = 0;
    }
    //if the ball is touching the down side
    if((ball_y + ball_size) > LCDHEIGHT){
      ball_y = LCDHEIGHT - ball_size;
    }
       
    //gb draw
    gb.display.fillRect(ball_x, ball_y, ball_size, ball_size);
    gb.display.print(ball_x);
    gb.display.print("_");
    gb.display.print(ball_y);
     gb.display.drawRect(33, 12, 32, 36);
    gb.display.drawRect(0, 0, 8, 48);
    gb.display.drawRect(7, 0, 77, 48);
  }
}
// dessine carre
void drawcarre()
{
  gb.display.drawBitmap(carre_x,carre_y,carre);
}

// posotion des variables !(il sont ignore)!//
void initGame()
{
  carre_x = 18;
  carre_y = 0;
  //----------------//
  ball_x = 18;
  ball_y = 38;
}

boolean IsAller = true;

void skyNet()
{
  if (IsAller)
  {
      //droite
    carre_y = carre_y +1;
  }
  else
  {
    //gauche
    carre_y = carre_y -1;
  }
 
  //depasse la taille de l'ecran fait demis tour
  if(carre_y>42)
  {
    //is aller est un boolean qui peut prendre deux valeur true ou false
    IsAller = false;
  }
  // dessous zero fait demis tour
  if(carre_y<=0)
  {
    IsAller = true;
  }
 
 
}


Pour ceu qui se le demande. j'ai utilisé l'exemple basic des controles avec le cube et 2 exemples du forum.
voici les 2 lien

viewtopic.php?f=8&t=2804

viewtopic.php?f=8&t=2804
Flix
 
Posts: 2
Joined: Fri Jan 02, 2015 11:51 pm

Re: [FR] probleme de position

Postby rodot » Sun Feb 01, 2015 8:05 am

Salut, et bienvenue sur le forum !

Tu déclare ta fonction initGame(), jusque là pas de problème. Après le truc c'est que tu ne l'appelle jamais, elle n'est donc jamais exécutée ! Tu peux l'ajouter dans ton setup() de la sorte :
Code: Select all
// the setup
void setup(){
  gb.begin();
  initGame(); //appel de la fonction déclarée plus bas
  gb.titleScreen(F("Hard Cube"));
  gb.popup(F("Test"),100);
}
User avatar
rodot
Site Admin
 
Posts: 1290
Joined: Mon Nov 19, 2012 11:54 pm
Location: France

Re: [FR] probleme de position

Postby Flix » Mon Feb 02, 2015 10:14 pm

ok merci

comme j'ai dit, le probleme et plus tôt simple et bête mais je vien juste de commencer a programmer alors je pensse que s'est plus normal que je me trompe.
Flix
 
Posts: 2
Joined: Fri Jan 02, 2015 11:51 pm

Re: [FR] probleme de position

Postby rodot » Sun Feb 08, 2015 3:58 pm

Aucun soucis, j’espère que ma réponse t'a aidé à avancer. Bon courage pour la suite du développement!
User avatar
rodot
Site Admin
 
Posts: 1290
Joined: Mon Nov 19, 2012 11:54 pm
Location: France


Return to Programming Questions

Who is online

Users browsing this forum: No registered users and 27 guests

cron