Ejemplo n.º 1
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));
        }
Ejemplo n.º 2
0
 public void SetStats(Barrel barrel)
 {
     bulletSpeed = barrel.Speed;
     lifetime    = barrel.LifeTime;
 }
Ejemplo n.º 3
0
        public void Update()
        {
            currentTime = stopwatch.ElapsedMilliseconds;
            deltaTime   = (currentTime - lastTime) / 1000.0f;

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

            body   = bodies[bodyPick];
            barrel = barrels[gunPick];
            //WIN CONDITION CHECK
            if (p1.armor <= 0 || p2.armor <= 0)
            {
                paused = true;
                if (p1.armor <= 0)
                {
                    p2.wins++;
                    p2.winStreak++;
                    p1.winStreak = 0;
                }
                if (p2.armor <= 0)
                {
                    p1.wins++;
                    p1.winStreak++;
                    p2.winStreak = 0;
                }
            }
            if (IsKeyPressed(KeyboardKey.KEY_INSERT))
            {
                Reset();
                paused = true;
            }

            if (IsKeyPressed(KeyboardKey.KEY_M))
            {
                //soundOn = !soundOn;
            }

            if (IsKeyPressed(KeyboardKey.KEY_H))
            {
                p1.HitboxToggle();
                p2.HitboxToggle();
                bullet.hitboxDisplay  = !bullet.hitboxDisplay;
                bullet_.hitboxDisplay = !bullet_.hitboxDisplay;
                foreach (SceneObject o in obstacles)
                {
                    o.hitboxDisplay = !o.hitboxDisplay;
                }
            }



            //
            //COLLISIONS!!!!!!!!!!!!!!
            // -- Bullet collides with player
            if (p1.Hitbox.Overlaps(bullet_.blankHitBox) && bullet_.TimeLeft > 0)
            {
                bullet_.Destroy();
                p1.TakeDamage(25 * barrels[p2.gunPick].DamageMult);
            }
            if (p2.Hitbox.Overlaps(bullet.blankHitBox) && bullet.TimeLeft > 0)
            {
                bullet.Destroy();
                p2.TakeDamage(25 * barrels[p1.gunPick].DamageMult);
            }
            // - Obstacle collisions
            foreach (SceneObject obs in obstacles)
            {
                if (obs.health > 0)
                {
                    // -- with bullet
                    if (obs.blankHitBox.Overlaps(bullet.blankHitBox) && bullet.TimeLeft > 0)
                    {
                        if (!obs.passThru)
                        {
                            bullet.Destroy();
                            obs.Damage(25 * barrels[p1.gunPick].DamageMult);
                            Console.Write("butt");
                        }
                        else
                        {
                            if (!bullet.pass)
                            {
                                bullet.pass = true;
                                obs.Damage(25 * barrels[p1.gunPick].DamageMult);
                                Console.Write("butt");
                            }
                            else
                            {
                            }
                        }
                    }
                    if (obs.blankHitBox.Overlaps(bullet_.blankHitBox) && bullet_.TimeLeft > 0)
                    {
                        if (!obs.passThru)
                        {
                            bullet_.Destroy();
                            obs.Damage(25 * barrels[p2.gunPick].DamageMult);
                            //Console.Write("butt");
                        }
                        else
                        {
                            if (!bullet.pass)
                            {
                                bullet_.pass = true;
                                obs.Damage(25 * barrels[p2.gunPick].DamageMult);
                                //Console.Write("butt");
                            }
                            else
                            {
                            }
                        }
                    }
                    // with player
                    if (obs.blankHitBox.Overlaps(p1.Hitbox))
                    {
                        if (!obs.passThru)
                        {
                            p1.Move(deltaTime, -64);
                        }
                    }
                    if (obs.blankHitBox.Overlaps(p2.Hitbox))
                    {
                        if (!obs.passThru)
                        {
                            p2.Move(deltaTime, -64);
                        }
                    }
                }
            }
            //
            bulspr.Load(barrels[p1.gunPick].BulTex);
            bulspr.SetPosition(bulspr.Height / 2.0f, -bulspr.Width / 2.0f);
            bulspr_.Load(barrels[p2.gunPick].BulTex);
            bulspr_.SetPosition(bulspr.Height / 2.0f, -bulspr.Width / 2.0f);


            if (explosionFX.TimeLeft <= 0)
            {
                expSprite.Reset();
            }
            explosionFX.Update(deltaTime);
            expSprite.SetPosition(-expSprite.Width / 2.0f, -expSprite.Height / 2.0f);

            if (explosionFX_.TimeLeft <= 0)
            {
                expSprite_.Reset();
            }
            explosionFX_.Update(deltaTime);
            expSprite_.SetPosition(-expSprite_.Width / 2.0f, -expSprite_.Height / 2.0f);

            bullet.SetStats(barrels[p1.gunPick]);
            bullet_.SetStats(barrels[p2.gunPick]);
            if (bullet.TimeLeft > 0)
            {
                bullet.Update(deltaTime);
            }
            else
            {
                if (!bullet.Explod)
                {
                    bullet.Explode(explosionFX);
                }
                else
                {
                    bullet.Face(p1.TurretPointer);
                }
            }
            if (bullet_.TimeLeft > 0)
            {
                bullet_.Update(deltaTime);
            }
            else
            {
                if (!bullet_.Explod)
                {
                    bullet_.Explode(explosionFX_);
                }
                else
                {
                    bullet_.Face(p2.TurretPointer);
                }
            }

            //DEBUG
            //if (IsKeyDown(KeyboardKey.KEY_KP_1))
            //{
            //    gunPick = 0;
            //}
            //if (IsKeyDown(KeyboardKey.KEY_KP_2))
            //{
            //    gunPick = 1;
            //}
            //if (IsKeyDown(KeyboardKey.KEY_KP_3))
            //{
            //    gunPick = 2;
            //}
            //if (IsKeyDown(KeyboardKey.KEY_KP_4))
            //{
            //    gunPick = 3;
            //}
            //if (IsKeyDown(KeyboardKey.KEY_KP_5))
            //{
            //    gunPick = 4;
            //}
            //if (IsKeyDown(KeyboardKey.KEY_KP_6))
            //{
            //    gunPick = 0;
            //}
            //if (IsKeyDown(KeyboardKey.KEY_KP_7))
            //{
            //    bodyPick = 0;
            //}
            //if (IsKeyDown(KeyboardKey.KEY_KP_8))
            //{
            //    bodyPick = 1;
            //}
            //if (IsKeyDown(KeyboardKey.KEY_KP_9))
            //{
            //    bodyPick = 2;
            //}
            //tank control
            if (IsKeyDown(KeyboardKey.KEY_A))
            {
                p1.Rotate(-deltaTime * body.TurnSpeed);
            }
            if (IsKeyDown(KeyboardKey.KEY_D))
            {
                p1.Rotate(deltaTime * body.TurnSpeed);
            }
            if (IsKeyDown(KeyboardKey.KEY_W))
            {
                p1.Move(deltaTime, true);
            }
            if (IsKeyDown(KeyboardKey.KEY_S))
            {
                p1.Move(deltaTime, false);
            }
            if (IsKeyDown(KeyboardKey.KEY_Q))
            {
                p1.GunRotate(-deltaTime * rotSpeed);
                if (barrels[p1.gunPick].guided)
                {
                    bullet.Rotate(-deltaTime * barrels[p1.gunPick].steer);
                }
            }
            if (IsKeyDown(KeyboardKey.KEY_E))
            {
                p1.GunRotate(deltaTime * rotSpeed);
                if (barrels[p1.gunPick].guided)
                {
                    bullet.Rotate(deltaTime * barrels[p1.gunPick].steer);
                }
            }
            if (IsKeyPressed(KeyboardKey.KEY_SPACE) && p1.reload >= p1.reloading && bullet.TimeLeft <= 0)
            {
                bullet.Reset();
                p1.Fire();
                if (soundOn)
                {
                    PlaySound(snd_fire);
                }
            }


            if (IsKeyDown(KeyboardKey.KEY_KP_4))
            {
                p2.Rotate(-deltaTime * body.TurnSpeed);
            }
            if (IsKeyDown(KeyboardKey.KEY_KP_6))
            {
                p2.Rotate(deltaTime * body.TurnSpeed);
            }
            if (IsKeyDown(KeyboardKey.KEY_KP_8))
            {
                p2.Move(deltaTime, true);
            }
            if (IsKeyDown(KeyboardKey.KEY_KP_5))
            {
                p2.Move(deltaTime, false);
            }
            if (IsKeyDown(KeyboardKey.KEY_KP_7))
            {
                p2.GunRotate(-deltaTime * rotSpeed);
                if (barrels[p2.gunPick].guided)
                {
                    bullet_.Rotate(-deltaTime * barrels[p2.gunPick].steer);
                }
            }
            if (IsKeyDown(KeyboardKey.KEY_KP_9))
            {
                p2.GunRotate(deltaTime * rotSpeed);
                if (barrels[p2.gunPick].guided)
                {
                    bullet_.Rotate(deltaTime * barrels[p2.gunPick].steer);
                }
            }
            if (IsKeyPressed(KeyboardKey.KEY_KP_0) && p2.reload >= p2.reloading && bullet_.TimeLeft <= 0)
            {
                bullet_.Reset();
                p2.Fire();
                if (soundOn)
                {
                    PlaySound(snd_fire);
                }
            }

            p1.Update(deltaTime);
            p2.Update(deltaTime);

            if (soundOn)
            {
                if (p1.reload == p1.reloading - 45)
                {
                    PlaySound(snd_load);
                }
                if ((IsKeyDown(KeyboardKey.KEY_W) || IsKeyDown(KeyboardKey.KEY_S)))
                {
                    if (IsSoundPlaying(snd_drive))
                    {
                        ResumeSound(snd_drive);
                    }
                    else
                    {
                        PlaySound(snd_drive);
                    }
                }
                else
                {
                    if (IsSoundPlaying(snd_drive))
                    {
                        PauseSound(snd_drive);
                    }
                }

                if ((IsKeyDown(KeyboardKey.KEY_Q) || IsKeyDown(KeyboardKey.KEY_E)))
                {
                    if (IsSoundPlaying(snd_rotate))
                    {
                        SetSoundVolume(snd_rotate, 1.0f);
                    }
                    else
                    {
                        PlaySound(snd_rotate);
                    }
                }
                else
                {
                    if (IsSoundPlaying(snd_rotate))
                    {
                        SetSoundVolume(snd_rotate, 0.0f);
                    }
                }
            }


            lastTime = currentTime;
        }