Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411469 Posts in 69368 Topics- by 58422 Members - Latest Member: daffodil_dev

April 23, 2024, 04:47:46 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsCommunityTownhallForum IssuesArchived subforums (read only)TutorialsTetris tutorial in C++ platform independent focused in game logic for beginners
Pages: [1]
Print
Author Topic: Tetris tutorial in C++ platform independent focused in game logic for beginners  (Read 14002 times)
Javilop
Level 2
**



View Profile
« on: December 13, 2008, 07:13:45 PM »

[EDITED]

Hideous asked...
Quote
I'd like to see a tetris tutorial in c++, actually. Thinking about how the rotation would work has had my brain stumped for a long time.

Et voila!

http://javilop.com/gamedev/tetris-tutorial-in-c-platform-independent-focused-in-game-logic-for-beginners/

After spending lot of hours this weekend I've just finished the Tutorial of how to create a clone of Tetris using c++.

We are going to learn how to create a stunning and great Tetris clone from scratch using simple and clean c++. And this will take you less than a hour! This is the perfect tutorial for beginners, there are a lot of game tutorials about how to create a Tetris on Internet, but I hope this will be one of the best. Just enjoy it and leave a comment if you want me to explain something better. I know my english sucks, so if you see some mistakes, please, tell me. Let’s go!



[/EDITED]

[Old post]

I'm making a tutorial that explains how to make a Tetris game from scratch using c++. It's almost finished.

Currently, I have all game logic, and I drawing each block just using rectangle primitives (using IndieLib or SDL).

I'm thinking in loading a background and tiles for each block, because it is a bit ugly like that. And making some effects, like the lines disappearing and to show the points amounts, etc. But this way, the sourcecode is going to be a little bit more complex, not so much but there will be things that could confuse the reader (or maybe not).

What do you prefer? Better graphics and more things or just having only the logic you really need but with an ugly design?

Let me now your opinion, please!
« Last Edit: April 03, 2012, 03:08:22 AM by Loover » Logged
Cymon
Level 9
****


Computer Kid


View Profile WWW
« Reply #1 on: December 13, 2008, 10:39:45 PM »

I would think that blocks like you're thinking of doing wouldn't require that much overhead. In fact they could probably be drawn procedurally within a function, so I don't see what the problem is with having both.

But if you had to do one, for a tutorial it's always good to stick with the basics. And since tetris has been done to death do you really need to make it pretty. Me, I go with text graphics, no sound or music save a default "bing" now and again and I still get my game on download sites.
Logged

Cymon's Games, free source code, tutorials, and a new game every week!
Follow me on twitter
Javilop
Level 2
**



View Profile
« Reply #2 on: December 14, 2008, 03:39:12 AM »

Hey guesst! I liked alleytris.

FInally, I think I'm going to publish 2 tutorials:

1. First, all the game logic, explained, using really simple SDL primitives for rendering.
2. Graphics improvements, points, effects, sprites, background, etc. Using IndieLib.

While I'm finishing it I let you with one funny screenshot. The GIANT Tetris board Smiley

Code:
#define BLOCK_SIZE 5				// Width and Height of each block of a 
#define BOARD_WIDTH 90 // Board width in blocks
#define BOARD_HEIGHT 90 // Board height in blocks
Logged
Javilop
Level 2
**



View Profile
« Reply #3 on: December 14, 2008, 05:40:54 PM »

Ok! The tutorial is ready!

Just waiting your comments and feedback!

PS: Guesst, I've sent you a PM.
« Last Edit: December 15, 2008, 01:57:21 AM by Loover » Logged
Javilop
Level 2
**



View Profile
« Reply #4 on: December 16, 2008, 01:09:23 PM »

Oh, come on guys! Say something! I put lot of hours on this tutorial!  Tears of Joy

Maybe it was too much simple? Should I have tried to teach something more complex?
Logged
Hideous
That's cool.
Level 10
*****


3D models are the best


View Profile WWW
« Reply #5 on: December 16, 2008, 01:14:42 PM »

Thank you! Thank you SO MUCH. I will read this now.
Logged

Ivan
Owl Country
Level 10
*


alright, let's see what we can see


View Profile
« Reply #6 on: December 16, 2008, 01:23:12 PM »

Very nice totoreal, Loover, I'm sure it will be useful to many people!

The first complete game I wrote was also tetris, though it was all in C.

