Help required with "drawing a river"

edited October 2013 in How To...

Here is what I am trying to achieve.

This is game where on is required to 1) Move a toy boat from start to end of a river. 2) If the boat hits the bank of the river the game ends.

I have so far figured how to draw a boat and how to move the boat by listening to mouseX and mouseY. Can someone help me with

1) drawing the river and 2) Identifying collision between the boat and river banks.

Answers

  • Answer ✓

    I think the good way to deal with collision checking is by using a PGraphic "mask" of the river. Lets say you have a screen filled with blue, represening the water, as the background color of the window. Then you draw onto a PGraphic image with green to represent the shore areas. The areas not colored with green in the PGraphic will be transparent and show the blue background when you draw the PGraphic to the screen.

    Then you can load the pixels of the PGraphic and loop through them testing the alpha of each pixel. If the pixel doesn't have alpha, then you are on land. There are many different ways to do this, this is just one way.

  • Cool, this seems to be a cool way to implement I will give it a shot. I was thinking of using curves to define the boundary of the river.

  • Hi,

    Here is my processing sketch code. I was able to draw a boundary for the river. I was also able to listen to the scroll input. I am using the scroll input to rotate the boat. Looks like whenever I try to rotate the boat based on the scroll, the boat moves away from its original location. Can someone point me out the issue could be ?

    My sketch can be found here, https://gist.github.com/perceptron/7147527

  • What do you mean by "scroll input", I couldn't get the boat to move at all.

  • The scroll input is the input from the scroll wheel. There was an issue with the code I had pasted above. Please try this, https://gist.github.com/perceptron/7148810. You can move the boat by clicking on it and then by dragging the mouse.

Sign In or Register to comment.