luento16esimerkkeja
 All Classes Files Functions Variables Properties
Luokat.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using Jypeli;
6 using Jypeli.Assets;
7 using Jypeli.Controls;
8 using Jypeli.Effects;
9 using Jypeli.Widgets;
10 
11 public class Efektit
12 {
13  public static void Savuta(PhysicsGame peli, IPhysicsObject olio, bool useShock = false, double kerroin = 10)
14  {
15 #if !MonoGame
16  Smoke savu = new Smoke();
17  savu.MaximumLifetime = TimeSpan.FromSeconds(3);
18  savu.Position = olio.Position;
19  peli.Add(savu); olio.Destroy();
20  // savu.FadeOut(5); // ei tuhoa oliota efektin jälkeen
21  Timer timer = new Timer();
22  timer.Interval = 3;
23  timer.Start();
24  timer.Timeout += delegate()
25  {
26  savu.Destroy();
27  timer.Stop();
28  };
29  // savunAani.Play();
30 #endif
31  }
32 }
33 
34 
35 public class Syotava : PhysicsObject
36 {
37  public Syotava(PhysicsGame peli, double w, Vector p, string tunniste, int elinaika)
38  : base(w, w)
39  {
40  this.Position = p;
41  this.Image = Game.LoadImage(tunniste);
42  this.Height = this.Width * this.Image.Height / this.Image.Width;
43  peli.Add(this);
44  this.Tag = tunniste;
45  this.LifetimeLeft = new TimeSpan(10000 * elinaika);
46  }
47 }
48 
49 
50 public class Luu : Syotava
51 {
52  public Luu(PhysicsGame peli, double w, Vector p)
53  : base(peli, w, p, "luu", 1000)
54  {
55  this.Destroyed += delegate() { Efektit.Savuta(peli, this); };
56  }
57 }
58 
59 
60 public class Juusto : Syotava
61 {
62  public Juusto(PhysicsGame peli, double w, Vector p)
63  : base(peli, w, p, "juusto", 5000)
64  {
65  // this.Destroyed += delegate() { Savuta(peli, this); };
66  }
67 }
68 
69 
70 public class Elain : PhysicsObject // PlatformCharacter
71 {
72  private string nimi;
73  public string Nimi { get { return nimi; } }
74 
75  private bool vasen = false;
76 
77  public Elain(PhysicsGame peli, double w, Vector p, string nimi, string tunniste)
78  : base(w, w)
79  {
80  this.Position = p;
81  this.Image = Game.LoadImage(tunniste);
82  this.Tag = tunniste;
83  this.Height = this.Width * this.Image.Height / this.Image.Width;
84  this.nimi = nimi;
85  Label label = new Label(nimi);
86  this.Add(label);
87  peli.Add(this);
88  CanRotate = false;
89  }
90 
91  public virtual void Liiku(Vector suunta)
92  {
93  //this.Hit(new Vector(0,suunta.Y));
94  //Walk(suunta.X);
95  this.Hit(suunta);
96  bool nytVasen = suunta.X < 0;
97  if (nytVasen ^ vasen) this.MirrorImage();
98  vasen = nytVasen;
99  }
100 
101 
102  public virtual void Aantele()
103  {
104 
105  }
106 
107 
108  public virtual void Syo(PhysicsObject kuka, PhysicsObject kenet)
109  {
110  kenet.Destroy();
111  this.Size += new Vector(10, 10);
112  this.Aantele();
113  }
114 }
115 
116 
117 public class Koira : Elain
118 {
119  public Koira(PhysicsGame peli, double w, Vector p, string nimi = "")
120  : base(peli, w, p, nimi, "koira")
121  {
122  peli.AddCollisionHandler(this, "luu", Syo);
123  }
124 
125 
126  public override void Aantele()
127  {
128  Game.PlaySound("KoiranAani1");
129  }
130 }
131 
132 
133 public class Kissa : Elain
134 {
135  public Kissa(PhysicsGame peli, double w, Vector p, string nimi = "")
136  : base(peli, w, p, nimi, "kissa")
137  {
138  peli.AddCollisionHandler(this, "hiiri", Syo);
139  }
140 
141  public override void Aantele()
142  {
143  Game.PlaySound("KissanAani01");
144  }
145 
146 }
147 
148 
149 public class Hiiri : Elain
150 {
151  public Hiiri(PhysicsGame peli, double w, Vector p, Juusto juusto)
152  : base(peli, w, p, "", "hiiri")
153  {
154  this.LifetimeLeft = new TimeSpan(0, 0, 0, 5);
155  peli.AddCollisionHandler(this, "juusto", Syo);
156  this.Destroyed += delegate() { new Luu(peli, Width * 0.8, Position); };
157  FollowerBrain brain = new FollowerBrain(juusto);
158  this.Brain = brain;
159  }
160 
161  public override void Syo(PhysicsObject kuka, PhysicsObject kenet)
162  {
163  base.Syo(kuka, kenet);
164  this.LifetimeLeft = new TimeSpan(0, 0, 0, 15);
165  }
166 
167  public override void Aantele()
168  {
169  Game.PlaySound("Naps");
170  }
171 }