コード例 #1
0
        public override void MapLoaded(TeeEngine engine, TiledMap map, MapEventArgs mapEventArgs)
        {
            LightShader lightShader = (LightShader)engine.GetPostGameShader("LightShader");
            lightShader.Enabled = true;

            base.MapLoaded(engine, map, mapEventArgs);
        }
コード例 #2
0
ファイル: Chest.cs プロジェクト: MichaelAquilina/Some-2D-RPG
        public override void Update(GameTime gameTime, TeeEngine engine)
        {
            Hero player = (Hero) engine.GetEntity("Player");
            KeyboardState keyboardState = Keyboard.GetState();

            if (KeyboardExtensions.GetKeyDownState(keyboardState, Keys.S, this, true)
                && Entity.IntersectsWith(this, "interaction", player, "Shadow", gameTime))
            {
                if (CurrentDrawableState != "Open")
                {
                    Random random = new Random();

                    _openSfx[random.Next(1)].Play();

                    CurrentDrawableState = "Open";
                    Drawables.ResetState("Open", gameTime);

                    for (int i = 0; i < 10; i++)
                    {
                        Coin coin = new Coin(this.Pos.X, this.Pos.Y, 100, (CoinType)random.Next(3));
                        coin.Pos.X += (float) ((random.NextDouble() - 0.5) * 100);
                        coin.Pos.Y += (float) ((random.NextDouble() - 0.5) * 100);
                        coin.TerrainCollisionEnabled = false;       // Prevent from getting stuck in sorrounding walls.

                        engine.AddEntity(coin);
                    }
                }
            }

            base.Update(gameTime, engine);
        }
コード例 #3
0
ファイル: Chest.cs プロジェクト: behindcurtain3/Some-2D-RPG
        public override void Update(GameTime gameTime, TeeEngine engine)
        {
            Hero player = (Hero) engine.GetEntity("Player");
            KeyboardState keyboardState = Keyboard.GetState();

            if (KeyboardExtensions.GetKeyDownState(keyboardState, Keys.S, this, true)
                && Entity.IntersectsWith(this, null, player, "Shadow", gameTime))
            {
                if (CurrentDrawableState != "Open")
                {
                    Random random = new Random();

                    CurrentDrawableState = "Open";
                    Drawables.ResetState("Open", gameTime);

                    for (int i = 0; i < 10; i++)
                    {
                        Coin coin = new Coin(this.Pos.X, this.Pos.Y, 100, (CoinType)random.Next(3));
                        coin.Pos.X += (float) ((random.NextDouble() - 0.5) * 100);
                        coin.Pos.Y += (float) ((random.NextDouble() - 0.5) * 100);

                        engine.AddEntity(coin);
                    }
                }
            }
        }
コード例 #4
0
        public virtual void MapLoaded(TeeEngine engine, TiledMap map, MapEventArgs mapEventArgs)
        {
            if (mapEventArgs.HasProperty("Target"))
            {
                Hero player = new Hero();
                MapEntrance targetEntrance = (MapEntrance)engine.GetEntity(mapEventArgs.GetProperty("Target"));

                player.Pos = targetEntrance.Pos + new Vector2(targetEntrance.Width, targetEntrance.Height) / 2;

                engine.AddEntity("Player", player);
            }
        }
コード例 #5
0
        void MapEntrance_MapZoneHit(MapZone sender, Entity entity, TeeEngine engine, GameTime gameTime)
        {
            if(KeyboardExtensions.GetKeyDownState(Keyboard.GetState(), ACTIVATE_KEY, engine, true) &&
               entity == engine.GetEntity("Player"))
            {
                MapEventArgs mapArgs = new MapEventArgs();
                mapArgs.SetProperty("Target", Target);

                engine.ClearEntities();
                engine.LoadMap(Destination, mapArgs);
            }
        }
コード例 #6
0
        private void CombatDummy_Hit(RPGEntity sender, Entity invoker, GameTime gameTime, TeeEngine engine)
        {
            if (!CurrentDrawableState.Contains("Spin"))
            {
                CurrentDrawableState = "Spin_" + Direction;
                Drawables.ResetState(CurrentDrawableState, gameTime);
            }

            // Play random Hit Sound.
            int index = _randomGenerator.Next(3);
            _hitSounds[index].Play();

            this.HP = this.MaxHP;
        }
