|
![]() |
I am missing out on. Logic
Where is the value of paddleXpos changed?My paddle works now fine,
There are three kinds of actuaries: those who can count, and those who can't.
Norm Radder wrote:Ok, I'm done now. I leave the thread to Piet so he can give you the code you need.
Good luck.
Piet Souris wrote:A way without using booleans is:
have a Field called paddleDeltaX, initially set to 0.
Then, in your run method, do:
And the KeyHandler will be:
and in the released handler:
There are three kinds of actuaries: those who can count, and those who can't.
There are three kinds of actuaries: those who can count, and those who can't.
Piet Souris wrote:But that way I did not get any notification.
@Matthias,
collision between the ball and a brick is done in the same way as a collision between the ball and the paddle, albeit that you now have to check for collision at the left and right sides of the brick as well, changing possibly the x-direction. You must do that check for all the bricks (still) present. Did you put all your bricks in a List or Set? It would also be very handy to use a Brick class instead of just Rectangles.
Matthias Utrata wrote:I create all of them in the run method. Is there a way, that I can create them in a constructor and then use them in the run method?
There are three kinds of actuaries: those who can count, and those who can't.
There are three kinds of actuaries: those who can count, and those who can't.
Piet Souris wrote:What is 'targets'?
Piet Souris wrote:
Matthias Utrata wrote:I create all of them in the run method. Is there a way, that I can create them in a constructor and then use them in the run method?
You can define your Rectangles upfront and put then in a List<Rectangle>.
Then, in your run-method, you can have, say:
SideHit is an enum, with the values West, North, East, South and NO_HIT, and depending on the state returned you can determine what new direction the ball gets.
But as you see, you have meny variables denoting position, speed, color et cetera. As we mentioned in earlier topics, you can ease the code by having a Ball class, a Brick class and a Paddle class. More on that later, perhaps
Piet Souris wrote:
Matthias Utrata wrote:I create all of them in the run method. Is there a way, that I can create them in a constructor and then use them in the run method?
You can define your Rectangles upfront and put then in a List<Rectangle>.
Then, in your run-method, you can have, say:
SideHit is an enum, with the values West, North, East, South and NO_HIT, and depending on the state returned you can determine what new direction the ball gets.
But as you see, you have meny variables denoting position, speed, color et cetera. As we mentioned in earlier topics, you can ease the code by having a Ball class, a Brick class and a Paddle class. More on that later, perhaps
There are three kinds of actuaries: those who can count, and those who can't.
There are three kinds of actuaries: those who can count, and those who can't.
Matthias Utrata wrote:There is one particular thing, that I now know is the mistake. I first did not know, that objects get drawn from the upper left corner first.
Matthias Utrata wrote:Now I am curious, if there is a way to get all points of the circle. I know now, how I wanna do the if statements and how I can make it work. I just need the information of getting every point of the circle
There are three kinds of actuaries: those who can count, and those who can't.
There are three kinds of actuaries: those who can count, and those who can't.
There are three kinds of actuaries: those who can count, and those who can't.
Matthias Utrata wrote:So I wanna activate the run() method in addition after I click the mouse button, while the setGameStarted() Method is going. I think I am missing out on something though. The run method is just for the movement of the ball and the paddle. The setGameStarted() Method should be when the major thing happens. Like rectangles getting cleared after a hit with .clearRect(). I tried that before in my run method, but it always gets redrawn so I gotta adapt my code to make it work. I am gonna change my code in pastebin so you can take a look and hopefully help me out
There are three kinds of actuaries: those who can count, and those who can't.
There are three kinds of actuaries: those who can count, and those who can't.
CAUTION! Do not touch the blades on your neck propeller while they are active. Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
|