# Excerpt

Member Since 15 Nov 2011
Offline Last Active May 29 2012 10:27 PM

### "Lighting" issues.

29 November 2011 - 09:36 AM

Here's the issue.

My friend, Mr. Zpace and I are working on a pretty complex line-of-sight system for a top-down, tile-based strategy/RPG. Yes, this is yet another Line-Of-Sight/Field-Of-Vision question, this time to do with drawing circles on a grid with the possibility of those circles overlapping to create an additive lighting effect.

The intended outcome:

> A circle is drawn on a grid around the object which is emitting light. This part I have worked out.
> The circle is filled in with 'light', preferably with a square-shaped gradient getting dimmer as it travels outward. How we thought to do this was to create a grid data structure that has an entry for each tile in the room and a value denoting how 'lit' that tile is. This is what I came up with:

```x0 = x/gridsize;
y0 = y/gridsize;
x1 = x/gridsize;
y1 = y/gridsize;

yy = r;
d = -r;
x2m1 = -1;
for (xx=0; xx<(r/sqrt(2)); xx+=1;)
{
x2m1 += 2;
d += x2m1;
if d >= 0 then
{
yy -= 1;
d -= yy << 1;
}
if x1+xx >= 0 and y1+yy >=0
{
light_line(round(x1+xx),round(y1+yy));
}

if x1-xx >= 0 and y1-yy >=0
{
light_line(round(x1-xx),round(y1-yy));
}

if x1+xx >= 0 and y1-yy >=0
{
light_line(round(x1+xx),round(y1-yy));
}

if x1-xx >= 0 and y1+yy >=0
{
light_line(round(x1-xx),round(y1+yy));
}}

xx = r;
d = -r;
y2m1 = -1;
for (yy=0; yy<(r/sqrt(2)); yy+=1;)
{
y2m1 += 2;
d += y2m1;
if d >= 0 then
{
xx -= 1;
d -= xx << 1;
}
if x1+xx >= 0 and y1+yy >=0
{
light_line(round(x1+xx),round(y1+yy));
}

if x1-xx >= 0 and y1-yy >=0
{
light_line(round(x1-xx),round(y1-yy));
}

if x1+xx >= 0 and y1-yy >=0
{
light_line(round(x1+xx),round(y1-yy));
}

if x1-xx >= 0 and y1+yy >=0
{
light_line(round(x1-xx),round(y1+yy));
}}
}```

