Page 1 of 1

Drawin issues: bottom line & window freezing

Posted: Mon Feb 27, 2012 7:27 pm
by evilgravedigger
Okay, what I have is a very basic block game, which computer plays with itself :mrgreen:
I have 2 questions about it:

1) How do I remove the bottom line, when it's filled with boxes and move the whole image down, like in tetris?
3) How do i avoid program freezing? When I click the window, program freezes and the image dissapears. Same happens when closing the window.
Here comes the code:

Code: Select all

beginit:
      StartDrawing(WindowOutput(0))
              Box(0,0,400,400,#Black) ; General field
      DrawingMode(#PB_2DDrawing_Outlined )

          Dim lowfields.i(20) ; lowfields array, to make a box understand when it should stop falling
          some1 = 380   
          ll = 1
 For z = 1 To 200
   
   wof = Random(19) ; vertical position to start
   If lowfields(wof) = 20 : Goto stopit : EndIf ; If a box reaches the top of the field, we start again

   some = some1 - lowfields(wof)*20 ; Fall until reaching some other box
   
                   For x = 0 To some Step 20 ; falling of a box

           Delay(10)
           Box(wof*20,x,20,20,RGB(Random(100)+100,Random(100)+100,Random(100)+100))
           Box(wof*20,x-20,20,20,#Black) ;covering the previously drawn position to have moving effect.
           
         Next
         lowfields(wof) + 1; The next box knows when to stop now.
      Next
            stopit:
        StopDrawing() 
            Goto beginit
Can anyone please help me? :(

Re: Drawin issues: bottom line & window freezing

Posted: Mon Feb 27, 2012 10:40 pm
by infratec
Hi,

let's begin with 3)

if you draw on the window, it is not refreshed.
You have to use an ImageGadget() or a CanvasGadget().
They are automatically refreshed.
Also you should use a timer (AddTimer()) for your falling events.
Else you can react on nothing during your program.

1)
You need 2 images.
If the line is full, simply grab the stuff above the line and put it into the second image
See GrabImage()

Bernd

Re: Drawin issues: bottom line & window freezing

Posted: Mon Feb 27, 2012 11:41 pm
by Demivec
You apparently open a window so you also need an event loop to handle events. Your program will then be able to respond to events such as refreshing or closing the program.


You also need other things. Take it in steps and fix one thing at a time.

Re: Drawin issues: bottom line & window freezing

Posted: Tue Feb 28, 2012 10:49 am
by evilgravedigger
I solved freezing problem. I just added waitwindowevent(1) to the loop, works like a charm now.