コード例 #7
0
        public void staticObject_UpdateEvent(Entity caller, GameTime gameTime, TeeEngine engine)
        {
            caller.Opacity = 1.0f;

            foreach (RPGEntity entity in engine.Collider.GetIntersectingEntities<RPGEntity>(caller.CurrentBoundingBox))
            {
                if (entity != caller
                    && caller.Pos.Y > entity.Pos.Y
                    && entity.CurrentBoundingBox.Intersects(caller.CurrentBoundingBox))
                {
                    caller.Opacity = 0.5f;
                    return;
                }
            }
        }
コード例 #8
0
ファイル: Hero.cs プロジェクト: MichaelAquilina/Some-2D-RPG
        public void PerformInteraction(GameTime gameTime, TeeEngine engine)
        {
            foreach (CollidableEntity entity in IntersectingEntities)
            {
                if (entity != this
                    && entity is RPGEntity
                    && Entity.IntersectsWith(this, null, entity, null, gameTime))
                {
                    RPGEntity rpgEntity = (RPGEntity)entity;
                    if (rpgEntity.Faction == this.Faction)
                        rpgEntity.OnInteract(this, gameTime, engine);
                }

            }
        }
コード例 #9
0
        public override void OnHit(Entity sender, int damage, GameTime gameTime, TeeEngine engine)
        {
            HP = 10000; // Combat dummy always has tons of HP

            base.OnHit(sender, damage, gameTime, engine);

            if (!CurrentDrawableState.Contains("Spin"))
            {
                CurrentDrawableState = "Spin_" + Direction;
                Drawables.ResetState(CurrentDrawableState, gameTime);
            }

            // Play random Hit Sound.
            int index = _randomGenerator.Next(3);
            _hitSounds[index].Play();
        }
コード例 #10
0
        public override bool PreCreate(GameTime gameTime, TeeEngine engine)
        {
            int coinx = (Width / CoinPadding);
            int coiny = (Height / CoinPadding);

            for (int i = 0; i < coinx; i++)
            {
                for (int j = 0; j < coiny; j++)
                {
                    Coin coin = new Coin();
                    coin.CoinType = CoinType;
                    coin.CoinValue = CoinValue;
                    coin.Pos = new Vector2(Pos.X + i * CoinPadding, Pos.Y + j * CoinPadding);

                    engine.AddEntity(coin);
                }
            }

            return false;   // Destory self when ready.
        }
コード例 #11
0
ファイル: NPC.cs プロジェクト: MichaelAquilina/Some-2D-RPG
        public override void Update(GameTime gameTime, TeeEngine engine)
        {
            if (HP > 0)
            {
                AggressiveNpcAI(gameTime, engine);
                base.Update(gameTime, engine);
            }
            else
            {
                this.EntityCollisionEnabled = false;
                this.TerrainCollisionEnabled = false;

                if (!_startedDeathAnim)
                {
                    _startedDeathAnim = true;
                    CurrentDrawableState = "Death";
                    Drawables.ResetState(CurrentDrawableState, gameTime);
                }
            }
        }
コード例 #12
0
        public override void MapLoaded(TeeEngine engine, TiledMap map, MapEventArgs mapEventArgs)
        {
            LightShader lightShader = (LightShader)engine.GetPostGameShader("LightShader");
            lightShader.Enabled = false;

            Random random = new Random();

            for (int i = 0; i < 50; i++)
            {
                int px = (int)Math.Ceiling(random.NextDouble() * engine.Map.pxWidth);
                int py = (int)Math.Ceiling(random.NextDouble() * engine.Map.pxHeight);

                Bat bat = new Bat(px, py);
                Coin coin = new Coin(px, py, 100, (CoinType)random.Next(3));

                // Switch between adding bats and coins to the map.
                if (i % 2 == 0)
                    engine.AddEntity(bat);
                else
                    engine.AddEntity(coin);
            }

            base.MapLoaded(engine, map, mapEventArgs);
        }
コード例 #13
0
 public virtual void MapUnloaded(TeeEngine engine, TiledMap map)
 {
 }
