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