Ejemplo n.º 1
0
        public void Update()
        {
            currentTime = stopwatch.ElapsedMilliseconds;
            deltaTime   = (currentTime - lastTime) / 1000.0f;

            timer += deltaTime;
            if (timer >= 1)
            {
                fps    = frames;
                frames = 0;
                timer--;
            }
            frames++;

            if (IsKeyDown(KeyboardKey.KEY_A))
            {
                tankObject.Rotate(-deltaTime * 10);
            }
            if (IsKeyDown(KeyboardKey.KEY_D))
            {
                tankObject.Rotate(deltaTime * 10);
            }
            if (IsKeyDown(KeyboardKey.KEY_W))
            {
                Vector3 facing = new Vector3(tankObject.LocalTransform.m1, tankObject.LocalTransform.m2, 1) * deltaTime * 500;
                tankObject.Translate(facing.x, facing.y);
            }
            if (IsKeyDown(KeyboardKey.KEY_S))
            {
                Vector3 facing = new Vector3(tankObject.LocalTransform.m1, tankObject.LocalTransform.m2, 1) * deltaTime * -500;
                tankObject.Translate(facing.x, facing.y);
            }
            if (IsKeyDown(KeyboardKey.KEY_Q))
            {
                turretObject.Rotate(-deltaTime * 50);
            }
            if (IsKeyDown(KeyboardKey.KEY_E))
            {
                turretObject.Rotate(deltaTime * 50);
            }
            if (IsKeyDown(KeyboardKey.KEY_SPACE))
            {
                tankObject.RemoveChild(bulletObject);
                fired = true;
            }
            if (fired == true)
            {
                Vector3 facing = new Vector3(bulletObject.LocalTransform.m1, bulletObject.LocalTransform.m2, 1) * deltaTime * 500;
                bulletObject.Translate(facing.x, facing.y);
            }

            /*if (IsKeyPressed(KeyboardKey.KEY_SPACE))
             * {
             *  bulletObject.GlobalTransform.m7++;
             * }*/

            tankObject.Update(deltaTime);

            lastTime = currentTime;
        }
