Friday, June 22, 2007

Vivid random colors

If you want more control over how to create random colors, you need to steer away from the RGB space and go into the more human-friendly HSB color space, which is Hue/Saturation/Brightness.

Unfortunately flash doesn't natively support this but you can convert between the color spaces using some help functions like the following which were found here:

function hsv2rgb(hue, sat, val) {
var red, grn, blu, i, f, p, q, t;
hue%=360;
if(val==0) {return({r:0, g:0, v:0});}
sat/=100;
val/=100;
hue/=60;
i = Math.floor(hue);
f = hue-i;
p = val*(1-sat);
q = val*(1-(sat*f));
t = val*(1-(sat*(1-f)));
if (i==0) {red=val; grn=t; blu=p;}
else if (i==1) {red=q; grn=val; blu=p;}
else if (i==2) {red=p; grn=val; blu=t;}
else if (i==3) {red=p; grn=q; blu=val;}
else if (i==4) {red=t; grn=p; blu=val;}
else if (i==5) {red=val; grn=p; blu=q;}
red = Math.floor(red*255);
grn = Math.floor(grn*255);
blu = Math.floor(blu*255);
return ({r:red, g:grn, b:blu});
}
//
function rgb2hsv(red, grn, blu) {
var x, val, f, i, hue, sat, val;
red/=255;
grn/=255;
blu/=255;
x = Math.min(Math.min(red, grn), blu);
val = Math.max(Math.max(red, grn), blu);
if (x==val){
return({h:undefined, s:0, v:val*100});
}
f = (red == x) ? grn-blu : ((grn == x) ? blu-red : red-grn);
i = (red == x) ? 3 : ((grn == x) ? 5 : 1);
hue = Math.floor((i-f/(val-x))*60)%360;
sat = Math.floor(((val-x)/val)*100);
val = Math.floor(val*100);
return({h:hue, s:sat, v:val});
}
So to create vivid random colors you just randomize the Hue, and set a high Saturation and Brightness. If you just want random shades of a color, you set the Hue and Saturation and just randomize the Brightness.

Tuesday, June 19, 2007

Random seed not settable in Flash Pseudo-Random Number Generator

I'm still polishing up the puzzle game I'm working on. I was in a debugging session and I wanted to set the random seed for the PRNG. And surprise!!! There is no method to set up the random seed for Math.random().

However I came across this which provides a class for a PRNG. Pretty useful ;)

Tuesday, June 12, 2007

Dynamic text problem

I wanted to markup some text in a dynamic text field using the .htmltext property . But the bold characters were not showing. I found the answer to the problem here.

I just needed to create an off-stage dynamic text whose only purpose is to embed the bold font. If I wanted italic as well, i would have to do another dynamic text which embeds the italic font.

Now if only flash warned me that there are missing font definitions, argh!

Array instantiation for actionscript classes

If you want to avoid some nightmares, don't instantiate the arrays in the variable definition inside a class.
i.e. DON'T do the following

class myClass {

var my_array:Array = new Array()

function myClass()
{
}

....
}


Coz this would end up with a behaviour similar to having the my_array defined as static. What I think that it is happening, is that it won't re-initialise the variables when you instantiate a class but will just give you a reference to the array. Thus each instance you create will have a reference to the same array. How dumb!

So the solution is ofcourse to move the array instantiation in the constructor, like so:

class myClass {

var my_array:Array;

function myClass()
{
my_array = new Array();
}

....
}

Monday, June 11, 2007

Dictionary service and getTextExtent

I'm still working on the word puzzle game so far.
I got this idea this morning, that when you manage to connect a word it would access an online dictionary service and give you a definition. Basically I was testing the game and I was forming words that I didn't ever hear before. So you can actually learn something by playing this game :)

I found this free dictionary service
http://services.aonaware.com/DictService/
I'm currently using it to request word definitions and then place them in a speech bubble.

I also worked on scrolling the speech bubble text if the definition didn't fit. I used the TextFormat.getTextExtent() method, even though it is errouneously marked as deprecated for Flash8.

