Creation of a Flash highscores API - Step 2
Now that you know how to communicate between two Flash movies thanks to the Creation of a Flash highscores API tutorial, it's time to introduce the next step that will make you save your highest score on your computer.
It's not an hard prototype once you read Create an Eskiv Flash game tutorial (in order to have a real game) and Managing savegames with Flash shared objects (to store data on your computer)
This is the game:
-
var send_score:LocalConnection = new LocalConnection();
-
_root.attachMovie("score", "score", 1);
-
_root.attachMovie("hero", "hero", 2, {_x:250, _y:200});
-
_root.attachMovie("target", "target", 3, {_x:Math.random()*400+25, _y:Math.random()*300+25});
-
enemy_power = 3;
-
points = 0;
-
max_score = 0;
-
hero.onEnterFrame = function() {
-
this._x = _root._xmouse;
-
this._y = _root._ymouse;
-
};
-
target.dir = Math.random()*2*Math.PI;
-
target.xspeed = enemy_power*Math.cos(foe.dir);
-
target.yspeed = enemy_power*Math.sin(foe.dir);
-
target.onEnterFrame = function() {
-
dist_x = this._x-hero._x;
-
dist_y = this._y-hero._y;
-
distance = Math.sqrt(dist_x*dist_x+dist_y*dist_y);
-
if (distance<(hero._width+this._width)/2) {
-
points++;
-
if (points>max_score) {
-
max_score = points;
-
send_score.send("hall_of_fame", "compare_scores", points);
-
}
-
score.scoretxt.text = points;
-
this._x = Math.random()*400+25;
-
this._y = Math.random()*300+25;
-
foe = _root.attachMovie("enemy", "enemy", _root.getNextHighestDepth(), {_x:Math.random()*400+25, _y:Math.random()*300+25});
-
foe.dir = Math.random()*2*Math.PI;
-
foe.xspeed = enemy_power*Math.cos(foe.dir);
-
foe.yspeed = enemy_power*Math.sin(foe.dir);
-
foe.onEnterFrame = function() {
-
this._x += this.xspeed;
-
this._y += this.yspeed;
-
if ((this._x<0) or (this._x>500)) {
-
this.xspeed *= -1;
-
}
-
if ((this._y<0) or (this._y>400)) {
-
this.yspeed *= -1;
-
}
-
dist_x = this._x-hero._x;
-
dist_y = this._y-hero._y;
-
distance = Math.sqrt(dist_x*dist_x+dist_y*dist_y);
-
if (distance<(hero._width+this._width)/2) {
-
points--;
-
score.scoretxt.text = points;
-
this.removeMovieClip();
-
}
-
};
-
}
-
};
The game game developer only needs to add line 1 and line 23 to his game
and this is the highscore table Read more
Turn wasted time into level design
I am about to complete my second one-week game. It's not a "play until the game is over" like BallBalance or Christmas Couples, but has various levels like Circle Chain.
And "levels" means level design. One of the hardest things to do in order to make a succesful game. You can have the best game engine, but if your levels suck, the entire game will suck.
That's why I spent a lot of time designing the levels. But I did not want to spend the time I could spend doing something more profitable, interesting or relaxing.
So I decided to design levels in the "old school" way, with pen and paper.
What? A geek using pen and paper?
Here it is the proof... I have dozens of blueprints like the ones you can see in the photo, and I am choosing the best 50 to be included in the game

Now the question is: why did you use pen and paper?
Because I designed the levels everytime I have really nothing to do, and even the minute or less waiting for the laptop to boot would be too long... or I can't use any computer at all
An example? Going out to have a nice dinner with my wife, waiting dressed and shaved for her to choose the dress... the bag... the shoes... obviously if only I touch the keyboard, I am a dead geek.
So, while my wife is changing for the 5th time her hairstyle, I design levels.
What else should I do?
Another idle time spent designing levels is... in the bathroom. Yes! While most people read gossip magazines, I design levels.
Look! This way I can't forget I have to designing levels while... you know...

