collision

edited May 2014 in Arduino

dw

Answers

  • Haven't you already posted the same thing in your 1st thread? :-$
    http://forum.processing.org/two/discussion/4678/i-need-help-in-creating-a-fish-game

  • yeah but i don't understand the flappy bird concept

  • im a beginner at processing

  • Answer ✓

    This is the smallest flappy bird code(when minified) made in processing at this moment (made by me. It will soon be crushed i'm sure). Read the //comments very carefully as I've tried to explain it as well as I can:

    //sets up the variables for the pipe and bird positions and score:
    float p=400, a;
    int g, s, v=166, w=500, z=200;
    boolean d, f, t;
    float[]y= {
      z, w, v
    };
    void setup() {
      //sets up the sketch
      size(w, 800);
      strokeWeight(3);
      textSize(25);
    }
    void draw() {
      //clears the display
      clear();
      if (d&&f) {
        //if you are not dead then move the pipes
        int x=w-frameCount*2%v;
        if (x==w) {
          y[0]=y[1];
          y[1]=y[2];
          y[2]=random(w);
        };
        //set the gravity:
        a+=.3;
        //draw the pipes:
        rect(x-v, -5, v, 805);
        rect(x-332, 0, 0, 800);
        stroke(0);
        int c=3;
        //draw the gap in the pipes
        for (int i=x;i>x-333;i-=v)line(i, y[c-=1], i, y[c]+z);
        stroke(255);
        //test for the pipes colour:
        d=get(100, int(p=max(min(p+a, 795), 5)))==color(0);
        //adds your score if you have just gone through a pipe
        if (d&&x==400)s++;
        //draw the player and your score:
        ellipse(100, p, 20, 20);
        r(0, 0, str(s));
      }
      else {
        //else if you are dead then display 'game over' and your score
        r(v, 300, (f?"game over":"flappy bird"));
        //if its your first time playing the game then it will have a title screen with 'flappy bird' 'click to play'
        r(v, w, (f?"score:"+s:"click to play"));
      }
      //If you press a button or the mouse then run function 'c'
      if (mousePressed||keyPressed)c();
    }
    void c() {
      //set the acceleration and score:
      if (!d)s=0;
      a=-7;
      d=f=!t;
    }
    void r(int x, int y, String s) {
      //draw the box with the text:
      stroke(255);
      rect(x, y, z, 40);
      fill(255);
      text(s, x+30, y+30);
      fill(0);
    }
    

    Does that help?

  • thankyou

  • also quick question how to i get the fish to move up and down using the arrow buttons?

  • edited April 2014

    Your fish has probably a variable telling the vertical position where to draw it. If not, create such variable!

    Then, on keyPressed(), detect if it is an arrow key, and if so, change the value of the vertical position.

    Beside, collision check and scoring are among the most asked topics in this forum, and are shown in lot of examples. Some search can help.

    Oh, and avoid to make duplicate threads. A simple additional question in the original thread would have been enough.

  • edited May 2014

    how do i create bubbles using loop?

  • edited May 2014 Answer ✓

    here collision check

    void collisionFish() {
    
      // collision check  
      boolean isWater; 
    
      // if near the wall area 
      if (x>455) {
        //  
        // is water or wall before the fish? 
        isWater = get ( x+26, y ) == color (70, 190, 199);
        if (isWater) {
          if (x>470) { 
            score++;
            // restart Fish
            restartFish();
          }
        }
        else 
        {
          // collision
          if (x>455) { 
            score--;
            // restart Fish
            restartFish();
          }
        } // else
      } // if
    } // func 
    
  • Answer ✓

    I did bubbles in one of the other threads for fish from your class.

    google it

    • you have to change it though because you're number 3 using it, so I mustn't look like plagiarism
  • edited May 2014

    @Chrisir, no use to keep helping him!
    @mikw123 is erasing everything and asking about "deactivating" his account! [-(

  • Answer ✓

    he even sent me PMs .....

  • edited May 2014
    mikw123
    
    Activity
    Discussions 2
    Comments 6
    
    dw
    Answered ✓ 13 comments Most recent by Chrisir11:12AMArduino
    dw
    Question 3 comments Most recent by GoToLoopApril 25How To...
    

    Don't do that (renaming your thread, removing the content of the question. If you don't want to leave traces on Internet, just don't use it.

  • im sorry

  • Answer ✓

    to stop the fish from starting automatically again, you need to change restartFish()

    don't set x to zero here

  • or display a text "Click mouse to play again"

  • im still confused

  • why?

    you see the function void restartFish() {

    ?

    Here is a line x=-70; or so

    delete this line

  • edited May 2014 Answer ✓

    or delete the complete function

    void restartFish() {
      // restart Fish
      x=-70;
      y=int(random(70, height-70));
      lengthY = int (random(10, height-120));
    } // func 
    

    and delete the line where it's called:

    restartFish();
    
  • Answer ✓

    I also made one version where the gap in the wall has a new position every time the fish goes through it

  • when I get rid of the void restartFish function, when the fish passes through the gap the score continues to rise

  • edited May 2014 Answer ✓

    you can have a global var

    boolean scorePauses = false;

    once the fish is through the score gets higher

    set

    scorePauses = true; 
    

    after that

    then when the mouse is clicked, and a new fish starts say

    scorePauses = false;

    of course

  • thankyou

Sign In or Register to comment.