Platform engine using Box2D – Step 3

In this third part of the platform engine, it’s time to make our hero jump.

First, I suggest you to read parts 1 and 2 if you already didn’t, then you should know something about the magic of compound objects and how Box2D manages collisions.

Then, you’re ready to follow the tutorial :)

The hero in order to jump must be on the ground, or over some solid object.

The main idea is creating the hero as a compound object made with the hero itself (the big rectangle) and a ground sensor (the small rectangle under the big one) that will be triggered every time the hero stands over something solid, without interacting with the world.

Then, we should check the sensor to collide with objects according to the response decide if the hero can or can’t jump.

Believe me, it’s easier than it seems. This is the main script: Read more

Embed Flash Yahoo Weather in your page with Yahoo APIs

If you have a touristic website about a city or a travel agency, it may be useful displaying the weather somewhere in the page.

There are hundreds of free services solving the task, but none of them comes without watermark, is fully customizable and has a dedicated AS3 API like Yahoo’s one.

Let’s see how to embed it in a Flash movie.

Download the ASTRA Web APIs

The Yahoo! ASTRA Web APIs library is a set of wrapper tools that facilitate access to Yahoo! public APIs from Flex and Flash applications. The library creates an abstraction layer above the communication protocols used by Yahoo! servers, enabling Flash and Flex developers to send and retrieve data without any manual parsing.

You can find the ASTRA Web APIs at this link.

Prepare your folder

Once you unzipped the file, copy the com directory inside the Source one in the main folder, the same you are using for your project, or create your project in the Source folder.

If you choose to copy the com directory, your folder will look like this:

The script

First, you need to retrieve your location code. Go to this page and search for the weather in your city. Then, look at the url of the page… in my case, looking for Venice, Italy, it’s this one:

http://weather.yahoo.com/forecast/ITXX0085.html

That means the city code for Venice is ITXX0085.

Now it’s time to look at the script: Read more

How to use an embedded text file in Flash – Trie edition

This script is the same as How to use an embedded text file in Flash using the method described in Trie Data Structure in Actionscript 3

You can try it just replacing the main file in the source you can download at this page with the new one I am publishing now.

Now I am going to made some optimization and benchmarking, and I’ll let you know which script works better, testing them in different situations.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package {
	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.text.TextFieldType;
	import flash.text.TextFormat;
	import flash.events.Event;
	public class wordz extends Sprite {
		var text_field:TextField = new TextField();
		var words:embedded_text = new embedded_text();
		var text_format:TextFormat = new TextFormat();
		var letters:Array;
		var words_array:Array = new Array();
		public function wordz() {
			addChild(text_field);
			text_field.type=TextFieldType.INPUT;
			text_field.x=20;
			text_field.y=20;
			text_field.width=460;
			text_field.height=30;
			text_field.background=true;
			text_field.text="write a word";
			text_field.border=true;
			text_format.color=0x000000;
			text_format.size=24;
			text_field.setTextFormat(text_format);
			letters=[];
			words_array=words.toString().split(",");
			words_array.forEach(populate_tree);
			text_field.addEventListener(Event.CHANGE,on_input);
		}
		public function populate_tree(element:*, index:int, arr:Array):void {
			add(element);
		}
		public function get(jumble:String):Array {
			var results:Array=[];
			var root=letters[jumble.substr(0,1)];
			if (! root) {
				return results;
			}
			getRecursively(jumble, 1, root, results);
			return results;
		}
		private function getRecursively(jumble:String,position:uint,root,results:Array):void {
			var letter:String=jumble.substr(position,1);
			var child=root.children[letter];
			if (! child) {
				return;
			}
			if (child.word) {
				results.push(jumble.substr(0, position + 1));
			}
			getRecursively(jumble, ++position, child, results);
		}
		public function add(word:String):void {
			var letter:String=word.substr(0,1);
			var root=letters[letter];
 
			if (! root) {
				root=createNode(letter);
				letters[letter]=root;
			}
			addRecursively(word, 1, root);
		}
		private function addRecursively(word:String,position:uint,root):void {
			if (position==word.length) {
				return;
			}
			var letter:String=word.substr(position,1);
			if (! letter) {
				return;
			}
			var child=root.children[letter];
			if (! child) {
				child=createNode(letter);
				root.children[letter]=child;
			}
			if (position==word.length-1) {
				child.word=true;
			} else {
				addRecursively(word, ++position, child);
			}
		}
		private function createNode(letter:String) {
			return { value: letter, word: false, children: [] };
		}
		public function on_input(e:Event) {
			var new_array:Array=get(text_field.text);
			var position:int=new_array.indexOf(text_field.text);
			trace(position);
			if (position>-1) {
				text_field.backgroundColor=0x00ff00;
			} else {
				text_field.backgroundColor=0xff0000;
			}
		}
	}
}

