#TouhouDanmakufu #Title[Random Sign uEntropyv] #Text[For demonstrating lists of objects. Warning: very random.] #Player[FREE] #ScriptVersion[2] script_enemy_main { // The counter variable. // In this case, it counts how many frames before the next shot is fired. let count = 90; // The countdown for the boss to move. let move_count = 300; // Stores the file name of the boss's image let character_image = "script\img\ExRumia.png"; // Start with an empty list of object shots let bullets = []; // This array holds the shot types that will be used by the attack. // See the function Get_Random_Shot_Type() for how this is used let bullet_type_array = [RED01, GREEN11, BLUE03, YELLOW21, PURPLE22, AQUA32, ORANGE12, WHITE05]; // Constant values. Modify these to change the behavior of the script let bullet_minimum_speed = 0.5; let bullet_maximum_speed = 4.5; let delay_between_shots = 15; let number_of_shots_fired = 5; // This is multiplied by 0.1% to get the chance, per frame, that each bullet is re-randomized. // 12 means a 1.2% chance per frame. let chance_of_re_randomize = 12; // This function returns one of the shot types listed in bullet_type_array // This works by getting a random integer index into the array (from zero to one less than the total length), and // returning that entry in the array. function Get_Random_Shot_Type() { return bullet_type_array[rand_int(0, length(bullet_type_array)-1)]; } @Initialize { // Typical Initialization stuff. SetScore(800000); CutIn(YOUMU, "Random Sign uEntropyv", 0, 0, 0, 0, 0); SetX(GetCenterX()); SetY(GetClipMinY()-50); LoadGraphic(character_image); SetGraphicRect(64, 1, 127, 64); SetGraphicRect(64, 1, 127, 64); SetMovePosition02(GetCenterX(), 120, 60); SetMovePosition02(GetCenterX(), 120, 60); SetTimer(60); SetLife(700); SetDamageRate(15, 8); SetInvincibility(150); SetShotDirectionType(ABSOLUTE); } @MainLoop { // Continue counting down count--; if (count <= 0) { count = delay_between_shots; ascent (shots in 1 .. number_of_shots_fired) { // Fire off another shot let obj = Obj_Create(OBJ_SHOT); Obj_SetPosition(obj, GetX(), GetY()); Obj_SetSpeed(obj, rand(bullet_minimum_speed, bullet_maximum_speed)); Obj_SetAngle(obj, rand(0, 360)); ObjShot_SetDelay(obj, 10); ObjShot_SetGraphic(obj, Get_Random_Shot_Type()); // Add the new object shot to the list bullets = bullets ~ [obj]; } } // Check if the boss should move. move_count--; if (move_count <= 0) { move_count = 300; SetMovePositionRandom01(100, 60, 2.5, GetClipMinX() + 50, GetClipMinY() + 50, GetClipMaxX() - 50, GetCenterY()); } // Here, we loop through the array of object bullets. // We first check if each one has been deleted, and if so it is removed from the array. // Otherwise, we use a random chance to determine if it should be re-randomized. let i = 0; while (i < length(bullets)) { if (Obj_BeDeleted(bullets[i])) { // The indexed shot has been deleted. Remove it from the list bullets = erase(bullets, i); // The i-- here counters the i++ below. // Since we're deleting the item at index i, the next element to check will // now be at index i. i--; } else { // The object is still active. Based on a random chance, possibly re-randomize it. if (rand(0, 1000) < chance_of_re_randomize) { // The variable obj is used here as a local copy of the object's ID, to save typing. let obj = bullets[i]; Obj_SetSpeed(obj, rand(bullet_minimum_speed, bullet_maximum_speed)); Obj_SetAngle(obj, rand(0, 360)); ObjShot_SetDelay(obj, 10); ObjShot_SetGraphic(obj, Get_Random_Shot_Type()); } } // When you're using this type of code, MAKE SURE that the loop variable is incrememted // properly, or the script will hang!!! i++; } // Set the boss collision radius SetCollisionA(GetX(), GetY(), 32); SetCollisionB(GetX(), GetY(), 24); } @DrawLoop { // Draw the boss. SetTexture("script\img\ExRumia.png"); DrawGraphic(GetX(), GetY()); // As an added bit of info, output the number of objects in the bullet list DrawText(length(bullets), 50, 50, 12, 255); } @Finalize { // Give the player some items let amnt = 10; if (GotSpellCardBonus) { // Give them more if they captured the card amnt = 40; } let i = 0; while (i < amnt) { CreateItem(ITEM_SCORE, GetCenterX() + prand(-100, 100), 100 + prand(-60, 60)); i++; } } }