Beispiel #1
0
        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            KeyboardState kState = Keyboard.GetState();

            Vector2 positionDelta = new Vector2();

            if (p != null && p.Alive)
            {
                if (kState.IsKeyDown(Keys.W)) // jump
                {
                }

                if (kState.IsKeyDown(Keys.A)) // move left
                {
                    positionDelta.X -= 4;
                }
                else if (kState.IsKeyDown(Keys.D)) // move right
                {
                    positionDelta.X += 4;
                }

                if (positionDelta.Length() > 0)
                    p.LeftwardFacing = positionDelta.X < 0;

                p.PendingMovement += positionDelta;

                camera.Focus = p.Position;

                if (positionDelta.Length() > 0 && p.EnabledGraphic != p.Graphics["run"])
                {
                    p.SwitchGraphic("run");
                }
                else if (positionDelta.Length() == 0 && p.EnabledGraphic != p.Graphics["idle"])
                {
                    p.SwitchGraphic("idle");
                }

                if (p.Hitbox.Intersects(tmapRenderer.EscapeDoorHitbox) && !p.Free)
                {
                    p.Free = true;
                    sfx["clear"].Play();

                    collisions.RemoveEntity(p);
                    p = null;

                    // display clear
                }
            }
            else
            {
                if(deathTimer == 0)
                    collisions.RemoveEntity(p);

                deathTimer += gameTime.ElapsedGameTime.Milliseconds;

                if (deathTimer >= 3*75)
                {
                    p = null;
                }
            }

            if (p != null)
                p.EnabledGraphic.Update(gameTime);

            base.Update(gameTime);
        }
Beispiel #2
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            Services.AddService(typeof(SpriteBatch), spriteBatch);

            score = new ScoreData();
            Services.AddService(typeof(ScoreData), score);

            camera = new GameCamera { X = 0, Y = 0, Width = Window.ClientBounds.Width, Height = Window.ClientBounds.Height };
            Services.AddService(typeof(GameCamera), camera);

            collisionManager = new CollisionManager(this,24,24);
            Components.Add(collisionManager);

            tmapRenderer = new TilemapRenderer(this);
            Components.Add(tmapRenderer);

            map = Tilemap.Load("testmap.tmx");
            tmapRenderer.Map = map;

            playerManager = new PlayerManager(this);
            Components.Add(playerManager);

            player = new Player();
            playerManager.Player = player;

            escapeeManager = new EscapeeManager(this);
            Components.Add(escapeeManager);

            sfx = new Dictionary<string, SoundEffect>();
            Services.AddService(typeof(Dictionary<string, SoundEffect>), sfx);

            round = new Round { ParticipantCount = 9, WaveInterval = 10 };

            uiManager = new UIManager(this);
            Components.Add(uiManager);

            base.Initialize();
        }