Breakout type game
Author |
Message |
NikG
|
Posted: Fri Mar 17, 2006 10:29 am Post subject: Breakout type game |
|
|
Hey all,
Here's the source for a breakout type game I began working on.
(It's not a game yet, just the ball bouncing around and the paddle).
The main reason for my creating this was to see how I could work with changing the angle of the ball's movement (because the previous time I created this time of game, the ball always moved at 45 degrees )
Here's what I did:
-if the ball hits the paddle while it's not moving, the angle will stay the same.
-if the ball hits the paddle while it's moving in the same direction as the ball, it will push the ball further in that direction and lower its angle (ball moves more horizontally)
-if the ball hits the paddle while it's moving in the oppisite direction as the ball, it will push the ball against that direction and increase its angle (ball moves more vertically).
Then, I added a little code to check the strength of the paddle movement, and made it so that the stronger the movement, the more the angle changed. I did this by keeping track of how long the user held the left or right arrow key. (I left the "strength" of the paddle movement and the angle of the ball visible on the top-left. Comment out lines 102-105 if you don't want to see them.)
My question is, is there a better way to handle angles in this type of game?
What I'm worried about is times when the angle becomes a problem (maybe too close to 0 degrees). How is this done in other breakout games?
Edit: removed double attachment, spelling
Description: |
Breakout.t
Source code for breakout type game |
|
Download |
Filename: |
Breakout.t |
Filesize: |
3.98 KB |
Downloaded: |
310 Time(s) |
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
cool dude
|
Posted: Fri Mar 17, 2006 11:34 am Post subject: (No subject) |
|
|
i made the same game before! i didn't concentrate to much on the angles though because the hardest part was the bricks and the angles on the bricks when the ball hits them and the collision and the power ups. u have a good start though but the thing is it just switches from going right and left. instead if it hits the right corner of the pad it should swithch to the right direction and change angle and vise versa with the left corner of the pad
|
|
|
|
|
|
NikG
|
Posted: Fri Mar 17, 2006 11:44 am Post subject: (No subject) |
|
|
I still have to add the code (to do just what you said) if the ball hits the very corner of the paddle.
However, I've noticed in many games that even when the ball hits the side of the paddle (not the corner), they still code it to change the ball's angle. To me, that doesn't make any sense. It's a flat surface so the angle should not be changing (unless the paddle is moving). The only way this makes sense is if the paddle were curved on the top.
As far as the bricks, I don't foresee a problem because there wont be as much angle-changing as there is with the paddle. Infact, the only time the angle should change would be if the ball hits the very corner of the block.
If I get that far, I'm really looking forward to coding the powerups. I've got some interesting (old an new) ones planned.
|
|
|
|
|
|
cool dude
|
Posted: Fri Mar 17, 2006 12:29 pm Post subject: (No subject) |
|
|
firstly the bricks part is a lot more coding for changing angles than the paddle. the reason i say this is when the ball hits the brick u want it to change the direction and the angle and go the opposite (right left) direction than u were originally goin.
for example:
the ball is going the right direction up and hits the bottom of the brick. now the ball should go down and instead of going down the same path it should change direction and go down and right.
the best way to see the ball changing angles and how it works is by actually playing the game. a really good site to play it is
http://javanoid.com/javanoid.html
also make sure your coding really efficiently because the powerups will be very tough to make. the reason i say this is because even when u get them fully working you'll run into a lot of problems such as if the ball is coming back and hits the powerup while its going down then the powerup will disapear. it is very tough with the powerups so good luck. post it when your done!
p.s. to make this game it took me about 2 weeks. approximately 1000 lines of code but thats because i included a menu, instructions, high scores, passwords, and levels.
|
|
|
|
|
|
NikG
|
Posted: Fri Mar 17, 2006 12:49 pm Post subject: (No subject) |
|
|
Quote: firstly the bricks part is a lot more coding for changing angles than the paddle. the reason i say this is when the ball hits the brick u want it to change the direction and the angle and go the opposite (right left) direction than u were originally goin.
for example:
the ball is going the right direction up and hits the bottom of the brick. now the ball should go down and instead of going down the same path it should change direction and go down and right.
I'm not sure I understand. Of course when the ball hits the block it will change direction and angle (45 degrees becomes 135 degrees).
But doesn't it do exactly the same thing when it hits the paddles? It has to go up instead of continuing down and the angle has to be the opposite as well.
However, when I talked about angle changing, that's not what I meant. If you look at my code, I code so that the angle is always between 0 and 90 (never above). I do this because I find I have better control over movement by using direction multiplies (xBallDir changes from 1 to -1) to see whether it changes from right to left (as opposed to the angle changing from 135 degrees to 45 degrees). My point is I have this part down.
What I did mean by angle-changing is to actually change the horizontal/vertical direction the ball normally moves in, not when it changes direction by hitting something. I don't know if you noticed but when you run my code up above and the ball hits the paddle while it's moving, the actual angle of the ball changes as well.
Btw, thanks for the link, thats an addicting game.
|
|
|
|
|
|
|
|