Wednesday, 26 December 2012

Action script.

All of the action script was made in separate files this was to done so i could see the individual classes, to do this i had to use a slightly different method to add the classes and functions to the main FLA. To do this i had to;

  1. name the files appropriate to the class name
  2. have everything on a file inside a "package"
  3. import everything buy using the "import statement"
Avatar

package
{
import flash.display.MovieClip;
public class Avatar extends MovieClip
{
public function Avatar()
{

}
}
}

Enemy

package
{
import flash.display.MovieClip;
public class Enemy extends MovieClip
{
public function Enemy( startX:Number, startY:Number )
{
x = startX;
y = startY;
}

public function moveDownAbit():void
{
var xSpeed:Number = 0; //pixels moved to the right per tick
var ySpeed:Number = 6; //pixels moved downwards per tick

x = x + xSpeed;
y = y + ySpeed;
}
}
}
Score

package
{
import flash.text.TextField;
public class Score extends Counter
{
public function Score()
{
super();
}
override public function updateDisplay():void
{
super.updateDisplay();
scoreDisplay.text = currentValue.toString();
}
}
}
Menu Screen

package
{
import flash.display.MovieClip;
import flash.display.SimpleButton;
import flash.events.MouseEvent;

public class MenuScreen extends MovieClip
{
public function MenuScreen()
{
startButton.addEventListener( MouseEvent.CLICK, onClickStart );
}

public function onClickStart( event:MouseEvent ):void
{
dispatchEvent( new NavigationEvent( NavigationEvent.START ) );
}
}
}
Navigation Event

package
{
import flash.events.Event;
public class NavigationEvent extends Event
{
public static const RESTART:String = "restart";
public static const START:String = "start";
public function NavigationEvent( type:String )
{
super( type );
}
}
}
Avatar Event

package
{
import flash.events.Event;
public class AvatarEvent extends Event
{
public static const DEAD:String = "dead";

public function AvatarEvent( type:String )
{
super( type );
}
}
}
Counter

package
{
import flash.display.MovieClip;
public class Counter extends MovieClip
{
public var currentValue:Number;

public function Counter()
{
reset();
}

public function addToValue( amountToAdd:Number ):void
{
currentValue = currentValue + amountToAdd;
updateDisplay();
}

public function reset():void
{
currentValue = 0;
updateDisplay();
}

public function updateDisplay():void
{

}
}
}
Level Data

package
{
public class LevelData
{
public var backgroundImage:String;
public var pointsToReachNextLevel:Number;
public var enemySpawnRate:Number;
public var levelNum:Number;

public function LevelData( levelNumber:Number )
{
levelNum = levelNumber;
{
backgroundImage = "grey";
pointsToReachNextLevel = 500;
enemySpawnRate = 0.1;
}
if ( levelNumber == 2 )
{
backgroundImage = "red";
pointsToReachNextLevel = 1500;
enemySpawnRate = 0.2;
}
if ( levelNumber == 3 )
{
backgroundImage = "skyblue";
pointsToReachNextLevel = 2500;
enemySpawnRate = 0.3;
}
if ( levelNumber == 4 )
{
backgroundImage = "black";
pointsToReachNextLevel = 3500;
enemySpawnRate = 0.5;
}
if ( levelNumber == 5 )
{
backgroundImage = "blue";
pointsToReachNextLevel = 99999;
enemySpawnRate = 0.55;
}
}
}
}
Game Over Screen

