Comunidad Game Maker

Ayuda => Preguntas y respuestas => Mensaje iniciado por: the_blade en Febrero 26, 2014, 09:32:37 PM

Título: Puzzle - Ayuda - como hago para que esto funcione
Publicado por: the_blade en Febrero 26, 2014, 09:32:37 PM
Hola amigos estoy nuevamente con una duda respecto a mi juego de puzzle tengo el siguiente codigo en el evento create de un objeto (control del puzzle):
win=0
offsetx=10
offsety=196
back=background0

//Specify how many pieces across the puzzle will be
size = 3;

//Find the dimensions of the pieces
tile = background_get_width(back) div size;

//Create a grid structure to hold the solution
solve = ds_grid_create(size,size);

//Create a grid structure to hold the board
board = ds_grid_create(size,size);

xinit=offsetx
yinit=offsety
xlast=0
ylast=0

//Create the pieces and add them to the list
for(i=0; i<sqr(size); i+=1)
{
    temp = instance_create(tile * (i mod size)+offsetx, tile * (i div size)+offsety,tileblock)
    if temp.x>xlast {xlast=temp.x}
    if temp.y>ylast {ylast=temp.y}
    temp.cn=size
    temp.size=tile
    temp.xc=i mod size
    temp.yc=i div size
    temp.image_xscale=tile
    temp.image_yscale=tile
    temp.back=back
    ds_grid_add(solve, i mod size, i div size, temp);
    ds_grid_add(board, i mod size, i div size, temp);
}

with(tileblock)
{
xinit=other.xinit
yinit=other.yinit
xlast=other.xlast
ylast=other.ylast
}

//Remove one corner piece from the puzzle
var xx, yy;
xx = choose(0,size-1);
yy = choose(0,size-1);
with (instance_nearest(xx*tile+offsetx,yy*tile+offsety,tileblock)) {instance_destroy()}
ds_grid_set(solve, xx, yy, -1);
ds_grid_set(board, xx, yy, -1);

//Shuffle the pieces
ds_grid_shuffle(board);

//Shuffle the pieces on the board
for(yy=0; yy<size; yy+=1)
for(xx=0; xx<size; xx+=1)
if ds_grid_get(board,xx,yy)
{
    (ds_grid_get(board,xx,yy)).x = tile*xx+offsetx;
    (ds_grid_get(board,xx,yy)).y = tile*yy+offsety;
}
   


alguien me podria decir que parte del mismo tengo que modificar para que el cuadrado negro osea la instancia borrada siempre sea la de la esquina inferior derecha, y digo esto porque osea si modifico la siguiente parte del codigo:

//Remove one corner piece from the puzzle
var xx, yy;
xx = choose(0,size-1);
yy = choose(0,size-1);
with (instance_nearest(xx*tile+offsetx,yy*tile+offsety,tileblock)) {instance_destroy()}
ds_grid_set(solve, xx, yy, -1);
ds_grid_set(board, xx, yy, -1);


lo consigo pero en la porcion de codigo de mas abajo me lo vuelve a mover, no se si me explico el bloque negro, instancia que se borra siempre debe quedar fija en la posicion inferior derecha y las demas piezas si deben moverse aleatoriamente al inicio del juego pero sin mover a esta.-
adjunto el editable por si alguien prefiere modificarlo de ahy y verificar si funciona, desde ya mil gracias.-