Flak-Games
26Jul/10

Welcome back, friends!

Posted by dank

Due to some overly aggressive malicious scripts, we've had to launch our new site prematurely. Though, as you can see, we haven't any functionality yet, but it is better than no site at all! There should be approximately 2 more updates comping over the course of about the next month.Maybe. The first will introduce the rest of the site's functionality including: Games, comments, profiles, etc.; the latter, open social interactivity and contribution to the community. Until then, I'm probably just going to be speaking in a vacuum.

Filed under: Site News No Comments
7Jul/09

Desolate Defense Released!

Posted by dank

Desolate Defense, a tower defense game created by myself, has just been released this last week and can be played here on this site. Also, we are now working on a game for newgrounds' "Power of Three" summer event, making a medieval defense game.

In other news, the game submission system seems to have stopped working (it won't upload the flash files for some reason). Hopefully, that will be fixed soon, but for now, email us the information and the links to the files.

-Chad Duncan

Filed under: Site News No Comments
10Apr/09

Basic Scoring In Flash

Posted by dank

Scores are an essential part in all games. They challenge the user while rewarding them at the same time. Keeping track of scores in Flash isn't tricky to use, but it is important that they are implemented correctly.

Declaring The Variable

The fundamental building block behind a score is the variable. As you ought to have learned, variables are used to store objects, pointers, and raw data. If you haven't, you only need to know that a variable will keep track of the player's score for us. This is what a score variable will look like when it is declared:

var score:Number = 0;

Though it should be evident, this line makes a new variable that can be accesed by 'score' and holds a value of zero. Typically, scores are numbers and thus the above is a strict declaration of Number meaning it can only hold a number (floats and intgers).

Note that where you place this line of code is important. Say if you have a frame for every level and put that on every frame, the score will be erased and reset to zero at a new place in memory. But perhaps you wanted the score to continue incrementing from level to level, then you would need to declare the score variable before the level frames. In most cases  you should declare the variable when the movie is initiated. In AS3, it is best to put it in the the document class; in AS2, the first frame. This way the variable can only be modified and not re-declared.

Changing The Score

Now that there is a variable in place to keep track of the player's score, the variable must be updated accordingly. This is done with simple arithmetic and assignment operators:

+, -, *, /, %, +=, -=, *=, /=, %=, ++, and --

When iplemented, a typical line should look like this:

score += 5;

This might have to be changed depending on the namespace of score. If it was declared as recommended (Main Timeline), it should always be called directly:

AS2:
_root.score += 5;

AS3:
MovieClip(root).score += 5;

Say if you call score += 5 from an instace of an enemy, it will try accessing an imaginary (unless created for some other reason) variable in the enemy object that does not exist. Thus being the reason the score variable is global, or at the lowest level of the internal namespace. (Unless you're anal about security and create an object for the game which has a variable with get() and set() functions)

Displaying The Score

Displaying the score is a quick process once you've got it down. To start, add a text box to the stage in the place you would like your score to be shown. Select the new box (it should be already) and find the poperties window (Ctrl+F3).  Now there will be two different proccesses depending on the version of actionscript your in.

AS2:
Change the text box's Text Type to Dynamic Text.
Change the Var to your score variable. (It's good to keep it on the main stage as mentioned, use _root if you did)

And that's it! Your the score will be displayed exactly as it is in memory.

AS3:
Change the text box's Text Type to Dynamic Text.
Give it an instance name (ie. txtBx)
Create an onFrame event and use 'MovieClip(root).scrBx.text = String(MovieClip(root).score).' Or to be more efficient, just use it when the score is updated.

Obviously it takes a bit more work to display the score in AS3, so to cut down a bit, it might be easier to create a function that will be called by some onFrame event running during the game.

public function changeScore(num:Number):void{

MovieClip(root).score += num;
MovieClip(root).scrBx.text = String(MovieClip(root).score);

}

30Mar/09

Sound in ActionScript 2

Posted by dank

Sound, whether in the form of music or sound effects,  is an important part of any flash game. While you may be able to get away with controlling sound with the timeline in an animation, a game must be a bit more dynamic and you will almost always need to control the sound with actionscript. This tutorial will help you understand not only control sound in actionscript 2, but avoid potential problems.

Example

Below gives an example of actionscript you may use to play a sound. Note: in this example, I attach the sound to a movieclip which should help avoid problems that may occur when implementing something else like mochiads or controlling the volume of music and sound effects separately.

var music:Sound = new Sound(music_mc);
music.attachSound("song");
music.start(0, 10000);
//0 is the offset (we want it to start at the beginning
//the 10000 is how many times I want the sound to play in a loop

In the above example, I'm trying to play a sound with the indentifier "song". You'll need to go to the library of your flash file and find the sound you want to control. In the right-click menu, press linkage to take you to the linkage menu of the sound file. Give it the identifier you want and make sure "export for actionscript" is checked, but make sure "export in first frame" is not checked if you want to have a preloader. Otherwise, if the sound is exported to the first frame, the preloader will not load until after the sound is loaded. Therefore, if "export in first frame" is not checked, on a frame on the timeline somewhere after the preloader, set the sound to start in the properties panel, but don't allow the timeline to play through the frame. I would suggest making the sound start in the second frame of a  movieclip and making the movieclip stop on the first to prevent it from playing. Having the sound technically start in the flash somewhere will allow the sound to be compiled with your swf file and not mess up your loader.

Other stuff

music.stop(); - can be used to stop the sound
music.setVolume(); - can be used to set the volume (ex: setVolume(80))
music.getVolume(); - can be used to find out what the volume is set to
music.loadSound("song.mp3", false); - use this instead of attachSound() if you want to load a sound externally. The first parameter is the file url and the second is whether you want the sound to stream or not

Filed under: Tutorials No Comments
29Mar/09

Aiming and Shooting in AS3

Posted by dank

Having the knowledge of how to simply aim and/or shoot is essential to many types of games. It can be done in many ways depending on the type of game but generally relies on the same concept.

Aiming

To make a MovieClip rotate towards the mouse, we need to find the difference in coordinates in the two, use some math to find the angle in radians, and then convert it to degrees. Create a player (or gun; whichever works for you), create a class to be linked to your MovieClip, and add this into your constructor function (the function with the same name as the class):

addEventListener(Event.ENTER_FRAME, aim);
stage.addEventListener(MouseEvent.MOUSE_DOWN, shoot);

These events are obviously used to make the MovieClip aim and react by calling the shoot function (which we will create later) whenever the player clicks on the screen. With that out of the way, we can continue by adding the following function:

public function aim(e:Event){
var changeInX:Number = x - stage.mouseX;
var changeInY:Number = y - stage.mouseY;
var angleInRadians:Number = Math.atan2(changeInY, changeInX);
var angleInDegrees:Number = Math.round(angleInRadians*180/Math.PI);
rotation = angleInDegrees;
}

In the first two lines, the difference in x and y coordinates is found. With Math.atan2, we can find out angle in radians. Then we must convert it to degrees with the formula: angle in degrees = angle in radians * 180 / Pi because 'rotation' uses degrees. Then, we tell the movieclip to rotate accordingly. For aiming, this should be all you'll ever need, but if you want to create something fancy, you can make your gun/player gradually rotate to your angle. That, unfortunately, is out of the scope of this tutorial.

Shooting

For shooting, a number of methods can be utilized. Sometimes visible bullets can be safely avoided altogether, but here I will give an example of how to make a bullet move towards a target.

First, you'll need to make a bullet MovieClip and set up a class for it. Then, for the constructor of your class file, add the following code:

public function Bullet(target:Point, _x, _y){

//Sets its position
x=_x;
y=_y;


//Look familiar? This finds the angle like before
var changeInX:Number = x - target.x;
var changeInY:Number = y - target.y;
var angleInRadians:Number = Math.atan2(changeInY, changeInX);
var angleInDegrees:Number = Math.round(angleInRadians*180/Math.PI);
rotation = angleInDegrees;

var speed:Number = 10; //This can be changed however you like.

//Find out the directions the bullet will go
var xDirection:Number = (target.x - x>=0)?1:-1;
var yDirection:Number = (target.y - y>=0)?1:-1;

//find the difference in the coordinates
var xDifference:Number = target.x-x;
var yDifference:Number = target.y-y;

//The speed is first multiplied by a ratio between the locations of the target
//and the bullet. Then, it is multiplied by -1 or 1 to determine direction
xSpeed = speed*Math.abs(xDifference/yDifference)*xDirection;
ySpeed = speed*Math.abs(yDifference/xDifference)*yDirection;

//Make sure it never goes past your speed
if(Math.abs(xSpeed)>speed){
xSpeed=speed*xDirection;
}
if(Math.abs(ySpeed)>speed){
ySpeed=speed*yDirection;
}

//Make it move constantly
this.addEventListener(Event.ENTER_FRAME, Move);

}

You'll also need to add this in your bullet class because we need them to pass onto other functions in the class:

public var xSpeed:Number;
public var ySpeed:Number;

Afterwards, copy the following function and paste it into your class to make the bullet constantly move according to the speed and direction that was calculated in the constructor function:

protected function Move(e:Event):void{
x+=xSpeed;
y+=ySpeed;
}

Simple enough, right? Now you just need to make the bullet appear on the screen. Return to your player/gun class and add this:

public function shoot(e:Event){
var theBullet:Bullet = new Bullet(new Point(stage.mouseX, stage.mouseY), x, y); //create the bullet
stage.addChildAt(theBullet, MovieClip(root).getChildIndex(this)); //add it to the screen
}

Another thing that you need to make sure of is that you import any necessary classes like MovieClip, Bullet, etc. into your classes. For example, to access the bullet from your gun/player, you'll need to have: import directoryOfYourClasses.Bullet;

That's it! Here is an example based on the code:

[swfobj src="http://localhost/fg/wp-content/uploads/2010/03/aimandshoot1.swf"]

25Mar/09

Game Submission System

Posted by dank

A new part of the site has just been finished--you can now submit games to the site. However, the games must be reviewed at this time and all games must be pg13 or below. So, now more games will be able to appear on the site than just mine and danks. For you devs, please feel free to start uploading.
:D

Chad Duncan

Filed under: Site News No Comments
9Dec/08

MiniGame Arcade 2 Released!

Posted by dank

The sequel to Minigame Arcade is finally complete! Because I thought the original could've been a lot better, I decided to make another but with improved quality. If you have played the original, you would know that it's a collection of a dozen minigames. It took several months to make, but you can see it now.

Go Play It!

Have Fun!

- Chad

Filed under: Tutorials No Comments
16Oct/08

Multi-Dimensional Arrays in Flash

Posted by dank

Arrays make a great way to store and manage data in actionscript. However, sometimes just a single dimension may not be adequate for some situations such as when storing table data. Then you will need to either: define an array for each column for every row, or just make a one two-dimensional array.

A two-dimensional array can be thought of an array nested in an array. To instantiate an array, we can either do:

var arr1:Array = new Array(1, 2, 3);
var arr2:Array = new Array(4, 5, 6);
var arr3:Array = new Array(7, 8, 9);
var arr:Array = new Array(arr1, arr2, arr3);

Or the quicker way:

var arr:Array = new Array([1, 2, 3], [4, 5, 6], [7, 8, 9]);

All we're doing here is defining arrays inside of an array. To reference a two-dimensional array is practically the same as a normal array except for we have a second element to reference. This means we just need to add another "[n-1]:"

// Output: 6
trace(arr[1][2]);

To add a new element to the first array, we can use the same syntax as we would with a single-dimension array, but we would be pushing an array data type:

// Adds another element to the outer array
arr.push(arr1);

To add an element to one of our existing arrays, we reference the array's element in the outer array:

// Ads a sub element to arr1[1] (= 4,5,6)
arr[1].push(arr1);

The rest of the functions in the Array package are used in the same way, but with different references to the caller.

15Oct/08

Minigame Arcade 2

Posted by dank

I've been working on Minigame Arcade 2. I decided to make it because Minigame Arcade needed much improvement, I liked making it, and some people asked for a sequel. So, I decided to make one that would be a lot better than the first.

Features:

  • 12-15 Minigames Total
  • 3-5 Minigames to Unlock
  • 4 Returning Mini-games
  • 4-5 Great Songs
  • 2 Difficulty Modes
  • A Music Menu in every Mini-game
  • A Stats Menu
  • 3 Additional Things to Unlock
  • A Spanish Translation
  • Less Ads
  • No Glitches
  • No Cheats
  • Improved Graphics and Presentation
  • Better Mini-games
  • Sound Effects
  • etc.

More can be read about the progress of the game here: http://chad-duncan.newgrounds.com/news/post/188277.

Filed under: Uncategorized No Comments
15Oct/08

Array Tutorial

Posted by dank

Arrays are very helpful when making games because they are able to hold more than one value unlike normal variables. Using arrays, you can have easy access to a large quantity of information. Arrays are essential to make many types of games and can make your job as a Flash developer easier. This tutorial will attempt to show you how use arrays.

1) Creating an Array

Here is an example of how to create an array:

var myArray:Array = new Array("value 1", "value 2", "value 3");

First, we give the array a name (like myArray), and then enter values into the array using new Array(). Values in an array can be strings (text), numbers, other arrays, etc.

Here is another example, but with an array becoming the same as another:

var myArray2:Array = myArray;

2) Accessing an Array

Below are examples of how to access an array and values in it:

colors[0] = "red";

inventory["money"] = 100;

weapons[2] = "Machine Gun";

var selectedWeapon:String = weapons[5];

You can access the values in an array by using [ ] . You give the number of the element in an array or supply a title. However, the elements in array are numbered beginning with zero instead of one. For example, if you wanted to access the third element of the array, myArray, you would use myArray[2] not myArray[3]. Also, you can put a variable in the [ ]. Example: if currentlevel is 3, levels[currentlevel] could be used to access the third level.

3) Other Things to Know

To get the length of the array use: myArray.length. The function push() can add a value to the end of an array, and unshift() can add it to the end. To remove the last element in an array use pop(), and to remove the first use shift(). You can also use reverse() to reverse the order of the elements in an array. Read more about all this here: http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/index.html?Array.html&class-list.html.

Conclusion

I hope this tutorial helps. If you don't understand something or something doesn't work for you, leave a comment or e-mail me. If you have a suggestion to improve this tutorial, leave a comment.

Filed under: Tutorials No Comments