controlling screen cells (strategy, puzzle)

You must understand the Game Editor concepts, before post here.

controlling screen cells (strategy, puzzle)

Postby DST » Wed Feb 25, 2009 3:55 am

Often you have a game where the screen is broken apart into cells; and everything snaps to that.

In these cases, its often good to store the information about the occupant of a cell directly into the cell.

Here's a quick way to control screen cell arrays.

cell[] - array, size is determined by your screen settings. 640x480 divided into 32x32 cells=300 total cells, with 0 being the upper left cell and 299 being the lower right cell.
ccell - global integer

so you can find the mouse clicks and refer them to a cell; in this type of setup, you would not use mousebuttondowns on any actor except one, filled region, that catches all mouse clicks.(simply put it on the bottom in editor mode, and put "ChangeZDepth("Event Actor", 1); in its creatactor to bring it to the top for gameplay.

filed region>mousebuttondown>
int i=round(xmouse/32);
int j=round(ymouse/32);
ccell=i+(j*20);
now we've found the cell clicked on , and can do anything from there.
Lets say you dropped a unit on a cell, you can set the cell values from that unit, or simply link the cell to the unit;

Each unit has an id(you can use cloneindex for instance).

so you can say cell[i]=unit.cloneindex; (though cloneindex isn't great because it can't reset. Next post, i'll show how to find unused array cells).

then refer to the cell
health[cid]-=damage[ccell]; etc. etc. and work off the cell values.//cid stands for current id....(selected actor).


or you can refer it, cell[ccell]=unit[id];

now at any time, lets say you dropped spike traps on a cell, we can ask for the unit id contained in that cell, then take damage[cell[id]]; where id would be the name of the spikes.

this would return the value of the damage array corresponding to the unit id that was found in the cell.

you can also use the ccell calculation for an object to know its cell value.
actor>event
int i=round(x/32);
int j=round(x/32);
mycell=i+(j*20);

and use that to calculate nearby cells, if its facing an enemy, it can ask for the enemy's cell number, and calculate distances, angles, etc. off that.



you can also precalculate the xy values of cells, at game startup, to avoid having to recalculate them.
int i;
int j;
int k;
for(i=0; i<300; i++){
cellx[i]=(j*32)+16; //assign x value for cell
//the +16 offsets to the center of the cell(very useful).

j++; //increment j, this is the x reference.

if(j>19){ //if j has reached the edge of the screen
j=0; //j returns to 0
k++; //increment k, this is the y reference.
}

celly[i]=(k*32)+16; //assign y value for cell

} //end loop


Now at any time, i can refer to cellx[ccell] or celly[ccell] for any calculations i need.

I stored the variable 'cid' on click, in the referncing method, cid would be set to the cell[ccell]] value, and not changed till we click on another cell, such as to highlight an actor, then pick another actor to attack.
It's easier to be clever than it is to be kind.
http://www.lostsynapse.com
http://www.dstgames.com
User avatar
DST
 
Posts: 1117
Joined: Sun Apr 15, 2007 5:36 pm
Location: 20 minutes into the future
Score: 151 Give a positive score

Re: controlling screen cells (strategy, puzzle)

Postby DST » Wed Feb 25, 2009 4:04 am

So cloneindex does not reset until all the clones are destroyed. You can use your own id instead.

id - actor variable
enemyid[] - integer array, stores id for bad guys
allyid[] - integer array, stores id for good guys

on good guy actor>createactor>
Code: Select all
int i;
for(i=0; i<(size of array); i++){ //replace (size of array) with the actual array size.
if(allyid[i]==0){                         //empty cell found
id=i;                                         //use this id
allyid[i]=1;                                  //update array
i=(size of array)+1;                   //exit this loop (loop stops if i>= size of array.
}//end allyid
}//end loop


Now on goodguy>destroy Actor>
allyid[id]=0;

to clean out that array cell for the next actor created.

Thus, if you have 100 actors, and the first 75 of them die, the next one won't be 101 (as it would be with cloneindex),
instead it will find an empty id to use.

now with the id in place, you can use it to fill cell values as described in the previous post.



Note that this thread is completely irrelevant to shooters, platformers, driving games etc. , and is mainly good for RTS/Puzzle games.

Still wish thanx would have finished squareland wars....seemed like a great game.....othello meets industrial warfare....:P
It's easier to be clever than it is to be kind.
http://www.lostsynapse.com
http://www.dstgames.com
User avatar
DST
 
Posts: 1117
Joined: Sun Apr 15, 2007 5:36 pm
Location: 20 minutes into the future
Score: 151 Give a positive score

Re: controlling screen cells (strategy, puzzle)

Postby jimmynewguy » Sat Mar 28, 2009 12:59 pm

i would really like to make a game based off cells, but even after this nice description i still barely understand :(

if i wanted an actor to move to an actor "cells" but move to the cloneindex of the actor based off of ccell why doesn't
Code: Select all
MoveTo("Event Actor", 0.000000, 0.000000, 4.000000, "cells.ccell", "");

work?

ill probably come back for more help later thnx in advanced and for inspiring me :D
Working on a probably too ambitious project! Wild-west-adventure-RPG-shooter-thing.
User avatar
jimmynewguy
 
Posts: 1137
Joined: Sat Mar 31, 2007 6:27 pm
Score: 89 Give a positive score


Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 1 guest