Пример #1
0
        public override void HandleKeyboardInput(GameTime gameTime, EngineGame world)
        {
            if (collided && DialogueRootsList.Count > 0)
            {
                if (InputManager.Instance.ActionPressed(InputManager.ButtonActions.Pickup) && !game.ScreenManager.IsInDialogueState())
                {
                    game.ScreenManager.AddScreen(DialogueScreen.InitializeDialogueBox(new Guid(DialogueRootsList[DialogueState])), null);
                    if (DialogueState == 1 && !vineDropped)
                    {
                        var x = PhysicsConstants.PixelsToMeters(3826);
                        var y = PhysicsConstants.PixelsToMeters(1611);
                        var vineLadder = new Ladder(new Vector2(x, y),
                                                    10,
                                                    750,
                                                    false,
                                                    true,
                                                    false);
                        var vineTile = new Tile("Textures/Tiles/Climbing vine",
                                                new Vector2(x, y),
                                                0f,
                                                new Vector2(1.0f, .8f),
                                                RenderLayer.Gameground,
                                                -50);

                        game.LevelManager.RegisterEntity(vineLadder);
                        game.LevelManager.RegisterTile(vineTile);

                        vineDropped = true;
                    }
                }
            }
        }
Пример #2
0
        public override void OnUpdate(GameTime time, EngineGame world)
        {
            timeSinceLastSpawn += time.ElapsedGameTime.Milliseconds;
            spawnGuard += time.ElapsedGameTime.Milliseconds;
            if (character != null && timeSinceLastSpawn > TimeBetweenSpawns)
            {
                if (spawnGuard > 1000)
                {
                    var zoomer = new Zoomer(character.Position + PhysicsConstants.PixelsToMeters(new Vector2(Engine.GraphicsDevice.Viewport.Width * .75f, 0)));
                    zoomer.Facing = 4.71f;
                    zoomer.Speed = 300;

                    Engine.LevelManager.RegisterEntity(zoomer);

                    zoomer.PerformZoom();

                    spawnGuard = 0;
                    count++;

                    if (count >= SpawnCount)
                    {
                        timeSinceLastSpawn = 0;
                        count = 0;
                    }
                }
            }
        }
Пример #3
0
 public override void HandleKeyboardInput(GameTime gameTime, EngineGame world)
 {
     if (collided && DialogueRootsList.Count > 0)
     {
         if (InputManager.Instance.ActionPressed(InputManager.ButtonActions.Pickup) && !game.ScreenManager.IsInDialogueState())
         {
             game.ScreenManager.AddScreen(DialogueScreen.InitializeDialogueBox(new Guid(DialogueRootsList[DialogueState])), null);
             Passable = true;
         }
     }
 }
Пример #4
0
        public override void OnUpdate(GameTime time, EngineGame world)
        {
            if (!Enabled)
            {
                object result;
                world.LevelManager.LevelCache.TryGetValue(ConditionKey, out result);
                if (result != null) Enabled = (bool)result;
            }
            else

            base.OnUpdate(time, world);
        }
Пример #5
0
        public EngineGame(int width, int height)
            : base()
        {
            graphics = new GraphicsDeviceManager(this);
            graphics.IsFullScreen = false;
            graphics.PreferredBackBufferHeight = height;
            graphics.PreferredBackBufferWidth = width;

            Content.RootDirectory = "Content";

            ScreenManager = new ScreenManager(this);

            Instance = this;

            GamepadEnabled = true;
        }
Пример #6
0
 public virtual void OnUpdate(GameTime time, EngineGame world)
 {
 }
Пример #7
0
 public virtual void HandleKeyboardInput(GameTime gameTime, EngineGame world)
 {
 }
