Exemplo n.º 1
0
        public void Init()
        {
            stopwatch.Start();
            lastTime = stopwatch.ElapsedMilliseconds;

            //Load and position the tank
            tankSprite.Load("tankBlue_outline.png");
            tankSprite.SetRotate(-90 * (float)(Math.PI / 180.0f));
            tankSprite.SetPosition(-tankSprite.Width / 2.0f, tankSprite.Height / 2.0f);

            //Load and position the green bullet to make the sprite go straight of the turrent
            bulletSprite.Load("bulletGreenSilver_outline.png");
            bulletSprite.SetRotate(90 * (float)(Math.PI / 180.0f));
            bulletSprite.imgScale = 0.5f;

            //Load and position the turret
            turrentSprite.Load("barrelBlue.png");
            turrentSprite.SetRotate(-90 * (float)(Math.PI / 180.0f));
            turrentSprite.SetPosition(0, turrentSprite.Width / 2.0f);

            //Add child to the parent
            bulletObject.AddChild(bulletSprite);
            turrentObject.AddChild(turrentSprite);
            tankObject.AddChild(tankSprite);
            tankObject.AddChild(turrentObject);

            //Set the position of the tank in the middle
            tankObject.SetPosition(rl.GetScreenWidth() / 2.0f, rl.GetScreenHeight() / 2.0f);
        }
Exemplo n.º 2
0
        /// <summary>
        /// This function initialiazes the bullets so they can be fired.
        /// </summary>
        public void Shoot()
        {
            SceneObject        bullet       = new SceneObject();
            SpriteObject       sprite       = new SpriteObject();
            List <SceneObject> HitBoxPoints = new List <SceneObject>(4);

            //This is where the bullets' sprites are initialized.
            sprite.Load("barrelBlue.png");
            sprite.SetRotate(-90 * (float)(Math.PI / 180f));
            sprite.SetPosition(0, sprite.Width / 2f);

            //This is where the bullets' corners are listed for the purpose of creating an AABB.
            for (int i = 0; i < HitBoxPoints.Capacity; i++)
            {
                HitBoxPoints.Add(new SceneObject());
            }
            HitBoxPoints[0].SetPosition(0, -sprite.Width / 2f);
            HitBoxPoints[1].SetPosition(sprite.Height, -sprite.Width / 2f);
            HitBoxPoints[2].SetPosition(sprite.Height, sprite.Width / 2f);
            HitBoxPoints[3].SetPosition(0, sprite.Width / 2f);

            //This is where the bullets are put togather.
            bullet.AddChild(sprite);
            bullet.SetRotate(turretObject.GlobalTransform.GetRotateZ());
            bullet.SetPosition(turretObject.GlobalTransform.m7, turretObject.GlobalTransform.m8);
            for (int i = 0; i < HitBoxPoints.Count; i++)
            {
                bullet.AddChild(HitBoxPoints[i]);
            }
            bulletObject.Add(bullet);
        }
Exemplo n.º 3
0
        public void Init()
        {
            SetTargetFPS(60);
            stopwatch.Start();
            lastTime = stopwatch.ElapsedMilliseconds;

            Hierarchy.Add(shellObject);
            Hierarchy.Add(tankObject);


            tankSprite.Load("tankblue_outline.png");
            //tankSprite.SetRotate(-90 * (float)(Math.PI / 180.0f));
            //tankSprite.SetPosition(-tankSprite.Width / 2.0f, tankSprite.Height / 2.0f);

            turretSprite.Load("barrelBlue.png");
            turretSprite.SetPosition(0, 0);
            //turretSprite.SetRotate(-90 * (float)(Math.PI / 180.0f));
            //turretSprite.SetPosition(turretSprite.Width / 2.0f, 0);
            turretSprite.SetPosition(25, 0);

            shellSprite.Load("TankGameshell.png");


            turretObject.AddChild(turretSprite);
            tankObject.AddChild(tankSprite);
            tankObject.AddChild(turretObject); // TODO: put this back

            tankObject.SetPosition(GetScreenWidth() / 2.0f, GetScreenHeight() / 2.0f);
        }
