Creation of new data types in AS3: Linked List

In computer programming, a data type (or datatype) is a classification identifying one of various types of data, such as floating-point, integer, or Boolean, stating the possible values for that type, the operations that can be done on that type, and the way the values of that type are stored. (source: Wikipedia).

Obviously any language is capable to create new data structures. I did not find any complete AS3 complete tutorial to create a new data type from scratch with AS3, so I am writing it by myself.

We are going to define a simple linked list data type.

A linked list is a data structure that consists of a sequence of data records such that in each record there is a field that contains a reference (i.e., a link) to the next record in the sequence.

(source and image: Wikipedia. Yes, I made a donation so I feel free to copy/paste :)).

In this example, we are going to reproduce the same linked list you see in the picture. Usually the “records” Wikipedia is talking about are called “nodes”, so we’ll define a node datatype. Read more

Create a Flash game like Blockage – Movement prototype

This is one of those days when you want to make a thing work that way FULLSTOP.

And that’s it… this is the typical Blockage movement:

I wanted to do it without any timeline tween or tricks to change registration point on the fly, just using localToGlobal method. If you aren’t familiar with this method, read understanding AS3 localToGlobal method first.

So here it is the uncommented and unoptimized prototype. While comments and tutorial will come when I’ll integrate it into the making of the game, I think this can be useful to someone of you to have a sneak peak of what’s going on.

This is the main class:

1
2
3
4
5
6
7
8
9
10
11
package {
	import flash.display.Sprite;
	public class blkg extends Sprite {
		private var block:block_mc=new block_mc();
		public function blkg() {
			block.x=0;
			block.y=50;
			addChild(block);
		}
	}
}

and this is block_mc class: Read more

Worms-like destructible terrain in Flash – Part 3

After another truck of Aspirin, Jordi Sanglas Molist is back with the 3rd step of his Worms tutorial.

I’ve finished part 3. I almost got a headache. Forgive me if there are some mistakes, I wrote this post and the comments quickly.

Now the character is affected by the explosions. To do that, I added an horizontal speed and a friction. However, I don’t want the character to slide when I’m using the arrow keys, so:

* The arrow keys won’t use horizontal speed
* If the horizontal speed is different than 0 (an explosion is moving the character), I can’t use the arrow keys

To calculate the impulse, we will need to use trigonometry:

I’ve also solved another bug: if the character was falling (without using the space bar), it could jump in the air. Here I removed the jumping variable and I check if the character is on the ground.

Pay attention!!! Sometimes I check if the character is ON the ground (character.y+10) and sometimes I check if the character is TOUCHING the ground (character.y+9).

KNOWN BUGS:

* The horizontal speed won’t decrease faster or more slowly if the character is on a slope.
* The for loop isn’t exact when the horizontal speed is a decimal number (I think).

What should I do in the next part? I must do it before I start school, or I won’t have time.

While you think about the next part to request, here it is the script: Read more

Create Box2D levels in a quick with Bison Kick

Some time ago I published a Basic Box2D editor using Flash movieclips.

Now it’s time to show you something way more interesting called Bison Kick by Jacob Schatz who runs the blog jacobschatz.com (bookmark it! It contains a lot of useful information).

It’s an online Box2D editor with live preview.

Besides it’s still under development, with more options to be added and a few bugs to be removed, it’s very fun and simple to use.

I tried to design a level to be used in a game like Totem Destroyer and I managed to export it both in AS3:

//order: x , y , height, width, rotation, isDynamic, shape, friction,density,restitution,ID 
 var map:Array = [
[175,324,50,50,0,true,'SQUARE' , 1,0.5,0.5,'normal']
,[325,325,50,50,0,true,'SQUARE' , 1,0.5,0.5,'normal']
,[250,375,50,500,0,false,'SQUARE' , 1,0.5,0.5,'ground']
,[250,275,50,300,0,true,'SQUARE' , 1,0.5,0.5,'normal']
,[250,200,100,150,0,true,'SQUARE' , 1,0.5,0.5,'normal']
,[125,225,50,50,0,true,'SQUARE' , 1,2,0.5,'heavy']
,[250,125,50,50,0,true,'SQUARE' , 1,2,0.5,'heavy']
,[375,225,50,50,0,true,'SQUARE' , 1,2,0.5,'heavy']
,[250,50,100,50,0,true,'SQUARE' , 1,0.25,0.5,'totem']
];

and in XML: Read more

Create a Flash game like Blockage

Did you play Blockage?

It’s a perfect game to make a tutorial series because at every level it introduces a new feature, so level after level you will see something new both in the game and in the prototype.

Other than that, it’s a tile based puzzle.

This first part will focus on level data. Since it’s a tile based game, you know we should create a bidimensional array, map all levels assigning each tile type a value such as zero for the empty space and one for the walls, and start creating the array tile after tile, just like in Create a Flash game like Rebuild Chile.

In this prototype I will try to “compress” the level packing it in a string containing comma separated values.