Пример #8
0
        public override void InitializePhysics(bool force, IComponentContext engineRegistrations)
        {
            if (force || !initialized)
            {
                var cache = engineRegistrations.Resolve<IResourceCache<Texture2D>>();
                var texture = cache.GetResource(TextureName);
                var world = engineRegistrations.Resolve<PhysicsManager>().World;
                game = engineRegistrations.ResolveOptional<EngineGame>();

                if (game != null && game.GamepadEnabled)
                {
                    ACTION_POPUP = InputManager.Instance.GamepadTextures[InputManager.ButtonActions.Pickup];
                }

                //Width = texture.Width;
                //Height = texture.Height;
                Physics = BodyFactory.CreateRectangle(
                    world,
                    PhysicsConstants.PixelsToMeters(Width),
                    PhysicsConstants.PixelsToMeters(Height),
                    1,
                    Position);
                Physics.FixedRotation = true;
                Physics.BodyType = BodyType.Static;
                Physics.UserData = this;

                var fix = Physics.FixtureList[0];
                fix.CollisionCategories = Category.Cat3;
                fix.CollidesWith = Category.Cat1;

                HitSensor = BodyFactory.CreateRectangle(
                    world,
                    PhysicsConstants.PixelsToMeters(Width) * 2,
                    PhysicsConstants.PixelsToMeters(Height),
                    1,
                    Position);
                HitSensor.IsSensor = true;
                HitSensor.CollisionCategories = Category.Cat2;
                HitSensor.CollidesWith = Category.Cat2;

                HitSensor.RegisterOnCollidedListener<UserControlledCharacter>(OnCollidedWith);
                HitSensor.RegisterOnSeparatedListener<UserControlledCharacter>(OnSeparation);

                popup = new ItemPopup(ACTION_POPUP,
                    Physics.Position + new Vector2(0, -PhysicsConstants.PixelsToMeters(Height / 2 + POPUP_OFFSET)),
                    cache);

                initialized = true;
            }

            base.InitializePhysics(false, engineRegistrations);
        }
Пример #9
0
        public override void OnUpdate(GameTime time, EngineGame world)
        {
            animTimer += (float)time.ElapsedGameTime.TotalMilliseconds;
            base.OnUpdate(time, world);

            if (!collided.Any())
                anchors.ForEach(x => x.IgnoreGravity = false);

            foreach (var x in collided)
                anchors.ForEach(b => b.ApplyForce(-x.Item2 * 10));

            if (PreviousPosition != null)
            {
                Vector2 move = Position - (PreviousPosition ?? Position);
                move.Normalize();

                angle = (float)Math.Atan2(move.Y, move.X);

                if (generalDirection == -1)
                    angle += (float)Math.PI;
            }
            if (animTimer >= animInterval)
            {
                anim.CurrentFrame = (anim.CurrentFrame + 1) % anim.NumFrames;
                animTimer = 0f;
            }
        }
Пример #10
0
        public override void InitializePhysics(bool force, IComponentContext engineRegistrations)
        {
            if (force || !initialized)
            {
                var world = engineRegistrations.Resolve<PhysicsManager>().World;
                levelManager = engineRegistrations.Resolve<LevelManager>();
                engineGame = engineRegistrations.ResolveOptional<EngineGame>();

                Physics = BodyFactory.CreateRectangle(
                    world,
                    PhysicsConstants.PixelsToMeters(Width),
                    PhysicsConstants.PixelsToMeters(Height),
                    1,
                    Position,
                    this);
                Physics.BodyType = BodyType.Static;
                Physics.IsSensor = true;
                _geom = Physics.FixtureList;

                RegisterCollisions();

                initialized = true;
            }

            base.InitializePhysics(false, engineRegistrations);
        }
Пример #11
0
        public override void OnUpdate(GameTime time, EngineGame world)
        {
            base.OnUpdate(time, world);
            if (!Dead)
            {
                elapsedCycle += time.ElapsedGameTime.Milliseconds;

                var slowDown = Engine.LevelManager.PhysicsManager.GlobalReferenceScale;
                if (lastGlobalReference != slowDown)
                {
                    elapsedCycle *= slowDown / lastGlobalReference;
                    lastGlobalReference = slowDown;
                }

                Physics.Rotation = (float)(-Math.Atan((float)Math.Cos(((elapsedCycle % (slowDown * CYCLE_TIME)) / (slowDown * CYCLE_TIME)) * 2 * Math.PI)) + Math.PI);
                Position = new Vector2(
                    startingX + (maxOffset * (float)Math.Sin(((elapsedCycle % (slowDown * CYCLE_TIME)) / (slowDown * CYCLE_TIME)) * 2 * Math.PI)),
                    Position.Y);
            }
        }
Пример #12
0
        public void Fire(UserControlledCharacter character, EngineGame world, GameTime gameTime, double holdTime, bool charged)
        {
            Arrow arrow = new Arrow(
                new Vector2(character.Physics.Position.X,// + UserControlledCharacter.X_OFFSET,
                            character.Physics.Position.Y + UserControlledCharacter.Y_OFFSET));

            world.LevelManager.RegisterEntity(arrow);

            character.InHold = false;

            var elapsedTime = Math.Min(gameTime.TotalGameTime.TotalSeconds - holdTime, MAX_ARROW_HOLD);
            // linear interp: y = 500 + (x - 0)(1300 - 500)/(MAX_HOLD-0) x = elapsedTime
            float speed =
                MIN_ARROW_INIT_SPEED + (MAX_ARROW_INIT_SPEED - MIN_ARROW_INIT_SPEED) /
                                       MAX_ARROW_HOLD *
                                       (float)elapsedTime;

            Vector2 initialVelocity = PhysicsConstants.PixelsToMeters(speed * character.Direction);
            if (character.Direction.Y == 0)
            {
                var rotation = (float)Math.PI / 32;
                rotation *= character.Direction.X > 0
                    ? -1
                    : 1;
                initialVelocity = Vector2.Transform(initialVelocity, Matrix.CreateRotationZ(rotation));
                arrow.Physics.Rotation = rotation;
            }
            arrow.Physics.LinearVelocity += initialVelocity;
        }
