Site Logo


Checkpoint - Tasking

Tasking style

#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["My First Danmakufu Script!"]
#Text["Code by Sparen[r]My First Bullet!"]
#BGM["./necrofantasia.ogg"]

#include "script/default_system/Default_ShotConst.txt"

let objBoss;
let objScene=GetEnemyBossSceneObjectID();

@Event{
    alternative(GetEventType())
    case(EV_REQUEST_LIFE){
        SetScriptResult(500);
    }
    case(EV_REQUEST_TIMER){
        SetScriptResult(60);
    }
    case(EV_REQUEST_SPELL_SCORE){
        SetScriptResult(1000000);
    }
}

@Initialize{
    objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
    ObjEnemy_Regist(objBoss);
    ObjMove_SetDestAtFrame(objBoss, GetCenterX, 60, 60);

    ObjEnemyBossScene_StartSpell(objScene);

    TDrawLoop;
    TFinalize;
    MainTask;
}

@MainLoop{
    ObjEnemy_SetIntersectionCircleToShot(objBoss, ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 32); 
    ObjEnemy_SetIntersectionCircleToPlayer(objBoss, ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 24);
    yield;
}

task MainTask{
    wait(120);
    movement;
    while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){
        let angleT = GetAngleToPlayer(objBoss);
        CreateShotA1(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 2, angleT, DS_BALL_S_RED, 5);
        wait(30);
    }
}

task movement{
    while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){
        ObjMove_SetDestAtFrame(objBoss, rand(GetCenterX + 90, GetCenterX - 90), rand(GetCenterY - 60, GetCenterY - 120), 60);
        wait(240);
    }
}

task TDrawLoop {
    let imgExRumia = GetCurrentScriptDirectory() ~ "ExRumia.png";
    ObjPrim_SetTexture(objBoss, imgExRumia);
    ObjSprite2D_SetSourceRect(objBoss, 64, 1, 127, 64);
    ObjSprite2D_SetDestCenter(objBoss);
}

task TFinalize {
    while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){yield;}
    if(ObjEnemyBossScene_GetInfo(objScene, INFO_PLAYER_SHOOTDOWN_COUNT)
            +ObjEnemyBossScene_GetInfo(objScene, INFO_PLAYER_SPELL_COUNT) == 0){
        AddScore(ObjEnemyBossScene_GetInfo(objScene, INFO_SPELL_SCORE));
    }
    Obj_Delete(objBoss);
    DeleteShotAll(TYPE_ALL, TYPE_IMMEDIATE);
    SetAutoDeleteObject(true);
    CloseScript(GetOwnScriptID());
    return;
}

function GetCenterX(){
    return GetStgFrameWidth() / 2;
}
function GetCenterY(){
    return GetStgFrameHeight() / 2;
}

function wait(n){
    loop(n){yield;}
}

Checkpoint - Sparen

Sparen style

#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["My First Danmakufu Script!"]
#Text["Code by Sparen[r]My First Bullet!"]
#BGM["./necrofantasia.ogg"]

#include "script/default_system/Default_ShotConst.txt"

let objBoss;
let objScene=GetEnemyBossSceneObjectID();
let count = -120;

@Event{
    alternative(GetEventType())
    case(EV_REQUEST_LIFE){
        SetScriptResult(500);
    }
    case(EV_REQUEST_TIMER){
        SetScriptResult(60);
    }
    case(EV_REQUEST_SPELL_SCORE){
        SetScriptResult(1000000);
    }
}

@Initialize{
    objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
    ObjEnemy_Regist(objBoss);
    ObjMove_SetDestAtFrame(objBoss, GetCenterX, 60, 60);

    ObjEnemyBossScene_StartSpell(objScene);

    TDrawLoop;
    TFinalize;
}

@MainLoop{
    ObjEnemy_SetIntersectionCircleToShot(objBoss, ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 32); 
    ObjEnemy_SetIntersectionCircleToPlayer(objBoss, ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 24);
    if(count == 0){movement;}

    if(count % 30 == 0 && count >= 0){
        fire;
    }
    count++;
    yield;
}

task fire{
    if(ObjEnemy_GetInfo(objBoss, INFO_LIFE) <= 0){return;}//Default kill to prevent (0,0) spawning
    let angleT = GetAngleToPlayer(objBoss);
    CreateShotA1(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 2, angleT, DS_BALL_S_RED, 5);
}

task movement{
    while(ObjEnemy_GetInfo(objBoss,INFO_LIFE) > 0){
        ObjMove_SetDestAtFrame(objBoss, rand(GetCenterX+90,GetCenterX-90), rand(GetCenterY-60,GetCenterY-120), 60);
        wait(240);
    }
}

task TDrawLoop {
    let imgExRumia = GetCurrentScriptDirectory() ~ "ExRumia.png";
    ObjPrim_SetTexture(objBoss, imgExRumia);
    ObjSprite2D_SetSourceRect(objBoss, 64, 1, 127, 64);
    ObjSprite2D_SetDestCenter(objBoss);
}

task TFinalize {
    while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){yield;}
    if(ObjEnemyBossScene_GetInfo(objScene, INFO_PLAYER_SHOOTDOWN_COUNT)
            +ObjEnemyBossScene_GetInfo(objScene, INFO_PLAYER_SPELL_COUNT) == 0){
        AddScore(ObjEnemyBossScene_GetInfo(objScene, INFO_SPELL_SCORE));
    }
    Obj_Delete(objBoss);
    DeleteShotAll(TYPE_ALL, TYPE_IMMEDIATE);
    SetAutoDeleteObject(true);
    CloseScript(GetOwnScriptID());
    return;
}

function GetCenterX(){
    return GetStgFrameWidth() / 2;
}
function GetCenterY(){
    return GetStgFrameHeight() / 2;
}

function wait(n){
    loop(n){yield;}
}