Ejemplo n.º 1
0
 protected override void Awake()
 {
     _mySprite = GetComponentInChildren<SpriteRenderer>();
     Transform[] children = GetComponentsInChildren<Transform>();
     _bulletSystem = this.gameObject.AddComponent<Bullets>();
     if (prefabBase != null && _bulletSystem != null)
     {
         _bulletSystem.InstantiatePool(200, prefabBase);
     }
     base.Awake ();
 }
Ejemplo n.º 2
0
 public DesertEagle(Game game, Texture2D bulletTexture2D)
     : base(game)
 {
     CurrentBulletsInCharger = bulletsInCharger = 10;
     TimeForRecharge = new TimeSpan(0, 0, 1);
     Bullets = new Bullets(game, bulletTexture2D, AllBullets);
     AllBullets = 20;
     timer = TimeSpan.Zero;
     IsRecharging = false;
     CurrentMoveDirection = MoveDirection.Right;
     Game.Components.Add(this);
 }
Ejemplo n.º 3
0
    public void Shot(Bullets bulletsManager, Vector2 velocity, WeaponHolder owner)
    {
        _owner = owner;
        _firedFrom = _owner.weapon;
        switch (owner.myTeam)
        {
            case WeaponHolder.Team.PLAYER:
                _targetLayer = 1 << LayerMask.NameToLayer("Enemy");
                break;
            case WeaponHolder.Team.ENEMY:
                _targetLayer = 1 << LayerMask.NameToLayer("Player");
                break;
        }

        ownerFiringSystem = bulletsManager;
        _rigidBody.velocity = velocity;
    }
Ejemplo n.º 4
0
 private static void Form_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.ControlKey)
     {
         Bullet bullet = new Bullet(new Point(ship.Rect.X + 10, ship.Rect.Y + 4), new Point(4, 0), new Size(4, 1));
         bullet.OnCount += Bullet_OnCount;
         Bullets.Add(bullet);
         bullet.Count();
     }
     if (e.KeyCode == Keys.Up)
     {
         ship.Up();
     }
     if (e.KeyCode == Keys.Down)
     {
         ship.Down();
     }
 }
Ejemplo n.º 5
0
        public void ShootBullets()
        {
            Bullets newBullet = new Bullets(bulletTexture);

            if (mode == 2 || mode == 1 && !keerLinks)
            {
                newBullet.velocity.X = velocity.X + 3f;
            }
            else if (mode == 3 || mode == 1 && keerLinks)
            {
                newBullet.velocity.X = -(velocity.X + 3f);
            }


            newBullet.position  = new Vector2(position.X + newBullet.velocity.X, position.Y + (texture.Height / 2) - (bulletTexture.Height / 2));
            newBullet.isVisible = true;
            bullets.Add(newBullet);
        }
Ejemplo n.º 6
0
    public void BulletHit()
    {
        spriteR.sprite = normalSprite;
        instBullet     = null;
        canRecall      = false;
        isRecalling    = false;
        hasShot        = false;
        Invoke("CanShoot", .25f);

        if (SceneManager.GetActiveScene().name == "tri.Attack")
        {
            FindObjectOfType <ComboUI>().ResetCounter();
        }
        else if (bullets != (Bullets)ReadWriteSaveManager.Instance.GetData("BulletType", 0))
        {
            bullets = (Bullets)ReadWriteSaveManager.Instance.GetData("BulletType", 0);
        }
    }
Ejemplo n.º 7
0
 /// <summary>
 /// If the player died, execute the following orders:
 ///     -disable the player body
 ///     -center him
 ///     -play sound
 ///     -blink until timer runs out and reenable the object
 /// </summary>
 private void Update()
 {
     if (!alive)
     {
         arrow_rend.enabled = false;
         spawnDelay         = Time.time + 4f;
         moveDelay          = Time.time + 1f;
         player.self.GetComponent <CollisionDetection>().enabled = false;
         bullets         = FindObjectOfType <Bullets>();
         bullets.enabled = false;
         float height = 2f * Camera.main.orthographicSize;
         float width  = height * Camera.main.aspect;
         player.self.transform.position = Camera.main.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 10f));
         alive = true;
         badunk.Play();
         Blink(player.self);
     }
 }