Пример #13
0
 public override void OnUpdate(GameTime time, EngineGame world)
 {
     if (Activated)
     {
         elapsedTime += time.ElapsedGameTime.Milliseconds;
         UpdatePostion(elapsedTime);
     }
 }
Пример #14
0
        public override void OnUpdate(GameTime time, EngineGame world)
        {
            //base.OnUpdate(time, world);

            if (IsShooting)
            {
                var lastTime = time.ElapsedGameTime.Milliseconds;
                lastShotTime += lastTime;
                animTimer += lastTime;

                if (lastShotTime > 5000)
                {
                    if (numShotsFired < 3)
                    {
                        anim.CurrentFrame = 7;
                        animTimer = 0f;
                        Shoot(world);
                        lastShotTime = 0;
                    }
                    else
                    {
                        IsShooting = false;
                    }
                }
                if (animTimer >= animInterval)
                {
                    if (anim.CurrentFrame < (anim.NumFrames - 2) && anim.CurrentFrame != 0)
                    {
                        anim.CurrentFrame = (anim.CurrentFrame + 1) % (anim.NumFrames - 1);
                    }
                    else if (anim.CurrentFrame == 0 || anim.CurrentFrame == 7)
                    {
                        anim.CurrentFrame = 1;
                    }

                    animTimer = 0;
                }
            }
            else
                anim.CurrentFrame = 0;
        }
Пример #15
0
 public override void HandleKeyboardInput(GameTime gameTime, EngineGame world)
 {
     if (collided && !used)
     {
         if (InputManager.Instance.ActionPressed(InputManager.ButtonActions.Pickup))
         {
             ExecuteAction();
         }
         if (InputManager.Instance.ActionHeld(InputManager.ButtonActions.Pickup))
         {
             ExecuteHeldAction(gameTime);
         }
     }
     if (used && !usedGuard)
     {
         engine.LevelManager.RenderManager.UnregisterRenderable(popup);
         registered = false;
         usedGuard = true;
     }
 }
Пример #16
0
        public override void OnUpdate(GameTime time, EngineGame world)
        {
            if (charged && character.Mana > 0)
            {
                character.Mana = Math.Max(0, character.Mana - time.ElapsedGameTime.Milliseconds * MANA_DRAIN_PER_MILLI);
                Engine.UpdateHealth();
            }
            else
            {
                charged = false;
                Engine.LevelManager.PhysicsManager.GlobalReferenceScale = 1;
            }

            timeSinceLastShot += time.ElapsedGameTime.Milliseconds;
            if (reloading)
            {
                reload_count += time.ElapsedGameTime.Milliseconds;
                chargeBar.UpdateProgress(reload_count, RELOAD_TIME);
                chargeBar.Position = Character.Position;

                if (reload_count > RELOAD_TIME * Engine.LevelManager.PhysicsManager.GlobalReferenceScale)
                {
                    Engine.LevelManager.RenderManager.UnregisterRenderable(chargeBar);
                    reload_count = 0;
                    reloading = false;
                    ammo = MAX_AMMO;
                }
            }

            base.OnUpdate(time, world);
        }
Пример #17
0
        public void Fire(UserControlledCharacter character, EngineGame world, GameTime gameTime, double holdTime, bool charged)
        {
            Character = character;
            if (timeSinceLastShot >= TIME_BETWEEN_SHOTS * Engine.LevelManager.PhysicsManager.GlobalReferenceScale && !reloading && ammo > 0)
            {
                timeSinceLastShot = 0;
                EnergyBullet bullet = new EnergyBullet(
                    new Vector2(character.Physics.Position.X,// + UserControlledCharacter.X_OFFSET,
                                character.Physics.Position.Y + Y_OFFSET),
                                20, 20,
                                PhysicsConstants.PixelsToMeters(BULLET_SPEED * character.Direction));

                ammo -= 1;

                if (ammo <= 0)
                {
                    Reload();
                }

                world.LevelManager.RegisterEntity(bullet);
            }
        }
