public void SetOwner(Ent2D parent, bool fromShip) { this.fromShip = fromShip; this.parent = parent; if (this.fromShip) { this.sr.flipY = true; } }
public void OnSpawn() { float spawnX = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width / 2.0f, 0.0f, 0.0f)).x; float spawnY = transform.position.y; GameObject go = Ent2D.Create2DGameObject(spawner, spawnX, spawnY); go.name = "player"; player = go.GetComponent <Player> (); player.Init(); }
public static Bomb CreateBomb(GameObject bomb, Ent2D owner, float dropY, float upBoundY, float downBoundY, bool bomFlip = true) { GameObject go = Create2DGameObject(bomb, owner.transform.position.x, owner.transform.position.y + dropY); Bomb b = go.GetComponent <Bomb>(); b.Init(); b.SetOwner(owner, bomFlip); b.SetUpBoundY(upBoundY); b.SetDownBoundY(downBoundY); owner.shootable = false; owner.isShooting = true; return(b); }
//driving index by an array for example // void Start(){ // Init (); // } public override void EntUpdate() { //Debug.Log("base shootable=" + base.shootable); //Debug.Log("alien Shootable:" + this.shootable); if (shootable && !isShooting) { //Debug.Log("Create bomb"); Ent2D.CreateBomb(child, this, -DIST_Y, UP_BOUND_Y /*7.79f*/, DOWN_BOUND_Y /*-7.79f*/, false); } if (startMoving && !MoveIndex(index)) { index = (index + 1) % 2; } }
//testing movement // void Start(){ // Init(transform.position.x, transform.position.x + diameterX, transform.position.y + diameterY/2.0f, transform.position.y - diameterY/2.0f); // if (dev) { // CreateCirc (new Vector3 (transform.position.x, transform.position.y, transform.position.z), Color.green); //lbx // CreateCirc (new Vector3 (transform.position.x + diameterX, transform.position.y, transform.position.z), Color.green); //rbx // CreateCirc (new Vector3 (transform.position.x + diameterX/2.0f, transform.position.y + diameterY/2.0f, transform.position.z), Color.green); //uby // CreateCirc (new Vector3 (transform.position.x + diameterX/2.0f, transform.position.y - diameterY/2.0f, transform.position.z), Color.green); //dby // } // } public override void EntUpdate() { if (shootable) { //Debug.Log("Create bomb"); Ent2D.CreateBomb(child, this, -DIST_Y, 7.79f, -7.79f, false); } if (startMoving && !MoveIndex(index)) { if (index >= indexSize) { return; } index = (index + 1) % indexSize; } }
// Update is called once per frame public override void EntUpdate() { if (isZombie) { return; } //not dead //Debug.Log ("width left:" + Camera.main.ScreenToWorldPoint (new Vector3 (-Screen.width, 0.0f, 0.0f)).x); if (Input.GetMouseButtonDown(0) && transform.position.x < ScreenX()) { moveRightWrapper(); } else if (Input.GetMouseButtonDown(0) && transform.position.x > ScreenX()) { moveLeftWrapper(); } if (Input.GetKeyDown(KeyCode.RightArrow)) { moveRightWrapper(); } if (Input.GetKeyDown(KeyCode.LeftArrow)) { moveLeftWrapper(); } if (Input.GetKeyDown(KeyCode.D)) { TakeDamageEvent.Invoke(); //die } if (/*Input.GetKeyDown (KeyCode.Space) &&*/ !isShooting && shootable) //autofire { Ent2D.CreateBomb(child, this, DIST_Y, UP_BOUND_Y, -DOWN_BOUND_Y); } }
void OnTriggerEnter2D(Collider2D other) { //Debug.Log ("collided with:" + other.name); //check colliding with another bomb Bomb otherBomb = other.GetComponent <Bomb>(); if (otherBomb) { //Debug.Log ("collided with otherBomb"); OnDie(other); otherBomb.OnDie(null); return; } Ent2D otherEnt = other.GetComponent <Ent2D> (); if (otherEnt && otherEnt != parent && !otherEnt.isZombie) { //destroy the bomb Debug.Log("collided with ent: " + otherEnt.name); otherEnt.OnDie(other); OnDie(other); } }