Ejemplo n.º 8
0
        private void PopulateState(BaseItem item)
        {
            if (item is AiTank aiTank)
            {
                AiTanks.Add(aiTank);

                if (item is AiPrizeTank aiPrizeTank)
                {
                    AiPrizeTanks.Add(aiPrizeTank);
                }

                return;
            }

            if (item is EnemyTank enemyTank)
            {
                EnemyTanks.Add(enemyTank);
                return;
            }

            if (item is MyTank myTank)
            {
                MyTank = myTank;
                return;
            }

            if (item is Bullet bullet)
            {
                Bullets.Add(bullet);
                return;
            }

            if (item is River river)
            {
                Rivers.Add(river);
                return;
            }

            if (item is Tree tree)
            {
                Trees.Add(tree);
                return;
            }
        }
Ejemplo n.º 9
0
 private void FixedUpdate()
 {
     if (period > 0.1f)
     {
         if (HasTarget)
         {
             if (Target.gameObject.activeInHierarchy)
             {
                 Bullets.ShootBullet(this.gameObject, Target, 0.5f);
                 period = 0;
             }
             else
             {
                 HasTarget = false;
             }
         }
     }
     period += Time.deltaTime;
 }
Ejemplo n.º 10
0
 void Start()
 {
     shooter_pos  = transform.position;
     form         = GetComponent <Transform> ();
     bot          = new Bullets();
     kill         = new killing();
     value        = new float[5, 7];
     value [0, 0] = -4.87f;
     value [0, 1] = -3.31f;
     value [0, 2] = -1.93f;
     value [0, 3] = -0.26f;
     value [0, 4] = 1.12f;
     value [0, 5] = 2.74f;
     value [0, 6] = 4.35f;
     value [1, 0] = -4.91f;
     value [1, 1] = -3.65f;
     value [1, 2] = 0f;
     value [1, 3] = -2.07f;
     value [1, 4] = 1.92f;
     value [1, 5] = 3.47f;
     value [1, 6] = 4.82f;
     value [2, 0] = -4.43f;
     value [2, 1] = -3.08f;
     value [2, 2] = -1.64f;
     value [2, 3] = -0.14f;
     value [2, 4] = 1.47f;
     value [2, 5] = 3.05f;
     value [2, 6] = 4.61f;
     value [3, 0] = -3.76f;
     value [3, 1] = -2.23f;
     value [3, 2] = -0.62f;
     value [3, 3] = 0.99f;
     value [3, 4] = 2.22f;
     value [3, 5] = 3.6f;
     value [3, 6] = 4.89f;
     value [4, 0] = -4.14f;
     value [4, 1] = -2.7f;
     value [4, 2] = -1.6f;
     value [4, 3] = 0.41f;
     value [4, 4] = 2.02f;
     value [4, 5] = 3.37f;
     value [4, 6] = 4.72f;
 }
Ejemplo n.º 11
0
    public void Shot(Bullets bulletsManager, Vector2 velocity, WeaponHolder owner)
    {
        _owner = owner;
        switch (owner.myTeam)
        {
            case WeaponHolder.Team.PLAYER:
                //_targetMask = 1 << LayerMask.NameToLayer("Enemy");
                //print(_targetMask);
                //gameObject.layer = _targetMask;
                break;
            case WeaponHolder.Team.ENEMY:
                ////_targetMask = 1 << LayerMask.NameToLayer("Player");
                //gameObject.layer = _targetMask;
                break;
        }

        ownerFiringSystem = bulletsManager;
        rigidBody.velocity = velocity *-1;
    }