... and if I am not satisfied with the levels, I can use them for a less noble use...
Remember that your time is precious, are you sure reading the last gossip about Britney Spears is better than doing something you will have to do anyway, maybe when you don't have the time?
So... what will you do next time you are waiting for the dentist?
Also remember to think twice before saying the levels of my incoming game look like crap...
Creation of a Flash highscores API
More and more game portals are developing their own Flash API to manage high scores.

Having high scores means giving players the opportunity to compete for a leaderboard, making them play your game more and more. And making you earn more and more.
I am showing you how to make one. I'll use LocalConnection, like, as example, MindJolt.
The LocalConnection class lets you develop SWF files that can send instructions to each other, and if all files are located in the same domain, you won't have security issues.
Nice!
So you need two files: the game itself and the leaderboard file. Once the game is over, I will send the score to the leaderboard file, that will generate the leaderboard itself Read more
Preventing the right mouse cheat in your Flash games
Today I played the millionth mouse avoider Flash game... Shirk!
I am a real pro at mouse avoider games... look how easily I beat the hard level.
Watch the video!
What a champion...
This happens because you can right click the mouse, showing the menu.
As far as I know, you can't prevent the menu to show, but you can detect when the player presses the right mouse button.
Just insert into your code, in a place that will be executed every frame, this script:
-
if (ASnative(800, 2)(2)) {
-
// code to execute when the player tries to cheat
-
}
What is that ASnative function?
It's an undocumented function used mainly by component developers. You can find some examples at Open Source Flash
Since the documented mouse handlers only detect left mouse button, we need to use this function to do the trick.
But remember this function is undocumented and therefore unsupported.
Moreover, there is no guarantee future versions will support it or work with it
But at the moment it seems to work, and that's enough.
Earn $50 including The Game Homepage API in your Flash game
Today I received some interesting news from Gaz, the brain behind The Game Homepage.
He developed an API for his brand new Compete section and hw is looking for good games to use it.
He is offering $50 for every game that will include the API, and he does not mind you leaving any sponsorship branding/Mochiads in
Including the API is very easy: you just have to add
tgh_startgame(_root.score, 0, 0);
to be called whenever a new game is started (ie. after play has been clicked) and
tgh_submitscore(_root.score);
when they get game over.
Also, you should remove your Mochiads leaderboard, if any.
Gaz is only looking for good games, and if you think your game is what Gaz wants, contact him at http://forums.thegamehomepage.com/sendmessage.php.
I am sending the API enabled version of BallBalance at once.
Prototype of a Flash game like Floaty Light
Do we really need another "move a ball in some way from A to B avoiding C" game?
Noooooooo... but it seems two or three people still like this kind of games, so the new torture branded Game Garage is Floaty Light.
Just kidding, of course.
I made this prototype using the gravity and speed as described in the Flash game creation tutorial - part 1 post, the collision detection as shown in the Create a flash draw game like Line Rider or others - part 2 post and the control system already seen at A new player control concept, with only a minor change.
As said, nothing new, but it's an interesting concept anyway
-
_root.attachMovie("ball", "ball", _root.getNextHighestDepth(), {_x:50, _y:50});
-
_root.attachMovie("wall", "wall", _root.getNextHighestDepth(), {_x:240, _y:200});
-
_root.attachMovie("arrow", "arrow", _root.getNextHighestDepth());
-
moving = false;
-
gravity = 0.01;
-
xspeed = 0;
-
yspeed = 0;
-
precision = 24;
-
radius = 15;
-
Mouse.hide();
-
arrow.onEnterFrame = function() {
-
this._x = _xmouse;
-
this._y = _ymouse;
-
dist_x = ball._x-this._x;
-
dist_y = ball._y-this._y;
-
total_dist = Math.sqrt(dist_x*dist_x+dist_y*dist_y);
-
if (total_dist>300) {
-
total_dist = 300;
-
}
-
total_dist = (300-total_dist)/500;
-
angle = Math.atan2(dist_y, dist_x);
-
this._rotation = angle*57.2957795;
-
};
-
ball.onEnterFrame = function() {
-
if (moving) {
-
dir = arrow._rotation;
-
xspeed += total_dist*Math.cos(dir*0.0174532925);
-
yspeed += total_dist*Math.sin(dir*0.0174532925);
-
}
-
yspeed += gravity;
-
this._x += xspeed;
-
this._y += yspeed;
-
xspeed *= 0.99;
-
yspeed *= 0.99;
-
for (x=1; x<precision; x++) {
-
spot_x = this._x+radius*Math.sin(x*360/precision*0.0174532925);
-
spot_y = this._y-radius*Math.cos(x*360/precision*0.0174532925);
-
if (wall.hitTest(spot_x, spot_y, true)) {
-
xspeed = 0;
-
yspeed = 0;
-
this._x = 50;
-
this._y = 50;
-
}
-
}
-
};
-
_root.onMouseDown = function() {
-
moving = true;
-
};
-
_root.onMouseUp = function() {
-
moving = false;
-
};
Let's play it!
Download the source code and give me feedback
Prototype of a Flash game like GearTaker
Do you know Tony Pa's GearTaker game?
You have a buddy jumping around rotating gears. As most Tony Pa's games, it's easier to play than to explain, and it's hard to link... from this page select "GearTaker" and play.
I made a Flash prototype using two objects, the cog and the hero Read more
Experiment: monetizing a Flash game - Part 9
Multipart tutorial: available parts 1, 2, 3, 4, 5, 6, 7, 8, 9
This is a big update of the experiment, because lots of interesting things happened since the last one.
Let's start:
Goals and targets
Obviously every experiment has its goals. I have two different types of goals: hourly income and games played.
The hourly income is necessary to earn a decent amount of money from the games, while the more games played, the more my brand spreading through the web.
The dollar did not get weaker during the last months, so the minimum goal is to earn $46 per hour of development/promotion, while the awesome goal is set to $123/hour.
As for the games played, I feel happy if a game joins the so-called million plays club and very very happy if joins the five millions plays club.
At the moment my games cannot aim to a more exclusive club... Read more
Creation of a matching game with Flash and AS3
This tutorial was inspired by the one written at chapter 3 in ActionScript 3.0 Game Programming University, but I changed some mechanics because I did not like some choices made by the author.
Anyway, this is not a "mine is better", just a tutorial that I did not write completely on my own.
Do you know what is a matching game?
In this version, you have 16 grey tiles. You can flip two tiles at a time by clicking on them. If colors of the flipped tiles match, they will be removed from the table. If colors don't match, they turn grey again.
Having 16 matchable tiles means having 8 different colors, and a "void" color to represent the unclicked tile.
The only object used in this movie is this movieclip:

