Monday, April 19, 2010

Isometric Snake game for Facebook

During the weekend I went with my girlfriend to my countryside house. Anyway, I didn't want to waste my daily gamedeveloping time.
I created there simple snake game (days ago one of the most popular mobile game for Nokia cells) with isometric graphic. I modify sprites from one wikipedia graphic and use logic from my old Snake game.

Find VD SNAKE 3d on Facebook or simply try this link: http://apps.facebook.com/vd_snakeiso/. (My average result is 700points, what's yours:)?)
You can also become a fan of the game.

Monday, April 5, 2010

Eastern Compo 2010

It's almost tradition that during Eastern Holidays Warsztat members organize special edition of Compo (game developing competition, check). Randomly chosen topic of competition was "A game with particles-effect, Zombies, arrows and deadly spikes". Quite creative.

I tried to create Tower Defense Game with Zombies as creatures, particle-flame throwers and spike-guns as towers and arrows as obstacles. I use some old javascript particle effects and try even to build few fire-towers. Unfortunately JS and web browsers are not adapted to generate thousand of tiny objects. It worked fine with one tower, very bad with two of them, and with three haven't work at all. Because of that I decided that required 'particle effect' will be "Hell fire", shown on spawn place of Zombie creatures. The same situation was with spike/nail guns. So i change my mind and simply put spikes like arrows - on the ground as obstacles. It took me about 8 hours to design, code, prepare the graphics and test the game, so it is not finished at all.

Finally, except me, there was only one participant took part in Compo, so there was no results. If you are interested in my game, download it here: EasternCompo [290KB]
(Readme and gui are in polish, sorry).

Thursday, March 4, 2010

Removing item with given value from an Array in Javascript

'Delete' operator is the easiest way to remove from Javascript's array elements with given index. It works fine with objects like literals but using it on arrays is worst thing you can ever do. What happens if you try?

var tab = [1,2,3];
delete tab[1];
//result: [1, undefined, 3]

It just removes particular element, not even try to fix undefined space left after the operation. So its better to use splice() instead.

var tab = [1,2,3];
tab.splice(1, 1);
// result: [1, 3]

Okey, but what to do if we have to remove item with some given value? We can google a little and find how to expand prototype of an Array object with remove() method, like that:

Array.prototype.remove = function(value) {
this.splice(this.indexOf(value), 1);
return true;
};
a=[112, 234, 32545];
a.remove(234);
// a is [112, 32545];

It works for that case, for sure, but what when item we try to find is not in our array? indexOf() will return -1, and splice() will start to removing elements from end of an array.

a=[112, 234, 32545];
a.remove(22);
//a is [112, 234]

Not funny. So to avoid situations like that we have to put one additional condition to our method.

Array.prototype.remove = function(value) {
if (this.indexOf(value)!==-1) {
this.splice(this.indexOf(value), 1);
return true;
} else {
return false;
};
}

a=[112, 234, 32545];
a.remove(234);
// [112, 32545];
a.remove(22);
// still [112, 32545];

Everything's fine. But in IE (there is always some 'but' in there, thanks Bill), for sure in 6.0, i don't know about new versions, Array type Objects have no indexOf() method, so we have to build it on our own:

if(!Array.indexOf){
Array.prototype.indexOf = function(obj){
for(var i=0; i < this.length; i++){
if(this[i]==obj){
return i;
}
}
return -1;
};
}


Now it works fine. Thanks.

Wednesday, March 3, 2010

var blog = new Blog();

Syntax highlighting test:


#!/usr/bin/env python
# encoding: utf-8

from django.core.mail import send_mail
from django import forms
from registration.forms import RegistrationForm
from registration.models import RegistrationProfile
from django.conf import settings
from accounts.models import User, UserProfile
from django.forms import ModelForm

class UserProfileForm(ModelForm):
class Meta:
model = UserProfile
exclude = ('user')
fields = (
'about',
'image',
'address_street',
'address_city',
'address_zip',
'address_country',
'phone'
)