• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker Area of effect inconsistant

D

Dawn DeerButt

Guest
I've been working on a roguelike and im currently making a spells and ability menu. Been trying to get spell area of effects to work and they mostly work but they seem to have a down/right bias, pictures included to better explain what i mean.


The code im currently using is this:
Code:
if ZapSelect != noone
{
    //debug spellrange
    var spellrange = 5;
    var spellpath = path_add()
    var PX = PlayerObj.x div CELL_WIDTH, PY = PlayerObj.y div CELL_HEIGHT;
    for(var i = PX-spellrange; i < PX+spellrange; i += 1)
    {
        for(var j = PY-spellrange; j < PY+spellrange; j += 1)
        {
            if mp_grid_path(LevelGen.mpgrid,spellpath,(PX*CELL_WIDTH),
                                                      (PY*CELL_HEIGHT),
                                                      (i*CELL_WIDTH),
                                                      (j*CELL_HEIGHT),
                                                       true)
            {
                if path_get_length(spellpath) < spellrange*CELL_WIDTH
                {
                    var dslist = ds_list_create(), dslistlength;
                    //add topleft corner of line of sight
                    dslistlength = collision_line_list((PX*CELL_WIDTH)+(CELL_WIDTH/2),(PY*CELL_HEIGHT)+(CELL_HEIGHT/2),
                                                        (i*CELL_WIDTH)+(CELL_WIDTH/2),(j*CELL_HEIGHT)+(CELL_HEIGHT/2),
                                                        EnemyObj, true, true, dslist, true);
                    if !collision_line((PX*CELL_WIDTH)+(CELL_WIDTH/2),(PY*CELL_HEIGHT)+(CELL_HEIGHT/2),
                                                        (i*CELL_WIDTH)+(CELL_WIDTH/2),(j*CELL_HEIGHT)+(CELL_HEIGHT/2),
                                                        WallObj, true, true)
                    {
                        if !collision_line((PX*CELL_WIDTH)+(CELL_WIDTH/2),(PY*CELL_HEIGHT)+(CELL_HEIGHT/2),
                                            (i*CELL_WIDTH)+(CELL_WIDTH/2),(j*CELL_HEIGHT)+(CELL_HEIGHT/2),
                                            EnemyObj, true, true)
                        {
                            targarray[# i, j] = 1;
                        }
                        else if dslist[| 0] != undefined
                        {
                            var ID = dslist[| 0];
                            var IX = ID.x div CELL_WIDTH, IY = ID.y div CELL_HEIGHT;
                            targarray[# IX, IY] = 1;
                        }
                    }
                    ds_list_destroy(dslist);
                }
            }
        }
    }
    for(var i = 0; i < PX+spellrange; ++i)
    {
        for(var j = 0; j < PY+spellrange; ++j)
        {
            if targarray[# i, j] == 1
            {
                draw_set_colour(c_red);
                draw_set_alpha(0.3);
                draw_rectangle(i*CELL_WIDTH, j*CELL_HEIGHT, (i*CELL_WIDTH)+CELL_WIDTH, (j*CELL_HEIGHT)+CELL_HEIGHT, false);
                draw_set_colour(c_white);
                draw_set_alpha(1);
            }
        }
    }
    path_delete(spellpath);
}
 
Top