Esempio n. 1
0
        public override void Start()
        {
            ((Game)Engine.Objects["game"]).AudioSource.Pause();

            GameManager.MainWindow = "gameover";
            Engine.TimeModifier = 0f;

            Timer.Set("limit", 1f, ignoreTimeModifier: true);

            var background = new RectangleObject(Engine.Width, Engine.Height)
            {
                Order = 20, 
                Color = Color.FromArgb(225, 52, 6, 6),
                IgnoreCamera = true,
                Fill = true,
            };
            Engine.SpawnObject("gameOverBg", background);

            var gameOverText = new TextObject(2f, Color.Crimson, 0.9f)
            {
                Order = 20,
                Text = "GAMEOVER"
            };
            var gameOverMeasure = gameOverText.Measure();
            gameOverText.X = Engine.Width/2 - gameOverMeasure.X/2;
            gameOverText.Y = Engine.Height/2 - gameOverMeasure.Y/2;
            gameOverText.IgnoreCamera = true;
            Engine.SpawnObject("gameOverTxt", gameOverText);
        }
Esempio n. 2
0
        public override void Start()
        {
            AddHitBox("player", 0, 0, width, height);

            redWindow = new RectangleObject();
            redWindow.width = 0;
            redWindow.height = 0;
            redWindow.name = "redWindow";
            redWindow.color = Color.Red;
            redWindow.x = 0;
            redWindow.y = 0;
            redWindow.fill = true;
            redWindow.order = 9;
            engine.SpawnObject("redWindow", redWindow);

            base.Start();
        }
Esempio n. 3
0
        public override void Start()
        {
            Console.WriteLine("Paused");

            var background = new RectangleObject();
            background.color = Color.Black;
            background.fill = true;
            background.width = engine.width;
            background.height = engine.height;
            background.order = 10;
            engine.SpawnObject("pause_background", background);
            var pauseText = new TextObject("Phosphate", 80, "darkgreen");
            pauseText.text = "PAUSE";
            var pauseTextSize = TextRenderer.MeasureText(pauseText.text, pauseText.font);
            pauseText.x = engine.width/2 - pauseTextSize.Width/2;
            pauseText.y = engine.height/2 - pauseTextSize.Height/2;
            pauseText.order = 11;
            engine.SpawnObject("pause_text", pauseText);
        }
Esempio n. 4
0
        public override void Start()
        {
            name = "map_borders";
            blocksWithHitBox = false;

            blockW = 32; //(blockAsset).sprite.Width;
            blockH = 32; //(blockAsset).sprite.Height;

            base.Start();

            blockObject = () =>
            {
                var rectangleBlock = new RectangleObject();
                rectangleBlock.color = Color.SandyBrown;
                rectangleBlock.width = blockW;
                rectangleBlock.height = blockH;
                rectangleBlock.fill = true;
                rectangleBlock.order = 10;
                return rectangleBlock;
            };

            SpawnBorders();

            var game = (Game) engine.objects["game"];
            var roomWidth = ((engine.width - blockW*2)/(game.currentFloor.mapWidth));
            var roomHeight = ((engine.height - blockH*2)/(game.currentFloor.mapHeight));
            if (game.currentFloor.mapWidth >= game.currentFloor.mapHeight)
            {
                roomHeight = (int) (roomWidth/1.77);
            }
            else if (game.currentFloor.mapHeight > game.currentFloor.mapWidth)
            {
                roomWidth = (int) (roomHeight*1.77);
            }

            var paddingX = (engine.width - roomWidth*game.currentFloor.mapWidth - blockW*2)/2 + blockW;
            var paddingY = (engine.height - roomHeight*game.currentFloor.mapHeight - blockH*2)/2 + blockH;

            for (var bx = 0; bx < game.currentFloor.mapWidth; bx++)
            {
                for (var by = 0; by < game.currentFloor.mapHeight; by++)
                {
                    if (game.currentFloor.rooms[bx, by] != null)
                    {
                        //Room room = game.currentFloor.rooms [x, y];
                        var mapObj = new RectangleObject();
                        mapObj.color = game.currentFloor.rooms[bx, by] == game.currentFloor.currentRoom
                            ? Color.Green
                            : (game.currentFloor.rooms[bx, by].enemies.Count > 0 ? Color.SaddleBrown : Color.Wheat);
                        mapObj.fill = true;
                        mapObj.x = paddingX + roomWidth*bx + roomHeight/10;
                        mapObj.y = paddingY + roomHeight*by + roomWidth/10;
                        mapObj.width = roomWidth - roomWidth/5;
                        mapObj.height = roomHeight - roomHeight/5;
                        mapObj.order = 10;
                        Console.WriteLine("Spawning map block at: {0}.{1}", mapObj.x, mapObj.y);
                        engine.SpawnObject(string.Format("map_border_{0}_{1}", bx, by), mapObj);
                    }
                }
            }
        }
