-
Notifications
You must be signed in to change notification settings - Fork 1
/
SpaceShip.cs
157 lines (142 loc) · 4.29 KB
/
SpaceShip.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
using System;
using System.Collections.Generic;
using System.Text;
using Tao.OpenGl;
using System.Windows.Forms;
using ShadowEngine;
using ShadowEngine.Sound;
using ShadowEngine.ContentLoading;
using WMPLib;
namespace Naves
{
public class SpaceShip
{
int vidas = 3;
Position p = new Position(0, 0, 0);
int count;
int compare = 10;
ModelContainer m;
bool moviendo;
public bool Moviendo
{
get { return moviendo; }
set { moviendo = value; }
}
public int Vidas
{
get { return vidas; }
set { vidas = value; }
}
public void Reiniciar()
{
vidas = 3;
p = new Position(0, 0, 0);
}
public void Create()
{
m = ContentManager.GetModelByName("nave.3DS");
m.CreateDisplayList();
}
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);
}
}
WMPLib.WindowsMediaPlayer Player;
public void PlayFile(String url)
{
Player = new WMPLib.WindowsMediaPlayer();
Player.PlayStateChange +=
new WMPLib._WMPOCXEvents_PlayStateChangeEventHandler(Player_PlayStateChange);
Player.MediaError +=
new WMPLib._WMPOCXEvents_MediaErrorEventHandler(Player_MediaError);
Player.URL = url;
Player.controls.play();
}
private void Player_PlayStateChange(int NewState)
{
if ((WMPLib.WMPPlayState)NewState == WMPLib.WMPPlayState.wmppsStopped)
{
//this.Close();
}
}
private void Player_MediaError(object pMediaObject)
{
// MessageBox.Show("Cannot play media file.");
// this.Close();
}
void RestarVida()
{
try
{
PlayFile("approaching-alien.mp3");
}
catch (Exception ex)
{ }
compare = 25;
vidas--;
p = new Position(0, 0, 0);
}
}
}