Ejemplo n.º 12
0
        public void BulletCollision()
        {
            for (var i = 0; i < Bullets.Count; i++)
            {
                if (CheckCollisionWithObstacle(new Point(Bullets[i].X, Bullets[i].Y), 0, 0))
                {
                    Bullets.Remove(Bullets[i]);
                    break;
                }

                var monsterToDamage = CheckCollisionWithBullet(Bullets[i]);
                if (monsterToDamage != null)
                {
                    RandomSpawnBoosters(monsterToDamage);
                    monsterToDamage.Die();
                    Bullets.Remove(Bullets[i]);
                }
            }
        }
Ejemplo n.º 13
0
 private IEnumerator Rolling()
 {
     for (int i = 0; i < 4; i++)
     {
         for (int j = 0; j < 20; j++)
         {
             bullet = Instantiate(bulletPrefab) as GameObject;
             Bullets bulletStuff = bullet.GetComponent <Bullets>();
             bulletStuff.type          = "shake";
             bullet.transform.position = new Vector3(this.transform.position.x + 1, this.transform.position.y, 0);
             bullet.transform.Rotate(0, 0, j * 18);
             bulletStuff.speed = (5);
         }
         yield return(new WaitForSeconds(0.75f));
     }
     dog.GetComponent <DogFunction>().runAnim.SetBool("Rolling", false);
     rolling = false;
     dog.GetComponent <DogFunction>().rolling = false;
 }