Meanwhile study this one, result and source code are useless..

How to use an embedded text file in Flash

The opportunity to win up to $7000 with “Word Play” Flash Game Contest ends in 20 days, and I already showed you how to embed a text file in Flash.

Now it’s time to make something useful out of it.

In this script, you will learn something about dynamic text fields styling, input text fields and arrays.

All in one.

First, and seen in How to embed a text file in Flash post, you need to embed the text file… this time I am using a comma separated file, like this:

aa,aah,aahed,aahing,...,zymurgy,zyzzyva,zyzzyvas

and I am embedding it in the same old way:

1
2
3
4
5
6
7
8
9
10
package {
	import flash.utils.ByteArray;
	// assuming that words.txt is the name of your text file
	// and it's stored in the same directory of your flash file
	[Embed(source="words.txt",mimeType="application/octet-stream")]
	public class embedded_text extends ByteArray {
		public function embedded_text() {
		}
	}
}

Now, the main file will hold the “game”… you have to write a word… if the word exists in the text file, then the textarea background color will turn to green, if the word does not exist, the textarea background will turn to red. Read more

10 Ways to make a bad casual game

This is my personal adaptation of keynote presented at Casuality Europe by Jason Kapalka, co-founder and chief creative officer at PopCap Games during Casuality Amsterdam, on February 8, 2006.

Yes, a bit old, and not exclusively Flash-oriented, but these rules did not change during the last three years, so… here they are:

1) Make it really hard!

Not enough playing time in your game? Kick it up to SUPER MAX DIFFICULTY!

Make people fail each level 5 or 6 times, at least.

Punish newbies with violent death. They deserve it! Heavy Weapon was probably too hard for new players…

What to do instead…

Don’t punish new players who click around randomly at first. Give them time to experiment.

No casual game ever failed for being too easy. But plenty have failed for being too hard.

Games that depend entirely on skill can be intimidating. Games that rely entirely on chance can be boring.

Bad tutorials can make an easy game seem much, much harder. Lavish lots of time and energy on teaching people how to play.

2) Have a dozen mediocre game modes instead of one good one

Which of these modes is good? Which to play first?!

Difficulty level… do I want Easy? Normal? Hard???

If you can’t decide on one version of the game that’s actually fun, just throw every iteration in there! Quantity will make up for quality.

What to do instead…

Extra modes do provide value, but focus on making sure the main game is as good as it can be.

Selectable difficulty levels are problematic. New players have no way to know what subjective terms like “Easy” or “Normal” mean in this new game. Avoid if you can!

Be sure to explain alternate game modes as clearly as you can before users have to choose what to play. But see Rule 8! Nobody wants to read!

3) Make it a 600mb download that requires 2 next-gen video cards and 4gb of RAM and test it on just 1 computer

3d texture bump mapping is awesome, let’s toss that into our Solitaire game just for fun!

Nobody still uses a modem anymore. Do they?

QA, shmoo A. It works fine on my computer. Anyway, we can always patch it later.

