Computer Science Canada Can't bounce ball off of opposite wall; goes behind bricks and flickering too much - Need help with Brick Breaker |
Author: | Swimmer [ Fri May 31, 2013 4:30 pm ] |
Post subject: | Can't bounce ball off of opposite wall; goes behind bricks and flickering too much - Need help with Brick Breaker |
Here is my code so far if you could help that would be awesome! /* Name: Rewati Prakash Date: May 31st, 2013 Version: 1.0 Description: Brick Breaker by Rewati Prakash */ %Variable Declaration var key : array char of boolean var paddle, circlex, circley, paddleDirection, circledir, circleny, circlenx, speed, winner,leftWall : int %Variable Initialization paddle := maxy div 2 circlex := maxx div 2 circley := maxy div 2 circlenx := 5 circleny := 5 speed := 5 leftWall:= 300 View.Set ("graphics:600,300,offscreenonly, title: Brick Breaker Ultimate") %start Program loop %Controls Input.KeyDown (key) if key (KEY_UP_ARROW) and paddle <= 370 then paddleDirection := 1 elsif key (KEY_DOWN_ARROW) and paddle >= 75 then paddleDirection := 2 else paddleDirection := 0 end if if paddleDirection = 1 then paddle := paddle + 5 elsif paddleDirection = 2 then paddle := paddle - 5 end if %Title colourback (gray) %Draw ball , paddle, and range of ball for count : 1 .. 300 %paddle drawfillbox (maxx - 25, paddle - 70, maxx - 10, paddle + 20, purple) %Ball drawfilloval (circlex, circley, 15, 15, purple) %Range of ball drawbox (0, 0, 600, 300, gray) end for Time.Delay (35) %Ball Land on Paddle if circlex >= maxx - 25 then if paddle + 20 >= circley + 5 and paddle - 60 <= circley + 5 then circlenx := -speed speed := speed + 1 end if end if %Bricks View.UpdateArea (0, 0, 600, 300) var drawx : int := 10 var drawy : int := 265 for a : 1 .. 9 for b : 1 .. 4 drawfillbox (drawx, drawy, drawx + 40, drawy + 17, green) drawx := drawx + 50 end for drawx := 10 drawy := drawy - 30 end for View.Update %Bounce ball of bricks?? %bottom ground if circlex <= 10 then winner := 1 exit elsif circley <= 10 then circleny := speed end if %top ground if circlex >= maxx - 10 then winner := 2 exit elsif circley >= maxy - 10 then circleny := -speed end if %Left Wall ?? %Control movement of ball circlex += circlenx circley += circleny cls end loop %END |
Author: | MihaiG [ Fri May 31, 2013 5:03 pm ] |
Post subject: | Re: Can't bounce ball off of opposite wall; goes behind bricks and flickering too much - Need help with Brick Breaker |
Take a look into the View.Update a bit more. You want to clear the screen at the beginning of your loop and place "view.update" at the end. You seem to be missing the cls part! The second issue is due to the fact that you are using integers for all your math. You may need to resort to using real. Instead of using hardcoded values in your declaration for paddle with, declare some constants so when reads your code we can follow it much easier. It also helps to use to code tag with syntax highlighting for turing so it makes it easier to follow. You need to address the issue of bouncing of bricks or walls the same way you did with the paddle. You are currently drawing bricks with two for loops. This isn't good for what you need. You need to be able do address each brick with some kind of identifier. What kind of data structure could we use to address a grid of bricks? If you can figure that out, then you can realize you can assign each point in that grid a value, of 0-x, where x is the number of its it takes to destroy it and 0 means it's destroyed. The downside to this is you need to develop an algorithm similar to your for loop to draw the bricks based on the data structure you used. |
Author: | Swimmer [ Fri May 31, 2013 5:54 pm ] |
Post subject: | RE:Can\'t bounce ball off of opposite wall; goes behind bricks and flickering too much - Need help with Brick Breaker |
Thank you very much about the View.Update; the flickering is gone! I added the constants for the paddle and that works thanks ![]() Unfortunately I don't know how to use the same format for bricks or the wall And could we use an array as a grid of bricks (I don't really know what this is but if is is it I will read up on it) And how would this work please, I'm not very good at this and need more explanation |
Author: | Swimmer [ Fri May 31, 2013 5:55 pm ] |
Post subject: | Re: Can't bounce ball off of opposite wall; goes behind bricks and flickering too much - Need help with Brick Breaker |
Here is what I have so far except as an attachment |
Author: | Swimmer [ Fri May 31, 2013 5:57 pm ] |
Post subject: | RE:Can\'t bounce ball off of opposite wall; goes behind bricks and flickering too much - Need help with Brick Breaker |
Here is how I fixed the paddle %paddle drawfillbox (maxx - PADDLEX1, paddle -PADDLEY1, maxx - PADDLEX2, paddle + PADDLEY2, purple) |
Author: | Swimmer [ Fri May 31, 2013 5:58 pm ] |
Post subject: | RE:Can\'t bounce ball off of opposite wall; goes behind bricks and flickering too much - Need help with Brick Breaker |
It appears the flickering has come back |
Author: | Swimmer [ Fri May 31, 2013 6:09 pm ] |
Post subject: | RE:Can\'t bounce ball off of opposite wall; goes behind bricks and flickering too much - Need help with Brick Breaker |
Could I add a rectangle the width of the screen and attempt to bounce the ball off of that? or even a line? |
Author: | Swimmer [ Fri May 31, 2013 6:14 pm ] |
Post subject: | RE:Can\'t bounce ball off of opposite wall; goes behind bricks and flickering too much - Need help with Brick Breaker |
Hello please help soon |
Author: | MihaiG [ Fri May 31, 2013 6:42 pm ] |
Post subject: | Re: Can't bounce ball off of opposite wall; goes behind bricks and flickering too much - Need help with Brick Breaker |
Hi swimmer, please don't spam the thread, if you have additional questions you may edit your latest post and add them on there! It makes reading the thread much easier! an array basically is similar to a row in excel where each cell is an index of the array specified by what ever length and type you want it to contain. the advantage of an array is you can iterate through the array very quickly using for loops arrays can be even more complex, they can exand to 2d ie like 4x4 grid of blocks. Now these aren't real blocks but containers for your data type that your array was initialized with. Flickering might occur because your screenmode isnt correctly set, you need to be in setscreen ("offscreenonly") if i recall |
Author: | Raknarg [ Sat Jun 01, 2013 1:25 pm ] | ||||||
Post subject: | Re: Can't bounce ball off of opposite wall; goes behind bricks and flickering too much - Need help with Brick Breaker | ||||||
You might want to make your description less jargony. To rephrase, an array is like a variable that holds a bunch of variables together, where each of these is assigned a number and a value. Here's an example: Let's say we had a list of people in order, and we wanted to store their names. We could create a bunch of variables to do that, or we could use arrays. Look at this:
Now this isn't very useful. However, you notice how we call name using an integer? What do we have in turing that gives you a series of integers? For loops!
Look how much we shortened that! Now let's change it up a bit. You can also make an array that is two dimensional. Htink of it like if you had a long box with a bunch of compartments in it, then you had a big square box with rows and columns of compartments. Let's say we wanted to make the screen into nine boxes of random colours, we could do something like this:
Notice how I use i to represent my x and j to represent my y. It doesn't really matter, this is just traditional (or use i and ii). In my examples, I usually use the first number to represent the column number and the second number to represent the row, because it makes more sense in terms of x and y coordinates. |
Author: | Swimmer [ Sat Jun 01, 2013 3:07 pm ] |
Post subject: | RE:Can\'t bounce ball off of opposite wall; goes behind bricks and flickering too much - Need help with Brick Breaker |
Umm ... Thank you for the information on arrays How do we bounce the ball off the left wall |
Author: | Insectoid [ Sat Jun 01, 2013 3:16 pm ] |
Post subject: | RE:Can\'t bounce ball off of opposite wall; goes behind bricks and flickering too much - Need help with Brick Breaker |
How do you know if the ball has hit the wall? What do you change when the ball hits the wall? |
Author: | Swimmer [ Sat Jun 01, 2013 3:19 pm ] |
Post subject: | RE:Can\'t bounce ball off of opposite wall; goes behind bricks and flickering too much - Need help with Brick Breaker |
Not sure |
Author: | Insectoid [ Sat Jun 01, 2013 3:29 pm ] |
Post subject: | RE:Can\'t bounce ball off of opposite wall; goes behind bricks and flickering too much - Need help with Brick Breaker |
What is the ball's X value when it hits the left wall? |
Author: | Swimmer [ Sat Jun 01, 2013 3:53 pm ] |
Post subject: | RE:Can\'t bounce ball off of opposite wall; goes behind bricks and flickering too much - Need help with Brick Breaker |
don't know probably 0 right? |
Author: | MihaiG [ Sat Jun 01, 2013 5:08 pm ] |
Post subject: | Re: Can't bounce ball off of opposite wall; goes behind bricks and flickering too much - Need help with Brick Breaker |
Think of it like this.. if you bounce a ball off a wall in a perfect system. it bounces right back at you with the same speed.. so what has changed? well the speed is the same the the velocity a vector value has been multiplied by -1. Now we can extrapolate this into 2d, if we bounce it off a vertical plane the vertical component stays the same but the horizontal component gets reversed. |