-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJugador.cs
171 lines (163 loc) · 5.55 KB
/
Jugador.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
namespace TarreeGame
{
class Jugador
{
#region declaraciones
Vector2 posicion;
Vector2 pantalla = new Vector2(759, 549);
int valorrate = 5;
string iNombre=null;
int ifrags = 0;
int ividas = 2;
bool ien_juego = false;
Texture2D playertexture;
#endregion
#region propiedades
public float X
{
get { return posicion.X; }
set { posicion.X = value; }
}
public float Y
{
get { return posicion.Y; }
set { posicion.Y = value; }
}
public int rate
{
get { return valorrate; }
set { valorrate = value; }
}
public string Nombre
{
get { return iNombre; }
set { iNombre = value; }
}
public int frags
{
get { return ifrags; }
set { ifrags = value; }
}
public int vidas
{
get { return ividas; }
set { ividas = value; }
}
public Vector2 poss {
get { return posicion; }
set { posicion = value; }
}
public bool en_juego
{
get { return en_juego; }
set { ien_juego = value; }
}
#endregion
#region constructores
public Jugador( ContentManager Content,string eleccion) {
if (eleccion == "Mava")
{
posicion.X = 10;
posicion.Y = 10;
iNombre = "Mava";
playertexture = Content.Load<Texture2D>(@"Texture\Mava");
}
if (eleccion == "Lito")
{
posicion.X = 749;
posicion.Y = 10;
iNombre = "Lito";
playertexture = Content.Load<Texture2D>(@"Texture\Lito");
}
if (eleccion == "Juba")
{
posicion.X = 10;
posicion.Y = 539;
iNombre = "Juba";
playertexture = Content.Load<Texture2D>(@"Texture\Juba");
}
if (eleccion == "Punchi")
{
posicion.X = 400;
posicion.Y = 400;
//posicion.X = 749;
//posicion.Y = 539;
iNombre = "Punchi";
playertexture = Content.Load<Texture2D>(@"Texture\Punchi");
}
ien_juego = false;
}
#endregion
#region metodos
public void Draw(SpriteBatch spritebatch,SpriteFont spritefont)
{
spritebatch.DrawString(spritefont, "(" + Nombre + ")", poss, Color.Black, 0, new Vector2(10, 30), 1f, SpriteEffects.None, 0);
spritebatch.DrawString(spritefont, "(" + Nombre + ")", poss + new Vector2(1, 1), Color.Red, 0, new Vector2(10, 30), 1f, SpriteEffects.None, 0);
spritebatch.DrawString(spritefont, vidas.ToString(), poss, Color.Black, 0, new Vector2(-15, -50), 1f, SpriteEffects.None, 0);
spritebatch.DrawString(spritefont, vidas.ToString(), poss+new Vector2(1,1), Color.Red, 0, new Vector2(-15, -50), 1f, SpriteEffects.None, 0);
spritebatch.Draw(playertexture,posicion,Color.White);
}
public bool ImpactoBala(Bala bala)
{
if (FastDistance(posicion + new Vector2(25, 25), bala.poss + new Vector2(3, 3)) - 26 <= 0 && bala.activo)
return true;
else return false;
}
public void Update(Vector2 playerinput)
{
posicion.X = posicion.X + playerinput.X * rate;
posicion.Y = posicion.Y + playerinput.Y * rate;
posicion = Vector2.Clamp(posicion, Vector2.Zero, pantalla);
}
public static int FastDistance(Vector2 p1, Vector2 p2)
{
int x = (int)System.Math.Abs(p2.X - p1.X);
int y = (int)System.Math.Abs(p2.Y - p1.Y);
int min = x < y ? x : y;
return System.Math.Abs(x + y - (min >> 1) - (min >> 2) + (min >> 4));
}
public void KillPlayer(Jugador player)
{
if (vidas <= 2) { vidas--; }
if (vidas == 0)
{
vidas = 2;
player.frags++;
if (Nombre == "Mava")
{
posicion.X = 10;
posicion.Y = 10;
}
if (Nombre == "Lito")
{
posicion.X = 749;
posicion.Y = 10;
}
if (Nombre == "Juba")
{
posicion.X = 10;
posicion.Y = 539;
}
if (Nombre == "Punchi")
{
posicion.X = 749;
posicion.Y = 539;
}
}
}
#endregion
}
}