1 | using System; |
---|
2 | using System.Collections.Generic; |
---|
3 | using Jypeli; |
---|
4 | using Jypeli.Assets; |
---|
5 | using Jypeli.Controls; |
---|
6 | using Jypeli.Effects; |
---|
7 | using Jypeli.Widgets; |
---|
8 | |
---|
9 | public class Player : PhysicsObject |
---|
10 | { |
---|
11 | const double defaultMoveSpeed = 1000; |
---|
12 | double speed = defaultMoveSpeed; |
---|
13 | |
---|
14 | public Player(Game game, double width, double height) : base(width, height) |
---|
15 | { |
---|
16 | this.Shape = Shape.Circle; |
---|
17 | this.Image = G.game.playerImage; |
---|
18 | this.LinearDamping = 0.9; |
---|
19 | |
---|
20 | SetControls(); |
---|
21 | IsUpdated = true; |
---|
22 | } |
---|
23 | |
---|
24 | public void SetControls() |
---|
25 | { |
---|
26 | G.game.Keyboard.Listen(Key.W, ButtonState.Down, delegate { this.Push(new Vector(0, speed)); }, null); |
---|
27 | G.game.Keyboard.Listen(Key.S, ButtonState.Down, delegate { this.Push(new Vector(0, -speed)); }, null); |
---|
28 | G.game.Keyboard.Listen(Key.A, ButtonState.Down, delegate { this.Push(new Vector(-speed, 0)); }, null); |
---|
29 | G.game.Keyboard.Listen(Key.D, ButtonState.Down, delegate { this.Push(new Vector(speed, 0)); }, null); |
---|
30 | G.game.Mouse.Listen(MouseButton.Left, ButtonState.Pressed, Shoot, null); |
---|
31 | } |
---|
32 | |
---|
33 | public void Shoot() |
---|
34 | { |
---|
35 | |
---|
36 | } |
---|
37 | |
---|
38 | public override void Update(Time time) |
---|
39 | { |
---|
40 | this.Angle = (G.game.Mouse.PositionOnWorld - this.AbsolutePosition).Normalize().Angle - Angle.FromDegrees(90); |
---|
41 | base.Update(time); |
---|
42 | } |
---|
43 | } |
---|