Jypeli 10
The simple game programming library
Particle.cs
Siirry tämän tiedoston dokumentaatioon.
1using System;
2
3namespace Jypeli.Effects
4{
8 public class Particle
9 {
10 #region Variables, getters and setters
11
13 private double scale;
14 private double rotation;
15 private double rotationSpeed;
18 private TimeSpan maxLifetime;
19 private TimeSpan creationTime;
20
25 {
26 get { return position; }
27 set { position = value; }
28 }
29
33 public double Scale
34 {
35 get { return scale; }
36 set { scale = value; }
37 }
38
42 public double Rotation
43 {
44 get { return rotation; }
45 set { rotation = value; }
46 }
47
51 public double RotationSpeed
52 {
53 get { return rotationSpeed; }
54 set { rotationSpeed = value; }
55 }
56
61 {
62 get { return velocity; }
63 set { velocity = value; }
64 }
65
70 {
71 get { return acceleration; }
72 set { acceleration = value; }
73 }
74
78 public bool Alive
79 {
80 get { return Lifetime < MaxLifetime; }
81 }
82
86 public TimeSpan MaxLifetime
87 {
88 get { return maxLifetime; }
89 set { maxLifetime = value; }
90 }
91
95 public TimeSpan Lifetime
96 {
97 get { return Game.Time.SinceStartOfGame - creationTime; }
98 }
99
100 #endregion
101
112 public void Initialize(Vector position, double scale, double rotation, double rotationSpeed, Vector velocity, Vector acceleration, double lifetime)
113 {
114 this.position = position;
115 this.scale = scale;
116 this.maxLifetime = TimeSpan.FromSeconds(lifetime);
117 this.creationTime = Game.Time.SinceStartOfGame;
118
119 this.velocity = velocity;
120 this.rotationSpeed = rotationSpeed;
121 this.acceleration = acceleration;
122
123 this.rotation = rotation;
124 }
125
126
131 public void Update(double time)
132 {
133 position += velocity * time;
134 velocity += acceleration * time;
135
136 rotation += rotationSpeed * time;
137 }
138 }
139}
Vector Position
Partikkelin sijainti
Definition: Particle.cs:25
TimeSpan Lifetime
Partikkelin tämän hetkinen ikä
Definition: Particle.cs:96
void Initialize(Vector position, double scale, double rotation, double rotationSpeed, Vector velocity, Vector acceleration, double lifetime)
Alusta partikkeli
Definition: Particle.cs:112
Vector Acceleration
Partikkelin kiihtyvyys
Definition: Particle.cs:70
TimeSpan MaxLifetime
Partikkelin elinikä
Definition: Particle.cs:87
double Scale
Partikkelin skaalaus
Definition: Particle.cs:34
Vector Velocity
Partikkelin nopeus
Definition: Particle.cs:61
bool Alive
Onko partikkelin "elossa", eli päivitetäänkö ja piirretäänkö se
Definition: Particle.cs:79
double RotationSpeed
Partikkelin kiertonopeus
Definition: Particle.cs:52
void Update(double time)
Päivittää partikkelin sijannin, nopeuden ja kierron
Definition: Particle.cs:131
double Rotation
Partikkelin kierto
Definition: Particle.cs:43
static Time Time
Peliaika. Sisältää tiedon siitä, kuinka kauan peliä on pelattu (Time.SinceStartOfGame) ja kuinka kaua...
Definition: Time.cs:25
TimeSpan SinceStartOfGame
Aika joka on kulunut pelin alusta.
Definition: Time.cs:35
2D-vektori.
Definition: Vector.cs:67