Beispiel #1
0
 protected Car(string name)
 {
     Name       = name;
     carLiquids = new Liquids();
     Menu.PrintServiceMessage("**Please specify what parts are broken: **");
     CarNames                     = new List <string>();
     CarContent                   = new List <CarPart>();
     CarContent.Add(body          = new BodyPart());
     CarContent.Add(carburetor    = new CarburetorPart());
     CarContent.Add(engine        = new EnginePart());
     CarContent.Add(gearbox       = new GearboxPart());
     CarContent.Add(heatregularor = new HeatRegulatorPart());
     CarContent.Add(muffler       = new MufflerPart());
     CarContent.Add(radiator      = new RadiatorPart());
     CarContent.Add(wheels        = new WheelsPart());
     CarContent.Add(horn          = new HornPart());
 }
Beispiel #2
0
    // Use this for initialization
    void Start()
    {
        rb2d = GetComponent <Rigidbody2D>();

        partsW = new List <EnginePart>();
        partsS = new List <EnginePart>();
        partsA = new List <EnginePart>();
        partsD = new List <EnginePart>();

        partsE = new List <EnginePart>();
        partsQ = new List <EnginePart>();

        Transform[] engineParts = GetComponentsInChildren <Transform>();

        foreach (Transform t in engineParts)
        {
            if (!t.tag.Equals("Engine"))
            {
                continue;
            }

            EnginePart enginePart = new EnginePart(t, t.GetComponent <Engine>());
            if (t.rotation.Equals(transform.rotation))
            {
                partsW.Add(enginePart);
                if (t.position.x < transform.position.x)
                {
                    partsE.Add(enginePart);
                }
                else if (t.position.x > transform.position.x)
                {
                    partsQ.Add(enginePart);
                }
            }
            else if (t.rotation.eulerAngles.Equals(new Vector3(0, 0, 180)))
            {
                partsS.Add(enginePart);
                if (t.position.x < transform.position.x)
                {
                    partsQ.Add(enginePart);
                }
                else if (t.position.x > transform.position.x)
                {
                    partsE.Add(enginePart);
                }
            }
            else if (t.rotation.eulerAngles.Equals(new Vector3(0, 0, 90)))
            {
                partsA.Add(enginePart);
                if (t.position.y < transform.position.y)
                {
                    partsE.Add(enginePart);
                }
                else if (t.position.y > transform.position.y)
                {
                    partsQ.Add(enginePart);
                }
            }
            else if (t.rotation.eulerAngles.Equals(new Vector3(0, 0, 270)))
            {
                partsD.Add(enginePart);
                if (t.position.y < transform.position.y)
                {
                    partsQ.Add(enginePart);
                }
                else if (t.position.y > transform.position.y)
                {
                    partsE.Add(enginePart);
                }
            }
        }
    }
