quicker way to make bricks for brick breaker...
Author |
Message |
Velocity

|
Posted: Mon Dec 12, 2011 10:10 pm Post subject: quicker way to make bricks for brick breaker... |
|
|
so anyways this whole time i was working on a brick breaker game vs AI, well now i need to make the actual bricks, how would i go about donig this?
I dont want to actually drawfillbox for all of them, is there a quicker way? Please help me, i want to know how i would go about doing this! |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
Insectoid

|
Posted: Mon Dec 12, 2011 10:34 pm Post subject: RE:quicker way to make bricks for brick breaker... |
|
|
Arrays and for loops. |
|
|
|
|
 |
RandomLetters
|
Posted: Mon Dec 12, 2011 11:04 pm Post subject: RE:quicker way to make bricks for brick breaker... |
|
|
A 2D array of integers representing a grid of bricks also lets you "draw" levels.
You will need to use some math to convert the row column coordinates in the array into x y coordinates on the screen |
|
|
|
|
 |
Aange10

|
Posted: Tue Dec 13, 2011 12:48 pm Post subject: RE:quicker way to make bricks for brick breaker... |
|
|
If you look at the Turing submissions under the brick breaker I posted about a week ago, you could see how to do them like RandomLetters said; to use a 2d array as a grid. |
|
|
|
|
 |
programmer1337
|
Posted: Tue Dec 13, 2011 3:23 pm Post subject: RE:quicker way to make bricks for brick breaker... |
|
|
Insectoid would be the best suggestion  |
|
|
|
|
 |
Velocity

|
Posted: Wed Dec 14, 2011 8:47 pm Post subject: RE:quicker way to make bricks for brick breaker... |
|
|
i love all your posts but i just chose to draw them, because i dont want to confuse my meeble mind. |
|
|
|
|
 |
Linkxgl
|
Posted: Wed Dec 14, 2011 10:47 pm Post subject: Re: RE:quicker way to make bricks for brick breaker... |
|
|
Velocity @ Wed Dec 14, 2011 8:47 pm wrote: i love all your posts but i just chose to draw them, because i dont want to confuse my meeble mind.
Not really the best way to go about it... What if you want to change the size of the bricks, or colours? It also gets confusing looking at that all the time... Here, I made a simple script you can understand...
Turing: |
proc makeBricks (len_,wid_,col_,xbound_,ybound_,spacex_,spacey_: int) %I'll explain each one throughout the code...
var len: int:=len_ %This will be the length of the brick
var wid: int:=wid_ %This will be the width of the brick
var col: int:=col_ %This will be the colour of the brick
var xbound: int:=xbound_ %This will be where you want the bricks to stop being made on the X
var ybound: int:=ybound_ %This will be where you want the bricks to stop being made on the Y
var spacex: int:=spacex_ %This will be the space between the bricks on the X
var spacey: int:=spacey_ %This will bet he space between the bricks on the Y
var displacex: int:=len+spacex %This will be the REAL size of the length from the added space between each length
var displacey: int:=wid+spacey %Same for this one but for the Y-Axis
var bricksx: int:= round(xbound/displacex ) % Calculates how many bricks can be put on one ROW, xbound, where you want the bricks to stop on the x, divided by the bricks REAL length
var bricksy: int:= round(ybound/displacey ) % Calculates how many bricks can be put on one COLUMN, ybound, where you want to stop on the y, divided by the bricks REAL wdith
var ar_len: int:=bricksx*bricksy- 1 % The TOTAL amount of bricks, basically the area formula, the reason for minus 1 is because I always start my arrays with 0... C++ and Python habit..
var cur_x: int:= 0 % This will be used later... It's the starting point of the bricks on the x-axis...
var cur_y: int:= maxy % This will be used later... It's the starting point of the bricks on the y-axis...
for i : 0..ar_len % Running for loop from 0 to the amount of bricks
drawfillbox(cur_x,cur_y-wid,cur_x+len,cur_y,col ) % Drawing a box... From the cur_x, cur_y-wid(So it doesn't go off screen),cur_x+len,cur_y(This will be at the top of the screen), colour.
cur_x:=cur_x+displacex % Add a brick AND space between new and previous brick (For the next cycle)
if cur_x+len > xbound then % We don't want the bricks to go off screen, once the x gets over the limit...
cur_x:= 0 % We reset the x position.
cur_y:=cur_y-displacey % Move one brick AND space on the y-axis
end if
delay(1) % A delay so you can see what haappens...
end for
end makeBricks
makeBricks (3, 1, 255, maxx, maxy, 2, 2)%Everything put together...
|
The code basically demonstrates how useful it actually is... What if you want to try 200 bricks? It's going to take a while to do that! The script took me 10 min to make, it's super simple and I took some extra time to add notes to almost every line!
Oh, and you can change any lower attribute like the in the for loop I do:
Turing: |
for i : 0..ar_len
|
You can change it to
Turing: |
for i : 1..ar_len
|
It's just that I get confused now when I start with 1 because I'm so used to starting with 0... I feel more comferatable like that... If you do change it though change this line:
Turing: |
var ar_len:int:=bricksx*bricksy-1
|
to
Turing: |
var ar_len:int:=bricksx*bricksy
|
That's it!
Basically, to use the procedure all you do is the following...
1) 1st and 2nd parameters: Length and Width of the brick in integers
2) 3rd parameter: Colour of the brick in Turing numbers...
3) 4th and 5th parameter: How far you want the bricks to go to the right of the screen, and how far you want the bricks to go to the bottom of the screen
4) 6th and 7th parameter: The space between the bricks on the x-axis, and the space in between the bricks on the y-axis...
Hopefully you will learn something from this, but if not, I was entertained for a good 10 minutes haha
EDIT
Here's a shorter version of the code... I just took out all the comments and the unneeded variables in the procedure, I don't re-defined the variables so it would be easier to understand. Again, there may be better ways to do it, but this is probably the best way you get can understand!
Turing: |
proc makeBricks (len,wid,col,xbound,ybound,spacex,spacey: int)
var displacex: int:=len+spacex
var displacey: int:=wid+spacey
var bricksx: int:= round(xbound/displacex )
var bricksy: int:= round(ybound/displacey )
var ar_len: int:=bricksx*bricksy- 1
var cur_x: int:= 0
var cur_y: int:= maxy
for i : 0..ar_len
drawfillbox(cur_x,cur_y-wid,cur_x+len,cur_y,col )
cur_x:=cur_x+displacex
if cur_x+len > xbound then
cur_x:= 0
cur_y:=cur_y-displacey
end if
delay(0)
end for
end makeBricks
makeBricks (3, 1, 255, maxx, maxy, 2, 2)
|
|
|
|
|
|
 |
Velocity

|
Posted: Mon Dec 19, 2011 5:46 pm Post subject: RE:quicker way to make bricks for brick breaker... |
|
|
wow link thank you so much for that! i was going to give bits on sight, tysm!
RE: And Karma, thanks. |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
|
|