{"size": 1451, "ext": "js", "max_stars_repo_path": "src/js/View/Enemy.js", "max_stars_repo_name": "youtakanke/mvc_learning_sample_shooting", "max_stars_repo_stars_event_min_datetime": "2020-04-17T06:24:50.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-17T06:24:50.000Z", "max_issues_repo_path": "src/js/View/Enemy.js", "max_issues_repo_name": "youtakanke/mvc_learning_sapmle_shooting", "max_issues_repo_issues_event_min_datetime": "2020-08-05T09:44:39.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-27T03:59:26.000Z", "max_forks_repo_path": "src/js/View/Enemy.js", "max_forks_repo_name": "peg0129/mvc_learning_sample_shooting", "max_forks_repo_forks_event_min_datetime": "2020-05-03T09:50:35.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-04T12:05:17.000Z"}
{"max_stars_count": 1, "max_issues_count": 5, "max_forks_count": 8, "avg_line_length": 25.4561403509, "max_line_length": 98, "alphanum_fraction": 0.5265334252}
import UnitBase from "./UnitBase";
import Bullet from "./Bullet";
import HitTest from "../Util/HitTest";

/**
 * 敵のBaseクラス。
 * 新規の敵を作る場合はこのクラスを継承してください。
 */
export default class Enemy extends UnitBase {
    constructor () {
        super ();
        this.x = 400;
        this.y = 200;
        this.scale = 20;
        this.width = this.scale;
        this.height = this.scale;
        this.setHP(5);
        this.crashScore = 10;
        setInterval(() => {
            // 一定間隔で弾を発射
            const bullet = new Bullet (this.x - 10, this.y);
            bullet.setSpeed(-4);
        }, 400)
    }
    /**
     * EnterFrame.jsの中で
     * requestAnimationFrameから自動的にcallされ続けます。
     */
    update (){
        // 動きはoverrideして下さい。↓のサンプルは上下運動
        this.deg = this.deg || 0;
        this.y = Math.cos(this.deg * (Math.PI / 180)) * 3 + this.y;
        this.deg++;

        const bullet = HitTest.getHitObjectByClassName (this, "Bullet");
        if (bullet) {
            // 弾にあたったらダメージを与え、EnemyManagerに通知して下さい。
            // bullet.damage
        }
    }
    /**
     * 描画
     * @param {context} context 
     */
    draw (context) {
        context.beginPath () ;

        context.arc( this.x, this.y, this.scale, 0 * Math.PI / 180, 360 * Math.PI / 180, false ) ;
        context.fillStyle = "rgba(255,0,0,0.8)" ;
        context.fill() ;

        context.strokeStyle = "purple" ;
        context.lineWidth = 8 ;
        context.stroke() ;
    }
}