Ejemplo n.º 2
0
        public void Update()
        {
            currentTime = stopwatch.ElapsedMilliseconds;
            deltaTime   = (currentTime - lastTime) / 1000.0f;

            timer += deltaTime;
            if (timer >= 1)
            {
                fps    = frames;
                frames = 0;
                timer -= 1;
            }

            frames++;

            if (IsKeyDown(KeyboardKey.KEY_A))
            {
                tankObject.Rotate(-deltaTime);
            }
            if (IsKeyDown(KeyboardKey.KEY_D))
            {
                tankObject.Rotate(deltaTime);
            }
            if (IsKeyDown(KeyboardKey.KEY_W))
            {
                //MathHelpers.Vector3 facing = new MathHelpers.Vector3(
                //    tankObject.LocalTransform.m[0],
                //    tankObject.LocalTransform.m[1], 1) * deltaTime * 100;
                //tankObject.Translate(facing.x, facing.y);
                MathHelpers.Vector3 facing = new MathHelpers.Vector3(
                    tankObject.LocalTransform.m1,
                    tankObject.LocalTransform.m2, 1) * deltaTime * 100;
                tankObject.Translate(facing.x, facing.y);
            }
            if (IsKeyDown(KeyboardKey.KEY_S))
            {
                //MathHelpers.Vector3 facing = new MathHelpers.Vector3(
                //tankObject.LocalTransform.m[0],
                //tankObject.LocalTransform.m[1], 1) * deltaTime * -100;
                //tankObject.Translate(facing.x, facing.y);
                MathHelpers.Vector3 facing = new MathHelpers.Vector3(
                    tankObject.LocalTransform.m1,
                    tankObject.LocalTransform.m2, 1) * deltaTime * -100;
                tankObject.Translate(facing.x, facing.y);
            }
            if (IsKeyDown(KeyboardKey.KEY_Q))
            {
                turretObject.Rotate(-deltaTime);
            }
            if (IsKeyDown(KeyboardKey.KEY_E))
            {
                turretObject.Rotate(deltaTime);
            }
            tankObject.Update(deltaTime);

            lastTime = currentTime;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// This is used to update the information of the objects in the game.
        /// </summary>
        public void Update()
        {
            currentTime = stopwatch.ElapsedMilliseconds;
            deltaTime   = (currentTime - lastTime) / 1000.0f;

            timer += deltaTime;
            if (timer >= 1)
            {
                fps    = frames;
                frames = 0;
                timer -= 1;
            }
            frames++;

            //These statements are used to rotate the tank.
            if (IsKeyDown(KeyboardKey.KEY_A))
            {
                tankObject.Rotate(-deltaTime * 5);
            }
            if (IsKeyDown(KeyboardKey.KEY_D))
            {
                tankObject.Rotate(deltaTime * 5);
            }
            //These are used to move the tank forward and back.
            if (IsKeyDown(KeyboardKey.KEY_W))
            {
                Vector3 facing = new Vector3(tankObject.LocalTransform.m1, tankObject.LocalTransform.m2, 1) * deltaTime * 250;
                tankObject.Translate(facing.x, facing.y);
            }
            if (IsKeyDown(KeyboardKey.KEY_S))
            {
                Vector3 facing = new Vector3(tankObject.LocalTransform.m1, tankObject.LocalTransform.m2, 1) * deltaTime * -250;
                tankObject.Translate(facing.x, facing.y);
            }
            //These are used to rotate the barrel on top of the tank.
            if (IsKeyDown(KeyboardKey.KEY_Q))
            {
                turretObject.Rotate(-deltaTime * 10);
            }
            if (IsKeyDown(KeyboardKey.KEY_E))
            {
                turretObject.Rotate(deltaTime * 10);
            }

            //These check the player is too off screen and, if so, moves them to the other side of the screen.
            if (tankObject.GlobalTransform.m7 < -100)
            {
                tankObject.globalTransform.m7 = 1600;
            }
            if (tankObject.GlobalTransform.m7 > 1600)
            {
                tankObject.globalTransform.m7 = -100;
            }
            if (tankObject.GlobalTransform.m8 < -100)
            {
                tankObject.globalTransform.m8 = 1000;
            }
            if (tankObject.GlobalTransform.m8 > 1000)
            {
                tankObject.globalTransform.m8 = -100;
            }

            //This calls the shoot function.
            if (IsKeyPressed(KeyboardKey.KEY_SPACE))
            {
                Shoot();
            }

            BulletManagement();

            tankObject.Update(deltaTime);

            lastTime = currentTime;
        }
Ejemplo n.º 4
0
        public void Update()
        {
            tankBulletObject1.Set(turretObject1);

            tank1.MyTankPoints[0] = new Vector2(tankHitBoxTL1.Position.x, tankHitBoxTL1.Position.y);
            tank1.MyTankPoints[1] = new Vector2(tankHitBoxTR1.Position.x, tankHitBoxTR1.Position.y);
            tank1.MyTankPoints[2] = new Vector2(tankHitBoxBR1.Position.x, tankHitBoxBR1.Position.y);
            tank1.MyTankPoints[3] = new Vector2(tankHitBoxBL1.Position.x, tankHitBoxBL1.Position.y);

            tankBullet1.MyTankPoints[0] = new Vector2(tankBulletHitBoxTL1.Position.x, tankBulletHitBoxTL1.Position.y);
            tankBullet1.MyTankPoints[1] = new Vector2(tankBulletHitBoxTR1.Position.x, tankBulletHitBoxTR1.Position.y);
            tankBullet1.MyTankPoints[2] = new Vector2(tankBulletHitBoxBR1.Position.x, tankBulletHitBoxBR1.Position.y);
            tankBullet1.MyTankPoints[3] = new Vector2(tankBulletHitBoxBL1.Position.x, tankBulletHitBoxBL1.Position.y);

            tank2.MyTankPoints[0] = new Vector2(tankHitBoxTL2.Position.x, tankHitBoxTL2.Position.y);
            tank2.MyTankPoints[1] = new Vector2(tankHitBoxTR2.Position.x, tankHitBoxTR2.Position.y);
            tank2.MyTankPoints[2] = new Vector2(tankHitBoxBR2.Position.x, tankHitBoxBR2.Position.y);
            tank2.MyTankPoints[3] = new Vector2(tankHitBoxBL2.Position.x, tankHitBoxBL2.Position.y);



            deltaTime = gameTime.GetDeltaTime();
            timer    += deltaTime;
            if (timer >= 1)
            {
                fps    = frames;
                frames = 0;
                timer -= 1;
            }
            frames++;

            if (IsKeyPressed(KeyboardKey.KEY_SPACE))
            {
                tankBulletFired1 = true;
                tankBulletObject1.Rotate(-deltaTime);

                bulletCoolDown1 -= deltaTime;
                do
                {
                    Vector3 facing = new Vector3(
                        tankObject1.LocalTransform.m1,
                        tankObject1.LocalTransform.m2, 1) * deltaTime * 100;
                    tankObject1.Translate(facing.x, facing.y);
                } while (bulletCoolDown1 > deltaTime);
            }
            if (deltaTime > bulletCoolDown1)
            {
                tankBulletFired1 = false;
            }
            //Player 1 movement
            if (IsKeyDown(KeyboardKey.KEY_A))
            {
                tankObject1.Rotate(-deltaTime);
            }
            if (IsKeyDown(KeyboardKey.KEY_D))
            {
                tankObject1.Rotate(deltaTime);
            }
            if (IsKeyDown(KeyboardKey.KEY_W))
            {
                Vector3 facing = new Vector3(
                    tankObject1.LocalTransform.m1,
                    tankObject1.LocalTransform.m2, 1) * deltaTime * 100;
                tankObject1.Translate(facing.x, facing.y);
            }
            if (IsKeyDown(KeyboardKey.KEY_S))
            {
                Vector3 facing = new Vector3(
                    tankObject1.LocalTransform.m1,
                    tankObject1.LocalTransform.m2, 1) * deltaTime * -100;
                tankObject1.Translate(facing.x, facing.y);
            }
            tankObject1.Update(deltaTime);

            if (IsKeyDown(KeyboardKey.KEY_Q))
            {
                turretObject1.Rotate(-deltaTime);
            }
            if (IsKeyDown(KeyboardKey.KEY_E))
            {
                turretObject1.Rotate(deltaTime);
            }

            //Player 2 movement

            if (IsKeyDown(KeyboardKey.KEY_KP_4))
            {
                tankObject2.Rotate(-deltaTime);
            }
            if (IsKeyDown(KeyboardKey.KEY_KP_6))
            {
                tankObject2.Rotate(deltaTime);
            }
            if (IsKeyDown(KeyboardKey.KEY_KP_8))
            {
                Vector3 facing = new Vector3(
                    tankObject2.LocalTransform.m1,
                    tankObject2.LocalTransform.m2, 1) * deltaTime * 100;
                tankObject2.Translate(facing.x, facing.y);
            }
            if (IsKeyDown(KeyboardKey.KEY_KP_5))
            {
                Vector3 facing = new Vector3(
                    tankObject2.LocalTransform.m1,
                    tankObject2.LocalTransform.m2, 1) * deltaTime * -100;
                tankObject2.Translate(facing.x, facing.y);
            }
            tankObject2.Update(deltaTime);

            if (IsKeyDown(KeyboardKey.KEY_KP_7))
            {
                turretObject2.Rotate(-deltaTime);
            }
            if (IsKeyDown(KeyboardKey.KEY_KP_9))
            {
                turretObject2.Rotate(deltaTime);
            }
        }
Ejemplo n.º 5
0
        public void Update()
        {
            currentTime = stopwatch.ElapsedMilliseconds;
            deltaTime   = (currentTime - lastTime) / 1000.0f;
            Timer coolDown = new Timer();

            timer += deltaTime;
            if (timer >= 1)
            {
                fps    = frames;
                frames = 0;
                timer -= 1;
            }

            frames++;
            #region Movement
            if (IsKeyDown(KeyboardKey.KEY_A))
            {
                tankObject.Rotate(-deltaTime);
            }
            if (IsKeyDown(KeyboardKey.KEY_D))
            {
                tankObject.Rotate(deltaTime);
            }
            if (IsKeyDown(KeyboardKey.KEY_W))
            {
                //MathHelpers.Vector3 facing = new MathHelpers.Vector3(
                //    tankObject.LocalTransform.m[0],
                //    tankObject.LocalTransform.m[1], 1) * deltaTime * 100;
                //tankObject.Translate(facing.x, facing.y);
                MathHelpers.Vector3 facing = new MathHelpers.Vector3(
                    tankObject.LocalTransform.m1,
                    tankObject.LocalTransform.m2, 1) * deltaTime * 100;
                tankObject.Translate(facing.x, facing.y);
            }
            if (IsKeyDown(KeyboardKey.KEY_S))
            {
                //MathHelpers.Vector3 facing = new MathHelpers.Vector3(
                //tankObject.LocalTransform.m[0],
                //tankObject.LocalTransform.m[1], 1) * deltaTime * -100;
                //tankObject.Translate(facing.x, facing.y);
                MathHelpers.Vector3 facing = new MathHelpers.Vector3(
                    tankObject.LocalTransform.m1,
                    tankObject.LocalTransform.m2, 1) * deltaTime * -100;
                tankObject.Translate(facing.x, facing.y);
            }
            if (IsKeyDown(KeyboardKey.KEY_Q))
            {
                turretObject.Rotate(-deltaTime);
            }
            if (IsKeyDown(KeyboardKey.KEY_E))
            {
                turretObject.Rotate(deltaTime);
            }
            #endregion Movement

            if (IsKeyPressed(KeyboardKey.KEY_SPACE))
            {
                Projectile shell = new Projectile(turretObject.GlobalTransform.m5, -turretObject.GlobalTransform.m4);
                shell.SetPosition(turretObject.GlobalTransform.m7, turretObject.GlobalTransform.m8);
                shellObject.AddChild(shell);


                //MathHelpers.Vector3 facing = new MathHelpers.Vector3 (
                //    tankObject.LocalTransform.m1,
                //    tankObject.LocalTransform.m2, 1) *deltaTime * -1000;
                //tankObject.Translate(facing.x, facing.y);
            }

            if (boxCollider.Overlaps(playerCollider))
            {
                boxColor = Color.DARKGREEN;
            }
            else
            {
                boxColor = Color.GREEN;
            }

            for (int i = 0; i < shellObject.GetChildCount(); i++)
            {
                if (shellObject.GetChild(i).proDel)
                {
                    shellObject.RemoveChild(shellObject.GetChild(i));
                }
            }
            for (int i = 0; i < shellObject.GetChildCount(); i++)
            {
                Projectile tShell = (Projectile)shellObject.GetChild(i);
                if (!boxCollider.Overlaps(playerCollider))
                {
                    if (tShell.projectileCollider.Overlaps(boxCollider))
                    {
                        boxColor = Color.RED;
                        break;
                    }
                    else
                    {
                        boxColor = Color.GREEN;
                    }
                }
            }

            tankObject.UpdateTransform();
            //tankObject.Update(deltaTime);



            playerCollider.Resize(new MathHelpers.Vector3(tankObject.GlobalTransform.m7 - (tankSprite.Width / 2), tankObject.GlobalTransform.m8 - (tankSprite.Height / 2), 0),
                                  new MathHelpers.Vector3(tankObject.GlobalTransform.m7 + (tankSprite.Width / 2), tankObject.GlobalTransform.m8 + (tankSprite.Height / 2), 0));
            //DrawRectangle(90, 90, 90, 10, Color.RED);
            Vector2 v2 = new Vector2(900, 24);
            //DrawLineStrip(ref v2, 255, Color.VIOLET);
            lastTime = currentTime;

            foreach (SceneObject i in Hierarchy)
            {
                i.Update(deltaTime);
            }
        }
Ejemplo n.º 6
0
        public void P1(float deltaTime)
        {
            if (IsKeyDown(KeyboardKey.KEY_A))
            {
                Rotate(-deltaTime * tankSpeed);
            }

            if (IsKeyDown(KeyboardKey.KEY_D))
            {
                Rotate(deltaTime * tankSpeed);
            }

            if (IsKeyDown(KeyboardKey.KEY_W))
            {
                Vector2 facing = new Vector2(LocalTransform.m1, LocalTransform.m2) * deltaTime * 100 * tankSpeed;

                Translate(facing.x, facing.y);
            }

            if (IsKeyDown(KeyboardKey.KEY_S))
            {
                Vector2 facing = new Vector2(LocalTransform.m1, LocalTransform.m2) * deltaTime * -100 * tankSpeed;

                Translate(facing.x, facing.y);
            }

            Update(deltaTime);

            if (IsKeyDown(KeyboardKey.KEY_Q))
            {
                turretObject.Rotate(-deltaTime * turretSpeed);
            }

            if (IsKeyDown(KeyboardKey.KEY_E))
            {
                turretObject.Rotate(deltaTime * turretSpeed);
            }

            bullet.Draw();
            float xR  = turretObject.GlobalTransform.m1;
            float yR  = turretObject.GlobalTransform.m2;
            float rot = MathF.Atan2(xR, yR);

            if (IsKeyPressed(KeyboardKey.KEY_SPACE) && (reloadTime * deltaTime) >= 5)
            {
                turretObject.AddChild(bullet);
                bullet.SetPosition(65, -5.5f);

                float bulletX = bullet.GlobalTransform.m7;
                float bulletY = bullet.GlobalTransform.m8;

                turretObject.RemoveChild(bullet);
                reloadTime = 0;
                bullet.SetRotate(rot);
                bullet.bulletSpawn(turretObject, deltaTime);
                bullet.SetPosition(bulletX, bulletY);

                isbullet = true;
            }

            if (isbullet)
            {
                Vector2 facing = new Vector2(bullet.LocalTransform.m1, bullet.LocalTransform.m2) * deltaTime * 100 * bulletSpeed;
                bullet.Translate(facing.x, facing.y);
            }
        }
Ejemplo n.º 7
0
        public void Update()
        {
            currentTime = stopwatch.ElapsedMilliseconds;
            deltaTime   = (currentTime - lastTime) / 1000.0f;

            timer += deltaTime;
            if (timer >= 1)
            {
                fps    = frames;
                frames = 0;
                timer -= 1;
            }
            frames++;

            //The controls for the tank
            if (rl.IsKeyDown(KeyboardKey.KEY_A))
            {
                tankObject.Rotate(-deltaTime);
            }
            if (rl.IsKeyDown(KeyboardKey.KEY_D))
            {
                tankObject.Rotate(deltaTime);
            }
            if (rl.IsKeyDown(KeyboardKey.KEY_W))
            {
                Vector3 facing = new Vector3(tankObject.LocalTransform.m1,
                                             tankObject.LocalTransform.m2, 1) *
                                 deltaTime * 100;

                tankObject.Translate(facing.x, facing.y);
            }
            if (rl.IsKeyDown(KeyboardKey.KEY_S))
            {
                Vector3 facing = new Vector3(tankObject.LocalTransform.m1,
                                             tankObject.LocalTransform.m2, 1) *
                                 deltaTime * -100;

                tankObject.Translate(facing.x, facing.y);
            }
            //The controls for the turret
            if (rl.IsKeyDown(KeyboardKey.KEY_Q))
            {
                turrentObject.Rotate(-deltaTime);
            }
            if (rl.IsKeyDown(KeyboardKey.KEY_E))
            {
                turrentObject.Rotate(deltaTime);
            }
            //The control for the bullet
            if (rl.IsKeyPressed(KeyboardKey.KEY_SPACE))
            {
                //Make the bullet appear, set the position, and update per frame when it becomes active
                turrentObject.AddChild(bulletObject);
                bulletObject.SetPosition(65, -5.5f);
                bulletObject.Update(deltaTime);
                bulletObject.active = true;

                float xPos = bulletObject.GlobalTransform.m7;
                float yPos = bulletObject.GlobalTransform.m8;

                float xR  = turrentSprite.GlobalTransform.m1;
                float yR  = turrentSprite.GlobalTransform.m4;
                float rot = (float)Math.Atan2(xR, yR);

                //Make the bullet remove from the turrent
                turrentObject.RemoveChild(bulletObject);

                //Set the rotation of the turrent from the globalTransform
                bulletObject.SetRotate(rot);
                //Set the position of the turrent from the globalTransform
                bulletObject.SetPosition(xPos, yPos);

                bulletTime = 2;
            }

            lastTime = currentTime;

            //The collision boundries to make the bullet disappear
            if (bulletObject.GlobalTransform.m7 > 795 || bulletObject.GlobalTransform.m7 < 5 || bulletObject.GlobalTransform.m8 > 445 || bulletObject.GlobalTransform.m8 < 5)
            {
                bulletObject.active = false;
            }

            //The method for when the bullet is active so the bullet appears
            if (/*bulletTime > 0 && */ bulletObject.active)
            {
                //bulletTime -= deltaTime;
                bulletSprite.Draw();
                //To make the bullet go foward
                Vector3 facing = new Vector3(bulletObject.LocalTransform.m1,
                                             bulletObject.LocalTransform.m2, 1) *
                                 deltaTime * 100;

                bulletObject.Translate(facing.x, facing.y);
            }
        }
Ejemplo n.º 8
0
 public void GunRotate(float amt)
 {
     turretObject.Rotate(amt);
 }
Ejemplo n.º 9
0
 public void Rotate(float amt)
 {
     tankObject.Rotate(amt);
 }
Ejemplo n.º 10
0
        public void Update()
        {
            currentTime = stopwatch.ElapsedMilliseconds;
            deltaTime   = (currentTime - lastTime) / 1000.0f;
            Timer coolDown = new Timer();

            timer += deltaTime;
            if (timer >= 1)
            {
                fps    = frames;
                frames = 0;
                timer -= 1;
            }

            frames++;
            #region Movement
            if (IsKeyDown(KeyboardKey.KEY_A))
            {
                tankObject.Rotate(-deltaTime);
            }
            if (IsKeyDown(KeyboardKey.KEY_D))
            {
                tankObject.Rotate(deltaTime);
            }
            if (IsKeyDown(KeyboardKey.KEY_W))
            {
                //MathHelpers.Vector3 facing = new MathHelpers.Vector3(
                //    tankObject.LocalTransform.m[0],
                //    tankObject.LocalTransform.m[1], 1) * deltaTime * 100;
                //tankObject.Translate(facing.x, facing.y);
                MathHelpers.Vector3 facing = new MathHelpers.Vector3(
                    tankObject.LocalTransform.m1,
                    tankObject.LocalTransform.m2, 1) * deltaTime * 100;
                tankObject.Translate(facing.x, facing.y);
            }
            if (IsKeyDown(KeyboardKey.KEY_S))
            {
                //MathHelpers.Vector3 facing = new MathHelpers.Vector3(
                //tankObject.LocalTransform.m[0],
                //tankObject.LocalTransform.m[1], 1) * deltaTime * -100;
                //tankObject.Translate(facing.x, facing.y);
                MathHelpers.Vector3 facing = new MathHelpers.Vector3(
                    tankObject.LocalTransform.m1,
                    tankObject.LocalTransform.m2, 1) * deltaTime * -100;
                tankObject.Translate(facing.x, facing.y);
            }
            if (IsKeyDown(KeyboardKey.KEY_Q))
            {
                turretObject.Rotate(-deltaTime);
            }
            if (IsKeyDown(KeyboardKey.KEY_E))
            {
                turretObject.Rotate(deltaTime);
            }
            #endregion Movement

            //Spawns a projectile that moves in the direction the barrel was pointed when pressed.
            if (IsKeyPressed(KeyboardKey.KEY_SPACE))
            {
                Projectile shell = new Projectile(turretObject.GlobalTransform.m5, -turretObject.GlobalTransform.m4);
                shell.SetPosition(turretObject.GlobalTransform.m7, turretObject.GlobalTransform.m8);
                shellObject.AddChild(shell);


                //MathHelpers.Vector3 facing = new MathHelpers.Vector3 (
                //    tankObject.LocalTransform.m1,
                //    tankObject.LocalTransform.m2, 1) *deltaTime * -1000;
                //tankObject.Translate(facing.x, facing.y);
            }

            //Checks to see if the player's collider interacts with the green box.
            if (boxCollider.Overlaps(playerCollider))
            {
                boxColor = Color.DARKGREEN;
            }
            else
            {
                boxColor = Color.GREEN;
            }

            //Goes through the children of shellObject and checks their lifespans.
            //If they expire they are removed from the shellObject.
            for (int i = 0; i < shellObject.GetChildCount(); i++)
            {
                if (shellObject.GetChild(i).proDel)
                {
                    shellObject.RemoveChild(shellObject.GetChild(i));
                }
            }

            for (int i = 0; i < shellObject.GetChildCount(); i++)
            {
                Projectile tShell = (Projectile)shellObject.GetChild(i);

                //If the green box isn't currently overlapping with the player
                //it will check if it's overlapping with a projectile; if it is, it will turn red.
                if (!boxCollider.Overlaps(playerCollider))
                {
                    if (tShell.projectileCollider.Overlaps(boxCollider))
                    {
                        boxColor = Color.RED;
                        break;
                    }
                    else
                    {
                        boxColor = Color.GREEN;
                    }
                }
            }

            tankObject.UpdateTransform();

            //Moves the collider in tandem with the tank by "resizing" it to the current dimensions
            //(and by extent, the position) of the player.
            playerCollider.Resize(new MathHelpers.Vector3(tankObject.GlobalTransform.m7 - (tankSprite.Width / 2), tankObject.GlobalTransform.m8 - (tankSprite.Height / 2), 0),
                                  new MathHelpers.Vector3(tankObject.GlobalTransform.m7 + (tankSprite.Width / 2), tankObject.GlobalTransform.m8 + (tankSprite.Height / 2), 0));

            Vector2 v2 = new Vector2(900, 24);
            lastTime = currentTime;

            //
            foreach (SceneObject i in Hierarchy)
            {
                i.Update(deltaTime);
            }
        }
Ejemplo n.º 11
0
        public void Update() //This is constantly Updating.
        {
            currentTime = stopwatch.ElapsedMilliseconds;
            deltaTime   = (currentTime - lastTime) / 1000.0f;

            timer += deltaTime;
            if (timer >= 1)
            {
                fps    = frames;
                frames = 0;
                timer -= 1;
            }
            frames++;

            if (IsKeyDown(KeyboardKey.KEY_A))   //Key A
            {
                tankObject.Rotate(-deltaTime);
            }

            if (IsKeyDown(KeyboardKey.KEY_D))   //Key D
            {
                tankObject.Rotate(deltaTime);
            }

            if (IsKeyDown(KeyboardKey.KEY_W))   //Key W
            {
                Vector3 facing = new Vector3(tankObject.GlobalTransform.m1, tankObject.GlobalTransform.m2, 1) * deltaTime * 100;

                tankObject.Translate(facing.x, facing.y);
            }

            if (IsKeyDown(KeyboardKey.KEY_S))   //Key S
            {
                Vector3 facing = new Vector3(tankObject.GlobalTransform.m1, tankObject.GlobalTransform.m2, 1) * deltaTime * -100;

                tankObject.Translate(facing.x, facing.y);
            }

            if (IsKeyDown(KeyboardKey.KEY_Q))   //Key Q
            {
                turretObject.Rotate(-deltaTime);
            }

            if (IsKeyDown(KeyboardKey.KEY_E))   //Key E
            {
                turretObject.Rotate(deltaTime);
            }

            if (IsKeyPressed(KeyboardKey.KEY_SPACE)) //Key SpaceBar
            {
                SceneObject bulletObject = new SceneObject();

                SpriteObject bulletSprite = new SpriteObject();


                bulletSprites.Add(bulletSprite);
                bulletObject.AddChild(bulletSprite);
                turretObject.AddChild(bulletObject);

                bulletSprite.Load("bulletBlue.png");
                bulletSprite.SetRotate(90 * (float)(Math.PI / 180.0f));

                bulletObject.SetPosition(55f, -6);

                bulletSprite.corners[0].SetPosition(bulletSprite.Width, bulletSprite.Height);
                bulletSprite.corners[1].SetPosition(-bulletSprite.Width + 9, bulletSprite.Height);
                bulletSprite.corners[2].SetPosition(bulletSprite.Width, -bulletSprite.Height + 25);
                bulletSprite.corners[3].SetPosition(-bulletSprite.Width + 10, -bulletSprite.Height + 25);

                tankObject.UpdateTransform();

                bulletObjects.Add(bulletObject);

                turretObject.RemoveChild(bulletObject);
                bulletObject.UpdateTransform();
            }
            tankObject.Update(deltaTime);

            boxObject.Update(deltaTime);

            for (int i = 0; i < bulletObjects.Count; i++)
            {
                Vector3 facing = new Vector3(bulletObjects[i].LocalTransform.m1, bulletObjects[i].LocalTransform.m2, 1) * deltaTime * 250;
                bulletObjects[i].Translate(facing.x, facing.y);
                bulletObjects[i].Update(deltaTime);
            }


            for (int i = 0; i < bulletSprites.Count; i++)
            {
                if (bulletSprites[i].boxCollider.Overlaps(boxSprite.boxCollider))
                {
                    boxSprite.color = Color.YELLOW;

                    break;
                }
                else
                {
                    boxSprite.color = Color.BLUE;
                }
            }

            lastTime = currentTime;
        }