Brick Breaker... Please Help
Author |
Message |
miller6
|
Posted: Tue Jan 26, 2010 7:49 pm Post subject: Brick Breaker... Please Help |
|
|
What is it you are trying to achieve?
Making the game Brick Breaker in Turing.
What is the problem you are having?
Getting two pictures to move at once (the sliding box and bouncing ball)
Describe what you have tried to solve this problem
EVERYTHING
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>
Turing: |
setscreen ("nocursor")
setscreen ("graphics:vga")
var WinId : int
var ch : string (1) % box move
const right := chr (203) % box move
const left := chr (205) % box move
var counter_b : int := 10 % counter for the box moving
var width_b : int := 180 % box width
var length_b : int := 28 % box length
var pic : int := Pic.FileNew ("sflake.gif")
var pic_x : int := maxx
var pic_y : int := maxy
var pic_width : int := 59
var borderx1 : int := 1
var bordery1 : int := 20
var borderx2 : int := maxx
var bordery2 : int := maxy
var x_angle, y_angle : int := 1
var b_colour : int := brightcyan
var box : int := Pic.FileNew ("box.bmp")
var score : int := 0
WinId := Window.Open ("position:centre;centre,graphics:1010;695")
Draw.Box (borderx1, bordery1, borderx2, bordery2, 104)
Draw.Box (1, 1, maxx, 28, 41)
View.Set ("offscreenonly")
loop
drawfillbox (1, 1, maxx, maxy, 104)
drawfillbox (1, 1, maxx, 28, 39)
drawfillbox (500, 500, 625, 520, b_colour )
drawfillbox (500, 400, 625, 420, b_colour )
drawfillbox (550, 450, 675, 470, b_colour )
drawfillbox (550, 550, 675, 570, b_colour )
drawfillbox (320, 500, 445, 520, b_colour )
drawfillbox (375, 550, 500, 570, b_colour )
drawfillbox (320, 400, 445, 420, b_colour )
drawfillbox (375, 450, 500, 470, b_colour )
drawfillbox (210, 550, 335, 570, b_colour )
drawfillbox (210, 450, 335, 470, b_colour )
drawfillbox (160, 500, 285, 520, b_colour )
drawfillbox (160, 400, 285, 420, b_colour )
drawfillbox (720, 550, 845, 570, b_colour )
drawfillbox (665, 500, 790, 520, b_colour )
drawfillbox (665, 400, 790, 420, b_colour )
drawfillbox (720, 450, 845, 470, b_colour )
Pic.Draw (box, counter_b, 1, picCopy)
if hasch then
getch (ch )
if ch = right then
counter_b := counter_b - 10
elsif ch = chr (205) then
counter_b := counter_b + 10
end if
Pic.Draw (box, counter_b, 1, picCopy)
cls
if counter_b + width_b >= maxx then
counter_b := counter_b - 10
elsif counter_b <= 0 then
counter_b := counter_b + 10
end if
end if
Pic.Draw (box, counter_b, 1, picCopy)
Pic.Draw (pic, pic_x, pic_y, picMerge)
pic_x := pic_x + x_angle
pic_y := pic_y + y_angle
% OUTSIDE COLLISION
if pic_y + pic_width >= maxy then
x_angle := Rand.Int (- 3, 3)
y_angle := Rand.Int (- 3, - 1)
elsif pic_y <= bordery1 then
cls
put "YOU LOOSE"
delay (500)
cls
elsif pic_x + pic_width >= maxx then
x_angle := Rand.Int (- 3, - 1)
y_angle := Rand.Int (- 3, 3)
elsif pic_x <= borderx1 then
cls
put "YOU LOOSE"
delay (500)
exit
elsif pic_x >= (counter_b ) and (pic_x + pic_width ) <= (counter_b + 180) and (pic_y ) >= (1 + 28) then
x_angle := Rand.Int (- 3, 3)
y_angle := Rand.Int (1, 3)
end if
Pic.Draw (pic, pic_x, pic_y, picMerge)
delay (1)
View.Update
end loop
|
Please specify what version of Turing you are using
4.1.1
Description: |
|
Filesize: |
2.45 KB |
Viewed: |
2198 Time(s) |

|
Description: |
|
Filesize: |
11.76 KB |
Viewed: |
84 Time(s) |

|
|
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
ProgrammingFun

|
Posted: Wed Jan 27, 2010 9:40 am Post subject: RE:Brick Breaker... Please Help |
|
|
You could go offscreenonly then specify new coordinates for the pics and then View.Update.
|
|
|
|
|
 |
TheGuardian001
|
Posted: Wed Jan 27, 2010 10:38 am Post subject: Re: RE:Brick Breaker... Please Help |
|
|
ProgrammingFun @ Wed Jan 27, 2010 9:40 am wrote: You could go offscreenonly then specify new coordinates for the pics and then View.Update.
That's what they're doing now...
Is there a reason that you're drawing the pic "box" 3 times inside of a single loop, and the pic "pic" twice? You should only be drawing each of these once per repetition. Drawing more than once will either be pointless (if they're all in the same position), or create multiple images (if they aren't.) In your code:
Turing: |
Pic.Draw (box, counter_b, 1, picCopy) %POINTLESS. box hasn't moved yet, and will be redrawn after moving
if hasch then
getch (ch )
if ch = right then
counter_b := counter_b - 10
elsif ch = chr (205) then
counter_b := counter_b + 10
end if
Pic.Draw (box, counter_b, 1, picCopy) %POINTLESS. drawn then immediately cls'd
cls
if counter_b + width_b >= maxx then
counter_b := counter_b - 10
elsif counter_b <= 0 then
counter_b := counter_b + 10
end if
end if
Pic.Draw (box, counter_b, 1, picCopy) %GOOD! only this one is necessary (or helpful).
|
You do a similar thing with the other image (draw move draw). You also draw the images at completely different times. Although this generally won't make a difference (since you're using offscreenonly,) however it's still a good idea to group that stuff together wherever possible, IE
code: |
loop
%All movement code here (no drawing)
move_box
move_pic
%All drawing code here
draw_box
draw_pic
View.Update()
cls
end loop
|
However I'd assume the main problem is a combined lack of cls outside of an if and the fact that you drew each image multiple times. Look into those.
|
|
|
|
|
 |
|
|