Esempio n. 5
0
        protected void GameUpdate()
        {
            Window.Update();

            UnchangedDeltaTime = Window.deltaTime;
            // having a deltatime higher than 0.33 means either that the game is having only 3fps or that something is loading
            // in both cases having a fixed maximum deltatime would make things smoother
            if (UnchangedDeltaTime > MaxDeltaTime)
                UnchangedDeltaTime = MaxDeltaTime;
            DeltaTime = UnchangedDeltaTime*TimeModifier;
            UnchangedTime += UnchangedDeltaTime;
            Time += DeltaTime;

            Timer.Update();

            OnBeforeUpdate?.Invoke(this);

            foreach (var obj in SortedObjects)
            {
                obj.UnchangedTime = UnchangedTime;
                obj.Time = Time;
                obj.UnchangedDeltaTime = UnchangedDeltaTime;
                obj.DeltaTime = DeltaTime;
                if (!obj.Enabled)
                    continue;
                obj.Draw();
                if (debugCollisions && obj.HitBoxes != null)
                {
                    foreach (var hitBox in obj.HitBoxes.Values)
                    {
                        if (hitBox.Width <= 0 || hitBox.Height <= 0)
                            continue;
                        if (!debugCollisionsBoxes.ContainsKey(hitBox) ||
                            hitBox.X != debugCollisionsBoxes[hitBox].X || hitBox.Y != debugCollisionsBoxes[hitBox].Y ||
                            hitBox.Width != debugCollisionsBoxes[hitBox].Width || hitBox.Height != debugCollisionsBoxes[hitBox].Height)
                            debugCollisionsBoxes[hitBox] = new RectangleObject(hitBox.Width, hitBox.Height)
                            {
                                Color = Color.Green
                            };
                        var rectangle = debugCollisionsBoxes[hitBox];
                        rectangle.X = obj.DrawX + hitBox.X;
                        rectangle.Y = obj.DrawY + hitBox.Y;
                        rectangle.Draw();
                    }
                }
            }

            OnAfterUpdate?.Invoke(this);

            if (dirtyObjects.Count > 0)
            {
                var newObjects = dirtyObjects.ToArray();
                dirtyObjects.Clear();
                foreach (var pair in newObjects)
                {
                    switch (pair.Value)
                    {
                        case 1:
                            pair.Key.Time = Time;
                            SortedObjects.Add(pair.Key);
                            break;
                        case 0:
                            SortedObjects.Remove(pair.Key);
                            break;
                        case 2:
                            SortedObjects.Remove(pair.Key);
                            SortedObjects.Add(pair.Key);
                            break;
                    }
                }
            }
        }
Esempio n. 6
0
        public override void Start()
        {
            int border = 1;
            int padding = 10;
            TextObject HP = new TextObject ("Arial Black", 18, "darkred");
            HP.order = this.order;
            HP.text = "HP";
            HP.x = padding;
            HP.y = padding;
            Size HPSize = TextRenderer.MeasureText (HP.text, HP.font);
            hpBarContainer = new RectangleObject ();
            hpBarContainer.x = HP.x + padding + HPSize.Width;
            hpBarContainer.y = HP.y;
            hpBarContainer.order = this.order;
            hpBarContainer.width = hudWidth;
            hpBarContainer.height = HPSize.Height;
            hpBarContainer.color = Color.Black;
            hpBar = new RectangleObject ();
            hpBar.order = this.order;
            hpBar.x = hpBarContainer.x + border;
            hpBar.y = hpBarContainer.y + border;
            hpBar.color = Color.DarkRed;
            hpBar.fill = true;
            hpBar.height = hpBarContainer.height - border * 2;
            hpTextObj = new TextObject ("Arial Black", 18, "darkred");
            hpTextObj.order = this.order;
            hpTextObj.x = hpBarContainer.x + hpBarContainer.width + padding;
            hpTextObj.y = HP.y;

            TextObject XP = new TextObject ("Arial Black", 18, "darkgreen");
            XP.order = this.order;
            XP.text = "XP";
            XP.x = padding;
            XP.y = padding + HP.y + HPSize.Height;
            Size XPSize = TextRenderer.MeasureText (XP.text, XP.font);
            xpBarContainer = new RectangleObject ();
            xpBarContainer.x = XP.x + padding + XPSize.Width;
            xpBarContainer.y = XP.y;
            xpBarContainer.order = this.order;
            xpBarContainer.width = hudWidth;
            xpBarContainer.height = XPSize.Height;
            xpBarContainer.color = Color.Black;
            xpBar = new RectangleObject ();
            xpBar.order = this.order;
            xpBar.x = xpBarContainer.x + border;
            xpBar.y = xpBarContainer.y + border;
            xpBar.color = Color.DarkOliveGreen;
            xpBar.fill = true;
            xpBar.height = xpBarContainer.height - border * 2;
            levelTextObj = new TextObject ("Arial Black", 18, "darkgreen");
            levelTextObj.order = this.order;
            levelTextObj.text = "0% to 1";
            levelTextObj.x = xpBarContainer.x + xpBarContainer.width + padding;
            levelTextObj.y = XP.y;

            engine.SpawnObject (this.name + "_hpText", HP);
            engine.SpawnObject (this.name + "_hpBarContainer", hpBarContainer);
            engine.SpawnObject (this.name + "_hpBar", hpBar);
            engine.SpawnObject (this.name + "_hpTextObj", hpTextObj);
            engine.SpawnObject (this.name + "_xpText", XP);
            engine.SpawnObject (this.name + "_xpBarContainer", xpBarContainer);
            engine.SpawnObject (this.name + "_xpBar", xpBar);
            engine.SpawnObject (this.name + "_levelTextObj", levelTextObj);
        }
