Tuesday, September 20, 2011

The Textures

I don't know if textures is the correct term for these guys. I think I should be using the word "sprites". But that's what I like to call the characters, so I'm gonna call these textures.


These are the blocks that are going to make up the entire world. Up there are some house textures. Some are Base textures and others are ones you can overlay.


I keep the textures over there to the right. Press space to open the panel and...


Categories!!! Click a category and you can choose which texture you want. The tetures are organized like this because there are gonna be a shit ton in this game. For grass I have one repeatable grass texture and eight transitional grass textures, and you better believe that this game will have more than one kind of grass.


Each tile has two pieces of data: It's category, and its number. The code for t_grass-LU is TG4, aka the fourth texture in the Ground category. You'll notice that there are three uncategorized tiles. Tclear (t_blank2) is used for blank overlay tiles, T0 (t_blank) is used for blank base tiles. Tback (t_BACK) is used for navigation in the texture menu.

And that's how it's organized. A lot of my code right now is going to be about finding texture data and changing texture data so we'll see this come up a lot.

Tiles are in a grid; tiles go in arrays.

This right here is a code post. I'm gonna be going through my code from beginning to end on what I have so far. Right now this is all level editor shit. All were concerned about is building maps. No character movement or any of that other shit. So without further ado here are the first lines of codes I got:

var game:MovieClip = new MovieClip();
addChild(game);
var bgArray:Array = new Array();
var fgArray:Array = new Array();
var bgData:Array = new Array();
var limitX:Number = 10;
var limitY:Number = 8;
var limitT:Array = [[0,2],["G",13],["H",15]];


var i:Number = 0;
var j:Number = 0;
var k:Number = 0;


First we declare game, that’s the empty movieclip where all the tiles will go. addChild(game) adds the game movieclip to the stage. bgArray will hold all of the Layer 4 tile movieclips. fgArray will hold all the Layer 3 tile movieclips. Soon I’ll add Layers 2 and 1. bgData holds all the data for each layer of each tile. There is no fgData, that data will be in bgData. LimitX and LimitY are arbitrary width and height values for our stage. LimitT has to do with textures. There are two catagories,Ground, with 13 textures, and House with 15 textures. i,j, and k will be useful whenever we need some number variables to manipulate. They will be used wherever needed throughout the code.

for (i=0; i<limitY; i++) {
bgArray.push([]);
fgArray.push([]);
bgData.push([]);
for (j=0; j<limitX; j++) {
bgArray[i][j] = new T0();
bgArray[i][j].x = j * 32;
bgArray[i][j].y = i * 32;
game.addChild(bgArray[i][j]);
fgArray[i][j] = new Tclear();
fgArray[i][j].x = j * 32;
fgArray[i][j].y = i * 32;
game.addChild(fgArray[i][j]);
bgData[i].push([0,0,0,0]);
//bgData[item#,category,item#overlay,cat.overlay]
}
}

This guy builds the arrays that will house are data. With the two for functions I have created a 10×8 grid, and in each place is a bgArray movieclip, a fgMovieClip, and an array in bgData that tells us the properties of this item. Soon there will be more data per block, at the moment it just records what texture it is, which is defaulted to T0, my blank block (More on the textures in the next post!)

The Level Editor


I’m pretty sure you have to make a level editor when you make a tiled game. You can’t manually write what each tile is in the code for each room, that would take forever. So when I make a tile based game, I make a level editor.

The tools are right there on the bottom. Hand moves the room around so you can have a large map and not need to see the whole thing the whole time. The pencil tool changes tiles you click on to whatever texture you have selected. The eyedropper is an easy way to select a texture right on the editor without having to go through all the textures. The Fill bucket isn’t working right now so ignore that. G centers the map in case you get lost.

To the left are the layers. Layer 4 is for all the base tiles, Layer 3 is another layer just for sprites with transparency. That way you can stack combinations of sprites which multiplies the variation of tiles. Layer 2 and Layer 1 are going to have to do with collision detection, depth, and special sprites like doors and treasure chests. I haven’t coded those yet.

As you can see, the textures themselves are all vector based. The problem with Flash and vector sprites is that they can look a little blurry. To avoid that make sure every rectangle is on an integer for its x and y values, and that its width and height are integers too.


And that goes for sprite games ESPECIALLY. If you are making a sprite game I’d go ahead and make sure every goddamned little pixel is on integers and is a whole number tall by a whole number wide. A good way to make sure you got the integers is by defaulting the movieclip register to the top-left instead of the middle, because if any image is an odd number wide than it’ll have an x-value of 7.5 or something and that’s bad.

Okay that’s enough for this post. In the next one I’ll get cracking on some of this code.

Hello World.

Welcome to The Fighting Melon. This is a blog about a game I’m making. A turn based RPG set in the middle ages. It is a tale of kidnapping, high robbery, adventure, and war. It is a tale of a young guard who loses everything close to her. It is a tale of an outcast ninja who wants nothing but money and hookers. It is the tale of a young gourd who must find his passion in life.

There’s lots of fighting too. I’d describe the battle system as final fantasy tactics on a smaller scale.  It’s turn based strategy where you control three characters and fight from one to fifteen enemies in each battle. Each turn you move your characters and attack and then the enemy moves and attacks. I haven’t thought out too much of the specifics yet.


I’m gonna make the entire thing tile based though because I want to have kind of a large world and I don’t want to have to draw every single background like I did with my last game. That was a pain in the ass. Also it’ll make collision detection a lot easier.

The graphics will be vectorz! I like pixels a lot but for this game I really want to take advantage of Flash’s vector capabilities. It’s the one thing Flash does better than every other kind of game, so why not use them? So each tile of grass will be a seamless vector square texture that is repeated. 


The characters are going to be in a stylized anime/realism style a la Chrono Trigger (but not really in that artist’s style).


In this blog I’ll be posting updates. Right now I’m about three days into coding the game. Screenshots will come, as well as code explanations and problems I’m having etc. Basically I’m doing this so I have a way to measure my progress, and also so I can actually remember what all my code does. Hell yeah, that will be so nice. This was the best idea ever.