Esempio n. 1
0
        public Stage1() : base("stage1")
        {
            this.Size.Set(500, 500);
            players = new Player[6];

            PlayerOverlay.NumOverlays = 0;

            this.Events.AddEvent("HandleNewConnections", PriorityType.INPUT, CheckForNewInput, 5000, 500);

            //Initializing First Entities
            map.AddEntity(new Enemy());
            map.AddEntity(new Sword());
            map.AddEntity(new PoisonBow());
            map.AddEntity(new Shield());
            map.AddEntity(new RegenPotion());
            map.AddEntity(new SpeedRing());

            audio.PlayBufferedAudio("AwesomeMusic.flac", "AwesomeMusic", true, 60);

            this.Events.AddEvent("add-new-enemy", PriorityType.LOGIC, AddEnemy, enemySpawnRate);
            this.Events.AddEvent("update-enemy-positions", PriorityType.LOGIC, UpdateEnemyPositions, 20);
            this.Events.AddEvent("update-enemy-positions", PriorityType.LOGIC, () => {
                foreach (var entity in map.GetEntities(e => e.EntityType == EntityType.Enemy))
                {
                    var enemy = entity as Enemy;
                    enemy.Animate();
                }
                return(ControlEvent.NONE);
            }, 1000);
            this.Events.AddEvent("update-fly-positions", PriorityType.LOGIC, UpdateFlyPositions, 20);
            this.Events.AddEvent("rotateSword", PriorityType.LOGIC, UpdateSwordAnimation, 100);
            this.Events.AddEvent("rotatePoisonArrow", PriorityType.LOGIC, UpdatePoisonBowAnimation, 100);
            this.Events.AddEvent("rotateShield", PriorityType.LOGIC, UpdateShieldAnimation, 100);
            this.Events.AddEvent("rotateRegenPotion", PriorityType.LOGIC, UpdateRegenPotionAnimation, 100);
            this.Events.AddEvent("rotateSpeedRing", PriorityType.LOGIC, UpdateSpeedRingAnimation, 100);

            this.Events.AddEvent("ant-fireballs", PriorityType.LOGIC, () => {
                var enemies = this.map.GetEntities(entity => entity as Enemy != null).ToArray();
                for (int i = 0; i < enemies.Length; i++)
                {
                    var entity = enemies[i];
                    var enemy  = entity as Enemy;

                    if (enemy.IsAnt)
                    {
                        enemy.CastFireball();
                    }
                }

                return(ControlEvent.NONE);
            }, 10);
            this.Events.AddEvent("ant-fireballs-update", PriorityType.LOGIC, (Func <ControlEvent>)(() => {
                var fireballs = this.map.GetEntities(entity => entity as Fireball != null).ToArray();
                for (int i = 0; i < fireballs.Length; i++)
                {
                    (fireballs[i] as Fireball).Move();
                }
                return(ControlEvent.NONE);
            }), 10);


            Debug.AddDebugCommand("enablekeys", (data) => {
                var canvas = GameWindow.Singleton.Canvas;
                this.Events.AddEvent("debug-keys", PriorityType.INPUT, () => {
                    float speed = 1;
                    float boost = 10;
                    float dx    = 0;
                    float dy    = 0;

                    if (canvas.IsKeyDown(KeyboardKey.LShift) || canvas.IsKeyDown(KeyboardKey.RShift))
                    {
                        speed = boost;
                    }
                    if (canvas.IsKeyDown(KeyboardKey.Up))
                    {
                        dy -= speed;
                    }
                    if (canvas.IsKeyDown(KeyboardKey.Down))
                    {
                        dy += speed;
                    }
                    if (canvas.IsKeyDown(KeyboardKey.Left))
                    {
                        dx -= speed;
                    }
                    if (canvas.IsKeyDown(KeyboardKey.Right))
                    {
                        dx += speed;
                    }

                    this.players[0]?.Position.Add(dx, dy);

                    return(ControlEvent.NONE);
                }, 10);
            });
            Debug.AddDebugCommand("setplayerposition", (data) => {
                int id  = int.Parse(data[0]);
                float x = float.Parse(data[1]);
                float y = float.Parse(data[2]);

                this.players[id]?.Position.Set(x, y);
            });
            Debug.AddDebugCommand("newplayer", (data) => {
                debugPlayerID = uint.Parse(data[0]);
                this.HandleJoystickButtonPressed(new JoystickButtonPressedEvent()
                {
                    Button     = JoystickButton.A,
                    JoystickID = debugPlayerID
                });
            });

            Debug.AddDebugCommand("additem", (data) => {
                map.AddEntity(new Sword());
            });
        }