WordPress MochiAds plugin beta FIXED – UPGRADE
Loyal readers know I am developing a WordPress theme and plugin to run an arcade site using MochiAds games.
Released some months ago, it has been fixed when the mochi feed changed and while I was working to make it compatible with Gallery theme and add some new features, the feed changed again so I am updating the plugin again.
Now you can download the mochi.php file and replace the old one.
Refer to WordPress MochiAds plugin beta released for full installation and how-to.
Then, before you start feeding the blog again, you must select Mochi Table to update your table.
You also will notice two new menu options: Mochi Directory, that you should click to create a directory to save your own games, and the alpha version of Manage Game Files that will allow to download selected games from Mochi servers directly to your blog, earning money with the MochiAds publisher program.
Even if it’s just a beta, you can look at the script to see how I developed this function.
If you have some suggestions, let me know. I am working to the theme+plugin so any idea is welcome.
Playing with Google Analytics API
I think you all know Google Analytics.
A Google Analytics API has long been one of the most widely anticipated (and wanted from developers) features. On April 21st, 2009 the official blog announced that the Google Analytics Data Export API beta is now publicly available to all Analytics users.
The API will allow developers to extend Google Analytics in new and creative ways and integrate Google Analytics into their existing products and create standalone applications that they sell.
Read more at the official post.
So I think it’s time to play a bit with this new toy.
Today we’ll learn how to autenticate to the service.
I made the script you are about to see reading the information at this page.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <?php header("Content-type: text/plain"); $email = "xxxxxx@xxx.xx"; $password = "xxxxxxx"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://www.google.com/accounts/ClientLogin"); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch,CURLOPT_HEADER,true); curl_setopt($ch, CURLOPT_POSTFIELDS,"accountType=GOOGLE&Email=$email&Passwd=$password&service=analytics&source=feronatoblog"); curl_exec($ch); curl_close($ch); ?> |
Line 3: Setting the header to text/plain because I am going to output plain text instead of html
Lines 5-6: Assigning to two variables my Analytics email and password. Obviously replace the xxx with your correct Analytics email and password
Line 8: Initializing a cURL handle. I am using it to communicate to Google servers using HTTP protocol and pass variables in POST mode. More information about the cURL library at this link.
Lines 9-12: Setting some options for the cURL handle. CURLOPT_URL is the URL to fetch, CURLOPT_POST to perform a HTTP POST, CURLOPT_HEADER to include the header in the output and CURLOPT_POSTFIELDS contains the full data to post in a HTTP “POST” operation.
This way I am simulating an HTML form submission to https://www.google.com/accounts/ClientLogin using POST method.
Let’s take a look at the variables I am sending:
accountType: Type of account to be authenticated. The default is GOOGLE (I found it’s not case sentitive).
Email: The user’s email address.
Passwd: The user’s password.
service: The Analytics service name is analytics.
source: A string identifying your client application in the form companyName-applicationName-versionID (actually you can write whatever you want).
Lines 13 and 14 perform and close the cURL session.
This is the result if everything went fine:
1 2 3 4 5 6 7 8 9 10 11 12 13 | HTTP/1.1 200 OK Content-Type: text/plain Cache-control: no-cache, no-store Pragma: no-cache Expires: Mon, 01-Jan-1990 00:00:00 GMT Date: Sat, 25 Apr 2009 19:02:11 GMT X-Content-Type-Options: nosniff Content-Length: 563 Server: GFE/2.0 SID=DQAAA... LSID=DQAAA... Auth=DQAAA... |
The Auth code is what we need to retrieve account and report data. I’ll show you how to do it next time.
At the moment I am integrating the Analytics in a control panel we provide to some customers, in order to give them access to all information from a single page.
Do you have a creative use of this API in your mind? Look at some examples at this link and you will agree this is a great feature
MagOrMin – an old php based game
This is an ooooooold (let’s call it) game I explained for a web programming class in 2003 or 2004.
It was made to explain some basics about Php, sessions, MySql and styles. All in one.
That’s how students learn… all in one and with a real world example.
It’s just a “guess if next number will be higher or slower than the current one” concept, the same that I applied to GuessNext last year.
It’s called MagOrMin and the name comes from the italian translation of “higher” (maggiore) and “lower” (minore).
Simply click to say if next number will be higher or lower, gain extra lives and compete for the high scores.
I plan to port the game in Ajax, adding a so-called “Web 2.0″ style and convert it into a Facebook application with all features… you know… I must monetize everything…
Meanwhile here it is the source code: Read more
Trying to solve a Sokoban level with brute force
Before you even think this script will solve a Sokoban level, I must warn you: this script won’t solve a sokoban level, it won’t even recognize whether a level is solved or not.
This script, part of an old project I am going to bring to life again, will just make Sokoban wander around the maze eventually pushing crates here and there, according to Sokoban’s rules.
Feel free to add some backtracking to make it more interesting, but I have to say coding a Sokoban solver could be a nightmare.
If you want to see another Sokoban script (this time to play the game), read Javascript Sokoban game script.
Sokoban levels are shown and created this way:
# = wall
$ = crate
. = place
* = crate in place
@ = man
+ = man in place
And now the script… Read more
Sudoku creator/solver with PHP
This is an old project for a class held in 2005.
At that time, Sodoku game was very popular in Italy, and I saw quite a lot of Flash games based upon it.
If you don’t know what is a Sudoku, Wikipedia says is a logic-based number-placement puzzle. The objective is to fill a 9×9 grid so that each column, each row, and each of the nine 3×3 boxes (also called blocks or regions) contains the digits from 1 to 9 only one time each. The puzzle setter provides a partially completed grid.
The script consists in a set of functions that emulate the “human way” to solve a Sudoku game, with trials and errors, using backtracking.
The only thing you need to know is how I represent the Sudoku table inside the script.
It’s an array (line 193) with 81 values representing positions from 0 to 80. The value at n-th position is the one you will find on the table at row floor(n/9) and column n%9.
A value from 1 to 9 represents a know number of a Sudoku table, while a zero represents an unknown one.
For this reason, an array filled only with zeros like the one in the script will generate a new, full Sudoku. Read more
Perfect maze generation – tile based version
You may wonder why I am publishing another maze script.
The reason is simple: in Perfect maze generation with AS3 post and previous ones I just showed you how to make a perfect maze, but it’s not the kind of maze you can use in tile based or roguelike games.
Why not? Because walls aren’t tiles but just a side of the tile. In tile based games, walls are solid, but in my mazes walls are just paper sheets placed between a tile and another.
And it’s not over: in future posts (yes, expect more mazes, so what?) we’ll see how to convert a perfect maze into a dungeon.
This time I used PHP but it’s easily adaptable to AS3 or whatever other language, and of course I used backtracking.
The script is similar to the other ones, anyway I want to focus on maze size: in a normal perfect maze the size of the maze is exactly the number of empty spaces (tiles) we have on each side.
This happens because walls are not solid tiles, but just lines between a tile and another. Same thing for the boundaries.
In a tile based maze, a wall is a concrete tile, and same thing for the boundaries, so if you want a tile based maze with (virtually) the same walkable tiles as a normal (x,y) one, your size has to be (x*2+1,y*2+1).
Finally, when you walk through the maze removing walls, in tile based mazes you must walk through 2 tiles at every step, assuming the first tile is a wall and the second one is the tile you want to land on. Read more
Create a Wordpress MochiAds Leaderboards Widget
Some time ago I blogged about Showing MochiAds leaderboards in any Flash movie or web page with a script made by myself that displayed MochiAds leaderboards on your site.
Yesterday MochiAds guys released a widget that accepts a game slug and partner ID and will display all the available leaderboards for the given game. The partner ID will constrain the widget to showing only scores from your site if you choose to do so. The widget is a Flash .SWF that can be embedded on any HTML page on your site.
In the official docs page there is an example using swfobject library but there is a much simpler way to embed scores... here it is:
-
<embed src="http://dev.mochiads.com/static/pub/swf/LeaderboardWidget.swf?game=ballbalance" allowscriptaccess="always" menu="false" quality="high" width="400" height="400" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>
Just replace ballbalance with the game slug you want to display highscores.
Width and height have minimum values of 230 and 200 pixels, and the score table will adjust according to size. Read more
Put a banner with your MochiAds stats in your blog
Let's imagine you made an awesome game and monetize it with MochiAds, and want to show your readers/the world how much your game rocks, now you have an interesting option.
Thanks to Rhu from Blargh now you can have a banner showing your game stats.
I am talking about something like this

