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

Revision 4381, 1.8 KB checked in by teematma, 10 years ago (diff)

asdf

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    private static Image image = Game.LoadImage("Player");
14
15    public Player(double width, double height, bool addDefaultControls) : base(width, height)
16    {
17        this.Tag = "player";
18        this.Shape = Shape.Rectangle;
19        this.Image = image;
20        this.LinearDamping = 0.9;
21       
22        if (addDefaultControls)
23            SetDefaultControls();
24
25        this.IsUpdated = true;
26
27       
28    }
29
30    public bool GiveItem(String itemName)
31    {
32        if (itemName == "cannon")
33        {
34            Cannon weapon = new Cannon(75, 25);
35            this.Add(weapon);
36            return true;
37        }
38        return false;
39    }
40
41    public void SetDefaultControls()
42    {
43        Game.Keyboard.Listen(Key.W, ButtonState.Down, delegate { this.Push(new Vector(0, speed)); }, null);
44        Game.Keyboard.Listen(Key.S, ButtonState.Down, delegate { this.Push(new Vector(0, -speed)); }, null);
45        Game.Keyboard.Listen(Key.A, ButtonState.Down, delegate { this.Push(new Vector(-speed, 0)); }, null);
46        Game.Keyboard.Listen(Key.D, ButtonState.Down, delegate { this.Push(new Vector(speed, 0)); }, null);
47        Game.Mouse.Listen(MouseButton.Left, ButtonState.Pressed, Shoot, null);
48    }
49
50    public void Shoot()
51    {
52        Game.MessageDisplay.Add("PEW PEW!");
53    }
54
55    public override void Update(Time time)
56    {
57        this.Angle = (Game.Mouse.PositionOnWorld - this.AbsolutePosition).Normalize().Angle - Angle.FromDegrees(90);
58        base.Update(time);
59    }
60}
Note: See TracBrowser for help on using the repository browser.