Jypeli  5
The simple game programming library
Particle.cs
Siirry tämän tiedoston dokumentaatioon.
1 using System;
2 using Microsoft.Xna.Framework.Graphics;
3 
4 namespace Jypeli.Effects
5 {
9  public class Particle
10  {
11  #region Variables, getters and setters
12 
13  private Vector position;
14  private double scale;
15  private double rotation;
16  private double rotationSpeed;
17  private Vector velocity;
18  private Vector acceleration;
19  private TimeSpan maxLifetime;
20  private TimeSpan creationTime;
21 
25  public Vector Position
26  {
27  get { return position; }
28  set { position = value; }
29  }
30 
34  public double Scale
35  {
36  get { return scale; }
37  set { scale = value; }
38  }
39 
43  public double Rotation
44  {
45  get { return rotation; }
46  set { rotation = value; }
47  }
48 
52  public double RotationSpeed
53  {
54  get { return rotationSpeed; }
55  set { rotationSpeed = value; }
56  }
57 
61  public Vector Velocity
62  {
63  get { return velocity; }
64  set { velocity = value; }
65  }
66 
70  public Vector Acceleration
71  {
72  get { return acceleration; }
73  set { acceleration = value; }
74  }
75 
79  public bool Alive
80  {
81  get { return Lifetime < MaxLifetime; }
82  }
83 
87  public TimeSpan MaxLifetime
88  {
89  get { return maxLifetime; }
90  set { maxLifetime = value; }
91  }
92 
96  public TimeSpan Lifetime
97  {
98  get { return Game.Time.SinceStartOfGame - creationTime; }
99  }
100 
101  #endregion
102 
113  public void Initialize(Vector position, double scale, double rotation, double rotationSpeed, Vector velocity, Vector acceleration, double lifetime)
114  {
115  this.position = position;
116  this.scale = scale;
117  this.maxLifetime = TimeSpan.FromSeconds(lifetime);
118  this.creationTime = Game.Time.SinceStartOfGame;
119 
120  this.velocity = velocity;
121  this.rotationSpeed = rotationSpeed;
122  this.acceleration = acceleration;
123 
124  this.rotation = rotation;
125  }
126 
127 
132  public void Update(double time)
133  {
134  position += velocity * time;
135  velocity += acceleration * time;
136 
137  rotation += rotationSpeed * time;
138  }
139  }
140 }
TimeSpan SinceStartOfGame
Aika joka on kulunut pelin alusta.
Definition: Time.cs:32
void Update(double time)
Päivittää partikkelin sijannin, nopeuden ja kierron
Definition: Particle.cs:132
Peliluokka reaaliaikaisille peleille.
Definition: DebugScreen.cs:10
static Time Time
Peliaika. Sisältää tiedon siitä, kuinka kauan peliä on pelattu (Time.SinceStartOfGame) ja kuinka kaua...
Definition: Game.cs:309
void Initialize(Vector position, double scale, double rotation, double rotationSpeed, Vector velocity, Vector acceleration, double lifetime)
Alusta partikkeli
Definition: Particle.cs:113
2D-vektori.
Definition: Vector.cs:56