Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Well last night I made a tic tac toe game, works like it is supposed to and the AI seems to work like it should. I guess I would like to try a new game and I was thinking of doing tetris. My question is where should I start? I dont have a clue on how to setup a animation on a program. I think if I knew what kind of object .net uses to do animation I might beable to slowly figure this out. Also my problem might be I just dont have a clue on how animations work in programs :D Anyways sorry to bother you all with my silly questions. Hope everyone is having a good monday!

 

Take care

 

LP

  • *Gurus*
Posted

Programs with animation, such as screensavers and games, tend to run in a main loop, using as much CPU as possible to render as many FPS as possible. In many ways they're easier to program than event-driven programs since your program never goes idle, and never leaves the loop.

 

Basically you loop until a boolean contition changes, then the program ends. Somewhere in your loop you check for, say, a keypress to set that condition and the loop will finish. Rendering graphics depends whether you're using GDI+ or DirectX, but either way you will usually draw a frame every iteration of the loop.

 

To do animation without DirectX, you use the GDI+ drawing methods in the System.Drawing namespace. Combined with the Windows Forms double buffering, this can produce a nice result. Every iteration of the loop you call Invalidate() then Application.DoEvents() and your main form gets repainted, and everything is drawn where it should be.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

  • 8 months later...
Posted
Look into FSM (finite state machines) they are basically a coding structure that allows you to manage a games state, that being a piece is falling or new level loading. alternatively, you could try and adopt an OO approach that has events in each object...
  • Leaders
Posted
As far as the graphics of tetris are concerned, you do not NEED to redraw every frame, just use a graphics object to erase where the tetris or line was, and redraw it at its new location, saving alot of cpu power and maintaining that familiar event driven program structure.
[sIGPIC]e[/sIGPIC]
Posted
Saving CPU power for what? Why worry about tracking when the screen needs to be redrawn? Games don't follow the event driven paradigm unless they're turn-based (and sometimes not even then). An OO approach wouldn't be bad and isn't necessarily the same thing as event driven.
Here's what I'm up to.
Posted

I'd have thought that it would be easier to write Tetris using an event-driven model rather than a main loop. Could you set up a timer event, say every 1/2 a second and have an event handler that moves the block down the screen. You could also have keyboard event handlers. When a key to move the block left or right is pressed, these would be triggered and it would store the key pressed, and when the timer event is next triggered the block would move left or right as well as down.

 

As the game progressed and got faster, all you would need to do is to reduce the interval of the timer events.

Posted

This is exactly the way I have my tetris clone working, see BloX on my site. As my book says using a timer in this case doesn't really matter as we are not after lightening speed, so a timer does the job.

 

Same goes for trapping user input:)

My website

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...