コード例 #1
0
ファイル: Cursor.cs プロジェクト: TimoTheeus/NvH
    public override void HandleInput(InputHelper inputHelper)
    {
        base.HandleInput(inputHelper);
        this.Position = inputHelper.MousePosition + GameWorld.Camera.Pos;
        Point position = new Point((int)(inputHelper.MousePosition.X + tileForOrigin.Sprite.Center.X + GameWorld.Camera.Pos.X),
                                   (int)(inputHelper.MousePosition.Y + tileForOrigin.Sprite.Center.Y + GameWorld.Camera.Pos.Y));

        if (!hasClickedTile)
        {
            currentTile = GameData.LevelGrid.GetTile(position);
            if (currentTile != null)
            {
                GameData.selectedTile.Position = currentTile.Position;
            }
        }
        for (int i = 0; i < GameData.Units.Objects.Count; i++)
        {
            // make return property that returns the right value instead
        }
        //stop hovering tiles
        if (inputHelper.LeftButtonPressed() && currentTile != null && !hasClickedTile && !HoveringOverUnit(inputHelper))
        {
            hasClickedTile = true;
        }

        if (spell != null)
        {
            if (inputHelper.RightButtonPressed())
            {
                spell.Position = GameData.Cursor.Position - new Vector2(GameData.LevelGrid.cellWidth / 2, GameData.LevelGrid.cellHeight / 2);
                GameData.LevelObjects.Add(spell);
                this.actionString = "$spel:" + spell.ID + "$type:" + spell.GetType() + "$posi:" + spell.Position.X + "," + spell.Position.Y;
                Spell             = null;
            }
        }

        bool mouseEnabled = true;

        if (inputHelper.IsKeyDown(Keys.K))
        {
            MeteorStorm s = new MeteorStorm(); s.Position = this.Position + GameWorld.Camera.Pos; GameData.LevelObjects.Add(s);
        }

        if (inputHelper.IsKeyDown(Keys.Right) || (mouseEnabled && inputHelper.MousePosition.X > GameSettings.GameWidth - borderWidth))
        {
            GameWorld.Camera.Move(new Vector2(15, 0));
        }
        else if (inputHelper.IsKeyDown(Keys.Left) || (mouseEnabled && inputHelper.MousePosition.X < borderWidth))
        {
            GameWorld.Camera.Move(new Vector2(-15, 0));
        }
        else if (inputHelper.IsKeyDown(Keys.Up) || (mouseEnabled && inputHelper.MousePosition.Y < borderWidth))
        {
            GameWorld.Camera.Move(new Vector2(0, -15));
        }
        else if (inputHelper.IsKeyDown(Keys.Down) || (mouseEnabled && inputHelper.MousePosition.Y > GameSettings.GameHeight - borderWidth))
        {
            GameWorld.Camera.Move(new Vector2(0, 15));
        }
    }
コード例 #2
0
        private void updateTick(object sender, UpdateTickedEventArgs e)
        {
            if (!Context.IsWorldReady)
            {
                return;
            }

            // Make Death Events not as bad
            if (Game1.killScreen && markedForDeath == false)
            {
                markedForDeath = true;
            }
            if (Game1.killScreen == false && markedForDeath && !Game1.eventUp && (Game1.player.currentLocation.name.Equals("Hospital") || Game1.player.currentLocation.name.Equals("Mine") || Game1.player.currentLocation is IslandLocation))
            {
                BuffManager.buffPlayer(new BuffOption("rush", "Adrenaline", true, 100).add_attack(6).addShortDesc("Buff Attack +6").setGlow(Color.OrangeRed));
                BuffManager.buffPlayer(new BuffOption("pain", "Pain Medicine", true, 100).add_defense(3).addShortDesc("Buff Defense +3"));
                BuffManager.buffPlayer(new BuffOption("speed", "Fight or Flight", true, 100).add_speed(4).addShortDesc("Buff Speed +4").setGlow(Color.LightBlue));
                markedForDeath = false;
            }
            // End of Death Event

            if (e.IsMultipleOf(15))
            {
                BuffManager.UpdateTick();
                Spawner.UpdateTick();
                actionManager.Update();

                if (!Game1.player.currentLocation.name.Equals("Hospital"))
                {
                    if (!IsBusyDoingSomething())
                    {
                        BombEvent.UpdateTick();
                    }
                }
            }

            if (e.IsOneSecond)
            {
                //MineBuffManager.UpdateTick();
                augmentManager.UpdateTick();
                BuffManager.Update();

                if (!Game1.player.currentLocation.name.Equals("Hospital") || Game1.player.currentLocation.Name.Equals("FarmHouse"))
                {
                    if (!IsBusyDoingSomething() &&
                        !Game1.paused &&
                        !Game1.menuUp &&
                        !Game1.isTimePaused &&
                        Game1.shouldTimePass())
                    {
                        MeteorStorm.UpdateTick();
                        FireballEvent.UpdateTick();
                    }
                }
            }
        }
