Ok so start of with creating a circle, doesn't matter what colour or anything. This will be your character. Call it man, and make sure it's a movie clip.
Now we are going to create the energy bar. Go back to the main stage and create a retangle, any colour you want. Select it and press f8, call it bar and make sure it's a movie clip. Go back to the main stage, select the bar, and press ctrl+f3 to open up the properties inspector. Do the following:
W:100.0 X:19.0
H:19.0 Y:19.0
Then set the instances name to 'bar' WITHOUT the quotations. Now select the man, and press f9 to open the actions panel. Copy and paste these actions in the action panel:
onClipEvent (load) {
moveSpeed = 5;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.SHIFT) && _root.bar._width>=3) {
moveSpeed += 0.5;
} else {
moveSpeed -= 0.5;
}
if (Key.isDown(Key.LEFT)) {
this._x -= moveSpeed;
}
if (Key.isDown(Key.RIGHT)) {
this._x += moveSpeed;
}
if (Key.isDown(Key.UP)) {
this._y -= moveSpeed;
}
if (Key.isDown(Key.DOWN)) {
this._y += moveSpeed;
}
if (moveSpeed >10){
moveSpeed = 10;
}
if (moveSpeed <5){
moveSpeed = 5;
}
}
Explanation: This is fairly simple. It sets the movespeed of the character to 5. Then says that if the key shift it down, AND the bar width is bigger than 3, then increase the movespeed by 0.5, until it reaches 10, and thats its max speed. Then if the shift key is not down, decrease the movespeed by 0.5, and minimum movespeed is 5. The rest is just the basic movements for your character.
Now select your bar movie clip, and press f9, and put these actions inside:
onClipEvent (enterFrame) {
if (Key.isDown(Key.SHIFT)) {
_width -= 3;
} else {
_width += 1;
}
if (_root.bar._width>=100) {
_width = 100;
}
}
Explanation: All this says is that if the shift key is down, make the bar width decrease by 3, or if the shift key is not down, increase the bar width by 1. Then the second part basically says if the bar width is bigger than 100, set the width to 100. This insures that the bar width will not go past it original width.
There you go, test your movie, and it you will be able to press shift, and your character will move twice as fast, and the sprint bar will decrease.
There is one more thing you can add, it's a cool number that will follow the enery bar, showing the percentage of energy left.
Select the text tool, open up the properties inspector, and select a dynamic textbox. Create a dynamic textbox, and make it big enough so that it can fit 3 numbers in it. Now select the textbox, and open up its properties inspectors, and make the var 'sprint' without the quotations. Select the textbox and press f8, and make it a movie clip called Sprint Text. Go back to the main stage, select the textbox Movie clip, and open it's properties inspector. Set these properties to it:
W: 35.0 X: 120.0
H: 24.1 Y: 16.8
Now select the textbox, and press f9 to open up its actions. Copy and paste these actions inside:
onClipEvent (load) {
sprint = 100;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.SHIFT)) {
sprint -= 3;
_x -= 3;
} else {
sprint += 1;
_x += 1;
}
if (_x<22>=120) {
_x = 120;
}
if (sprint <0>= 100) {
sprint = 100;
}
}
Explanation: This all just is repeat from all the other scripts. Pretty self-explanatory.
There, test your movie, you should now have a percentage that shows how much energy you have left. You can find the SWF example here: http://media.putfile.com/Example-9
If there are any errors please tell me so I can fix them.
~Minty