Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > General > Gaming and Game Development

Reply
 
Thread Tools Rate Thread Display Modes
Old 12-11-2010, 02:46 PM   #1
musikako
Registered User
 
Join Date: Nov 2010
Posts: 11
Default [AS3] shooting an arrows to pop balloon

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.
musikako is offline   Reply With Quote
Old 12-11-2010, 03:07 PM   #2
henke37
Senior Member
 
henke37's Avatar
 
Join Date: Mar 2009
Location: Sweden
Posts: 10,673
Send a message via Skype™ to henke37
Default

The indention is busted and parts of this looks like as 2. Go and read up on the differences. Such as there being no magic callback properties and the underscores being removed.

It is a miracle that this code even compiles. Did you turn off strict compiling?
__________________
Signature: I wrote a pair of articles about the timeline.
henke37 is online now   Reply With Quote
Old 12-11-2010, 03:12 PM   #3
musikako
Registered User
 
Join Date: Nov 2010
Posts: 11
Default

i dont know the strict compiling as i wrote im new to the actionscript and dunno where to start.
musikako is offline   Reply With Quote
Old 12-12-2010, 03:07 AM   #4
musikako
Registered User
 
Join Date: Nov 2010
Posts: 11
Default

i got a problem with the arrow class

Quote:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at archer()
at arrows()
at flash.display::Sprite/constructChildren()
at flash.display::Sprite()
at flash.display::MovieClip()
at BalloonPop()
Code:
package
{
	import flash.display.Sprite;
	import flash.display.MovieClip;
	import flash.events.*;
	
	public class arrows extends MovieClip{
		public var arc:MovieClip = new archer();
		public function arrows():void
		{
			addEventListener(Event.ENTER_FRAME, onEnter);
			stage.addEventListener(MouseEvent.CLICK, onClick);
		}
		
		function onEnter(event:MouseEvent)
		{
			arc.x-=(arc.x-mouseX)*.1;
			arc.y-=(arc.y-350)*.2;
		}
		
		function onClick(event:MouseEvent)
		{
			arc.y=365;
			var ar:Sprite = new arrows();
			ar.y=arc.y;
			ar.x=arc.x;
			addChild(ar);
		}


	}
}
musikako is offline   Reply With Quote
Old 12-12-2010, 09:46 AM   #5
musikako
Registered User
 
Join Date: Nov 2010
Posts: 11
Default shooting an arrows to pop balloon

I dont know what the problem is, when i clicked the mouse the arrow shows up but it doesnt shoot vertically.
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 var arr:MovieClip = new arrows();
		public function archer():void{
			
			
			this.gotoAndStop('still');
			stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed);
            stage.addEventListener(KeyboardEvent.KEY_UP, keyReleased);
            stage.addEventListener(MouseEvent.CLICK, onClick);
			addEventListener(Event.ENTER_FRAME, Walk);
        }
		
		function onClick (event:MouseEvent)
		{
			addChild(arr);
		}

        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;
			}
        }
    }
}
it is an as3 files.. pls help me. thx in advance
musikako is offline   Reply With Quote
Old 12-12-2010, 10:17 AM   #6
henke37
Senior Member
 
henke37's Avatar
 
Join Date: Mar 2009
Location: Sweden
Posts: 10,673
Send a message via Skype™ to henke37
Default

No, you don't. If you read properly, you see that the error lies in the archer class.

Run it in the debugger and you will see the error as it happens.
__________________
Signature: I wrote a pair of articles about the timeline.
henke37 is online now   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:18 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.