示例#1
0
        public AABB(Vector3[] listOfPoints)
        {
            Vector3 min = new Vector3(float.MaxValue, float.MaxValue, 0);
            Vector3 max = new Vector3(float.MinValue, float.MinValue, 0);

            foreach (var p in listOfPoints)
            {
                if (p.x < min.x)
                {
                    min.x = p.x;
                }
                if (p.y < min.y)
                {
                    min.y = p.y;
                }

                if (p.x > max.x)
                {
                    max.x = p.x;
                }
                if (p.y > max.y)
                {
                    max.y = p.y;
                }
            }

            // movePosition and recalculate halfExtent
            position   = (max + min) * 0.5f;
            halfExtent = (max - min) * 0.5f;
        }
示例#2
0
        public void AddPoint(Vector3 p)
        {
            Vector3 min = Min();
            Vector3 max = Max();

            if (p.x < min.x)
            {
                min.x = p.x;
            }
            if (p.y < min.y)
            {
                min.y = p.y;
            }

            if (p.x > max.x)
            {
                max.x = p.x;
            }
            if (p.y > max.y)
            {
                max.y = p.y;
            }

            // movePosition and recalculate halfExtent
            position   = (max + min) * 0.5f;
            halfExtent = (max - min) * 0.5f;
        }
示例#3
0
        public bool PointOverlapsMethod2(Vector3 p)
        {
            var mn = Min();
            var mx = Max();

            return(p.x < mx.x && p.x > mn.x && p.y < mx.y && p.y > mn.y);
        }
示例#4
0
        public bool PointOverlaps(Vector3 p)
        {
            Vector3 np = p - position;

            np.x = Math.Abs(np.x);
            np.y = Math.Abs(np.y);

            return(np.x < halfExtent.x && np.y < halfExtent.y);
        }
示例#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++;
            tankObject.Update(deltaTime);
            if (IsKeyDown(KeyboardKey.KEY_A))
            {
                tankObject.Rotate(-deltaTime);
            }
            if (IsKeyDown(KeyboardKey.KEY_D))
            {
                tankObject.Rotate(deltaTime);
            }
            if (IsKeyDown(KeyboardKey.KEY_W))
            {
                Vector3 facing = new Vector3(
                    tankObject.LocalTransform.m1,
                    tankObject.LocalTransform.m2, 1) * deltaTime * 100;
                tankObject.Translate(facing.x, facing.y);
            }
            if (IsKeyDown(KeyboardKey.KEY_S))
            {
                Vector3 facing = new Vector3(
                    tankObject.LocalTransform.m1,
                    tankObject.LocalTransform.m2, 1) * deltaTime * -100;
                tankObject.Translate(facing.x, facing.y);
            }
            tankObject.Update(deltaTime);

            lastTime = currentTime;
        }
示例#6
0
 public Missile(Texture2D texture, Vector3 posAndRot, string name = "New Sprite") : base(texture, posAndRot, name)
 {
 }
 public AsteroidSpawner(Texture2D texture, Vector3 posAndRot, List <Sprite> children, string name = "New Sprite") : base(texture, posAndRot, children, name)
 {
 }
 public AsteroidSpawner(Texture2D texture, Vector3 posAndRot, string name = "New Sprite") : base(texture, posAndRot, name)
 {
 }