コード例 #14
0
ファイル: Hero.cs プロジェクト: MichaelAquilina/Some-2D-RPG
        public override void Update(GameTime gameTime, TeeEngine engine)
        {
            KeyboardState keyboardState = Keyboard.GetState();
            Vector2 movement = Vector2.Zero;

            if (CurrentState == EntityStates.Attacking)
            {
                if (Drawables.IsStateFinished(CurrentDrawableState, gameTime))
                    CurrentState = EntityStates.Alert;
                else
                    PerformHitCheck(gameTime, engine);
            }
            else
            {
                // PERFORM ATTACK MOVE.
                if (KeyboardExtensions.GetKeyDownState(keyboardState, Keys.A, engine, true))
                {
                    CurrentState = EntityStates.Attacking;
                    CurrentDrawableState = "Slash_" + Direction;
                    ClearHitList();

                    Drawables.ResetState(CurrentDrawableState, gameTime);
                }
                else
                {
                    // PERFORM INTERACTION
                    if (KeyboardExtensions.GetKeyDownState(keyboardState, Keys.S, engine, true))
                        PerformInteraction(gameTime, engine);

                    // MOVEMENT BASED KEYBOARD EVENTS.
                    if (keyboardState.IsKeyDown(Keys.Up))
                        movement.Y--;

                    if (keyboardState.IsKeyDown(Keys.Down))
                        movement.Y++;

                    if (keyboardState.IsKeyDown(Keys.Left))
                        movement.X--;

                    if (keyboardState.IsKeyDown(Keys.Right))
                        movement.X++;

                    if (movement.Length() > 0)
                    {
                        movement.Normalize();
                        Pos += movement * _moveSpeed;
                    }

                    if (PrevPos != Pos)
                    {
                        Vector2 difference = Pos - PrevPos;
                        if (Math.Abs(difference.X) > Math.Abs(difference.Y))
                            Direction = (difference.X > 0) ? Direction.Right : Direction.Left;
                        else
                            Direction = (difference.Y > 0) ? Direction.Down : Direction.Up;

                        CurrentDrawableState = "Walk_" + Direction;
                    }
                    else CurrentDrawableState = "Idle_" + Direction;
                }
            }

            base.Update(gameTime, engine);

            // Update Light Source based on latest position.
            LightSource.Pos = this.Pos;
        }
コード例 #15
0
        public void NorthBridge_MapZoneHit(MapZone sender, Entity entity, TeeEngine engine, GameTime gameTime)
        {
            /*
            // Return if the bridge is already destroyed
            if (!(entity is Hero))
                return;

            // If it was the player that hit the zone, destroy the bridge

            TileLayer layer = engine.Map.GetLayerByName("Bridges and Items");

            if (layer != null)
            {
                layer[22, 10] = 58;
                layer[22, 11] = 59;
                layer[22, 12] = 60;
                layer[22, 13] = 59;
                Tile tile = engine.Map.GetTxTopMostTile(22, 13);
                tile.SetProperty("Impassable", "true");

                // Remove the zone that triggers this event
                engine.RemoveEntity("NorthBridgeExit");

                // Rebuild the pathfinding nodes
                engine.Pathfinding.RebuildNeighbors(engine.Map);
            }
             */
        }
コード例 #16
0
        public void Update(TeeEngine engine, GameTime gameTime)
        {
            if (!_mapLoaded) return;

            if (_isGameOver)
            {
                if (!_gameOverLoaded)
                {
                    List<Component> hudComponents = Component.LoadComponentsFromXml("HUD/Elements/GameOver.ui", engine.Game.Content);
                    foreach (Component c in hudComponents)
                        Hud.AddComponent(c.Name, c);

                    _gameOverLoaded = true;

                    Button restart = (Button)Hud.GetComponent("RestartButton");
                    restart.onMouseClick += new Component.MouseEventHandler(delegate(Component sender, MouseState mouse)
                    {
                        engine.ClearEntities();
                        engine.LoadMap("Content/Maps/arena.tmx");
                    });

                    Button exit = (Button)Hud.GetComponent("QuitButton");
                    exit.onMouseClick += new Component.MouseEventHandler(delegate(Component sender, MouseState mouse)
                    {
                        engine.Game.Exit();
                    });
                }
            }
            else
            {
                Hero player = (Hero)engine.GetEntity("Player");
                bool reduceIntensity = true;

                foreach (Entity entity in engine.EntitiesOnScreen)
                {
                    if (entity is Mob)
                    {
                        Mob mob = (Mob)entity;

                        // If any mob on screen is attacking the player, don't reduce their intensity value
                        if (mob.Stance == Mob.AttackStance.Attacking)
                        {
                            reduceIntensity = false;
                            break;
                        }
                    }
                }

                if (reduceIntensity)
                {
                    _intensityReductionTimer += gameTime.ElapsedGameTime.Milliseconds;

                    // Intensity should reduce at a rate of 90pts per 30 sec or 3pts per second
                    if (_intensityReductionTimer >= _intensityReductionDuration)
                    {
                        player.Intensity--;
                        if (player.Intensity < 0) player.Intensity = 0;

                        _intensityReductionTimer = 0;
                    }
                }

                // Check to spawn new mobs
                _mobSpawnTimer += gameTime.ElapsedGameTime.Milliseconds;

                if (_mobSpawnTimer >= _mobSpawnDelay && player.Intensity < 30)
                {
                    List<Entity> entities = new List<Entity>(engine.GetEntities());
                    List<Entity> mobs = entities.FindAll(delegate(Entity e) { return e is Mob; });

                    // Only have up to x mobs at once
                    if (mobs.Count < 15)
                    {

                        // Spawn a new mob on a random mob spawner
                        int spawner = randomGenerator.Next(0, _spawners.Count);

                        _spawners[spawner].SpawnMob(engine);
                    }

                    // Reset the timer regardless, just check again later
                    _mobSpawnTimer = 0;
                }
            }
        }
