public Asteroid() { p = default(Position); rot = r.Next(90); Reset(); if (r.Next(2) == 1) { this.texture = ContentManager.GetTextureByName("asteroide1.jpg"); } else { this.texture = ContentManager.GetTextureByName("asteroide2.jpg"); } }
public static bool CheckCollision(Position pNave, float radio) { foreach (var item in listAsteroid) { Position pAsteroide = item.Position; if (Math.Pow(Math.Pow(pAsteroide.x - pNave.x, 2) + Math.Pow(pAsteroide.y - pNave.y, 2) + Math.Pow(pAsteroide.z - pNave.z, 2), 1 / 3f) < radio) { if (item.Crashed == false) { item.Crashed = true; return true; } } } return false; }
public void Dibujar() { if (vidas > 0) { switch (Main.Moviendo) { case 1: { if (p.x < 3) p.x += 0.08f; break; } case -1: { if (p.x > -3) p.x -= 0.08f; break; } case 2: { if (p.y < 3) p.y += 0.08f; break; } case -2: { if (p.y > -3) p.y -= 0.08f; break; } default: break; } count++; if (count == compare) { if (compare == 25) { compare = 10; } Position wingLeft = new Position(this.p.x - 1f, this.p.y, this.p.z); Position wingRight = new Position(this.p.x + 1f, this.p.y, this.p.z); if (AsteroidGenerator.CheckCollision(this.p, 1.1f)) { RestarVida(); } else if (AsteroidGenerator.CheckCollision(wingRight, 1.1f)) { RestarVida(); } else if (AsteroidGenerator.CheckCollision(wingLeft, 1.1f)) { RestarVida(); } count = 0; } Gl.glPushMatrix(); Gl.glTranslatef(p.x, p.y, p.z); Gl.glScalef(0.3f, 0.3f, 0.3f); m.DrawWithTextures(); Gl.glPopMatrix(); Gl.glDisable(Gl.GL_TEXTURE_2D); } }
void RestarVida() { try { PlayFile("approaching-alien.mp3"); } catch (Exception ex) { } compare = 25; vidas--; p = new Position(0, 0, 0); }
public void Reiniciar() { vidas = 3; p = new Position(0, 0, 0); }