コード例 #3
0
        private void InputEvents_ButtonPressed(object sender, ButtonPressedEventArgs e)
        {
            this.Monitor.Log(e.Button.ToString());
            if (!Game1.IsMasterGame)
            {
                return;
            }


            if (e.Button.Equals(SButton.J))
            {
                Gift gift = new Gift();

                gift.item = 421;

                gift.cnt = 1;

                gift.Handle();
            }

            if (e.Button.Equals(SButton.N))
            {
                //Game1.game1.parseDebugInput("minelevel 1");

                MeteorStorm storm = new MeteorStorm();
                storm.from      = "test";
                storm.stormtype = "apocalyptic";
                storm.Handle();
            }
            if (e.Button.Equals(SButton.B))
            {
                for (int i = 0; i < 1; i++)
                {
                    //Game1.player.currentLocation.temporarySprites.Add(new CosmeticDebris(new Fence().fenceTexture.Value, new Vector2(Game1.player.getTileX() * 64f + 32f, Game1.player.getTileY() * 64f + 32f), (float)Game1.random.Next(-5, 5) / 100f, (float)Game1.random.Next(-64, 64) / 30f, (float)Game1.random.Next(-800, -100) / 100f, (int)((Game1.player.getTileY() + 1f) * 64f), new Rectangle(32 + Game1.random.Next(2) * 16 / 2, 96 + Game1.random.Next(2) * 16 / 2, 8, 8), Color.White, (Game1.soundBank != null) ? Game1.soundBank.GetCue("shiny4") : null, null, 0, 200));
                    //Meteor projectile = new Meteor(getRangeFromPlayer(1000));
                    //Meteor projectile = new Meteor(getRangeFromViewPort(700), Game1.random.Next(100, 600), Game1.player.currentLocation);
                    //projectile.height.Value = 24f;
                    //projectile.ignoreMeleeAttacks.Value = true;
                    //projectile.hostTimeUntilAttackable = 0.1f;
                    //Game1.player.currentLocation.projectiles.Add(projectile);

                    FireballEvent storm = new FireballEvent();

                    storm.from      = "test";
                    storm.stormtype = "insane";
                    actionManager._actionQueue.Enqueue(storm);
                }


                //SpawnCat.tryMoveCats();
            }
        }
