Jul
23
2008
This is the continuation and final chapter of the Jetman and the Helicopter Game Tutorial series .
Read part one here.
Wall collision:
Now it is time to make the helicopter actually check for the walls.
The Wall Class:
package
{
import flash.display.MovieClip;
import flash.events.Event;
public class Wall extends MovieClip
{
public var bPlaying:Boolean = false;
public function Wall ( BStarting:Boolean ) : void
{
bPlaying = BStarting;
this.addEventListener ( Event.ENTER_FRAME, onEnterFrameHandler );
}
private function onEnterFrameHandler ( E:Event ) : void
{
if ( bPlaying )
{
this.x -= 15;
}
}
public function EndGame ( ) : void
{
this.removeEventListener ( Event.ENTER_FRAME, onEnterFrameHandler );
}
}
}
Lines 25-28: A public function that removes the event listener for the instance of the Wall class.
Continue Reading »
Jul
22
2008
I remember playing the Helicopter game and thinking it was extremely complex. Looking back on it now, I realize it is probably one of the easiest flash games on the internet to clone. Jetman, a popular game on Facebook is actually a clone of the helicopter game. In fact, it is so easy, it can be programmed in less than 400 lines of code! So let’s get started.
The Title Screen:
The title screen is supposed to disappear when you click it and start the game.
Document Class:
package
{
import flash.display.Sprite;
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class Main extends Sprite
{
private var TitleScreen:StartScreen;
private var bGameStarted:Boolean;
public function Main ( ) : void
{
addTitleScreen();
stage.addEventListener ( MouseEvent.MOUSE_DOWN, mouseDownHandler );
stage.addEventListener ( MouseEvent.MOUSE_UP, mouseUpHandler );
}
private function addTitleScreen ( ) : void
{
TitleScreen = new StartScreen ();
TitleScreen.x = stage.stageWidth/2 + 100;
TitleScreen.y = stage.stageHeight/2;
this.addChild(TitleScreen);
bGameStarted = false;
}
private function startGame ( ) : void
{
}
private function mouseDownHandler ( ME:MouseEvent ) : void
{
if ( bGameStarted == false )
{
bGameStarted = true;
this.removeChild(TitleScreen);
}
}
private function mouseUpHandler ( ME:MouseEvent ) : void
{
}
}
}
Lines 1-8: Importing the classes I need, setting up the class.
Lines 9-10: Creating two variables. The first holds the TitleScreen. It is of type StartScreen which is a movieclip with linkage in the library. The second is a boolean to let us know if the game has started.
Lines 12-18: Running the function to add the TitleScreen and adding a MOUSE_DOWN and a MOUSE_UP event listener in the constructor.
Lines 20-28: Adding the TitleScreen to the stage and setting the bGameStarted variable to false.
Lines 35-42: The MOUSE_DOWN handler function. If bGameStarted is false, then start the game and remove the title screen.
Continue Reading »
Jul
14
2008
This post is a continuation of a previous post, Raiden Part 1.
WARNING! REFRESH THIS PAGE EVERY ONCE IN A WHILE! THE SWFS DO NOT HAVE CHECKS BECAUSE I WANTED YOU TO ACTUALLY SEE THE PROBLEMS STEP BY STEP AND BE ABLE TO FIX THEM. BECAUSE OF THIS, YOUR BROWSER WILL START EATING A LOT OF MEMORY AND POSSIBLY FREEZE YOUR COMPUTER!
Now it is time to add the background. For this game, it is just going to be a simple background of stars.
Adding a star:
Continue Reading »
Jul
10
2008
There are a lot of games that use the “click a point and the character moves there” type of control method. Probably one of my favorites was the Diablo’s.
To achieve this effect in Flash is really simple. The main thing to use is the Tween class. The Tween class lets you create dynamic Tweens through code.
Tween Movement 1.0:
package
{
import flash.display.Sprite;
import flash.display.MovieClip;
import fl.transitions.easing.*;
import fl.transitions.Tween;
import flash.events.MouseEvent;
public class TweenMovement extends Sprite
{
private var Character:RedBall;
public function TweenMovement ( ) : void
{
Character = new RedBall ();
Character.x = 200;
Character.y = 200;
stage.addChild(Character);
stage.addEventListener ( MouseEvent.CLICK, moveCharacter );
}
private function moveCharacter ( ME:MouseEvent ) : void
{
var twMoveX:Tween = new Tween ( Character, "x", Regular.easeOut, Character.x, ME.currentTarget.mouseX, 2, true );
var twMoveY:Tween = new Tween ( Character, "y", Regular.easeOut, Character.y, ME.currentTarget.mouseY, 2, true );
}
}
}
Continue Reading »