
-----------------------------------
miller6
Tue Jan 26, 2010 7:49 pm

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)




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 = maxy then
        x_angle := Rand.Int (-3, 3)
        y_angle := Rand.Int (-3, -1)
    elsif pic_y = maxx then
        x_angle := Rand.Int (-3, -1)
        y_angle := Rand.Int (-3, 3)
    elsif pic_x = (counter_b) and (pic_x + pic_width) = (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

-----------------------------------
ProgrammingFun
Wed Jan 27, 2010 9:40 am

RE:Brick Breaker... Please Help
-----------------------------------
You could go offscreenonly then specify new coordinates for the pics and then View.Update.

-----------------------------------
TheGuardian001
Wed Jan 27, 2010 10:38 am

Re: RE:Brick Breaker... Please Help
-----------------------------------
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:

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 