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