Beispiel #3
0
        public static Scenario GetScenario(Guid scenarioGuid, Player currentPlayer, Player enemyPlayer)
        {
            Scenario result = new Scenario();

            using (CodeFighterContext db = new CodeFighterContext())
            {
                ScenarioData scenario = db.ScenarioData
                                        .Include("Features").Include("Features.Feature")
                                        .Include("Ships").Include("Ships.Ship")
                                        .Include("Ships.Ship.ShipHull").Include("Ships.Ship.Parts")
                                        .Include("Ships.Ship.Parts.PartData").Include("Ships.Ship.Parts.PartData.ActionData")
                                        .FirstOrDefault(x => x.ScenarioGUID.Equals(scenarioGuid));
                if (scenario != null)
                {
                    // scenario data
                    result = new Scenario(scenario);

                    // features
                    foreach (ScenarioFeatureData fd in scenario.Features)
                    {
                        result.Features.Add(new Feature(fd));
                    }

                    // ships
                    foreach (ScenarioShipData sd in scenario.Ships)
                    {
                        Ship ship = new Ship();
                        // create hull
                        ShipHull shipHull = new ShipHull(sd.Ship.ShipHull.ClassName, sd.Ship.ShipHull.HullSize);

                        // create parts
                        List <BasePart> parts = new List <BasePart>();
                        foreach (ShipPartData spd in sd.Ship.Parts)
                        {
                            PartData          pd      = spd.PartData;
                            List <BaseAction> actions = new List <BaseAction>();
                            BasePart          part    = null;
                            switch (pd.Type)
                            {
                            case "Weapon":
                                part = new WeaponPart(pd, shipHull.Size.Classification, actions);
                                break;

                            case "Defense":
                                part = new DefensePart(pd, shipHull.Size.Classification, actions);
                                break;

                            case "Action":
                                part = new ActionPart(pd, shipHull.Size.Classification, actions);
                                break;

                            case "Engine":
                                part = new EnginePart(pd, shipHull.Size.Classification, actions);
                                break;
                            }

                            foreach (ActionData ad in pd.ActionData)
                            {
                                switch (ad.Type)
                                {
                                case "RepairPart":
                                    var repairPartActions = JsonConvert.DeserializeObject <Dictionary <string, object> >(ad.ActionValuesJSON);
                                    actions.Add(new RepairPart(part, new CloneableDictionary <string, object>(repairPartActions)));
                                    break;

                                case "RepairShip":
                                    var repairShipActions = JsonConvert.DeserializeObject <Dictionary <string, object> >(ad.ActionValuesJSON);
                                    actions.Add(new RepairShip(ship, new CloneableDictionary <string, object>(repairShipActions)));
                                    break;
                                }
                            }
                            if (actions.Count > 0)
                            {
                                part.Actions = actions;
                            }

                            parts.Add(part);
                        }



                        Point origin = new Point(sd.StartingPositionX, sd.StartingPositionY);

                        ship.ID          = sd.Id;
                        ship.Name        = sd.ShipName;
                        ship.Owner       = sd.IsPlayer?currentPlayer:enemyPlayer;
                        ship.Hull        = shipHull;
                        ship.Parts       = parts;
                        ship.Position    = origin;
                        ship.IsDestroyed = false;
                        ship.MP          = new StatWithMax(ship.MaxMP);
                        ship.GameLogic   = ship.Owner.GameLogic;

                        result.Ships.Add(ship);
                    }
                }
            }


            return(result);
        }
