Exemplo 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;
        }
Exemplo n.º 2
0
        public SceneObject()
        {
            if (parent != null)
            {
                parent.RemoveChild(this);
            }

            foreach (SceneObject so in children)
            {
                so.parent = null;
            }
        }
Exemplo n.º 3
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);
            }
        }
Exemplo n.º 4
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);
            }
        }
Exemplo n.º 5
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);
            }
        }
Exemplo n.º 6
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);
            }
        }
Exemplo 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;
        }