(Here's the game logic bit from it, maybe it will be helpful to compare.
http://code.google.com/p/tetryx/source/browse/trunk/src/tetris_game.c?r=14)
Logged

http://polycode.org/ - Free, cross-platform, open-source engine.
David Pittman
Level 2
**


MAEK GAEM


View Profile WWW
« Reply #7 on: December 16, 2008, 05:37:46 PM »

Nice tutorial. I've never written Tetris myself--thought about it several times and always ended up with the most convoluted solutions to handling rotations. It seems obvious now, but defining a pivot point was the secret sauce I was missing. Also, I always wanted to find the best valid place for a blocked rotation to go like some versions of Tetris do. It probably wouldn't be too difficult to handle the most common cases, though; if the rotation is blocked, try it along with an automatic move left or right. If that doesn't work, it's probably ok to not allow the move. The extreme case is Tetris DS, which does some really weird stuff with rotations where you can keep a piece alive after it's touched down and sometimes make it worm up and over other blocks by rotating it properly.
Logged

Cymon
Level 9
****


Computer Kid


View Profile WWW
« Reply #8 on: December 17, 2008, 09:45:17 AM »

I PMed you, I commented on your blog. What, one fan isn't enough for you?

Know you know how I feel. Heh.
Logged

Cymon's Games, free source code, tutorials, and a new game every week!
Follow me on twitter
Matt Thorson
Level 7
**

c'est la vie


View Profile WWW
« Reply #9 on: December 17, 2008, 09:29:13 PM »

This is pretty cool.

The only issue I noticed was in sdl_gfxprimitives.h, there is the following line:
Code:
#include <G:/trabajo/programacion/SDL-1.2.11/include/SDL.h>

Obviously that directory doesn't exist on my PC so I had to change it, and I didn't see this mentioned anywhere in the tut.

I'm already familiar with C++/Game Logic, but I used this to teach me how to get started with SDL.  Thanks!  Beer!
Logged

Javilop
Level 2
**



View Profile
« Reply #10 on: December 17, 2008, 11:49:18 PM »

- toastie, thank your for sharing your source.
- YMM, thank you! I changed this line and now it is already fixed and you can directly click "compile" without problems. I uploaded the new zip. I forget that, thank you!
- Hahaha, guesst. Watching your blog I'm not sure who is the fan. You have really good post on it. I enjoyed a lot this about procedural "Zelda". It is something I also thought about in the past. I've just seen your PM, I will answer you later when I'll be back from work.
- dphrygian, thank you. I own a DS myself too and it is true what you say. Some improvement I'm planning to make to this Tetris clone in another tutorial are:
* After a time delay pressing a key, the key moves without having to press again.
* If a piece is near to the boundarie and you rotate it, allow rotation with a little displacement.
* The piece can not be stored while pressing rotation buttom. And "the The extreme case is Tetris DS, which does some really weird stuff with rotations where you can keep a piece alive after it's touched down and sometimes make it worm up and over other blocks by rotating it properly." => sorry for copy pasting you, but I'm really bad at English and this sentece explain it perfectly Smiley
* Create the pieces completly outside, and no one-block inside the board. This is just changing the "y" displacements in the array.
* Rotation in serveral directions.
* Buttom for keeping a piece to use it later
* Showing more pieces.
* Stadistic (and not completly random) calculation of new pieces. If you have played Tetris DS you will see that in fact they are not random, it has some type of stadistic distribution in order to no to be waiting for a piece too much time.

Thank you for the feedback!
Logged
Cymon
Level 9
****


Computer Kid


View Profile WWW
« Reply #11 on: December 18, 2008, 08:42:09 AM »

* The piece can not be stored while pressing rotation button. And "the The extreme case is Tetris DS, which does some really weird stuff with rotations where you can keep a piece alive after it's touched down and sometimes make it worm up and over other blocks by rotating it properly." => sorry for copy pasting you, but I'm really bad at English and this sentence explain it perfectly Smiley
* Create the pieces completely outside, and no one-block inside the board. This is just changing the "y" displacements in the array.
The latest version of alleytris does both of these things. The first is just to try different wiggles when you rotate before discounting the rotation as being impossible. The last one has a caviat in that you may be able to move your piece off the side of the board on the top if you're not careful with your colision detection in that strange negative y land. (It only appears in alleytris if you turn shadows on.
Logged

Cymon's Games, free source code, tutorials, and a new game every week!
Follow me on twitter
Javilop
Level 2
**



View Profile
« Reply #12 on: April 03, 2012, 03:07:05 AM »

Hi there!

I've just updated this old tutorial adding some details and fixing minor errors. Here you have: http://javilop.com/gamedev/tetris-tutorial-in-c-platform-independent-focused-in-game-logic-for-beginners/
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic