Results 1 to 24 of 24

Thread: Tetris

  1. #1

    Thread Starter
    PowerPoster Jenner's Avatar
    Join Date
    Jan 2008
    Location
    Mentor, OH
    Posts
    3,712

    Resolved Tetris

    I've decided to post my first major XNA work for review, criticism, etc: Tetris.

    This game was originally programmed in VB.NET 2008 and XNA 3.1. I made all the graphics myself and all the sounds effects are public domain. The current version uploaded uses VB.NET 2010, .NET4 and XNA 4.0.

    In order for you to get the sound to work, you'll need to download bass.dll here. It's the link at the VERY TOP of the page that says: "Platform: Win32, OSX" with two very tiny "Download" links. The Bass.NET library found further down the page is not used. The bass.dll file must simply be in your output directory.

    If you drop OGG or MP3 files in the "Music" directory created in the output directory, it'll random shuffle them and play them as you play the game. Once again, you need the bass.dll library to make this work.

    I chose to use the Bass.dll library over the native XNA methods for it's native support of MP3s (thus making file sizes much smaller), it's easy on-demand firing of sound FX and it's simplicity. Compared to the ugly behemoth XNA gave me which requires conversions of audio files with the XACT tool and only allowing storage of those audio files as bulky WAV files, it was a no-brainer.

    The game is completely keyboard driven:
    F1 = New Game
    Esc = Quit Program
    Left - Right Arrow Keys = Move Piece
    Down Arrow = Drop Piece
    Up Arrow = Rotate Piece

    I tried to keep the game action as faithful to the arcade original as I could, thus, there's extensive coding in just mapping how the controls work with things like grace periods before a piece is considered "stacked" and auto-repeat for holding left and right. I really was impressed by how much time I had to spend tweaking the controls; it was something I totally didn't expect. Leaving the controls as simple keypresses made for lackluster game play on the early levels and immense frustration at the higher levels when pieces would unforgivingly stack as soon as they made contact. It was certainly a learning experience.

    I'm not entirely happy with the actual code I used; it's probably some of my sloppiest work, but I was trying to go for functionality over form with this project. Plus, I upgraded the project several times without rewrite and it shows.

    Anyways, download it, compile it, tell me what you think. Tear it apart and show me how I could have written it better or study it to learn how to make your own VB.NET/XNA games. I appreciate all comments.

    Project files only (no binary code, needs XNA installed and bass.dll): Tetris.zip

    UPDATE: Full solution package with binaries, bass.dll, XNA runtime installer and setup project..

    UPDATE: Here is an updated version that has been modified to work in Visual Studio 2010 under .NET 4 and XNA 4.0. This contains project files only. You'll need bass.dll to make it work: Tetris_NET4_XNA4.zip

    Name:  Tetris.png
Views: 10100
Size:  300.4 KB

    Name:  Tetris2.png
