automatic score

edited February 2016 in Programming Questions

Hey guys, I've to programm a game for a school: I decided for a table hockey and everything works but i would like to add the automatic score when one player make a goal. It d be awesome if someone could help! Thanks in advance. [-O<

Tagged:

Answers

  • table hockey game*

  • Answer ✓

    There is no such thing as automatic in processing

    You have to do it by hand

    Global var score for each Player scorePlayer1 and 2

    When goal say score for the right guy

    Use text() to display both scores

    text( scorePlayer1+ ":" + scorePlayer2, 22,22);

  • code copied from duplicate (now deleted)

    import fisica.*;
    FWorld world;
    FCircle box1;
    FCircle box2;
    FCircle palla;
    int x;
    int x1;
    int scoreb=0;
    int scorer=0;
    PImage b0;
    
    PImage r0;
    
    void setup() {
      size(1300, 700);
      smooth();
      textSize(30);
      fill(0);
      x=1050;
    
      x1=90;
    
      Fisica.init(this);
      world= new FWorld();
      world.setGravity(0, 0);
      world.setEdges();
      palla = new FCircle(10);
      palla.setPosition(600, 350);
      palla.setDensity(0.1);
      palla.setFill(0, 255, 0);
      palla.setNoStroke();
      palla.setRestitution(0.75);
      palla.setDamping(0);
    
      world.add(palla);
    
      box1= new FCircle(40);
      box1.setPosition(950, 350);
      box1.setDensity(100);
      box1.setFill(255, 0, 0);
      box1.setNoStroke();
      box1.setDamping(0);
      box1.setRestitution(1);
    
      world.add(box1);
    
      box2= new FCircle(40);
      box2.setPosition(250, 350);
      box2.setDensity(100);
      box2.setFill(0, 0, 255);
      box2.setNoStroke();
      box2.setDamping(0);
      box2.setRestitution(1);
    
      world.add(box2);
    
      FBox box3= new FBox(20, 150);
      box3.setPosition(30, 350);
      box3.setDensity(10);
      box3.setRestitution(1);
      box3.setFill(0, 0, 255);
      box3.setNoStroke();
      box3.setDamping(0);
      box3.setStatic(true);
    
      world.add(box3);
    
      FBox box4= new FBox(20, 150);
      box4.setPosition(1170, 350);
      box4.setDensity(10);
      box4.setFill(255, 0, 0);
      box4.setRestitution(0.50);
      box4.setNoStroke();
      box4.setDamping(0);
      box4.setStatic(true);
    
      world.add(box4);
    
      FBox box5= new FBox(20, 550);
      box5.setPosition(50, 0);
      box5.setDensity(10);
      box5.setRestitution(0.50);
      box5.setFill(0);
      box5.setNoStroke();
      box5.setDamping(0);
      box5.setStatic(true);
    
      world.add(box5);
    
      FBox box6= new FBox(20, 275);
      box6.setPosition(50, 562);
      box6.setDensity(10);
      box6.setRestitution(0.5);
      box6.setFill(0);
      box6.setNoStroke();
      box6.setDamping(0);
      box6.setStatic(true);
    
      world.add(box6);
    
      FBox box7= new FBox(20, 275);
      box7.setPosition(1150, 562);
      box7.setDensity(10);
      box7.setFill(0);
      box7.setNoStroke();
      box7.setDamping(0);
      box7.setStatic(true);
      box7.setRestitution(0.5);
    
      world.add(box7);
    
      FBox box8= new FBox(20, 550);
      box8.setPosition(1150, 0);
      box8.setDensity(10);
      box8.setFill(0);
      box8.setRestitution(0.5);
      box8.setNoStroke();
      box8.setDamping(0);
      box8.setStatic(true);
      world.add(box8);
    }
    
    void draw() {
      background(255);
      println(scoreb);
      text("good game", 1600, 0);
      text("Score blue: " + scoreb, 1170, 60);
      text("Score red: " + scorer, 1170, 100);
      //box1.setPosition(x, y);
      //box2.setPosition(x1, y1);
      world.step();
      world.draw();
    }
    
    void keyPressed() {
      if (key == 'w') {
        box2.setVelocity(0, -90);
      }
      if (key == 's') {
        box2.setVelocity(0, 90);
      }
      if (key == 'd') {
        box2.setVelocity(90, 0);
      }
      if (key == 'a') {
        box2.setVelocity(-90, 0);
      }
      if (key == 'i') {
        box1.setVelocity(0, -90);
      }
      if (key == 'k') {
        box1.setVelocity(0, 90);
      }
      if (key == 'l') {
        box1.setVelocity(90, 0);
      }
      if (key == 'j') {
        box1.setVelocity(-90, 0);
      }
      if (key == 'b') {
        scoreb++;
      }
      if (key == 'r') {
        scorer++;
      }
      if (key == 'g') {
        palla.setPosition(600, 350);
        palla.setVelocity(0, 0);
        box1.setPosition(950, 350);
        box1.setVelocity(0, 0);
        box2.setPosition(250, 350);
        box2.setVelocity(0, 0);
      }
    }
    
  • please don't duplicate (or triplicate) questions. if you do then you split the answers and everyone gets confused. also, I have to tidy up the others and i hate that.

  • I'm sorry for the duplication but can you help my please [-O<

  • I'm sorry for the duplication

    but not so sorry that you didn't create a 4th duplicate thread.

    i have better things to do with my time than tidy up after you.

  • Is the automatic score something in fiscia?

    Then ask in section libraries?

    Or ask the maker of the lib...

    Or look in its documentation

Sign In or Register to comment.