forums

TNT Basic Forums > Programming Q&A
tetris (first game)
< Last Thread     Next Thread >
Author
Thread        Post A Reply

06-20-2007 19:19

Posted by:
MT86

Location:
US

Find more posts by MT86

Hi
i have decided tetris is a good game to try to make. I have some experience programming (some intro C++, basic, and pascal) but have never made a game. I was wondering if I could have some pointers on how to even begin this cause im not sure were to start. Thanks

Mike

06-20-2007 23:22

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

Well the answer varies greatly depending on your skills/neds

I would suggest before trying making any game to play around with TNT, make things move on screen, experiment with sound, sprites, etc. Then you will a) learn how it works so when you start a game it won't be so confusing b) discover where your knowledge lacks and be able to ask questions

If you have already done that, you can ask for more rpecise questions as it's hard to know what you have problems with when it's so general

06-21-2007 03:28

Posted by:
MT86

Location:
US

Find more posts by MT86

sorry i was a little brief. I have had this software for a long while and have made things move around on the screen, made sprites "jump", and while is still dont a 100% get it make a ship fire bullets. I need help started a "game" making a full product. I don't want it all done for me though cause i need and want to know how to do this. But I'm not sure were to start with this. Ive looked at beans and was confused (didn't know to were to start reading and too many global vars (there is probably no classes in tnt basic is there :) ))

Anyway, some direction, how to plan, and how create multiple sprites (of the same thing) would be nice. Sorry for my about my writing.

Thanks for responding
Mike

06-21-2007 03:34

Posted by:
MT86

Location:
US

Find more posts by MT86

About above post.....

I just read my reply and all i can say is wow.... i forgot spell check and my grammar is horrible. You don't need to read it. I will post a better and more detailed post tomorrow cause i am too sleepy now.

Sorry for everyting,
Mike

06-21-2007 13:52

Posted by:
Jacob

Location:
San Francisco, CA

Click Here to Email Jacob   Find more posts by Jacob

You'll want to start with defining arrays for many pieces of the same type:

Global Int peiceX[99]
Global Int peiceY[99]
Global Int peiceRotation[99]
Global Int peiceType[99]

I do lots of this in my Game Pack available here: TNT Basic Files

Have fun,
Jacob

06-21-2007 22:56

Posted by:
allnodcoms

Location:
hertfordshire (England)

Click Here to Email allnodcoms   Find more posts by allnodcoms

You usually start with a GDD...

A GDD is a 'Game Design Document', a simple English language description of what the game is supposed to do and how the player goes about doing it. This is generally written as a single sentence description of the game's objective, followed by a series of short, concise sentences, or optionally a bulleted list (I used the latter) describing the main elements of that description. Take time over this, and try to be as complete as possible, as though you are describing the game to someone who has never played a game before. I find hand written is best, it's easy to see more of the document at once (which can be handy), you can make quick side notes and sketches etc. and a notebook and pencil is more portable for ideas on the go. I've not written commercial game code for over ten years but I still always carry a notebook!
This might sound a bit pointless, but the next step is to take each of these sentences and start to look at ways of implementing them in code (which is why the sentences should be short and concise). Don't write any code, just extend the document to describe how things could be implemented, initial data storage strategies and so on. Take each sentence and break it down into a separate section. If necessary you can take each of these sections, and the sentences they contain, and break these down further. You will find that after a few break downs you will almost be writing code anyway.

That's how the Pro's start, it's simple and straight forward. Don't consider the GDD to be carved in stone though, it's just a means to an end, a way of getting the ideas onto paper (or silicon) in a way that enables you to break it down and examine the workings. I could give examples for Tetris, but I'll let you have a play and see how it goes, if you need anything else though we're always about with a bit of advice... or a shoulder to cry on ;)

Good luck with the game, and have fun. I always preferred writing games to playing them, it's just a big logic problem and can be very rewarding. If you've written code before you'll be fine, you just need to look at things slightly differently.

Keep us informed on your progress...

Danny (nod the mod)

06-21-2007 23:33

Posted by:
allnodcoms

Location:
hertfordshire (England)

Click Here to Email allnodcoms   Find more posts by allnodcoms

Oh, forgot...

Just re-read your earlier posts.

quote:
"multiple sprites (of the same thing)"

A sprite is kind of like an instance of an internal type 'sprite' which is referenced by number rather than a pointer. When you use the 'sprite' command to place (or create) a sprite 'instance' you give it an image id (kind of member variable if you like) which tells TNT which image to associate with that 'instance', so to create two sprites with the same image just use 'sprite' twice with the same image id. Doddle really!

There are no classes as such in TNT, it's not an 'OO' implementation, but in some ways it can be thought of as such (if this helps you get things straight). Where you see a call asking for an 'ID' number to reference something, just think 'pointer'. The current version is actually written in C++ and does use classes and object definitions internally, so the link is not totally hypothetical.

Danny (nod the mod)

06-21-2007 23:46

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

quote:
Ive looked at beans and was confused


Beans is more to show the capacities of TNT than to learn - I don't recommend studying full-grown project as learning tool, it's more confusing than anything else.

Danny's explaination is very good - and if you have never coded before, and you feel insecure about what you are doing, you could start with even easier [useless] demos (from what you say I think you already have - then you can ask questions about parts you didn't quite get and you can progress with the answers you get)

