Changeset 7809


Ignore:
Timestamp:
2016-07-05 17:33:31 (3 years ago)
Author:
empaheik
Message:

Yksinpelaajan kamerakokeiluja.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 2016/27/ohjaajat/VenienteFragore/VenienteFragore/VenienteFragore/VenienteFragore.cs

    r7807 r7809  
    2222        private List<Player> advenae = new List<Player>(); 
    2323 
     24        private Vector cameraSpeed = new Vector(2.0, 4.0); 
     25        private Vector cameraTarget; 
     26 
    2427        public VenienteFragore() : base(tileSize: 50) 
    2528        { 
     
    2831        public override void Begin() 
    2932        { 
    30  
    31  
    3233            objectMethods = new Dictionary<string, ObjectMethod>(); 
    3334            objectMethods.Add("ball", TestBall); 
     
    4344            Gravity = new Vector(0, -800); 
    4445 
    45             Camera.ZoomToLevel(); 
    46  
     46            //Camera.ZoomToLevel(); 
    4747 
    4848            Level.Background.Color = Color.Beige; 
    4949 
    5050            Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
     51 
     52            CameraInitialization(); 
     53        } 
     54 
     55        void CameraInitialization() 
     56        { 
     57            Camera.StayInLevel = true; 
     58 
     59            Timer checkit = new Timer(); 
     60            checkit.Interval = 0.02; 
     61            checkit.Timeout += () => { UpdateCameraTarget(checkit); }; 
     62            checkit.Start(); 
     63        } 
     64 
     65        void UpdateCameraTarget(Timer checkit) 
     66        { 
     67            List<Player> activePlayers = advenae.FindAll(o => o.IsVisible == true); 
     68 
     69            switch (activePlayers.Count) 
     70            { 
     71                case 1: 
     72                    Player soloYolo = activePlayers[0]; 
     73                    cameraTarget.X = soloYolo.Position.X + (soloYolo.FacingDirection.GetVector().X * (TileSize * 4)); 
     74                    if (soloYolo.IsCrouching) cameraTarget.Y = soloYolo.Position.Y - TileSize * 4; 
     75                    else if (soloYolo.IsGrounded) cameraTarget.Y = soloYolo.Position.Y; 
     76                    break; 
     77                case 2: 
     78                    cameraTarget = activePlayers[1].Position; 
     79                    break; 
     80                default: 
     81                    Camera.StopFollowing(); 
     82                    checkit.Stop(); 
     83                    break; 
     84            } 
     85        } 
     86 
     87        protected override void Update(Time time) 
     88        { 
     89            Camera.X += (cameraTarget.X - Camera.X) * time.SinceLastUpdate.TotalSeconds * cameraSpeed.X; 
     90            Camera.Y += (cameraTarget.Y - Camera.Y) * time.SinceLastUpdate.TotalSeconds * cameraSpeed.Y; 
     91 
     92            base.Update(time); 
    5193        } 
    5294 
     
    159201        } 
    160202 
    161  
    162         /*  
    163          private void SetMovementKeys(Player adven, Key up, Key down, Key left, Key right, Key morph) 
    164          { 
    165              Keyboard.Listen(right, ButtonState.Down, Walk, null, adven, 200.0); 
    166              Keyboard.Listen(left, ButtonState.Down, Walk, null, adven, -200.0); 
    167              Keyboard.Listen(up, ButtonState.Down, Jump, null, adven); 
    168              Keyboard.Listen(down, ButtonState.Pressed, Crouch, null, adven, true); 
    169              Keyboard.Listen(down, ButtonState.Released, Crouch, null, adven, false); 
    170  
    171              Keyboard.Listen(morph, ButtonState.Pressed, SplitOrMorph, "Splits or morphs the player back to 1 player"); 
    172  
    173          } 
    174          */ 
    175  
    176203        private void SetGeneralKeys() 
    177204        { 
     
    182209            Keyboard.Listen(Key.X, ButtonState.Pressed, SplitOrMorph, "Splits or morphs the player", 2); 
    183210            Keyboard.Listen(Key.RightShift, ButtonState.Pressed, SplitOrMorph, "Splits or morphs the player", 1); 
    184             Keyboard.Listen(Key.LeftShift, ButtonState.Pressed, () => { advenae[0].Reappear(); advenae[0].X = Level.Left - advenae[0].Width; }, ""); 
    185211        } 
    186212 
     
    193219            adven.Tag = "player"; 
    194220            adven.Crushed += adven.Destroy; 
    195             //adven.Destroyed += delegate { advenae.Remove(adven); }; 
    196221            adven.CollisionIgnoreGroup = playerNum; 
    197222            adven.PlayerNumber = playerNum; 
    198             //adven.AddCollisionHandler("player", HandleMorphing); 
    199223            adven.ControlKeys = keys; 
    200224            adven.OnInteractedWith += Pickup; 
     
    214238        private void SplitOrMorph(int playerNro) 
    215239        { 
    216             //if (advenae.FindAll(o => o.IsVisible == true).Count == 1) 
    217240            if (!advenae[playerNro - 1].IsVisible && advenae[1 - playerNro + 1].IsVisible) 
    218241            { 
     
    233256                Player destroyable = advenae.Find(o => o.PlayerNumber != adven.PlayerNumber); 
    234257 
    235                 /*destroyable.ControlKeys.ForEach(delegate (Key key) 
     258                destroyable.ControlKeys.ForEach(delegate (Key key) 
    236259                { 
    237260                    Keyboard.Disable(key); 
    238                 });*/ 
     261                }); 
    239262 
    240263                destroyable.Destroy(); 
Note: See TracChangeset for help on using the changeset viewer.