Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Tetris considerations

Author
Message
Alkerak
15
Years of Service
User Offline
Joined: 7th Mar 2011
Location:
Posted: 14th May 2012 23:26
I am starting to write a tetris game, and although I know the commands I find it quite difficult since it's my first 2D game.
I wanted to know which approach is better.

1) Make the whole tetris blocks in a raster/vectoring program?
2) Make only one tetris tile in the aforementioned program and create the tetris shape in darkbasic?

Also ... how would I check if there is a clear lines condition?
I make a grid and the state of the grid checks wether it's full or not?
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 14th May 2012 23:57 Edited at: 15th May 2012 00:03
Make the graphics however you like, no speed issues. Personally, I would paste sprites.

You use Data for the lines.

1,1,1 is a red line
2,2,2 is a blue line
3,3,3 is a green line
4,4,4 is a yellow line
1,2,3 is not a line

1
1
1
...is a red vertical line

2
2
2
.. blue etc.


Make an array X,Y and fill it with those numbers as the shapes drop down.


Then Y will have a limit ...say 20. When the array = Y(21) > 0 then you have filled the frame.

Alkerak
15
Years of Service
User Offline
Joined: 7th Mar 2011
Location:
Posted: 15th May 2012 14:08
So basically I make the whole tetroshapes in a vectoring program. But they are sprites. How would I see if an L shaped piece is in what part of the array? I mean I must detect each block composing the shape in the array, right?
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 15th May 2012 16:26 Edited at: 15th May 2012 16:30
You don't need to detect the shapes. When you drop a block down you also update the array. Say a red L..

0,0,1
1,1,1

Rotated...

1,0,
1,0,
1,1,

Rotated...

1,1,1
1,0,0

Rotated...

1,1
0,1
0,1

Move the data down like that. Totally ignore the sprite shape, just make sure it matches the data. Then when it drops in place, you need to make sure that the zeros are added to the data at that location. So if a zero drops on a 2 you get 0+2. But if the zero drops on a zero it is 0+0 so still a hole.

Alkerak
15
Years of Service
User Offline
Joined: 7th Mar 2011
Location:
Posted: 15th May 2012 17:42
Ok, im kinda slow ...

Let's say I have a 20 height and 10 width grid which is represented by an array. I start dropping a shape.
The code detects based on the sprite name if it's an L shaped and it fills the array acordingly, right?
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 15th May 2012 18:10 Edited at: 15th May 2012 18:29
You move your shape down say 16 pixels at a time. You have to update the array as the shape falls. This code is a sort of rough idea, but will not work without being typed out properly, and I just used the first idea that came into my head, which can be improved on...

PSEUDO CODE...

Dim Map(10,22)... an extra few Y for the fill area
Dim RedLRow1(3)
Dim RedLRow2(3)

For n = 1 to 3
Read Red_LRow1(n)
Next n

For n = 1 to 3
Read Red_LRow2(n)
Next n

X = Drop_point
Y = 21

Move_shape_down 16 pixels
Dec Y

If map(X,Y) > 0 then your shape has collided with another block

Data 0,0,1
Data 1,1,1

Alkerak
15
Years of Service
User Offline
Joined: 7th Mar 2011
Location:
Posted: 15th May 2012 19:25
I see what is happening.
But why RedLRow array? And why two of them?
I mean an L Row is something like this

1 0 0
1 1 1

and can also be

1 1 0
1 0 0
1 0 0

so why 3 the array type?
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 15th May 2012 20:07 Edited at: 15th May 2012 20:17
You have 3 zeros at the end which is a space. You don't need an extra space at the end. But you don't need two rows either, you can write it like this...

Data 1,0,0,1,1,1

But I wanted you to see that it was a 'L' shape, because the above is more confusing. That's why Pseudo Code is written to be read easily, but the code isn't that good.

Alkerak
15
Years of Service
User Offline
Joined: 7th Mar 2011
Location:
Posted: 15th May 2012 20:51
Oh I get it. Makes sense!

So I hard code all the data of the shapes in a separate file?
I mean if I want to rotate a ship, do I hardcode also the rotated shape?

like:

data 0, 0, 1
data 1, 1, 1

data 1, 1
data 0, 1
data 0, 1
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 15th May 2012 21:00 Edited at: 15th May 2012 21:16
You can hard code them or you can read the array in different orders to fake rotate them. Just imagine that the Data is numbered...

No...1,2,3,4,5,6
Data 0,0,1,1,1,1

Then change the way that you look at the array. But it doesn't really matter if you hard code them. It's best to draw all of the art shapes though. You can have the highlight on the correct side, rotation will rotate the light source, unless you use 3D lights.