package
{
import flash.display.MovieClip;
import flash.display.SimpleButton;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.ui.Mouse;
import flash.net.SharedObject;

public class GameOverScreen extends MovieClip
{
var sharedObject:SharedObject;

public function GameOverScreen()
{
Mouse.show();
restartButton.addEventListener( MouseEvent.CLICK, onClickRestart );
sharedObject = SharedObject.getLocal("alienavoider");
}
public function onClickRestart( mouseEvent:MouseEvent ):void
{
dispatchEvent( new NavigationEvent( NavigationEvent.RESTART ) );
}
public function setFinalScore( scoreValue:Number ):void
{
finalScore.text = scoreValue.toString();
try
{
if (sharedObject.data.bestScore == null)
{
sharedObject.data.bestScore = scoreValue;
}
else if ( scoreValue > sharedObject.data.bestScore )
{
sharedObject.data.bestScore = scoreValue;
}
bestScore.text = sharedObject.data.bestScore.toString();
sharedObject.flush();
}
catch (sharedObjectError:Error)
{
trace( "Caught this error:", sharedObjectError.name, sharedObjectError.message );
bestScore.text = "???";
}
}
}
}
Pixel Perfect Collision

package
{
import flash.display.BitmapData;
import flash.display.BitmapDataChannel;
import flash.display.BlendMode;
import flash.display.DisplayObject;
import flash.display.DisplayObjectContainer;
import flash.geom.Matrix;
import flash.geom.Point;
import flash.geom.Rectangle;
public class PixelPerfectCollisionDetection
{
/** Get the collision rectangle between two display objects. **/
public static function getCollisionRect(target1:DisplayObject, target2:DisplayObject, commonParent:DisplayObjectContainer, pixelPrecise:Boolean = false, tolerance:Number = 0):Rectangle
{
// get bounding boxes in common parent's coordinate space
var rect1:Rectangle = target1.getBounds(commonParent);
var rect2:Rectangle = target2.getBounds(commonParent);
// find the intersection of the two bounding boxes
var intersectionRect:Rectangle = rect1.intersection(rect2);
if (intersectionRect.size.length> 0)
{
if (pixelPrecise)
{
// size of rect needs to integer size for bitmap data
intersectionRect.width = Math.ceil(intersectionRect.width);
intersectionRect.height = Math.ceil(intersectionRect.height);
// get the alpha maps for the display objects
var alpha1:BitmapData = getAlphaMap(target1, intersectionRect, BitmapDataChannel.RED, commonParent);
var alpha2:BitmapData = getAlphaMap(target2, intersectionRect, BitmapDataChannel.GREEN, commonParent);
// combine the alpha maps
alpha1.draw(alpha2, null, null, BlendMode.LIGHTEN);
// calculate the search color
var searchColor:uint;
if (tolerance <= 0)
{
searchColor = 0x010100;
}
else
{
if (tolerance> 1) tolerance = 1;
var byte:int = Math.round(tolerance * 255);
searchColor = (byte <<16) | (byte <<8) | 0;
}
// find color
var collisionRect:Rectangle = alpha1.getColorBoundsRect(searchColor, searchColor);
collisionRect.x += intersectionRect.x;
collisionRect.y += intersectionRect.y;
return collisionRect;
}
else
{
return intersectionRect;
}
}
else
{
// no intersection
return null;
}
}
/** Gets the alpha map of the display object and places it in the specified channel. **/
private static function getAlphaMap(target:DisplayObject, rect:Rectangle, channel:uint, commonParent:DisplayObjectContainer):BitmapData
{
// calculate the transform for the display object relative to the common parent
var parentXformInvert:Matrix = commonParent.transform.concatenatedMatrix.clone();
parentXformInvert.invert();
var targetXform:Matrix = target.transform.concatenatedMatrix.clone();
targetXform.concat(parentXformInvert);
// translate the target into the rect's space
targetXform.translate(-rect.x, -rect.y);
// draw the target and extract its alpha channel into a color channel
var bitmapData:BitmapData = new BitmapData(rect.width, rect.height, true, 0);
bitmapData.draw(target, targetXform);
var alphaChannel:BitmapData = new BitmapData(rect.width, rect.height, false, 0);
alphaChannel.copyChannel(bitmapData, bitmapData.rect, new Point(0, 0), BitmapDataChannel.ALPHA, channel);
return alphaChannel;
}
/** Get the center of the collision's bounding box. **/
public static function getCollisionPoint(target1:DisplayObject, target2:DisplayObject, commonParent:DisplayObjectContainer, pixelPrecise:Boolean = false, tolerance:Number = 0):Point
{
var collisionRect:Rectangle = getCollisionRect(target1, target2, commonParent, pixelPrecise, tolerance);
if (collisionRect != null && collisionRect.size.length> 0)
{
var x:Number = (collisionRect.left + collisionRect.right) / 2;
var y:Number = (collisionRect.top + collisionRect.bottom) / 2;
return new Point(x, y);
}
return null;
}
/** Are the two display objects colliding (overlapping)? **/
public static function isColliding(target1:DisplayObject, target2:DisplayObject, commonParent:DisplayObjectContainer, pixelPrecise:Boolean = false, tolerance:Number = 0):Boolean
{
var collisionRect:Rectangle = getCollisionRect(target1, target2, commonParent, pixelPrecise, tolerance);
if (collisionRect != null && collisionRect.size.length> 0) return true;
else return false;
}
}
}
Document Class