コード例 #4
0
    private void parseAction(string s)
    {
        string[] pairs = s.Split('$');
        if (pairs.Length > 1)
        {
            string sig = pairs[1].Substring(0, 4);
            if (sig.Equals("unit"))
            {
                string id = pairs[1].Substring(5, pairs[1].Length - 5);
                for (int i = 2; i < pairs.Length; i++)
                {
                    switch (pairs[i].Substring(0, 4))
                    {
                    case "move":
                        try
                        {
                            string[] coords = pairs[i].Substring(5, pairs[i].Length - 5).Split(',');
                            Unit     u      = ((Unit)(GameData.LevelObjects.Find(id)));
                            u.TargetPosition = new Vector2(float.Parse(coords[0]), float.Parse(coords[1]));
                            u.TargetUnit     = null;
                        }
                        catch (NullReferenceException e)
                        {
                            string[] coords = pairs[i].Substring(5, pairs[i].Length - 5).Split(',');
                            Unit     u      = ((Unit)(GameData.LevelObjects.Find(id)));
                            if (u != null)
                            {
                                u.TargetPosition = new Vector2(float.Parse(coords[0]), float.Parse(coords[1]));
                                //u.TargetUnit = null;
                            }
                            Console.WriteLine("null");
                        }
                        break;

                    case "targ":
                        try
                        {
                            string targID  = pairs[i].Substring(5, pairs[i].Length - 5);
                            Unit   theUnit = ((Unit)(GameData.LevelObjects.Find(id)));
                            Unit   targetU = (Unit)GameData.LevelObjects.Find(targID);
                            theUnit.SetTargetUnit(targID);
                        }
                        catch (NullReferenceException e) { }
                        break;

                    case "tgbd":
                        string bdtgID = pairs[i].Substring(5, pairs[i].Length - 5);
                        ((Unit)(GameData.LevelObjects.Find(id))).targetBuilding = (Building)GameData.Buildings.Find(bdtgID);
                        break;

                    case "buil":
                        //build
                        break;

                    case "damg":
                        try
                        {
                            string[] parameters = pairs[i].Substring(5, pairs[i].Length - 5).Split(',');
                            string   attackerID = parameters[1];
                            Unit     attacker   = (Unit)(GameData.LevelObjects.Find(attackerID));
                            ((Unit)(GameData.LevelObjects.Find(id))).DealDamage(int.Parse(parameters[0]), attacker);
                        }
                        catch (NullReferenceException e)
                        {
                            Console.WriteLine(e.ToString());
                        }
                        break;

                    case "dead":
                        try
                        {
                            GameData.Units.Remove(((Unit)(GameData.LevelObjects.Find(id))));
                        }
                        catch (NullReferenceException e) {
                            Console.WriteLine(e.ToString());
                        }
                        break;
                    }
                }
            }
            else if (sig.Equals("bdng"))
            {
                Building b        = null;
                bool     polytile = false;
                string   id       = pairs[1].Substring(5, pairs[1].Length - 5);
                for (int i = 2; i < pairs.Length; i++)
                {
                    switch (pairs[i].Substring(0, 4))
                    {
                    case "type":
                        string type = pairs[i].Substring(5, pairs[i].Length - 5);
                        switch (type)
                        {
                        case "NatureBarracks":
                            b = new NatureBarracks();
                            break;

                        case "HumanityBarrack":
                            b        = new HumanityBarrack();
                            polytile = true;
                            break;

                        case "SunlightTree":
                            b = new SunlightTree();
                            break;

                        case "NatureBase":
                            b        = new NatureBase();
                            polytile = true;
                            break;

                        case "HumanityBase":
                            b        = new HumanityBase();
                            polytile = true;
                            break;

                        case "Mine":
                            b = new Mine();
                            break;

                        case "WaterTree":
                            b = new WaterTree();
                            break;
                        }
                        break;

                    case "posi":
                        string[] coords = pairs[i].Substring(5, pairs[i].Length - 5).Split(',');
                        b.gridPosition = new Point(int.Parse(coords[0]), int.Parse(coords[1]));
                        break;

                    case "fnsh":

                        GameData.LevelGrid.replaceTile((Tile)GameData.LevelGrid.Objects[b.gridPosition.X, b.gridPosition.Y], b, false);
                        if (polytile)
                        {
                            ((PolyTileBuilding)b).AddQuadCoTiles();
                        }
                        GameData.Buildings.Add(b);
                        break;

                    case "damg":
                        try
                        {
                            string[] parameters = pairs[i].Substring(5, pairs[i].Length - 5).Split(',');
                            string   attackerID = parameters[1];
                            Unit     attacker   = (Unit)(GameData.LevelObjects.Find(attackerID));
                            ((Building)(GameData.Buildings.Find(id))).DealDamage(int.Parse(parameters[0]), attacker);
                        }
                        catch (NullReferenceException e)
                        {
                            Console.WriteLine(e.ToString());
                        }
                        break;

                    case "dead":
                        try
                        {
                            GameData.Buildings.Remove(((Building)(GameData.LevelObjects.Find(id))));
                        }
                        catch (NullReferenceException e) {
                            Console.WriteLine(e.ToString());
                        }
                        break;
                    }
                }
            }
            else if (sig.Equals("spel"))
            {
                Spell  spell = null;
                string id    = pairs[1].Substring(5, pairs[1].Length - 5);
                for (int i = 2; i < pairs.Length; i++)
                {
                    switch (pairs[i].Substring(0, 4))
                    {
                    case "type":
                        switch (pairs[i].Substring(5, pairs[i].Length - 5))
                        {
                        case "MeteorStorm":
                            spell = new MeteorStorm();
                            break;

                        case "SnowStorm":
                            spell = new SnowStorm();
                            break;

                        case "Spell":
                            spell = new Spell();
                            break;
                        }
                        break;

                    case "posi":
                        string[] coords = pairs[i].Substring(5, pairs[i].Length - 5).Split(',');
                        spell.Position = new Vector2(float.Parse(coords[0]), float.Parse(coords[1]));
                        break;
                    }
                }
                spell.ID = id;
                GameData.LevelObjects.Add(spell);
            }
            else if (sig.Equals("addu"))
            {
                Unit u;//$addu:10$type:HumanityWorker$posi:1080,420
                u = null;
                string id = pairs[1].Substring(5, pairs[1].Length - 5);

                for (int i = 2; i < pairs.Length; i++)
                {
                    switch (pairs[i].Substring(0, 4))
                    {
                    case "type":

                        switch (pairs[i].Substring(5, pairs[i].Length - 5))
                        {
                        case "HumanityWorker":
                            u = new HumanityWorker();
                            break;

                        case "NatureWorker":
                            u = new NatureWorker();
                            break;

                        case "Melee1":
                            string asset = "";
                            asset = "natureWolf";
                            if (GameData.player.OppositeFaction == Player.Faction.humanity)
                            {
                                asset = "chainsaw";
                            }
                            u = new Melee1(GameData.player.OppositeFaction, asset, id);
                            break;

                        case "Ranged":
                            asset = "natureWolf";
                            if (GameData.player.OppositeFaction == Player.Faction.humanity)
                            {
                                asset = "flamethrower";
                            }
                            u = new Ranged(GameData.player.OppositeFaction, asset, id);
                            break;

                        case "Melee2":
                            asset = "treeUnit";
                            if (GameData.player.OppositeFaction == Player.Faction.humanity)
                            {
                                asset = "flamethrower";
                            }
                            u = new Melee2(GameData.player.OppositeFaction, asset, id);
                            break;

                        case "FlameThrower":
                            u = new FlameThrower();
                            break;

                        case "Unicorn":
                            asset = "unicorn";
                            if (GameData.player.OppositeFaction == Player.Faction.humanity)
                            {
                                asset = "quad";
                            }
                            u = new Unicorn(GameData.player.OppositeFaction, asset, id);
                            break;

                        case "WoodCutter":
                            u = new WoodCutter();
                            break;

                        case "Unit":
                            u = new Unit();
                            break;
                        }
                        break;

                    case "posi":
                        string[] coords = pairs[i].Substring(5, pairs[i].Length - 5).Split(',');
                        u.Position = new Vector2(int.Parse(coords[0]), int.Parse(coords[1]));
                        break;
                    }
                }
                u.ID = id;
                GameData.Units.Add(u);
                GameData.unitIdIndex++;
            }
        }
    }