Changeset 2366 for 2011/26


Ignore:
Timestamp:
2011-06-30 14:39:51 (8 years ago)
Author:
teeevasa
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 2011/26/JaakkoL/Rogue Agent 2372/Rogue Agent 2372/Rogue Agent 2372/Player.cs

    r2363 r2366  
    1414    SoundEffect walking = Game.LoadSoundEffect("Sounds/walkingsound"); 
    1515 
     16    string currentWeapon; 
    1617    Pistol pistol; 
    1718    Rifle rifle; 
     
    3738        pistol.X = 18; 
    3839        pistol.Y = 11; 
    39         //this.Weapon = pistol; // The default weapon 
     40        this.Weapon = pistol; 
    4041        pistol.ProjectileCollision += bulletReachedTarget; 
    4142 
     
    4344        rifle.X = 18; 
    4445        rifle.Y = 11; 
    45         this.Weapon = rifle; 
    4646        rifle.ProjectileCollision += bulletReachedTarget; 
    47          
    4847        // Collision handlers for enemies 
    4948        //AddCollisionHandler(); 
     
    5554        Game.Keyboard.Listen(Key.Left, ButtonState.Down, moveLeft, "Moves left", speed); 
    5655        Game.Keyboard.Listen(Key.Up, ButtonState.Down, jump, "Jumps", jumpSpeed); 
    57         Game.Keyboard.Listen(Key.Space, ButtonState.Pressed, shoot, "Shoots"); 
     56        Game.Keyboard.Listen(Key.Space, ButtonState.Down, shoot, "Shoots"); 
     57        Game.Keyboard.Listen(Key.D1, ButtonState.Pressed, changeWeapon, "Changes weapon to the pistol", pistol.name()); 
     58        Game.Keyboard.Listen(Key.D2, ButtonState.Pressed, changeWeapon, "Changes weapon to the rifle", rifle.name()); 
     59    } 
     60 
     61    private void changeWeapon(string weaponName) 
     62    { 
     63        if (weaponName == "Pistol") 
     64        { 
     65            this.Weapon = pistol; 
     66        } 
     67        else if (weaponName == "Rifle") 
     68        { 
     69            this.Weapon = rifle; 
     70        } 
     71        else 
     72        { 
     73            throw new Exception("Invalid weapon name: '" + weaponName + "'"); 
     74        } 
     75 
     76        // We only get here if the weaponName is valid 
     77        currentWeapon = weaponName; 
    5878    } 
    5979 
Note: See TracChangeset for help on using the changeset viewer.