Let me explain the idea: count, from left to right, from upper to bottom corners, the number of contiguous walls.

There are 49 walls. Then, 14 empty spaces. Then, two walls. And so on. Exluding the actors (the square and the goal), create a string like this one:

49,1,14,0,2,1,14,0,2,1,14,0,8,1,1,0,56,1

That means the level has 49 walls (marked with 1), 14 empty spaces (marked with 0), then 2 walls, 14 spaces and so on.

So this code: Read more

Create your own tween manager class in AS3

I publish this tutorial with the permission of Krasimir Tsonev, from Bulgaria, who runs krasimirtsonev.com (take a look at the light bulbs: don’t you think it can be done using a basic Box2D rope?). It’s an amazing tutorial with clean and well commented code that will guide you through the process of the creation of a custom tween manager class with AS3.

There are some features in Flash that we can’t work without. Tween classes are among the most used ones. They give you ability to animate objects without using the timeline, to change the animation fast and easy. The idea of these classes is very simple. That’s why I think that it is a good idea to have your own tween manager that you can modify to fit into your needs.

The basic structure of our tween manager:

1
2
3
4
5
6
7
8
9
10
11
package {
	import flash.display.MovieClip;
	public class TweenManager extends MovieClip {
		private var _objectToModify:Object;
		private var _properties:Object;
		public function TweenManager(objectToModify:Object, properties:Object) {
			_objectToModify = objectToModify;
			_properties = properties;
		}
	}
}

We are going to pass the object that we want to modify and the properties that we want to change. The idea is to create a function that calls every frame. All the magic will be done there. As you can see in the code below I created a public function – start, which adds listener for ENTER_FRAME event. So now we have a repeated method, i.e. loop. Read more

Worms-like destructible terrain in Flash – Part 2

After having some troubles with the email, I am finally able to post Jordi Sanglas Molist‘s second step of Worms-like destructible terrain in Flash.

Now the character can jump and move. I’ve also solved a bug: in the last script I checked a collision using the feet, so if the terrain was between both feet the character would fall.

Now, instead of using a hitTest between a BitmapData and a point I use a hitTest between a BitmapData and a Rectangle.

We have to check more collisions, so I used four rectangles:

* The rectangle below the character is used to check if the character must fall

* The rectangle above the character is used to check if the character hit the ground (while he was jumping)

* The rectangles at the sides are used to check if the character can move.

These rectangles aren’t as long as the character, they’re 17 pixels height instead of 20. That’s because, if the character wants to move left and the obstacle isn’t high enough (high enough to reach the rectangle), the character will be able to move. A similar strategy is used in “Create a flash draw game like line rider or others – part 5“, where a point (the knee point) is used to check if the character can move.

I renamed the function “fall”: now it’s “move_character”. I only commented the new lines. Now I’m working on part 3, but I still don’t know how to calculate the explosion impulse. I looked for some information, but now I’m thinking about maths (an explosion is a growing circle). Read more

Changing a Movieclip registration point on the fly with AS3

Do you know what is a Movieclip registration point? If you ever played with Flash drawing tools, you should.

The registration point is like the origin in a Cartesian coordinate system, the default point of a Movieclip from which its x and y coordinates are calculated.

In the example we are about to see, I created this square with a 100 pixel side and placed at (-50,-50), so its center of rotation is at (0,0), as you can see from the tiny white crosshair in the centre of the square.

Now the question is: can I change dynamically the registration point with AS3?

The answer is: NO. No code to download, and see you later.

Anyway, there is a little trick.

Look at this script: Read more

Create a Flash racing game – Flex version

Hamilton Lombardi is a brazilian Flex programmer who decided to rewrite the code you can find in the original post for Flex 4.

Moreover he added a splash screen, as you can see:

The source code is clearly formatted and commented as you can see from Level class: Read more

Claytus Hood Tower Defense case study

I always loved games that revive an old concept with new features, and Claytus Hood Tower Defense is one of them.

Based on the old “tower defense” theme, it introduces new strategy options with large, scrollable maps and the capability to block some paths to make enemies take a larger route to attack you base.

Roux Raphaƫl, the author, shares with us his experience:

« Why did I decide to work on Claytus?

Before that, I used to be a developer for a web agency, coding online shops or institutional communication websites… not that fun!

After I lost my job at the end of 2009, I decided to increase my knowledges in AS3, to code funny stuff like games for example!

I always learnt programming by myself (the geekish way), with books, resources found on the web and personal experience…

I thus decided to read Keith Peters’ book “AS3 animation – Making Things Move” to fill my gaps in maths, and I saw lots of quite useful things to code games I had forgotten.

After reading this book, I managed to learn AI and Pathfinding, I thus studied A* algorithm.

Here are the examples I inspired myself of to learn A* :
http://www.remixtechnology.com/view/AStar-haXe.

Well, I reviewed trigonometry, I know A*, what can I do with it? A Tower Defense game! Let’s code! Read more

Next Page →