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:

ACTIONSCRIPT:
  1. if (ASnative(800, 2)(2)) {
  2.     // code to execute when the player tries to cheat
  3. }

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.

If you liked this post buy me a beer (or two)

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.

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.

If you liked this post buy me a beer (or two)

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?

Floaty Light

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

ACTIONSCRIPT:
  1. _root.attachMovie("ball", "ball", _root.getNextHighestDepth(), {_x:50, _y:50});
  2. _root.attachMovie("wall", "wall", _root.getNextHighestDepth(), {_x:240, _y:200});
  3. _root.attachMovie("arrow", "arrow", _root.getNextHighestDepth());
  4. moving = false;
  5. gravity = 0.01;
  6. xspeed = 0;
  7. yspeed = 0;
  8. precision = 24;
  9. radius = 15;
  10. Mouse.hide();
  11. arrow.onEnterFrame = function() {
  12.     this._x = _xmouse;
  13.     this._y = _ymouse;
  14.     dist_x = ball._x-this._x;
  15.     dist_y = ball._y-this._y;
  16.     total_dist = Math.sqrt(dist_x*dist_x+dist_y*dist_y);
  17.     if (total_dist>300) {
  18.         total_dist = 300;
  19.     }
  20.     total_dist = (300-total_dist)/500;
  21.     angle = Math.atan2(dist_y, dist_x);
  22.     this._rotation = angle*57.2957795;
  23. };
  24. ball.onEnterFrame = function() {
  25.     if (moving) {
  26.         dir = arrow._rotation;
  27.         xspeed += total_dist*Math.cos(dir*0.0174532925);
  28.         yspeed += total_dist*Math.sin(dir*0.0174532925);
  29.     }
  30.     yspeed += gravity;
  31.     this._x += xspeed;
  32.     this._y += yspeed;
  33.     xspeed *= 0.99;
  34.     yspeed *= 0.99;
  35.     for (x=1; x<precision; x++) {
  36.         spot_x = this._x+radius*Math.sin(x*360/precision*0.0174532925);
  37.         spot_y = this._y-radius*Math.cos(x*360/precision*0.0174532925);
  38.         if (wall.hitTest(spot_x, spot_y, true)) {
  39.             xspeed = 0;
  40.             yspeed = 0;
  41.             this._x = 50;
  42.             this._y = 50;
  43.         }
  44.     }
  45. };
  46. _root.onMouseDown = function() {
  47.     moving = true;
  48. };
  49. _root.onMouseUp = function() {
  50.     moving = false;
  51. };

Let's play it!

Download the source code and give me feedback

If you liked this post buy me a beer (or two)

Prototype of a Flash game like GearTaker

Do you know Tony Pa's GearTaker game?

GearTaker

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 the rest

If you liked this post buy me a beer (or two)

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 the rest

If you liked this post buy me a beer (or two)

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 the rest

If you liked this post buy me a beer (or two)

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.

ActionScript 3.0 Game 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!

If you liked this post buy me a beer (or two)

Create an Eskiv Flash game tutorial

Do you know a Flash game called Eskiv? No?

Never mind, it's not the best game around there, but there is a thread called Eskiv Clone? in the forum asking help in making a game like that one.

First, play it a minute

Then, take this prototype, starting from an old tutorial called Flash game creation tutorial - part 1.