コード例 #17
0
ファイル: Hero.cs プロジェクト: MichaelAquilina/Some-2D-RPG
 public override void PostCreate(GameTime gameTime, TeeEngine engine)
 {
     engine.AddEntity(LightSource);
 }
コード例 #18
0
ファイル: NPC.cs プロジェクト: MichaelAquilina/Some-2D-RPG
        private bool PathfindingValidator(ANode current, ANode target, TeeEngine engine, GameTime gameTime)
        {
            Tile tile = engine.Map.GetTxTopMostTile((int)target.TxPos.X, (int)target.TxPos.Y);

            // Diagonal to the current tile
            bool diagonalResult = true;

            if (current != null && Vector2.Distance(current.TxPos, target.TxPos) > 1 )
            {
                Tile diagonal1 = engine.Map.GetTxTopMostTile((int)target.TxPos.X, (int)current.TxPos.Y);
                Tile diagonal2 = engine.Map.GetTxTopMostTile((int)current.TxPos.X, (int)target.TxPos.Y);

                diagonalResult =
                    diagonal1 != null && diagonal2 != null &&
                    !diagonal1.HasProperty("Impassable") && !diagonal2.HasProperty("Impassable");
            }

            return tile != null && !tile.HasProperty("Impassable") && diagonalResult;
        }
コード例 #19
0
        public void MapLoaded(TeeEngine engine, TiledMap map, MapEventArgs args)
        {
            engine.GetPostGameShader("LightShader").Enabled = false;

            _player = (Hero)engine.GetEntity("Player");

            // The player should start with zero intensity
            _player.Intensity = 0;
            _spawners = new List<MobSpawner>();

            List<Entity> entities = new List<Entity>(engine.GetEntities());
            foreach (Entity e in entities)
            {
                if (e is MobSpawner)
                    _spawners.Add((MobSpawner)e);
            }

            // Setup and load the UI
            Hud = new ArenaUI(engine.Game);

            List<Component> hudComponents = Component.LoadComponentsFromXml("HUD/Elements/Components.ui", engine.Game.Content);
            foreach (Component c in hudComponents)
                Hud.AddComponent(c.Name, c);

            // Bind data to components
            if (_player != null)
            {
                Label label = (Label)Hud.GetComponent("HeroLevel");
                if (label != null)
                    label.SetDataBinding("Level", _player);

                label = (Label)Hud.GetComponent("HeroStrength");
                if (label != null)
                    label.SetDataBinding("Strength", _player);

                label = (Label)Hud.GetComponent("HeroDexterity");
                if (label != null)
                    label.SetDataBinding("Dexterity", _player);

                label = (Label)Hud.GetComponent("HeroWisdom");
                if (label != null)
                    label.SetDataBinding("Wisdom", _player);

                Button cheat = (Button)Hud.GetComponent("CheatButton");
                if(cheat != null)
                    cheat.onMouseClick += new Component.MouseEventHandler(delegate(Component sender, MouseState mouse)
                    {
                        _player.LevelUp();
                        _player.HP = _player.MaxHP;
                    });

                _player.onItemEquipped += new NPC.OnItemEquippedEventHandler(NPC_onItemEquiped);
                _player.onItemUnEquipped += new NPC.OnItemUnEquippedEventHandler(NPC_onItemUnEquiped);
                _player.onDeath += new NPC.OnDeathEventHandler(NPC_onDeath);

                // Load the currently equipped items
                foreach (KeyValuePair<ItemType, Item> pair in _player.Equiped)
                {
                    NPC_onItemEquiped(_player, pair.Value);
                }
            }

            _mapLoaded = true;
        }
