Changeset 7400 for 2016


Ignore:
Timestamp:
2016-06-16 23:31:50 (7 years ago)
Author:
sieerinn
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 2016/24/SimoR/Tasohyppelypeli/Tasohyppelypeli/Tasohyppelypeli/Tasohyppelypeli.cs

    r7399 r7400  
    139139    float matrixLerp = 0f; 
    140140    float cameraRotation = 0f; 
     141    float norsuRotation = 0f; 
     142 
     143    bool rotateStar = false; 
     144    float starRotation = 0f; 
    141145 
    142146    bool perspective = false; 
    143147    bool light = false; 
    144  
    145  
    146     protected override void Initialize() 
    147     { 
    148         base.Initialize(); 
    149  
    150         var parameters = new PresentationParameters() 
    151         { 
    152             MultiSampleCount = 4 
    153         }; 
    154  
    155         //graphics = new GraphicsDevice(GraphicsAdapter.DefaultAdapter, GraphicsProfile.Reach, parameters); 
    156     } 
    157148 
    158149    protected override void LoadContent() 
     
    184175        tahtiTexture = Content.Load<Texture2D>("tahti"); 
    185176 
     177        Keyboard.Listen(Key.W, ButtonState.Pressed, () => 
     178        { 
     179            rotateStar = !rotateStar; 
     180            if (!rotateStar) 
     181                starRotation = 0f; 
     182        }, null); 
     183 
     184        Keyboard.Listen(Key.F2, ButtonState.Down, () => { norsuRotation += 0.3f; }, null); 
     185 
    186186        // A ja D pyörittää maailmaa. 
    187187        Keyboard.Listen(Key.A, ButtonState.Down, () => { cameraRotation += 0.005f; }, null); 
     
    197197    protected override void Draw(Microsoft.Xna.Framework.GameTime gameTime) 
    198198    { 
     199        float dt = (float)gameTime.ElapsedGameTime.TotalSeconds; 
     200 
    199201        base.Draw(gameTime); // Piirretään Jypeli jutut ensin. 
     202 
     203        // Tähtien pyörittely. 
     204        if (rotateStar) 
     205            starRotation += -1.3f * dt; 
    200206 
    201207        // Sulava muunnos projektiomatriisien välille. 
    202208        float dir = perspective ? 1f : -1f; 
    203         matrixLerp += dir * 0.3f * (float)gameTime.ElapsedGameTime.TotalSeconds; 
     209        matrixLerp += dir * 0.3f * dt; 
    204210        matrixLerp = MathHelper.Clamp(matrixLerp, 0f, 1f); 
    205211 
     
    208214 
    209215        // Piirretään 3D-mallit päälle. 
    210         DrawModel(norsuModel, norsuTexture, pelaaja1.Position); 
     216        DrawModel(norsuModel, norsuTexture, pelaaja1.Position, norsuRotation); 
    211217        foreach (var taso in tasot) 
    212218        { 
    213             DrawModel(tasoModel, vihreaTexture, taso.Position); 
     219            DrawModel(tasoModel, vihreaTexture, taso.Position, 0f); 
    214220        } 
    215221        foreach (var tahti in tahdet) 
    216222        { 
    217             DrawModel(tahtiModel, tahtiTexture, tahti.Position); 
    218         } 
    219     } 
    220  
    221     void DrawModel(Model model, Texture2D tex, Vector jypeliPos) 
     223            DrawModel(tahtiModel, tahtiTexture, tahti.Position, starRotation); 
     224        } 
     225    } 
     226 
     227    void DrawModel(Model model, Texture2D tex, Vector jypeliPos, float rotation) 
    222228    { 
    223229        var transforms = new Matrix[model.Bones.Count]; 
     
    246252                    effect.EnableDefaultLighting(); 
    247253                    effect.DiffuseColor = new Vector3(1f, 1f, 1f); 
    248                     //effect.DirectionalLight0. 
    249254                } 
    250255 
    251                 effect.World = transforms[mesh.ParentBone.Index] * Matrix.CreateRotationY(0f) * Matrix.CreateTranslation(modelPosition); 
     256                effect.World = transforms[mesh.ParentBone.Index] * Matrix.CreateRotationY(rotation) * Matrix.CreateTranslation(modelPosition); 
    252257                effect.View = Matrix.CreateLookAt(cameraPos, Vector3.Zero, Vector3.Up); 
    253258                effect.Projection = finalMat; 
Note: See TracChangeset for help on using the changeset viewer.