用途別リファレンス

オブジェクトに連続でぶつからないようにする

プレイヤーが敵に当たったときに,一定時間無敵になって連続で敵に当たらないようにします.

Main

new Enemy{x=rnd($screenWidth),y=rnd($screenHeight),p=8};
new Enemy{x=rnd($screenWidth),y=rnd($screenHeight),p=8};
new Enemy{x=rnd($screenWidth),y=rnd($screenHeight),p=8};
new Player{x=$screenWidth/2,y=$screenHeight/2};

Player

c=0;//c>0なら無敵,c==0なら無敵でない
life=5;
while(true){
    x=$mouseX;
    y=$mouseY;
    if(crashTo(Enemy) && c<=0){
        // 無敵でない場合のみ,ここが実行される
        c=30;//無敵時間を30フレーム(1秒)に設定
        // 体力を減らす
        life--;
        print("Life",life);
        if (life<=0) die();
    }
    //無敵中であれば無敵時間を減らす
    if (c>0) c--;
    //無敵中に点滅させる処理
    if (c%2==0) alpha=255; else alpha=0;
    update();
}

Enemy

//何も書かなくてもよいが,ファイルEnemyは作成する

ライブデモ