Views: 8240
Size:  332.0 KB
    Last edited by Jenner; Sep 14th, 2011 at 05:32 PM. Reason: [VB.NET 2008][XNA 3.0]
    My CodeBank Submissions: TETRIS using VB.NET2010 and XNA4.0, Strong Encryption Class, Hardware ID Information Class, Generic .NET Data Provider Class, Lambda Function Example, Lat/Long to UTM Conversion Class, Audio Class using BASS.DLL

    Remember to RATE the people who helped you and mark your forum RESOLVED when you're done!

    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe. "
    - Albert Einstein

  2. #2
    Super Moderator
    Join Date
    Dec 2003
    Posts
    4,787

    Re: Tetris

    I've moved this to the Game Demos Section and left a redirect in the XNA forum. I will check this out soon!

    Pino

  3. #3

    Thread Starter
    PowerPoster Jenner's Avatar
    Join Date
    Jan 2008
    Location
    Mentor, OH
    Posts
    3,712

    Re: Tetris

    Thanks much! I didn't even know there was a Game Demos section!
    My CodeBank Submissions: TETRIS using VB.NET2010 and XNA4.0, Strong Encryption Class, Hardware ID Information Class, Generic .NET Data Provider Class, Lambda Function Example, Lat/Long to UTM Conversion Class, Audio Class using BASS.DLL

    Remember to RATE the people who helped you and mark your forum RESOLVED when you're done!

    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe. "
    - Albert Einstein

  4. #4
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,621

    Re: Tetris

    i've noticed that giving a program (a game in my experience) an update or a recode in a particular area almost always results in some ugly coding, especially when you have to nest if/thens or cases to take into account stuff like you said before.
    My light show youtube page (it's made the news) www.youtube.com/@artnet2twinkly
    Contact me on the socials www.facebook.com/lordorwell

  5. #5
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Tetris

    @ Jenner,

    Cool! Although, I can't open the project I download the express edition of VB2008 but when I tried to open the project I received a message saying the program was created in a newer version of VB2008.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  6. #6

    Thread Starter
    PowerPoster Jenner's Avatar
    Join Date
    Jan 2008
    Location
    Mentor, OH
    Posts
    3,712

    Re: Tetris

    @Lord Orwell: I may rewrite this one soon actually. I've learned some nifty tricks with shaders and particles that could make for some interesting effects. I also want to have an animating backdrop as well; like in some of the arcade versions. I've been tempted with some other projects though as of late.

    @Nightwalker: It should work just fine in VB2008 express; though when I wrote it, I used XNA 3.0. XNA 3.1 is the new standard, and you'll probably have to replace the XNA references with those to get it to work.
    My CodeBank Submissions: TETRIS using VB.NET2010 and XNA4.0, Strong Encryption Class, Hardware ID Information Class, Generic .NET Data Provider Class, Lambda Function Example, Lat/Long to UTM Conversion Class, Audio Class using BASS.DLL

    Remember to RATE the people who helped you and mark your forum RESOLVED when you're done!

    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe. "
    - Albert Einstein

  7. #7
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Tetris

    Damn! I Tried opening the code using VS 2010 and the converter apparently converted the code but when I ran the code I received a big list of errors in the VS console.

    Edit:

    I don't have XNA! Do I need it? If so which site can I get it from?
    Last edited by Nightwalker83; Apr 22nd, 2010 at 02:22 AM. Reason: Adding more!
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  8. #8

    Thread Starter
    PowerPoster Jenner's Avatar
    Join Date
    Jan 2008
    Location
    Mentor, OH
    Posts
    3,712

    Re: Tetris

    Straight from Microsoft.

    You may need to download Visual C# Express 2008 to install it. The installer is stupidly picky about this sort of thing. Last time I did, I installed VC#2008, installed XNA3.1, and uninstalled VC#2008. You can manually install it as well without having the installer scream at you that you NEED C# installed by following the instructions here.
    My CodeBank Submissions: TETRIS using VB.NET2010 and XNA4.0, Strong Encryption Class, Hardware ID Information Class, Generic .NET Data Provider Class, Lambda Function Example, Lat/Long to UTM Conversion Class, Audio Class using BASS.DLL

    Remember to RATE the people who helped you and mark your forum RESOLVED when you're done!

    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe. "
    - Albert Einstein

  9. #9
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Tetris

    Thanks! Great game. I managed to get up to level 2 before I had to stop.

    I had to dowload/install bass.dll regardless of whether I wanted music or not. Perhaps the you could make it so the gam can still be played without bass.dll?

    For those trying to figure out where to put bass.dll it seems to do in the "bin -> debug" folder if you are running the game in Visual Studios.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  10. #10

    Thread Starter
    PowerPoster Jenner's Avatar
    Join Date
    Jan 2008
    Location
    Mentor, OH
    Posts
    3,712

    Re: Tetris

    Yea, I should use a little reflection to make the library link and load at runtime. I just figured out how to do that with a small installer program I had to write that needed to open a firewall port on both Windows XP and Windows Vista/7 machines. XP named the firewall access dll one thing, and Vista/7 named it something else. Had to detect it and load/link it appropriately.

    I have other little games that I wrote in VB.NET, but policy on here makes things a pain to post, because I'm telling everyone how to recreate my development environment.

    "Go here to get XNA, go here to get BASS, go here to get FlatRedBall, go here to get Farseer... ok, this is how you install ALL this mess...."

    I understand the policy and why it exists, but it would be nice to be able to upload an install file on here just so people can easily see a program in action. Even if you have to go through a "Are you sure you understand the risks?" type dialog. Maybe as a perk of high reputation on here? Maybe I'll post that as a suggestion on the forums thread.
    My CodeBank Submissions: TETRIS using VB.NET2010 and XNA4.0, Strong Encryption Class, Hardware ID Information Class, Generic .NET Data Provider Class, Lambda Function Example, Lat/Long to UTM Conversion Class, Audio Class using BASS.DLL

    Remember to RATE the people who helped you and mark your forum RESOLVED when you're done!

    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe. "
    - Albert Einstein

  11. #11
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Tetris

    Quote Originally Posted by Jenner View Post
    I understand the policy and why it exists, but it would be nice to be able to upload an install file on here just so people can easily see a program in action. Even if you have to go through a "Are you sure you understand the risks?" type dialog. Maybe as a perk of high reputation on here? Maybe I'll post that as a suggestion on the forums thread.

    Actually, I was just informed (and then read the rules again just so I was up to date) but you are allowed to post executables in this section. So if you wanted to post an installer, it would be ok in the Game Demos section.

    The only drawback being that people are hesitant of downloading exes, but when someone with your rep and post count puts something up, I'm sure most people wouldn't hesitate much.

  12. #12

    Thread Starter
    PowerPoster Jenner's Avatar
    Join Date
    Jan 2008
    Location
    Mentor, OH
    Posts
    3,712

    Re: Tetris

    Oh that's cool. Yea, I think I will post up a zip to an installer that'll install the XNA runtimes, BASS.dll, etc. That way, people don't need to elaborately recreate my development environment.
    My CodeBank Submissions: TETRIS using VB.NET2010 and XNA4.0, Strong Encryption Class, Hardware ID Information Class, Generic .NET Data Provider Class, Lambda Function Example, Lat/Long to UTM Conversion Class, Audio Class using BASS.DLL

    Remember to RATE the people who helped you and mark your forum RESOLVED when you're done!

    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe. "
    - Albert Einstein

  13. #13
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Tetris

    Quote Originally Posted by kfcSmitty View Post
    Actually, I was just informed (and then read the rules again just so I was up to date) but you are allowed to post executables in this section. So if you wanted to post an installer, it would be ok in the Game Demos section.
    Yeah, I was informed by Penagate via pm about that.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  14. #14
    Fanatic Member
    Join Date
    Oct 2009
    Location
    Missouri
    Posts
    770

    Re: Tetris

    Okay. =) Good game! =D Fun, and informative. Some comments on code would be nice.... =D
    Rate my post if i helped you!


    Button Configuration Control For VB6 GetAsyncKeyState
    I'm the 7th best high school programmer in the nation!(according to SkillsUSA Nationals)(Used C#.Net)

  15. #15

    Thread Starter
    PowerPoster Jenner's Avatar
    Join Date
    Jan 2008
    Location
    Mentor, OH
    Posts
    3,712

    Re: Tetris

    Having some time lately, someone requested I upload my full Tetris solution, binary, installer and all. I finally did so and it is available here.

    The installer in the TetrisSetup project comes with the XNA 3.1 runtime package, but not .NET 3.5 or Windows Installer 3.1 (I assume you have those already). In the Tetris project, I left the release source if you didn't want to recompile it yourself. I also included the aforementioned bass.dll.

    Have fun!
    My CodeBank Submissions: TETRIS using VB.NET2010 and XNA4.0, Strong Encryption Class, Hardware ID Information Class, Generic .NET Data Provider Class, Lambda Function Example, Lat/Long to UTM Conversion Class, Audio Class using BASS.DLL

    Remember to RATE the people who helped you and mark your forum RESOLVED when you're done!

    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe. "
    - Albert Einstein

  16. #16
    New Member
    Join Date
    Mar 2011
    Posts
    15

    Re: Tetris

    Quote Originally Posted by Jenner View Post
    Having some time lately
    .....
    Have fun!
    Hey Jenner, I saw a post you made here:
    showthread.php?t=625045
    and this has really helped me with starting out 3D visual basic programming.

    I was going to start with a cube.. and then branch into a 3D tetris game. And then to my looking about I found this where you yourself made a tetris game.
    I tried to find out how to PM you, but I failed. I made an account just to say wow, we must have a lot of the same interests.
    I myself love tetris! I actually spent three days making my own visual basic tetris before I started digging around with 3D things.
    youtube.com/watch?v=VFywKMim4yc would demonstrate the attempt I made.
    Maybe you can teach me to be elite, for I am newb. lol

  17. #17
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,621

    Re: Tetris

    Quote Originally Posted by Jenner View Post
    Thanks much! I didn't even know there was a Game Demos section!
    i didn't know there was an xna forum!
    My light show youtube page (it's made the news) www.youtube.com/@artnet2twinkly
    Contact me on the socials www.facebook.com/lordorwell

  18. #18

    Thread Starter
    PowerPoster Jenner's Avatar
    Join Date
    Jan 2008
    Location
    Mentor, OH
    Posts
    3,712

    Re: Tetris

    Awesome WB! Yea, I love Tetris too and decided it would be a great choice to teach myself game programming. It was a rough lesson too! Learning XNA wasn't too hard. Adapting it for use in VB.NET was the tricky part. I don't blame Lord Orwell for switching to C#; it certainly makes trolling the forums easier.

    But I love VB and I saw no reason why I couldn't use VB.NET with XNA. I'm glad I did, because once I had the basics down, it was ridiculously easy..
    My CodeBank Submissions: TETRIS using VB.NET2010 and XNA4.0, Strong Encryption Class, Hardware ID Information Class, Generic .NET Data Provider Class, Lambda Function Example, Lat/Long to UTM Conversion Class, Audio Class using BASS.DLL

    Remember to RATE the people who helped you and mark your forum RESOLVED when you're done!

    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe. "
    - Albert Einstein

  19. #19
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,621

    Re: Tetris

    Quote Originally Posted by Jenner View Post
    Awesome WB! Yea, I love Tetris too and decided it would be a great choice to teach myself game programming. It was a rough lesson too! Learning XNA wasn't too hard. Adapting it for use in VB.NET was the tricky part. I don't blame Lord Orwell for switching to C#; it certainly makes trolling the forums easier.

    But I love VB and I saw no reason why I couldn't use VB.NET with XNA. I'm glad I did, because once I had the basics down, it was ridiculously easy..
    what other games have you worked on?
    My light show youtube page (it's made the news) www.youtube.com/@artnet2twinkly
    Contact me on the socials www.facebook.com/lordorwell

  20. #20

    Thread Starter
    PowerPoster Jenner's Avatar
    Join Date
    Jan 2008
    Location
    Mentor, OH
    Posts
    3,712

    Re: Tetris

    Actually finished projects, I don't have many. Tetris was my first XNA project, and the only one that uses XNA exclusively. After Tetris, I discovered some game engines that work in conjunction with XNA as well as things like audio engines, physics libraries, lighting and rendering systems... One of those "learning curve" things I learned about game programming is that it's like a salad bar.

    Salad bars are filled with all sorts of things you use to make a salad with; you take some and leave the rest. Game programming is like that though. There are engines, tools, APIs, all sorts of things out there to help you make a killer game. When programming games, you need to "explore the salad bar". A game made with VB.NET alone can certainly be done; but like a salad bar, there are other things you can pile on the plate to make it better.

    I've got a lot of unfinished test projects. I made both a pac-man and space invader's game. Not refined enough to really play too hardcore. Both games just lack polishing; the space invaders needs better art and the pac-man becomes unplayable at later levels. I did some platforming examples, but I'm not really a platform player so I never did anything with them besides a gravity simulation and edge detection. I have some 3D projects as well, some using the Torque XNA game engine.

    I have a 100% working layered tile engine I wrote in VB.NET, XNA and FlatRedBall for making a game like final fantasy 6 or Ultima 5, but haven't made any games with it yet and want to write some better world-building tools first. I also want to do some work on the script engine for scripting sequences.

    I'm also working on crime-lord based game using VB.NET, XNA and FlatRedBall. It's somewhat of a simulation game as you build a criminal network and thus, a crime empire. As you get larger, you begin to attract more attention to your organization and thus, need to put more time and efforts into protecting it. It's about 30% done and I'm deciding if I want to make it real-time where actions happen on a timer or turn-based more like a 4X game. I can go either direction at this point since the AI is pretty rudimentary. It's my current game project I've been playing with for the last three-four months now. I don't get much time to program for myself anymore.
    My CodeBank Submissions: TETRIS using VB.NET2010 and XNA4.0, Strong Encryption Class, Hardware ID Information Class, Generic .NET Data Provider Class, Lambda Function Example, Lat/Long to UTM Conversion Class, Audio Class using BASS.DLL

    Remember to RATE the people who helped you and mark your forum RESOLVED when you're done!

    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe. "
    - Albert Einstein

  21. #21
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,621

    Re: Tetris

    i was just about to start work on a layered tile engine. Can you tell me how you did the land structure? I've been wondering the best way to serialize it.
    My light show youtube page (it's made the news) www.youtube.com/@artnet2twinkly
    Contact me on the socials www.facebook.com/lordorwell

  22. #22

    Thread Starter
    PowerPoster Jenner's Avatar
    Join Date
    Jan 2008
    Location
    Mentor, OH
    Posts
    3,712

    Re: Tetris

    I wrote a program that stores the map data as bitmap files. It's a basic map builder/editor program. Each discrete color of the bitmap corresponds to a tile. myland_0.bmp is my base-layer. myland_1.bmp is the first layer on top that. You can further save space by then saving the bitmaps in a non-lossy graphic format. It makes the files extremely tiny. The correspondence table that maps colors to tile-files is just XML. This file also holds the information about the tile such as if a player or monster can move through it or not. The game, when loading a new map then just reverses the process. Nice part is, if you want, you can tweak the maps in a graphics editor like Paint.

    The engine pre-loads my tilesets, reads the map file, and assembles the map graphic in memory as a sprite. It does this for each layer. Then, it draws those on the screen during the render loop. Since each map is at most 3-4 layers, it's only displaying 3-4 sprites, thus it's fast. Monsters, objects, NPCs, the player... are all their own sprites at some layer-depth; I believe they're all at layer 5 by default unless told to be drawn otherwise. My maps are typically 0 being water and hole fields, 1 being the main terrain with transparent edge-pieces that overlap the water and hole pieces, 2 being things like walls, structures, tree-trunks, and then I skip up to 8 for tree-tops, roofs, things that obscure the view of characters/etc.

    When it creates the layer-sprites, it also makes collision zones around non-movable tiles. I can then use the collision detection of the FlatRedBall engine as a control for boundaries.
    My CodeBank Submissions: TETRIS using VB.NET2010 and XNA4.0, Strong Encryption Class, Hardware ID Information Class, Generic .NET Data Provider Class, Lambda Function Example, Lat/Long to UTM Conversion Class, Audio Class using BASS.DLL

    Remember to RATE the people who helped you and mark your forum RESOLVED when you're done!

    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe. "
    - Albert Einstein

  23. #23
    New Member
    Join Date
    Mar 2011
    Posts
    15

    Re: Tetris

    I started using MySQL to make an mmorpg. rofl. literally just started. I got it so when you log in your a cube.. and when you move your cube around it shows it on all other windows logged in. <_<

  24. #24

    Re: Tetris

    Nice game . Thank you.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width