示例#9
0
        /// <summary>
        /// check if "other" collider is intersecting with this collider
        /// </summary>
        public bool CheckCollision(Collider other)
        {
            collisionChecksPerFrame++;
            Vector3 center3      = new Vector3(center.X, center.Y, 0);
            Vector3 otherCenter3 = new Vector3(other.center.X, other.center.Y, 0);
            //distance between both objects
            float dist = (float)Math.Sqrt((otherCenter3.x - center3.x) * (otherCenter3.x - center3.x) + (otherCenter3.y - center3.y) * (otherCenter3.y - center3.y));
            //a maximum distance collisions need to be checked at
            float range = new Vector3(boxTransform.m1, boxTransform.m2, 0).Magnitude() + new Vector3(boxTransform.m4, boxTransform.m5, 0).Magnitude()
                          + new Vector3(other.boxTransform.m1, other.boxTransform.m2, 0).Magnitude() + new Vector3(other.boxTransform.m4, other.boxTransform.m5, 0).Magnitude();

            if (dist > range)
            {
                return(false);//stop check we already know the two objects are too faar apart
            }


            {//other in this
                Vector3 xExtent = new Vector3(boxTransform.m1, boxTransform.m2, 0);
                Vector3 yExtent = new Vector3(boxTransform.m4, boxTransform.m5, 0);

                {//other point A in this
                    Vector2 preV = other.pointA - center;
                    Vector3 v    = new Vector3(preV.X, preV.Y, 0);
#if ShowCollisionDebug
                    DrawLine((int)center.X, (int)center.Y, (int)other.pointA.X, (int)other.pointA.Y, RED);
#endif
                    collisionChecksPerFrame++;
                    if (!(Math.Sqrt(Math.Abs(v.Dot(xExtent))) > xExtent.Magnitude() || Math.Sqrt(Math.Abs(v.Dot(yExtent))) > yExtent.Magnitude()))
                    {
#if ShowCollisionDebug
                        DrawLine((int)center.X, (int)center.Y, (int)other.pointA.X, (int)other.pointA.Y, GREEN);
#endif
                        return(true);
                    }
                }

                {//other point B in this
                    Vector2 preV = other.pointB - center;
                    Vector3 v    = new Vector3(preV.X, preV.Y, 0);
#if ShowCollisionDebug
                    DrawLine((int)center.X, (int)center.Y, (int)other.pointB.X, (int)other.pointB.Y, RED);
#endif
                    collisionChecksPerFrame++;
                    if (!(Math.Sqrt(Math.Abs(v.Dot(xExtent))) > xExtent.Magnitude() || Math.Sqrt(Math.Abs(v.Dot(yExtent))) > yExtent.Magnitude()))
                    {
#if ShowCollisionDebug
                        DrawLine((int)center.X, (int)center.Y, (int)other.pointB.X, (int)other.pointB.Y, GREEN);
#endif
                        return(true);
                    }
                }

                {//other point C in this
                    Vector2 preV = other.pointC - center;
                    Vector3 v    = new Vector3(preV.X, preV.Y, 0);
#if ShowCollisionDebug
                    DrawLine((int)center.X, (int)center.Y, (int)other.pointC.X, (int)other.pointC.Y, RED);
#endif
                    collisionChecksPerFrame++;
                    if (!(Math.Sqrt(Math.Abs(v.Dot(xExtent))) > xExtent.Magnitude() || Math.Sqrt(Math.Abs(v.Dot(yExtent))) > yExtent.Magnitude()))
                    {
#if ShowCollisionDebug
                        DrawLine((int)center.X, (int)center.Y, (int)other.pointC.X, (int)other.pointC.Y, GREEN);
#endif
                        return(true);
                    }
                }

                {//other point D in this
                    Vector2 preV = other.pointD - center;
                    Vector3 v    = new Vector3(preV.X, preV.Y, 0);
#if ShowCollisionDebug
                    DrawLine((int)center.X, (int)center.Y, (int)other.pointD.X, (int)other.pointD.Y, RED);
#endif
                    collisionChecksPerFrame++;
                    if (!(Math.Sqrt(Math.Abs(v.Dot(xExtent))) > xExtent.Magnitude() || Math.Sqrt(Math.Abs(v.Dot(yExtent))) > yExtent.Magnitude()))
                    {
#if ShowCollisionDebug
                        DrawLine((int)center.X, (int)center.Y, (int)other.pointD.X, (int)other.pointD.Y, GREEN);
#endif
                        return(true);
                    }
                }
            }

            {//this in other
                Vector3 xExtent = new Vector3(other.boxTransform.m1, other.boxTransform.m2, 0);
                Vector3 yExtent = new Vector3(other.boxTransform.m4, other.boxTransform.m5, 0);
#if ShowCollisionDebug
                DrawLine((int)other.center.X, (int)other.center.Y, (int)other.center.X + (int)xExtent.x, (int)other.center.Y + (int)xExtent.y, DARKPURPLE);
                DrawLine((int)other.center.X, (int)other.center.Y, (int)other.center.X + (int)yExtent.x, (int)other.center.Y + (int)yExtent.y, DARKPURPLE);
#endif
                {//this point A in other
                    Vector2 preV = pointA - other.center;
                    Vector3 v    = new Vector3(preV.X, preV.Y, 0);
#if ShowCollisionDebug
                    DrawLine((int)other.center.X, (int)other.center.Y, (int)pointA.X, (int)pointA.Y, RED);
#endif
                    collisionChecksPerFrame++;
                    if (!(Math.Sqrt(Math.Abs(v.Dot(xExtent))) > xExtent.Magnitude() || Math.Sqrt(Math.Abs(v.Dot(yExtent))) > yExtent.Magnitude()))
                    {
#if ShowCollisionDebug
                        DrawLine((int)other.center.X, (int)other.center.Y, (int)pointA.X, (int)pointA.Y, GREEN);
#endif
                        return(true);
                    }
                }

                {//this point B in other
                    Vector2 preV = pointB - other.center;
                    Vector3 v    = new Vector3(preV.X, preV.Y, 0);
#if ShowCollisionDebug
                    DrawLine((int)other.center.X, (int)other.center.Y, (int)pointB.X, (int)pointB.Y, RED);
#endif
                    collisionChecksPerFrame++;
                    if (!(Math.Sqrt(Math.Abs(v.Dot(xExtent))) > xExtent.Magnitude() || Math.Sqrt(Math.Abs(v.Dot(yExtent))) > yExtent.Magnitude()))
                    {
#if ShowCollisionDebug
                        DrawLine((int)other.center.X, (int)other.center.Y, (int)pointB.X, (int)pointB.Y, GREEN);
#endif
                        return(true);
                    }
                }

                {//this point C in other
                    Vector2 preV = pointC - other.center;
                    Vector3 v    = new Vector3(preV.X, preV.Y, 0);
#if ShowCollisionDebug
                    DrawLine((int)other.center.X, (int)other.center.Y, (int)pointC.X, (int)pointC.Y, RED);
#endif
                    collisionChecksPerFrame++;
                    if (!(Math.Sqrt(Math.Abs(v.Dot(xExtent))) > xExtent.Magnitude() || Math.Sqrt(Math.Abs(v.Dot(yExtent))) > yExtent.Magnitude()))
                    {
#if ShowCollisionDebug
                        DrawLine((int)other.center.X, (int)other.center.Y, (int)pointC.X, (int)pointC.Y, GREEN);
#endif
                        return(true);
                    }
                }

                {//this point D in other
                    Vector2 preV = pointD - other.center;
                    Vector3 v    = new Vector3(preV.X, preV.Y, 0);
#if ShowCollisionDebug
                    DrawLine((int)other.center.X, (int)other.center.Y, (int)pointD.X, (int)pointD.Y, RED);
#endif
                    collisionChecksPerFrame++;
                    if (!(Math.Sqrt(Math.Abs(v.Dot(xExtent))) > xExtent.Magnitude() || Math.Sqrt(Math.Abs(v.Dot(yExtent))) > yExtent.Magnitude()))
                    {
#if ShowCollisionDebug
                        DrawLine((int)other.center.X, (int)other.center.Y, (int)pointD.X, (int)pointD.Y, GREEN);
#endif
                        return(true);
                    }
                }
            }

            return(false);
        }
 public LifePickup(Texture2D texture, Vector3 posAndRot, string name = "New Sprite") : base(texture, posAndRot, name)
 {
 }
