Making a small game in delphi, need help with movement.
I'm basically making a small game, it involves click and kill mechanics. The image must start off the screen (not visible) then it must move in a random direction onto the screen. Once it goes off the screen (or clicked) it will respawn again onto one of the sides (off the screen) and will again go in a random direction (one of 8 directions). A number will be added to the score, but this isn't really relevant (it's fairly easy to pull off). The image will also have random sizes (within a certain thresh-hold).
I tried to do this, several attempts at it actually, but I can't seem to get what I want to happen. Ive looked all over the internet and can't find a solution. I am a bit of a noob. The code for how to pull off some of this would be extremely helpful.
June 20th, 2012, 01:22 AM
You must break down your problem into smaller ones and attack them one by one. Your current question is simply asking someone to finish the whole project for you.
June 21st, 2012, 10:09 AM
What you're talking about sounds like a sprite moving across an image. Store the sprite image in a TBitmap object. Put a TImage on the form. Use Canvas.Draw in TImage to draw the sprite bitmap at a given position. Use Canvas.CopyRect to erase the sprite from its previous position first (you can store another bitmap of the background). That should work but you may find that you get flickering. In that case use an off-screen bitmap and draw everything on that and then draw it directly on the form's canvas for each frame. That's the graphics side.
Use a TTimer for the animation and redraw the image in its ontimer event.
If you need keyboard controls then use GetKeyboardState.
Hope that helps a bit.