script_enemy_main{
let count = 0; let angle = 0; let angle2 = 180; let bullet = GetCurrentScriptDirectory~"bullet.wav";
let ZUNbullet = GetCurrentScriptDirectory~"supershot.txt"; let yrm = GetCurrentScriptDirectory~"yrm.png";
let vanishtime = 1200;
let item = 0;
//let Xmin = 0; let Xmax = 448; let Ymin = 0; let Ymax = 480;
//Made Jan 21, 2013
@Initialize{LoadGraphic(yrm); LoadUserShotData(ZUNbullet); SetLife(500); LoadSE(bullet);}
@MainLoop{
SetCollisionA(GetX, GetY, 32); SetCollisionB(GetX, GetY, 24);
SetMovePosition02(GetArgument, GetCenterY, 150); //150 frames.
if(count > 150 && count % 60 == 0){loop(6){
CreateShot02(GetX, GetY, 1, angle, 0.05, 3, 34, 2); angle += 60;}PlaySE(bullet);
}
angle += 3; angle2 -= 3;
if(count % 9 == 0){CreateShot01(GetX, GetY, 0.5, angle, 12, 2); CreateShot01(GetX, GetY, 0.5, angle2, 13, 2);}
if(count == 450){SetMovePosition02(GetArgument, GetCenterY - 60, 150);}
//if(GetX < Xmin || GetX > Xmax || GetY < Ymin || GetY > Ymax){
// item = 1;
// VanishEnemy;
//}
if(vanishtime == 0) {item = 1; VanishEnemy;}else{vanishtime--;}
count++;
yield;
}
@DrawLoop{
SetTexture(yrm); SetGraphicRect(0, 0, 65, 62); //Add one pixel to height and width
SetAlpha(250); SetGraphicAngle(0, 0, 0);
SetGraphicScale(1, 1); DrawGraphic(GetX,GetY);
}
@Finalize{
if(item==0){loop(5){CreateItem(ITEM_SCORE, GetX + rand(-15,15), GetY + rand(-15,15));}}}}
This is the code for the fourth stage enemy in Danmaku Dodging for Dummies. (collapsed)
Now, I shall explain.
let vanishtime = 1200;
let item = 0;
//let Xmin = 0; let Xmax = 448; let Ymin = 0; let Ymax = 480;
//if(GetX < Xmin || GetX > Xmax || GetY < Ymin || GetY > Ymax){
// item = 1;
// VanishEnemy;
//}
if(vanishtime == 0) {item = 1; VanishEnemy;}else{vanishtime--;}
Vanishtime is a variable I use for the obvious purpose of vanishing. When a timer hits 0, the enemy dies.
Item is a variable I use to test if the enemy will drop an item or not.
Then, comes the main one that YOU SHOULD BE USING if your enemies are supposed to die upon leaving the screen.
let Xmin = 0; let Xmax = 448; let Ymin = 0; let Ymax = 480;
The above code states the boundaries of the Danmakufu window. You can also opt to replace this with GetClipM(in/ax)(X/Y). The code deletes enemies after they pass a certain distance out of the screen.
Understand a bit better?