1 | using System; |
---|
2 | using System.Collections.Generic; |
---|
3 | using System.Linq; |
---|
4 | using System.Text; |
---|
5 | using Jypeli; |
---|
6 | using Jypeli.Assets; |
---|
7 | |
---|
8 | public class Pelaaja : PhysicsObject |
---|
9 | { |
---|
10 | public bool IsOnGround { get; set; } |
---|
11 | public IntMeter Elamat { get; set; } |
---|
12 | |
---|
13 | private AssaultRifle LyontiAse { get; set; } |
---|
14 | private AssaultRifle PotkuAse { get; set; } |
---|
15 | |
---|
16 | private Animation kavelyOikealle = new Animation(Sticman_The_Last_Stand.Peli.kavelyAnimaatio); |
---|
17 | private Animation kavelyVasemmalle = new Animation(Image.Mirror(Sticman_The_Last_Stand.Peli.kavelyAnimaatio)); |
---|
18 | private Image seisomisKuva = Sticman_The_Last_Stand.Peli.pelaajanKuva; |
---|
19 | private Image lyontiKuva = Sticman_The_Last_Stand.Peli.lyontiKuva; |
---|
20 | private Image lyontiKuvaPeilattu = Image.Mirror(Sticman_The_Last_Stand.Peli.lyontiKuva); |
---|
21 | private Image potkuKuva = Sticman_The_Last_Stand.Peli.potkuKuva; |
---|
22 | private Image potkuKuvaPeilattu = Image.Mirror(Sticman_The_Last_Stand.Peli.potkuKuva); |
---|
23 | |
---|
24 | |
---|
25 | private bool onkoLyomassa = false; |
---|
26 | private bool onkoPotkaisemassa = false; |
---|
27 | |
---|
28 | public Pelaaja(double width, double height, int elamat) |
---|
29 | : base(width, height) |
---|
30 | { |
---|
31 | this.IsOnGround = true; |
---|
32 | this.Elamat = new IntMeter(elamat, 0, elamat); |
---|
33 | this.Elamat.LowerLimit += Destroy; |
---|
34 | |
---|
35 | this.LyontiAse = new AssaultRifle(10, 5); |
---|
36 | this.LyontiAse.IsVisible = true; |
---|
37 | this.LyontiAse.InfiniteAmmo = true; |
---|
38 | this.Add(LyontiAse); |
---|
39 | this.PotkuAse = new AssaultRifle(10, 5); |
---|
40 | this.PotkuAse.IsVisible = false; |
---|
41 | this.PotkuAse.InfiniteAmmo = true; |
---|
42 | this.Add(PotkuAse); |
---|
43 | |
---|
44 | kavelyOikealle.FPS = 3; |
---|
45 | kavelyVasemmalle.FPS = 3; |
---|
46 | } |
---|
47 | |
---|
48 | public void Lyo() |
---|
49 | { |
---|
50 | PhysicsObject ammus = this.LyontiAse.Shoot(); |
---|
51 | |
---|
52 | if (ammus == null) return; |
---|
53 | |
---|
54 | ammus.IsVisible = true; |
---|
55 | ammus.MaximumLifetime = TimeSpan.FromSeconds(0.05); |
---|
56 | |
---|
57 | Sticman_The_Last_Stand.Peli.AddCollisionHandler<PhysicsObject, PhysicsObject>(ammus, "taistelu", delegate(PhysicsObject a, PhysicsObject kohde) { HyokkaysOsui(a, kohde, 10); }); |
---|
58 | Sticman_The_Last_Stand.Peli.AddCollisionHandler<PhysicsObject, PhysicsObject>(ammus, "vihollinen", delegate(PhysicsObject a, PhysicsObject kohde) { HyokkaysOsui(a, kohde, 10); }); |
---|
59 | |
---|
60 | onkoLyomassa = true; |
---|
61 | Timer.SingleShot(0.3, delegate { onkoLyomassa = false; }); |
---|
62 | } |
---|
63 | |
---|
64 | private void HyokkaysOsui(PhysicsObject ammus, PhysicsObject kohde, int damage) |
---|
65 | { |
---|
66 | ammus.Destroy(); |
---|
67 | if (kohde.Tag.ToString() == "taistelu") |
---|
68 | { |
---|
69 | Pelaaja p = kohde as Pelaaja; |
---|
70 | p.Elamat.Value -= damage; |
---|
71 | return; |
---|
72 | } |
---|
73 | Vihollinen v = kohde as Vihollinen; |
---|
74 | v.Elamat.Value -= damage; |
---|
75 | } |
---|
76 | |
---|
77 | public void Potkaise() |
---|
78 | { |
---|
79 | PhysicsObject ammus = this.PotkuAse.Shoot(); |
---|
80 | |
---|
81 | if (ammus == null) return; |
---|
82 | |
---|
83 | ammus.IsVisible = true; |
---|
84 | ammus.MaximumLifetime = TimeSpan.FromSeconds(0.05); |
---|
85 | |
---|
86 | Sticman_The_Last_Stand.Peli.AddCollisionHandler<PhysicsObject, PhysicsObject>(ammus, "vihollinen", delegate(PhysicsObject a, PhysicsObject kohde) { HyokkaysOsui(a, kohde, 15); }); |
---|
87 | |
---|
88 | onkoPotkaisemassa = true; |
---|
89 | Timer.SingleShot(0.3, delegate { onkoPotkaisemassa = false; }); |
---|
90 | } |
---|
91 | |
---|
92 | public override void Update(Time time) |
---|
93 | { |
---|
94 | if (onkoLyomassa) |
---|
95 | { |
---|
96 | if (this.Velocity.X > 0) |
---|
97 | this.Image = lyontiKuva; |
---|
98 | if (this.Velocity.X <= 0) |
---|
99 | this.Image = lyontiKuvaPeilattu; |
---|
100 | base.Update(time); |
---|
101 | return; |
---|
102 | } |
---|
103 | |
---|
104 | if (onkoPotkaisemassa) |
---|
105 | { |
---|
106 | if (this.Velocity.X > 0) |
---|
107 | this.Image = potkuKuva; |
---|
108 | if (this.Velocity.X <= 0) |
---|
109 | this.Image = potkuKuvaPeilattu; |
---|
110 | base.Update(time); |
---|
111 | return; |
---|
112 | } |
---|
113 | |
---|
114 | if (this.Velocity.X > 10) |
---|
115 | { |
---|
116 | this.LyontiAse.Angle = Angle.FromDegrees(0); |
---|
117 | this.PotkuAse.Angle = Angle.FromDegrees(0); |
---|
118 | if (this.Animation != kavelyOikealle) |
---|
119 | { |
---|
120 | this.Animation = kavelyOikealle; |
---|
121 | this.Animation.Start(); |
---|
122 | } |
---|
123 | } |
---|
124 | if (this.Velocity.X < -10) |
---|
125 | { |
---|
126 | this.LyontiAse.Angle = Angle.FromDegrees(180); |
---|
127 | this.PotkuAse.Angle = Angle.FromDegrees(180); |
---|
128 | if (this.Animation != kavelyVasemmalle) |
---|
129 | { |
---|
130 | this.Animation = kavelyVasemmalle; |
---|
131 | this.Animation.Start(); |
---|
132 | } |
---|
133 | } |
---|
134 | if (this.Velocity.X > -10 && this.Velocity.X < 10) |
---|
135 | { |
---|
136 | this.Animation = null; |
---|
137 | this.Image = seisomisKuva; |
---|
138 | } |
---|
139 | |
---|
140 | base.Update(time); |
---|
141 | } |
---|
142 | } |
---|