Posted: 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
%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
%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
Sponsor Sponsor
MihaiG
Posted: 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.
Swimmer
Posted: 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
Swimmer
Posted: 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
Posted: 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
Posted: 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
Swimmer
Posted: 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?
Swimmer
Posted: 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
Sponsor Sponsor
MihaiG
Posted: 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
Raknarg
Posted: 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:
name (1):="George"
name (2):="Jake"
name (3):="Sally"
name (4):="Timmy"
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!
Turing:
var name1, name2, name3, name4 :string
get name1
get name2
get name3
get name4
%Here is the same thing with arrays:
var name :array1.. 4ofstring
for i :1.. 4 get name (i) endfor
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:
Turing:
var box :array1.. 3, 1.. 3ofint
for i :1.. 3 for j :1.. 3
box (i, j):= Rand.Int (1, 255) endfor endfor
%Now lets say you needed to store this and use it later:
var thirdx :int:=maxxdiv3 var thirdy :int:=maxydiv3
for i :1.. 3 for j :1.. 3 Draw.FillBox((i - 1)* thirdx, (j - 1)* thirdy, (i)* thirdx, (j)* thirdy, box (i, j)) endfor endfor
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.
Swimmer
Posted: 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
Insectoid
Posted: 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?
Swimmer
Posted: 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
Insectoid
Posted: 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?
Swimmer
Posted: 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