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.

Newcomers AppGameKit Corner / better ball control

Author
Message
alphabravoab
8
Years of Service
User Offline
Joined: 30th Oct 2015
Location:
Posted: 7th Nov 2015 11:49
I started playing with AppGameKit and made a variation of pong (I've seen this version here and there not sure if it had a name) my biggest problem at the moment is my ball control. As soon as it hits a brick atm it reverses directions in both x and y axis. Is there a way to see what way it hits and only reverse that direction, or a better way to set up the ball bouncing? Another problem I have is that atm the ball always travels at a 45 degree angle while I like pong I want the angle to be more variable. Preferably like pong or breakout the more to the side you hit a paddle or block the steeper the hook. Is there anyway to set that up and if does anyone know how.

Another weird thing is that as soon as it hits one paddle the score goes up 30 points even if only 10 should have been added.

And be kind it's my first program evarrr. Or better yet if you have some tips for tutorials or for code optimization I'm really interested.

I also uploaded the png's for everything incase someone is interested. They're nothing special just made them real quick for this program.

Attachments

Login to view attachments
29 games
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 7th Nov 2015 21:14 Edited at: 7th Nov 2015 21:15
Hi alphabravoab,

I had a quick look at this and came up with a simple solution:



When the ball hits the block the code compares the position of the ball to the position of the block and from this it can tell with the ball has hit the bottom/top of the block or the sides. If it hits the top/bottom then the y direction is reversed. If it hits the sides then the x direction is changed.

I also added a couple of other bits and pieces but the most important one is that the block sprite should not be deleted and recreated whilst the game is being played as this can slow the app down if you're using a lot of sprite or on an old device. In this case the block can simply be repositioned. If the blocks are being destroyed when the ball hits them then just position the block somewhere off the screen where it won't get bit by the ball: -1000,-1000 for example. This is a rather crude way of doing this but it'll work fine for what you're doing.
Invaders of the 29th Dimension - available now on Google Play
Find me on indieDB
alphabravoab
8
Years of Service
User Offline
Joined: 30th Oct 2015
Location:
Posted: 8th Nov 2015 12:58
Thanks for the fast reply, good tips and rewrite of the code they're working great. I'm playing a bit with the code now to understand what it all does.

Just one question remains is it possible like the normal pong that the more to the side of the paddle the ball hits the more of a curve ball you get?

alphabravoab
8
Years of Service
User Offline
Joined: 30th Oct 2015
Location:
Posted: 9th Nov 2015 17:13
For other newcomers that want to use this code to make a pong version or run into simulaire problems. I solved my score problem mostly thanks to 29games.
I started by changing the codes for the paddles.



It gives a funny effect of staying glued to the paddle. This is usefull if you want to use it as a special powerup maybe. Also it showed me that the reason I got a triple score with each hit is that it takes 3 loops to break the contact. A simple solution for now is setting the ballx or bally (depending on the paddle that hits) 10 pixels further. So it breaks contact in the first loop. For the pro's this will probarbly be obvious but for noobs such as I (and maybe someone else) it took a while to see.
This is the new code.


I hope I've been a help to another newbie that wants to try his hand at this and if it the program is finished I'll turn it into a tutorial for other people if there is a request for it.

Login to post a reply

Server time is: 2024-03-28 08:56:49
Your offset time is: 2024-03-28 08:56:49