06-23-2007 01:11

Posted by:
appleide

Click Here to Email appleide   Find more posts by appleide

beware the Tetris Company.

06-27-2007 03:47

Posted by:
MT86

Location:
US

Find more posts by MT86

thanks for input

Thanks everyone for your input it has been very helpful. First off i followed allnodcoms advice and made a GDD. Its working great but I have few questions on things.

First: Should the pieces be four sprites made up to be "one piece" or should a "piece" be one sprite. When the player forms a line, the line disappears. Does this mean the pieces have to be four sprites made into one piece? (Is that the best way?? and rotating would be a headache (coding wise)??!?)

Second: since all the pieces have to be in an array for example
int xPiece[99] //x location of a peice

as time passes the player elimates some lines and more and more peices fall, won't the game reach the end of the array? how do i avoid this?

Also should i post my GDD??

Thats all for questions for now. I have not actually started coding yet (i might play around with some code tonight) but I think once i get these questions cleared i might be able to start something.

Thanks
,Mike

Note: i know this game is not the most original idea in the world but i don't plan to distribute the game in anyway I'm just using this as practice and for fun)

06-27-2007 12:51

Posted by:
allnodcoms

Location:
hertfordshire (England)

Click Here to Email allnodcoms   Find more posts by allnodcoms

You're welcome

Glad we could help... The GDD is supposed to throw up this sort of thing, that's what it's for, so I'm glad to see it's working for you.

OK, answers: (but only ideas, I'll let you work out the details)

1) Sprites: You only need one sprite on screen at a time. When it lands you can paste it in place as it wont move again. One sprite, that's was a hint. It has to rotate though, so you could save multiple angles as different images, then just cycle backwards or forwards through the pictures dependant on which key was pressed. When a line disappears, just copy the screen down over the top of the old line, same thing with the array that holds the data (more on this in a second).

2) The array only needs to be width of the play area / width of a single block wide, and the height of the play area / height of a block high. As hinted at above, when a line (array row) goes, copy every row above it down by one, starting at the bottom and working your way up. Now you'll never run out of space, and if you do, the game's over! Cool huh?

3) No, you don't need to post the GDD...

Hope this helps, these are just possible solutions to your questions, you may come up with a better way that fits more neatly within your design spec. Remember when writing code, "There is never a right way, only a best way".
Anything else you need, you know where to find us...

Danny (nod the mod)

06-27-2007 16:04

Posted by:
MT86

Location:
US

Find more posts by MT86

pasting/copying

alright you mention pasting and copying. I confused what you mean (is a copy/paste function or something) I do now get how to have pieces fall down screen and rotating but when they land I got confused with the copying and pasting. Could you please explain in more detail?

,mike

06-27-2007 18:38

Posted by:
MT86

Location:
US

Find more posts by MT86

ok

Window mode 800, 800
load images 128


sprite 128,20,20,0
draw frame
sprite 128,50,50,0
draw frame

while not mouse button
wend

when i run this it only shows one sprite (it moves from on location to another). How do i make 2 sprite of the same thing appear(please)

Mike

06-27-2007 20:40

Posted by:
allnodcoms

Location:
hertfordshire (England)

Click Here to Email allnodcoms   Find more posts by allnodcoms

Check out 'paste sprite'...

'Paste Sprite spriteID' does what it says on the packet, it pastes a copy of the sprite to the background, leaving the original untouched. Give it a go, it's kind of groovy...

When the sprite gets to the bottom, 'paste' it to the background, move the original sprite back up to the top again, and change the image to that of the next block.

Have fun!

Danny (nod the mod)

06-27-2007 21:06

Posted by:
allnodcoms

Location:
hertfordshire (England)

Click Here to Email allnodcoms   Find more posts by allnodcoms

Sorry, missed second question...

The format of the sprite command is 'sprite spriteNumber, spriteX, spriteY, spriteImage', so your code is just drawing sprite 128 twice...

