The fastest way to find the distance between two points

While I was reading Claytus Hood Tower Defense case study I was impressed by this:

To estimate the distances and so check the range, I use Manhattan distance formula, less accurate but faster than Euclidian distance

Named after the grid layout of most Manhattan streets, it’s a form of geometry in which the usual metric of Euclidean geometry is replaced by a new metric in which the distance between two points is the sum of the absolute differences of their coordinates (for more information refer to Wikipedia’s Taxicab geometry page).

Now the question is: is Manhattan distance really faster than Euclidian distance?

For the following test I used PHP, but feel free to make it in any other language and I’ll be glad to publish your results. Read more

Complete Flash Sokoban game in less than 2KB

Some days ago I blogged about 6 games you must be able to make in less than a day.

Among these games I included Sokoban, and since I don’t remember if I’ve ever tried to make a complete Sokoban game, I did it today.

In less than a day and, above all, in less than 2KB!!

And don’t expect an incomplete prototype… my Sokoban game features:

* 10 levels
* Tiles of different color and shape
* Shared objects to save the games
* Eye-candy effects (being only 2KB!!) to show completed levels and current level
* Copyable level moves to publish your own level solution
* In game instructions
* No external files or other tricks to reduce file size.

As said, in less than 2KB. My latest build is 2,002 bytes that’s less than 2,048.

This is the source code, that wasn’t written with readability or performance in mind, just aiming to stay under 2KB… just an exercise: Read more

6 games you must be able to make in less than a day

Do you think you are a game developer? Do you want to start to make games in any language but you want to test yourself?

This is a list of six games you must be able to make in any language in less than a day.

Every game is a classic you can see on any device, and each of them has a particular feature that will help you growing in game programming.

If you aren’t able to make them… well…

Let’s see them

Concentrationhttp://en.wikipedia.org/wiki/Concentration_(game)

Concentration, also known as Memory, Pelmanism, Shinkei-suijaku, Pexeso or simply Pairs, is a card game in which all of the cards are laid face down on a surface and two cards are flipped face up over each turn. The object of the game is to turn over pairs of matching cards.

Why you must be able to make it: It’s the simplest game ever… just an array. Come on. Read more

Travelmates

Every travel can be the best travel ever if you choose the right travelmates.

In this photo, my travelmates

Let’s see them:

1) An iPhone, with some interesting apps to kill some time during a 11 hours flight

2) Sony Bloggie camera. High definition MP4 video, 5-megapixel still photos, USB arm, 270-degree swivel lens. Apart from that, decent videos with a pocket camera

3) Electric plug adapters… because sometimes batteries need to be recharged

4) Olympus TOUGH-3000… 12 Megapixels, waterproof to 3m, shockproof to 1.5m and freezeproof to -10°C (quite useless in Cuba anyway…)

5) Sony Handycam full HD with 40Gb hard disk… bigger than the Bloggie but with a lot better video quality… for the “really interesting events”

6) Nintendo Dsi + Zelda Spirit Tracks… you know… an 11 hours flight…. back and forth…

7) 16Gb USB Key… with all my stuff

8) Internet key… because I hate to wait at the airport (and no, no free WiFi in Italy)

9) Entry level MacBook Pro… I still don’t love Macs… but I don’t hate them anymore

10) The camera used to take this shot… a Sony Cybershot

11) A Lonsdale backpack to make all this stuff fit without problems

These are my travelmates. I would like to know yours

Saving and storing your work

No matter if you are a Flash game developer, a web designer, a video editor, a programmer or whatever… the more your work on your computer, the more files you will generate.

After a while, your hard disk will become a nasty place full of shattered project if you don’t follow some simple rules.

That’s how I organize, save and store my work.

1) I keep on the computer’s hard disk only the projects I am currently working on

With more than 10 years of work, keeping all projects, images, video and every other kind of file on the computer I am currently using would be really a nonsense. First, there is no reason to keep old projects on your hard disk, second I don’t want someone to rob my notebook and have access to an entire life of work. So I use to keep on my computer only the projects I am currently working on. When a project is finished, I move it on another hard disk. Should I work again on an old project, I copy it on my computer and start working on it, until it’s finished, then I move it on another hard disk.

Since you will access this hard disk once in a while (sometimes once a week, sometimes once a month), there isn’t any particular recommendation about the hard disk. I am using two USB 1TB iomega where I store almost all my work.

Why “almost”? Because I have some other USB 500GB hard disks with video projects. Videos can consume a lot of hard disk space, so it’s better to dedicate an entire hard disk to each project

2) I create a folder for each branch of my projects

In the picture you can see four directories. Two are obvious, while “Beta” contains all the abandoned projects and “No internet” contains all the projects I did not develop for the web, such as executable software, brochures, business cards, and so on. As said, videos are on other hard disks.