Esempio n. 7
0
        public override void Start()
        {
            base.Start();

            Engine.SpawnObject("hpNumber", hpNumber);
            hpNumber.IgnoreCamera = true;

            Engine.SpawnObject("hp", hp);
            hp.X = Padding;
            hp.Y = Padding;
            hp.IgnoreCamera = true;
            hp.Text = "HP";

            Engine.SpawnObject("xpNumber", xpNumber);
            xpNumber.IgnoreCamera = true;

            var hpMeasure = hp.Measure();
            Engine.SpawnObject("xp", xp);
            xp.X = hp.X;
            xp.Y = hp.Y + hpMeasure.Y + InnerPadding;
            xp.IgnoreCamera = true;
            xp.Text = "XP";
            var xpMeasure = xp.Measure();

            //WAVE
            Engine.SpawnObject("wave", wave);
            wave.IgnoreCamera = true;

            Engine.SpawnObject("waveTimer", waveTimer);
            waveTimer.IgnoreCamera = true;
            //

            hpBar = new RectangleObject(150, (int) hpMeasure.Y)
            {
                Fill = true,
                Order = 10
            };
            xpBar = new RectangleObject(150, (int) xpMeasure.Y)
            {
                Fill = true,
                Order = 10
            };

            hpBarBorder = new RectangleObject(150, (int) hpMeasure.Y)
            {
                Order = 10
            };
            xpBarBorder = new RectangleObject(150, (int) xpMeasure.Y)
            {
                Order = 10
            };

            Engine.SpawnObject("lvl", lvl);
            lvl.X = xp.X;
            lvl.Y = xp.Y + xpMeasure.Y + InnerPadding;
            lvl.IgnoreCamera = true;
            lvl.Text = $"Level 1";

            Engine.SpawnObject("timer", timer);
            timer.X = lvl.X;
            timer.Y = lvl.Y + lvl.Measure().Y + InnerPadding;
            timer.IgnoreCamera = true;
            timer.Text = $"Timer 0";

            Engine.SpawnObject("hpBar", hpBar);
            hpBar.X = hp.X + hpMeasure.X + InnerPadding;
            hpBar.Y = hp.Y;
            hpBar.Color = Color.IndianRed;
            hpBar.IgnoreCamera = true;

            Engine.SpawnObject("xpBar", xpBar);
            xpBar.X = xp.X + xpMeasure.X + InnerPadding;
            xpBar.Y = xp.Y;
            xpBar.Color = Color.DarkBlue;
            xpBar.IgnoreCamera = true;

            Engine.SpawnObject("hpBarBorder", hpBarBorder);
            hpBarBorder.X = hp.X + hpMeasure.X + InnerPadding;
            hpBarBorder.Y = hp.Y;
            hpBarBorder.Color = Color.Black;
            hpBarBorder.IgnoreCamera = true;

            Engine.SpawnObject("xpBarBorder", xpBarBorder);
            xpBarBorder.X = xp.X + xpMeasure.X + InnerPadding;
            xpBarBorder.Y = xp.Y;
            xpBarBorder.Color = Color.Black;
            xpBarBorder.IgnoreCamera = true;
        }
Esempio n. 8
0
 public void GameOver()
 {
     mainWindow = "gameover";
     var background = new RectangleObject();
     background.color = Color.Black;
     background.fill = true;
     background.width = engine.width;
     background.height = engine.height;
     background.order = 10;
     engine.SpawnObject("gameover_background", background);
     var gameOver = new TextObject("Phosphate", 80, "red");
     gameOver.text = "GAMEOVER";
     var gameOverSize = TextRenderer.MeasureText(gameOver.text, gameOver.font);
     gameOver.x = engine.width/2 - gameOverSize.Width/2;
     gameOver.y = engine.height/2 - gameOverSize.Height/2;
     gameOver.order = 11;
     engine.SpawnObject("gameover_text", gameOver);
     gameOverTimer = gameOverDelay;
 }