Game Development Tutorial

Everything a total beginner needs for game programing!

10. Timing is crutial

We've made it to a break-point in our game's development. In this chapter we'll automate our game, so it will create new columns every second. And after that, we'll make our existing colums move to the right. We'll also check, if the conditions for Game Over, or New Level are met. The first step in this part is to add a timer to the form. You can find it in your ToolBox, under the 'Components' section. And when you double-click it, it won't be placed to the form. It will be placed in a new toolbar under your Form Designer window. Here's a screenshot:

So, click the timer in the components toolbar, and set it's properties like shown in the next table:

Timer

  • (name): Game
  • Interval: 1000

Obviously, the timer has a 'Interval' property. That tells the timer the 'lenght' of the pauses between repeating all of the commands writen in it's Tick method. The interval is defined in miliseconds. That means, if you want your timer to repeat it's code every second, you'll have to enter '1000' in it's interval property. And if you want it to repeat it's code every two and a half seconds – enter 2500. And so on, and so on, and … ;o)

So, now, we have the timer set – let's try it out. Double click on it in your components toolbar, and you'll see the code for it's Tick method. Add next lines of code in it's method:

// Call to our function responsible
// for creating new columns:

CreateNewColumn();
// Call our two 'draw' functions...
// So we can see when the new
// columns are created.

DrawField();
DrawGrid();

Ok, that'll do the trick. But, we have to tell our timer when to start 'ticking', and we'll do this with our 'New Game' button. So, go to the code for your button, and add this line of code after the existing lines:

// Telling our game timer to
// start ticking:

Game.Start();

Oh, and before moving on, remove, or comment out (check your C# toolbar for a button that does that) the code wich we used to test our field:
 
Field[0,0] = 1;
Field[4,8] = 2;
Field[2,12] = 3;
Field[9,14] = 4;

Don't worry, we don't need that code any more. Our blocks will be filled automaticaly, frow now on. Cool, heh? But wait untill you see this stuff in action! :o) Run your game, click on the button and enjoy the fireworks! Here's what you should see after 15 seconds (and after 15 column changes):

Moooooving on! As promised, we'll move all existing colums to the right. But that's the story from our next chapter.

0 comments:

Post a Comment

Downloads

Downloads
Finished Bubble Splash Game

Followers

Translate

Blog Directories

Programming Blogs - BlogCatalog Blog Directory
blog directory
Software Computers Business Directory - BTS Local
Top Blogs GoLedy.com
TopOfBlogs DigNow.net
Blog Directory blog search directory
Top Computers blogs Add to Technorati Favorites
Computers Blogs Blog Directory
blogsbycategory.com Blog Directory & Search engine
Blog Flux Directory Programming Blog Directory
Join My Community at MyBloglog! BlogRankers.com
Technology Blogs - Blog Rankings Blog Directory
C# Game programming tutorial Blogs lists and reviews
Bloglisting.net - The internets fastest growing blog directory Blog Directory - photarium
blogarama - the blog directory Blog Toplist
Blog directory Computers (Linux) - TOP.ORG
Blog Ratings si.blogs
Blogz game, development, programming, c#, visual studio, tutorial, source code
On our way to 1,000,000 rss feeds - millionrss.com
RSSMountain
TopBlogLists.com - Blog Search