Пример #1
0
 public void Update(float deltaTime)
 {
     if (!IsOnline)
     {
         return;
     }
     if (Rotation != RotationState.Motionless)
     {
         RotationAngle += (ROTATION_SPEED * deltaTime) * (Rotation.Equals(RotationState.Left) ? -1f : 1f);
     }
     if (Movement != MovementState.Motionless)
     {
         Continental.Games.Vector2 pos = Position;
         // eval and update position..z
         if (Movement.Equals(MovementState.Forward))
         {
             pos.X += MOVEMENT_SPEED * deltaTime * (float)Math.Sin(RotationAngle * Deg2Rad);
             pos.Y += MOVEMENT_SPEED * deltaTime * (float)Math.Cos(RotationAngle * Deg2Rad);
         }
         else if (Movement.Equals(MovementState.Backward))
         {
             pos.X -= MOVEMENT_SPEED * deltaTime * (float)Math.Sin(RotationAngle * Deg2Rad);
             pos.Y -= MOVEMENT_SPEED * deltaTime * (float)Math.Cos(RotationAngle * Deg2Rad);
         }
         // keep in bounds
         if (pos.X < Globals.MIN_X)
         {
             pos.X = Globals.MIN_X;
         }
         if (pos.Y < Globals.MIN_Y)
         {
             pos.Y = Globals.MIN_Y;
         }
         if (pos.X > Globals.MAX_X)
         {
             pos.X = Globals.MAX_X;
         }
         if (pos.Y > Globals.MAX_Y)
         {
             pos.Y = Globals.MAX_Y;
         }
         this.Position = pos;
     }
 }
Пример #2
0
        public new void Deserialize(System.IO.BinaryReader br, short command)
        {
            Continental.Games.Vector2 pos;
            switch (command)
            {
            case NetworkCommands.INIT_AREA:
            case NetworkCommands.PLAYER_ADDED:
                playerId = br.ReadUInt64();
                Name     = br.ReadString();
                IsOnline = br.ReadBoolean();
                pos      = new Continental.Games.Vector2();
                pos.Deserialize(br, command);
                Position      = pos;
                RotationAngle = br.ReadSingle();
                Rotation      = (RotationState)br.ReadByte();
                Movement      = (MovementState)br.ReadByte();
                Continental.Games.Color color = new Continental.Games.Color();
                color.Deserialize(br, command);
                Color = color;
                break;

            case NetworkCommands.PLAYER_CHARACTER_STATE_CHANGE:
                playerId = br.ReadUInt64();
                Movement = (MovementState)br.ReadByte();
                if (Movement.Equals(MovementState.Motionless))                         // character stopped, update position
                {
                    pos = new Continental.Games.Vector2();
                    pos.Deserialize(br, command);
                    Position = pos;
                }
                Rotation = (RotationState)br.ReadByte();
                if (Rotation.Equals(RotationState.Motionless))                         // rotation stopped, update angle
                {
                    RotationAngle = br.ReadSingle();
                }
                CommandTime = new DateTime(br.ReadInt64());
                break;

            case NetworkCommands.ONLINE_STATE_CHANGE:
                playerId = br.ReadUInt64();
                IsOnline = br.ReadBoolean();
                break;
            }
        }