Items – The important stuff

Lovely image of the monsters heading for the beach and the magician thinking up three items to summon.

Lovely image of the monsters heading for the beach and the magician thinking up three items to summon.

Magic writer is a game concept me and a group of other people are developing.
In this you play as a magician that has a holiday on a tropical beach. Unfortunately he is interrupted by monster invading the beach. Ah no holiday this time.

The magician is skilled in summoning magic. So he uses this to summon objects and throwing them with magic on the monsters. By doing this the monsters will be defeated and the oncoming tide halted. Summoning is done by typing in the word of the item displayed on the screen.

So the game needs items of some kind to be implemented in the game so you can summon them and throw them. I with this in mind decided to make an item class that inherit from entity class. This is made to handle everything about the item, to manage its operations and give info about it like position and size etc.

But before this is done we need some items. These I decided to load in from a text file. In the text document was information first what kind of entity and how many. Then was the path to the image file where the sprites (Items) will be taken from. After that the positions and name of the item.

Using a function to load the items from the file. The number of objects are taken from the file and it does a loop that many times, so it gets all the items. In loop the positions and size are loaded into variables and then put into a sprite along with the texture (image), the sprite has a function which basically copies a piece of the image at the position given and making it the given size.

text file and item class:
Item
Item

ItemPickup

magician has summoned a zombie and is ready to throw it

The sprite is put in an object of the item class, which in turn is put in a list of entities. In the class entity there is an enumerator (basically a list of numbers with a name ex. ENTITY_ITEM) containing different types of entities. These are used to identify and interact with program, to know what type of entity it is and what it should do in that case.

Item is given the type ENTITY_ITEM and a word connected to the sprite, the item calls a class that contains positions and is allocated one that is free. There is three positions for items and texts/words. The word is then placed on the same position but higher up, so they end up above the items. This allocation is only done when the entity is activated. This is so that it has no position before and just the three positions for items are used, this make it easy control and check if there are an item on that position.

The item class has function hold that is used to indicate if the object is being held by the character. When the character is holding it it sets to holding and entity type switch to projectile. When the item is the projectile type it has different properties. When updated it will travel straight forward but only when not being held any more. This is when the player presses the firing button.

ThrowingPoodle

Magician throwing a poodle at a monster

Each monster has a weakness Alive, Dead, Hard, Soft and each item has a combination of these. Alive and Soft in the poodles case. If a monster is hit by an item with the same property it takes more damage. So there is an enumerator in entity with the weaknesses and each item and monster is set to a weakness.  When the item and monster collide there is a check on whether any weakness match.

About Isak Ekedahl

2014  Programming