public Shot(Rectangle boundaries, Parameters.Direction direction, Point location) { this.boundaries = boundaries; this.direction = direction; this.location = location; removeShotFlag = false; }
public void MoveAllInvaders() { bool createNewInvaders = false; Invader maxWidthInvader = new Invader(new Point(boundaries.Left, 0)); Invader minWidthInvader = new Invader(new Point(boundaries.Right), 0); foreach (Invader invader in invaders) { if (invader.Location.X <= minWidthInvader.Location.X) { minWidthInvader = invader; } if (invader.Location.X >= maxWidthInvader.Location.X) { maxWidthInvader = invader; } } foreach (Invader invader in invaders) { if (minWidthInvader.Location.X <= boundaries.Left) { invader.Move(Parameters.Direction.Down, level); invaderDirection = Parameters.Direction.Right; } else if (maxWidthInvader.Location.X + maxWidthInvader.Image.Width >= boundaries.Right) { invader.Move(Parameters.Direction.Down, level); invaderDirection = Parameters.Direction.Left; } if (invader.Location.Y + invader.Image.Height >= boundaries.Bottom) { createNewInvaders = true; break; } else { invader.Move(invaderDirection, level); } } if (createNewInvaders) { ResetInvaders(); GenerateInvaders(); } if (mothership) { mother.Move(Parameters.Direction.Right); if (mother.Location.X >= boundaries.Right || mother.Location.X <= boundaries.Left) { RemoveMothership(); } } }
// constructor of class Game public Game(Rectangle boundaries) { this.boundaries = boundaries; stars = new Stars(boundaries); random = new Random(); initialInvaderDirection = invaderDirection; lives = 0; pause = false; }
public override void Move(Parameters.Direction direction, int level) { if (direction == Parameters.Direction.Left) { location.X -= Parameters.invaderHorziontalIncreament + level / 2; } else if (direction == Parameters.Direction.Right) { location.X += Parameters.invaderHorziontalIncreament + level / 2; } else if (direction == Parameters.Direction.Down) { location.Y += Parameters.invaderVerticalIncreament + level; } }
// method to move playership into positive and negative x and y direction public void MovePlayer(Parameters.Direction direction) { // if conditions to check if ship is out of boundaries if ((playerShip.Location.X < boundaries.Left + Parameters.playerShipIncremeant && direction == Parameters.Direction.Left) || (playerShip.Location.X >= boundaries.Right - Parameters.playerShipIncremeant - playerShip.Image.Width && direction == Parameters.Direction.Right) || (playerShip.Location.Y < boundaries.Top + Parameters.playerShipIncremeant && direction == Parameters.Direction.Up) || (playerShip.Location.Y >= boundaries.Bottom - Parameters.playerShipIncremeant - playerShip.Image.Height && direction == Parameters.Direction.Down)) { return; } playerShip.Move(direction); }
// method to move playership into positive and negative x and y direction public virtual void Move(Parameters.Direction direction) { if (direction == Parameters.Direction.Left) { location.X -= Parameters.playerShipIncremeant; } else if (direction == Parameters.Direction.Right) { location.X += Parameters.playerShipIncremeant; } else if (direction == Parameters.Direction.Up) { location.Y -= Parameters.playerShipIncremeant; } else if (direction == Parameters.Direction.Down) { location.Y += Parameters.playerShipIncremeant; } }
// Update is called once per frame void Update() { this.ActionFsm.Execute(); this.spriteRenderer = this.anim.GetComponent <SpriteRenderer>(); if (invulnTime > 0) { invulnTime -= Time.deltaTime; Debug.Log((int)(invulnTime / (baseInvulnTime * 0.125))); if ((int)(invulnTime / (baseInvulnTime * 0.125)) % 2 == 1) { this.spriteRenderer.color = Color.red; } if ((int)(invulnTime / (baseInvulnTime * 0.125)) % 2 == 0) { this.spriteRenderer.color = Color.white; } this.environmentCollisionBox.gameObject.layer = LayerMask.NameToLayer("Invuln"); this.hitboxManager.deactivateAllHitboxes(); if (invulnTime <= 0) { this.environmentCollisionBox.gameObject.layer = LayerMask.NameToLayer("Player"); this.hitboxManager.activateAllHitboxes(); } } if (inCutscene) { return; } //Animation control stuff Vector2 movementInputVector = Controls.getDirection(); //Controlling where we are aiming this.aim = Parameters.VectorToAim(movementInputVector); if (this.grounded && this.aim == Parameters.Aim.Down) { this.aim = Parameters.Aim.TiltDown; } if (Controls.AimDownInputHeld()) { this.aim = Parameters.Aim.TiltDown; } if (Controls.AimUpInputHeld()) { this.aim = Parameters.Aim.TiltUp; } //Controlling the direction we are facing if (movementInputVector.x != 0 && !lockedDir) { this.direction = Parameters.VectorToDir(movementInputVector); } this.anim.SetFloat("Direction", Parameters.GetDirAnimation(this.direction)); this.anim.SetFloat("Aim", Parameters.GetAimAnimation(this.aim)); //Syncing the anims SyncAnims(); //Shooting controls if (Controls.ShootInputHeld() && activeWeapon != null) { if (isUnderWater) { activeWeapon.Fire(direction, aim); } else { AudioSource.PlayClipAtPoint(audio[0], transform.position); //Do another indicator you can't fire } LockDirection(); } else { activeWeapon.CeaseFire(); if (grounded) { UnlockDirection(); } } //Switching Weapons Controls if (Controls.PrevWeaponInputDown()) { AudioSource.PlayClipAtPoint(audio[1], transform.position); SwitchWeapons(currentWeaponIndex - 1); } if (Controls.NextWeaponInputDown()) { AudioSource.PlayClipAtPoint(audio[1], transform.position); SwitchWeapons(currentWeaponIndex + 1); } //Interacting Controls if (Controls.InteractInputDown() && currentInteractable != null) { currentInteractable.Interact(this); } //Toggle controls (for weights and related things) if (hasWeights && Controls.Toggle1Down()) { if (isWeighted) { AudioSource.PlayClipAtPoint(audio[3], transform.position); } else { AudioSource.PlayClipAtPoint(audio[2], transform.position); } isWeighted = !isWeighted; SetAnimator(); } //Contextual visuals if (currentInteractable != null && !inCutscene) { showControl(PlayerControls.Interact); } else //Try to hide controls if they are visible if (InstructionSprite.gameObject.activeSelf) { hideControl(); } }
public abstract void Move(Parameters.Direction direction, int level);
override public void Fire(Parameters.Direction dir, Parameters.Aim aim) { firing = true; float xRand = Random.Range(-0.1f, 0.1f); float yRand = Random.Range(-0.1f, 0.1f); if (dir == Parameters.Direction.Left) { if (aim == Parameters.Aim.Up) { firePosition = this.transform.position + new Vector3(0, 0.5f, 0) * bombDistance; fireVelocity = new Vector3(xRand, 1, 0) * bombSpeed; } else if (aim == Parameters.Aim.TiltUp) { firePosition = this.transform.position + new Vector3(-0.25f, 0.25f, 0) * bombDistance; fireVelocity = new Vector3(-0.5f + xRand, 0.5f + yRand, 0) * bombSpeed; } else if (aim == Parameters.Aim.Neutral) { firePosition = this.transform.position + new Vector3(-0.5f, 0, 0) * bombDistance; fireVelocity = new Vector3(-1, yRand, 0) * bombSpeed; } else if (aim == Parameters.Aim.TiltDown) { firePosition = this.transform.position + new Vector3(-0.25f, -0.25f, 0) * bombDistance; fireVelocity = new Vector3(-0.5f + xRand, -0.5f + yRand, 0) * bombSpeed; } else if (aim == Parameters.Aim.Down) { firePosition = this.transform.position + new Vector3(-0.25f, -0.25f, 0) * bombDistance; fireVelocity = new Vector3(-0.5f + xRand, -0.5f + yRand, 0) * bombSpeed; //Temporary measures to mesh sprites together /* * firePosition = this.transform.position + new Vector3(0, -0.5f, 0); * fireVelocity = new Vector3(xRand, -1, 0) * bombSpeed; */ } } else if (dir == Parameters.Direction.Right) { if (aim == Parameters.Aim.Up) { firePosition = this.transform.position + new Vector3(0, 0.5f, 0) * bombDistance; fireVelocity = new Vector3(xRand, 1, 0) * bombSpeed; } else if (aim == Parameters.Aim.TiltUp) { firePosition = this.transform.position + new Vector3(0.25f, 0.25f, 0) * bombDistance; fireVelocity = new Vector3(0.5f + xRand, 0.5f + yRand, 0) * bombSpeed; } else if (aim == Parameters.Aim.Neutral) { firePosition = this.transform.position + new Vector3(0.5f, 0, 0) * 1.5f; fireVelocity = new Vector3(1, yRand, 0) * bombSpeed; } else if (aim == Parameters.Aim.TiltDown) { firePosition = this.transform.position + new Vector3(0.25f, -0.25f, 0) * bombDistance; fireVelocity = new Vector3(0.5f + xRand, -0.5f + yRand, 0) * bombSpeed; } else if (aim == Parameters.Aim.Down) { firePosition = this.transform.position + new Vector3(0, -0.5f, 0) * bombDistance; fireVelocity = new Vector3(0.5f + xRand, -0.5f + yRand, 0) * bombSpeed; } } }
public void ResetInvaders() { invaders.Clear(); invaderDirection = initialInvaderDirection; }
/// <summary> /// What happens when the weapon fires /// You need to specify what direction the weapon is being fired in. /// </summary> public abstract void Fire(Parameters.Direction dir, Parameters.Aim aim);