| Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next 1 | 1. Making 2D game with mouse input... #4847 Posted by: JonA 2004-07-19 06:36:07 | I am trying to build a game very similar to Collapse...and I am new to BASIC.
I guess it is sort of foolish of me to just jump right in, but I really wanted to try this.
I have the interface set up, and the title screen images, etc. I need to know how to put them in my game. Now, I was using the form editor, and had the images displaying, but I can only get them to work in a 'bsSizeable' border. Anything else I try just ends up looking like 'bsNone'. I need a window that can be closed by clicking on the X, and minimized by clicking on the _, but not resizeable--i.e. no button to full screen, and no window resize arrows poping up. How can I do this?
How could I set it up so that when the next row of blocks was coming up, they would be random, and then when it was done filling up that row, it pushed the whole thing up? Also, I need to set it so that when I click on three of the colored squares in a group they dissapear, and that only so many rows come up each level... (like Collapse).
Plus! How can I make sound...I am on Win XP, and I read something about there being sound issues when using XP...what are those issues, and can I run sound? 'Cause I can get most of the rest of the program to work on XP?
Thank you, JonA | 2. Re: Making 2D game with mouse input... #4872 Posted by: 2004-07-21 20:37:36 | I take it that you are using separate images for the blocks, painting each one individually rather than "pasting" the images to a single graphics area? While this has the advantage of making each image click-able it also means you end up with devilishly difficult code ....
Rather than using the form editor to build your form (at least as far as the images are concerned) write code to build up the playing field. I don't know what size those blocks of yours are so change H and V to suitable values in the code below. Don't know the playfield size (rows and columns) so change X and Y too!
H = 20 :
y = 10 :
V = 20 :
x = 10 :
DIM Image AS QCANVAS
Image.Height = H*y
Image.Width = V*x
Image.Left = 100
Image.Top = 2
Image.OnPaint = Image.Paint
Image.PARENT = Form
DIM grd(x,y)
SUB Image.Paint
FOR a=1 TO x
FOR b=1 TO y
HP = a*V-V : VP = b*H-H : bl = grd(a,b)
Image.draw (HP,VP,block(bl).BMP)
NEXT b
NEXT a
END SUB
See the animated gif question (my answer to it) for how to put the block images into the program (in the array BLOCK() in this case) and remember to include an 'empty' block.. Use the array GRD(a,b) to manage the playfield pattern with (in that array you can check for connected identical blocks etcetera).
Tha above code makes a single image area for your game, the Image.Paint routine refreshes the image after "overdraw". For drawing the game field you can use the same routine of course. If a new row comes in use the routine on a timer and shift the new row in a pixel at a time (do a loop in which VP is changed).
For the new row just fill the next line of the grid with random values (in a range) after shifting the existing values up in the GRD(,) array. Do not forget to use RANDOMIZE TIMER because otherwise those 'random values' will follow a set pattern. | 3. Re: Making 2D game with mouse input... #4881 Posted by: JonA 2004-07-22 17:04:37 | Thank you!
I will try to make sense out of all that, and see what I can actually 'do' before I need more help. This will take me a while I see...the only thing that I have ever workied with in BASIC has been my calculator (hardly anything like this).
Is there anything that I can do about the form border? And what about adding sound?
Thankyou soo much, JonA | 4. Re: Making 2D game with mouse input... #4884 Posted by: 2004-07-22 22:04:49 | A bit more code for you;
DECLARE SUB TIJTH (sender AS QTIMER)
$RESOURCE m1 AS "p1.bmp"
.......
$RESOURCE m18 AS "pi.bmp"
RANDOMIZE TIMER
DIM pat(18) AS QIMAGE
pat(1).BMPhandle = m1
.......
pat(18).BMPhandle = m18
DIM Form AS QFORM
form.CAPTION = " Pattern demo"
form.Width = 600
form.Height = 460
form.Center
H = 48 : V = 48 :Row = 6: Col = 6
DIM grd(col,row+1)
FOR x=1 TO col : FOR y=1 TO row
grd(x,y)=0
NEXT y : NEXT x
br = H * Col + 2
ho = V * (Row+1) + 2
pinr = 1
nob = 18
DIM Image1 AS QCANVAS
Image1.PARENT = form
Image1.Left = 30
Image1.Top = 10
Image1.Width = br
Image1.Height = ho
DIM klok AS QTIMER
klok.interval = 1000
klok.ontimer = TIJTH
Form.SHOWMODAL
SUB SHIFTUP
pinr=1
FOR x=1 TO col : FOR y=2 TO row+1
block = grd(x,y)
grd(x,y-1) = block
NEXT y : NEXT x
FOR x=1 TO col : grd(x,row+1)=0 : NEXT x
END SUB
SUB TIJTH (sender AS QTIMER)
Image1.FillRect(0,0,br,ho,&hffffff)
Image1.Rectangle(0,0,br,ho,&H00e000)
FOR x=1 TO col : FOR y=1 TO row+1
block = grd(x,y)
IF block>0 THEN
Image1.Draw(x*H-H+1,y*V-V+1,pat(grd(x,y)).BMP)
ELSE
Image1.FillRect(x*H-H+1,y*V-V+1,x*H+1,y*V+1,&hffffff)
END IF
NEXT y : NEXT x
IF pinr<col+1 THEN
block = INT(RND*nob)+1
grd(pinr,row+1) = block
pinr=pinr+1
ELSE
SHIFTUP
END IF
END SUB
The SHIFTUP isn't smooth this way of course but it'll do (you can refine it to a by-pixel upward shift). Just change it to include your own graphics (blocks) at the start (the .... lines are just space savers) and set NOB to the number of blocks you use. | 5. Re: Making 2D game with mouse input... #4891 Posted by: JonA 2004-07-23 07:39:34 | Ok, I get that. What about making the 'Game Over' when even one of the squares tries to go past the top? I would you if/then, but how would I know what square to use? Would I have to put it for all of the squares, or should I use something other than if/then or cases?
Also, when I try to run the first bit of code that you gave me, I get an error:
Line 12: ERROR: Expected QT type but got FORM randomblocks.bas: In main section randomblocks.bas: Image.PARENT = Form randomblocks.bas: ^-- error
What causes this?
Thankyou, JonA | 6. Re: Making 2D game with mouse input... #4892 Posted by: 2004-07-23 13:59:16 | That was just a small bit of code, you'd still have to set up a form (for which I used the name FORM). Using DIM rather than CREATE means you have to attach the element(s) to the form (create automatically stes the PARENT property).
SUB SHIFTUP
gmvr = 0
pinr=1
FOR x=1 TO col : FOR y=1 TO row+1
IF y>1 THEN grd(x,y-1) = grd(x,y)
IF y=1 AND grd(x,y)>0 THEN gmvr=1
NEXT y : NEXT x
FOR x=1 TO col : grd(x,row+1)=0 : NEXT x
IF gmvr>0 THEN Form.CAPTION = "game over!"
END SUB
A simple "game over" check; if a non empty (non zero) block gets shifted (in any column) you get a game over (of sorts). Compare this to the previous code / routine.
In game you'd use the game over condition to turn off the timer;
klok.enabled = 0
(of course you can turn it back on by using = 1).
| 7. Re: Making 2D game with mouse input... #4898 Posted by: 2004-07-25 03:45:45 | Ah mouse input, better show you some way to do THAT eh ;)
DECLARE SUB MouseSelect (MouseButton AS LONG, X AS LONG, Y AS LONG, Shift AS LONG, Sender AS QIMAGE)
DIM Image1 AS QCANVAS
Image1.PARENT = form
Image1.Left = 60
Image1.Top = 60
Image1.Width = br
Image1.Height = ho
Image1.OnMouseDown = MouseSelect
SUB MouseSelect (MouseButton AS LONG, X AS LONG, Y AS LONG, Shift AS LONG, Sender AS QIMAGE)
hp=INT(X/H)
vp=INT(Y/V)
a$=" column "+STR$(hp)+" row "+STR$(vp)
form.CAPTION = a$
Image1.Rectangle(hp*H+1,vp*V+1,hp*H+H+1,vp*V+V+1,&h3030ff)
END SUB
Add the declaration to the very start of the program. Append the last line to the Image1 declaration. Add the routine to the very end of the program.
Now you can click on a block on the graphics area to select it (and for a second you get a red outline).
As to making selected identical blocks disappear; work on the MouseSelect routine so that it checks to see what the clicked-on block is (using)
block = grd(hp+1,vp+1)
then use that to see if consecutively clicked blocks are the same. If they are remove them from the grid and call a routine that "collapses" the blocks above the gap (using a sort of inverted SHIFTUP if you catch my drift). | Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next 1 |
|
|