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

Revision 2337, 1.8 KB checked in by jaollipa, 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 = 500;
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        public Player(double width, double height, Shape shape)
19        : base(width, height, shape)
20        {
21        hitPoints = 100;
22        AddedToGame += addControls;
23        this.Image = portrait;
24
25        walker = new Timer();
26        walker.Interval = 0.7;
27        walker.Trigger += playWalkingSound;
28
29        Pistol pistol = new Pistol(20.0, 10.0);
30        pistol.X = -0.05;
31        pistol.Y = 5;
32        this.Weapon = pistol;
33        }
34
35    private void addControls()
36    {
37        Game.Keyboard.Listen(Key.Right, ButtonState.Down, moveRight, "Moves right", speed);
38        Game.Keyboard.Listen(Key.Left, ButtonState.Down, moveLeft, "Moves left", speed);
39        Game.Keyboard.Listen(Key.Up, ButtonState.Down, jump, "Jumps", jumpSpeed);
40        Game.Keyboard.Listen(Key.Space, ButtonState.Pressed, shoot, "Shoots");
41    }
42
43    private void shoot()
44    {
45        PhysicsObject bullet = this.Weapon.Shoot();
46        bullet.Hit(new Vector(1000, 0));
47    }
48
49    private void playWalkingSound(Timer sender)
50    {
51        this.walking.Play();
52    }
53
54    private void moveRight(int speed)
55    {
56        walker.Start();
57        this.Walk(speed);
58        //this.Image = Image.Mirror(portrait); // Doesn't work at all!
59    }
60
61    private void moveLeft(int speed)
62    {
63        walker.Start();
64        this.Walk(-speed);
65        this.Image = Image.Mirror(portrait);
66    }
67
68    public void jump(int jumpSpeed)
69    {
70        this.Jump(jumpSpeed);
71    }
72
73}
Note: See TracBrowser for help on using the repository browser.