Пример #18
0
        public override void OnUpdate(GameTime time, EngineGame game)
        {
            base.OnUpdate(time, game);

            if (!zoomed)
            {
                RayCastCallback cb = delegate(Fixture fixture, Vector2 point, Vector2 normal, float fraction)
                {
                    if (fixture.Body.UserData is UserControlledCharacter)
                    {
                        PerformZoom();
                        return 0;
                    }
                    else if (fixture.Body.UserData is WorldGeometry2)
                    {
                        return 0;
                    }
                    else
                    {
                        return -1;
                    }
                };

                game.LevelManager.PhysicsManager.World.RayCast(
                    cb,
                    Position,
                    Position + (new Vector2((float)Math.Sin(Facing), -(float)Math.Cos(Facing)) * RAY_LENGTH));
            }
        }
Пример #19
0
        public override void OnUpdate(GameTime time, EngineGame world)
        {
            base.OnUpdate(time, world);

            if (Dead)
            {
                world.LevelManager.RenderManager.UnregisterRenderable(this);
                world.LevelManager.PhysicsManager.UnregisterPhysicsBody(this);
            }
            else
                Physics.Rotation = (float)Math.Atan2(Physics.LinearVelocity.Y, Physics.LinearVelocity.X);
        }
Пример #20
0
        internal void Update(GameTime time, EngineGame world)
        {
            OnUpdate(time, world);

            if (Physics != null)
            {
                PreviousPosition = new Vector2(Position.X, Position.Y);
            }
        }
Пример #21
0
        public override void OnUpdate(GameTime time, EngineGame world)
        {
            timer += (float)time.ElapsedGameTime.TotalMilliseconds;

            if (rendering.CurrentFrame == rendering.NumFrames - 1)
            {
                activated = true;
                activating = false;
            }
            else if (timer >= interval && activating)
            {
                rendering.CurrentFrame = (rendering.CurrentFrame + 1) % rendering.NumFrames;
                timer = 0f;
            }
            rendering.Position = PhysicsConstants.MetersToPixels(position);
        }
Пример #22
0
 public override void HandleKeyboardInput(GameTime gameTime, EngineGame world)
 {
     if (InputManager.Instance.ActionPressed(InputManager.ButtonActions.Interact) && registered)
     {
         Physics.IgnoreGravity = false;
         Physics.BodyType = BodyType.Dynamic;
     }
 }
Пример #23
0
 private void Shoot(EngineGame world)
 {
     var largeBullet = new LargeBullet(
         Position + PhysicsConstants.PixelsToMeters(new Vector2(Width / 2, -Height / 4)),
         100, 30, new Vector2(30, 0));
     world.LevelManager.RegisterEntity(largeBullet);
     numShotsFired++;
 }
Пример #24
0
        public void Fire(UserControlledCharacter character, EngineGame world, GameTime gameTime, double holdTime, bool charged)
        {
            character.InHold = false;

            var elapsedTime = Math.Min(gameTime.TotalGameTime.TotalSeconds - holdTime, MAX_GRENADE_HOLD);
            // linear interp: y = 500 + (x - 0)(1300 - 500)/(MAX_HOLD-0) x = elapsedTime
            float speed =
                MIN_GRENADE_INIT_SPEED + (MAX_GRENADE_INIT_SPEED - MIN_GRENADE_INIT_SPEED) /
                                       MAX_GRENADE_HOLD *
                                       (float)elapsedTime;

            Vector2 initialVelocity = PhysicsConstants.PixelsToMeters(speed * character.Direction);
            if (character.Direction.Y == 0)
            {
                var rotation = (float)Math.PI / 32;
                rotation *= character.Direction.X > 0
                    ? -1
                    : 1;
                initialVelocity = Vector2.Transform(initialVelocity, Matrix.CreateRotationZ(rotation));
            }

            TimeGrenade grenade = new TimeGrenade(
                new Vector2(character.Physics.Position.X,// + UserControlledCharacter.X_OFFSET,
                            character.Physics.Position.Y + UserControlledCharacter.Y_OFFSET),
                initialVelocity,
                DEFAULT_FUSE_TIME,
                DEFAULT_LINGER_TIME);

            world.LevelManager.RegisterEntity(grenade);
        }