Ejemplo n.º 14
0
        public void UpdateBullets(ref int score)
        {
            var Removed = new List <Bullet>();

            for (int i = 0; i < Bullets.Count; i++)
            {
                var bul = Bullets[i];
                if (bul.y > 1)
                {
                    int prev = bul.y;
                    bul.y--;
                    var c = ReadCharacterAt(bul.x, bul.y);
                    if (c != ' ')
                    {
                        Removed.Add(bul);
                        Console.SetCursorPosition(bul.x, prev);
                        Console.WriteLine(' ');
                        CheckForDeadEnemiesAndDelete(bul.x, bul.y);
                        UpdateEnemies();
                        UIfunctions.UpdateScore(ref score);
                    }
                    else
                    {
                        Console.SetCursorPosition(bul.x, bul.y);
                        Console.WriteLine('*');
                        Console.SetCursorPosition(bul.x, prev);
                        Console.WriteLine(' ');
                    }
                }
                else
                {
                    Bullets.Remove(bul);
                    Console.SetCursorPosition(bul.x, bul.y);
                    Console.WriteLine(' ');
                }
            }
            foreach (var bulet in Removed)
            {
                Bullets.Remove(bulet);
                UpdateBullets(ref score);
            }
        }
        /// <summary>
        ///  LoadContent command will load all the game commands when called including explosions and animations.
        /// </summary>
        public override void LoadContent()
        {
            var bulletTexture = _content.Load <Texture2D>("Bullet");

            _font = _content.Load <SpriteFont>("Font");

            _scoreManager = ScoreManager.Load();

            _sprites = new List <Sprite>()
            {
                new Sprite(_content.Load <Texture2D>("Background/Game"))
                {
                    Layer    = 0.0f,
                    Position = new Vector2(ShooterGame.ScreenWidth / 2, ShooterGame.ScreenHeight / 2),
                }
            };

            var bulletPrefab = new Bullets(bulletTexture)
            {
                Explosion = new Explosion(new Dictionary <string, Models.Animation>()
                {
                    { "Explode", new Models.Animation(_content.Load <Texture2D>("Explosion"), 3)
                      {
                          FrameSpeed = 0.1f,
                      } }
                })
                {
                    Layer = 0.5f,
                }
            };;

            if (PlayerCount >= 1)
            {
                AddPlayer(1);
            } //Lambda Code used so continuation occurs when specific code is called.
            _players = _sprites.Where(c => c is MainPlayer).Select(c => (MainPlayer)c).ToList();

            _enemyManager = new EnemyManager(_content)
            {
                Bullet = bulletPrefab,
            };
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Spawns, despawns and updates bullets and starts indicator animations.
        /// </summary>
        public CollisionType Update(LevelTime levelTime, Player player,
                                    CircleParticleSystem particles, bool slomo)
        {
            playerCenter = player.Center;

            var collType = CollisionType.None;

            this.slomo = slomo;

            // update bullets on screen
            for (int i = 0; i < Bullets.Count; i++)
            {
                var bullet = Bullets[i];

                MoveBullet(levelTime, bullet, player.Center);

                (bool left, bool forgotHug) = CheckIfBulletLeftArena(bullet, slomo);
                if (left)
                {
                    if (Config.GameSettings.DrawParticles)
                    {
                        particles.CreateBulletDespawnParticles(bullet);
                    }
                    Bullets.RemoveAt(i);
                    i--;
                }
                if (forgotHug && player.Invincibility == InvincibilityType.None)
                {
                    collType = CollisionType.Bad;
                }
            }

            if (!player.HasHeart && collType == CollisionType.Bad)
            {
                MarkAllBulletsHit();
            }

            shotIterator.Update(levelTime);
            UpdateStreams(levelTime, player.Center);

            return(collType);
        }
Ejemplo n.º 17
0
        public void Fire(GameTime gameTime, out bool canFire)
        {
            canFire = false;
            float elapsed = (float)gameTime.TotalGameTime.TotalMilliseconds - _lastCall;

            if (elapsed >= RechargeTime && this.NeedsRecharge && this.UsedFireRate == 1f)
            {
                this.Recharge();
            }

            if ((this._currFireRate < FireRate || !this.NeedsRecharge) && elapsed > TimeBetweenBullets)
            {
                Vector2 bpos = BulletStartPos.HasValue ? BulletStartPos.Value :
                               new Vector2(this.X + this.GetRealWidth(), this.Y + this.GetRealHeight() / 2);

                BulletEntity b = new BulletEntity(BulletSpeed, bpos.X, bpos.Y);
                b.Y -= this.BulletsImage.Height / 2;

                b.Jump  = BulletSpeed.Y;
                b.Speed = BulletSpeed.X;

                b.Image = this.BulletsImage;

                b.Damage = this.BulletDamage;

                b.MaxLifeSpan = this.BulletLifespan;

                Bullets.Add(b);

                canFire = true;
                this._currFireRate++;
                this._lastCall = (float)gameTime.TotalGameTime.TotalMilliseconds;

                if (Settings.SoundFX)
                {
                    if (ShootingEffect != null)
                    {
                        ShootingEffect.Play();
                    }
                }
            }
        }
Ejemplo n.º 18
0
        public void ShootBullets()
        {
            Bullets newBullet = new Bullets(bulletTexture);

            if (playerTurnRight)
            {
                newBullet.velocity.X = velocity.X + 6f;
            }
            else if (!playerTurnRight)
            {
                newBullet.velocity.X = -(velocity.X + 12f);
            }

            newBullet.position  = new Vector2(position.X + newBullet.velocity.X, position.Y + (texture.Height / 2) - (bulletTexture.Height / 2));
            newBullet.isVisible = true;
            if (buttons.Space)
            {
                bullets.Add(newBullet);
            }
        }
Ejemplo n.º 19
0
        public void PlayerAction(Keys key)
        {
            switch (key)
            {
            case Keys.Space:
                if (Player.Shoot())
                {
                    Bullets.Add(new Bullet(Player));
                }
                break;

            case Keys.R:
                Player.Reload();
                break;

            case Keys.F:
                OpenDoor();
                break;
            }
        }
Ejemplo n.º 20
0
 public void InputControls(double deltaT, HashSet <Keys> keyPressed)
 {
     if (keyPressed.Contains(Keys.Left))
     {
         PlayerMove(-1, deltaT);
     }
     else if (keyPressed.Contains(Keys.Right))
     {
         PlayerMove(1, deltaT);
     }
     if (keyPressed.Contains(Keys.B))
     {
         this.multipleBullet = true;
     }
     if (keyPressed.Contains(Keys.Space) && (Bullets.Count(x => x.IsAlive) <= 0 || (multipleBullet && Bullets.Count(x => x.IsAlive) < 3)))
     {
         Shoot();
         keyPressed.Remove(Keys.Space);
     }
 }
Ejemplo n.º 21
0
        public void Shoot()
        {
            if (faceDirection == FaceDirection.Left)
            {
                barrelLocation = new Vector2(base.Position.X + 5f, base.Position.Y);
                barrelRotation = (1.05f * pi);
            }
            else
            {
                barrelLocation = new Vector2(base.Position.X + 20f, base.Position.Y);
                barrelRotation = ((1.05f * pi - pi) * -1);
            }

            //Bullet bullet = new Bullet(barrelRotation, barrelLocation, this.faceDirection);

            Bullet bullet = new TankBullet(barrelRotation, barrelLocation, this.faceDirection);

            bullet.Texture = bulletTexture;
            Bullets.Add(bullet);
        }
        public AutomaticRifles()
        {
            Bullet = new Bullets();
            Random rand = new Random();
            int    a    = rand.Next(1000);

            if (a % 2 == 1)
            {
                Silencer = true;
                Bayonet  = false;
            }
            else
            {
                Silencer = false;
                Bayonet  = true;
            }
            NBulletsPerShot = a % 3 + 1;
            NumberOfBullets = a % 30 + 10;
            Bullet.Caliber  = rand.NextDouble() * 10;
        }
Ejemplo n.º 23
0
    // Update is called once per frame
    void Update()
    {
        timeBetweenShots += Time.deltaTime * 50f;
        SHOOTING_DIRECTION dir = Input.GetKey(KeyCode.RightArrow) ? SHOOTING_DIRECTION.RIGHT :
                                 Input.GetKey(KeyCode.LeftArrow) ? SHOOTING_DIRECTION.LEFT :
                                 Input.GetKey(KeyCode.UpArrow) ? SHOOTING_DIRECTION.UP :
                                 Input.GetKey(KeyCode.DownArrow) ? SHOOTING_DIRECTION.DOWN : SHOOTING_DIRECTION.NONE;

        if (timeBetweenShots > ShotDelay)
        {
            if (dir != SHOOTING_DIRECTION.NONE)
            {
                GameObject B = (GameObject)Instantiate(bulletPrefab, transform.position, Quaternion.identity);
                //HurtEnemy bScript = B.GetComponent<HurtEnemy>();
                Bullets b = new Bullets(B, dir);
                Bullets.Add(b);
                timeBetweenShots = 0;
            }
        }

        List <Bullets> deleteList = new List <Bullets>();

        foreach (Bullets goBullet in Bullets)
        {
            if (goBullet.IsBulletDead())
            {
                //Agregar a projectiles a borrar
                deleteList.Add(goBullet);
            }
            else
            {
                goBullet.Update(Time.deltaTime);
            }
        }
        //Borrar todos los projectiles que corresponda
        foreach (Bullets delete in deleteList)
        {
            Bullets.Remove(delete);
            //DestroyObject(delete);
        }
    }
Ejemplo n.º 24
0
    public void HandleInput()
    {
        const int SPEED = 5;

        if (SplashKit.KeyDown(KeyCode.LeftKey))
        {
            X -= SPEED;
        }
        if (SplashKit.KeyDown(KeyCode.RightKey))
        {
            X += SPEED;
        }


        if (SplashKit.MouseClicked(MouseButton.LeftButton))
        {
            Bullet bullet = new Bullet(this);
            Bullets.Add(bullet);
            FireSound.Play();
        }
    }
Ejemplo n.º 25
0
        public override void Update()
        {
            base.Update();
            if (Keyboard.IsKeyPressed(Keyboard.Key.Z))
            {
                Attack();
            }

            for (int i = Bullets.Count - 1; i > -1; i--)
            {
                if (!Bullets[i].IsObjectInGameArea())
                {
                    _bulletPoolBase.Release(Bullets[i]);
                    Bullets.Remove(Bullets[i]);
                }
                else
                {
                    Bullets[i].Update();
                }
            }
        }
    private void FixedUpdate()
    {
        RaycastHit2D hit        = Physics2D.Raycast(transform.position + new Vector3(1f, 0, 0), Vector2.right, 1f);
        RaycastHit2D hit_friend = Physics2D.Raycast(transform.position + new Vector3(0.9f, 0, 0), Vector2.right, 0.1f);

        if (hit.collider != null)
        {
            if (hit.collider.tag == "PlayerTroop")
            {
                if (period > 1f)
                {
                    Bullets.ShootBullet(this.gameObject, hit.collider.gameObject, 1f);
                    period = 0;
                }
                period += Time.deltaTime;
            }
            else if (hit.collider.tag == "Bullet")
            {
                Debug.Log("I see a bullet");
            }
            else if (hit_friend.collider != null)
            {
                if (hit_friend.collider.tag == "EnemyTroop")
                {
                }
                else
                {
                    Move();
                }
            }
            else
            {
                Move();
            }
        }
        else
        {
            Move();
        }
    }
Ejemplo n.º 27
0
        public override void Update(float elapsed)
        {
            if (shootTimer > 0)
            {
                shootTimer -= elapsed;
            }
            if (damageTimer > 0)
            {
                damageTimer -= elapsed;
            }

            for (int i = 0; i < Bullets.Count; i++)
            {
                Bullets[i].Update(elapsed);

                foreach (Entity e in Level.Entities)
                {
                    if (Bullets[i].CollisionBox.Intersects(e.CollisionBox))
                    {
                        Bullets[i].OnCollide(e);
                    }
                }

                if (Level.GetTile(Bullets[i].X / Tile.Size, Bullets[i].Y / Tile.Size).IsSolid())
                {
                    Bullets[i].IsActive = false;
                }
                if (!Bullets[i].IsActive)
                {
                    Bullets.RemoveAt(i);
                    i--;
                }
            }

            if (Level.Complete && CollisionBox.Intersects(Level.ExitTile))
            {
                Level.GoToNextLevel = true;
            }
            base.Update(elapsed);
        }
Ejemplo n.º 28
0
        public GameLevel1(SpaceGame game) : base(game)
        {
            /*Neutral Objects*/
            asteroids           = new Asteroids(game);
            backgroundAsteroids = new Asteroids(game);
            backgroundPlanets   = new Planets(game);
            //aircrafts = new Aircrafts(game);
            bullets = new Bullets(game);

            /*Players*/
            player1 = new Player1(game);
            player2 = new Player2(game);
            pilots  = new Pilots(game);

            // questStage = Level1Quests.START;
            questStage     = Level1Quests.ENEMYFOCUS;
            startQuest     = false;
            StartQuestTime = 0;

            destroyedAsteroids     = 0;
            destroyedEnemyAircraft = 0;
        }
Ejemplo n.º 29
0
        public void AddBullet(BulletInfo n)
        {
            Bullets.Add(n);


            var p = default(Point);

            var c = 0;

            n.Element.PositionChanged +=
                delegate
            {
                c++;

                var k = n.Element.ToPoint();

                var DoHitTest = ((k - p).length > 12);

                if (c % 4 == 0)
                {
                    DoHitTest = true;
                }

                if (DoHitTest)
                {
                    // only check for hit on each moved one pixel

                    BulletHitTest(n);
                }

                p = k;
            };

            n.Element.removed +=
                delegate
            {
                Bullets.Remove(n);
            };
        }
Ejemplo n.º 30
0
    // 按下“开枪”按键事件
    private void PressWeapon(int index, Weapon weapon)
    {
        //Debug.Log("Shot");
        if (weapon == null)
        {
            return;
        }

        GameObject bulletGO = Pool.Instance.getObjFromPool(Pool.PoolType.Bullet);
        Bullets    bullet   = bulletGO.GetComponent <Bullets>();

        // 设置子弹与武器相关的属性
        switch (weapon.Type)
        {
        case EquipmentManager.WeaponType.Rifle:
            //bullet.bulletGameObject.GetComponent<MeshRenderer>().material.mainTexture = Resources.Load("Effect/Ammo_001_mip_1") as Texture;
            // 发射者
            bullet.sender = Bullets.Sender.Player;
            // 位置
            bulletGO.transform.position = player.transform.FindChild("Point_Rifle").position;
            // 方向
            bulletGO.transform.rotation = new Quaternion(0, 0, orientLeft ? 0 : 180, 0);
            //bullet.bulletGameObject.transform.LookAt(orientLeft ? GameRoot_InBattle.getSingleton<BulletsManager>().go_Left.transform.position
            //    : GameRoot_InBattle.getSingleton<BulletsManager>().go_Right.transform.position);
            // 速度
            bulletGO.GetComponent <Rigidbody>().velocity = new Vector3(weapon.BulletSpeed * (orientLeft ? -1 : 1),
                                                                       0, Random.Range(-weapon.BulletAngle, weapon.BulletAngle));
            // 自动销毁协程
            StartCoroutine(DestroyBulletCoroutine(3, bullet));

            break;
        }
        // 子弹图片
        bulletGO.GetComponent <MeshRenderer>().material = Resources.Load(weapon.BulletPath) as Material;

        bullet.weapon = weapon;
        // 发送“子弹发射成功”消息
        GameRoot_InBattle.getSingleton <MessageManager_InBattle>().SendMessage_ShotSuccessfulEvent(index, weapon);
    }
Ejemplo n.º 31
0
        private void ShootBullet(Vector2 direction)
        {
            // Bullet shooting
            basicAttackSound.Play();
            bulletTimeElapsed = TimeSpan.Zero;
            direction.Normalize();

            Bullet[] bullet = new Bullet[0];
            switch (bulletType)
            {
            case (Bullet.BulletType.Normal):
                bullet = Bullet.CreateBullet(bulletSprite, bulletType, direction, Colour, HostileToPlayer, this);
                break;

            case (Bullet.BulletType.Trident):
                bullet = Bullet.CreateBullet(tridentSprite, bulletType, direction, Colour, HostileToPlayer, this);
                break;

            case (Bullet.BulletType.Bubble):
                bullet = Bullet.CreateBullet(bubbleSprite, bulletType, direction, Colour, HostileToPlayer, this);
                break;

            case (Bullet.BulletType.Razor):
                bullet = Bullet.CreateBullet(razorSprite, bulletType, direction, Colour, HostileToPlayer, this);
                break;

            case (Bullet.BulletType.Magnet):
                bullet = Bullet.CreateBullet(magnetSprite, bulletType, direction, Colour, HostileToPlayer, this);
                break;
            }

            for (int i = 0; i < bullet.Length; i++)
            {
                bullet[i].Position *= 5;
                bullet[i].Position += Boat.Position;
                Bullets.Add(bullet[i]);
            }
        }
Ejemplo n.º 32
0
    public override void _Ready()
    {
        _cameraController = GetNode <CameraController>(CameraPath);
        _castle           = GetNode <Castle>(CastlePath);
        _enemyCastle      = GetNode <Castle>(EnemyCastlePath);
        _bullets          = GetNode <Bullets>(BulletsPath);
        _mainPanelView    = GetNode <MainPanelView>(MainPanelPath);
        _menuView         = GetNode <MenuView>(MenuViewPath);
        _crossHair        = GetNode <CrossHair>(CrossHairPath);
        _inputTimer       = GetNode <Timer>("input_timer");

        _bullets.BulletHitsTarget    += OnBulletHitTarget;
        _menuView.ActivateWeaponView += OnShowWeaponView;
        _menuView.ActivateCastleView += OnShowCastleView;
        _menuView.Build       += OnBuildBuilding;
        _castle.BuildingAdded += OnBuildingAdded;

        _mainPanelView.UpdateOwnMinimap(_castle);
        _mainPanelView.UpdateEnemyMiniMap(_enemyCastle);

        _menuView.SetMenuState(MenuState.RootMenuCastleView);
        ChangeState(GameState.CastleView);
    }
Ejemplo n.º 33
0
        public void invaderisDead(object sender, EventArgs e)
        {
            Bullets bullet = (Bullets)sender;

            for (int i = 0; i < InvaderList.Count; i++)
            {
                Invader inv = InvaderList[i];

                if (bullet.Bounds.IntersectsWith(inv.Bounds))
                {
                    inv.Dispose();
                    if (!inv.isDead)
                    {
                        countDeadInvs++;
                        bullet.Dispose();
                    }
                    inv.isDead = true;
                    //var point = new Point(250, 73);
                    //Invader invadd = new Invader(point);
                    //InvaderList.Add(invadd);
                }
            }
        }
Ejemplo n.º 34
0
        public override void HandleInput(InputState Input, GameTime gameTime)
        {
            float DeltaTime  = (float)Math.Round(gameTime.ElapsedGameTime.TotalSeconds, 2);
            float DeltaSpeed = Speed;            // * DeltaTime;

            if (Input.IsNewKeyPress(Globals.KeyUp))
            {
                Velocity -= new Vector2(0, DeltaSpeed);
            }
            if (Input.IsNewKeyPress(Globals.KeyDown))
            {
                Velocity += new Vector2(0, DeltaSpeed);
            }
            if (Input.IsNewKeyPress(Globals.KeyLeft))
            {
                Velocity -= new Vector2(DeltaSpeed, 0);
            }
            if (Input.IsNewKeyPress(Globals.KeyRight))
            {
                Velocity += new Vector2(DeltaSpeed, 0);
            }

            //Shoot
            if (Input.IsNewKeyPress(Globals.KeyShoot) && CurrentTime >= ShootInterval)
            {
                CurrentTime = 0f;

                AssetManager.PlaySoundRandomPitch("Shoot", 1, 0.3f, -0.3f);

                for (int i = 0; i < ShootPoints.Length; i++)
                {
                    Bullets.Add(new Bullet(new Rectangle(ShootPoints[i].X + (int)X, ShootPoints[i].Y + (int)Y, 3, 4), AssetManager.Sprites["Bullet"], Color.White, ShotSpeed));
                }

                Parent.Camera.ScreenShake(5, 0.1f);
            }
        }
Ejemplo n.º 35
0
    protected override void Awake()
    {
        _mySprite = GetComponentInChildren<SpriteRenderer>();
        Transform[] children = GetComponentsInChildren<Transform>();
        foreach(Transform child in children)
        {
            if(child.gameObject.name == "PlayerBullets") _playerBulletParticles = child.GetComponent<Bullets>();
            else if(child.gameObject.name == "EnemyBullets") _enemyBulletsParticles = child.GetComponent<Bullets>();
        }
        if(_playerBulletParticles == null) Debug.LogError (name + " needs a player bullet particle system in a child object called 'PlayerBullets'");
        if(_playerBulletParticles == null) Debug.LogError (name + " needs an enemy bullet particle system in a child object called 'EnemyBullets'");

        base.Awake ();
    }