Friday, June 8, 2007

Word list in Flash word game

I'm working on a word puzzle game for a client and I had the challenge to find if a word was created on a game board and had to access 28,000 words (taken from a word list found at http://wordlist.sourceforge.net/ which are used for spell checking, word games, etc)
Originally there were over 80,000 words but I trimmed off the long words which cannot be created on the board.

To overcome the slow speed of flash accessing a huge array, I split up the word list in 26 arrays (one for each letter). This was not enough. You could tell that the CPU was doing something since the animation stop until he checks the board. So I re-split each array into another 26 arrays. Flash doesn't have red-black trees (or is there??) so I had to improvise ;) This was the simplest and now you won't notice it is checking the board for 28,000 words :D.

Wednesday, June 6, 2007

Not much progress this week

Not much progress on the prototype this week. I'm currently busy doing a flash puzzle game for a client and also getting updated on all the changes (and problems/bugs) with AS3.

Monday, June 4, 2007

Player disconnections

It was a busy day, but I found some time for the flash game prototype ;). Started coding some support for player disconnections. The idea is that when a player disconnects, the other players will know that the other player was disconnected (by showing an icon in the HUD near the avatar which got disconnected). And then the player with the same username only can reconnect to the game session. We will also notify the player that he has a game pending and he can reconnect (without going to the lobby).

For now anyone can reconnect ;)
But we will get to the above semantics.

Debugging Flash Player 9 with a logfile

There has been some changes in Flash Player 9...
mainly that you cannot change where the log file will be saved.
You will find the flashlog.txt in C:\Documents and Settings\user_name\Application Data\Macromedia\Flash Player\Logs

You need the debug player/activex/plugin from here.

For more details on setting the necessary mm.cfg check out the docs.

Saturday, June 2, 2007

Trolls and ActionScript3

I have started coding the trolls which currently are very simple objects that just move horizontally. Nothing really intelligent.

I have also started learning a bit about AS3 (about time huh?). There are some new concepts which I'm reading about. It seems like they have taken a good direction into scrapping a lot of stupid stuff that was in AS1/2 like movie depth assigning ... they have have gone for a display list approach. I will comment more once I will start using it. They have changed so much that you have to read a bit about migrating the code to AS3. So I think it will be time well spent ;). Especially because of the optimizations they have done. FINALLY we have int and uint! (instead of just Number class), i.e. optimizations can be done by the compiler. Also no more removeMovieClip... you just set the reference to null, and a movie will be garbage collected.

Wednesday, May 30, 2007

Change of focus, bigger screen size, reached end marker, and dying

So the most important thing I've coded today is the change of focus. This is used a lot to give some visual cues to the player. For example when he throws an arrow, the focus is now on the arrow (until the player decides to moves or the arrow strikes something). It is also used when he activates some lift and we want to show him what he activated. It will later be used when he clicks on the minimap and when we want to show the players the waypoints.

Another important thing is the concept of dying. Well the player doesn't really die. We just reset him to the start position. The player dies when he falls at a certains speed, or (when we have health and damage implemented) when health reaches 0.

I've also increased the screen size to 640 x 480.
And I've made a "very good" sign to appear on the avatars' icon that reach the exit point.
Also I've added the ping that is automatically sent every 10seconds and displayed under the respective avatar. Give's an indication of how much the latency is ;)

Tuesday, May 29, 2007

Mantis bug tracker installed

I needed a central place where to put the number of features being proposed and also the number of bugs that crop up ;). So I've installed Mantis... it's open source and free plus easy to use and installs within a couple of minutes.

I will later give access to anyone who takes part in the development ;)

Fixed some bugs and new help screen


