Perfect maze generation with AS3
I already talked about perfect mazes a couple of years ago with Step by step perfect maze generation with php and Perfect maze generation with Flash actionscript, but now it’s time to make it with AS3 and understand how can we use a perfect maze.
Think about a perfect maze as a maze with no loops.
Apart from the classic game where someone is trapped into a maze filled with enemies and items to collect, it’s not that hard turning a perfect maze into a randomly generated dungeon to make roguelike games.
From Wikipedia: The roguelike genre of computer games is characterized by randomization for replayability, permanent death, ASCII graphics, and turn-based movement. Games are typically dungeon crawls, with many monsters, items, and environment features. Death is frequent and often avoidable. Many roguelikes employ the majority of the keyboard to facilitate interaction with items and the environment. The name of the genre comes from the 1980 game, Rogue.
The script I am going to introduce uses backtracking.
From Wikipedia: Backtracking is a general algorithm for finding all (or some) solutions to some computational problem, that incrementally builds candidates to the solutions, and abandons each partial candidate c (”backtracks”) as soon as it determines that c cannot possibly be completed to a valid solution [1] [2] [3].
Let’s see the code: Read more
Goodbye AS2…
If you noticed, my last post about AS2 coding is New tile based platform engine – part 11 – slopes part b, almost a month ago.
I decided to quit talking about AS2 because I am not using it anymore, excluding a couple of games I am about to complete.

I am not that happy I had to learn a language I won’t use anymore, but this happened a lot of times in my life… from Commodore Basic to AS2, including AMOS, Pascal and some more.
When a programmer quits a language, it’s not a big problem, but when a blogger does it, he should think about his readers that don’t want to migrate to a new language.
While I don’t want to force anybody, let me share some thoughts:
You can get the latest Flash version, the so called CS4, for $699, and you can download a complete trial working for 30 days.
Even if you don’t have the money, I suggest you to download the trial, make a couple of simple games in a month and raise the funds to buy the license.
All new cool libraries are written in AS3, just think about BOX2D and the games you can make with it.
A PROgrammer **must** know the latest languages, not the old ones. Soon you won’t find any AS2 tutorial around the web.
Last but not least, you can make your own custom tombstone at tombstonebuilder.com.
What about old AS2 tutorials? Well, the most successful ones will be translated into AS3 using classes. Which one would you like to see first?
Monetizing Flash games: analyzing failures
The web is full of successful stories about monetizing Flash games… you will find some of them in Casual Games, Hard Money or you can read about my results at The experiment – one year later.
Today I am writing about the other side of the coin… when you fail at monetizing Flash games.
You can’t always win, and sometimes things don’t go that well. It’s not a tragedy. But you must learn from your mistakes. Just like in a platform game…
This is my list of such bad things: Read more
Platform engine variation with hangable tiles
This is another version of my platform engine made by Bryan Devlin introducing some graphics, a visual death and hangable roofs.
Bryan spread out the code to follow and understand it a bit better.
This is what you’ll get:
Notice the hangable tiles, that’s the major improvement.
You can download source code here.
Also, Bryan is working on a game probably started from my engine but with some new features like climbable walls, scrolling maps and timer, and would like some feedback… here it is the game:
Thanks Bryan!
AS3 Flash game creation tutorial – part 6: timing
In previous part we added some gameplay, now it's time to add timing.
I recommend you to read Understanding AS3 Timer Class.
I used time for two reasons: first, I want the player to collect as much coins as he can before a certain amount of time (to be defined), second to give the player some king of invulnerability every time he respawns.
To time the game, I created the time.as class with this content:
-
package {
-
import flash.display.Sprite;
-
import flash.utils.Timer;
-
import flash.events.TimerEvent;
-
import flash.text.TextField;
-
public class time extends Sprite {
-
private var time_passed = new showtime;
-
public function time(movieclip) {
-
movieclip.addChild(time_passed);
-
var time_count:Timer = new Timer(1000);
-
time_count.addEventListener(TimerEvent.TIMER, show_time);
-
time_count.start();
-
}
-
public function show_time(event:TimerEvent) {
-
time_passed.timetext.text=String(event.target.currentCount);
-
}
-
}
-
}
At line 7 showtime is a movieclip with a dynamic text to show time passed.
This class is invoked in the main as3circle.as file at line 6 and line 24, this way: Read more
Dragging objects with Box2D Flash
This is ideally the next part after Understanding pixels and meters with Box2D and how to select an object with mouse - part 2, but it's so important understanding how to drag objects with Box2D that I decided to change the title.
Anyway, in this uncommented example (a commented one will follow) you can select any crate with the mouse and drag it.
Changing at line 89 the mouse_joint.maxForce value will affect gameplay.
This is the source code: Read more
Win $16,000 with Flash Game Walk of Fame Contest!
Are you ready for a big Flash game development contest?
MochiAds and ArcadeTown are running the Flash Game Walk of Fame Contest with $16,000 in sponsorships to be distributed to top five entries in this way:
1st Place: $7,000
2nd Place: $4,000
3rd Place: $2,000
4th Place: $1,500
5th Place: $1,500