Beispiel #4
0
        private void createAbominations(RectangularHull p, int nbrOfHulls, int nbrOfParts)
        {
            bool hasEngine = false; // abominations needs movement

            //random # of hulls
            RectangularHull[] hulls      = new RectangularHull[nbrOfHulls];
            RectangularHull   oldCarrier = p;

            for (int i = 0; i < hulls.Length; i++)
            {
                int rndCarrier = SRandom.Next(-1, i - 1);
                hulls[i] = new RectangularHull();
                int pos   = SRandom.Next(0, 3);
                int count = 0;
                while (oldCarrier.TakenPositions[pos] && count < 4)
                {
                    pos = (pos + 1) % 4;
                    count++;
                    if (count == 4)
                    {
                        count      = 0;
                        oldCarrier = FindEmptySlotHull(p, hulls, i);
                    }
                }
                oldCarrier.AddPart(hulls[i], pos);

                if (rndCarrier == -1)
                {
                    oldCarrier = p;
                }
                else
                {
                    oldCarrier = hulls[rndCarrier];
                }
            }

            //random # and type of parts
            Part[] parts = new Part[nbrOfParts];
            for (int i = 0; i < parts.Length; i++)
            {
                int  type    = SRandom.Next(0, 3);
                Part newPart = null;
                switch (type)
                {
                case 0:
                    newPart   = new EnginePart();
                    hasEngine = true;
                    break;

                case 1:
                    newPart = new GunPart();
                    break;

                case 2:
                    newPart = new SprayGunPart();
                    break;

                case 3:
                    newPart = new RectangularHull();
                    break;
                }


                int             partPos     = SRandom.Next(0, 3);
                int             pos         = SRandom.Next(-1, hulls.Length - 1);
                RectangularHull currentHull = null;
                if (pos == -1)
                {
                    currentHull = p;
                }
                else
                {
                    currentHull = hulls[pos];
                }

                int count = 0;
                while (count < 4)
                {
                    if (currentHull.TakenPositions[partPos])
                    {
                        partPos = (partPos + 1) % 4;
                    }
                    else
                    {
                        currentHull.AddPart(newPart, partPos);
                        count = 4;
                    }
                    count++;
                }


                if (!hasEngine)
                {
                    count = 0;
                    while (p.TakenPositions[count] && count < 3)
                    {
                        count++;
                    }
                    p.AddPart(new EnginePart(), count);
                }

                //random movePattern

                //attackTimer.maxTime = SRandom.Next(0, 6);

                int movePattern = SRandom.Next(0, 99);
                specialMove = SPREAD_OUT;
                switch (movePattern)
                {
                //case 0:
                //    specialMove = PIRATOS;
                //    TurnSpeed = 0.2f * (float)Math.PI;
                //    break;
                case 1:
                    specialMove = PIRATOSBOSS;
                    TurnSpeed   = 0.1f * (float)Math.PI;
                    break;

                case 3:
                    usingWaitTimer    = true;
                    waitTimer.maxTime = SRandom.Next(0, 6);
                    break;
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

            #region Adding base texture to Sprite

            Texture2D baseTex = new Texture2D(GraphicsDevice, 2, 2);
            Color[]   c       = new Color[4];
            c[0] = Color.White;
            c[1] = Color.White;
            c[2] = Color.White;
            c[3] = Color.White;
            baseTex.SetData(c);
            Texture2DPlus baseTexPlus = new Texture2DPlus(baseTex);
            Sprite.addBaseTexture(baseTexPlus);
            #endregion

            #region Loading fonts

            DrawHelper.DEBUGFONT   = Content.Load <SpriteFont>("fonts/debugfont");
            DrawHelper.SCOREFONT   = Content.Load <SpriteFont>("fonts/ScoreFont");
            DrawHelper.BIGFONT     = Content.Load <SpriteFont>("fonts/BigScoreFont");
            DrawHelper.UPGRADEFONT = Content.Load <SpriteFont>("fonts/currencyFont");
            #endregion

            #region Loading textures

            Texture2DPlus backgroundTex = new Texture2DPlus(Content.Load <Texture2D>("background/Background"));
            Texture2DPlus bluePlanetTex = new Texture2DPlus(Content.Load <Texture2D>("background/BluePlanet"));
            Texture2DPlus smallRedTex   = new Texture2DPlus(Content.Load <Texture2D>("background/LittleRedPlanet"));
            Texture2DPlus bigRedTex     = new Texture2DPlus(Content.Load <Texture2D>("background/RedBigPlanet"));
            Texture2DPlus cursorTex     = new Texture2DPlus(Content.Load <Texture2D>("textures/cursor"));

            Texture2DPlus errorTex             = new Texture2DPlus(Content.Load <Texture2D>("textures/noTexture"));
            Texture2DPlus enemyTex1            = new Texture2DPlus(Content.Load <Texture2D>("textures/enemyShip"), 2);
            Texture2DPlus enemyTex2            = new Texture2DPlus(Content.Load <Texture2D>("textures/enemyShoot"), 2);
            Texture2DPlus enemyTex3            = new Texture2DPlus(Content.Load <Texture2D>("textures/enemySpeed"), 2);
            Texture2DPlus enemyTex4            = new Texture2DPlus(Content.Load <Texture2D>("textures/asteroid"));
            Texture2DPlus shipTex              = new Texture2DPlus(Content.Load <Texture2D>("parts/Hull_3"));
            Texture2DPlus wallTex              = new Texture2DPlus(Content.Load <Texture2D>("textures/wall"));
            Texture2DPlus shotTex              = new Texture2DPlus(Content.Load <Texture2D>("textures/lazor"), 4);
            Texture2DPlus sprayBulletTex       = new Texture2DPlus(Content.Load <Texture2D>("textures/SprayBullet"), 2);
            Texture2DPlus mineBulletTex        = new Texture2DPlus(Content.Load <Texture2D>("textures/mineBullet_1"), 9);
            Texture2DPlus chargingBulletTex    = new Texture2DPlus(Content.Load <Texture2D>("textures/ChargingBullet"), 6);
            Texture2DPlus gravityBulletTex     = new Texture2DPlus(Content.Load <Texture2D>("textures/GravityBullet"), 6);
            Texture2DPlus homingTex            = new Texture2DPlus(Content.Load <Texture2D>("textures/homing"));
            Texture2DPlus healthDropTex        = new Texture2DPlus(Content.Load <Texture2D>("textures/healthPack"), 4);
            Texture2DPlus moneyDropTex         = new Texture2DPlus(Content.Load <Texture2D>("textures/MoneyDrop"), 7);
            Texture2DPlus healthDrop_TIER2_Tex = new Texture2DPlus(Content.Load <Texture2D>("textures/healthDrop_TIER2"), 4);
            Texture2DPlus wrenchTex            = new Texture2DPlus(Content.Load <Texture2D>("textures/wrench"));
            Texture2DPlus explosionDropTex     = new Texture2DPlus(Content.Load <Texture2D>("textures/explosionDrop"), 8);
            Texture2DPlus boltTex              = new Texture2DPlus(Content.Load <Texture2D>("textures/bolt"));
            Texture2DPlus moneyTex             = new Texture2DPlus(Content.Load <Texture2D>("textures/money"));
            Texture2DPlus energyDropTex        = new Texture2DPlus(Content.Load <Texture2D>("textures/energyDrop"), 8);
            Texture2DPlus unitBarBorderTex     = new Texture2DPlus(Content.Load <Texture2D>("textures/unitBarBorder"));
            Texture2DPlus gunTex1              = new Texture2DPlus(Content.Load <Texture2D>("parts/Gun_1"));
            Texture2DPlus mineGunTex           = new Texture2DPlus(Content.Load <Texture2D>("parts/MineGun"));
            Texture2DPlus sprayGunTex          = new Texture2DPlus(Content.Load <Texture2D>("parts/SprayGun"));
            Texture2DPlus chargingGunTex       = new Texture2DPlus(Content.Load <Texture2D>("parts/ChargingGun"));
            Texture2DPlus gravityGunTex        = new Texture2DPlus(Content.Load <Texture2D>("parts/GravityGun"));
            Texture2DPlus engineTex1           = new Texture2DPlus(Content.Load <Texture2D>("parts/Engine_1"));
            Texture2DPlus selectionBoxTex      = new Texture2DPlus(Content.Load <Texture2D>("parts/SelectionBox"));
            Texture2DPlus upgradeBkg           = new Texture2DPlus(Content.Load <Texture2D>("parts/UpgradeBarBkg"));
            Texture2DPlus popupTextBkgTex      = new Texture2DPlus(Content.Load <Texture2D>("textures/PopupTextBkg"));
            Texture2DPlus menuScreenBkg        = new Texture2DPlus(Content.Load <Texture2D>("parts/MenuScreenBkg"));
            Texture2DPlus rotateItemTex        = new Texture2DPlus(Content.Load <Texture2D>("textures/Rotate"));
            Texture2DPlus hammerItemTex        = new Texture2DPlus(Content.Load <Texture2D>("textures/Hammer"));
            Texture2DPlus alertTex             = new Texture2DPlus(Content.Load <Texture2D>("textures/AlertParticle"));
            Texture2DPlus logoTex              = new Texture2DPlus(Content.Load <Texture2D>("textures/logo"));

            //allUpgradeParts.Insert(PartTypes.DETECTORPART, shotTex);
            #endregion

            #region Loading sounds and adding them to list
            SoundHandler.Sounds[(int)IDs.DEFAULT]             = Content.Load <SoundEffect>("sounds/shotSnd");
            SoundHandler.Sounds[(int)IDs.GUNPART]             = Content.Load <SoundEffect>("sounds/shotSnd");
            SoundHandler.Sounds[(int)IDs.GRAVITYBULLET]       = Content.Load <SoundEffect>("sounds/blackholeSnd");
            SoundHandler.Sounds[(int)IDs.MENUCLICK]           = Content.Load <SoundEffect>("sounds/menuclickSnd");
            SoundHandler.Sounds[(int)IDs.CHARGINGGUNPART]     = Content.Load <SoundEffect>("sounds/chargeshotSnd");
            SoundHandler.Sounds[(int)IDs.EXPLOSIONDEATHSOUND] = Content.Load <SoundEffect>("sounds/ExplosionDeath");
            SoundHandler.Sounds[(int)IDs.PLAYERDEATHSOUND]    = Content.Load <SoundEffect>("sounds/player_death");
            SoundHandler.Sounds[(int)IDs.SLOWMOSOUND]         = Content.Load <SoundEffect>("sounds/slomo");
            SoundHandler.Sounds[(int)IDs.REVERSESLOWMOSOUND]  = Content.Load <SoundEffect>("sounds/reverse_slomo");
            SoundHandler.Sounds[(int)IDs.PICKUPSOUND]         = Content.Load <SoundEffect>("sounds/pickup");
            SoundHandler.Songs[(int)IDs.SONG1INTRO]           = Content.Load <SoundEffect>("sounds/OdysseanIntro");
            SoundHandler.Songs[(int)IDs.SONG1]    = Content.Load <SoundEffect>("sounds/Odyssean");
            SoundHandler.Songs[(int)IDs.SONG2]    = Content.Load <SoundEffect>("sounds/Galaxian");
            SoundHandler.Songs[(int)IDs.VICTORY]  = Content.Load <SoundEffect>("sounds/Victorian");
            SoundHandler.Songs[(int)IDs.GAMEOVER] = Content.Load <SoundEffect>("sounds/GameOver");
            //Console.WriteLine(SoundHandler.Songs[(int)IDs.SONG1INTRO].Duration);
            #endregion
            //Directory.GetFiles(Directory.GetCurrentDirectory() + "\\Content\\textures");

            #region Adding sprites to list
            SpriteHandler.Sprites[(int)IDs.DEFAULT] = new Sprite(errorTex);
            //SpriteHandler.Sprites[(int)IDs.DEFAULT_ENEMY] = new Sprite(enemyTex1, 2, 4);
            //SpriteHandler.Sprites[(int)IDs.ENEMYSHOOT] = new Sprite(enemyTex2, 2, 4);
            //SpriteHandler.Sprites[(int)IDs.ENEMYSPEED] = new Sprite(enemyTex3, 2, 4);
            SpriteHandler.Sprites[(int)IDs.ENEMYASTER]       = new Sprite(enemyTex4);
            SpriteHandler.Sprites[(int)IDs.DEFAULT_BULLET]   = new Sprite(shotTex, 4);
            SpriteHandler.Sprites[(int)IDs.CHARGINGBULLET]   = new Sprite(chargingBulletTex, 24);
            SpriteHandler.Sprites[(int)IDs.GRAVITYBULLET]    = new Sprite(gravityBulletTex, 24);
            SpriteHandler.Sprites[(int)IDs.SPRAYBULLET]      = new Sprite(sprayBulletTex, 2);
            SpriteHandler.Sprites[(int)IDs.HOMINGBULLET]     = new Sprite(homingTex);
            SpriteHandler.Sprites[(int)IDs.HEALTHDROP]       = new Sprite(healthDropTex, 6);
            SpriteHandler.Sprites[(int)IDs.HEALTHDROP_TIER2] = new Sprite(healthDrop_TIER2_Tex, 6);
            SpriteHandler.Sprites[(int)IDs.EXPLOSIONDROP]    = new Sprite(explosionDropTex, 6);
            SpriteHandler.Sprites[(int)IDs.ENERGYDROP]       = new Sprite(energyDropTex, 6);
            SpriteHandler.Sprites[(int)IDs.MINEBULLET]       = new Sprite(mineBulletTex, 6);
            SpriteHandler.Sprites[(int)IDs.RECTHULLPART]     = new Sprite(shipTex);
            SpriteHandler.Sprites[(int)IDs.GUNPART]          = new Sprite(gunTex1);
            SpriteHandler.Sprites[(int)IDs.MINEGUNPART]      = new Sprite(mineGunTex);
            SpriteHandler.Sprites[(int)IDs.GRAVITYGUNPART]   = new Sprite(gravityGunTex);
            SpriteHandler.Sprites[(int)IDs.CHARGINGGUNPART]  = new Sprite(chargingGunTex);
            SpriteHandler.Sprites[(int)IDs.SPRAYGUNPART]     = new Sprite(sprayGunTex);
            SpriteHandler.Sprites[(int)IDs.ENGINEPART]       = new Sprite(engineTex1);
            SpriteHandler.Sprites[(int)IDs.DEFAULT_PARTICLE] = new Sprite();
            SpriteHandler.Sprites[(int)IDs.WALL]             = new Sprite(wallTex);
            SpriteHandler.Sprites[(int)IDs.WRENCH]           = new Sprite(wrenchTex);
            SpriteHandler.Sprites[(int)IDs.BOLT]             = new Sprite(boltTex);
            SpriteHandler.Sprites[(int)IDs.EMPTYPART]        = new Sprite(selectionBoxTex);
            SpriteHandler.Sprites[(int)IDs.UPGRADEBAR]       = new Sprite(upgradeBkg);
            SpriteHandler.Sprites[(int)IDs.POPUPTEXTBKG]     = new Sprite(popupTextBkgTex);
            SpriteHandler.Sprites[(int)IDs.MENUSCREENBKG]    = new Sprite(menuScreenBkg);
            SpriteHandler.Sprites[(int)IDs.MONEYDROP]        = new Sprite(moneyDropTex, 6);
            SpriteHandler.Sprites[(int)IDs.MONEY]            = new Sprite(moneyTex);
            SpriteHandler.Sprites[(int)IDs.ROTATEPART]       = new Sprite(rotateItemTex);
            SpriteHandler.Sprites[(int)IDs.HAMMERPART]       = new Sprite(hammerItemTex);
            SpriteHandler.Sprites[(int)IDs.ALERTPARTICLE]    = new Sprite(alertTex);
            SpriteHandler.Sprites[(int)IDs.LOGO]             = new Sprite(logoTex);
            #endregion

            #region Adding partIDs to list
            List <IDs> ids = new List <IDs>();
            for (int i = (int)IDs.DEFAULT_PART + 1; i <= (int)IDs.EMPTYPART; i++)
            {
                ids.Add((IDs)i);
            }
            ids.Add(IDs.ROTATEPART); //!!
            #endregion

            #region Initializing game objects etc.
            background = new Background(new Sprite(backgroundTex), bluePlanetTex, bluePlanetTex, bigRedTex, smallRedTex);
            //Camera.Player = player; //Reintroduce if camera is to be used
            AchievementController achController = new AchievementController();
            SaveHandler.InitializeGame(achController);
            GameMode    gameMode    = new GameMode();
            Projectiles projectiles = new Projectiles();
            GunPart.projectiles = projectiles;

            Player player = new Player(new Vector2(graphics.PreferredBackBufferWidth / 2, graphics.PreferredBackBufferHeight / 2), projectiles); //ok, projectiles null before?
            eventOperator = new EventOperator(this, shipTex, gameMode, achController, player, ids);
            RectangularHull rectHull1 = new RectangularHull();
            RectangularHull rectHull2 = new RectangularHull();
            GunPart         gunPart1  = new ChargingGunPart();
            GunPart         gunPart2  = new ChargingGunPart();
            GunPart         gunPart3  = new GunPart(IDs.DEFAULT);
            EnginePart      engine1   = new EnginePart();
            EnginePart      engine2   = new EnginePart();
            EnginePart      engine3   = new EnginePart();
            Drops           drops     = new Drops(WindowSize.Width, WindowSize.Height);
            gameController = new GameController(player, projectiles, drops, gameMode);
            //wall = new Wall(new Vector2(-4000, -4000)); //! wall location
            UnitBar healthBar = new UnitBar(new Vector2(50, 50), new Sprite(unitBarBorderTex), Color.OrangeRed, 5); //! LOL
            UnitBar energyBar = new UnitBar(new Vector2(50, 85), new Sprite(unitBarBorderTex), Color.Gold, player.maxEnergy);
            playerUI = new PlayerUI(healthBar, energyBar, achController);
            Mouse.SetCursor(MouseCursor.FromTexture2D(cursorTex.Texture, cursorTex.Texture.Width / 2, cursorTex.Texture.Height / 2));
            #endregion

            // TODO: use this.Content to load your game content here
        }