示例#11
0
        // main program method
        public static int Main()
        {
            // Initialization
            //--------------------------------------------------------------------------------------

            // file name variables
            string tankFileName   = @"ref\tankBlue_outline.png";
            string turretFileName = @"ref\barrelBlue.png";

            InitWindow(screenWidth, screenHeight, "Tanks for Everything!");
            // set Frames-Per-Second and window size
            SetTargetFPS(60);

            // initialize classes
            Timer  timer  = new Timer();
            Game   game   = new Game();
            Tank   player = new Tank();
            Bullet bullet = new Bullet();

            //set array of bullets and assign index
            Bullet[] rockets = new Bullet[10];
            for (int i = 0; i < rockets.Length; ++i)
            {
                rockets[i] = new Bullet();
                rockets[i].LoadAmmo(bulletFile);
            }

            // assign tank in Bullet class to player tank
            Bullet.tank = player;

            // color conversion holding
            MathClasses.Vector3 colorVecBackground = ColorToHSV(LIGHTGRAY);
            Color backgroundColor = ColorFromHSV(colorVecBackground);

            // load player tank image and turret image
            player.Setup(tankFileName, turretFileName);

            // load bullet image
            bullet.LoadAmmo(bulletFile);

            //--------------------------------------------------------------------------------------

            // Main game loop
            while (!WindowShouldClose())    // Detect window close button or ESC key
            {
                // Update
                //----------------------------------------------------------------------------------

                float deltaTime = timer.DeltaTime;

                timer.Update();
                player.OnUpdate(deltaTime);
                bullet.OnUpdate(deltaTime);
                //update each rocket in the array
                foreach (Bullet rock in rockets)
                {
                    rock.OnUpdate(deltaTime);
                }

                // press "SPACEBAR" to shoot bullets out of tank barrel
                if (IsKeyPressed(KeyboardKey.KEY_SPACE))
                {
                    foreach (Bullet rock in rockets)
                    {
                        if (!rock.bulletActive)
                        {
                            // set bullet to active
                            rock.bulletActive = true;

                            // set rotate will reset position and scale values
                            rock.bulletObj.SetRotate(0.0f);

                            // set / start shooting position of bullet at turrets x and y after rotation reset
                            rock.bulletObj.SetPosition(Tank.turretObject.GlobalTransform.m7, Tank.turretObject.GlobalTransform.m8);

                            // get the rotation of the turret and fire in that direction
                            float firingAngle = (float)Math.Atan2(Tank.turretObject.GlobalTransform.m2, Tank.turretObject.GlobalTransform.m1);
                            rock.bulletObj.Rotate(-firingAngle);

                            // add 1 to "firing" count each time
                            amountOfBulletsFired++;

                            break;
                        }
                    }
                }


                //----------------------------------------------------------------------------------
                // Draw
                //----------------------------------------------------------------------------------

                BeginDrawing();

                ClearBackground(backgroundColor);

                // draws images to screen
                bullet.Draw();
                foreach (Bullet rock in rockets)
                {
                    rock.Draw();
                }
                player.Draw();

                // end game controls
                DrawText("Press the 'Esc' key to close window", 10, 20, 20, RED);

                // screen text for score, deltaTime, and time since game started
                DrawText("Time Since Start: " + GetTime().ToString("0.0"), 10, 40, 20, RED);
                DrawText("DeltaTime: " + timer.DeltaTime.ToString("0.000000"), 10, 60, 20, RED);
                DrawText("Targets Hit: " + score.ToString("0"), 600, 20, 20, BLUE);
                DrawText("Bullets Fired: " + amountOfBulletsFired.ToString("0"), 600, 40, 20, BLUE);

                EndDrawing();
                //----------------------------------------------------------------------------------
            }

            // De-Initialization
            //--------------------------------------------------------------------------------------
            game.Shutdown();                    // Close window and OpenGL context
            //--------------------------------------------------------------------------------------

            return(0);
        }
