Annonce

>>> Bienvenue sur codelab! >>> Première visite ? >>> quelques mots sur codelab //// partage de liens //// une carte des membres//// (apéros) codelab


#1 2017-02-15 18:15:19 |Débutant| Mettre un mode deux joueur a un petit jeu

MrSmooth
nouveau membre
Date d'inscription: 2017-02-15
Messages: 1

|Débutant| Mettre un mode deux joueur a un petit jeu



Bonjour a tous. Alors voila j'ai fait un petit stage d'informatique où nous avons crée un petit jeu tron.  Seulement par manque de temps, nous n'avons pu faire qu'une seule 'moto'. J'ai donc essayé de rajouter un deuxième joueur. Cependant, les controles du joueur 1 influent sur le joueur deux et quand on appuie sur n'importe quelle touche du j1, le j2 va vers le bas. Je ne comprend pas mon erreur et je m'en remet donc a vous. neutral
Voici le code :

//Map
int map[][] = {{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,1,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,1,0,0,0,0,0,1},
{1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1},
{1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1},
{1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1},
{1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1},
{1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1},
{1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1},
{1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}};

//Coordonées personnage
int x = 0;
int y = 0;
int a = 0;
int b = 0;

int j = 300;
int k = 120;
int p = 900;
int o = 120;
int pixel;
PImage gameover;
int direction = 0;
PImage background;
boolean e;
int direct = 0;


void setup()
{
  size(1201,500);
  background = loadImage("background.jpg");
  background(background);
  test();
  import processing.sound.*;
  SoundFile file3;
        file3 = new SoundFile(this, "derrezedmonté.mp3");
        file3.play();
        file3.amp(1);
  e = false;
 
}