コード例 #20
0
ファイル: Hero.cs プロジェクト: behindcurtain3/TheArena
        public override void Update(GameTime gameTime, TeeEngine engine)
        {
            if (HP <= 0)
            {
                // Hero is dead :(
                // Make sure the correct animation is playing
                if (!CurrentDrawableState.Equals("Death"))
                {
                    Drawables.ResetState("Death", gameTime);
                    CurrentDrawableState = "Death";
                }

                // Reset the opacity
                if(Opacity < 1) Opacity = 1f;

            }
            else
            {
                KeyboardState keyboardState = Keyboard.GetState();

                Vector2 movement = Vector2.Zero;
                float prevX = Pos.X;
                float prevY = Pos.Y;

                Tile prevTile = engine.Map.GetPxTopMostTile(Pos.X, Pos.Y);
                float moveSpeedModifier = prevTile.GetProperty<float>("MoveSpeed", 1.0f);

                // TODO: Improve, we are retrieving this twice because it is called again in the CollidableEntity loop.
                //List<CollidableEntity> intersectingEntities = engine.GetIntersectingEntities<CollidableEntity>(CurrentBoundingBox);

                if (CurrentDrawableState.Contains("Slash")
                    && !Drawables.IsStateFinished(CurrentDrawableState, gameTime))
                {
                    foreach (Entity entity in IntersectingEntities)
                    {
                        if (this != entity && entity is NPC && !_hitEntityList.Contains(entity))
                        {
                            NPC entityNPC = (NPC)entity;
                            if (entityNPC.Faction != this.Faction)
                            {
                                _hitEntityList.Add(entityNPC);
                                entityNPC.OnHit(this, RollForDamage(), gameTime, engine);
                            }
                        }
                    }
                }
                else
                {
                    _hitEntityList.Clear();

                    if (KeyboardExtensions.GetKeyDownState(keyboardState, Keys.Space, engine, true))
                    {
                        CurrentDrawableState = "Slash_" + Direction;
                        Drawables.ResetState(CurrentDrawableState, gameTime);
                    }
                    else
                    {
                        // Interaction
                        if (KeyboardExtensions.GetKeyDownState(keyboardState, Keys.E, engine, true))
                        {
                            foreach (Entity entity in IntersectingEntities)
                            {
                                if (entity != this && entity is NPC)
                                {
                                    NPC entityNPC = (NPC)entity;
                                    if (entityNPC.Faction == this.Faction)
                                        entityNPC.OnInteract(this, gameTime, engine);
                                }

                            }
                        }

                        // MOVEMENT BASED KEYBOARD EVENTS.
                        if (keyboardState.IsKeyDown(Keys.Up) || keyboardState.IsKeyDown(Keys.W))
                        {
                            CurrentDrawableState = "Walk_Up";
                            Direction = Direction.Up;

                            movement.Y--;
                        }
                        if (keyboardState.IsKeyDown(Keys.Down) || keyboardState.IsKeyDown(Keys.S))
                        {
                            CurrentDrawableState = "Walk_Down";
                            Direction = Direction.Down;

                            movement.Y++;
                        }
                        if (keyboardState.IsKeyDown(Keys.Left) || keyboardState.IsKeyDown(Keys.A))
                        {
                            CurrentDrawableState = "Walk_Left";
                            Direction = Direction.Left;

                            movement.X--;
                        }
                        if (keyboardState.IsKeyDown(Keys.Right) || keyboardState.IsKeyDown(Keys.D))
                        {
                            CurrentDrawableState = "Walk_Right";
                            Direction = Direction.Right;

                            movement.X++;
                        }

                        // Set animation to idle of no movements where made.
                        if (movement.Length() == 0)
                            CurrentDrawableState = "Idle_" + Direction;
                        else
                        {
                            movement.Normalize();
                            Pos += movement * MOVEMENT_SPEED * moveSpeedModifier;
                        }

                        LightSource.Pos = this.Pos;
                    }
                }

                if (Opacity < 1.0f)
                    Opacity += 0.02f;

                if (Opacity > 1.0f)
                    Opacity = 1.0f;
            }

            base.Update(gameTime, engine);
        }
