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 Discussion / Tetris help

Author
Message
TylerN
18
Years of Service
User Offline
Joined: 27th Nov 2007
Location:
Posted: 27th Nov 2007 19:54
Hi, I was wondering if anyone could help me figure out how to fix what I have done wrong, or if there is any way to set a sprite as a variable to choose a random sprite number each time and then make the correct sprite.

What happens is, when the variable "moving" is the same as the variable "stagnant" then it won't sprite moving, and will instead sprite the sprite to stagnant instead. Therefore the blocks can never be the same set of blocks. This causes a stop in the game, because the "stagnant" variable gets sprited after the "moving variable". Also, if there are any ideas on how to keep the blocks from going to far left or right, please let me know. Thank you in advance.

Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 27th Nov 2007 23:26 Edited at: 27th Nov 2007 23:38
pretty sure you can't use "sprite" as a verb, and... what??

I'll take a look at your code as I like tetris
If I work out what you meant and I can help I'll post back later

[edit]
You don't have any images; a sprite takes the form of whatever image you assign to it.

Looking at your code I think Tetris may be a bit advanced for you right now, it's pretty complicated.

The best way to do it (IMHO) would be to use a grid, each cell in the grid could be empty or occupied by a block. You'd program the tetronimos as a series of joined blocks. The reason for keeping them separate is for when you clear a line

"You must be someone's friend to make comments about them." - MySpace lied.
TylerN
18
Years of Service
User Offline
Joined: 27th Nov 2007
Location:
Posted: 28th Nov 2007 04:53
Heh, that's just part of the code that I showed you, I have sprited everything up above. All of the blocks appear, but I will go back and try using a grid. Not exactly sure how to do the series of joined blocks though.
LBFN
19
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 29th Nov 2007 15:42
I agree with Obese; Tetris seems like a bit much for you now.

If you are adamant about doing a Tetris clone, I would suggest making an array for the entire screen area where your sprites will be located. You could use Grid(20,40) for example, with the understanding that each 'box' is 10 X 10 pixels. You could then 'burn' in the boxes of the pieces into the array which would include the color of the piece. This way, you will be able to check whether or not a piece is below or beside the one dropping (your code does not check for anything existing).

Suggestions:
1. Complete a pong or breakout game first and get some experience.
2. I would lose the goto and would use gosub instead. Have all of your code called from within the do-loop. You never want to go in and out of a do-loop like you have done.
3. Why do you need five different sprites? You aren't moving five at the same time. Just use one sprite with five different images.
4. Establish an array for checking against what has been put in place previously.
5. Search for 'Tetris' on the forum. There are lots of examples out there.

Good luck.

LB
Bluestar4
20
Years of Service
User Offline
Joined: 19th Dec 2005
Location: USA
Posted: 29th Nov 2007 21:14
you know , I've never done a tetrus or pong clone. I 'll have to do that someday.

Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 29th Nov 2007 22:50 Edited at: 30th Nov 2007 00:19
@TylerN
A Tetris grid is 10x18
I'm gonna give this a go
I'll post up how to move each Tetromino as independent blocks
(one handy thing is that every Tetromino is made of 4 blocks)

Have you done TDK's tutorials? They're awesome

[edit]
damn tetris is hard
I'm going to have the active tetromino "float" on the grid in it's own array and then when it collides transfer its position to the grid and grab a new tetromino for the tetromino array

[edit]
This is as far as I've gotten (only square tetrominos)


This is really difficult
I haven't even worked out how to rotate them yet

"You must be someone's friend to make comments about them." - MySpace lied.
demons breath
22
Years of Service
User Offline
Joined: 4th Oct 2003
Location: Surrey, UK
Posted: 30th Nov 2007 22:52
yeah I was going to try tetris a few weeks back, because I'd made snake the day before and that was really easy. I sat down and thought about how to make tetris for about half an hour, realised i didn't have a clue, and gave up without a single line of code. Well that's not entirely true i did have a very pretty title, but otherwise...

TDK
Retired Moderator
23
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 1st Dec 2007 02:36 Edited at: 1st Dec 2007 02:45
I've never liked Tetris so it's not a game I've ever considered writing, but have to admit that it's probably one of those games that sounds a doddle to write at first but the more you look into it, the harder it actually is.

Definitely not the sort of program that a beginner can knock together in an afternoon...

[Edit]

Quote: "I haven't even worked out how to rotate them yet "


You would just create four images for each shape - one for each of the four rotation positions.

Then there's the problem of removing rows (part sections of sprites?) at the bottom when they are completed...

TDK_Man

demons breath
22
Years of Service
User Offline
Joined: 4th Oct 2003
Location: Surrey, UK
Posted: 1st Dec 2007 13:11
where do the tiles rotate around in tetris? cos there isn't like a middle tile or anyhing on some of them...

Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 1st Dec 2007 18:19 Edited at: 1st Dec 2007 18:22
@TDK
Quote: "
You would just create four images for each shape - one for each of the four rotation positions."

