#Collision Detection Falling Game

116 messages · Page 1 of 1 (latest)

cursive minnow
#

I’ve been trying to work on making a falling catcher game, where there is a ‘catcher’ catching falling objects. I just don’t know where I should start since, I’m not very knowledgeable yet with these new commands. Can anyone give me an example on how it can work so I can understand how it works? ct_semicolon

#

A visualize of what I’m trying to do

amber oracle
#

@cursive minnow I swear I have seen a video of Dan's where there is rain and you are catching the drops. Let me Google.

#

Here it is.

#

Same concepts. You just need to decide what it looks like.

#

Learning Processing Dan's book is very good. It's not a video but you will see some good starter ideas.

cursive minnow
#

Ok tysm!

strange radish
#

I don't do the rain catching in this processing course, but the section on object interaction with dist() coudl be useful! https://youtu.be/4JzDttgdILQ?t=16909

Choo choo! Welcome aboard to the world of creative coding! Join me in this beginner-friendly video series learning to code with Processing! https://thecodingtrain.com/tracks/learning-processing/processing

🚀 Watch this video ad-free on Nebula! https://nebula.tv/videos/codingtrain-beginners-guide-to-creative-coding-with-processing-full-course

W...

▶ Play video
cursive minnow
#

Thank you Dan, I’ll take a look on it

cursive minnow
amber oracle
#

You need 2 variables. 1 to hold caught and 1 to hold missed.
Then you simply do the math.
Total = caught + missed.
Missed/total= percentage of missed.
Caught/total = percentage of caught.

#

Percentage of missed + percentage of caught = 100%

amber oracle
obtuse yoke
#

theoretically at least 😉 built-in rounding might not agree with you on that 100% for certain ratios xD

amber oracle
obtuse yoke
#

I think even then? 0.333333333333 get's rounded at some point I assume

#

not sure how doubles handle that, honestly never tried

cursive minnow
#

So it was that easy..

obtuse yoke
#

Yep, don't overcomplicate things :D

cursive minnow
#

I over thinked the problem.

#

😭

obtuse yoke
#

sometimes things are just way easier than they seem

amber oracle
#

You may need a decision on WHEN to do the math.

#

But just a ratio, no decision.

obtuse yoke
#

if you're using processing, you could just do it in the draw loop?

#

might be a bit inefficient though

cursive minnow
#

everytime the catcher touches one object it adds up, and then if the object reachs to the bottom then it adds 1 to miss.

obtuse yoke
#

yeah exactly

#

and then you just display those values!

cursive minnow
#

hold up lemme write a text rq

cursive minnow
obtuse yoke
#

as in, write this on the screen

cursive minnow
#

?

obtuse yoke
#

you wanted to that no?

cursive minnow
#

yes but like caught extacyl 2

#

and missed exactly 7

#

Like I want it start on zero ofc and then tally up to depending how much I caught and missed

obtuse yoke
#

yeah you can totally do that, just replace the 2 with the value of your caught variable, and the 7 with the value of the missed variable!

amber oracle
#

If you use an int data type it will just drop any decimal numbers

cursive minnow
#

ct_rainbow Thanks I'll work on that when I have the time

#

Hopefully 🙏

obtuse yoke
#

You can do it pepeThumbsup

cursive minnow
#

Thank you! 🙏

amber oracle
#

You got this. Check in for advice.

amber oracle
#

@cursive minnow Here is how I do it in the game I am working on.java efficiency = (enemies_killed/enemy_count)*100;

#

I display it to the screen like this.java text("EFFICIENCY", column_1, row_3); text(int(efficiency), column_2, row_3);

#

I convert it to int() so it drops the decimals without rounding. Calculation is done with floats. You cannot get a percentage without being able to have .65. To do that you use a double or a float data type.

cursive minnow
#

I see now thx!

#

What’s does row 3 and Columns for etc?

#

I basically did like every time I catcher something, I would do a ‘’if statement’s’

amber oracle
#

I will show you let me get on my laptop.

obtuse yoke
#

guessing those variables correlate to certain x and y values on the screen

cursive minnow
#

Alr no worries take your time but