What to do instead…

Don’t use 3d. Or have a 2d fallback mode.

Remember that every extra technical requirement you add shrinks your potential audience for the game… whether that is a newer processor, more memory, a larger download footprint, etc.

Test thoroughly.

Beware of requiring weird plugins or the like for your web game. Users are not keen on installing the latest JVM. Similarly, any apps you require to be present on the user’s machine for a downloadable game, whether that is the latest version of DirectX, or some arcane video player, are problematic and risky.

4) Price your game at $35. Or $3.50. And sell it only from your myspace home page

I dunno, that price just feels right to me.

We don’t need no stinking contracts or partners! We’ll launch this game on our own!

Someone offered us a deal! No time to read the fine print! Sign!

What to do instead…

If you price too low, people will think your game is probably garbage.

Be polite and reasonable when talking to publishers. It’s a small industry and word gets around if you’re difficult.

Consider your upsell incentives very carefully.

5) Use the Right Mouse Button

Making critical control elements rely on the right mouse button or the mouse wheel is cool. Doesn’t everybody have an RMB?

For that matter, why not use the keyboard to control stuff too?

Mouse AND keyboard at the same time? Even better! How about a flightstick?

What to do instead…

Casual game players prefer to use a mouse, and they don’t like to right-click or use the mousewheel or keyboard.

Many players run games in windows… be aware of the interface problems this poses.

Players do not generally have the patience to master complex or fidgety control schemes… if they don’t “get it” in 5 minutes they will move on.

6) Give it a terrible name or theme

Everyone knows casual game players love dungeons. In space. With robots. And skulls. Right?

How about a game with robot skulls… in a SPACE DUNGEON?

Remember to use words that resonate with your target audience, like “blood,” “war,” and “assault.”

What to do instead…

Pick an easy-to-spell, easy-to-pronounce title.

Make sure you can trademark the title.

Find non-violent, bright themes that appeal to casual gamers.

Make sure your theme meshes well with the mechanics of the game.

7) Award low scores

It’s not logical to award 10 points when 1 point will do.

It doesn’t matter if people think the game is low-scoring.

Touchy-feely psychological factors have no place in game design!

What to do instead…

Award lots of points!

Set up as many combos and bonuses as you can, to reward the player for anything positive they do. Reinforce with audio and video.

If something “feels” fun, pursue it whether or not it seems to make sense in “normal” game design terms.

8) Expect users to read

If the game is complex, we’ll just put a few pages of instructional text at the beginning.

What do you mean you didn’t get that part? There’s a three-paragraph pop-up that explains it!

It’s best to explain everything all at once so people understand the function of every single thing in the game before they start playing.

What to do instead…

Use as little text as possible.

Show, don’t tell. Use illustrations and animations whenever possible.

Lead users by the hand… make the instructions interactive and engaging.

Use big, readable fonts, and pay attention to layout and typography. Don’t make whatever text you do have hard to read.

The more text you have, the more difficult it will be if you ever have to localize it.

If you’re producing a game in a language that isn’t your native tongue, do not skimp on getting a good writer who is fluent. Writing very clear instructions in a very small space is NOT an easy task, and style matters.

Be careful with stories. It’s very easy to put in way too much text, so that people will just ignore or skip it. You should probably never have more than a single screen of story stuff at any given point, eg. between levels. Keep in mind some people will skim or skip it no matter what.

9) Make it challenging and cerebral

People LOVE really hard, really challenging mental puzzles. The kind that can totally stump and/or frustrate you for HOURS.

Well, some people do, don’t they? People who play Sudoku or the New York Times Crossword puzzle?

What do you mean those people aren’t the same ones playing casual games? That’s just crazy talk!

What to do instead…

Strive to make games compelling, addictive, and replayable.

Avoid stumping the player so that they can no longer proceed in the game.

Be generous with hints. Let them play the way they want to play.