Exemplo n.º 4
0
        public void Init(List<Body> bodys, List<Barrel> barels, int player)
        {
            bodies = bodys; barrels = barels;
            bodyPick = 0;
            gunPick = 0;
            SetBody(0);
            SetGun(0);
            reload = reloading;
            armor = maxArmor;

            if (player == 1) { tankObject.SetRotate(0); }
            if (player == 2) { tankObject.SetRotate(180 * (float)(Math.PI / 180.0f)); }
            tankSprite.SetRotate(-90 * (float)(Math.PI / 180.0f));
            tankSprite.SetPosition(-tankSprite.Width / 2.0f, tankSprite.Height / 2.0f);

            turretSprite.SetRotate(-90 * (float)(Math.PI / 180.0f));
            turretSprite.SetPosition(-10, turretSprite.Width / 2.0f);

            tankObject.AddChild(tankSprite);
            tankObject.AddChild(turretObject);
            turretObject.AddChild(turretSprite);
            turretObject.AddChild(turretSprite);

            tankObject.AddChild(tankTL);
            tankObject.AddChild(tankTR);
            tankObject.AddChild(tankBL);
            tankObject.AddChild(tankBR);
            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.Add(tankTL.position);
            tankObject.myPoints.Add(tankTR.position);
            tankObject.myPoints.Add(tankBR.position);
            tankObject.myPoints.Add(tankBL.position);

            turretSprite.AddChild(shotFX);
            shotSprite.Load("Resources/shotLarge.png");
            shotFX.AddChild(shotSprite);
            shotFX.SetPosition(turretSprite.Width / 2.0f, turretSprite.Height);
            shotSprite.SetPosition(-(shotSprite.Width / 2.0f), 0);
        }
Exemplo n.º 5
0
 void SetBody(int b)
 {
     if (body != bodies[b])
     {
         body = bodies[b];
         maxArmor = bodies[b].Armor;
         tankSprite.Load(bodies[b].Tex);
         tankSprite.SetPosition(-tankSprite.Height / 2, tankSprite.Width / 2);
         turretObject.SetPosition(body.BarrelPlace, 0);
     }
 }
Exemplo n.º 6
0
        public void Init()
        {
            stopwatch.Start();
            lastTime = stopwatch.ElapsedMilliseconds;


            tankSprite.Load("tankBlue_outline.png");                                    //This loads the image of the tank's body
            tankSprite.SetRotate(-90 * (float)(Math.PI / 180.0f));                      //This tells command to have ths image rotated by -90 degrees.
            tankSprite.SetPosition(-tankSprite.Width / 2.0f, tankSprite.Height / 2.0f); //This sets the tank's starting position to
                                                                                        //it's sprite's width and height.

            tankSprite.corners[0].SetPosition(tankSprite.Width / 2 + 41, tankSprite.Height / 2 + 40);
            tankSprite.corners[1].SetPosition(-tankSprite.Width / 2 + 41, tankSprite.Height / 2 + 40);
            tankSprite.corners[2].SetPosition(tankSprite.Width / 2 + 41, -tankSprite.Height / 2 + 40);
            tankSprite.corners[3].SetPosition(-tankSprite.Width / 2 + 41, -tankSprite.Height / 2 + 40);


            turretSprite.Load("barrelBlue.png");                                            //This loads the image of the tank's barrel
            turretSprite.SetRotate(-90 * (float)(Math.PI / 180.0f));                        //This tells command to have ths image rotated by -90 degrees.
            turretSprite.SetPosition(turretSprite.Width / 1.5f, turretSprite.Width / 2.0f); //This sets the tank's starting position to
                                                                                            //it's sprite's width and height.

            turretSprite.corners[0].SetPosition(turretSprite.Width / 2, turretSprite.Height / 2);
            turretSprite.corners[1].SetPosition(-turretSprite.Width / 2 + 10, turretSprite.Height / 2 + 10);
            turretSprite.corners[2].SetPosition(turretSprite.Width / 2 + 8, -turretSprite.Height / 2 + 1);
            turretSprite.corners[3].SetPosition(-turretSprite.Width / 2 + 10, -turretSprite.Height / 2 + 10);


            boxSprite.SetPosition(boxSprite.Width / 2, boxSprite.Height / 2);

            boxSprite.corners[0].SetPosition(40, 40);
            boxSprite.corners[1].SetPosition(-40, 40);
            boxSprite.corners[2].SetPosition(40, -40);
            boxSprite.corners[3].SetPosition(-40, -40);


            tankObject.AddChild(tankSprite);     //This makes "tankObject" become the parent of "tankSprite"
            tankObject.AddChild(turretObject);   //This makes "tankObject" become the parent of "turretObject"
            turretObject.AddChild(turretSprite); //This makes "turretObject" become the parent of "tankSprite"
            boxObject.AddChild(boxSprite);

            boxObject.SetPosition(500, 240);
            tankObject.SetPosition(GetScreenWidth() / 2.0f, GetScreenHeight() / 2.0f); //This sets the tankObject's position to the
                                                                                       //Screen's Width and Height.
        }
