Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Ball physics (Pong / Breakout)

Author
Message
DerCel
12
Years of Service
User Offline
Joined: 3rd Jul 2012
Location:
Posted: 5th Jul 2012 18:42
Hi all,

I tried to start with something simple like Pong and if I get more used to AppGameKit try and do something Breakout style.

First steps were promising. I managed to set up the physics correctly(?) using dynamic for the ball and kinetic for the paddles, giving the ball a small impulse to get it going in the beginning.

Now (as you'd expect) I am facing a problem that I cannot solve although I think that it cannot be that complicated:

- How can I maintain a set speed of the ball? If it hits a moving paddel for example it loses much of it's speed depending on the angle. I tried with damping and even restricted the angular velocity (which didn't work at all).

- In case you hit it perfectly the ball goes straight up and down indefinitely?

For the second one I came up with the following lines of sloppy code but I'm pretty sure that there are better ways:


As usual thanks a lot for your help,
Cel
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 6th Jul 2012 12:01
Have you used SetSpritePhysicsRestitution(sprite,1). this will ensure the ball does not lose or gain energy when it collides.

SetSpritePhysicsFriction(sprite,0) will set the effect of friction when colliding. I'm not sure if this will reduce energy if greater than 0 or not. It might need some experimentation but my guess would be that a higher value will create more spin, allow a moving paddle to change the angle more dramatically and maybe prevent the up/down problem.

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 6th Jul 2012 16:55
Quote: "Have you used SetSpritePhysicsRestitution(sprite,1). this will ensure the ball does not lose or gain energy when it collides."

I found sometimes this causes an increase in speed (not sure why). I tend to use something more like 0.95 rather than 1 in my game "Flick Pong". If you set the speed of the ball manually after an impact it might be slightly more constant.

Make sure you aren't using setSpritePhysicsDamping too as this will slow your ball down.

I would set the velocity of the ball rather than using impulse as it seems like you want something less spongy than changing the speed gradually (which is what will happen using impulse).


this.mess = abs(sin(times#))
DerCel
12
Years of Service
User Offline
Joined: 3rd Jul 2012
Location:
Posted: 6th Jul 2012 21:34
Thanks a lot BatVink & baxslash,

This works like a charm now! To maintain the set speed I also had to set SetSpritePhysicsCanRotate of the ball to zero as else the ball would get slower with increasing angular velocity - not to mention that it makes it easier to play.

Quote: "
If you set the speed of the ball manually after an impact it might be slightly more constant.
"


How would that be done? I had a look at the available commands and could only find GetSpritePhysicsVelocityX and GetSpritePhysicsVelocityY which would give me the velocities before impact and then calculate the resulting exit angle?

Thanks a lot,
Cel
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 7th Jul 2012 09:16
Use setSpritePhysicsVelocity(spriteID,vx#,vy#)


this.mess = abs(sin(times#))
DerCel
12
Years of Service
User Offline
Joined: 3rd Jul 2012
Location:
Posted: 10th Jul 2012 17:36
Hi all,

I'm afraid that I need your help once again. I managed to get a breakout "game" working so far complete with ball collision handling of blocks and paddle, a score, etc.

I create the blocks using the makeobjectblock UCF in a for/next loop until the total number of blocks is reached. (I know ... a level looking like a colored Excel sheet is not the most entertaining view but it works!)

Now I wanted to add properties to the sprites/blocks like "state" (indestructible for example) and "power up included".
Unfortunately I ran out of ideas - well to be honest a multi dimensional array like: DIM block[totalblocks, state, power] was my only idea and this of course didn't work ...

It works fine for power ups if I randomize it but for setting-up solid blocks a randomizer could be a game breaker.

Maybe someone of you did something similar already and can point me to the right direction?

As usual thanks a lot for your help!
Cel
DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 11th Jul 2012 15:14 Edited at: 11th Jul 2012 15:19
Well, I recommend you read up the tutorials included with AppGameKit, it will help you with some of this sort of thing.
But you are on the right track. You could try DIM block[totalblocks,3]. There 1 is your id ref number, 2 will be your state variable and 3 will be power.
For example.
block[totalblocks,2]=1 `state
block[totalblocks,3]=100 `power

Or you could use types.
So,

That's a couple of ideas, you will find explanations of types in the guide as I said. However for some things the first method is easier, as numbers are easier to loop through than names.
Hope that helps.

Edit - oh forgot to mention, if you don't know, you can then use something like this using the type method.

block[totalblocks].power=10
block[totalblocks].state=1

DerCel
12
Years of Service
User Offline
Joined: 3rd Jul 2012
Location:
Posted: 12th Jul 2012 15:52
Hi DVader,

Thanks a lot for your help, I got it working! I decided to go for the TYPE variant as then I can add whatever values I want.

I will follow your advice and check the tutorials.

Thanks again,
Cel
DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 13th Jul 2012 16:05
Happy to help, the tutorials look quite good for beginners when I glanced over them, :p. They certainly cover this sort of thing. Glad you got it working!

Login to post a reply

Server time is: 2024-11-23 17:36:41
Your offset time is: 2024-11-23 17:36:41