package
{
import flash.display.MovieClip;
public class DocumentClass extends MovieClip
{
public var menuScreen:MenuScreen;
public var playScreen:AvoiderGame;
public var gameOverScreen:GameOverScreen;

public function DocumentClass()
{
menuScreen = new MenuScreen();
menuScreen.addEventListener( NavigationEvent.START, onRequestStart, false, 0, true );
menuScreen.x = 0;
menuScreen.y = 0;
addChild( menuScreen );

stage.focus = menuScreen;
stage.stageFocusRect = false;
}

public function onAvatarDeath( avatarEvent:AvatarEvent ):void
{
var finalScore:Number = playScreen.getFinalScore();
gameOverScreen = new GameOverScreen();
gameOverScreen.addEventListener(NavigationEvent.RESTART, onRequestRestart, false, 0, true );
gameOverScreen.x = 0;
gameOverScreen.y = 0;
gameOverScreen.setFinalScore( finalScore );
addChild( gameOverScreen );

removeChild( playScreen );
playScreen = null;

stage.focus = gameOverScreen;
}

public function onRequestStart( navigationEvent:NavigationEvent ):void
{
playScreen = new AvoiderGame();
playScreen.addEventListener(AvatarEvent.DEAD, onAvatarDeath, false, 0, true );
playScreen.x = 0;
playScreen.y = 0;
addChild( playScreen );

removeChild( menuScreen );
menuScreen = null;

stage.focus = playScreen;
}

public function onRequestRestart( navigationEvent:NavigationEvent ):void
{
restartGame();
}

public function restartGame():void
{
playScreen = new AvoiderGame();
playScreen.addEventListener( AvatarEvent.DEAD, onAvatarDeath, false, 0, true );
playScreen.x = 0;
playScreen.y = 0;
addChild( playScreen );

removeChild( gameOverScreen );
gameOverScreen = null;

stage.focus = playScreen;
}
}
}
Avoider Game

