/
Explosion.cs
137 lines (107 loc) · 4.16 KB
/
Explosion.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
125
126
127
128
129
130
131
132
133
134
135
136
137
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SharpDX;
using SharpDX.Toolkit;
namespace Project1
{
using SharpDX.Toolkit.Graphics;
using SharpDX.Toolkit.Input;
using System.Diagnostics;
// Projectile classed, used by both player and enemy.
class Explosion : ColoredGameObject
{
private Vector3 vel;
private float hitRadius = 0.5f;
private float squareHitRadius;
private float aliveTime = .9f;
private float timeElapsed = 0.0f;
private float dynamicScale;
private Color color;
private float spawnTimeOffset = 0;
private bool head;
private Matrix scale;
// an array of Vectors without color setting
private Vector3[] buffer;
// an array of Vectors with color setting
private VertexPositionColor[] colorBuffer;
// Constructor.
public Explosion(Project1Game game)
{
this.game = game;
this.SetBuffer();
vertices = Buffer.Vertex.New(game.GraphicsDevice, colorBuffer);
basicEffect = new BasicEffect(game.GraphicsDevice)
{
View = game.camera.View,
Projection = game.camera.Projection,
World = Matrix.Identity,
VertexColorEnabled = true
};
inputLayout = VertexInputLayout.FromBuffer(0, vertices);
}
// Frame update method.
public override void Update(GameTime gameTime)
{
//// Apply velocity to position.
//pos += vel * timeDelta;// *0.5f;
//transformation = Matrix.RotationQuaternion(game.asteroidRotate);
//timeElapsed += timeDelta;
////dynamicScale *= 1.01f;
//dynamicScale *= .95f;
//if (timeElapsed < aliveTime / 2)
//{
// this.vel.X -= this.vel.Y / 100f;
// this.vel.Y += this.vel.X / 100f;
// this.vel.Z += this.vel.X / 100f;
//}
//else
//{
// this.vel.X += this.vel.Y / 100f + Game.random.Next(-100, 100) / 100f; ;
// this.vel.Y -= this.vel.X / 100f + Game.random.Next(-100, 100) / 100f; ;
// this.vel.Z -= this.vel.X / 100f + Game.random.Next(-100, 100) / 100f; ;
//}
//if (head && spawnTimeOffset + 0.1f < timeElapsed)
//{
// var newVel = this.vel / 2f;
// newVel.X += spawnTimeOffset + Game.random.Next(-100, 100) / 100f;
// newVel.Y -= spawnTimeOffset + Game.random.Next(-100, 100) / 100f;
// newVel.Z += spawnTimeOffset + Game.random.Next(-100, 100) / 100f;
// game.Add(new Explosion(game, this.pos, newVel, this.colour, 0.1f, false));
// spawnTimeOffset = timeElapsed;
//}
//this.scale = Matrix.Scaling(dynamicScale);
//if (timeElapsed > aliveTime)
// game.Remove(this);
}
public override void Draw(GameTime gameTime)
{
// Setup the vertices
game.GraphicsDevice.SetVertexBuffer(vertices);
game.GraphicsDevice.SetVertexInputLayout(inputLayout);
// Apply the basic effect technique and draw the rotating cube
basicEffect.CurrentTechnique.Passes[0].Apply();
game.GraphicsDevice.Draw(PrimitiveType.TriangleList, vertices.ElementCount);
}
private void SetBuffer()
{
this.colorBuffer = setVertex();
}
public VertexPositionColor[] setVertex()
{
VertexPositionColor[] buffer = new VertexPositionColor[3];
List<VertexPositionColor> colorBufferList = buffer.ToList();
for (int i = 0; i < 2; i++)
{
colorBufferList.Add(this.game.assets.CreateColoredTriangle(new Vector3(10, 10, 10), Color.Red)[i]);
}
buffer = colorBufferList.ToArray();
return buffer;
}
public Vector3 findPos()
{
return new Vector3(1, 1, 1);
}
}
}