source: 2011/26/JaakkoL/Rogue Agent 2372/Rogue Agent 2372/Rogue Agent 2372/Player.cs @ 2286

Revision 2286, 1.5 KB checked in by teeevasa, 8 years ago (diff)
RevLine 
[2203]1using System;
2using Jypeli;
3using Jypeli.Assets;
4using Jypeli.Controls;
5using Jypeli.Effects;
6using Jypeli.Widgets;
7
[2205]8public class Player : GenCharacter
[2203]9{
[2286]10    const int speed = 200;
[2219]11    const int jumpSpeed = 1000;
[2286]12    const int mass = 10;
[2261]13    Image portrait = Game.LoadImage("Images/character");
[2286]14    SoundEffect walking = Game.LoadSoundEffect("Sounds/walkingsound");
[2245]15
[2286]16    Timer walker;
17   
18
[2203]19        public Player(double width, double height, Shape shape)
20        : base(width, height, shape)
21        {
[2206]22        hitPoints = 100;
[2234]23        AddedToGame += addControls;
[2261]24        this.Image = portrait;
[2286]25
26        walker = new Timer();
27        walker.Interval = 1.0;
28        walker.Trigger += playWalkingSound;
29
[2206]30        }
[2205]31
[2286]32    private void addControls()
[2206]33    {
[2217]34        Game.Keyboard.Listen(Key.Right, ButtonState.Down, moveRight, "Moves right", speed);
[2219]35        Game.Keyboard.Listen(Key.Left, ButtonState.Down, moveLeft, "Moves left", speed);
36        Game.Keyboard.Listen(Key.Up, ButtonState.Down, jump, "Jumps", jumpSpeed);
[2206]37    }
[2209]38
[2286]39    private void playWalkingSound(Timer sender)
[2209]40    {
[2286]41        this.walking.Play();
42    }
43
44    private void moveRight(int speed)
45    {
46        walker.Start();
[2234]47        this.Walk(speed);
[2286]48        //this.Image = Image.Mirror(portrait); // Doesn't work at all!
[2209]49    }
[2218]50
[2286]51    private void moveLeft(int speed)
[2218]52    {
[2286]53        walker.Start();
[2218]54        this.Walk(-speed);
[2261]55        this.Image = Image.Mirror(portrait);
[2218]56    }
57
[2219]58    public void jump(int jumpSpeed)
59    {
60        this.Jump(jumpSpeed);
61    }
62
[2203]63}
Note: See TracBrowser for help on using the repository browser.