The movieclip is linked as colors and has 9 frames: the ones from 1 to 8 represent the eight colors, while frame number 9 represents the grey tile.
The .fla file is called color_match.as and in its properties window the document class is color_match Read more
ActionScript 3.0 Game Programming University
If you want to learn some good AS3 game development basics, then you should read ActionScript 3.0 Game Programming University.
Inside ActionScript 3.0 Game Programming University you will find a brief introduction to AS3 and a guide how to create 17 among the most common Flash game types you can find in every game portal.
Games range from platform games to puzzles, and every game is explained starting from the creation of a working prototype, then adding more and more features until you get the final game.
You won't get NewGrounds frontpage with such games, but you will learn the AS3 basics behind the creation of a game.
I have to say this book is not for absolute beginners: you will need some previous experience with AS2 and Flash environment.
Also, sometimes I felt like the author took shortcuts to avoid some common problems you will have to face in the creation of a Flash game.
But if you are familiar with AS2 and are afraid to jump into AS3, this book can be the one you are looking for.
Even if the code is well explained, sometimes in my opinion the author does not explain why should you write that code, giving a feeling like "shut up and code like me"
Anyway, maybe I am just envy he wrote 17 AS3 game tutorials while I still have to write one.
On the official site you can find the source code of all games, a forum where to discuss with other readers and a blog with some other tutorials.
Go buy the book!