Obviously, the folders you will have may vary according to the type of projects you are working on… so you couldn’t have “Flash games” but you could have “Magazines”… this depends on your work.

Just remember: don’t delete anything. Never. That’s why I have a directory for abandoned projects. Hard disk are so inexpensive you can afford a lot of them Read more

Being a geek in Venezuela

Yesterday I bought a MacBook on the Apple Store using some of the income generated by this blog. Do you know why I could do this? Because I am a geek, and because I live in Italy.

If I lived in Venezuela, things could have been quite different. This is the story of John Freddy Vega, a blogger and geek from Venezuela.

He runs Cristalab, a blog full of AS3 and PHP tips, just like mine. But it’s not as easy as it seems.

« Any self-respecting geek has certain basic needs, and Venezuelans are no exception: smartphones, laptops, permanent internet connection, access to information and, above all, the ability to purchase a lot of stuff we love although we don’t need it at all.

That’s why Venezuela’s technology case is so curious. We are one of the Countries with highest Blackberry penetration, so much so that RIM (Research In Motion: the Canadian company that developes the BlackBerry smartphone) people were forced to know we’re not an African country, we have crappy but still profitable Internet connections and we can even (in many cases) afford a cable TV. Read more

11 questions to ask to yourself once you complete a project

Let’s say you just finished a project… no matter whether a website or a Flash game… but you finished it right now.

Let’s suppose your client gave you a deadline, or you just wanted to finish it today because tomorrow you’ll be busy on another project, or you’ll have some holidays.

In most cases, you know the whole project can be optimized. Depending on the project complexity, you will see a lot of things you could improve to make the project run faster, look better, being more understandable and – above all – reusable.

Unfortunately, in most cases we prefer to leave it “as is” since “it works” and “that’s enough”, because we think the customer is already satisfied

I have to say, once I finish a project, I promise myself to keep it as clean as I can, even if I know I won’t be able to reuse anything… like, as example, a website. But as I have a lot of work, almost all the times I end leaving the project “as is”.

While you can’t work for the rest of your life to the same project, there are 11 questions you should ask yourself before you can consider a project as “completed”

Let’s see them: Read more

Keep your WordPress Blog (or any site) clean with new Google Webmaster Tools

Yesterday I blogged about 10 ways to secure your WordPress blog

Today I found a new, important tool to keep your blog (or site) clean: Google Webmaster Tools and its new services “Fetch as Googlebot” and “Malware details”.

Once you enter into Webmaster Tools you will find on the left Dashboard sidebar a Labs item with two sub-items: “Fetch as Googlebot” and “Malware details”.

“Fetch as Googlebot” answer the common question “What does Googlebot see when it accesses my page?” Read more

The return of “Under Construction” – evolution of a malpractice

In the late 90′s most personal and some commercial websites used to place a big, animated, irritating image like this one:

This picture, placed in a webpage browsed at a 800×600 resolution (the most popular one during those years), fills half of the visible area.

This means the page was shouting “hey, I am incomplete, probably I will never be completed so what are you doing here?”

We know a good site is always under construction. This blog is always under construction. I add new content almost every day.

As co-owner of a web agency, I notice almost all customers ask some minor changes to their sites about every six months… no matter if it’s a new set of photos or an update to the “about” page… they are changing. Read more

Understanding (AS3) access modifiers (Public, Internal, Protected, Private)

I see a lot of confusion around the web about access modifiers, so I am going to give a brief explication about them.

First, if you noticed the post title, you’ll see I wrote AS3 in brackets because access modifiers have not been introduced with AS3, but AS3 finally featured access modifiers.

As far as I can remember, access modifiers came from C, or at least I started studying them when I was programming with C.

Acess modifiers are anguage keywords for specifying the visibility of classes and members, that means they determine which code may access classes and class members.

Just think about a bartender in a exclusive pub that may require membership, and everything will be easier.

public (available to all code): allows access from every class… the bartender will attend everyone, no matter where he’s coming from

internal (available within the same package): allows Classes sharing this package access… the bartender will attend only people somehow related with the pub (workers that built it, people involved in furnishing, and so on)… this definition may lead to misunderstandings, so let’s say access is limited exclusively to classes defined within the current project.

protected (availabile within the same class and subclasses): allows subclasses access… the bartender will only attend customers with membership and their sons

private (available only within the same class): allows access only by the same class… the bartender will only attend customers with membership

Now the big question: is it so important to use the right access modifier?… I have to say in most small projects that you’re sure you’ll be the only one using them, you can define everything as public and forget about the rest, but obviously if you are looking for reusability and portability, you should pay attention to access modifiers.

Next Page →