Beginner question

Blitz3D Forums/Blitz3D Beginners Area/Beginner question

TomShep(Posted 2012) [#1]
Hello,

I am very new to blitz and programming in general - but try to make smallish games to help learning process-however - have come across something Im a bit stuck on.

Im trying to make a small game when blocks fall from the top of the screen and then land at the bottom of the screen, or on top of the blocks underneath (I suppose like tetris)

I have the blocks falling properly but getting only the relevant ones to stop is causing me problems, e.g

For b.block = Each block
DrawImage img_block,b\x,b\y
b\y = b\y + gravity
If b\y < 568 gravity = 0
Next

Obviously this stops all the blocks where they are at as soon as one hits the bottom, the line;

If b\y < 568 then b\y = 568 is fine for a bottom layer of blocks, but i can not get the blocks to land ontop of one another. Further, I cannot use the imagescolllide command to only refer to the actualy blocks colliding

Can anybody help? Any help at all would be greatlyappreciated.
Tom


Adam Novagen(Posted 2012) [#2]
Well, the first part of your problem is easily solved: give each block its own gravity.
For b.block = Each block
    DrawImage img_block,b\x,b\y
    b\y = b\y + b\gravity
    If b\y < 568 b\gravity = 0
Next

For a more compact solution, reverse your problem. Rather than stopping gravity when a block reaches a certain height, only move the block if it hasn't reached its intended position yet, e.g.:
For b.block = Each block
    DrawImage img_block,b\x,b\y
    If b\y > 568 Then b\y = b\y + gravity
Next


Last edited 2012

Last edited 2012


Ross C(Posted 2012) [#3]
If you are doing a tetris type game, I think you are better to create a container for your dropped blocks. An Array:


Dim Play_Area(6,20) ; 7 wide by 21 tall.



Anytime a block has fallen and is resting in position, place a 1 in the array slot. You can also use this to determine where to stop a block, and whether it will collide with a block. When your block is falling, assign it to a grid slot in the array.

When it moving between grid slots, check the grid slot underneath to see if it contains a 1:

If it does, the block cannot fall anymore. Leave that array slot with a 1 in it.

If it does not, then place a one in the new array slot, and delete the previous one (set it to zero)




Ross C(Posted 2012) [#4]
Here is some example code to work from, when dealing with an array play area. It's very basic, and I have tried to comment the best I can. It doesn't use types for simplicity. Arrow keys DOWN, LEFT and RIGHT to operate:



Last edited 2012

Last edited 2012


TomShep(Posted 2012) [#5]
Thanks you all for your comments and code pieces - I am hugely appreciative,

Tom