Wizard test updated with ability to hurl magic

Well things moved at a bit more pace last night as I quickly introduced the fire button in to my simple canvas anim test.
I love the ability to string animation frames together in to a single spritesheet and have the code logically step through to locate the frame to display. Reminds me of my GameBody Advance days which is no bad thing.

So I created an additional frame to display when the wizard is hurling magic.

Wizard sprite sheet

Wizard sprite sheet

I intend to add frames to allow the player to hold down the fire button and charge up the magic in the wizard’s hand before hurling it. Perhaps another 3 or 4 frames that are activated the longer the player holds the button down. Of course releasing the fire button before the magic is fully charged stops the process altogether and the wizard defaults back to the standing frame.

The key to this is adding a bit more structure to the spritesheet class such I am able to set the frames that correspond to each action.

I may use properties within the class such as:

this.attackframe
this.attackframecount

which will allow me to go straight to the attack frames when the player is shooting missiles.

My approach with the player missiles (magic bolts) is the same as in all my games.
I define what I call a pot of missiles to pick from. The size of the pot (array) is identical to the amount of missiles that I am prepared to let the player shoot at any one time. i.e. the maximum number of missiles on screen at any one time.

Each sprite in the missile array has an alive flag which by default is set to false.
When the player presses the fire button the code loops through the array looking for a missile that isn’t alive.
When it finds one it sets its status to true, initialises it’s position to that of the missile initiator (in this case the player sprite) and breaks out of the loop. When the missile expires (reaches canvas edge, strikes a target) I kill() it which effectively sets its status to false again and therefore renders it available for selection once more. Strictly speaking I should also move it well off screen to a negative location (e.g. -32, -32).

So there you have it. Take a look at the results here: www.wilfscorner.co.uk/sandpit/1/wizard3.php

 

Advertisements
Post a comment or leave a trackback: Trackback URL.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: