1 | using System; |
---|
2 | using Jypeli; |
---|
3 | using Jypeli.Assets; |
---|
4 | using Jypeli.Controls; |
---|
5 | using Jypeli.Effects; |
---|
6 | using Jypeli.Widgets; |
---|
7 | |
---|
8 | public 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 = 5; |
---|
31 | pistol.Y = 10; |
---|
32 | this.Weapon = pistol; |
---|
33 | |
---|
34 | // pistol.ProjectileCollision += bulletReachedTarget; |
---|
35 | } |
---|
36 | |
---|
37 | private void addControls() |
---|
38 | { |
---|
39 | Game.Keyboard.Listen(Key.Right, ButtonState.Down, moveRight, "Moves right", speed); |
---|
40 | Game.Keyboard.Listen(Key.Left, ButtonState.Down, moveLeft, "Moves left", speed); |
---|
41 | Game.Keyboard.Listen(Key.Up, ButtonState.Down, jump, "Jumps", jumpSpeed); |
---|
42 | Game.Keyboard.Listen(Key.Space, ButtonState.Pressed, shoot, "Shoots"); |
---|
43 | } |
---|
44 | |
---|
45 | private void shoot() |
---|
46 | { |
---|
47 | PhysicsObject bullet = this.Weapon.Shoot(); |
---|
48 | //bullet.Hit(new Vector(1000, 0)); |
---|
49 | |
---|
50 | // As of now weapons are set to have infinite ammo, but that might change |
---|
51 | if (bullet != null) |
---|
52 | { |
---|
53 | |
---|
54 | } |
---|
55 | } |
---|
56 | |
---|
57 | void bulletReachedTarget(Projectile bullet, PhysicsObject target) |
---|
58 | { |
---|
59 | |
---|
60 | } |
---|
61 | |
---|
62 | private void playWalkingSound(Timer sender) |
---|
63 | { |
---|
64 | this.walking.Play(); |
---|
65 | } |
---|
66 | |
---|
67 | private void moveRight(int speed) |
---|
68 | { |
---|
69 | walker.Start(); |
---|
70 | this.Walk(speed); |
---|
71 | //this.Image = Image.Mirror(portrait); // Doesn't work at all! |
---|
72 | } |
---|
73 | |
---|
74 | private void moveLeft(int speed) |
---|
75 | { |
---|
76 | walker.Start(); |
---|
77 | this.Walk(-speed); |
---|
78 | this.Image = Image.Mirror(portrait); |
---|
79 | } |
---|
80 | |
---|
81 | public void jump(int jumpSpeed) |
---|
82 | { |
---|
83 | this.Jump(jumpSpeed); |
---|
84 | } |
---|
85 | |
---|
86 | } |
---|