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 / 2D Movement Vectors?

Author
Message
Yodaman Jer
User Banned
Posted: 12th Jan 2015 19:58 Edited at: 12th Jan 2015 19:59
Hi all,

I'm currently trying to create my own version of Breakout/Pong using AppGameKit v2, and a problem I'm having is that I can't get the ball to reverse its direction properly.

This is how I'm handling movement now... (ball.sx stands for "speed x", same for ball.sy)


It works for the most part, except that it will NEVER execute the "reversal" code for the y movement of the ball, only the x movement, but what it does execute is flawless and works as expected.

It occurred to me that if I could store the movement in some kind of vector, this would be a lot easier - all I would have to do then is say something like:

moveVector = -moveVector + speed_increase
, which could go underneath the if-then statement of course. But I would still have the problem of determining which side of the brick the ball hit but that's relatively easy!

I tried searching the documentation but I found nothing about 2D vectors, just ones for 3D. Does anybody have any solutions?

I would love to get this game working, I'm very determined to complete it! I'm so close but so far at the same time.

Edited for typos...


It's back, baby!
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 12th Jan 2015 20:12
I had written a breakout tutorial but I can't find it at the moment.

Try this instead:
ball.sx = -(ball.sx + speed_increase)

So your ball increases speed whenever it hits a wall?


"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
Yodaman Jer
User Banned
Posted: 12th Jan 2015 20:16
Yes, it increases when it hits walls and the bricks. And that way is definitely cleaner than the way I had written!

Any idea as to why it would execute the top part of that code block just fine but never seems to execute the ElseIf part?


It's back, baby!
george++
AGK Tool Maker
16
Years of Service
User Offline
Joined: 13th May 2007
Location: Thessaloniki, Hellas
Posted: 12th Jan 2015 20:47 Edited at: 12th Jan 2015 20:51
With no comments

Yodaman Jer
User Banned
Posted: 13th Jan 2015 20:49
Thanks george++, that looks great!


It's back, baby!
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 13th Jan 2015 22:34
Oh, if you were just looking for a vector library:
http://forum.thegamecreators.com/?m=forum_view&t=192569&b=6


"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
george++
AGK Tool Maker
16
Years of Service
User Offline
Joined: 13th May 2007
Location: Thessaloniki, Hellas
Posted: 13th Jan 2015 22:52
Oh.. nice share Phaelax
I am wondering where I could use the 'linearInterpolateVector2' function
Jukuma
20
Years of Service
User Offline
Joined: 18th Nov 2003
Location: Germany
Posted: 14th Jan 2015 03:16 Edited at: 14th Jan 2015 03:45
Cosinus Interpolate

Yodaman Jer
User Banned
Posted: 14th Jan 2015 03:52
Phaelax you are a life saver! That's exactly what I was hoping for!

You may have just saved my sanity, thank you!


It's back, baby!

Login to post a reply

Server time is: 2024-05-05 23:52:37
Your offset time is: 2024-05-05 23:52:37