hi i have created a game called balloon pop, i draw an archer, arrow and a balloon. My archer start to walk but the main problem is the arrows it doesnt wanna shoot an arrow could some pls help me to solve this. Im new to actionscript.
Code:
package
{
import flash.events.*;
import flash.display.MovieClip;
import flash.ui.Keyboard;
public class archer extends MovieClip{
public var rightArrow:Boolean = false;
public var leftArrow:Boolean = false;
public function archer():void{
this.gotoAndStop('still');
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed);
stage.addEventListener(KeyboardEvent.KEY_UP, keyReleased);
addEventListener(Event.ENTER_FRAME, Walk);
}
function keyPressed(event:KeyboardEvent)
{
if (event.keyCode==Keyboard.RIGHT)
{
this.gotoAndStop('walking');
rightArrow=true;
}
else if (event.keyCode==Keyboard.LEFT)
{
this.gotoAndStop('walking');
leftArrow=true;
}
}
function keyReleased(event:KeyboardEvent)
{
if (event.keyCode==Keyboard.RIGHT)
{
this.gotoAndStop('still');
rightArrow=false;
}
else if (event.keyCode==Keyboard.LEFT)
{
this.gotoAndStop('still');
leftArrow=false;
}
}
public function Walk(event:Event):void
{
if (rightArrow == true)
{
this.x+=10;
}
if (leftArrow == true)
{
this.x-=10;
}
}
}
}
the code for the archer
Code:
package
{
import flash.display.MovieClip;
import flash.events.*;
public class arrows extends MovieClip{
{
Mouse.hide();
attachMovie("archer");
archer.onEnterFrame = function() {
mousex = _xmouse-this._x;
mousey = (_ymouse-this._y)*-1;
angle = Math.atan(mousey/mousex)/(Math.PI/180);
if (mousex<0) {
angle += 180;
}
if (mousex>=0 && mousey<0) {
angle += 360;
}
if (angle>160) {
angle = 160;
}
if (angle<20) {
angle = 20;
}
firepower = Math.sqrt(mousex*mousex+mousey*mousey);
if (firepower>200) {
firepower = 200;
}
this.archer._rotation = angle*-1;
};
function onMouseDown() {
angle = archer.cannon._rotation-1;
start_arrows_x = archer._x+48*Math.cos(angle*Math.PI/180);
start_arrows_y = archer._y+48*Math.sin(angle*Math.PI/180);
arrow_fired = attachMovie("arrow", "arrow_"+_root.getNextHighestDepth(), _root.getNextHighestDepth(), {_x:start_ball_x, _y:start_ball_y});
arrow_fired.dirx = Math.cos(angle*Math.PI/180)*firepower;
arrow_fired.diry = Math.sin(angle*Math.PI/180)*firepower;
arrow_fired.onEnterFrame = function() {
this._x += this.dirx/50;
this._y += this.diry/50;
};
}
}
}
}
code for the arrows.. thx in advance and merry xmas.