Ignore:
Timestamp:
2012-07-03 10:45:45 (9 years ago)
Author:
dezhidki
Message:

Talletus.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 2012/27/DenisZ/TheDungeonGame/TheDungeonGame/TheDungeonGame/TheDungeonGame.cs

    r3446 r3462  
    77using Jypeli.Widgets; 
    88using MathHelper; 
     9using Entity; 
    910 
    1011public class TheDungeonGame : PhysicsGame 
    1112{ 
    12     private PhysicsObject player; 
    13     private bool isMoving = false; 
    14     private Vector movementVector = Vector.Zero; 
    15     private Vector moveUp = new Vector(0, 200); 
    16     private Vector moveDown = new Vector(0, -200); 
    17     private Vector moveRight = new Vector(200, 0); 
    18     private Vector moveLeft = new Vector(-200, 0); 
     13    private Player player; 
    1914 
    2015    public override void Begin() 
     
    2520        Camera.ZoomToLevel(); 
    2621 
    27         player = new PhysicsObject(75, 75); 
     22        player = new Player(Vector.Zero); 
    2823        Add(player); 
    2924 
    30  
    31  
    32  
    33         Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Lopeta peli"); 
    34         Keyboard.Listen(Key.W, ButtonState.Down, moveObject, "Move Up", player, moveUp); 
    35         Keyboard.Listen(Key.A, ButtonState.Down, moveObject, "Move Right", player, moveRight); 
    36         Keyboard.Listen(Key.S, ButtonState.Down, moveObject, "Move Down", player, moveDown); 
    37         Keyboard.Listen(Key.D, ButtonState.Down, moveObject, "Move Left", player, moveLeft); 
    38  
    39         Keyboard.Listen(Key.W, ButtonState.Released, removeMovement, null, moveUp); 
    40         Keyboard.Listen(Key.A, ButtonState.Released, removeMovement, null, moveRight); 
    41         Keyboard.Listen(Key.S, ButtonState.Released, removeMovement, null, moveDown); 
    42         Keyboard.Listen(Key.D, ButtonState.Released, removeMovement, null, moveLeft); 
     25        Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Lopeta peli");    
    4326    } 
    4427 
    4528    protected override void Update(Time time) 
    4629    { 
    47         if (!isMoving) 
    48         { 
    49             movementVector = Vector.Zero; 
    50             player.Stop(); 
    51         } 
    52         isMoving = false; 
     30        player.Update(time); 
    5331        base.Update(time); 
    5432    } 
    55  
    56     private void moveObject(IPhysicsObject obj, Vector vec) 
    57     { 
    58         if (vec.X > 0 || vec.X < 0) 
    59             movementVector.X = vec.X; 
    60         if (vec.Y > 0 || vec.Y < 0) 
    61             movementVector.Y = vec.Y; 
    62         obj.Move(movementVector); 
    63         isMoving = true; 
    64     } 
    65  
    66     private void removeMovement(Vector vec) 
    67     { 
    68         movementVector = VecMath.sub(movementVector, vec); 
    69     } 
    7033} 
Note: See TracChangeset for help on using the changeset viewer.