Drawin issues: bottom line & window freezing

Just starting out? Need help? Post your questions and find answers here.
evilgravedigger
New User
New User
Posts: 8
Joined: Thu Feb 23, 2012 1:06 pm

Drawin issues: bottom line & window freezing

Post 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? :(
infratec
Always Here
Always Here
Posts: 7583
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Drawin issues: bottom line & window freezing

Post 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
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Drawin issues: bottom line & window freezing

Post 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.
evilgravedigger
New User
New User
Posts: 8
Joined: Thu Feb 23, 2012 1:06 pm

Re: Drawin issues: bottom line & window freezing

Post by evilgravedigger »

I solved freezing problem. I just added waitwindowevent(1) to the loop, works like a charm now.
Post Reply