Exemplo n.º 7
0
        public void Init()
        {
            stopwatch.Start();
            lastTime = stopwatch.ElapsedMilliseconds;

            tankSprite.Load("tankblue_outline.png");
            tankSprite.SetRotate(-90 * (float)(Math.PI / 180.0f));
            tankSprite.SetPosition(-tankSprite.Width / 2.0f, tankSprite.Height / 2.0f);

            turretSprite.Load("barrelBlue.png");
            turretSprite.SetRotate(-90 * (float)(Math.PI / 180.0f));
            turretSprite.SetPosition(0, turretSprite.Width / 2.0f);

            turretObject.AddChild(turretSprite);
            tankObject.AddChild(tankSprite);
            tankObject.AddChild(turretObject);
            tankObject.SetPosition(GetScreenWidth() / 2.0f, GetScreenHeight() / 2.0f);
        }
Exemplo n.º 8
0
        public void Init()
        {
            stopwatch.Start();
            lastTime = stopwatch.ElapsedMilliseconds;



            tankSprite.Load("tankBlue_outline.png");
            tankSprite.SetRotate(-90 * (float)(Math.PI / 180.0f));
            tankSprite.SetPosition(-tankSprite.Width / 2.0f, tankSprite.Height / 2.0f);

            tankHitboxPoint1.SetPosition(-tankSprite.Width / 2.0f, -tankSprite.Height / 2.0f);
            tankHitboxPoint2.SetPosition(tankSprite.Width / 2.0f, -tankSprite.Height / 2.0f);
            tankHitboxPoint3.SetPosition(tankSprite.Width / 2.0f, tankSprite.Height / 2.0f);
            tankHitboxPoint4.SetPosition(-tankSprite.Width / 2.0f, tankSprite.Height / 2.0f);

            turretSprite.Load("barrelBlue.png");
            turretSprite.SetRotate(-90 * (float)(Math.PI / 180.0f));
            turretSprite.SetPosition(0, turretSprite.Width / 2.0f);

            bulletSprite.Load("FriendBullet.png");
            bulletSprite.SetRotate(-90 * (float)(Math.PI / 180f));
            bulletSprite.SetPosition(50, bulletSprite.Width / 2.0f);

            turretObject.AddChild(turretSprite);
            tankObject.AddChild(tankSprite);
            bulletObject.AddChild(bulletSprite);
            tankObject.AddChild(turretObject);
            tankHitboxPoint1.AddChild(bulletObject);
            tankHitboxPoint2.AddChild(bulletObject);
            tankHitboxPoint3.AddChild(bulletObject);
            tankHitboxPoint4.AddChild(bulletObject);
            tankObject.AddChild(tankHitboxPoint1);
            tankObject.AddChild(tankHitboxPoint2);
            tankObject.AddChild(tankHitboxPoint3);
            tankObject.AddChild(tankHitboxPoint4);
            tankObject.SetPosition(GetScreenWidth() / 2.0f, GetScreenHeight() / 2.0f);
        }
