Ignore:
Timestamp:
2016-07-03 08:26:16 (3 years ago)
Author:
sieerinn
Message:

Kyykkyyn meno

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 2016/27/SimoR/SimplePhysicsTest/SimplePhysicsTest/SimplePhysicsTest/SimplePhysicsTest.cs

    r7646 r7647  
    3131} 
    3232 
     33class Player : SimplePlatformCharacter 
     34{ 
     35    public bool IsCrouching { get; private set; } 
     36 
     37    public bool Crouch { get; set; } 
     38 
     39    private readonly double fullHeight; 
     40    private readonly double crouchHeight; 
     41 
     42    public Player(double width, double height) : base(width, height) 
     43    { 
     44        fullHeight = height; 
     45        crouchHeight = height / 2.0 - 1.0; 
     46    } 
     47 
     48    public override void Update(Time time) 
     49    { 
     50        if (!IsCrouching && Crouch) 
     51        { 
     52            var oldBottom = Bottom; 
     53            Height = crouchHeight; 
     54            Bottom = oldBottom; 
     55            IsCrouching = true; 
     56        } 
     57 
     58        if (IsCrouching && !Crouch) 
     59        { 
     60            var oldBottom = Bottom; 
     61            Height = fullHeight; 
     62            Bottom = oldBottom; 
     63            IsCrouching = false; 
     64 
     65            if (Game.Collisions(this, Vector.Zero, true).Count > 0) 
     66            { 
     67                Height = crouchHeight; 
     68                Bottom = oldBottom; 
     69                IsCrouching = true; 
     70            } 
     71        } 
     72 
     73        base.Update(time); 
     74    } 
     75} 
     76 
    3377class Enemy : SimplePlatformCharacter 
    3478{ 
     
    66110        } 
    67111 
    68         Walk(walkRight? Speed : -Speed); 
     112        Walk(walkRight ? Speed : -Speed); 
    69113        base.Update(time); 
    70114    } 
     
    98142public class SimplePhysicsTest : SimplePhysics.Game 
    99143{ 
    100     private SimplePlatformCharacter player1; 
     144    private Player player1; 
    101145 
    102146    public SimplePhysicsTest() : base(tileSize: 30) 
     
    128172        Keyboard.Listen(Key.Left, ButtonState.Down, Walk, null, player1, -200.0); 
    129173        Keyboard.Listen(Key.Up, ButtonState.Down, Jump, null, player1); 
     174        Keyboard.Listen(Key.Down, ButtonState.Pressed, Crouch, null, player1, true); 
     175        Keyboard.Listen(Key.Down, ButtonState.Released, Crouch, null, player1, false); 
    130176        Keyboard.Listen(Key.Space, ButtonState.Pressed, Shoot, null, player1); 
    131177        Keyboard.Listen(Key.B, ButtonState.Down, MegaShoot, null, player1); 
     
    190236    private void CreatePlayer(int x, int y) 
    191237    { 
    192         player1 = new SimplePlatformCharacter(TileSize * 0.98, TileSize * 1.98); 
     238        player1 = new Player(TileSize * 0.98, TileSize * 1.98); 
    193239        player1.Position = TileToWorldPosition(x, y); 
     240        player1.Friction = 0.2; 
    194241        player1.Tag = "player"; 
    195242        player1.Crushed += player1.Destroy; 
     
    203250    { 
    204251        var pos = TileToWorldPosition(x, y); 
    205         var platform = new MovingPlatform(pos, 3*TileSize, TileSize); 
     252        var platform = new MovingPlatform(pos, 3 * TileSize, TileSize); 
    206253        Add(platform); 
    207254    } 
     
    219266    #endregion 
    220267 
    221     private void Walk(SimplePlatformCharacter player, double speed) 
    222     { 
    223         //player1.Velocity = new Vector(speed, player1.Velocity.Y); 
     268    private void Walk(Player player, double speed) 
     269    { 
    224270        player.Walk(speed); 
    225271    } 
    226272 
    227     private void Jump(SimplePlatformCharacter obj) 
    228     { 
    229         if (obj.IsGrounded) 
    230             player1.Velocity = new Vector(player1.Velocity.X, 500); 
    231     } 
    232      
     273    private void Jump(SimplePlatformCharacter player) 
     274    { 
     275        if (player.IsGrounded) 
     276            player.Velocity = new Vector(player.Velocity.X, 500); 
     277    } 
     278 
    233279    private SimplePhysics.Object CreateProjectile(SimplePlatformCharacter player) 
    234280    { 
     
    260306    } 
    261307 
     308    private void Crouch(Player player, bool crouch) 
     309    { 
     310        player.Crouch = crouch; 
     311    } 
     312 
    262313    private void Shoot(SimplePlatformCharacter player) 
    263314    { 
Note: See TracChangeset for help on using the changeset viewer.