示例#12
0
        // int count = 1000;
        public void Update()
        {
            lastTime    = currentTime;
            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))
            {
                player.Rotate(-deltaTime);
                //tankRotation = new Matrix3(1.0f, 0.0f, tankPosition.x,
                //                        0.0f, 1.0f, tankPosition.y,
                //                        0.0f, 0.0f, 1.0f);
                //rotation += (-1 * DEG2RAD);
                //Matrix3 newRotation = new Matrix3();
                //newRotation.SetRotateZ(rotation * DEG2RAD);

                //   tankRotation = tankRotation * newRotation;

                // player.Rotate(-degrees, speed, deltaTime);
                //  player.RotateTank(-90 * (float)(Math.PI / 180.0f)); //deltaTime
            }
            if (IsKeyDown(KeyboardKey.KEY_D))
            {
                player.Rotate(deltaTime);
                //  player.RotateTank(90 * (float)(Math.PI / 180.0f));
                //tankRotation = new Matrix3(1.0f, 0.0f, tankPosition.x,
                //                        0.0f, 1.0f, tankPosition.y,
                //                        0.0f, 0.0f, 1.0f);
                //rotation += (1 * DEG2RAD);
                //Matrix3 newRotation = new Matrix3();
                //newRotation.SetRotateZ(rotation * DEG2RAD);

                //tankRotation = tankRotation * newRotation;
                // player.Rotate(degrees, speed, deltaTime);
            }
            if (IsKeyDown(KeyboardKey.KEY_W))
            {
                Vector3 facing = new Vector3(player.localTransform.m1, player.localTransform.m2, 1) * deltaTime * 100;
                player.Translate(facing.x, facing.y);

                //player.Move(new Vector3(0, 1, 1), speed, deltaTime);
                //Vector3 newPos = tankRotation * new Vector3(0, 1, 1) * speed * deltaTime;
                //tankPosition = tankPosition + newPos;
            }
            if (IsKeyDown(KeyboardKey.KEY_S))
            {
                Vector3 facing = new Vector3(player.localTransform.m1, player.localTransform.m2, 1) * deltaTime * -100;
                player.Translate(facing.x, facing.y);
                // player.Move(new Vector3(0, -1, 1), speed, deltaTime);
                //Vector3 newPos = tankRotation * new Vector3(0, -1, 1) * speed * deltaTime;
                //tankPosition = tankPosition + newPos;
                //Vector3 newGunPos = gunRotation * new Vector3(0, -1, 1) * speed * deltaTime;
                //gunPosition = gunPosition + newGunPos;
            }
        }