//Affichage map
void test()
{
  x = 0;
  y = 0;
  a = 0;
  b = 0;
 
  while (x <= 16)
  {
    y = 0;
    while (y <= 39)
    {
      if (map[x][y] == 1)
      {
        noStroke();
        fill(255);
        rect(a,b,30,30);
       
        a = a + 30;
      }
      if (map[x][y] == 0)
      { 
       /* noStroke();
        fill(0);
        rect(a, b, 30, 30);*/
        a = a + 30;
      }
     y = y + 1;
    }
     x = x + 1;
     a = 0;
     b = b + 30;
  }


//Personnage
void draw()
{
  fill(255,255,255);
  test();
  keyCode = '0';
  key();
  keyPressed();
  mouvement2p();
  mouvement(); 
  fill(150);
  ellipse(p,o,10,10);
  fill(255);
  ellipse(j,k,10,10);
}

//Déplacement de la boule
void keyPressed()
{
  if (keyCode == DOWN)
    {
      direction=1;
    }
    if (keyCode == UP)
    {
      direction=2;
    }
    if (keyCode == RIGHT)
    {
      direction=3;
    }
    if (keyCode == LEFT)
    {
      direction=4;
    }
}

void key()
{
   if (key == 's' || key == 'S' ) ;
    {
      direct = 1;
    }
    if (key == 'z' || key == 'Z')
    {
      direct = 2;
    }
    if (key == 'd'|| key == 'D')
    {
      direct = 3;
    }
    if (key == 'q' || key == 'S')
    {
      direct = 4;
    }
}
void mouvement()
{
  if (direction==1)
  {
    k+=2;
    pixel = get(j, k + 15);
    print(pixel);
    if (pixel == -1 || pixel == -6908266)
      {
        noLoop();
        println("Game OverDOWN");
        PFont police;
        police = loadFont("TimesNewRomanPSMT-48.vlw");
        textFont(police);
        fill(245,20,20);
        text("Game Over",450,220);
        text("Player 2 WIN ",430,280);
          SoundFile file;
        file = new SoundFile(this, "gameover.mp3");
        file.play();
      }
   
  }
  if (direction==2)
  {
    k-=2;
    pixel = get(j, k - 15);
    print(pixel);
    if (pixel == -1 || pixel == -6908266)
      {
        noLoop();
        println("Game OverUP");
        PFont police;
        police = loadFont("TimesNewRomanPSMT-48.vlw");
        textFont(police);
        fill(245,20,20);
        text("Game Over",450,220);
        text("Player 2 WIN ",430,280);
        SoundFile file;
        file = new SoundFile(this, "gameover.mp3");
        file.play();
      }
  }
  if (direction==3)
  {
    j+=2;
    pixel = get(j + 15, k);
    print(pixel);
    if (pixel == -1 || pixel == -6908266)
      {
        noLoop();
        println("Game OverRIGHT");
        PFont police;
        police = loadFont("TimesNewRomanPSMT-48.vlw");
        textFont(police);
        fill(245,20,20);
        text("Game Over",450,220);
        text("Player 2 WIN ",430,280);
        SoundFile file;
        file = new SoundFile(this, "gameover.mp3");
        file.play();
      }
  }
  if (direction==4)
  {
    j-=2;
    pixel = get(j - 15, k);
    print(pixel);
    if (pixel == -1 || pixel == -6908266)
      {
        noLoop();
        println("Game OverLEFT");
        PFont police;
        police = loadFont("TimesNewRomanPSMT-48.vlw");
        textFont(police);
        fill(245,20,20);
        text("Game Over",450,220);
        text("Player 2 WIN ",430,280);
        SoundFile file;
        file = new SoundFile(this, "gameover.mp3");
        file.play();
      }
  }
}
void mouvement2p()
{
    if (direct == 1)
  {
    o+=2;
    pixel = get(p, o + 15);
    print(pixel);
    if (pixel == -1 || pixel == -6908266)
      {
        noLoop();
        println("Game OverDOWNp2");
        PFont police;
        police = loadFont("TimesNewRomanPSMT-48.vlw");
        textFont(police);
        fill(245,20,20);
        text("Game Over",450,220);
        text("Player 1 WIN ",430,280);
          SoundFile file;
        file = new SoundFile(this, "gameover.mp3");
        file.play();
      }
   
  }
  if (direct == 2)
  {
    o-=2;
    pixel = get(p, o - 15);
    print(pixel);
    if (pixel == -1 || pixel == -6908266)
      {
        noLoop();
        println("Game OverUPp2");
        PFont police;
        police = loadFont("TimesNewRomanPSMT-48.vlw");
        textFont(police);
        fill(245,20,20);
        text("Game Over",450,220);
        text("Player 1 WIN ",430,280);
        SoundFile file;
        file = new SoundFile(this, "gameover.mp3");
        file.play();
      }
  }
  if (direct == 3)
  {
    p+=2;
    pixel = get(p + 15, o);
    print(pixel);
    if (pixel == -1 || pixel == -6908266)
      {
        noLoop();
        println("Game OverRIGHTp2");
        PFont police;
        police = loadFont("TimesNewRomanPSMT-48.vlw");
        textFont(police);
        fill(245,20,20);
        text("Game Over",450,220);
        text("Player 1 WIN ",430,280);
        SoundFile file;
        file = new SoundFile(this, "gameover.mp3");
        file.play();
      }
  }
  if (direct == 4)
  {
    p-=2;
    pixel = get(p - 15, o);
    print(pixel);
    if (pixel == -1 || pixel == -6908266)
      {
        noLoop();
        println("Game OverLEFTp2");
        PFont police;
        police = loadFont("TimesNewRomanPSMT-48.vlw");
        textFont(police);
        fill(245,20,20);
        text("Game Over",450,220);
        text("Player 1 WIN ",430,280);
        SoundFile file;
        file = new SoundFile(this, "gameover.mp3");
        file.play();
      }
  }
}

En espérant que vous puissiez m'aider smile

Hors ligne

 

#2 2017-02-19 11:13:06 Re : |Débutant| Mettre un mode deux joueur a un petit jeu

cgiles
membre
Lieu: Est de la France
Date d'inscription: 2005-05-25
Messages: 329

Re: |Débutant| Mettre un mode deux joueur a un petit jeu



Tu devrais faire une classe player, avec une fonction keyManagement(int key) et les mettres dans ton gestionnaire de key, keyPressed()

Hors ligne

 

fil rss de cette discussion : rss

Pied de page des forums

Powered by FluxBB

codelab, graphisme & code : emoc / 2008-2017