コード例 #21
0
ファイル: Hero.cs プロジェクト: behindcurtain3/TheArena
        public override void OnHit(Entity sender, int damage, GameTime gameTime, TeeEngine engine)
        {
            base.OnHit(sender, damage, gameTime, engine);

            if (HP <= 0)
            {
                if (!CurrentDrawableState.Contains("Death"))
                {
                    CurrentDrawableState = "Death";
                    Drawables.ResetState("Death", gameTime);
                    _onDeathSfx[randomGenerator.Next(0, _onDeathSfx.Length)].Play(0.5f, 0.0f, 0.0f);
                }
            }
            else
            {
                // Increase intensity based on how much damage is done
               Intensity += damage;

                // Gfx & Sfx
                Opacity = 0.5f;
                _onHitSfx[randomGenerator.Next(0, _onHitSfx.Length)].Play(0.5f, 0.0f, 0.0f);
            }
        }
コード例 #22
0
 public override void Update(TeeEngine engine, GameTime gameTime)
 {
     base.Update(engine, gameTime);
 }
コード例 #23
0
ファイル: Bat.cs プロジェクト: behindcurtain3/Some-2D-RPG
        public override void Update(GameTime gameTime, TeeEngine engine)
        {
            // Get the Hero player for interaction purposes.
            Hero player = (Hero)engine.GetEntity("Player");
            Vector2 prevPos = Pos;

            // Check if this Bat has died.
            if (HP <= 0)
            {
                this.Opacity -= 0.02f;
                this.Drawables.ResetState(CurrentDrawableState, gameTime);
                if (this.Opacity < 0)
                    engine.RemoveEntity(this);
            }
            else
            {
                // ATTACKING LOGIC.
                if (_attackStance == AttackStance.Attacking)
                {
                    this.Pos.X -= (float) (Math.Cos(_attackAngle) * _attackSpeed);
                    this.Pos.Y -= (float) (Math.Sin(_attackAngle) * _attackSpeed);
                    this._attackHeight.Y += 30.0f / ATTACK_COUNTER_LIMIT;
                    this.Drawables.SetGroupProperty("Body", "Offset", _attackHeight);

                    if (Entity.IntersectsWith(this, "Shadow", player, "Shadow", gameTime))
                        player.HP -= 3;

                    if (_attackCounter++ == ATTACK_COUNTER_LIMIT)
                        _attackStance = AttackStance.NotAttacking;
                }
                // ATTACK PREPERATION LOGIC.
                else if (_attackStance == AttackStance.Preparing)
                {
                    _attackHeight.Y -= 2;

                    if (_attackHeight.Y < -40)
                    {
                        _attackHeight.Y = -40;
                        _attackAngle = Math.Atan2(
                            this.Pos.Y - player.Pos.Y,
                            this.Pos.X - player.Pos.X
                            );
                        _attackStance = AttackStance.Attacking;
                        _attackCounter = 0;
                    }

                    Drawables.SetGroupProperty("Body", "Offset", _attackHeight);
                }
                // NON-ATTACKING LOGIC. PATROL AND APPROACH.
                else if (_attackStance == AttackStance.NotAttacking)
                {
                    double distance = Vector2.Distance(player.Pos, this.Pos);

                    if (distance < AGRO_DISTANCE)
                    {
                        // Move towards the player for an attack move.
                        double angle = Math.Atan2(
                            player.Pos.Y - this.Pos.Y,
                            player.Pos.X - this.Pos.X
                            );

                        // Approach Function.
                        double moveValue;
                        if (distance < ATTACK_DISTANCE)
                        {
                            _attackStance = AttackStance.Preparing;
                            moveValue = 0;
                        }
                        else
                            moveValue = _moveSpeed;

                        Pos.X += (float)(Math.Cos(angle) * moveValue);
                        Pos.Y += (float)(Math.Sin(angle) * moveValue);
                    }
                    else
                    {
                        // Perform a standard patrol action.
                        Pos.X += (float)(Math.Cos(gameTime.TotalGameTime.TotalSeconds - _randomModifier * 90) * 2);
                    }
                }

                // Determine the animation based on the change in position.
                if (Math.Abs(prevPos.X - Pos.X) > Math.Abs(prevPos.Y - Pos.Y))
                {
                    if (prevPos.X < Pos.X)
                        this.CurrentDrawableState = "Right";
                    if (prevPos.X > Pos.X)
                        this.CurrentDrawableState = "Left";
                }
                else
                {
                    if (prevPos.Y < Pos.Y)
                        this.CurrentDrawableState = "Down";
                    if (prevPos.Y > Pos.Y)
                        this.CurrentDrawableState = "Up";
                }
            }
        }