I had the same idea
Although I'm using cells instead of images.
Using cells means you can remove rows easily:
The tetromino floats on top of the grid until it collides, then it becomes part of the grid. Once there is a complete row on the grid, all the cells in that row are deleted.
I will have to apply gravity to all the cells so that when a row is cleared they will fall.

"You must be someone's friend to make comments about them." - MySpace lied.
Bluestar4
20
Years of Service
User Offline
Joined: 19th Dec 2005
Location: USA
Posted: 2nd Dec 2007 02:41
interesting .... I'll have to try this in the future sometime and see what I can come up with.

aluseus GOD
19
Years of Service
User Offline
Joined: 19th Mar 2007
Location: I\'m here. Now I\'m there. I keep moving
Posted: 2nd Dec 2007 03:31
Im going to try tetris too!
When thinking how to make it I come with:

Make grid-
Make simple shapes appear-
Make simple shapes fall-
Make row deletion algorithm-
Make pieces rotatable-
Add cool stuff-

alus.portbb.com go there.
Quote: A book. I hate books. book is stupid. I know that I need codes but I dont know the codes -zenicanin14 the 2nd stupidest user in the world
Diggsey
20
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 2nd Dec 2007 17:19
Here is an idea of how to easily create a tetris clone:

Store the playing field as a grid of cells. Each cell would contain one dword value. When 0, the cell would be empty. Any other value would specify the colour of the cell.
Each tile would be stored as a similar, but much smaller grid (maybe 5x5).
To rotate the shape, just rotate the cells in the smaller grid.
Create a function that loops through all the cells in the small grid that checks if any cells overlap with the large grid when the small grid is at a certain position.
Each time when the tile moves down, and when the player tries to rotate the tile, that function is run with the new position and rotation. If there is an overlap when the function is run after moving the piece down, the old position is restored, and the tiles are baked into the large grid.
Every time a tile is baked into the large grid, you check each row in the large grid for a complete row. As this would only ever happen just before a new piece is created, you can have a piece of code to animate all the rows above falling down the correct distance, and then actually move the cell values down, and then continue with the game.
To draw everything, just go through each tile on both grids, pasting a white tile sprite set to the diffuse colour of that cell, to the correct position.

Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 2nd Dec 2007 19:43
@diggsey
wow, that's almost exactly the same as what I was thinking!
I would store the different rotation positions for each tetromino and switch between them instead of actually rotating.

That just sparked a thought: when you rotate the tetromino you have to check that the new rotation wont overlap any cells, if it does don't rotate.

"You must be someone's friend to make comments about them." - MySpace lied.
TylerN
18
Years of Service
User Offline
Joined: 27th Nov 2007
Location:
Posted: 3rd Dec 2007 00:03
Wow, thanks guys, I think i understand how to do it now. Just a quick question though.

How exactly do i tell my grid where to start at on the screen?
Bluestar4
20
Years of Service
User Offline
Joined: 19th Dec 2005
Location: USA
Posted: 7th Dec 2007 07:21
When I get time I will definately have to do this - I'll call it bluetris lol

Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 7th Dec 2007 08:21
Quote: "How exactly do i tell my grid where to start at on the screen?"


When drawing your grid you need two things: the screen position of your grid (starting at the upper left corner) and the size of each cell.
I will draw a 10x10 grid where each cell is 5x5. The grid will start at 100,100 on the screen:

It looks like one big box but it is a grid. Drawing them more losely will make it easier to see:


"You must be someone's friend to make comments about them." - MySpace lied.
Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 7th Dec 2007 08:32
Here's a more colourful version


"You must be someone's friend to make comments about them." - MySpace lied.
Pixelator
18
Years of Service
User Offline
Joined: 8th Jul 2007
Location: here
Posted: 24th Dec 2007 23:51
somebody (im too busy, sorry ) should try and make a tetris and asteroids mix!!! Treat the blocks like asteroids and have a ship but the asteroids will stack up on the bottom of the screen and if they reach a cirtain hight you lose!!!!

Just one of my famous "W00t W00t!!!! I GOT IT" ideas...


Maryville Game Developers
Visit our website at http://www.freewebs.com/maryville-game-developers/index.htm
Bluestar4
20
Years of Service
User Offline
Joined: 19th Dec 2005
Location: USA
Posted: 25th Dec 2007 00:53
that would be an interesting game pix.

Pixelator
18
Years of Service
User Offline
Joined: 8th Jul 2007
Location: here
Posted: 25th Dec 2007 03:33
MY DAD ROCKS AT ASTEROIDS!!!!!!!!!!!!![b][/b]


Maryville Game Developers
Visit our website at http://www.freewebs.com/maryville-game-developers/index.htm
jason p sage
19
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 27th Dec 2007 19:07
@BlueStar:
Quote: "you know , I've never done a tetrus or pong clone. I 'll have to do that someday.
"


No you don't.

Bluestar4
20
Years of Service
User Offline
Joined: 19th Dec 2005
Location: USA
Posted: 29th Dec 2007 12:15
@jason
someday....maybe.

Login to post a reply

Server time is: 2026-07-06 13:34:53
Your offset time is: 2026-07-06 13:34:53