Computer Science Canada Game Engine problem (based off of the tutorial) |
Author: | rcbhs [ Tue Jan 06, 2009 12:42 pm ] | ||||||
Post subject: | Game Engine problem (based off of the tutorial) | ||||||
Soooo, I am trying to expand the Game Engne tutorial to work with my own game. Now a quick explination is...I want to make it so I can place objects as sprites instead of pictures. I am not exactly sure how to do this. Where would I put the Sprite.New, Sprite.SetHeight, Sprite.SetLocation, etc... I am really confused here. MageObjects.t:
mageGame.t (driver):
mageEngine.t:
Well you don't have the files so it won't work, however that is the code there. So my problem is, instead of a picture I want that to be a sprite (so I can do some movement animation. Also, what if I don't want 8 point movement? Just 4 point? What do I change there?) |
Author: | DemonWasp [ Tue Jan 06, 2009 1:41 pm ] | ||
Post subject: | RE:Game Engine problem (based off of the tutorial) | ||
Well, there are a few strategies: Simple, Easy Strategy: Each player has their own image / sprite. In the class, add a method called "setup" (these are technically called "constructors", but I don't think Turing has those); that's where you would do your Pic.New and your Sprite.New calls. You should also add a "destroy" method (destructor) which calls Sprite.Free and Pic.Free. Then, in move, you'd do the Sprite.SetLocation. Harder, More Efficient Strategy: A lot of your players may be using the same image (particularly if you want to use things like projectiles). It would be really cumbersome to load the same image over and over, so why not make a "library" of images. A library looks like this:
In this case, Pic.New is within ImageLibrary.GetImage, while Sprite.New is still in a constructor ("setup") method and Sprite.Free is in a destructor ("destroy") method. Pic.Free should only be called in ImageLibrary.Destroy, which is only called to clean up after your game. This strategy is somewhat more difficult, but should save you headaches later with running out of the number of images you can load and performance issues. 4 versus 8-point movement The solution to this is somewhere between the Update() and Move() procedures, you need to limit the entities to 4-point movement. |