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 | GameObject thrusterEffect; |
---|
12 | Proto236b parent; |
---|
13 | private List<Weapon> weapons = new List<Weapon>(); |
---|
14 | |
---|
15 | public void rotate(double rotSpeed) |
---|
16 | { |
---|
17 | this.AngularVelocity = rotSpeed; |
---|
18 | } |
---|
19 | public void thrusterStart(double speed) |
---|
20 | { |
---|
21 | this.thrusterEffect.IsVisible = true; |
---|
22 | this.Push(Vector.FromLengthAndAngle(speed * 800, this.Angle + Angle.RightAngle)); |
---|
23 | } |
---|
24 | public void thrusterEnd() |
---|
25 | { |
---|
26 | this.thrusterEffect.IsVisible = false; |
---|
27 | //if this.ids, enable ids |
---|
28 | } |
---|
29 | public Player(Proto236b parent) |
---|
30 | : base(40, 40) |
---|
31 | { |
---|
32 | this.parent = parent; |
---|
33 | this.Image = parent.Images["player"]; |
---|
34 | this.Shape = Shape.FromImage(parent.Images["player"]); |
---|
35 | bool IDS = false; //inertial dampening system, katsotaan pistetäänkö ostettavaksi peliin |
---|
36 | if (IDS == true) |
---|
37 | { |
---|
38 | this.LinearDamping = 0.97; |
---|
39 | } |
---|
40 | else |
---|
41 | { |
---|
42 | this.LinearDamping = 1; |
---|
43 | } |
---|
44 | this.AngularDamping = 0.7; |
---|
45 | this.Restitution = 0.2; |
---|
46 | this.MaxVelocity = 1400; //2*800 on 1400 |
---|
47 | //ei niin |
---|
48 | |
---|
49 | this.thrusterEffect = new GameObject(40, 40); |
---|
50 | thrusterEffect.Animation = new Animation(parent.ImageLists["player_thruster"]); |
---|
51 | thrusterEffect.Animation.FPS = 18; |
---|
52 | thrusterEffect.Animation.Start(); |
---|
53 | thrusterEffect.IsVisible = false; |
---|
54 | thrusterEffect.Y -= 19; |
---|
55 | Add(thrusterEffect); |
---|
56 | } |
---|
57 | public void shoot() |
---|
58 | { |
---|
59 | foreach (Weapon weapon in weapons) |
---|
60 | { |
---|
61 | PhysicsObject bullet = weapon.Shoot(); |
---|
62 | if (bullet != null) |
---|
63 | { |
---|
64 | bullet.Velocity += this.Velocity; |
---|
65 | |
---|
66 | } |
---|
67 | } |
---|
68 | } |
---|
69 | public void attachWeapon() |
---|
70 | { |
---|
71 | Weapon weapon = new AssaultRifle(1, 1); |
---|
72 | weapon.Angle += Angle.RightAngle; |
---|
73 | weapon.IsVisible = false; |
---|
74 | weapon.InfiniteAmmo = true; |
---|
75 | Add(weapon); |
---|
76 | weapons.Add(weapon); |
---|
77 | } |
---|
78 | public override void Update(Time time) |
---|
79 | { |
---|
80 | base.Update(time); |
---|
81 | //this.parent.MessageDisplay.Clear(); |
---|
82 | //this.parent.MessageDisplay.Add(this.AbsolutePosition.ToString()); |
---|
83 | if (parent.CurrentLevel.IsPlanet) |
---|
84 | { |
---|
85 | //PLANEETAN PINNALLA |
---|
86 | if (this.X > parent.Level.Right) |
---|
87 | { |
---|
88 | this.X = parent.Level.Left; |
---|
89 | this.parent.Camera.X = parent.Level.Left; // kamera päivitetään ettei pelaaja välky |
---|
90 | } |
---|
91 | else if (this.X < parent.Level.Left) |
---|
92 | { |
---|
93 | this.X = parent.Level.Right; |
---|
94 | this.parent.Camera.X = parent.Level.Right; // ditto |
---|
95 | } |
---|
96 | if (this.Y > parent.Level.Top - parent.GameScreen.Height / 2) |
---|
97 | { |
---|
98 | //player pystyy lähteä pois planeetalta kun menee tarpeeksi ylös |
---|
99 | Angle shipAngle = Angle.FromRadians((Math.PI * 2) * ((parent.Player.X + parent.Level.Width / 2) / parent.Level.Width)); |
---|
100 | parent.LoadLevel("space", shipAngle); |
---|
101 | } |
---|
102 | } |
---|
103 | else |
---|
104 | { |
---|
105 | //AVARUUDESSA |
---|
106 | foreach (KeyValuePair<string, Planet> kvpair in parent.Galaxy.planets) |
---|
107 | { |
---|
108 | if (Vector.Distance(this.Position, kvpair.Value.Position) < kvpair.Value.Radius) |
---|
109 | { |
---|
110 | //mennään planeettaan |
---|
111 | //approach angle? |
---|
112 | double deltaX = kvpair.Value.X - this.X; |
---|
113 | double deltaY = this.Y - kvpair.Value.Y; |
---|
114 | Angle approachAngle; |
---|
115 | if (deltaX != 0) |
---|
116 | { |
---|
117 | approachAngle = Angle.ArcTan(deltaY / deltaX); |
---|
118 | } |
---|
119 | else |
---|
120 | { |
---|
121 | approachAngle = Angle.RightAngle; |
---|
122 | } |
---|
123 | |
---|
124 | if (this.X < kvpair.Value.X) |
---|
125 | { |
---|
126 | approachAngle += Angle.StraightAngle; |
---|
127 | } |
---|
128 | else if (this.Y > kvpair.Value.Y) |
---|
129 | { |
---|
130 | approachAngle += Angle.FullAngle; |
---|
131 | } |
---|
132 | parent.LoadLevel(kvpair.Key, approachAngle); |
---|
133 | this.parent.MessageDisplay.Add(approachAngle.GetPositiveDegrees().ToString()); |
---|
134 | } |
---|
135 | } |
---|
136 | } |
---|
137 | } |
---|
138 | } |
---|