Ignore:
Timestamp:
2016-07-02 21:59:20 (4 years ago)
Author:
sieerinn
Message:

Liikkuvat tasanteet toimii

File:
1 edited

Legend:

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

    r7638 r7639  
    1818    { 
    1919        base.Update(time); 
    20         IsGrounded = Game.CanCollide(this, new Vector(0, -2)); 
     20        IsGrounded = Game.Collisions(this, new Vector(0, -2), true).Count > 0; 
    2121    } 
    2222} 
     
    3030    public MovingPlatform(Vector position, double width, double height) : base(width, height) 
    3131    { 
    32         direction = new Vector(0, 100); 
     32        direction = new Vector(100, 0); 
    3333        Position = startPosition = position; 
    34         IsStatic = true; 
     34        IgnoresGravity = true; 
    3535    } 
    3636 
    3737    public override void Update(Time time) 
    3838    { 
    39         if (Vector.Distance(startPosition, Position) > 200) 
     39        if (Vector.Distance(startPosition, Position) > 100) 
    4040        { 
    4141            direction = -direction; 
    4242        } 
    4343        Velocity = direction; 
    44         Position += Velocity * time.SinceLastUpdate.TotalSeconds; 
    45         base.Update(time); 
     44        Game.UpdateMovingPlatform(this, time); 
     45        //base.Update(time); 
    4646    } 
    4747} 
     
    6565        tilemap.SetTileMethod(Color.Black, CreateTile); 
    6666        tilemap.SetTileMethod(Color.FromHexCode("C6723D"), CreateOneWayTile); 
    67         tilemap.SetTileMethod(Color.FromHexCode("00FFFF"), CreateMovingPlatform); 
     67        tilemap.SetTileMethod(Color.FromHexCode("00FFFF"), CreateIceTile); 
     68        tilemap.SetTileMethod(Color.FromHexCode("FFFF00"), CreateMovingPlatform); 
     69        tilemap.SetTileMethod(Color.FromHexCode("B70909"), CreateDangerousBlock); 
    6870        tilemap.SetTileMethod(Color.Blue, CreatePlayer); 
    6971        tilemap.SetTileMethod(Color.Red, CreateEnemy); 
     
    8486    private void CreateTile(int x, int y) 
    8587    { 
    86         var tile = new SimplePhysics.Object(TileSize, TileSize); 
     88        var tile = new SimplePhysics.Object(TileSize, TileSize) { IsStatic = true }; 
    8789        tile.Color = Color.Green; 
    88         tile.IsStatic = true; 
     90        Add(tile); 
     91        SetTile(x, y, tile); 
     92    } 
     93 
     94    private void CreateIceTile(int x, int y) 
     95    { 
     96        var tile = new SimplePhysics.Object(TileSize, TileSize) { IsStatic = true }; 
     97        tile.Color = Color.Cyan; 
     98        tile.Friction = 0.0; 
     99        Add(tile); 
     100        SetTile(x, y, tile); 
     101    } 
     102 
     103    private void CreateDangerousBlock(int x, int y) 
     104    { 
     105        var tile = new SimplePhysics.Object(TileSize, TileSize) { IsStatic = true }; 
     106        tile.Color = Color.Red; 
     107        tile.Tag = "death"; 
    89108        Add(tile); 
    90109        SetTile(x, y, tile); 
     
    93112    private void CreateOneWayTile(int x, int y) 
    94113    { 
    95         var tile = new SimplePhysics.Object(TileSize, TileSize); 
     114        var tile = new SimplePhysics.Object(TileSize, TileSize) { IsStatic = true }; 
    96115        tile.Color = Color.Brown; 
    97         tile.IsStatic = true; 
    98116        tile.OneWayPlatform = true; 
    99117        Add(tile, -1); 
     
    105123        player = new SimplePlatformCharacter(TileSize * 0.98, TileSize * 1.98); 
    106124        player.Position = TileToWorldPosition(x, y); 
     125        player.Tag = "player"; 
     126        player.Crushed += player.Destroy; 
     127        Add(player); 
     128 
    107129        player.AddCollisionHandler("enemy", HitsEnemy); 
    108         Add(player); 
     130        player.AddCollisionHandler("death", (a, b) => player.Destroy()); 
    109131    } 
    110132 
     
    112134    { 
    113135        var pos = TileToWorldPosition(x, y); 
    114         var platform = new MovingPlatform(pos, TileSize, TileSize); 
     136        var platform = new MovingPlatform(pos, 3*TileSize, TileSize); 
    115137        Add(platform); 
    116138    } 
     
    120142        var enemy = new SimplePhysics.Object(TileSize * 0.99, TileSize * 0.99); 
    121143        enemy.Position = TileToWorldPosition(x, y); 
    122         enemy.Tag = "asdasd"; 
     144        enemy.Tag = "enemy"; 
    123145        Add(enemy); 
    124146    } 
Note: See TracChangeset for help on using the changeset viewer.