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
        public void Update(float deltaTime)
        {
            SetBody(bodyPick);
            SetGun(gunPick);
            if (reload < reloading) { reload++; loadColor = Color.LIME; }
            else { reload = reloading; loadColor = Color.GREEN; }

            tankObject.Update(deltaTime);

            tankTL.SetPosition(-tankSprite.Height / 2, -tankSprite.Width / 2);
            tankTR.SetPosition(tankSprite.Height / 2, -tankSprite.Width / 2);
            tankBR.SetPosition(tankSprite.Height / 2, tankSprite.Width / 2);
            tankBL.SetPosition(-tankSprite.Height / 2, tankSprite.Width / 2);

            tankObject.myPoints[0] = new Vector3(tankTL.position.x - tankObject.position.x, tankTL.position.y - tankObject.position.y, tankTL.GlobalTransform.m9);
            tankObject.myPoints[1] = new Vector3(tankTR.position.x - tankObject.position.x, tankTR.position.y - tankObject.position.y, tankTR.GlobalTransform.m9);
            tankObject.myPoints[2] = new Vector3(tankBR.position.x - tankObject.position.x, tankBR.position.y - tankObject.position.y, tankBR.GlobalTransform.m9);
            tankObject.myPoints[3] = new Vector3(tankBL.position.x - tankObject.position.x, tankBL.position.y - tankObject.position.y, tankBL.GlobalTransform.m9);

            shotFX.SetPosition((turretSprite.Width / 2.0f) + gun.Offset.y, turretSprite.Height);
            shotSprite.SetPosition(-(shotSprite.Width / 2.0f), 0);
        }
Ejemplo n.º 4
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.º 5
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.º 6
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.º 7
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;
        }