ACTIONSCRIPT:
  1. _root.attachMovie("score","score",1);
  2. _root.attachMovie("hero", "hero", 2, {_x:250, _y:200});
  3. _root.attachMovie("target", "target", 3, {_x:Math.random()*400+25, _y:Math.random()*300+25});
  4. power = 3;
  5. enemy_power = 5;
  6. points = 0;
  7. hero.onEnterFrame = function() {
  8.     if (Key.isDown(Key.LEFT)) {
  9.         this._x -= power;
  10.     }
  11.     if (Key.isDown(Key.RIGHT)) {
  12.         this._x += power;
  13.     }
  14.     if (Key.isDown(Key.UP)) {
  15.         this._y -= power;
  16.     }
  17.     if (Key.isDown(Key.DOWN)) {
  18.         this._y += power;
  19.     }
  20. };
  21. target.onEnterFrame = function() {
  22.     dist_x = this._x-hero._x;
  23.     dist_y = this._y-hero._y;
  24.     distance = Math.sqrt(dist_x*dist_x+dist_y*dist_y);
  25.     if (distance<(hero._width+this._width)/2) {
  26.         points++;
  27.         score.scoretxt.text = points;
  28.         this._x = Math.random()*400+25;
  29.         this._y = Math.random()*300+25;
  30.         foe = _root.attachMovie("enemy", "enemy", _root.getNextHighestDepth(), {_x:Math.random()*400+25, _y:Math.random()*300+25});
  31.         foe.dir = Math.floor(Math.random()*4);
  32.         foe.onEnterFrame = function() {
  33.             switch (this.dir) {
  34.             case 0 :
  35.                 this._x += enemy_power;
  36.                 if (this._x>500-this._width/2) {
  37.                     this.dir = 1;
  38.                 }
  39.                 break;
  40.             case 1 :
  41.                 this._x -= enemy_power;
  42.                 if (this._x<0+this._width/2) {
  43.                     this.dir = 0;
  44.                 }
  45.                 break;
  46.             case 2 :
  47.                 this._y += enemy_power;
  48.                 if (this._y>400-this._width/2) {
  49.                     this.dir = 3;
  50.                 }
  51.                 break;
  52.             case 3 :
  53.                 this._y -= enemy_power;
  54.                 if (this._y<0+this._width/2) {
  55.                     this.dir = 2;
  56.                 }
  57.                 break;
  58.             }
  59.             dist_x = this._x-hero._x;
  60.             dist_y = this._y-hero._y;
  61.             distance = Math.sqrt(dist_x*dist_x+dist_y*dist_y);
  62.             if (distance<(hero._width+this._width)/2) {
  63.                 points--;
  64.                 score.scoretxt.text = points;
  65.                 this.removeMovieClip();
  66.             }
  67.         };
  68.     }
  69. };

And this is the result

Move the purple ball with arrow keys and take the red one. Avoid blue ones and score as much as you can.

This version has better collision detection than the original one

Download and play with it

If you liked this post buy me a beer (or two)

Marketing Flash games: email template

When you make a Flash game, unless it hits top portals frontpages (like NewGrounds) and spreads virally, you have to submit it to thousands portals in order to give it some decent exposure.

At the moment the best resource about Flash game marketing is Marketing Flash Games: The Other Half of the Battle, but if you're not into marketing, you will also need a mail template.

I was (heavily) inspired by the creator of Kullors and this is an email template that should work the first time (you'll understand later why)

[greeting]
Hi

[brief ice breaker]
My Latest game (gamename) has just (been released/completed a 7 day exclusive license/etc) and I am now able to distribute the game freely. As such I would be most grateful if you were to consider it for inclusion on your website/Game Portal.

[brief game description]
(gamename) is (about 20 words to describe it)

[links to play and download]
You can play it at (link) and you can download a zip file containing the swf a txt description and game icons of various sizes in gif format at (link).

[encourage feed back]
If you have any questions or comments I would more than happy to hear from you.

[thank ]
Many thanks for your time and consideration

[close]
Kind regards
(your name)

Now just two or three (well... three!) considerations:

1) The link to the game to play should be the one of an important portal only if the game has good rating/reviews... you don't want the portal owner going to play your game at Kongregate just to read players don't like it

2) This, as said, is the template for the first email you will send to the portal. Once they reply, if they do, save the contact of the person who replied and try to establish a contact more... let's say "human" than a "developer to portal owner" one.

This will help you when you will need to release future games. Remember that good marketers don't have millions of contacts. They have some good contacts. When I need some information about MochiAds, I don't look for an invisible "contact us" button... I write to Ada. When I want to show my new game to AddictingGames, I write to Justin... and so on. Make your own priceless contact list and your life will be easier

3) When you managed to have a good contact list, remember they are not your classmates. Don't bother them with "I have a new girlfriend!" and don't submit them bad games just because you think they will publish anything you produce since they are friends of yours

Follow those rules and your games marketing will reach a new level.

If you liked this post buy me a beer (or two)

Finding adjacent cells in an hex map - part 2

In the Finding adjacent cells in an hex map post I showed you how to find adjacent cells in horizontal hex maps.

Now it's time to find adjacent cells in vertical hex maps.

