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 01-06-2010, 09:48 AM   #1
Broth3R
Registered User
 
Join Date: Dec 2009
Posts: 12
Question [AS3] Space Invader (create bullet) AS2 to AS3

This code work fine in AS2, but how do you change it to AS3? I want to see the different between AS2 and AS3 and try to learn more about AS3.

Code:
//======= fireBullet creates a bullet and attaches a moveBullet behaviour to its onEnterFrame event
//
function fireBullet() {
	numBombs = getNextHighestDepth();
	attachMovie("bomb", "aBomb" + numBombs, numBombs);
	this["aBomb" + numBombs].onEnterFrame = moveBullet;
	with (this["aBomb" + numBombs]) {
		_xscale = _yscale = 75;
		_x = theTank._x;
		_y = theTank._y - theTank._height / 2;
	}
}
//
// ====== Basically moves each bullet up the screen; when it hits the top edge, or the bottom of the info_txt box, 
// we create and attach an explosion symbol at the point of contact, then remove the associated Bullet movie clip.
//
function moveBullet() {
	this._y -= 10;
	hit = this.hitTest(alien_mc);
	if (this._y < 0 || this.hitTest(_root["info_txt"]) || hit) {
		numExplosions = getNextHighestDepth();
		_root.attachMovie("explosion_mc", "explosion" + numExplosions, numExplosions);
		// ==== swapDepths just swaps the depths of two movieclips. Since we created info_txt first, it is "beneath" all of the other clips we've created.
		// swapping the depths "brings it the the front".  Try commenting out the line below to see why we need to swap. Can you explain what happens?
		//=================================
		_root["explosion" + numExplosions].swapDepths(_root["info_txt"]);
		_root["explosion" + numExplosions].onEnterFrame = function() {
			// response to the EnterFrame event for the explosion movie clip: don't want to loop exploding so get rid of ourselves after a single play;
			// uses the _currentframe & _totalframes properties to see if we've got to the end of the mc.
			if (this._currentframe > this._totalframes - 1) {
				removeMovieClip(this);
			}
		};
		with (_root["explosion" + numExplosions]) {
			_x = this._x;
			_y = this._y + 10;
			_xscale = _yscale = 50;
		}
		removeMovieClip(this);
		if (hit) {
			with (alien_mc) {
				_x = Math.random() * 500 + 20;
				_y = 0;
			}
		}
	}
}

Last edited by Broth3R; 01-07-2010 at 05:51 PM.
Broth3R is offline   Reply With Quote
Old 01-07-2010, 05:49 PM   #2
Broth3R
Registered User
 
Join Date: Dec 2009
Posts: 12
Default

This is just like the 'space invader' game
Broth3R is offline   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 11:56 PM.

///
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.