Click here to Skip to main content
15,892,768 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to give movement to a bitmap inserted in a directx window, like tetris but only the falling part (free fall down direction), I supose it needs a timer and the coordinates can someone give me a sample code?(I am a newbie). So far I have created the window inserted the main bitmap but I need the animation falling.

Thank you
Kyriakos
Posted
Updated 14-Nov-10 8:08am
v2
Comments
Henry Minute 14-Nov-10 14:20pm    
There are loads of Tetris clones on the web. Use a search engine to search you will have loads of code to browse.

No, you shouldn't use a timer. Typically, what you will have to do is have a class that represent an entity (in the case of the tetris, a class representing a block). It is the responsability of this class to manage the movement of the block and to draw the image of the block on the screen.
Your main loop constantly update all elements of your code and they update their positions depending if they are in movement or not.
If you are interested, you can have a look at a tutorial I made about openGL here[^] (the second part is more likely to interest you). This is specific to OpenGL but movement is also covered.
 
Share this answer
 
You mean I will create the class and have a function that will update the x,y coordinates to 1 or 2 ... and in the loop in every rate this will happen?

Kyriakos
 
Share this answer
 
Comments
Cedric Moonen 15-Nov-10 6:04am    
What you could do is have an update(int timeElapsed) method of the class. The timeElapsed argument represent the amount of msec elapsed since the last class to update. Inside the class, you can specify its speed and easily calculate the new position of the sprite (based on the previous position and time elapsed). The update method is constantly called from your main loop (you have control over your main loop so you can adjust the update rate).
Can you give me a sample code?

Thank you
Kyriakos
 
Share this answer
 
Comments
aayu 15-Nov-10 6:23am    
no one will help you for the code... search in google you will get many sample code
Cedric Moonen 15-Nov-10 6:51am    
Did you have a look at the link I provided ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900