ACTIONSCRIPT:
  1. hexagon_width = 44;
  2. hexagon_height = 38;
  3. grid_x_size = 10;
  4. grid_y_size = 12;
  5. sector_width = hexagon_width/4*3;
  6. sector_height = hexagon_height;
  7. gradient = (hexagon_width/4)/(hexagon_height/2);
  8. for (x=0; x<grid_x_size; x++) {
  9.     for (y=0; y<grid_y_size; y++) {
  10.         hexagon_x_position = hexagon_width*y/4*3;
  11.         hexagon_y_position = hexagon_height*x+(y%2)*hexagon_height/2;
  12.         hexagon_number = y+x*grid_y_size;
  13.         hexagon_movieclip = attachMovie("hhexagon", "hhexagon_"+hexagon_number, hexagon_number, {_x:hexagon_x_position, _y:hexagon_y_position});
  14.         hexagon_movieclip.gotoAndStop(1);
  15.         hexagon_movieclip.txt.text = hexagon_number;
  16.     }
  17. }
  18. onEnterFrame = function () {
  19.     _root["hhexagon_"+hexagon_hover].gotoAndStop(1);
  20.     _root["hhexagon_"+(hexagon_hover+1)].gotoAndStop(1);
  21.     _root["hhexagon_"+(hexagon_hover-1)].gotoAndStop(1);
  22.     _root["hhexagon_"+(hexagon_hover+11)].gotoAndStop(1);
  23.     _root["hhexagon_"+(hexagon_hover+12)].gotoAndStop(1);
  24.     _root["hhexagon_"+(hexagon_hover+13)].gotoAndStop(1);
  25.     _root["hhexagon_"+(hexagon_hover-11)].gotoAndStop(1);
  26.     _root["hhexagon_"+(hexagon_hover-12)].gotoAndStop(1);
  27.     _root["hhexagon_"+(hexagon_hover-13)].gotoAndStop(1);
  28.     sector_x = Math.floor(_xmouse/sector_width);
  29.     sector_y = Math.floor(_ymouse/sector_height);
  30.     delta_sector_x = _xmouse%sector_width;
  31.     delta_sector_y = _ymouse%sector_height;
  32.     switch (sector_x%2) {
  33.         case 1 :
  34.             if (delta_sector_y>=hexagon_height/2) {
  35.                 if (delta_sector_x>(hexagon_width/2-delta_sector_y*gradient)) {
  36.                     real_x = sector_x;
  37.                     real_y = sector_y;
  38.                 }
  39.                 else {
  40.                     real_x = sector_x-1;
  41.                     real_y = sector_y;
  42.                 }
  43.             }
  44.             else {
  45.                 if (delta_sector_x<delta_sector_y*gradient) {
  46.                     real_x = sector_x-1;
  47.                     real_y = sector_y;
  48.                 }
  49.                 else {
  50.                     real_x = sector_x;
  51.                     real_y = sector_y-1;
  52.                 }
  53.             }
  54.             break;
  55.         case 0 :
  56.             real_x = sector_x;
  57.             real_y = sector_y;
  58.             if (delta_sector_x<((hexagon_width/4)-delta_sector_y*gradient)) {
  59.                 real_x = sector_x-1;
  60.                 real_y = sector_y-1;
  61.             }
  62.             if (delta_sector_x<((-hexagon_width/4)+delta_sector_y*gradient)) {
  63.                 real_x = sector_x-1;
  64.                 real_y = sector_y;
  65.             }
  66.             break;
  67.     }
  68.     if ((real_x>=0) and (real_x<grid_y_size) and (real_y>=0) and (real_y<grid_x_size)) {
  69.         hexagon_hover = real_x+real_y*grid_y_size;
  70.         _root["hhexagon_"+hexagon_hover].gotoAndStop(2);
  71.         if(hexagon_hover%grid_y_size!=grid_y_size-1){
  72.             _root["hhexagon_"+(hexagon_hover+1)].gotoAndStop(3);
  73.         }
  74.         if(hexagon_hover%grid_y_size!=0){
  75.             _root["hhexagon_"+(hexagon_hover-1)].gotoAndStop(3);
  76.         }
  77.         if (hexagon_hover%2 == 0) {
  78.             _root["hhexagon_"+(hexagon_hover-11)].gotoAndStop(3);
  79.             if(hexagon_hover%grid_y_size!=0){
  80.                 _root["hhexagon_"+(hexagon_hover-13)].gotoAndStop(3);
  81.             }
  82.             _root["hhexagon_"+(hexagon_hover+12)].gotoAndStop(3);
  83.             _root["hhexagon_"+(hexagon_hover-12)].gotoAndStop(3);
  84.         }
  85.         else {
  86.             if(hexagon_hover%grid_y_size!=grid_y_size-1){
  87.                 _root["hhexagon_"+(hexagon_hover+13)].gotoAndStop(3);
  88.             }
  89.             _root["hhexagon_"+(hexagon_hover+11)].gotoAndStop(3);
  90.             _root["hhexagon_"+(hexagon_hover+12)].gotoAndStop(3);
  91.             _root["hhexagon_"+(hexagon_hover-12)].gotoAndStop(3);      
  92.         }
  93.     }
  94. };

Here it is:

This is the last uncommented step, during next one we will discuss about the method used to determine adjacent cells.

Download and enjoy!!

<