コード例 #24
0
ファイル: Hero.cs プロジェクト: behindcurtain3/Some-2D-RPG
        public override void Update(GameTime gameTime, TeeEngine engine)
        {
            KeyboardState keyboardState = Keyboard.GetState();

            Vector2 movement = Vector2.Zero;
            float prevX = Pos.X;
            float prevY = Pos.Y;

            Tile prevTile = engine.Map.GetPxTopMostTile(Pos.X, Pos.Y);
            float moveSpeedModifier = prevTile.GetProperty<float>("MoveSpeed", 1.0f);

            // ATTACK KEY.
            if (keyboardState.IsKeyDown(Keys.A))
            {
                bool reset = !CurrentDrawableState.StartsWith("Slash");
                CurrentDrawableState = "Slash_" + Direction;

                if (reset) Drawables.ResetState(CurrentDrawableState, gameTime);
            }
            else
            {
                // MOVEMENT BASED KEYBOARD EVENTS.
                if (keyboardState.IsKeyDown(Keys.Up))
                {
                    CurrentDrawableState = "Walk_Up";
                    Direction = Direction.Up;

                    movement.Y--;
                }
                if (keyboardState.IsKeyDown(Keys.Down))
                {
                    CurrentDrawableState = "Walk_Down";
                    Direction = Direction.Down;

                    movement.Y++;
                }
                if (keyboardState.IsKeyDown(Keys.Left))
                {
                    CurrentDrawableState = "Walk_Left";
                    Direction = Direction.Left;

                    movement.X--;
                }
                if (keyboardState.IsKeyDown(Keys.Right))
                {
                    CurrentDrawableState = "Walk_Right";
                    Direction = Direction.Right;

                    movement.X++;
                }

                if (KeyboardExtensions.GetKeyDownState(keyboardState, Keys.T, this, true))
                {
                    if (IsEquiped(ItemRepository.GameItems["RobeShirt"]))
                        Equip(ItemRepository.GameItems["PlateChest"]);
                    else
                        Equip(ItemRepository.GameItems["RobeShirt"]);
                }

                // Set animation to idle of no movements where made.
                if (movement.Length() == 0)
                    CurrentDrawableState = "Idle_" + Direction;
                else
                {
                    movement.Normalize();
                    Pos += movement * MOVEMENT_SPEED * moveSpeedModifier;
                }

                LightSource.Pos = this.Pos;
            }

            base.Update(gameTime, engine);
        }
コード例 #25
0
ファイル: NPC.cs プロジェクト: MichaelAquilina/Some-2D-RPG
        private void NPC_Interact(RPGEntity sender, Entity invoker, GameTime gameTime, TeeEngine engine)
        {
            SpeechBubble speech = new SpeechBubble(this, "Hello there Adventurer! Whats you're name?");

            engine.AddEntity(speech);

            Vector2 distance = this.Pos - invoker.Pos;
            if (distance.X > distance.Y)
                Direction = (distance.X > 0) ? Direction.Left : Direction.Right;
            else
                Direction = (distance.Y > 0) ? Direction.Up : Direction.Down;
        }
コード例 #26
0
        protected override void Initialize()
        {
            Engine = new TeeEngine(this, WINDOW_WIDTH, WINDOW_HEIGHT);

            base.Initialize();
        }
コード例 #27
0
 public virtual void Update(TeeEngine engine, GameTime gameTime)
 {
 }