示例#13
0
        public void Update()
        {
            lastTime    = currentTime;
            currentTime = stopwatch.ElapsedMilliseconds;
            deltaTime   = (currentTime - lastTime) / 1000.0f;
            timer      += deltaTime;
            if (timer >= 1)
            {
                fps    = frames;
                frames = 0;
                timer -= 1;
            }
            frames++;

            // insert game logic here
            if (IsKeyDown(KeyboardKey.KEY_Q))
            {
                gunObject.Rotate(-deltaTime);
            }
            if (IsKeyDown(KeyboardKey.KEY_E))
            {
                gunObject.Rotate(deltaTime);
            }
            if (IsKeyDown(KeyboardKey.KEY_A))
            {
                tankObject.Rotate(-deltaTime);
            }
            if (IsKeyDown(KeyboardKey.KEY_D))
            {
                tankObject.Rotate(deltaTime);
            }
            if (IsKeyDown(KeyboardKey.KEY_W))
            {
                Vector3 facing = tankObject.Forward * deltaTime * 100;
                tankObject.Translate(facing.x, facing.y);
            }
            if (IsKeyDown(KeyboardKey.KEY_S))
            {
                Vector3 facing = tankObject.Forward * deltaTime * -100;
                tankObject.Translate(facing.x, facing.y);
            }
            if (IsKeyDown(KeyboardKey.KEY_SPACE) && bulletCooldown <= 0)
            {
                bulletTexture.isHit = false;
                bulletObject.UpdateAllTransforms(gunObject.globalTransform);
                bulletObject.SetPosition(gunTexture.globalTransform.m7, gunTexture.globalTransform.m8);
                bulletDirection = new Vector3(gunObject.globalTransform.m1, gunObject.globalTransform.m2, bulletDirection.z);

                bulletCooldown = intialBulletCountdown;
            }
            if (bulletCooldown > 0 && !bulletTexture.isHit)
            {
                if (Collisions.CheckCollision(bulletTexture, wallTexture) && !wallTexture.isHit)
                {
                    positionWall();
                    while (Collisions.CheckCollision(tankTexture, wallTexture))
                    {
                        positionWall();
                    }
                    //wallTexture.isHit = true;
                    bulletTexture.isHit = true;
                }
                bulletObject.Translate(bulletDirection.x * bulletSpeed, bulletDirection.y * bulletSpeed);
                bulletCooldown -= deltaTime;
            }
            if (bulletTexture.isHit)
            {
                bulletCooldown      = -1f;
                bulletTexture.isHit = false;
            }
        }