Here's a little bit of homework for you. Try writing a bit of code that moves the sprite about with the mouse, and puts another sprite where the first one used be, a sort of 'mouse trail' program. This program should paste the sprite when the mouse is pressed, and quit on the space bar. This will get you using loops, two identical sprites, pasting images and handling variables. It's pretty quick to write (hint: You've already done a lot of it), and at the end of it you'll have a finished project. You'd be surprised what a boost it is to stand back and look at a finished piece of code. Write up a GDD and get back to me when you're done, I'll mark it and hand out stars later ;)

Happy coding...

Danny (nod the mod)

06-28-2007 02:10

Posted by:
MT86

Location:
US

Find more posts by MT86

Yeah its like a drawling app...

alright I wrote up the program like you suggested and it works. It moves the sprite around screen then pastes it when i click. And i will be glad to write up a GDD but for what (this or tetris)

Im going to work with tetris tonight and try a few things. I'll keep posting my progress.

also quick question, when making a program/game where is it best to start coding, the menus and options or do those come last after the game/program is completed.

thanks,
Mike

06-28-2007 15:59

Posted by:
allnodcoms

Location:
hertfordshire (England)

Click Here to Email allnodcoms   Find more posts by allnodcoms

Don't worry on the GDD...

It was for the little test program, but you've done it.

When writing a game, I start with the game itself. The main reason being I don't need to test the playability of the menus or title screen. Don't worry about pretty graphics to start with, they can be replaced when the main engine is in place.

Have fun, and keep us posted...

Danny (nod the mod)

07-01-2007 16:57

Posted by:
MT86

Location:
US

Find more posts by MT86

progress

ok ive made some progress. I have made a grid that can tell if a piece is in it and to turn on its bit when a piece has stopped on it. I have even been able to have the pieces to stack on top of each other. Only one problem: they are single pieces not the 4-piece tetris pieces!. how would make it so that when my 100 by 100 (square piece) sprite lands on another square piece without it seeking. Right now it checks to see if the pieceX and pieceY = the spriteX and spriteY. Help!

Mike

07-01-2007 18:14

Posted by:
allnodcoms

Location:
hertfordshire (England)

Click Here to Email allnodcoms   Find more posts by allnodcoms

I'm not totally sure I get what you mean...

If you mean how do you stop a piece from falling without checking all the other pieces to see if it's going to hit one, then you've already answered that one. As each piece is only a single square (I think), then don't check the other pieces, just look at your array. If the next row down is empty, move the piece by down by one row and repeat. If it's not empty, don't move the piece, and flag the current row/column as occupied.

If that's not what you mean then you're going to have to be a bit more precise with your problem, sorry, it's been a long day... ;)

Danny (nod the mod)

07-03-2007 02:28

Posted by:
MT86

Location:
US

Find more posts by MT86

I actually ment to post this earlier but forgot

ok i have these sprites that are images of the pieces (the square, long piece,etc). they come down but since the x and y of a sprite is only one pixel, sprites overlap each other (due to the diff sizes of pieces.
Example:
_ _ _
|*||_| |*|
|_||_| |_|
|_|
|_| * - is the pixel that is the x and y of sprite

So what do i do? Also when i check to see if the line is occupied so the sprites can go there, am I using the sprites x and y to find the grid's x and y of the position below the sprite so that the program can find out decide weither or not the space is occupied.

(I probably made it more confusing sorry)

07-03-2007 02:29

Posted by:
MT86

Location:
US

Find more posts by MT86

OOPS

oops picture got smashed together! u can ignore it sorry!

07-03-2007 09:02

Posted by:
allnodcoms

Location:
hertfordshire (England)

Click Here to Email allnodcoms   Find more posts by allnodcoms

I was expecting this question earlier too... ;)

Easiest way, try and get away from co-ordinates a bit more, think arrays. Each piece is made up of four squares, and you need a way of describing which four, from a possible sixteen (hint 4x4), are occupied at each stage of rotation.

Obvious method: Each sprite, and rotation, has a 4x4 array and the sprite handle is always in the upper left corner of the sprite image. Find out what play area array cell the handle is in, then map the sprite array onto it. This would work, but it's not terribly elegant...

Elegant method: If the sprite handle is in the top left of the first occupied square of the piece, not necessarily the actual top left of the whole image, you would only need to hold the 'offsets' of the other three occupied squares. Treating the top left occupied square as 0,0 the 'square piece' could be defined as (1,0), (0,1), (1,1) for example. No need to hold a complete 4x4 array, and the values you store make it a lot easier to map the piece to your play area array (If that same 'square piece' is in play area array cell (4,7) for example, the other occupied squares are (5,7), (4,8) and (5,8)... Cool huh?).

A quick question, how many rotations are you holding? If the answer is 4 then are you sure you need that many? ;)

Have fun...

Danny (nod the mod)

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.