Alkerak
15
Years of Service
User Offline
Joined: 7th Mar 2011
Location:
Posted: 15th May 2012 21:07
Oh, ok, thanks for the help. Hope I can finish the game
zeroSlave
17
Years of Service
User Offline
Joined: 13th Jun 2009
Location: Springfield
Posted: 15th May 2012 21:41 Edited at: 15th May 2012 21:48
I'd suggest making just one block of different colors, and then use the data for the shapes to build the actual pieces out of the individual blocks. That way, you don't have to rotate anything (and maintain lighting and shadow position), nor do you have to make each shape in several different colors. Just make a bunch of different colored blocks.

You could even get different shapes not in Tetris just by changing the data. Here is an example:


And since you'll already be using the array to drop the pieces and store the data of where they are on the screen, it would be easy to just use the same array information to place them on the screen.

Everybody is a genius. But if you judge a fish by its ability to climb a tree, it will live its whole life believing that it is stupid.
Alkerak
15
Years of Service
User Offline
Joined: 7th Mar 2011
Location:
Posted: 15th May 2012 21:58
Hmm, thats a great ideea. Im gonna kill my brain assembling everything but its a nice exercise to make it. The rotations I guess imply some interesting matrix transformations.
Alkerak
15
Years of Service
User Offline
Joined: 7th Mar 2011
Location:
Posted: 20th May 2012 02:57
@zeroSlave

But I still have to use the DATA statements to rotate then right?

110
011

would become

011
110

Would I hardcode this?
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 20th May 2012 03:33
If you have a 1 you drop a red brick. The rotation is hard coded. I looked at the maths for rotation, and it looks easier to hard code it.

zeroSlave
17
Years of Service
User Offline
Joined: 13th Jun 2009
Location: Springfield
Posted: 20th May 2012 23:25 Edited at: 20th May 2012 23:40
This way is just flipping it horizontally:

It would be more like this for rotating it:


The goofy 'z' shape (man, i hate those pieces. They always seem to screw up my tetrises(tetrisi?)) is somewhat different because it only has 2 actual rotational positions.

An 'L' shape rotating clock-wise would be:

But I would maybe store the data as:

In 3x3 data blocks so as to keep the data sizes the same.

I would approach the idea like this:

If you run the code, you'll see it rotate the shape in place. It should get an idea on how to get the data and place it on the screen from the array.

As seƱor Paxton said, it would be easier to hard code the rotations than to do all the math involved.

Everybody is a genius. But if you judge a fish by its ability to climb a tree, it will live its whole life believing that it is stupid.
Diggsey
20
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 21st May 2012 01:44
This is one I made ages ago: http://forum.thegamecreators.com/?m=forum_view&t=119154&b=5&p=0

It has some fairly clear code for doing the rotations and storing the tiles. (see the functions RotateTile and LoadNewTile)

[b]
Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 21st May 2012 05:04 Edited at: 21st May 2012 05:29
I had a play with zero's (ironic name see below) code. Rotation isn't hard when you think about it, no maths required.

Added
* Rotation from one set of data
* Better "one pulse" key sensor.
* Incredible 2-tone graphics!!!
* The number zero



Zero, see how the block no longer jumps around but spins? That's because the 3x3 grid fits neatly inside the 0to2,0to2 array. When you had the array start at 1 this left row0 and column0 unused, that meant you had a 4x4 grid with 3x3 data on, so when rotated the centre was not in the middle of the block but in the middle of the 4x4 so it looked funny.

I've never made a Tetris game before but I am inspired by the Diggsey 30 minute challenge. I will try tomorrow but I doubt I will be able to finish that fast!

WARNING: The above comment may contain sarcasm.
zeroSlave
17
Years of Service
User Offline
Joined: 13th Jun 2009
Location: Springfield
Posted: 21st May 2012 06:40
I'm a slave to zeros. Ya, I should have mentioned that arrays go from 0 to the defined number, I was just being lazy. :p

I'm not sure what you mean by: how the block no longer jumps around but spins? The blocks still spin around the center point in a 3x3 (0-2, and 1-3) point... I typically start with one in arrays for my own sake. Generally, when I multiply things by the position, I like to return the original multiplier and not 0 (n * 0 = 0). It's lazy, I know, I just like it that way.

Everybody is a genius. But if you judge a fish by its ability to climb a tree, it will live its whole life believing that it is stupid.
Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 21st May 2012 15:25
Quote: "I'm not sure what you mean by: how the block no longer jumps around but spins?"

I realise that doesn't happen to your original code, I must have somehow produced that effect half-way through my changes. Starting at 1 can get very confusing in some circumstances, especially with multi-dimensional arrays.

something like this would be very awkward to start from 1:

You can easily add an offset as if you started at 1:


WARNING: The above comment may contain sarcasm.
LBFN
19
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 21st May 2012 16:54
Diggsey:

Played your tetris game - very impressive work, especially for 30 minutes.

So many games to code.......so little time.

Login to post a reply

Server time is: 2026-07-22 06:01:39
Your offset time is: 2026-07-22 06:01:39