The model for most casual games is closer to Solitaire than the New York Times Crossword Puzzle.

Remember that many casual players want to relax when they play a game… they don’t want to be challenged, frustrated, or agitated. This is in stark contrast to the typical console title, which is aimed at producing excitement.

10) Ignore what everyone else says about your game

What the hell does my MOM know about games, anyway?

These testers have been playing the game for 6 months now! So I trust their opinion on how new players will feel.

If you don’t get it, you’re… you’re just stupid!

Use the Mom Test.

Get fresh audiences frequently to see how newbies will respond to your game.

The less interested and experienced a person is with games, the more you should listen to their comments about your game.

MochiMedia redesigns the site and launches Mochi Coins

Today MochiMedia, the company that launched MochiAds and other awesome tools to monetize, distribute and track games, redesigned the site.

Now all features are accessible from the home page, and some of them changed their name, such as MochiAds now called Ads API, Mochibot (Analytics API), Version Control and Encryption (Live Updates) and Leaderboards (Scores API).

But the most interesting feature is the Coins API, a new product, enables Flash game developers to profit by selling game upgrades and items directly to their players.

Just like GamerSafe’s GameGold, you will be able to manage transactions and get the 60% revenue share.

If you don’t believe in microtransactions, just think about Ninja Kiwi’s SAS Zombie Assault: 2 was able to generate on a daily basis more than the entirety of their ad revenues.

At the moment, coins aren’t available for everyone, but you must pass through an application form to ensure the game has the required quality.

Another nice service to test, I positively have to develop games more quickly.

If you haven’t signed up yet, this is the right time for signing up to MochiMedia and start making money with your Flash games

Basic Filler engine with Box2D – part 2

Some time ago I published Basic Filler engine with Box2D – part 1, now it’s time to see the next step.

I am going to add enemies, the evil bouncing balls.

Obviously, enemies aren’t affected by gravity, and this can be made following the instructions published at Managing multiple gravities with Box2D.

The next, big, problem is enemies must have a constant speed, or at least a minumum speed, otherwise it will be easy to use your generated balls to collide with enemies and change their momentum slowing them down.

This is the part I fully commented on the script, at the moment I don’t manage player deaths, so you can create your red balls wherever you want. Read more

Managing multiple gravities with Box2D

One of the apparently hardest things to do with Box2D is assigning different gravity forces to different objects.

For instance, you may want the world to be ruled with regular gravity, while you don’t want the bullet fired by your character to be affected, or you may want regular gravity for all boxes and inverted one for all circles, like in the example I am talking about.

There is one way to simulate different gravity and one way to apply different gravity in your Box2D projects.

This is the main script, directly from the HelloWorld.as example provided with Box2D distribution (so just copy/paste the code)

In some case you should need to refresh the page to see the movies in action. Read more

Understanding MochiAds Publisher Bridge

Now that you have a WordPress theme and plugin in order to set uo your own MochiAds arcade site like triqui.com, let’s see how we can add some interesting features with the Publisher Bridge.

Every step explained in this tutorial will be included in the next upgrade of Triqui MochiAds Arcade theme, but it’s very interesting to see how does it work in order to custom it or install it in your own arcade site.

First, let me explain why you should use the Publisher Bridge… the reasons are listed in the official page:

  1. Leverage the hundreds of MochiAds leaderboard enabled games to attract new players.
  2. Receive new traffic – MochiAds’ Challenges feature will drive new players back to your site to compete in top scores.
  3. Build exciting site features – Save player scoring info for all MochiAds leaderboard-enabled games.
  4. Encourage competition – In-game scores are listed for your community only.
  5. Maintain consistency – Display your own community usernames when players post scores.
  6. Promote your brand – Put your site logo directly in the game.

but, as usual, it’s up to your creativity finding the best way to use them.

Cross-domain policy

