Ultra Simple, but in Dart – Pacman

I programmed a very simple Pacman. I had always programmed only desktop or web applications and never a single game, and for a long time I had wanted to program at least a small 2D game (now I am longing to write a simple 3D game again), so now my wish has come true. My Pacman is programmed in Dart, which is “the JavaScript of the 21st century”, a language that, drawing on many languages (to name a few: Java, JavaScript, C#, Erlang, etc.), takes only the best.

I saw a question on Stack Overflow where the asker wanted to know why he should choose Dart for web development. Seth Ladd gave him a detailed answer with 20 reasons why Dart is better than JavaScript and other similar languages. At first, Dart and Dart Editor didn’t make much sense to me, but then I got into its syntax and especially its principles, and now I say – Dart really is a better language. Of course, Dart Editor is probably no match for Visual Studio and never will be, so this is where Dart falls short.

At first I tried on my own, using only built-in libraries, to detect collisions with ghosts, walls and food, but after 8 hours I admitted that I needed some external library. So I tried StageXL, which has a Rectangle class, which in turn has an intersects method. Then things moved quickly, and after half a day of non-stop programming Pacman was done. I “modified” the rules of Pacman: when he eats a power pill and runs into a ghost, the ghost does not move back to its house, it just leaves Pacman unharmed and continues on its way.

You can tell that you are protected from the ghosts by the blinking frame around the whole game. You can play the game at www.sunamo.cz . You can browse the source code on GitHub: 👻 The server went down, the owner moved out, and DNS forgot all about it.. And here is how it does (or doesn’t) work in individual browsers on Windows 7:

  • Internet Explorer 11 – Doesn’t work. It freezes the whole of IE and Pacman leaves a trail as he moves.
  • Opera 20 – Works OK. (no wonder, since Opera runs on Blink just like Chrome)
  • Chrome 33 – Works OK.
  • Firefox 27 – Works, it is playable, but it is not as fast as in Chrome.

That is why Chrome/Opera is the best choice for playing this game.

Categories

Leave a Reply