Пример #25
0
        /// <summary>
        /// Updates the state of the game. This method checks the GameScreen.IsActive
        /// property, so the game will stop updating when the pause menu is active,
        /// or if you tab away to a different application.
        /// </summary>
        public override void Update(GameTime gameTime, bool otherScreenHasFocus,
            bool coveredByOtherScreen, EngineGame world)
        {
            // Make the menu slide into place during transitions, using a
            // power curve to make things look more interesting (this makes
            // the movement slow down as it nears the end)

            base.Update(gameTime, otherScreenHasFocus, false, world);

            // Gradually fade in or out depending on whether we are covered by the pause screen.
            if (coveredByOtherScreen)
                pauseAlpha = Math.Min(pauseAlpha + 1f / 32, 1);
            else
                pauseAlpha = Math.Max(pauseAlpha - 1f / 32, 0);

            if (IsActive)
            {
                UpdateHudElements();
                currentLevel.PhysicsManager.Update(gameTime);
                currentLevel.Level.Entities.ForEach(
                    x =>
                    {
                        var scale = currentLevel.PhysicsManager.TimeScaleLookup(x.PreviousPosition ?? x.Position);
                        x.Update(
                            new GameTime(
                                new TimeSpan((long)(gameTime.TotalGameTime.Ticks * scale)),
                                new TimeSpan((long)(gameTime.ElapsedGameTime.Ticks * scale)),
                                gameTime.IsRunningSlowly),
                            EngineGame.Instance);
                    });
            }
        }
Пример #26
0
 public override void OnUpdate(GameTime time, EngineGame world)
 {
     if (!exploded)
     {
         fuseTime -= time.ElapsedGameTime.TotalMilliseconds;
         if (fuseTime <= 0)
         {
             exploded = true;
             blast = new TimeScaleCircle()
             {
                 Center = Position,
                 Radius = PhysicsConstants.PixelsToMeters(100),
                 TimeScale = .3f
             };
             world.LevelManager.Level.TimeScaleCircles.Add(blast);
         }
     }
     else
     {
         lingerTime -= time.ElapsedGameTime.TotalMilliseconds;
         if (lingerTime <= 0)
         {
             world.LevelManager.RenderManager.UnregisterRenderable(this);
             world.LevelManager.PhysicsManager.UnregisterPhysicsBody(this);
             world.LevelManager.Level.TimeScaleCircles.Remove(blast);
             Dead = true;
         }
     }
 }
Пример #27
0
        public override void InitializePhysics(bool force, IComponentContext engineRegistrations)
        {
            if (force || !initialized)
            {
                var cache = engineRegistrations.Resolve<IResourceCache<Texture2D>>();
                var world = engineRegistrations.Resolve<PhysicsManager>().World;
                engine = engineRegistrations.ResolveOptional<EngineGame>();
                Physics = BodyFactory.CreateBody(world, Position, this);

                if (engine != null && engine.GamepadEnabled)
                {
                    ACTION_POPUP = InputManager.Instance.GamepadTextures[InputManager.ButtonActions.Interact];
                }

                float spriteWidthMeters = PhysicsConstants.PixelsToMeters(Width);
                float spriteHeightMeters = PhysicsConstants.PixelsToMeters(Height);

                var rect = FixtureFactory.AttachRectangle(
                    spriteWidthMeters,
                    PhysicsConstants.PixelsToMeters(10),
                    1.4f,
                    Vector2.Zero,
                    Physics);

                Physics.BodyType = BodyType.Static;
                Physics.IgnoreGravity = true;
                Physics.IsSensor = false;

                Physics.RegisterOnCollidedListener<UserControlledCharacter>(OnCollidedWith);
                Physics.RegisterOnSeparatedListener<UserControlledCharacter>(OnSeparation);

                popupTrigger = new ItemPopup(
                    ACTION_POPUP,
                    new Vector2(Physics.Position.X, Physics.Position.Y - PhysicsConstants.PixelsToMeters(100)),
                    cache);

                initialized = true;
            }

            base.InitializePhysics(false, engineRegistrations);
        }
Пример #28
0
 public void Use(UserControlledCharacter character, EngineGame world, GameTime gameTime, double holdTime, bool charged)
 {
     Fire(character, world, gameTime, holdTime, charged);
 }
Пример #29
0
        public override void OnUpdate(GameTime time, EngineGame world)
        {
            base.OnUpdate(time, world);

            var transform = StartPosition - EndPosition;

            var timeScale = Math.PI * 2 / TimeSpan;
            var theta = timeScale * time.TotalGameTime.TotalSeconds;

            var targetPosition = StartPosition + transform * (-.5f * (float)Math.Cos(theta) - .5f) * Vector2.One;

            Physics.LinearVelocity = (targetPosition - Position) / (float)time.ElapsedGameTime.TotalSeconds;
        }
Пример #30
0
 public override void HandleKeyboardInput(GameTime gameTime, EngineGame world)
 {
 }