From the Cross-domain policy file specification you cana cross-domain policy file is an XML document that grants a web client – such as Adobe Flash Player (though not necessarily limited to it) – permission to handle data across multiple domains. When a client hosts content from a particular source domain and that content makes requests directed towards a domain other than its own, the remote domain would need to host a cross-domain policy file that grants access to the source domain, allowing the client to continue with the transaction.

So the first thing you should do is to create a file called crossdomain.xml in your root, with this content:

1
2
3
4
5
6
7
8
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM
"http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
     <site-control permitted-cross-domain-policies="master-only"/>
     <allow-access-from domain="x.mochiads.com"/>
     <allow-access-from domain="www.mochiads.com"/>
</cross-domain-policy>

This will allow Mochi client to communicate with your server.

Javascript call

Once your server is able to communicate, you need to insert the javascript provided by Mochi in the same page where you host (or leech) a game.

You don’t need to know if the game has a leaderboard, if the game does not support highscores, nothing will happen.

This is the one I used:

1
2
<script src="http://xs.mochiads.com/static/pub/swf/leaderboard.js" type="text/javascript"></script>
               <script type="text/javascript">var options = {partnerID: "3b7a2ab2368e1d2d", id: "leaderboard_bridge",globalScores:"true",gateway : "http://www.triqui.com/wp-content/themes/triqui/postscores.php",callback : function (params) {document.getElementById('latest').innerHTML="Your latest score: "+params.score;}}; Mochi.addLeaderboardIntegration(options);</script>

I used only a few options among the ones provided by Mochi, let me explain them:

partnerID: this is the ID MochiAds gave you when you signed up as a publisher. Remember: the Publisher ID, not the Publisher Secret Key!!!

id: The id of the HTML element you want to place the Bridge SWF into. Place such element wherever you want, it’s not important since it does not contain anything.

globalScores: Set to true if you wish to display global scores and not just those submitted from your site. I recommend to set it to true if your portal does not have that much visits per day (under 10,000).

gateway: the absolute path of a file that will receive posted data with POST method. I’ll explain how to use such data in next tutorial

callback: a JavaScript function which will be called when the player submits a score. In my case, I simply display in the page the latest score the player got, but obviously you can use Ajax to improve the interactivity.

Try to see it in action playing a leaderboard enabled game on Triqui.com, such as Mazeroll and see what happens when you submit a score.

But the most exciting feature lies in the gateway: having all score data in the POST array will allow you to create custom leaderboards and some other interesting things I’ll explain during next tutorial.

Meanwhile, look at the variables the bridge passes to postscores.php page when I submit a score, obtained with a simple var_dump:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
array(14) {
  ["signature"]=>
  string(32) "(had to omit it)"
  ["sessionID"]=>
  string(0) ""
  ["userID"]=>
  string(0) ""
  ["username"]=>
  string(0) ""
  ["scoreLabel"]=>
  string(6) "Points"
  ["sortOrder"]=>
  string(4) "desc"
  ["datatype"]=>
  string(6) "number"
  ["description"]=>
  string(0) ""
  ["title"]=>
  string(10) "Highscores"
  ["gameID"]=>
  string(16) "98c536dbf70a1cbc"
  ["boardID"]=>
  string(32) "4b2ac948de239f8853a3bc6a1b771d9d"
  ["name"]=>
  string(4) "ququ"
  ["score"]=>
  string(3) "520"
  ["lcId"]=>
  string(1) "1"
}

Next time I’ll show you how to use these values.

Platform engine using Box2D – Step 2

After publishing Platform engine using Box2D, my attempt to replicate the Rick Triqui‘s main character continues.

Now you can move the guy with left and right arrows, aim the bazooka with the mouse and shoot a bullet clicking on the mouse.

The bazooka isn’t a Box2D object because I didn’t need to include it into the physics world, so it’s just a sprite, like the pills in Mazeroll game.

This is the source code, still uncommented (I’ll made the tutorial when I’ll have the character jumping and textured) Read more

Next Page →