Esempio n. 1
0
        public Cannon(CannonTemplate cannonTemplate) : base(35, 35)
        {
            Price  = cannonTemplate.Price;
            Damage = cannonTemplate.Damage;
            Speed  = cannonTemplate.Interval;
            Image  = GameManager.Images[cannonTemplate.Image];
            Tag    = "Cannon";

            AmmoColor = (Color)typeof(Color).GetField(cannonTemplate.AmmoColor).GetValue(null);

            ShootTimer          = new Timer();
            ShootTimer.Interval = Speed;

            if (cannonTemplate.BurstCount == 0)
            {
                ShootTimer.Timeout += Shoot;
            }
            else
            {
                ShootTimer.Timeout += delegate
                {
                    Timer burstTimer = new Timer(cannonTemplate.BurstDelay);
                    burstTimer.Timeout += Shoot;
                    burstTimer.Start(cannonTemplate.BurstCount);
                };
            }

            ShootTimer.Start();

            Game.Instance.Mouse.ListenOn(this, MouseButton.Left, ButtonState.Pressed, Upgrade, null);
        }
Esempio n. 2
0
File: JTD.cs Progetto: roeyskoe/JTD
        /// <summary>
        /// Game initialization
        /// </summary>
        public override void Begin()
        {
            ClearAll();

            IsPaused = false;

            GameManager.Level         = 1;
            GameManager.EnemiesAlive  = 0;
            GameManager.Money         = new IntMeter(1000);
            GameManager.KillCount     = new IntMeter(0);
            GameManager.Images        = new Images();
            GameManager.ListenContext = ControlContext;
            GameManager.DebugText     = "";
            GameManager.Grid          = new Grid();
            GameManager.Grid.CellSize = new Vector(20, 20);

            cannons = JsonSerializer.Deserialize <Dictionary <string, CannonTemplate> >(System.IO.File.ReadAllText("Content/cannons/CannonDefinitions.json"));
            enemies = JsonSerializer.Deserialize <Dictionary <string, EnemyTemplate> >(System.IO.File.ReadAllText("Content/enemies/EnemyDefinitions.json"));

            foreach (var item in cannons.Keys)
            {
                CannonTemplate c = cannons[item];
                c.Name        = item;
                cannons[item] = c; // TODO: Simpler way without modifying json?
            }

            GameManager.CannonSelected = cannons.First().Value.Name;

            SetWindowSize(2000, 1200);

            CreateLevel();
            Controllers();
            CreateMoneyCounter();
            KillCounter();

            Camera.ZoomToAllObjects();
            Level.Size             = Screen.Size;
            Level.Background.Image = GameManager.Images["grass.png"];
            Level.Background.TileToLevel();

            Wave();

            pointsAdded = false;

            Cannonselector cs = new Cannonselector(cannons.Values.ToList());

            cs.X = Screen.Left + cs.Width / 1.5;
            cs.Y = Screen.Bottom + cs.Height;
            Add(cs);

            mousevisualizer             = new Widget(20, 20);
            mousevisualizer.Color       = Color.Transparent;
            mousevisualizer.BorderColor = Color.LightGray;
            Add(mousevisualizer);

            debugLabel   = new Label();
            debugLabel.Y = 100;
            Add(debugLabel);
        }
Esempio n. 3
0
File: JTD.cs Progetto: roeyskoe/JTD
        /// <summary>
        /// Create a tower on mouses location
        /// </summary>
        public void BuildCannon()
        {
            CannonTemplate selected = cannons[GameManager.CannonSelected];

            if (GameManager.Money.Value >= selected.Price)
            {
                Cannon cannon = new Cannon(selected);
                cannon.Position = GameManager.Grid.SnapToLines(Mouse.PositionOnWorld);

                Add(cannon, +1);
                GameManager.Money.Value -= cannon.Price;

                // Tower aiming timer
                cannon.TurnTimer          = new Timer();
                cannon.TurnTimer.Interval = 0.1;
                cannon.TurnTimer.Timeout += delegate { cannon.Aim(); };
                cannon.TurnTimer.Start();
            }
        }