Exemplo n.º 9
0
        /// <summary>
        /// This intializes the game.
        /// </summary>
        public void Init()
        {
            stopwatch.Start();
            lastTime = stopwatch.ElapsedMilliseconds;

            //Here is where the tank sprite is initialized.
            tankSprite.Load("tankBlue_outline.png");
            tankSprite.SetRotate(-90 * (float)(Math.PI / 180f));
            tankSprite.SetPosition(-tankSprite.Width / 2f, tankSprite.Height / 2f);

            //Here is where the barrel sprite is initialized.
            turretSprite.Load("barrelBlue.png");
            turretSprite.SetRotate(-90 * (float)(Math.PI / 180f));
            turretSprite.SetPosition(0, turretSprite.Width / 2f);

            //This is where the points used to fit the tank's AABB are set up.
            for (int i = 0; i < tankHitBoxPoint.Capacity; i++)
            {
                tankHitBoxPoint.Add(new SceneObject());
            }
            tankHitBoxPoint[0].SetPosition(-tankSprite.Width / 2f, (-tankSprite.Height / 2f) - 4);
            tankHitBoxPoint[1].SetPosition((tankSprite.Width / 2f) - 4, (-tankSprite.Height / 2f) - 4);
            tankHitBoxPoint[2].SetPosition((tankSprite.Width / 2f) - 4, tankSprite.Height / 2f);
            tankHitBoxPoint[3].SetPosition(-tankSprite.Width / 2f, tankSprite.Height / 2f);

            //Here is where the individual parts of the tank are put together by adding them to the main object as children.
            turretObject.AddChild(turretSprite);
            tankObject.AddChild(tankSprite);
            tankObject.AddChild(turretObject);
            for (int i = 0; i < tankHitBoxPoint.Count; i++)
            {
                tankObject.AddChild(tankHitBoxPoint[i]);
            }

            tankObject.SetPosition(GetScreenWidth() / 2f, GetScreenHeight() / 2f);
        }