You can find an easy wizard at the official page and some more suggestions in this MochiAds forum thread.
I asked Rhu to give me more information about this project and this is what he said:
« Gathering data can be done through JSON, the link for which can be found here for example:
It works equally as well if you just type in (last time I checked, they just changed to the above format recently I noticed):
https://www.mochiads.com/share/stats/
The start/end dates will obviously need to be changed.
Graphics are all done through PHP, and are updated in the morning (the JSON stats suffer from the limitation of being updated once daily :) ). I also just got told that they're probably going to make it into an officially supported API sometime soon, so everyone should be able to make their own stats programs without much hassle (and without worry of them changing the JSON format :p ) »
That's really nice, I should consider developing a WP widget showing game stats...
Separate comments from trackbacks in your WordPress blog
When your blog starts becoming popular, people will visit, read and talk about it and your blog will have comments pingbacks, and trackbacks.
While everybody knows what is a comment, I am going to explain pingbacks and trackbacks.
From WordPress Codex Glossary:
Pingback lets you notify the author of an article if you link to his article (article on a blog, of course). If the links you include in an article you write on a blog lead to a blog which is pingback-enabled, then the author of that blog gets a notification in the form of a pingback that you linked to his article.
Trackback helps you to notify another author that you wrote something related to what he had written on his blog, even if you don't have an explicit link to his article. This improves the chances of the other author sitting up and noticing that you gave him credit for something, or that you improved upon something he wrote, or something similar. With pingback and trackback, blogs are interconnected. Think of them as the equivalents of acknowledgements and references at the end of an academic paper, or a chapter in a textbook.
Unfortunately WP's default theme (and a lot of other themes too) includes comments, pingbacks and trackbacks all together. Read more
Parsing MochiAds feed in a friendly way
I made this little script to debug my portal script (almost completed) and I want to share it with you.
It simply shows MochiAds feed in a friendly way, using lists.
-
<?php
-
-
$mochi_url = "http://www.mochiads.com/feeds/games?format=json";
-
$games_array = json_decode($feed, true);
-
-
-
echo "<ol>";
-
for($x=0;$x<$number_of_games;$x++){
-
echo "<li><ul>";
-
foreach($games_array[games][$x] as $varname => $varvalue) {
-
echo "<li><strong>$varname</strong>: ";
-
echo "<ol>";
-
foreach($varvalue as $subvar => $subvalue){
-
echo "<li>";
-
foreach($subvalue as $lastvar => $lastvalue){
-
echo "$lastvalue";
-
if(!$lastvar){
-
echo ": ";
-
}
-
}
-
}
-
else{
-
echo "$subvalue";
-
}
-
echo "</li>";
-
}
-
echo "</ol>";
-
}
-
else{
-
echo "<a href = \"$varvalue\" target = \"_blank\">$varvalue</a>";
-
}
-
else{
-
echo $varvalue;
-
}
-
}
-
echo "</li>";
-
}
-
echo "</ul></li>";
-
}
-
echo "</ol>";
-
-
?>
Hope you will find it useful.
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)


