Tolstoï VS Capitaliste

Ce wiki a été archivé en 2018.

Le nouveau wiki se trouve à: ressources.labomedia.org

Les fonctionnalités sont désactivées: vous pouvez faire une recherche sur Google site:https://wiki.labomedia.org et découvrir La Labomedia.

De Centre de Ressources Numériques - Labomedia
Aller à : navigation, rechercher

Code du jeu présent dans le spectacle Ni Gueux Ni Maître de la compagnie des Arracheurs de dents.

Principe

Chaque joueur crie dans un micro pour faire lancer à son personnage, soit des colombes, soit des billets de banque. Le premier qui fait tomber l'autre dans le précipice a gagné.

Tolstoi-VS-capitaliste.png

Matos

Il est nécessaire d'avoir une carte son avec deux entrées séparées sur lesquelles il est possible de brancher deux micros. Le sketch est configuré pour utiliser la carte son par défaut. À vous de faire en sorte que celle choisie le soit.

Ressources

  • La police utilisée est Subatomic Screen de Kevin Meinert.
  • Les personnages sont des modifications de Gen et Eagle du jeu Street Fighter.

Code

// Copyright Olivier Baudu - 2018
// Publié sous les termes de la GPL v3.0

import ddf.minim.*;
import java.util.Set;
import java.util.HashSet;
import java.util.Iterator;

Minim minim;
AudioInput in;

Boolean start;

float inLeft, inRight, seuil;
int widthIndicator, heightIndicator;
PFont font;

ArrayList<Dove> mesColombes;
ArrayList<Dollar> mesDollars;
ArrayList<Choc> mesChocs;

PImage[] leon = new PImage[4];
PImage affichageLeon, victoireLeon;

PImage[] capital = new PImage[4];
PImage affichageCapital, victoireCapital;

PVector posLeon, posCapital, zoneLeon, zoneCapital;
Boolean chocLeon, chocCapital, delaisL, delaisC, vivantLeon, vivantCapital;
Blast[] chocFinal;
int posInit, chuteLeon, chuteCapital, vitesseDep;
float delaisRefMax, delaisRefMin, delaisRefLeon, delaisRefCapital;

PImage front, back, fond, victoirePersonne;
int compteReboursInit, compteRebours;
int etatJeu;
// 1 : compte à rebours
// 2 : combat
// 3 : Léon a gagné
// 4 : Capital a gagné
// 5 : Personne n'a gagné 


void setup()
{
  size(1600, 900);
  font = createFont("atomics.TTF", 24);
  textFont(font);
  textAlign(CENTER);
  rectMode(CENTER);
  imageMode(CENTER);
  noSmooth();
  noStroke();

  minim = new Minim(this);
  in = minim.getLineIn();

  widthIndicator = 50;
  heightIndicator = 4;

  posInit = 540;

  for (int i=0; i<4; i++) {
    leon[i] = loadImage(str(i)+"l.png");
  }

  for (int i=0; i<4; i++) {
    capital[i] = loadImage(str(i)+"c.png");
  }

  front = loadImage("front.png");
  back = loadImage("back.png");
  fond = loadImage("fond.png");
  victoireLeon = loadImage("leonWins.png");
  victoireCapital = loadImage("capitalismeWins.png");
  victoirePersonne = loadImage("nobodyWins.png");
  compteReboursInit = 60; // tps en seconde
  compteReboursInit *= 60;

  initialisation();

  chuteLeon = 440;
  chuteCapital = width-chuteLeon;
  chocFinal = new Blast[2];
  vitesseDep = 6;
  delaisL = true;
  delaisC = true;
  delaisRefMax = 5;
  delaisRefMin = 0.2;
  seuil = 0.5;
}