Today I didn't do much as regards to new features. However, I've fixed the following bugs:
- arrow falling from help sign (this was actually funny)
- character not having right characteristics (was using a static variable pfff)
- tile glitch fixing (was moving the tiles with floating point and so some seams where appearing)
- initial speed of projectiles
- no aim for the runner (doesn't need it)
- some minor code cleanup

I've also tried out Sven's idea for zooming out. Ofcourse it was very crude... I just modified _xscale and _yscale of the _root movie, but still got an idea if it would be useful. Let's say that i need to feel it in a bigger level before I take out the guts of the level class to cater properly for this feature. The effect looks pretty cool though ;)

I also created a new help screen. Hopefully it gives a better idea of what keys are to be used and the characteristisc of each player.

Coming up next is the notion of having a focus point for the level. So I can follow an arrow, another player, or show the players where they need to go before they start playing.

Monday, May 28, 2007

ActionScript3, Proxy Servers and Binary Sockets

I tried to show the prototype to a friend of mine, but he cannot do a direct connections. In fact he uses a proxy server for browsing too.

I made a quick search and apparently there are some hints that ActionScript3 supports the CONNECT method which basically uses HTTP to tunnel a connection. Although I'm not really sure how to do this.

Another interesting thing I've learnt is that now in AS3 there are Binary Sockets... (rather than using XMLSocket)

I've also found this blog entry (which is almost 1yr old) of this guy who seems to work @ adobe who has done some class that uses the CONNECT method. Will look into it sometime later on.

If anyone has ever used these or would like to dig deeper on how we can use it for the prototype, leave a comment or send me an email ;)

Exit pointer

I've just implemented an exit indicator which is shown when the exit area is not on screen. It renders itself near the edges of the screen and it also displays the distance the player is from the exit area. Nothing special but gives some bearings to the players ;)

Attachmovie and Graphic type

Be ware when you're using attachMovie(). Make sure that the type of the object you want to attach is actually a Movie type and not a Graphic. Else you will be manipulating _level0 without knowing!

Game sessions,minimap and in-game chat

I have finally updated the server code so proper game sessions are held. Basically when you're playing you don't receive lobby related commands, and when u're in the game you will only broadcast game related messages to your level players only.

Also I have implemented the minimap. It will show the other players' positions with small colored pins. Your pin will be white. For now it is not clickable. However in the future I will make it clickable so the view will jump to where you clicked.

I've also placed the avatars' faces at the top. And whenever someone chats, a speech bubble is displayed under the avatar which talked. Cool :D

Sucky flash comboboxes

I wanted to use combo boxes (aka dropdowns) for when editing a help sign to make it easier to show what the user is selecting (rather than entering 1 for the shooter actor).

The first problem I encountered was the depth of the rendered list when you click on the arrow to the discover the list. It doesn't use the depth of the combobox itself. It somehow uses it own shitty depth which would render behind the tiles in the level. (So that is why I'm pushing them to the side of the help sign so that the lists are visible at least).
Update: this problem has been temporarily solved by swapping the depths of the related tile when entering edit mode, so that it is not hidden under some other tile.

Secondly if I set the selectedindex while i'm loading the level (using a class file and not in a frame coz in a frame it works fine), the selectedindex is set alright, HOWEVER the combobox is not rendered right... it is just blank. WTF!!! So I had to save the selected index value in a temp variable, and when we switch to the editor mode, I set the selectedindex to the temp variable value.

If anyone has some idea why this happens and any solution for this... leave a comment or email me. Don't have time to waste on such stupid things...
on to the next thing...

Saturday, May 26, 2007

HUD mockup

I just made a HUD (heads-up display) mockup. Comments from the artists please ;)

It's shows a chat msg in action.
The minimap area is reserved as well.
The player icon will be marked with some overlay icon when he reaches the exit area.
There will be the names of the players underneath the respective player icon (not shown in mockup).

Sven's zoom in/out idea

Hey Nev,

Have you thought about the possibility of a zoom? This game almost cries out to be able to zoom in and out smoothly according to what u do, like smooth out when you run/walk, and zoom in when u interact with things.

Sven
I love this idea... especially for the runner. Since he is much faster, the player needs to view more in order to control the player better. I will keep this in mind for later. But definitely a very good idea.