示例#14
0
        public void Move(Vector3 movement, float speed, float deltaTime)
        {
            //Vector3 newPos = transform * movement * speed * deltaTime;
            //transform.m3 += newPos.x;
            //transform.m6 += newPos.y;
            //transform.m9 = 1;

            //UpdateGunTransform();


            //tankTranslation = new Matrix3(1.0f, 0.0f, transform.m3,
            //                             0.0f, 1.0f, transform.m6,
            //                             0.0f, 0.0f, transform.m9);
            //tankRotation = new Matrix3();
            //tankRotation.SetRotateZ(rotation * DEG2RAD);

            //Matrix3 mat = tankTranslation * tankRotation;
            //transform = tankRotation * transform;
            // Vector3 newPos = mat * new Vector3(0, movement.y, 1) * speed * deltaTime;

            /*  tankTranslation = new Matrix3(1.0f, 0.0f, position.x,
             *                           0.0f, 1.0f, position.y,
             *                           0.0f, 0.0f, position.z);
             * tankRotation = new Matrix3();
             * tankRotation.SetRotateZ(rotation * DEG2RAD);
             * // tankMatrix= tankMatrix
             * Console.WriteLine("tankRotation");
             * Console.WriteLine(tankRotation.ToString());
             *
             * Matrix3 mat = tankTranslation * tankRotation;
             * transform = tankRotation * transform;
             * Vector3 newPos = mat * new Vector3(0, movement.y, 1) * speed * deltaTime;
             * position = position + newPos;*/



            //  topGun.UpdateGunTransform(mat);
            //  ContrainToScreen();


            /*
             *  tankTranslation = new Matrix3(1.0f, 0.0f, position.x,
             *                           0.0f, 1.0f, position.y,
             *                           0.0f, 0.0f, position.z);
             * tankRotation = new Matrix3();
             * tankRotation.SetRotateZ(rotation * DEG2RAD);
             * Console.WriteLine("tankRotation");
             * Console.WriteLine(tankRotation.ToString());
             *
             * Matrix3 mat = tankTranslation * tankRotation;
             * Vector3 newPos = mat * new Vector3(0, movement.y , 1) * speed * deltaTime;
             * position = position + newPos;
             *
             *
             * gunTranslation = new Matrix3(1.0f, 0.0f, gunPositionOffset.x,
             *                          0.0f, 1.0f, gunPositionOffset.y,
             *                          0.0f, 0.0f, gunPositionOffset.z);
             * gunRotation = new Matrix3();
             * gunRotation.SetRotateZ(rotation * DEG2RAD);
             *
             * Matrix3 gunMat = gunTranslation * gunRotation;
             *
             * gunMatrix = mat * gunMat;
             *
             * Vector3 newPosGun = gunMatrix * new Vector3(0, movement.y, 1) * speed * deltaTime;
             * gunPosition = gunPosition+ newPosGun;
             */
        }