void draw() {

  image(fond, width/2, height/2);

  // Récupère le niveau sonore
  inLeft = in.left.level();
  inRight = in.right.level();  

  delaisRefLeon = map(inLeft, seuil, 1, delaisRefMax, delaisRefMin);
  delaisRefCapital = map(inRight, seuil, 1, delaisRefMax, delaisRefMin);

  // Affichage jauges à gauche et à droite
  fill(150);
  indicator(inLeft, 0);
  //fill(255, 0, 0);
  indicator(inRight, width);

  // Actualiste la zone sensible des personages
  zoneLeon = new PVector(posLeon.x-20, posLeon.y-50);
  zoneCapital = new PVector(posCapital.x+20, posCapital.y-50);

  //// Gestion son
  if (start) {
    if (delaisL && (inLeft > seuil) && vivantLeon) {
      mesColombes.add(new Dove(posLeon.x));
      affichageLeon = leon[1];
    }

    if (delaisC && (inRight > seuil) && vivantCapital) {
      mesDollars.add(new Dollar(posCapital.x));
      affichageCapital = capital[1];
    }
  }

  // Gestion des chutes
  if (posLeon.x < chuteLeon) {
    posLeon.y += vitesseDep; 
    vivantLeon = false;
    affichageLeon = leon[3];
    if (posLeon.y > height+700) {
      if (!vivantCapital) etatJeu = 5;
      else etatJeu = 4;
    }
  }

  if (posCapital.x > chuteCapital) {
    posCapital.y += vitesseDep;
    vivantCapital = false;
    affichageCapital = capital[3];
    if (posCapital.y > height+700) {
      if (!vivantLeon) etatJeu = 5;
      else etatJeu = 3;
    }
  }

  // Affichage personnages
  image(affichageLeon, posLeon.x, posLeon.y, affichageLeon.width*2, affichageLeon.height*2);
  image(affichageCapital, posCapital.x, posCapital.y, affichageCapital.width*2, affichageCapital.height*2);

  Set<Dove> colombeASuppr = new HashSet<Dove>();
  Set<Dollar> dollarASuppr = new HashSet<Dollar>();

  Iterator<Dove> itDove = mesColombes.iterator();
  while (itDove.hasNext()) {
    Dove colombe = itDove.next();
    Iterator<Dollar> itDollar = mesDollars.iterator();
    while (itDollar.hasNext()) {
      Dollar dollar = itDollar.next();
      if (dollar.centre.dist(colombe.centre) < 10) {
        itDove.remove();
        itDollar.remove();
        mesChocs.add(new Choc(dollar.centre, 0));
        break;
      }
    }
  }

  // Gestion Colombe et collisions avec Capital
  delaisL = true;
  for (int i = mesColombes.size ()-1; i >= 0; i--) {

    Dove colombe = mesColombes.get(i);
    // Gère la sortie d'écran
    if (colombe.vie < delaisRefLeon) delaisL = false;
    if (vivantCapital &&zoneCapital.dist(colombe.centre) < 15) {
      posCapital.x += vitesseDep;
      mesColombes.remove(i);
      affichageCapital = capital[2];
      delaisC = false;
      if (posCapital.x > chuteCapital) chocFinal[1] = new Blast(colombe.centre, 2);
      else mesChocs.add(new Choc(colombe.centre, 1));
    }
    colombe.dessine();
    // Suprimer la colombe si elle sort de l'écran
    if (colombe.centre.x > width+50) mesColombes.remove(i);
  }

  // Gestion Dollard et collisions avec Léon
  delaisC = true;
  for (int i = mesDollars.size ()-1; i >= 0; i--) {

    Dollar dollar = mesDollars.get(i);
    if (dollar.vie < delaisRefCapital) delaisC = false;
    // Si un dollar touche Léon 
    if (vivantLeon && zoneLeon.dist(dollar.centre) < 15) {
      posLeon.x -= vitesseDep;
      mesDollars.remove(i);
      affichageLeon = leon[2];
      delaisL = false;
      if (posLeon.x < chuteLeon) chocFinal[0] = new Blast(dollar.centre, 1);
      else mesChocs.add(new Choc(dollar.centre, 2));
    }
    dollar.dessine();
    // Suprimer le dollard si il sort de l'écran
    if (dollar.centre.x < -50) mesDollars.remove(i);
  }

  for (int i = mesChocs.size ()-1; i >= 0; i--) {
    Choc choc = mesChocs.get(i);
    choc.affichage();
    if (choc.vie > 20) mesChocs.remove(i);
  }

  if (delaisL) affichageLeon = leon[0];
  if (delaisC) affichageCapital = capital[0];

  // Affichage du Blast avant la chute
  if (!vivantLeon) {
    chocFinal[0].affichage();
  }

  if (!vivantCapital) {
    chocFinal[1].affichage();
  }

  // Affichage falaise
  image(front, 327+front.width, 510+front.height, front.width*2, front.height*2);

  if (etatJeu == 1) {
    compteRebours--;
    int nb = compteRebours/60;

    fill(255);
    text("Prochain combat", width/2, 390);
    text("dans "+str(nb)+" secondes", width/2, 430);

    fill(0, map(compteRebours, compteReboursInit-180, compteReboursInit, 0, 255));
    //else fill(0, 255);
    rect(width/2, height/2, width, height);

    if (compteRebours < 61) {
      start = true;
      etatJeu = 2;
      compteRebours = 1200;
    }
  }

  if (etatJeu == 3) {
    affichageVictoire(victoireLeon);
  }

  if (etatJeu == 4) {
    affichageVictoire(victoireCapital);
  }

  if (etatJeu == 5) {
    affichageVictoire(victoirePersonne);
  }
}

