#include <acknex.h>
#include <default.c>
ENTITY* Player1;
ENTITY* ent;
var flashlight = 0; // dunno how to do :(
var bullets = 30;
var shotDelay;
BMAP* Crosshair = "crosshair.pcx";
BMAP* weapon = "images\flare0.pcx";
BMAP* bmpAmmo = "images\ammo_hud.tga";
PANEL* mostrar =
{
digits(5, 5, 5, *, 1, camera.tilt);
digits(70, 515, 5, "Arial#40b", 1, bullets);
layer = 100;
flags = SHOW;
}
PANEL* displayBullets =
{
pos_x = 5;
pos_y = 500;
bmap = bmpAmmo;
layer = 1;
flags = SHOW;
}
PANEL* displayCrosshair =
{
pos_x = 400;
pos_y = 300;
bmap = Crosshair;
flags = SHOW | OVERLAY;
}
PANEL* showWeapon =
{
pos_x = 0;
pos_y = 300;
bmap = weapon;
flags = SHOW | OVERLAY;
}
void updateCam(ENTITY* ent)
{
while(1)
{
camera.x = ent.x;
camera.y = ent.y;
camera.z = ent.z;
camera.z += 75;
camera.pan = ent.pan;
camera.tilt += mouse_force.y*9*time_step;
if (camera.tilt > 90)
{
camera.tilt = 90;
}
else if (camera.tilt < -60)
{
camera.tilt = -60;
}
wait(1);
}
}
action playerMovement()
{
//Parameter
var movespeed = 70.0/16.0;
var turnspeed = 10;
var fallacc = 3.68; // "Gravedad"
var jumpacc = 20;
//Animations
var anim_percent = 0;
var attack_percent = 0;
var stand_percent = 0;
//Temporäres
VECTOR movedir;
vec_set(movedir, vector(0, 0, 0));
ANGLE rotdir;
vec_set(rotdir, vector(0, 0, 0));
var grounddist;
//Ermitteln der Playerhöhe
c_setminmax(my);
wait(1);
var feedheight = -my.min_z;
//Anpassen der Boundingbox
my.min_x *= 0.7;
my.min_y *= 0.8;
my.min_z = 0;
my.max_x *= 0.7;
my.max_y *= 0.8;
my.max_z *= 0.8;
//move_friction = 0.5;
//Starten der Kamerafunktionen
updateCam(my);
proc_mode = PROC_EARLY;
while(1)
{
//Abfrage der Tasteneingaben
movedir.x = (key_w-key_s)*(1+key_shift*2);
if (key_w || key_s)
{
anim_percent += 2* movedir.x % 100; // 1.3 = walk cycle percentage per quant
ent_animate(me,"run",anim_percent,ANM_CYCLE); // play the "walk" animation
}
movedir.y = (key_a-key_d * 1.5) * (1 + key_shift);
if (key_a || key_d)
{
anim_percent += 2* movedir.y % 100; // 1.3 = walk cycle percentage per quant
ent_animate(me,"run",anim_percent,ANM_CYCLE); // play the "walk" animation
}
//Abfrage der Mausbewegung
rotdir.pan = -mouse_force.x;
//Berechnen der Laufgeschwindigkeit
movedir.x *= movespeed*time_step;
movedir.y *= movespeed*time_step;
//Berechnen der Bewegungsgeschwindigkeit
rotdir.pan *= turnspeed*time_step;
//Rotieren und Bewegen
vec_add(my.pan, rotdir);
c_move(my, vector(movedir.x, movedir.y, 0), nullvector, GLIDE|IGNORE_PASSABLE);
//Check der Distanz zum Boden
grounddist = c_trace(my.x, vector(my.x, my.y, my.z-10000), IGNORE_ME|IGNORE_PASSABLE)-feedheight;
if(grounddist > 0 || movedir.z < 0)
{
//Fallbeschleunigung
movedir.z += fallacc*time_step;
}else
{
movedir.z = 0;
}
//Anwenden der Fallbeschleunigung
my.z -= minv(movedir.z*time_step, grounddist);
if(grounddist-minv(movedir.z*time_step, grounddist) == 0)
{
//Springen
if(key_space)
{
movedir.z = -jumpacc;
}
}
if (mouse_left && bullets > 0 && shotDelay == 0)
{
attack_percent += 15 * time_step % 100;
ent_animate(me,"attack",attack_percent,ANM_CYCLE); // play the "walk" animation
bullets --;
shotDelay = 4;
}
wait(1);
if (key_f)
{
if (flashlight == 0) flashlight = 1;
else flashlight = 0;
}
/*if (flashlight == 1)
{
vec_set(sun_color, vector(0,0,255));
sun_light = 1;
sun_pos.x = Player1.x;
sun_pos.x = Player1.y;
sun_pos.z = Player1.z + 15;
sun_angle.pan = Player1.pan;
sun_angle.tilt = camera.tilt;
ent.x = Player1.x;
ent.y = Player1.y;
ent.z = Player1.z;
ent.pan = camera.pan;
ent.tilt = camera.tilt;
}
else
{
sun_light = 0;
sun_pos.z = -99999;
}*/
if (!key_any) ent_animate(me,"run", 0, ANM_CYCLE); // play the "walk" animation
if (shotDelay > 0) shotDelay --;
}
}
function main()
{
video_mode = 7;
video_depth = 16;
video_screen = 1;
shadow_stencil = 4;
d3d_autotransparency = 1;
d3d_antialias = 4;
level_load("level.wmb");
ent_createlayer("skycube+6.dds", SKY | CUBE | SHOW, 0);
wait(3);
Player1 = ent_create("gangst2.mdl", vector(0, 50, 0), playerMovement);
ph_setgravity(vector(0,0,-368));
}