Exemplo n.º 10
0
        public void Init()
        {
            //P1

            tankSprite1.Load("Resources/topdowntanks/PNG/Tanks/tankGreen_outline.png");
            // sprite is facing the wrong way... fix that here
            tankSprite1.SetRotate(-90 * (float)(Math.PI / 180.0f));
            // sets an offset for the base, so it rotates around the centre
            tankSprite1.SetPosition(-tankSprite1.Width / 2.0f, tankSprite1.Height / 2.0f);

            turretSprite1.Load("Resources/topdowntanks/PNG/Tanks/barrelGreen.png");
            turretSprite1.SetRotate(-90 * (float)(Math.PI / 180.0f));
            // set the turret offset from the tank base
            turretSprite1.SetPosition(0, turretSprite1.Width / 2.0f);

            // set up the scene object hierarchy - parent the turret to the base,
            // then the base to the tank sceneObject
            turretObject1.AddChild(turretSprite1);
            tankObject1.AddChild(tankSprite1);
            tankObject1.AddChild(turretObject1);
            tankObject1.AddChild(tankHitBoxTL1);
            tankObject1.AddChild(tankHitBoxTR1);
            tankObject1.AddChild(tankHitBoxBR1);
            tankObject1.AddChild(tankHitBoxBL1);

            tankObject1.SetPosition((GetScreenWidth() / 2.0f) - 100f, GetScreenHeight() / 2.0f);

            tankHitBoxTL1.SetPosition((-tankSprite1.Height / 2.0f), -tankSprite1.Width / 2.0f);    //(0,0)
            tankHitBoxTR1.SetPosition((-tankSprite1.Height / 2.0f), tankSprite1.Width / 2.0f);     //(1,0)
            tankHitBoxBR1.SetPosition((tankSprite1.Height / 2.0f), tankSprite1.Width / 2.0f);      //(1,1)
            tankHitBoxBL1.SetPosition((tankSprite1.Height / 2.0f), -tankSprite1.Width / 2.0f);     //(0,1)

            tank1.MyTankPoints.Add(new Vector2(tankHitBoxTL1.Position.x, tankHitBoxTL1.Position.y));
            tank1.MyTankPoints.Add(new Vector2(tankHitBoxTR1.Position.x, tankHitBoxTR1.Position.y));
            tank1.MyTankPoints.Add(new Vector2(tankHitBoxBR1.Position.x, tankHitBoxBR1.Position.y));
            tank1.MyTankPoints.Add(new Vector2(tankHitBoxBL1.Position.x, tankHitBoxBL1.Position.y));

            //P1 Bullet
            tankBulletSprite1.Load("Resources/topdowntanks/PNG/Bullets/bulletGreen.png");
            tankBulletSprite1.SetRotate(-90 * (float)(Math.PI / 180.0f));
            tankBulletSprite1.SetPosition(-tankBulletSprite1.Width / 2.0f, tankBulletSprite1.Height / 2.0f);
            tankBulletObject1.AddChild(tankBulletSprite1);
            tankBulletObject1.AddChild(tankBulletHitBoxTL1);
            tankBulletObject1.AddChild(tankBulletHitBoxTR1);
            tankBulletObject1.AddChild(tankBulletHitBoxBR1);
            tankBulletObject1.AddChild(tankBulletHitBoxBL1);

            tankBulletObject1.SetPosition((GetScreenWidth() / 2.0f) - 100f, GetScreenHeight() / 2.0f);

            tankBulletHitBoxTL1.SetPosition((-tankBulletSprite1.Height / 2.0f), -tankBulletSprite1.Width / 2.0f);    //(0,0)
            tankBulletHitBoxTR1.SetPosition((-tankBulletSprite1.Height / 2.0f), tankBulletSprite1.Width / 2.0f);     //(1,0)
            tankBulletHitBoxBR1.SetPosition((tankBulletSprite1.Height / 2.0f), tankBulletSprite1.Width / 2.0f);      //(1,1)
            tankBulletHitBoxBL1.SetPosition((tankBulletSprite1.Height / 2.0f), -tankBulletSprite1.Width / 2.0f);     //(0,1)

            tankBullet1.MyTankPoints.Add(new Vector2(tankBulletHitBoxTL1.Position.x, tankBulletHitBoxTL1.Position.y));
            tankBullet1.MyTankPoints.Add(new Vector2(tankBulletHitBoxTR1.Position.x, tankBulletHitBoxTR1.Position.y));
            tankBullet1.MyTankPoints.Add(new Vector2(tankBulletHitBoxBR1.Position.x, tankBulletHitBoxBR1.Position.y));
            tankBullet1.MyTankPoints.Add(new Vector2(tankBulletHitBoxBL1.Position.x, tankBulletHitBoxBL1.Position.y));

            //P2

            tankSprite2.Load("Resources/topdowntanks/PNG/Tanks/tankBlue_outline.png");
            tankSprite2.SetRotate(-90 * (float)(Math.PI / 180.0f));
            tankSprite2.SetPosition(-tankSprite2.Width / 2.0f, tankSprite2.Height / 2.0f);
            turretSprite2.Load("Resources/topdowntanks/PNG/Tanks/barrelBlue.png");
            turretSprite2.SetRotate(-90 * (float)(Math.PI / 180.0f));
            turretSprite2.SetPosition(0, turretSprite2.Width / 2.0f);
            turretObject2.AddChild(turretSprite2);
            tankObject2.AddChild(tankSprite2);
            tankObject2.AddChild(turretObject2);
            tankObject2.AddChild(tankHitBoxTL2);
            tankObject2.AddChild(tankHitBoxTR2);
            tankObject2.AddChild(tankHitBoxBR2);
            tankObject2.AddChild(tankHitBoxBL2);
            tankObject2.SetPosition((GetScreenWidth() / 2.0f) + 100f, GetScreenHeight() / 2.0f);

            tankHitBoxTL2.SetPosition((-tankSprite2.Height / 2.0f), -tankSprite2.Width / 2.0f);    //(0,0)
            tankHitBoxTR2.SetPosition((-tankSprite2.Height / 2.0f), tankSprite2.Width / 2.0f);     //(1,0)
            tankHitBoxBR2.SetPosition((tankSprite2.Height / 2.0f), tankSprite2.Width / 2.0f);      //(1,1)
            tankHitBoxBL2.SetPosition((tankSprite2.Height / 2.0f), -tankSprite2.Width / 2.0f);     //(0,1)

            tank2.MyTankPoints.Add(new Vector2(tankHitBoxTL2.Position.x, tankHitBoxTL2.Position.y));
            tank2.MyTankPoints.Add(new Vector2(tankHitBoxTR2.Position.x, tankHitBoxTR2.Position.y));
            tank2.MyTankPoints.Add(new Vector2(tankHitBoxBR2.Position.x, tankHitBoxBR2.Position.y));
            tank2.MyTankPoints.Add(new Vector2(tankHitBoxBL2.Position.x, tankHitBoxBL2.Position.y));
        }
