-
Notifications
You must be signed in to change notification settings - Fork 0
/
BarcoBot.cs
193 lines (158 loc) · 8.21 KB
/
BarcoBot.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
using System;
using System.Collections.Generic;
using System.Text;
using TgcViewer.Example;
using TgcViewer;
using Microsoft.DirectX.Direct3D;
using System.Drawing;
using Microsoft.DirectX;
using TgcViewer.Utils.Modifiers;
using TgcViewer.Utils.TgcSceneLoader;
using TgcViewer.Utils.Input;
using Microsoft.DirectX.DirectInput;
using TgcViewer.Utils.Terrain;
using TgcViewer.Utils.TgcGeometry;
namespace AlumnoEjemplos.Quicksort
{
class BarcoBot : Barco
{
float cooldown = 0;
Barco BarcoEnemigo { get; set; }
public Vector3 LastPos { get; set; }
public BarcoBot(int vida, int danio, float velocidad,float aceleracion, float rotacion, TgcMesh mesh, double pot, Barco barcoEnemigo,TgcSceneLoader bm,TgcMesh bala) : base (vida, danio, velocidad, rotacion, mesh,pot,bm,bala)
{
BarcoEnemigo = barcoEnemigo;
LastPos = Mesh.Position;
BarcosEnemigos.Add(barcoEnemigo);
daniado = false;
}
public float distancia()
{
Vector3 vectplanchado1 = new Vector3(BarcoEnemigo.Mesh.Position.X, 0, BarcoEnemigo.Mesh.Position.Z);
Vector3 vectplanchado2 = new Vector3(this.Mesh.Position.X, 0, this.Mesh.Position.Z);
return (Vector3.Length(vectplanchado1 - vectplanchado2));
}
public Boolean estaEnCarrera()
{
Vector3 vect = BarcoEnemigo.Mesh.Position - this.Mesh.Position;
var vnulo = new Vector3(0,0,0);
if(Vector3.Cross(vect,this.Mesh.Rotation) == vnulo){
return true;
}else{
return false;
}
}
public void Movimiento(float elapsedTime)
{
//Calcular proxima posicion de personaje segun Input
TgcD3dInput d3dInput = GuiController.Instance.D3dInput;
// distancia para aproximarse al barco
if( distancia() > 500){
acelerar();
var vect = new Vector3(FastMath.Sin(Mesh.Rotation.Y), 0 ,FastMath.Cos(Mesh.Rotation.Y));
var vect2 = new Vector3(FastMath.Sin(BarcoEnemigo.Mesh.Rotation.Y), 0, FastMath.Cos(BarcoEnemigo.Mesh.Rotation.Y));
Vector3 vectplanchado1 = new Vector3(BarcoEnemigo.Mesh.Position.X, 0, BarcoEnemigo.Mesh.Position.Z);
Vector3 vectplanchado2 = new Vector3(this.Mesh.Position.X, 0, this.Mesh.Position.Z);
Vector3 vectnDireccion = Vector3.Normalize(vectplanchado1-vectplanchado2);
Vector3 vectnMio = Vector3.Normalize(this.Mesh.Rotation);
var cdot = Vector3.Dot(vectnDireccion, vectnMio);
var angulo = Geometry.RadianToDegree((float)Math.Acos(Vector3.Dot(vectnDireccion, vect)));
//var a =VDot(vectEnem.Normalize(), vectMio.Normalize());
if (!(Vector3.Dot(vect, vectnDireccion) == 1))
{
if (Vector3.Cross(vect, vectnDireccion).Y > 0 && VelocidadMov > 15)//el barco esta a la izq
{
this.rotar(1);
}
if (Vector3.Cross(vect, vectnDireccion).Y <0 && VelocidadMov > 15) //el barco esta a la derecha o atras
{
this.rotar(-1);
}
}
}
else if (distancia() < 200)
{
var vect = new Vector3(FastMath.Sin(Mesh.Rotation.Y), 0, FastMath.Cos(Mesh.Rotation.Y));
//var vect2 = new Vector3(FastMath.Sin(BarcoEnemigo.Mesh.Rotation.Y), 0, FastMath.Cos(BarcoEnemigo.Mesh.Rotation.Y));
Vector3 vectplanchado1 = new Vector3(BarcoEnemigo.Mesh.Position.X, 0, BarcoEnemigo.Mesh.Position.Z);
Vector3 vectplanchado2 = new Vector3(this.Mesh.Position.X, 0, this.Mesh.Position.Z);
Vector3 vectnDireccion = Vector3.Normalize(vectplanchado1 - vectplanchado2);
//Vector3 vectnMio = Vector3.Normalize(this.Mesh.Rotation);
//var cdot = Vector3.Dot(vectnDireccion, vectnMio);
//var angulo = Geometry.RadianToDegree((float)Math.Acos(Vector3.Dot(vectnDireccion, vect)));
//var a =VDot(vectEnem.Normalize(), vectMio.Normalize());
if (!(Vector3.Dot(vect, vectnDireccion) == 1))
{
if (Vector3.Cross(vect, vectnDireccion).Y > 0 && VelocidadMov > 15)//el barco esta a la izq
{
this.rotar(-1); //roto al revez
}
if (Vector3.Cross(vect, vectnDireccion).Y< 0 && VelocidadMov> 15) //el barco esta a la derecha o atras
{
this.rotar(1); //roto al revez
}
}
acelerar();
}else
{
if(cooldown < 1){
frenar();
var vect = new Vector3(FastMath.Sin(Mesh.Rotation.Y), 0, FastMath.Cos(Mesh.Rotation.Y));
Vector3 vectplanchado1 = new Vector3(BarcoEnemigo.Mesh.Position.X, 0, BarcoEnemigo.Mesh.Position.Z);
Vector3 vectplanchado2 = new Vector3(this.Mesh.Position.X, 0, this.Mesh.Position.Z);
Vector3 vectnDireccion = Vector3.Normalize(vectplanchado1-vectplanchado2);
if (!(Vector3.Dot(vect, vectnDireccion) == 1))
{
if (Vector3.Cross(vect, vectnDireccion).Y > 0)//el barco esta a la izq
{
dispararBala(1, 1); //dispara der
}
if (Vector3.Cross(vect, vectnDireccion).Y < 0) //el barco esta a la derecha o atras
{
dispararBala(1, 0); //dispara izq
}
}
cooldown = 5;
}else
{
cooldown -= elapsedTime*1;
var vect = new Vector3(FastMath.Sin(Mesh.Rotation.Y), 0, FastMath.Cos(Mesh.Rotation.Y));
Vector3 vectnDireccion = Vector3.Normalize(BarcoEnemigo.Mesh.Position - this.Mesh.Position);
var angulo = (float)Math.Acos(Vector3.Dot(vectnDireccion, vect));
//if (Vector3.Cross(vect, vectnDireccion).Y > 0)//el barco esta a la izq
//{
if (Math.Cos(angulo) > 0)
{
this.Mesh.rotateY(Geometry.DegreeToRadian((float)-6 * elapsedTime));
}
if (Math.Cos(angulo) < 0)
{
this.Mesh.rotateY(Geometry.DegreeToRadian((float)6 * elapsedTime));
}
//}
//if (Vector3.Cross(vect, vectnDireccion).Y < 0) //el barco esta a la derecha o atras
//{
// this.Mesh.rotateY(Geometry.DegreeToRadian((float)-1 * elapsedTime)); //dispara izq
//}
}
}
//Si hubo rotacion
if (VelocidadMov > 15)
{
//Rotar personaje y la camara, hay que multiplicarlo por el tiempo transcurrido para no atarse a la velocidad el hardware
float rotAngle = Geometry.DegreeToRadian((float)VelocidadRot * elapsedTime);
this.Mesh.rotateY(rotAngle);
//GuiController.Instance.ThirdPersonCamera.rotateY(rotAngle);
}
//Si hubo desplazamiento
//if (moving)
{
//Aplicar movimiento hacia adelante o atras segun la orientacion actual del Mesh
Vector3 lastPos = this.Mesh.Position;
//La velocidad de movimiento tiene que multiplicarse por el elapsedTime para hacerse independiente de la velocida de CPU
//Ver Unidad 2: Ciclo acoplado vs ciclo desacoplado
this.Mesh.moveOrientedY((float)VelocidadMov *boostOla()* elapsedTime);
}
}
}
}