示例#15
0
 public Missile(Texture2D texture, Vector3 posAndRot, List <Sprite> children, string name = "New Sprite") : base(texture, posAndRot, children, name)
 {
 }
 public TimedObject(Texture2D texture, Vector3 posAndRot, string name = "New Sprite") : base(texture, posAndRot, name)
 {
 }
        public override void Update()
        {
            if (!gameOver)
            {
                base.Update();
                if (IsKeyDown(KeyboardKey.KEY_W))
                {
                    //apply forward thrust
                    Vector3 direction = new Vector3(transform.m2, -transform.m5, 0);
                    direction.Normalize();
                    collider.velocity += direction * (acceleration * GetFrameTime());

                    //keep velocity at a max
                    float speed = MathF.Abs(MathF.Sqrt(MathF.Pow(collider.velocity.x, 2) + MathF.Pow(collider.velocity.y, 2)));
                    if (speed > maxSpeed)
                    {
                        float maxSpeedPercent = maxSpeed / speed;
                        collider.velocity.x *= maxSpeedPercent;
                        collider.velocity.y *= maxSpeedPercent;
                    }

                    //show flame comming out main thruster
                    foreach (Sprite s in children)
                    {
                        if (s.objectName == "Thrust")
                        {
                            s.visable = true;
                        }
                    }
                }
                else
                {
                    //hide flame comming out main thruster
                    foreach (Sprite s in children)
                    {
                        if (s.objectName == "Thrust")
                        {
                            s.visable = false;
                        }
                    }
                }

                //rotate ship
                if (IsKeyDown(KeyboardKey.KEY_A))
                {
                    Rotation -= rotationSpeed * GetFrameTime();
                    //show flame comming out side thruster
                    foreach (Sprite s in children)
                    {
                        if (s.objectName == "ThrustA")
                        {
                            s.visable = true;
                        }
                    }
                }
                else
                {
                    //hide flame comming out side thruster
                    foreach (Sprite s in children)
                    {
                        if (s.objectName == "ThrustA")
                        {
                            s.visable = false;
                        }
                    }
                }
                if (IsKeyDown(KeyboardKey.KEY_D))
                {
                    Rotation += rotationSpeed * GetFrameTime();
                    //show flame comming out side thruster
                    foreach (Sprite s in children)
                    {
                        if (s.objectName == "ThrustD")
                        {
                            s.visable = true;
                        }
                    }
                }
                else
                {
                    //hide flame comming out side thruster
                    foreach (Sprite s in children)
                    {
                        if (s.objectName == "ThrustD")
                        {
                            s.visable = false;
                        }
                    }
                }

                //count down for fire rate
                if (curTime > 0)
                {
                    curTime -= GetFrameTime();
                }

                //fire new missile
                if (curTime <= 0 && IsKeyDown(KeyboardKey.KEY_SPACE))
                {
                    Missile m = new Missile(textures["Missile"], new Vector3(transform.m7, transform.m8, Rotation), new List <Sprite> {
                        new ParticleSystem(textures["Square"], new Vector2(0, 0), "MissileParticles")
                        {
                            color = Fade(YELLOW, 0.2f), lifeTime = 2, scale = new Vector2(5, 5), minVelocity = new Vector2(-10, -10), maxVelocity = new Vector2(10, 10)
                        },
                        new ParticleSystem(textures["Square"], new Vector2(0, 150), "MissileParticles")
                        {
                            color = Fade(YELLOW, 0.2f), lifeTime = 2, scale = new Vector2(5, 5), minVelocity = new Vector2(-10, -10), maxVelocity = new Vector2(10, 10)
                        },
                        new ParticleSystem(textures["Square"], new Vector2(0, 50), "MissileParticles")
                        {
                            color = Fade(YELLOW, 0.2f), lifeTime = 2, scale = new Vector2(5, 5), minVelocity = new Vector2(-10, -10), maxVelocity = new Vector2(10, 10)
                        },
                        new ParticleSystem(textures["Square"], new Vector2(0, 100), "MissileParticles")
                        {
                            color = Fade(YELLOW, 0.2f), lifeTime = 2, scale = new Vector2(5, 5), minVelocity = new Vector2(-10, -10), maxVelocity = new Vector2(10, 10)
                        }
                    }, "Missile")
                    {
                        Scale = 0.3f
                    };
                    NewObject(m);
                    Vector3 direction = new Vector3(transform.m2, -transform.m5, 0);
                    direction.Normalize();
                    m.Translate(direction * 50);
                    m.collider.velocity = direction * 500;
                    curTime             = shotTimer;
                }
            }
            //screen wrap
            if (transform.m7 > 1650)
            {
                transform.m7 = -30;
            }
            if (transform.m7 < -50)
            {
                transform.m7 = 1630;
            }
            if (transform.m8 > 950)
            {
                transform.m8 = -30;
            }
            if (transform.m8 < -50)
            {
                transform.m8 = 930;
            }

            //end the game
            if (health <= 0)
            {
                gameOver = true;
            }

            //reset game
            if (gameOver && IsMouseButtonPressed(MouseButton.MOUSE_LEFT_BUTTON))
            {
                foreach (Sprite s in objects)
                {
                    if (s.objectName == "Asteroid" || s.objectName == "Missile" || s.objectName == "LifePickup")
                    {
                        Destroy(s);
                    }
                }
                health            = 3;
                gameOver          = false;
                score             = 0;
                Rotation          = 180;
                collider.velocity = new Vector3(0, 0, 0);
                transform.m7      = 800;
                transform.m8      = 450;
            }
        }