package
{
import flash.display.MovieClip;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.ui.Mouse;

public class AvoiderGame extends MovieClip
{
public var army:Array;
public var enemy:Enemy;
public var avatar:Avatar;
public var gameTimer:Timer;
public var currentLevelData:LevelData;

public function AvoiderGame()
{
currentLevelData = new LevelData(1);
if (currentLevelData.backgroundImage == "grey")
{
backgroundContainer.addChild( new GreyBackground() );
}
else if ( currentLevelData.backgroundImage == "red" )
{
backgroundContainer.addChild( new RedBackground() );
}
Mouse.hide();
army = new Array();


avatar = new Avatar();
addChild( avatar );
avatar.x = mouseX;
avatar.y = mouseY;

gameTimer = new Timer(25);
gameTimer.addEventListener( TimerEvent.TIMER, onTick );
gameTimer.start();
}

public function onTick( timerEvent:TimerEvent ):void
{
if (Math.random() < currentLevelData.enemySpawnRate)
{
var randomX:Number = Math.random() * 800;
var newEnemy:Enemy = new Enemy(randomX,-15);
army.push( newEnemy );
addChild( newEnemy );
gameScore.addToValue( 10 );
}
avatar.x = mouseX;
avatar.y = mouseY;

var i:int = army.length - 1;
var enemy:Enemy;
while ( i > -1 )
{
enemy = army[i];
enemy.moveDownAbit();
if ( PixelPerfectCollisionDetection.isColliding( avatar, enemy, this, true ) )
{
gameTimer.stop();
dispatchEvent( new AvatarEvent( AvatarEvent.DEAD ) );
}
if (enemy.y > 480)
{
removeChild( enemy );
army.splice( i, 1 );
}
i = i - 1;
}

if (gameScore.currentValue >= currentLevelData.pointsToReachNextLevel)
{
currentLevelData = new LevelData(currentLevelData.levelNum + 1);
setBackgroundImage();
}
}
public function setBackgroundImage():void
{
if (currentLevelData.backgroundImage == "grey")
{
backgroundContainer.addChild( new GreyBackground() );
}
else if ( currentLevelData.backgroundImage == "red" )
{
backgroundContainer.addChild( new RedBackground() );
}
else if ( currentLevelData.backgroundImage == "skyblue" )
{
backgroundContainer.addChild( new BlueBackground() );
}
else if ( currentLevelData.backgroundImage == "black" )
{
backgroundContainer.addChild( new BlackBackground() );
}
}
public function getFinalScore():Number
{
return gameScore.currentValue;
}
}
}











Tuesday, 23 October 2012

Article about Flash

Flash and IDE's
Flash is used for many things such as:


Animation,Vector based Graphics,Frames,Library,Timeline etc. This software is great for learning action script and learning about basic animation.

Adobe has helped us out by providing an archive of code snippets to help make the process easier for our self  You just have to find the snippet which you are needing and place it in - you would mostly likely have to tweak it though. If you cannot find the snippet you require in the software, the resources for Flash online are great and often a place to resort for assistance. The software is a powerful authoring environment where many applications can be made.The main application of flash is the IDE.

An IDE is a software application that provides options and facilities to the computer programmers for software development. In Flash you are working with many files dotted all around your computer. This can become very cluttered and hard to keep control of. That is why Flash has a Library. Here you can store all of your assets and simply drag them out when needed. It is ideal to see what exactly you need and what you don't need. It is also a great way to spot problems, for example if a file is named incorrectly you can view all the assets in your scene and make changes accordingly. The library is a vital tool in creating inside of Flash, it helps keep you organised and prevents you from potentially running into problems.

IDE's are designed to maximize programmer productivity by providing tight-knit components with similar user interfaces. This means that the programmer will have to do less mode switches versus using discrete development programs.

The IDE would include a source code editor which in my case would be an action script 3.0 and also a build automation tools along with a debugger in some of them they would include extra features like a interpreter or a contain compile and even both. and a graphical user interface (GUI) builder.

The BASIC programming language, for example, can be used within Microsoft Office applications, which makes it possible to write a Word Basic program within the Microsoft Word application. IDE's provide a user-friendly framework for many modern programming languages, such as Visual Basic, Java, and Power Builder. Some IDE's support multiple languages allows it to be more user friendly.

 Dartmouth BASIC was the first language to be created with an IDE and it was also the first to be designed for use while sitting in front of a console or terminal. Its IDE, that was part of the Dartmouth Time Sharing System was command-based, and therefore did not look much like the menu-driven, graphical IDEs prevalent today. However it integrated editing, file management, compilation, debugging and execution in a manner consistent with a modern IDE.
IDEs initially became possible when developing via a console or terminal. Early systems could not support one, since programs were prepared using flowcharts, entering programs with punched cards (or paper tape, etc.) before submitting them to a compiler.

Wednesday, 19 September 2012

Script


//**************VARIABLES**************/
var gameState:String;
This creates a string variable (Like an envelope) which is adding a variable called gamestate which is for characters.
//*********BEGINNING STUFF**************/
endScreen.visible = false; 
This make the end screen not visible