cursive minnow
amber oracle
#
    column_1 = width/4+100;
    column_2 = width*.750-250;

    row_1 = height/4 + 100;
    row_2 = height/4 + 150;
    row_3 = height/2;
    row_4 = height/4 + 200;
    row_5 = height/2 + 50;```
#

@cursive minnow correct. I just named them instead of having confusing numbers.

cursive minnow
#

Yeah

#

Alr I get it now! I’ll prob do it in evening Since I gtg now

amber oracle
#

Putting text on a screen is kinda trial and error.

amber oracle
cursive minnow
cursive minnow
amber oracle
#

Understandable. No biggie. Check back if you need help.

cursive minnow
cursive minnow
#

I just wanna move the catcher catching rain drops not by mouse but by keys

obtuse yoke
#

save the x location of the basket in a global variable, then when a certain key is pressed, you either add or remove a bit from that variable. Then just draw the basket at a fixed y coordinate with that x variable

cursive minnow
#

Can you show me an example i don’t get@it

amber oracle
#

@cursive minnow You want a switch statement nested in an if statement. java if(keyPressed){ switch(key){ case 'a' : move left break; case 's' etc.... } }

#

I'ma t work on my phone, but look up. keyPressed, keyCode and key in the processing reference. You will see how the keyboard inputs are used in Processing.

#

I will be home after 4pm EST. I will show you how I handle it in my game.

#

Also the above is not working code. I used words instead of expressions for understanding.

cursive minnow
#

I’ll see you at 4 pm then I’ll prob need that help

amber oracle
#

@cursive minnow I am going to rake for a bit until it gets dark so I will have my phone but not my laptop. I will give you some thing to look at for a minute.

#
//Moves ship
void move(ArrayList<Actor> actors) {//argument is the     ArrayList containing the ship and asteroids
     if (keyPressed) {//boolean is true when any key is                       //pressed
      switch(key) {//looks at WHAT key was pressed
      case 'w':
      case 'W'://north Character that moves up in a -y                 //direction. Will accept upper and lower                //case letter. Each case down, left, etc.
        y -= y_speed;
        break;
      case 's':
      case 'S'://south
        y += y_speed;
        break;
      case 'a':
      case 'A'://east
        x -= x_speed;
        break;
      case 'd':
      case 'D'://west
        x += x_speed;
        break;
      case 'q':
      case 'Q'://northwest
        x -= x_speed;
        y -= y_speed;
        break;
      case 'e':
      case 'E'://northeast
        x += x_speed;
        y -= y_speed;
        break;
      case 'z':
      case 'Z'://northwest
        x -= x_speed;
        y += y_speed;
        break;
      case 'c':
      case 'C'://northwest
        x += x_speed;
        y += y_speed;
        break;
      case 'x'://This is a button I can use to test a                  //method to see if it works before I                    //control it.
      case 'X':
        //Test method goes here
        break;
      case ' '://fire s_bullet. This is the space bar key
        add_S_bullet();
        break;
      }
    }
  }```
#

I made some comments that explain what is going on. If you have any questions, I can explain in more detail.

amber oracle
cursive minnow
#

@amber oracle Maybe could you implement in the rain drop code?

#

be much easier to understnad

#

So the catcher would be moved by A and D left and right

amber oracle
#

It is implemented. The ship is the rain catcher. Show me what you have coded so far.

#

I was you a year ago. I started with Learning Processing. First the PDF on line. I did end up getting a hard copy on Thrift Books.

#

Start with just a square. Learn different ways to move the square. This isn't an overnight process.

amber oracle
cursive minnow
#

ohh

cursive minnow
amber oracle
#

If you have any questions about what you are reading I can help you if you are stuck, but just giving you the method won't necessarily help you understand.

#

I love this book.

cursive minnow
cursive minnow
#

@amber oracle could I see like your sound part? For the game

#

Because I wanna add some sounds to my game, every time I catch and then a sound when I miss to catch it

amber oracle
amber oracle
#

Saturday I was working on getting it to save a score and display it back when the game is started

#

I have it working on the serial monitor.

cursive minnow
#

Mhm i see

amber oracle
#

@cursive minnow I think I updated my repository. When I get something done I upload so I have the last working version.

#

This is the source code if you want to look at it.

#

Score tab is there so I did upload what I accomplished.

cursive minnow
#

If

#

Ic

amber oracle
cursive minnow
amber oracle
#

Oh duh!! You can tell I'm old.

#

I thought it was an L.