Exemplo n.º 11
0
        public void Init()
        {
            stopwatch.Start();
            lastTime = stopwatch.ElapsedMilliseconds;

            InitAudioDevice();
            snd_drive  = LoadSound("Resources/Sound/drive.ogg");
            snd_rotate = LoadSound("Resources/Sound/rotate.ogg");
            snd_fire   = LoadSound("Resources/Sound/fire.ogg");
            snd_load   = LoadSound("Resources/Sound/reload.ogg");


            for (int p = 0; p < 9; p++)
            {
                float b = (obsPositions.Length / 2);
                float c = p - b;
                obsPositions[p] = new Vector3((GetScreenWidth() / 2) + (p * 64) - (b * 64), (GetScreenHeight() / 2) + (((float)Math.Pow(c, 3)) + (9 * c)), 0);
            }

            Texture2D body1     = LoadTexture("Resources/tankBody_blue_outline.png");
            Texture2D body1a    = LoadTexture("Resources/tankBody_red_outline.png");
            Texture2D body2     = LoadTexture("Resources/tankBody_darkLarge_outline.png");
            Texture2D body3     = LoadTexture("Resources/tankBody_huge_outline.png");
            Texture2D bodyS     = LoadTexture("Resources/tankBody_dark.png");
            Texture2D barrel1   = LoadTexture("Resources/tankBlue_barrel1_outline.png");
            Texture2D barrel2   = LoadTexture("Resources/tankBlue_barrel2_outline.png");
            Texture2D barrel3   = LoadTexture("Resources/tankBlue_barrel3_outline.png");
            Texture2D s_barrel1 = LoadTexture("Resources/specialBarrel1_outline.png");
            Texture2D s_barrel2 = LoadTexture("Resources/specialBarrel2_outline.png");
            Texture2D s_barrel3 = LoadTexture("Resources/specialBarrel3_outline.png");
            Texture2D s_barrel4 = LoadTexture("Resources/specialBarrel4_outline.png");
            Texture2D s_barrel5 = LoadTexture("Resources/specialBarrel5_outline.png");
            Texture2D s_barrel6 = LoadTexture("Resources/specialBarrel6_outline.png");
            Texture2D s_barrel7 = LoadTexture("Resources/specialBarrel7_outline.png");
            Texture2D rocketL   = LoadTexture("Resources/barrelGrey_side.png");
            Texture2D bullet1   = LoadTexture("Resources/bulletDark1_outline.png");
            Texture2D bullet2   = LoadTexture("Resources/bulletDark2_outline.png");
            Texture2D bullet3   = LoadTexture("Resources/bulletDark3_outline.png");
            Texture2D bulletM   = LoadTexture("Resources/bulletDark1.png");
            Texture2D rocket1   = LoadTexture("Resources/spaceMissiles_003.png");
            Texture2D rocket2   = LoadTexture("Resources/spaceMissiles_006.png");
            Texture2D obs1      = LoadTexture("Resources/barricadeWood.png");
            Texture2D obs2      = LoadTexture("Resources/sandbagBeige.png");

            Body bodyBasic = new Body(body1, 100f, 1f, 100f, 0f);

            bodyBasic.Rename("Cruiser tank");
            Body bodyBasic2 = new Body(body1a, 100f, 1f, 100f, 0f);

            bodyBasic2.Rename("Cruiser tank");
            Body bodyBig = new Body(body2, 75f, 0.8f, 125f, 8f);

            bodyBig.Rename("Infantry tank");
            Body bodyBigger = new Body(body3, 50f, 0.6f, 150f, -32f);

            bodyBigger.Rename("Super-heavy tank");

            //bodies.Add(bodySmall);
            bodies.Add(bodyBasic);
            bodies.Add(bodyBig);
            bodies.Add(bodyBigger);

            bodies2.Add(bodyBasic2);
            bodies2.Add(bodyBig);
            bodies2.Add(bodyBigger);

            Ammo ammoAvg = new Ammo(bullet1, 1f, 600);
            Ammo ammoFst = new Ammo(bullet3, 0.75f, 700);
            Ammo ammoHvy = new Ammo(bullet2, 1.25f, 500);

            Barrel barrelAvg = new Barrel(s_barrel6, bullet1, 1f, 600, 59, 75, -8f, 0);

            barrelAvg.Rename("105mm cannon");
            barrelAvg.Details(snd_load, 45, false, 0.0f);
            Barrel barrelPrc = new Barrel(s_barrel7, bullet3, 0.75f, 700, 58, 60, -8f, 0);

            barrelPrc.Rename("Self-propelled Sabot");
            barrelPrc.Details(snd_load, 45, false, 0.0f);
            Barrel barrelHwz = new Barrel(s_barrel5, bullet2, 1.25f, 500, 59, 90, -8f, 0);

            barrelHwz.Rename("120mm Howitzer");
            barrelHwz.Details(snd_load, 45, false, 0.0f);
            Barrel barrel45g = new Barrel(s_barrel4, bulletM, 0.5f, 900, 28, 30, -16f, -4f); //20mm machine gun

            barrel45g.Rename("45mm gun");
            barrel45g.Details(snd_load, 45, false, 0.0f);
            Barrel barrelMrl = new Barrel(s_barrel1, rocket1, 2f, 850, 28, 120, -16f, 0);

            barrelMrl.Rename("Rocket launcher");
            barrelMrl.Details(snd_load, 45, false, 0.0f);
            Barrel barrelGui = new Barrel(rocketL, rocket1, 2f, 500, 90, 240, -24f, 0);

            barrelGui.Rename("Guided missile");
            barrelGui.Details(snd_load, 45, true, 3.0f);
            Barrel barrelMac = new Barrel(s_barrel4, bulletM, 0.5f, 900, 28, 30, -16f, -4f);

            barrels.Add(barrelAvg);
            barrels.Add(barrelPrc);
            barrels.Add(barrelHwz);
            barrels.Add(barrel45g);
            barrels.Add(barrelGui);

            body   = bodyBasic;
            barrel = barrelAvg;

            expSpr = new Texture2D[5]
            {
                LoadTexture("Resources/explosion1.png"),
                LoadTexture("Resources/explosion2.png"),
                LoadTexture("Resources/explosion3.png"),
                LoadTexture("Resources/explosion4.png"),
                LoadTexture("Resources/explosion5.png"),
            };
            expSprite.Load(expSpr);
            expSprite_.Load(expSpr);

            bulspr.Load("Resources/bulletBlue1_outline.png");
            bulspr.SetRotate(90 * (float)(Math.PI / 180.0f));
            bulspr.SetPosition(90, 0);

            bulspr_.Load("Resources/bulletBlue1_outline.png");
            bulspr_.SetRotate(90 * (float)(Math.PI / 180.0f));
            bulspr_.SetPosition(90, 0);

            explosionFX.AddChild(expSprite);
            explosionFX.ChangeLifetime(10);
            explosionFX_.AddChild(expSprite_);
            explosionFX_.ChangeLifetime(10);

            bullet.explosion  = explosionFX;
            bullet_.explosion = explosionFX_;

            bullet.AddChild(bulspr);
            bullet_.AddChild(bulspr_);

            bullet.myPoints.Add(new Vector3(-16, 16, 0));
            bullet.myPoints.Add(new Vector3(16, 16, 0));
            bullet.myPoints.Add(new Vector3(16, -16, 0));
            bullet.myPoints.Add(new Vector3(-16, -16, 0));
            bullet_.myPoints.Add(new Vector3(-16, 16, 0));
            bullet_.myPoints.Add(new Vector3(16, 16, 0));
            bullet_.myPoints.Add(new Vector3(16, -16, 0));
            bullet_.myPoints.Add(new Vector3(-16, -16, 0));

            p1.Init(bodies, barrels, 1);
            p2.Init(bodies2, barrels, 2);

            //
            for (int p = 0; p < obsPositions.Length; p++)
            {
                float        half  = obsPositions.Length / 2;
                float        third = obsPositions.Length / 3;
                SceneObject  buh   = new SceneObject(obsHealth, false);
                SpriteObject crap  = new SpriteObject(); crap.Load(obs1);
                buh.AddChild(crap);
                //buh.Rotate(pos.z * ((float)(Math.PI / 180.0f)));
                buh.SetPosition(obsPositions[p].x, obsPositions[p].y);
                crap.SetPosition(-crap.Width / 2, -crap.Height / 2);
                buh.myPoints.Add(new Vector3(-obsRad, obsRad, 0));
                buh.myPoints.Add(new Vector3(obsRad, obsRad, 0));
                buh.myPoints.Add(new Vector3(obsRad, -obsRad, 0));
                buh.myPoints.Add(new Vector3(-obsRad, -obsRad, 0));
                obstacles.Add(buh);
                if (p < (int)third - 1 || p > (int)(third * 2) - 1)
                {
                    crap.Load(obs2);
                }
            }
            //
            p1.Place(new Vector2(GetScreenWidth() / 4, GetScreenHeight() / 4 * 3));
            p2.Place(new Vector2(GetScreenWidth() / 4 * 3, GetScreenHeight() / 4));
        }
Exemplo n.º 12
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.º 13
0
 public void Place(Vector2 position)
 {
     tankObject.SetPosition(position.x, position.y);
 }
Exemplo n.º 14
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;
        }