//**************INTRO SCREEN**************/
introScreen.play_btn.addEventListener (MouseEvent.CLICK, clickAway); Intro screen is a movie clip with the child play_btn that has a function inside it called EventListener that waits for the mouse click.
function clickAway (event:MouseEvent):void {  This makes a function named clickaway which is a mouse event once you click on that, it activates movescreenoff which takes the intro screen off the page but the name movescreenoff could be called anything
      moveScreenOff (introScreen); - calls a function called moveScreenoff
}
function moveScreenOff (screen:MovieClip):void { This mean the function above is now void once clicked. Which means that the function after clicked will no longer go back to the same.
      screen.x = (screen.width)*-1; The screen is moved away I the x axis
      gameState = "INITGAME";  This is the value of gamestate
      addEventListener (Event.ENTER_FRAME, gameLoop); This triggers the enterframe event which when triggered it activates gameLoop
}

//**************STATE_INIT_GAME**************/
function initGame ():void {  The function initgame is being taken away by being void.
trace("add stuff to initGame") This allows the value initgame to show
         gameState = "STARTPLAYER"; The variable gamestate now remembers the word STARTPLAYER.

//**************STATE_START_PLAYER**************/
function startPlayer ():void {
       trace("add player stuff")
      gameState = "PLAYGAME"; The variable gamestate now remembers the word PLAYGAME


//**************STATE_PLAY_GAME**************/
function playGame ():void { This creates the function playeGame
      makeEnemies (); Calls the function maleenemies
      testForEnd (); calls the function testForEnd
}
function makeEnemies ():void { Flash will not return these values by default
     
}
function testForEnd ():void { Flash will not return these values by default
      gameState = "ENDGAME"; Makes gamestate variable to rememeber ENDGAME.
}

//**************STATE ENDGAME**************/
function endGame ():void { This creates the function endGame
      removeGame ();
      endScreen.visible = true;
      removeEventListener (Event.ENTER_FRAME, gameLoop);
      showResults ();
}

function showResults ():void {
      trace ("Show Results"); 
      endScreen.play_btn.addEventListener (MouseEvent.CLICK, clickFinalAway);
      function clickFinalAway (event:MouseEvent):void {
             trace ("clickFinalAway");
             moveScreenOff (endScreen);
      }
}

//**************REMOVE GAME**************/
function removeGame ():void {
     
}


Ideas Generation

Ideas Generation
Summary of submarine game
I took a look at a previously made flash game in the style of asteroid games but a completely different theme. The theme is an underwater theme with submarine moving side to side across the screen and the player being a simple ship. The game mechanics are pretty simple to not complicate the player by using arrow keys to move left to right and the space bar to shoot bombs straight down aiming for the submarines. The HUD is well set out as well showing you the amount of lives you have remaining, the amount of bullets and also the amount of pints earned. This is all well set out in a yellow bar at the top.

Idea 1.
I want to incorporate aliens and monsters into my game. The game will include a slime creature/monster as the player and either food or humans and them come into the screen from left and right  moving the character left and right to eat them. If i have time i want to make it possible so you can progress to eat bigger sizes and thus grow bigger making you stronger and have a higher score in the game. The art style will be a slight "Team fortress 2" style and use a differential shades of the same color. There will be upgrades incorporated such as speed boost, Armour upgrade,damage multiplier,score multiplier etc.

Idea 2.
I could come up with a gladiator themed game where you play as a gladiator and fight off enemy coming down the screen such as tigers,lions other gladiators,chariot etc. This will be portrait and enemies will come down and the player will move on the x axis,shooting arrows or slashing sword. There will be upgrades incorporated such as speed boost, Armour upgrade,damage multiplier,score multiplier etc.

Idea 3.
My other idea would be a avoider game where the player has to stay alive for as long as he/she can by using either the mouse or arrow keys (not decided). The game will progressively get faster and more enemies will appear on the screen. Once you die i think the player will be able to buy new upgrades for next he/she plays giving them a reason to play again and these will be saved on a profile. The scoring system will work by counting up all the time the player is alive then when dead it'll stop. The level could be announced each time and then shown constantly in a corner.

My chosen idea.
I'm going to work on Idea 3 as i think it changes the way of gaming from the other two and gives me more ideas for characters and upgrades and so on.








Wednesday, 12 September 2012

Asteroid Games

Asteroid Games.
Asteroid games are one of the most generic flash games around using a classic side scrolling or down scrolling system, with the player controlling the one ship alone and then proceeds to fight off and clear either enemies or clear asteroid from the field using a simple rotating control along with a shoot button.
These games all show signs of:

·         Replay values - this keeps the player wanting to play again to either beat a high score or time or even because it's fun to play.
·         Difficulty levels - This is there in a game for when more experienced or dedicated players want more of a challenge. 
·         Scoring systems - These are in games to keep track of your progression and show your ability when you finish the game.
·         Themes/graphic styles - This is crucial for these games as it keeps the game fresh and different between levels and makes the player have something nice to looks at whilst playing.
·         Animations - The animations in a game bring it to life this is what makes the games look a play so much better and also feel more real.
·         Sound effects- This is a game also makes the games more e.g. gun shots. You get to know how it would sound and enjoy the difference in sounds such as crashes.

1.Asteroids
   
This game consists of a spaceship in the middle shaped as a triangle and proceed to shoot at incoming asteroids as you push the up arrow to move forward and the side arrows to turn and the space bar to shoot mini circles representing bullets. You have a number of three lives and as soon as you lose those three lives the game ends showing your score in the top left corner. The main feature i liked about this game was the freedom to move around at will.The replay value of this game is average as it has harder enemies as you progress and there is also a score so you feel like you want to beat your previous score but the one problem is there is now high score system so sometimes you may forget the previous score you achieved and then feel unfulfilled.

The difficulty levels do progress and get harder but do now show a number of levels just a change in size of asteroids and adding of new enemies.The scoring system is as simple as it gets with it held in the top left corner and counting up each time the asteroids are hit. It's hard to find a unique scoring system but usually in flash games in uses the classic count in a corner.The theme of this game is very simple keeping to the black background to represent space and all enemies and player being a white outline with no fill. The graphics are as good as the theme allows them to be with the theme being retro and classic its hard to push to more crisp and more colourful ideas I think they could of at least added stars to the background.The animation is the game is at minimum as well having the asteroids only spin around and a fire that is also a white outline and is a very small animation which I guess uses only two different images switching between each other very fast.

The sound effects have a very retro style of sound with the shooting have its personal sound which sounds very original and when they hit asteroids the sound is a very distorted smash and crash kind of noise that work actually quite well keeping to the theme. 
2. Asteroids revenge 3

    This game is like the opposite of the first game I played and you get to play as the asteroids and try to destroy the ships. It uses quite a few of the keyboard keys which all are explained in a main menu and also starting levels which get you to use certain controls in order to get better and more comfortable with the game. One of the main features in the game that I personally enjoyed was the choice of a new upgrade at the end of each level, which makes you want to keep on progressing in the game to get higher level upgrades.
The replay value is well thought out leaving you with high scores and the idea of wanting to get a better upgraded asteroid, the only thing I could think that could help to improve this, is by adding a save system to make the player want to come back to previous points or maybe a level selector once you've completed that certain level.There isn't any sign of a difficulty selector in the game but you can tell that the levels can much harder to beat and harder to figure which controls you should use for certain enemies. I think if they were to add difficulty levels they have to make a set of maps for each so that might be why this is done instead.The graphics are well developed and goes well with the theme of block colours and with slight shading. they make the game feel more modern and up to date with over flash games. The sound and animation was good, by using a song on loop to keep the players motivated and good explosion and laser sounds for the ships. There isn't much they good do to animating the game but to have the asteroids spin as if they were in space and the ship simply have a bit of fire spitting out the back of them.