To be elegible for the contest, games have to incorporate the MochiAds Version Control and Encryption service and run MochiAds.
Unlike most contest, this one has no theme so you can unleash your creativity (or submit any of your games currently under development without changing a byte) and you have to opt-in your game to enter the contest.
Deadline is midnight December 31, 2008 PST.
More information at the official page.
Understanding AS3 Timer Class
A lot of time ago I wrote about AS2 time management in Flash simple timer/countdown. Now it's time to see how to manage time with AS3.
AS3 has its own class to manage time, the Timer class. You can read some documentation about this class in the official AS3 page, but in this test drive I am going to create two different timers... one using time intervals and one checking for elapsed time at every frame.
You will find some differences.
-
package {
-
import flash.display.Sprite;
-
import flash.events.Event;
-
import flash.utils.Timer;
-
import flash.utils.getTimer;
-
import flash.events.TimerEvent;
-
import flash.text.TextField;
-
public class as3timer extends Sprite {
-
var interval_timer = new timetext;
-
var frame_timer = new timetext;
-
public function as3timer() {
-
addChild(interval_timer);
-
addChild(frame_timer);
-
frame_timer.y = 50;
-
var time_count:Timer = new Timer(1000);
-
time_count.addEventListener(TimerEvent.TIMER, show_time);
-
stage.addEventListener(Event.ENTER_FRAME,on_enter_frame);
-
time_count.start();
-
}
-
function show_time(event:TimerEvent) {
-
interval_timer.txt.text = event.target.currentCount;
-
}
-
function on_enter_frame(event:Event) {
-
var elapsed = getTimer();
-
frame_timer.txt.text = Math.floor(elapsed/1000)+"."+(elapsed%1000);
-
}
-
}
-
}
Let's analyze this script: Read more
Understanding pixels and meters with Box2D and how to select an object with mouse – part 2
Ok, time to learn once for all how does Box2D manages object sizes, and how to set them right when working with AS3
In previous step I used a 90x90 pixel crate.
The problem is Box2D does not works with pixels because it does not have a native pixel render engine. In other words, Box2D does not display anything on the screen, it just calculates position and rotation of all bodies. There is a built-in debug renderer but, as the name suggests, it should be used only for debugging purposes.
That's why in the Update function (lines 63-72) I have to "manually" place every crate in the right place according to its position and rotation (lines 67-69).
Box2D works in meters, and there is an unwritten rule saying 1 meter = 30 pixels. That's why at line 16 I have the pixels_in_a_meter variable.
So when I think about the crate, I don't have to think about it as a 90px crate but a 90/30 = 3 meters crate.
But if you look at lines 47 - 48 you'll see I am assigning 1.5 (meters) to crate_width and crate_height variables. Why?
Because Box2D to create a box (but you will find the same concept applied to other shapes) uses SetAsBox (line 50) that wants width and height relative to the registration point placed in its center.
So that's how you should think about pixels when you work with BOX2D:

I hope this will help you saving some time...
Understanding pixels and meters with Box2D and how to select an object with mouse – part 1
This will be the longest post title in blogging history... anyway I am about to explain you two things that seem to be still unclear about AS3 version of Box2D.
The first one is Box2D measuring units that may seem weird until you realize Box2D works with meters where 1mt = 30 pixels.
The second one is the capability of selecting single objects with the mouse thanks to the custom GetBodyAtMouse. There are even people willing to pay for those information in the official forum.
So I modified the HelloWorld example in my own way in order to have some 90x90 ox sided crates (texture by http://www.reallyreallygoodthings.com/) I can make "jump" and "torque" clicking the mouse on them.
This is the uncommented actionscript, I will post the step-by-step explaination tomorrow. Read more
Posts
- Rick Triqui: my first PlayCrafter game
- Prototype of a Flash game like Meeblings
- Games for the game developers!
- The art of debugging
- How to embed a text file in Flash
- Create a Flash game in minutes with PlayCrafter
- Upgrade your Flash CS4 to 10.0.2
- Play Mazeroll, my latest Box2D game
- Triqui MochiAds Arcade plugin for WordPress Released!!
- The MochiAds funnel
- Flash game creation tutorial - part 1
- Create a Lightbox effect only with CSS - no javascript needed
- Flash game creation tutorial - part 2
- Make a Flash game like Flash Element Tower Defense - Part 2
- Flash game creation tutorial - part 3
- Create a flash draw game like Line Rider or others - part 1
- Create a Flash Racing Game Tutorial
- Make a Flash game like Flash Element Tower Defense - Part 1
- Create a flash artillery game - step 1
- Create a flash draw game like Line Rider or others - part 5
- Flash game creation tutorial – part 5.2




(4.9 out of 5) - Flash game creation tutorial – part 3




(4.86 out of 5) - Creation of a platform game with Flash – step 2




(4.84 out of 5) - Create a survival horror game in Flash tutorial – part 1




(4.82 out of 5) - Create a flash artillery game – step 1




(4.82 out of 5) - Create a Flash Racing Game Tutorial




(4.8 out of 5) - Create a flash artillery game – step 2




(4.75 out of 5) - New tile based platform engine – part 6 – ladders




(4.74 out of 5) - Flash game creation tutorial – part 2




(4.73 out of 5) - The experiment – one year later




(4.7 out of 5)

