source: 2013/27/TeemuM/Game/Game/Game/Player.cs @ 4353

Revision 4353, 1.4 KB checked in by jumakall, 9 years ago (diff)
Line 
1using System;
2using System.Collections.Generic;
3using Jypeli;
4using Jypeli.Assets;
5using Jypeli.Controls;
6using Jypeli.Effects;
7using Jypeli.Widgets;
8
9public 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}
Note: See TracBrowser for help on using the repository browser.