-
Notifications
You must be signed in to change notification settings - Fork 1
/
Bullet.cs
144 lines (114 loc) · 4.57 KB
/
Bullet.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
138
139
140
141
142
143
144
using System;
using System.Collections;
using System.IO;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
namespace tglrf
{
public struct PointVertex
{
public Vector3 v;
public int color;
//public static readonly VertexFormats Format = VertexFormats.Position | VertexFormats.Diffuse;
};
public class BulletBuffer
{
private ArrayList bullets = new ArrayList();
private Texture2D texture;
private VertexPositionColor[] vertices;
public BulletBuffer(GraphicsDevice device, ContentManager content)
{
vertices = new VertexPositionColor[1024];
texture = content.Load<Texture2D>(@"gfx\particle");
//,
// D3DX.Default, D3DX.Default, 0, (Usage)0, Format.Unknown, Pool.Managed,
// Filter.None, (Filter)0, 0);
}
public void Render(GraphicsDevice device, BasicEffect basicEffect, ObjectShip ship, LevelBackgroundGF levelBackground)
{
basicEffect.World = Matrix.Identity;
basicEffect.LightingEnabled = false;
device.RenderState.DepthBufferEnable = false;
device.RenderState.CullMode = CullMode.None;
device.RenderState.PointSpriteEnable = true;
//device.RenderState.PointScaleEnable = true ;
device.RenderState.PointSize = 10.0f;
device.RenderState.PointSizeMin = 0.00f;
device.RenderState.PointSizeMax = 100.00f;
//device.RenderState.PointScaleA = 0.00f;
//device.RenderState.PointScaleB = 0.00f;
//device.RenderState.PointScaleC = 1.00f;
device.RenderState.AlphaBlendEnable = true;
device.RenderState.SourceBlend = Blend.One;
device.RenderState.DestinationBlend = Blend.One;
basicEffect.Texture = texture;
basicEffect.TextureEnabled = true;
int count = 0;
bool hackColliding = false;
for(int i = 0; i < 6; i++)
{
Vector3 v = ship.colisionPoints[i];
//v = Vector3.TransformCoordinate(v, ship.renderMatrix);
v = Vector3.Transform(v, ship.renderMatrix);
//// Vector3 v = ship.Position;
//// v.Y = v.Y + (float)(ship.boundingBoxMax.Y * ship.scale * Math.Cos(ship.Rotation.Z));
//// v.X = v.X - (float)(ship.boundingBoxMax.Y * ship.scale * Math.Sin(ship.Rotation.Z));
bool collide = levelBackground.CheckCollision(v);
VertexPositionColor pv;
pv.Position = v;
pv.Color = collide ? Color.Yellow : Color.White;
if(collide)
{
vertices[count] = pv;
count++;
}
hackColliding |= collide;
}
if(!ship.hackColliding && hackColliding)
{
ship.Position = ship.OldPosition;
ship.Speed = -ship.Speed * 0.3f;
SoundHandler.Checkpoint();
}
ship.hackColliding = hackColliding;
device.VertexDeclaration = new VertexDeclaration(device, VertexPositionColor.VertexElements);
//// Unlock the vertex buffer
//vertexBuffer.Unlock();
//// Render any remaining particles
if (count > 0)
{
basicEffect.Begin();
foreach(EffectPass pass in basicEffect.CurrentTechnique.Passes)
{
pass.Begin();
device.DrawUserPrimitives(PrimitiveType.PointList, vertices, 0, count);
pass.End();
}
basicEffect.End();
}
//// Reset render states
//device.RenderState.PointSpriteEnable = false;
//device.RenderState.PointScaleEnable = false;
//device.RenderState.PointSpriteEnable = true;
//device.RenderState.PointScaleEnable = true ;
//device.RenderState.AlphaBlendEnable = false;
device.RenderState.PointSpriteEnable = false;
device.RenderState.DepthBufferWriteEnable = true;
device.RenderState.SourceBlend = Blend.SourceAlpha;
device.RenderState.DestinationBlend = Blend.InverseSourceAlpha;
}
}
/// <summary>
/// Summary description for Bullet.
/// </summary>
public class Bullet
{
public Bullet()
{
//
// TODO: Add constructor logic here
//
}
}
}