-
Notifications
You must be signed in to change notification settings - Fork 0
/
DustParticleManager.cs
124 lines (106 loc) · 4.05 KB
/
DustParticleManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#region Using Statements
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
using Microsoft.Xna.Framework.GamerServices;
#endregion
namespace Tanks
{
class DustParticleManager
{
private DustParticle[] dustArray;
private Random random;
private Tank tank;
private Map map;
private Vector3 tankButtPosition;
private int randomYaw;
private int randomPitch;
private float randomSpeed;
private float randomPitchSpeed;
public DustParticleManager(GraphicsDevice graphicsDevice, Map map, Tank tank)
{
dustArray = new DustParticle[500];
random = new Random();
this.tank = tank;
this.map = map;
FindTankButt();
for (int i = 0; i < dustArray.Length; i++)
{
dustArray[i] = new DustParticle(graphicsDevice, map.Effect);
MakeItRain(i);
}
}
public void FindTankButt()
{
tankButtPosition = tank.Position + tank.NewDirection * -1 + tank.TankOrientation;
tankButtPosition.Y = tank.Position.Y;
if ((tankButtPosition.X > 2f && tankButtPosition.X < map.Width - 2f && tankButtPosition.Z > 2f && tankButtPosition.Z < map.Height - 2f))
{
tankButtPosition = map.CalcSurfaceFollow(tankButtPosition, 0);
}
else
{
tankButtPosition = tank.Position;
}
}
public void MakeItRain(int i)
{
randomYaw = random.Next((int)MathHelper.ToRadians(-90), (int)MathHelper.ToRadians(90));
randomPitch = random.Next(0, (int)MathHelper.ToRadians(-10));
randomSpeed = random.Next(10, 30) * 0.005f;
randomPitchSpeed = random.Next(1, 5) * 0.05f;
dustArray[i].Position = tankButtPosition + Vector3.Transform(Vector3.Right, Matrix.CreateRotationY(tank.Yaw)) * random.Next(-5, 5) * 0.2f;
dustArray[i].Speed = randomSpeed;
dustArray[i].Yaw = tank.Yaw + randomYaw;
dustArray[i].Pitch = randomPitch;
dustArray[i].PitchSpeed = randomPitchSpeed;
}
public void Update()
{
FindTankButt();
for (int i = 0; i < dustArray.Length; i++)
{
if ((dustArray[i].Position.X > 2f && dustArray[i].Position.X < map.Width - 2f && dustArray[i].Position.Z > 2f
&& dustArray[i].Position.Z < map.Height - 2f))
{
if (dustArray[i].Position.Y > map.CalcSurfaceFollow(dustArray[i].Position, 0).Y - 0.5f)
dustArray[i].Update();
if (dustArray[i].Position.Y <= map.CalcSurfaceFollow(dustArray[i].Position, 0).Y - 0.5f && tank.Moving)
{
MakeItRain(i);
}
}
else
{
if (dustArray[i].Position.Y > 0)
dustArray[i].Update();
if (dustArray[i].Position.Y <= 0 && tank.Moving)
{
MakeItRain(i);
}
}
}
}
public void Draw()
{
for (int i = 0; i < dustArray.Length; i++)
{
if ((dustArray[i].Position.X > 2f && dustArray[i].Position.X < map.Width - 2f && dustArray[i].Position.Z > 2f
&& dustArray[i].Position.Z < map.Height - 2f))
{
if (dustArray[i].Position.Y > map.CalcSurfaceFollow(dustArray[i].Position, 0).Y - 0.5f)
dustArray[i].Draw();
}
else
{
if (dustArray[i].Position.Y > 0)
dustArray[i].Draw();
}
}
}
}
}