-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.s3d
347 lines (303 loc) · 6.59 KB
/
player.s3d
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
#include "bullet.s3d"
#include "screen.s3d"
#define SWAT_START_WALK 16
#define SWAT_END_WALK 48
#define NUM_ARMI 2
#define LIFE_MAX 100
#define JUMP 0.24
var time_b =0;
var enter = FALSE;
var first_visual = FALSE;
var jump_start = 400;
var jump_end = TRUE;
var enable = TRUE;
class player
{
// mesh
var mesh_lower;
var mesh_upper;
var mesh_railgun;
// obj
var obj_root;
var obj_lower;
var obj_upper;
var obj_railgun;
// player management
var old_position;
var position;
var verso;
var corsa;
var speed;
var direction;
var direction_lr;
var angleY;
var lat;
// player color and mesh animation
var color;
var current_frame;
// player's ammo
var player_bullet;
var shot_direction;
var selected_weapon;
var unlock;
//player life and score
var life;
var score;
// sound
var sfx_step;
// after died variable
var restart;
// screen managemente variable
var scr;
//init(i,c,p);
controll();
draw();
update();
reset_pl();
update_other();
ChangeWeapon();
visual(visual);
SetShotDirection(direction);
SetPosition(x,y,z);
GetPosition();
GetDirection();
step(move);
SetAngle(angle);
GetAngle();
LooseLife(value);
GetWeapon();
};
function player::player(i,c,p)
{
restart = FALSE;
unlock = FALSE;
color = c;
score = 0;
verso = 0;
lat = 0;
corsa = 0;
shot_direction = [0,0,0];
selected_weapon = 0;
life = LIFE_MAX;
scr = screen();
mesh_lower = CVmNewMesh("swat_lower.AAM");
mesh_upper = CVmNewMesh("swat_upper.AAM");
mesh_railgun = CVmNewMesh("railgun.AAM");
mesh_lower.scale(0.036);
mesh_upper.scale(0.036);
mesh_railgun.scale(0.036);
obj_lower = CVmObj(mesh_lower);
obj_upper = CVmObj(mesh_upper);
obj_railgun = CVmObj(mesh_railgun);
obj_root = CVmObj();
obj_root.addChild(obj_upper);
obj_root.addChild(obj_lower);
obj_root.addChild(obj_railgun);
obj_root.modulateMaterials(color);
position = p;
old_position = position;
obj_root.setPosition(position);
angleY = 0;
speed = 0.1;
current_frame = SWAT_START_WALK;
player_bullet = array(NUM_ARMI);
for(var i=0;i<NUM_ARMI;i++){
player_bullet[i] = bullet(color+[i,0,0],0.1+0.3*i,1+9*i,50+i*20);
}
sfx_step = CVmVRAWav("step.wav",true); //file .wav
}
function player::reset_pl()
{
position = [0,0,0];
life = LIFE_MAX;
score = 0;
// valore usato dalla network per capire se il giocatore è tornato in vita
restart = TRUE;
}
function player::LooseLife(value)
{
if(life>0)
if(life-value<0)
life = 0;
else
life -= value;
}
function player::update_other()
{
verso = verso*0.01 ;
lat = lat *0.01;
// avanti-indietro
direction = [sin(angleY*GRAD_TO_RAD),0,cos(angleY*GRAD_TO_RAD)];
// destra-sinista
direction_lr = [-sin((90-angleY)*GRAD_TO_RAD),0,cos((90-angleY)*GRAD_TO_RAD)];
position = position + direction*verso*speed+direction_lr*lat*speed;
obj_root.SetPosition(position);
obj_root.SetRotation(angleY,0,1,0);
sfx_step.SetPosition(position);
sfx_step.SetListenerPosition(CameraGetPosition());
sfx_step.SetListenerOrientation(-CameraGetDirection());
if(verso != 0)
{
step(verso);
}
player_bullet[selected_weapon].update_other();
}
function player::update()
{
// avanti-indietro
direction = scr.direction();
// destra-sinista
direction_lr = scr.direction_lr();
// check the pressed key
controll();
old_position = position;
position = position + (direction*verso*corsa+direction_lr*lat)*speed;
obj_root.SetPosition(position);
obj_root.SetRotation(scr.angle,0,1,0);
sfx_step.SetPosition(position);
sfx_step.SetListenerPosition(CameraGetPosition());
sfx_step.SetListenerOrientation(-CameraGetDirection());
if(verso != 0)
step(verso);
if(lat != 0)
step(lat);
player_bullet[selected_weapon].update();
visual(first_visual);
ConsoleText(0.1,0.20,"Life");
ConsoleText(0.1,0.15,str(life));
if(selected_weapon == 1)
ConsoleText(0.6,0.9,"Type Ammo: Strong");
else
ConsoleText(0.6,0.9,"Type Ammo: Normal");
}
function player::step(move)
{
var delta_frame = 0.30*corsa*move;
current_frame += delta_frame;
if(current_frame >= SWAT_END_WALK)
{
current_frame = SWAT_START_WALK;
sfx_step.Play();
}
else
if(current_frame <= SWAT_START_WALK)
{
current_frame = SWAT_END_WALK;
sfx_step.Play();
}
else
if(current_frame >= 31 && current_frame <=32)
sfx_step.Play();
}
function player::controll()
{
corsa = 1;
lat = lat * 0.01;;
verso = verso*0.01;
if(GetTime()-time_b > 1000)
{
enter = TRUE;
time_b = GetTime();
}
if(Keypressed("d",FALSE))
lat = 1;
if(Keypressed("a",FALSE))
lat = -1;
if(Keypressed("w",FALSE))
verso = 1;
if(Keypressed("s",FALSE))
verso = -1;
if(Keypressed(VK_SHIFT))
corsa = 2.4;
if(Keypressed("q",FALSE) && enter && unlock)
{
enter = FALSE;
ChangeWeapon();
}
if(Keypressed("r",FALSE) && enter)
{
enter = FALSE;
player_bullet[selected_weapon].recharge();
}
if((Keypressed("e",FALSE)|| Mouse.ButtonL()) && enter)
{
enter = FALSE;
player_bullet[selected_weapon].shot(position,scr.direction_ud());
}
if(KeyPressed("v",FALSE) && enter)
{
enter = FALSE;
first_visual = !first_visual;
}
if(KeyPressed(VK_SPACE,FALSE) && jump_end)
{
jump_end = FALSE;
jump_start = 0;
}
if(jump_start < 18)
{
position.y += JUMP;
jump_start ++;
}
else
jump_end = TRUE;
}
function player::draw()
{
obj_root.Draw(VR_FRAMENUMBER,current_frame);
player_bullet[selected_weapon].draw();
}
function player::visual(visual)
{
scr.move();
CameraGetCurrent().SetDirection(scr.direction_ud());
if(visual)
{
obj_root.Unhide();
CameraGetCurrent().SetPosition(position+[0,1.4,0]-direction);
SetCursorPos(0.5,0.5);
}
else
{
ShowCursor(FALSE);
obj_root.Hide();
CameraGetCurrent().SetPosition(position+[0,1.2,0]);
SetCursorPos(0.5,0.5);
ConsoleFont("Arial",25);
ConsoleText(0.496,0.5,"x");
}
}
function player::SetPosition(x,y,z)
{
position.x = x;
position.z = z;
position.y = y;
}
function player::GetPosition()
{
return position;
}
function player::GetDirection()
{
return direction;
}
function player::SetAngle(angle)
{
angleY += angle;
}
function player::GetAngle()
{
return angleY;
}
function player::SetShotDirection(direction)
{
shot_direction = direction;
}
function player::ChangeWeapon()
{
selected_weapon = (selected_weapon+1)%NUM_ARMI;
}
function player::GetWeapon()
{
return player_bullet[selected_weapon];
}