コード例 #28
0
ファイル: Coin.cs プロジェクト: behindcurtain3/TheArena
        public override void Update(GameTime gameTime, TeeEngine engine)
        {
            Hero player = (Hero)engine.GetEntity("Player");
            Vector2 target;
            if (CoinState == State.Spawning)
            {
                target = SpawnTarget;
                float distance = Vector2.Distance(Pos, SpawnTarget);

                if (distance < 2.5)
                {
                    CoinState = State.Active;
                    Drawables.SetGroupProperty("Body", "Offset", Vector2.Zero);
                }
            }
            else
            {
                target = player.Pos;
            }

            if (IsOnScreen)
            {
                float COIN_MOVE_SPEED = 5000;
                float TERMINAL_VELOCITY = 5;

                // Find the distance between the player and this coin.
                float distanceSquared = Vector2.DistanceSquared(Pos, target);

                float speed = COIN_MOVE_SPEED / distanceSquared;  // Mangitude of velocity.
                speed = Math.Min(speed, TERMINAL_VELOCITY);

                if (speed > 0.5)
                {
                    // Calculate the angle between the player and the coin.
                    double angle = Math.Atan2(
                        target.Y - this.Pos.Y,
                        target.X - this.Pos.X
                        );

                    this.Pos.X += (float)(Math.Cos(angle) * speed);        // x component.
                    this.Pos.Y += (float)(Math.Sin(angle) * speed);        // y component.

                    // Check to see if coin can be considered collected.
                    if (Entity.IntersectsWith(this, "Shadow", player, "Shadow", gameTime))
                    {
                        CoinSound.Play(0.05f, 0.0f, 0.0f);
                        player.Gold += this.CoinValue;
                        engine.RemoveEntity(this);
                    }
                }
            }
        }
コード例 #29
0
 public override void MapUnloaded(TeeEngine engine, TiledMap map)
 {
     base.MapUnloaded(engine, map);
 }
コード例 #30
0
ファイル: NPC.cs プロジェクト: MichaelAquilina/Some-2D-RPG
        private void AggressiveNpcAI(GameTime gameTime, TeeEngine engine)
        {
            _target = GetHighestPriorityTarget(gameTime, engine, _agroDistance);

            if (CurrentState == EntityStates.Idle)
            {
                if (_target != null) CurrentState = EntityStates.Alert;
            }
            else if (CurrentState == EntityStates.Alert)
            {
                if (_target == null) CurrentState = EntityStates.Idle;
                else
                {
                    if (Vector2.Distance(this.Pos, _target.Pos) < _attackDistance)
                    {
                        // Only Attack during specific delayed intervals.
                        if (gameTime.TotalGameTime.TotalMilliseconds - _lastAttack > _attackDelay + _randomDelay)
                        {
                            _lastAttack = gameTime.TotalGameTime.TotalMilliseconds;
                            _randomDelay = RPGRandomGenerator.Next(1000);

                            CurrentDrawableState = "Slash_" + Direction;
                            CurrentState = EntityStates.Attacking;

                            ClearHitList();
                            Drawables.ResetState(CurrentDrawableState, gameTime);
                        }
                    }
                    else
                    {
                        Path path = engine.Pathfinding.GeneratePath(this.Pos, _target.Pos, engine, gameTime, PathfindingValidator);
                        FollowPath(path, engine);
                    }

                    Vector2 difference = this.Pos - _target.Pos;
                    if (Math.Abs(difference.X) > Math.Abs(difference.Y))
                        Direction = (difference.X > 0) ? Direction.Left : Direction.Right;
                    else
                        Direction = (difference.Y > 0) ? Direction.Up : Direction.Down;
                }
            }
            else if (CurrentState == EntityStates.Attacking)
            {
                PerformHitCheck(gameTime, engine);
                if (Drawables.IsStateFinished(CurrentDrawableState, gameTime))
                    CurrentState = EntityStates.Alert;
            }

            // Update Idle or Walking animations.
            if (CurrentState == EntityStates.Alert || CurrentState == EntityStates.Idle)
            {
                if (PrevPos != Pos)
                {
                    Vector2 difference = Pos - PrevPos;
                    if (Math.Abs(difference.X) > Math.Abs(difference.Y))
                        Direction = (difference.X > 0) ? Direction.Right : Direction.Left;
                    else
                        Direction = (difference.Y > 0) ? Direction.Down : Direction.Up;

                    CurrentDrawableState = "Walk_" + Direction;
                }
                else CurrentDrawableState = "Idle_" + Direction;
            }
        }