[GMS]Match3 Gamemaker studio 따라하기 (candy crush) Part6~8
Part6
보석이 없어지면 위에서 부터 새로운 보석이 생성되는 코드 입니다. 또한 선택되었을때 선택 박스를 보이게 합니다
Sprites->name:sp_creator:60*60 이미지
oGG::sprite:sp_creator
Control::create
globalvar F1,F2,F1x,F1y,F2x,F2y;
F1=0;
F2=0;
F1x=0;
F1y=0;
F2x=0;
F2y=0;
Xs = 116;
Ys = 166-68;
scr0();
Script::scr0
for(i=0;i<7;i++){
for(j=0;j<8;j++){
instance_create(Xs+i*68,Ys+j*68,ogems);
}
}
for(i=0;i<7;i++){
instance_create(Xs+i*68,Ys,oGG);
}
oGG::step
if !place_meeting(x,y+4,ogems)
{
instance_create(x,y,ogems);
}
oGG::visible=false
ogems::depth = 0
Control::depth = -50
Control::draw
draw_background_part(bag0,0,0,640,132,0,0);
Sprites->name:sp_select:68*68 이미지
ogems::draw
draw_self();
if(F1=id)and(F2=0)
draw_sprite(sp_select,0,x,y);
Part7
보석이 터지는 효과와 점수를 구현합니다.
Sprite::sp_puff 68*68*10장 폭발 장면 애니메이션
object::opuff
opuff::Create
a=0;
f=1;
alarm[0]=1;
co=0;
switch(co)
{
case 0:
c1=make_colour_rgb(99,254,123);
c2=make_colour_rgb(0,138,42);
break;
case 1:
c1=make_colour_rgb(107,107,221);
c2=make_colour_rgb(33,41,82);
break;
case 2:
c1=make_colour_rgb(254,230,1);
c2=make_colour_rgb(187,163,1);
break;
case 3:
c1=make_colour_rgb(254,205,107);
c2=make_colour_rgb(180,24,1);
break;
case 4:
c1=make_colour_rgb(164,164,164);
c2=make_colour_rgb(33,3,33);
break;
case 5:
c1=make_colour_rgb(221,234,254);
c2=make_colour_rgb(66,82,147);
break;
}
opuff::alarm[0]
switch(co)
{
case 0:
c1=make_colour_rgb(99,254,123);
c2=make_colour_rgb(0,138,42);
break;
case 1:
c1=make_colour_rgb(107,107,221);
c2=make_colour_rgb(33,41,82);
break;
case 2:
c1=make_colour_rgb(254,230,1);
c2=make_colour_rgb(187,163,1);
break;
case 3:
c1=make_colour_rgb(254,205,107);
c2=make_colour_rgb(180,24,1);
break;
case 4:
c1=make_colour_rgb(164,164,164);
c2=make_colour_rgb(33,3,33);
break;
case 5:
c1=make_colour_rgb(221,234,254);
c2=make_colour_rgb(66,82,147);
break;
}
opuff::draw
if(a<10)
draw_sprite(sp_puff,a,x,y);
a+=1;
f-=0.03;
draw_set_halign(fa_center);
draw_set_valign(fa_middle);
draw_set_font(font);
draw_text_colour(x+1,(y+1)-a,60,c2,c2,c2,c2,f);
draw_text_colour(x,(y)-a,60,c1,c1,c1,c1,f);
if(a>60)
instance_destroy();
ogems::destory
op=instance_create(x,y,opuff);
op.co=image_index;
fonts->font: size 30, Bold, Italic, Digit,
opuff::depth=-2;
Control::depth=-1;
Part8
전체적으로 수치적으로 나타낸 부분을 변수로 정리하였습니다.
가장 핵심이 되는 부분은 Cs=68 이 4의 배수가 되어야 한다는 점입니다. 이유는 물리 이동시 아래쪽으로 +4만큼 이동을 하는데 배수가 되지 않으면 해당 위치까지 가지 않는 문제가 발생합니다. 변경하려면 그것까지 고려가 되어야 합니다.
Control::create
globalvar F1,F2,F1x,F1y,F2x,F2y,Xs,Ys,Cs,clw,clh;
Cs=68;
clw=7
clh=7
F1=0;
F2=0;
F1x=0;
F1y=0;
F2x=0;
F2y=0;
Xs = 116;
Ys = 166;
scr0();
Script::scr0
for(i=0;i<clw;i++){
for(j=0;j<clh;j++){
instance_create(Xs+i*Cs,Ys+j*Cs,ogems);
}
}
for(i=0;i<clw;i++){
instance_create(Xs+i*Cs,Ys-Cs,oGG);
}
script::scr2();
match=0;
mxw=(Xs+((clh-3)*Cs))+1;
mxh=(Ys+((clh-3)*Cs))+1;
mnh=Ys-1;
if (x<mxw) and (y>mnh)
if (!position_empty(x+Cs,y)) and (!position_empty(x+(Cs*2),y))
{
var N1,N2;
N1=instance_position(x+Cs,y,ogems);
N2=instance_position(x+(Cs*2),y,ogems);
if (N1.stable==true and N2.stable==true)
{
if(N1.image_index==image_index) and (N2.image_index==image_index)
{
match=1;
}
}
}
if (y<mxh) and (y>mnh)
if (!position_empty(x,y+Cs)) and (!position_empty(x,y+(Cs*2)))
{
var N3,N4;
N3=instance_position(x,y+Cs,ogems);
N4=instance_position(x,y+(Cs*2),ogems);
if (N3.stable==true and N4.stable==true)
{
if(N3.image_index==image_index) and (N4.image_index==image_index)
{
match=2;
}
}
}
switch(match)
{
case 1:
with(N1)
alarm[1]=1;
with(N2)
alarm[1]=1;
alarm[1]=1;
with(F1)
{
x=F2x;
y=F2y;
}
with(F2)
{
x=F1x;
y=F1y;
}
F1=0;
F2=0;
with(all)
{
off=false;
onhold=false;
nomatch=false;
}
match=0;
break;
case 2:
with(N3)
alarm[1]=1;
with(N4)
alarm[1]=1;
alarm[1]=1;
with(F1)
{
x=F2x;
y=F2y;
}
with(F2)
{
x=F1x;
y=F1y;
}
F1=0;
F2=0;
with(all)
{
off=false;
onhold=false;
nomatch=false;
}
match=0;
break;
default:
if(F1=id)
{F2.nomatch=true;}
if(F2=id)
{F1.nomatch=true;}
}
ogems::Alarm[0]
off=false;
mxw=(Xs+((clh-3)*Cs))+1;
mxh=(Ys+((clh-3)*Cs))+1;
mnh=Ys-1;
if (x<mxw) and (y>mnh)
if (!position_empty(x+Cs,y)) and (!position_empty(x+(Cs*2),y))
{
var N1,N2;
N1=instance_position(x+Cs,y,ogems);
N2=instance_position(x+(Cs*2),y,ogems);
if (N1.stable==true and N2.stable==true)
{
if(N1.image_index==image_index) and (N2.image_index==image_index)
{
match=1;
}
}
}
if (y<mxh) and (y>mnh)
if (!position_empty(x,y+Cs)) and (!position_empty(x,y+(Cs*2)))
{
var N3,N4;
N3=instance_position(x,y+Cs,ogems);
N4=instance_position(x,y+(Cs*2),ogems);
if (N3.stable==true and N4.stable==true)
{
if(N3.image_index==image_index) and (N4.image_index==image_index)
{
match=2;
}
}
}
switch(match)
{
case 1:
with(N1)
alarm[1]=1;
with(N2)
alarm[1]=1;
alarm[1]=1;
match=0;
break;
case 2:
with(N3)
alarm[1]=1;
with(N4)
alarm[1]=1;
alarm[1]=1;
match=0;
break;
}
ogems::Create
image_index = irandom(5);
image_speed = 0;
off=false;
stable=false;
onhold=false;
match=0;
nomatch=false;
Ye=Ys+(clh*Cs)-Cs;
if (off)
exit;
if (!onhold)
{
if place_free(x,y+12) and (y<Ye)
{
y+=4;
stable=false;
}else{
stable=true;
off=true;
alarm[0]=5;
}
}else{
if(!nomatch)
{
if(F1=id)
{
if((x<F2x)and(y=F2y))
{x+=4}else
if((x>F2x)and(y=F2y))
{x-=4};
if((x=F2x)and(y<F2y))
{y+=4}else
if((x=F2x)and(y>F2y))
{y-=4};
if((x==F2x)and(y==F2y))
{
with(all)
scr2();
exit;
}
}
if(F2=id)
{
if((x<F1x)and(y=F1y))
{x+=4}else
if((x>F1x)and(y=F1y))
{x-=4};
if((x=F1x)and(y<F1y))
{y+=4}else
if((x=F1x)and(y>F1y))
{y-=4};
if((x==F1x)and(y==F1y))
{
with(all)
scr2();
exit;
}
}
}else{
if(F2=id)
{
if((x<F2x)and(y=F2y))
{x+=4}else
if((x>F2x)and(y=F2y))
{x-=4};
if((x=F2x)and(y<F2y))
{y+=4}else
if((x=F2x)and(y>F2y))
{y-=4};
if((x==F2x)and(y==F2y))
{
onhold=false;
nomatch=false;
F2=0;
exit;
}
}
if(F1=id)
{
if((x<F1x)and(y=F1y))
{x+=4}else
if((x>F1x)and(y=F1y))
{x-=4};
if((x=F1x)and(y<F1y))
{y+=4}else
if((x=F1x)and(y>F1y))
{y-=4};
if((x==F1x)and(y==F1y))
{
onhold=false;
nomatch=false;
F1=0;
exit;
}
}
}
}
ogems::mouse_left_press
if(F2=0) and (stable) and (y>(Ys-1))
if(F1=0)
{
scr1();
}else
{
if(F1!=id)and((x=F1x+Cs and y=F1y)or(x=F1x-Cs and y=F1y)or(x=F1x and y=F1y+Cs)or(x=F1x and y=F1y-Cs))
{
F2=id;
F2x=x;
F2y=y;
with(all)
onhold=true;
}else{scr1();}
}
댓글 없음:
댓글 쓰기