void keyPressed() {

  if (start) {
    if (key == 'w') {
      if (delaisL && vivantLeon) {
        mesColombes.add(new Dove(posLeon.x));
        affichageLeon = leon[1];
      }
    }

    if (key == 'x') {
      if (delaisC && vivantCapital) {
        mesDollars.add(new Dollar(posCapital.x));
        affichageCapital = capital[1];
      }
    }
  }

  if (key == 'i') {
    initialisation();
  }

  if (key == 's') {
    start = !start;
  }

  if (key == 'q') {
    seuil += 1;
    seuil = seuil%2;
  }
}

void indicator(float inLevel, int xPos)
{
  //rect(xPos, height*20/100, widthIndicator/1.8, heightIndicator);
  rect(xPos, height-map(inLevel, 0.0, 1.0, 0, height), widthIndicator, heightIndicator);
  rect(xPos, height*(1-seuil), widthIndicator/1.5, heightIndicator);
}

void initialisation()

{

  mesColombes = new ArrayList<Dove>(0);
  mesDollars = new ArrayList<Dollar>(0);
  mesChocs = new ArrayList<Choc>(0);

  etatJeu = 1;
  compteRebours = compteReboursInit;
  start = false;
  affichageLeon = leon[0];
  affichageCapital = capital[0];
  vivantLeon = true;
  vivantCapital = true;
  chocLeon = false;
  posLeon = new PVector(posInit, height/2);
  posCapital = new PVector(width-posInit, height/2);
}

void affichageVictoire(PImage quelleVictoire) {
  compteRebours--;
  if (compteRebours/60%2 == 0) image(quelleVictoire, width/2, 390);
  if (compteRebours < 360) fill(0, map(compteRebours, 180, 360, 255, 0));
  else fill(0, 0);
  rect(width/2, height/2, width, height);
  if (compteRebours < 61) initialisation();
}

///////////

class Blast
{
  PImage[] blasts = new PImage[3];
  PVector position;
  int vie;
  int nature;

  Blast(PVector pos, int quelleNature) {    
    blasts[0] = loadImage("blast0.png");
    blasts[1] = loadImage("blast1.png");
    blasts[2] = loadImage("blast2.png");
    nature = quelleNature;
    if (nature == 1) {
      position = new PVector(pos.x-80, pos.y);
      posLeon.y -= 50;
    }
    if (nature == 2) {
      position = new PVector(pos.x+80, pos.y);
      posCapital.y -= 50;
    }
    vie = 0;
  }

  void affichage() {
    if (vie<12) {
      int index = int(vie/4);
      image(blasts[index], position.x, position.y, blasts[index].width*2, blasts[index].height*2);
      if (nature == 1) delaisL = false;
      if (nature == 2) delaisC = false;
    }
    vie += 1;
  }
}

//////////////////////

class Choc
{
  PImage[] flash = new PImage[3];
  PVector position;
  int vie;
  int nature;

  Choc(PVector pos, int quelleNature) {    
    flash[0] = loadImage("flash0.png");
    flash[1] = loadImage("flash1.png");
    flash[2] = loadImage("flash2.png");
    position = pos;
    vie = 0;
    nature = quelleNature;
       
  }

  void affichage() {
    if (vie<12) {
      int index = int(vie/4);
      image(flash[index], position.x, position.y, flash[index].width*2, flash[index].height*2);
      if (nature == 1) delaisC = false;
      if (nature == 2) delaisL = false;
    }
    vie += 1;
  }
}

////////////////

class Dollar
{

  PImage[] dollars = new PImage[4];

  PVector centre;
  PVector vitesse;
  float vie;

  Dollar(float posX) {

    dollars[0] = loadImage("dol0.png");
    dollars[1] = loadImage("dol1.png");
    dollars[2] = loadImage("dol2.png");
    dollars[3] = loadImage("dol3.png");

    centre = new PVector(posX-60, height/2-50+int(random(-14, 14)));
    vitesse = new PVector(-4, 0);
    if (!vivantLeon) vitesse = new PVector(random(-3, -7), random(-3, 0.65));
    vie = 0;
  }

  void dessine() {   
    centre.add(vitesse);
    int index = int(vie%4);
    image(dollars[index], centre.x, centre.y, 30, 30);
    vie += 0.25;
  }
}

//////

class Dove
{

  PImage[] colombes = new PImage[4];

  PVector centre;
  PVector vitesse;
  float vie;

  Dove(float posX) {

    colombes[0] = loadImage("col0.png");
    colombes[1] = loadImage("col1.png");
    colombes[2] = loadImage("col2.png");
    colombes[3] = loadImage("col1.png");

    centre = new PVector(posX+60, height/2-50+int(random(-14, 14)));
    vitesse = new PVector(4, 0);
    if (!vivantCapital) vitesse = new PVector(random(3, 7), random(-3, 0.65));
    vie = 0;
  }

  void dessine() {

    centre.add(vitesse);
    int index = int(vie%4);
    image(colombes[index], centre.x, centre.y, 30, 30);
    vie += 0.25;
  }
}