(Where "light_line" is a script that draws a line of light to each tile of the circle growing dimmer as it goes out. It works fine - using the same code we're using for line-of-sight.)

Now. This method had 'holes' in it. Not every tile of the circle was filled. Not only that, but some tiles were filled twice, adding light where they shouldn't have. I can perfectly see the reasons for this -- it makes sense. I just can't think of an alternative method. Drawing circles slightly smaller as it goes down either leaves holes (decreasing 'r' by one every loop) or looks asymmetrical (decreasing by less than one every loop and then rounding off the results).

Again, the reasons for this make sense. I just can't come up with an alternative. Any ideas?

### Speeding up a complicated draw routine

23 November 2011 - 07:01 AM

So, I've been working on a grid-based field-of-vision/line-of-sight system for a turn-based/strategy RPG. It takes into account multiple light sources and a few other cool features, but there's a bit of a problem. If the room's tile count is more than about 300x300, it slows down massively.

I think I know why, too. First of all, I have an array that contains an entry for every tile (not every x,y coordinate -- each 32x32 tile) which is marked as either true or false; or, conventionally, 'lit' or 'unlit'. I then have this script in the draw event:

```for (i=0; i <room_width/gridsize; i+=1)
{
for (f=0; f <room_height/gridsize; f+=1)
{
if i*gridsize > view_xview
if i*gridsize < view_wview
if f*gridsize > view_yview
if f*gridsize < view_hview
if player_can_see(i*gridsize,f*gridsize)=false
or
global.is_lit[i,f]=false
draw_sprite(spr_fog,image_index,i*gridsize,f*gridsize)
}
}```

Where 'player_can_see(a,' is the Bresenham's Line Algorithm (for line of sight), gridsize is a constant (32) and "is_lit" is my global array. The purpose of the script is to draw a sprite 'spr_fog' under the conditions:

- It is inside the view, and
- It is either not in the player's line of sight, and/or
- It is on an 'unlit' tile.

Is there any way I can achieve this same effect without bucket-tons of lag? Appreciation points in advance. ^.^

### Editor failing to update game.

17 November 2011 - 02:37 PM

Just thought I'd see if anyone's having this same problem (and to help anyone who's wondering why a problem won't disappear when it really should).

So, I'm working away at an issue. I edit, run game, it's still there. I tweak, run game, it's still there. I turn my entire code upside down (on a backup save, thankfully), it's still there.

Still. There.

Then, of course, I close Game Maker, open it again, and the problem's gone. Basically, it seems like the editor wasn't updating the game even though I was updating the code. I realise that this might be a common thing, because, you know, it's happened to me twice this evening. It's not too big of an issue, really (just need to check if it's happening whenever problems persist conspicuously). I just thought it was interesting.

### A 'fake' ini file?

17 November 2011 - 04:40 AM

Ok, so let's say that in my hypothetical RPG, I have a master table of every default item in the game. This list may very well exceed one, two or even three-hundred. Not even thinking of the time it's going to take to write out descriptions for all these items, it's going to be an unprecedented headache reorganising it if it looks like this:

```global.item[0,0]=0
global.item[0,1]="Infinity Herb"
global.item[0,2]="Yellow Herb"
global.item[0,3]="Upon very close examination of the herb's sheen and hue, you can verify with satisfaction that it is, indeed, yellow."
global.item[0,4]="This herb, despite its common appearance, has the ability to distort the senses into seeing, hearing and feeling all. Effectively, allows the consumer to perceive a far greater amount of information than simple eyesight."
global.item[0,5]=false
global.item[0,6]=0
global.item[0,7]=0
global.item[0,8]=2
global.item[0,9]=0
global.item[0,11]=0
```

And that's not even a quarter of the eventual number of properties each item is going to have.

So, I can throw this data into an INI file to make the process far easier on me... but then any old player is going to be able to tamper with the precious contents and give themself, say, a sword with over 9,000 strength. What I need, I guess, is an easy way to tabulate this stuff in-project in such a way that I can reorganise it later without renaming a quarter-million stack of array indices.

The solution's probably really simple, I just can't think of one. Any tips? ^.^

### Arrays and Inventories.

15 November 2011 - 06:52 AM

Hey, first post.

To business then. Probably a few of you guys know what a "roguelike" dungeon crawler is. Well, I'm trying to recreate the inventory system from one of those games. I think I've got a handle on the theory of it, I'm just having some issues with the execution.

Here's my method:

I have three types of arrays. First, I have the 'item' array. It's a global 2D array, and it sets the definitions, attributes, etc., of every item in the game. It's used when an item is first created, and it's also used to check whether or not the item's function is known by the player character.

Secondly, there's the 'instance' array, which is a local, 1D array that each physical instance of an item has, specifying how it differs from the stock 'item'. As an example;

The 'item' table specifies that item ID "1" 'looks' like a Pinewood Staff, is actually a Staff of Menace, is not known by the player and has a maximum of ten uses.
The 'instance' table specifies that this particular Pinewood Staff is cursed, has six uses remaining and has been tentatively labelled "Useless?" by the player. However, the player does not know that the staff is cursed, nor that it has six uses remaining.

Then there's the inventory array. It's a local, 2D array that details everything the character or an NPC/Enemy owns.

Now, what I need to happen (but am having a little trouble with executing) is this: no matter what, the 'instance' array needs to transition in and out of the 'inventory' arrays seamlessly, because item manipulation is going to be happening a lot... and making sure the individual aspects of each item don't change in this process is very necessary. Let's say I drop the item. I need it to create an instance of obj_item whose 'instance' array is identical to the inventory slot it came out of. Then let's say I pick it back up again. Considering the 1D instance array as a 'column', Is there a fast way of transcribing the 'instance' column onto a free 'inventory' column (without, of course, individually setting each slot) and vice versa?

Any advice would be appreciated. ^.^