public CanvasCharacterRenderer(Character character)
        {
            Character = character;

            RenderPosition = new Rectangle(-1, -1, 0, 0);

            RenderRotation = 0;
        }
        public void ClientScriptSetUp()
        {
            CharacterFactory.ClearPlayers();

            CharacterFactory.AddPlayer();

            _localPlayer = CharacterFactory.GetLocalPlayerCharacter();
        }
        public static string AddPlayer()
        {
            var playerGuid = Guid.NewGuid().ToString();

            var newCharacter = new Character();

            newCharacter.Id = Guid.NewGuid();

            _playerCharacters.Add(playerGuid, newCharacter);

            LastUpdate = DateTime.Now;

            return playerGuid;
        }
        public static Guid CreateProjectile(Character owner, float speed)
        {
            var projectile = new Character
            {
                Position = new Point(owner.Position.X, owner.Position.Y),
                LookTarget = new Point(owner.LookTarget.X, owner.LookTarget.Y),
                Destination = new Point(owner.LookTarget.X, owner.LookTarget.Y),
                Speed = speed,
                Health = 10
            };
            projectile.Id = Guid.NewGuid();
            //projectile.Health = 10;

            _projectiles.Add(owner.Id, projectile);

            LastUpdate = DateTime.Now;

            return projectile.Id;
        }
示例#5
0
        private static void MoveEntityTowardDestination(Character character)
        {
            // Base class operator override would be nice, but this is one of those places we have to acquiesce to sharpkit
            if (character.Destination.X == character.Position.X && character.Destination.Y == character.Position.Y) return;

            var remainingSpeed = character.Speed;

            var xDestDiff = Math.Abs(character.Destination.X - character.Position.X);
            var yDestDiff = Math.Abs(character.Destination.Y - character.Position.Y);

            while (remainingSpeed > 0)
            {
                if (xDestDiff > yDestDiff)
                {
                    if (character.Destination.X > character.Position.X)
                    {
                        character.Position.X += 1;
                    }
                    else character.Position.X -= 1;

                    xDestDiff = Math.Abs(character.Destination.X - character.Position.X);
                }
                else
                {
                    if (character.Destination.Y > character.Position.Y)
                    {
                        character.Position.Y += 1;
                    }
                    else character.Position.Y -= 1;

                    yDestDiff = Math.Abs(character.Destination.Y - character.Position.Y);
                }

                remainingSpeed--;
            }
        }
 private static void CreateCharacterRenderer(Character character)
 {
     if(_characterRenderers == null) _characterRenderers = new List<CanvasCharacterRenderer>();
     _characterRenderers.Add(new CanvasCharacterRenderer(character));
 }
        public static void KillCharacter(Character character)
        {
            foreach (KeyValuePair<Guid, Character> projectile in _projectiles)
            {
                if (projectile.Value == character)
                {
                    _projectiles.Remove(projectile.Key);

                    return;
                }
            }

            foreach (KeyValuePair<string, Character> player in _playerCharacters)
            {
                if (player.Value == character)
                {
                    _playerCharacters.Remove(player.Key);

                    return;
                }
            }

            LastUpdate = DateTime.Now;
        }
示例#8
0
        private void SetUpTwoPlayers()
        {
            _playerOneSession = CharacterFactory.AddPlayer();

            _playerOne = CharacterFactory.GetPlayerCharacter(_playerOneSession);

            var playerTwoId = CharacterFactory.AddPlayer();

            _playerTwo = CharacterFactory.GetPlayerCharacter(playerTwoId);
        }
示例#9
0
 private static bool IsColliding(Character characterOne, Character characterTwo)
 {
     return characterOne.Area.Contains(characterTwo.Area);
 }
示例#10
0
 private static void DoCollisionDamage(Character character)
 {
     character.Health -= 10;
 }
        private void InitialConnect(out string playerId)
        {
            _browser = new Browser(with => with.Module<InitialConnect>());

            var result = _browser.Get("/InitialConnect", with => with.HttpRequest());

            var connectPacket = JsonConvert.DeserializeObject<ConnectPacket>(result.Body.AsString());

            playerId = connectPacket.SessionId;

            var playerCharacterId = connectPacket.CharacterId;

            _browser = new Browser(with => with.Module<GetPlayerList>());

            result = _browser.Get("/GetPlayerList", with => with.HttpRequest());

            var characterList = JsonConvert.DeserializeObject<Character[]>(result.Body.AsString());

            _localPlayer = characterList.FirstOrDefault(character => character.Id == playerCharacterId);

            //_localPlayer = decodedResult.CharacterId;

            //_localPlayer = decodedResult[decodedResult.Length - 1];
        }