#ifndef player_c
#define player_c
/////
//
//
#define nullframe -2
#define blend -1
#define stand 0
#define run 1
#define walk 2
#define jump 3
#define fall 4
#define attack_a 5
#define attack_b 6
#define attack_c 7
#define attack_d 8
#define attack_e 9
#define attack_f 10
TEXT* pl1_tAnim = {
strings = 32;
string = "stand";
string = "run";
string = "walk";
string = "jump";
string = "fall";
string = "attack_a";
string = "attack_b";
string = "attack_c";
string = "attack_d";
string = "attack_e";
string = "attack_f";
}
var pl1_aAnimMode[32];
var pl1_aAnimSp[32];
#define jmp0 0
#define jmp1 1
#define jmp2 2
#define jmp3 3
#define jmp10 10
#define mv0 0
#define mv1 1
#define mv2 2
//
#define _moveX skill22
#define _moveY skill23
#define _moveZ skill24
#define force_x skill25
#define force_y skill26
#define force_z skill27
#define velocity_x skill28
#define velocity_y skill29
#define velocity_z skill30
#define _ani1 skill31
#define _ani2 skill32
#define _aniBlend skill33
#define currentframe skill34
#define blendframe skill35
#define z_offset skill50
#define _jmp skill51
#define _gravity skill52
#define _mv skill53
#define _moving skill54
#define hit_by_player skill55
#define entity_type skill56
#define _ht skill57
ENTITY* pl1_eWp1;
ENTITY* pl1_eTargetEnemy;
var pl1_nAirAttack = 0;
var pl1_nComboNext = 0;
var pl1_nLockOn = 0;
VECTOR* cam_vMoveTo = { x=0; y=0; z=0; }
var cam_nDist = 200;
var cam_nPan;
var cam_nTilt;
//
var in_space = 0;
var in_mouseL = 0;
var in_mouseR = 0;
//
VECTOR* v1 = { x=0; y=0; z=0; }
VECTOR* v2= { x=0; y=0; z=0; }
ANGLE* angle1 = { pan=0; tilt=0; roll=0; }
ANGLE* angle2= { pan=0; tilt=0; roll=0; }
//
//
var c_nResult = 0;
var c_nRotate = 2;
STRING* wp1_md1 = "sword.mdl";
function pl1f_anim(var animation_speed);
function cf_rotate1(var _nAngle, var _nSp);
function cf_rotate2(var _angle, var _speed);
action wpa_1() {
pl1_eWp1 = me;
set(my,PASSABLE);
proc_mode = PROC_LATE;
while(you!=NULL) {
vec_for_vertex(v1.x, you, 1175); //hand palm base
vec_for_vertex(v2.x, you, 1240); //hand palm tip
vec_set(my.x, v1.x);
vec_diff(v1.x, v2.x, v1.x);
vec_to_angle(angle1.pan, v1.x);
vec_set(my.pan, angle1.pan);
wait(1);
}
}
/******************************
pl1f_animE
*******************************/
function pl1f_animE(var _index, STRING* _name, var _mode, var _speed) {
str_cpy((pl1_tAnim.pstring)[_index], _name);
pl1_aAnimMode[_index] = _mode;
pl1_aAnimSp[_index] = _speed;
}
/******************************
pl1f_animInit
*******************************/
function pl1f_animInit() {
pl1f_animE(stand, "stand", ANM_CYCLE, 5);
pl1f_animE(run, "run", ANM_CYCLE, 8);
pl1f_animE(walk, "walk", ANM_CYCLE, 8);
pl1f_animE(jump, "jump", 0, 10);
//plf_animE(fall, "fall", 0,
pl1f_animE(attack_a, "attack_a", 0, 20);
pl1f_animE(attack_b, "attack_b", 0, 15);
pl1f_animE(attack_c, "attack_c", 0, 10);
pl1f_animE(attack_d, "attack_d", 0, 15);
pl1f_animE(attack_e, "attack_e", 0, 15);
pl1f_animE(attack_f, "attack_f", 0, 6);
}
/******************************
pl1f_move
*******************************/
function pl1f_move() {
v1.x = -1000;
v1.y = 0;
my._moving = 0;
if (key_w == 1 && key_s == 0 && key_a == 0 && key_d == 0) { v1.x = camera.pan; }
if (key_s == 1 && key_w == 0 && key_a == 0 && key_d == 0) { v1.x = camera.pan + 180; }
if (key_a == 1 && key_s == 0 && key_w == 0 && key_d == 0) { v1.x = camera.pan + 90; }
if (key_d == 1 && key_s == 0 && key_a == 0 && key_w == 0) { v1.x = camera.pan - 90; }
if (key_w == 1 && key_a == 1 && key_d == 0 && key_s == 0) { v1.x = camera.pan + 45; }
if (key_w == 1 && key_d == 1 && key_a == 0 && key_s == 0) { v1.x = camera.pan - 45; }
if (key_s == 1 && key_a == 1 && key_d == 0 && key_w == 0) { v1.x = camera.pan + 135; }
if (key_s == 1 && key_d == 1 && key_a == 0 && key_w == 0) { v1.x = camera.pan - 135; }
if (v1.x != -1000) {
my._moving = 1;
if (key_shift == 1) {
v1.y = 10 * time_step;
} else {
v1.y = 15 * time_step;
}
}
if (my._mv == mv0) {
my._moveX = fcos(v1.x,v1.y);
my._moveY = fsin(v1.x,v1.y);
}
if (my._mv == mv1 || my._mv == mv2) {
v1.y = fsin((my._ani1 * 1.2) + 45,15 * time_step);
my._moveX = fcos(my.pan,v1.y);
my._moveY = fsin(my.pan,v1.y);
v1.y = 0;
if (v1.x != -1000) { v1.y = 1; } //if we need to rotate whilst attacking (the player is pressing keys to rotate)
}
//
c_move(me,nullvector,my._moveX, USE_AABB|IGNORE_PASSABLE|GLIDE);
//
//result = trace(vector(my.x,my.y,my.z - my.z_offset),vector(my.x,my.y,my.z - 4000));
//if (result < 0) { my.z -= result; my.velocity_z = 0; }
if (pl1_eTargetEnemy == NULL) {
if (v1.y > 0) { cf_rotate1(v1.x,30); }
} else {
vec_diff(v2.x,pl1_eTargetEnemy.x,my.x);
vec_to_angle(angle2.pan,v2.x);
cf_rotate1(angle2.pan,30);
}
//
switch(my._mv) {
case mv0:
my._gravity = 6;
if (my._moveX != 0 || my._moveY != 0) { //if we are moving
if (my._aniBlend == stand) {//if our current animation is stand
if (key_shift == 1) {
my.blendframe = walk;
} else {
my.blendframe = run;
}
}
if (my._aniBlend == run && key_shift == 1) { my.blendframe = walk; }
if (my._aniBlend == walk && key_shift == 0) { my.blendframe = run; }
} else {
//if we arn't moving and our current animation is walk or run, blend and cycle the stand animation
if (my._aniBlend > stand
&& my._aniBlend != jump
&& my._aniBlend != fall) {
my.blendframe = stand;
}
}
if (mouse_left == 0 && in_mouseL == 1) { in_mouseL = 0; }
if (mouse_left == 1
&& in_mouseL == 0
&& my._aniBlend >= stand) {
in_mouseL = 1;
my.blendframe = attack_a;
pl1_nAirAttack = (my._jmp == jmp1);
my._mv = 1;
pl1_nComboNext = 0;
}
if (mouse_right == 0 && in_mouseR == 1) { in_mouseR = 0; }
if (mouse_right == 1 && in_mouseR == 0) {
if (pl1_nLockOn == 0) {
c_scan(player.x,player.pan,vector(360,180,250),SCAN_ENTS|SCAN_LIMIT|IGNORE_ME);
if (you != NULL) {
if (you.entity_type == 2) {//make sure you've scanned an enemy
pl1_nLockOn = 1;
pl1_eTargetEnemy = you;
}
}
} else {
pl1_nLockOn = 0; pl1_eTargetEnemy = NULL;
}
in_mouseR = 1;
}
break;
case mv1:
if (my._jmp != jmp10) {
my._jmp = jmp0;
} else if((my._ani1 >= 60)
&&(my._aniBlend >= stand)) {
my._jmp = jmp0;
}
if(mouse_left == 0 && in_mouseL == 1) { in_mouseL = 0; }
if(mouse_left == 1
&& in_mouseL == 0
&& my._ani1 >= 30
&& pl1_nComboNext == 0) {
in_mouseL = 1;
pl1_nComboNext = 1;
}
break;
case mv2:
my._jmp = jmp0;
if(mouse_left == 0 && in_mouseL == 1) { in_mouseL = 0; }
if(mouse_left == 1
&& in_mouseL == 0
&& my._ani1 >= 30
&& pl1_nComboNext == 0) {
in_mouseL = 1;
pl1_nComboNext = 1;
}
break;
}
}
/******************************
pl1f_gravity
*******************************/
function pl1f_gravity() {
//c_nResult = c_trace(vector(my.x,my.y,my.z - my.z_offset),vector(my.x,my.y,my.z - 1000),IGNORE_ME|IGNORE_PASSABLE|USE_POLYGON);
my._ht = c_trace(vector(my.x,my.y,my.z - my.z_offset),vector(my.x,my.y,my.z - (my.z_offset * 2)),IGNORE_ME|IGNORE_PASSABLE|USE_POLYGON);
my._ht += (trace_hit == 0 && my._ht == 0) * my.z_offset * 2;
//spof_n1("ht: ", my._ht);
if(my._ht < 3) {
//if(c_nResult < 0) { c_nResult = c_trace(my.x,vector(my.x,my.y,my.z + 4000),IGNORE_ME|IGNORE_PASSABLE|USE_POLYGON); }//!!FUDGE!! stop skyjumping
//
if(my._jmp==jmp0) {
my.force_z = -1 * my._ht;
if((key_space==0) && (in_space==1)) { in_space = 0; }
if((key_space==1)
&& (in_space==0)
&& (my._mv==mv0)
&& (my._aniBlend>=stand)
&& (my._aniBlend!=jump)
&& (my._aniBlend!=fall)) {
in_space = 1;
my._jmp = jmp1;
my.force_z = 25;
my.blendframe = jump;
my._ani2 = 0;
my._aniBlend = blend;
}
}
if((my._jmp==jmp2) || (my._jmp==jmp3)) { my._jmp = jmp0; }
} else {
if(my._jmp==jmp2) {
if(my._ht > 120) {
my._ani1 = 60;
my._jmp = jmp3;
} else {
my._jmp = jmp0;
}
}
if((my._jmp==jmp3) && (my._ht <=120)) { my._jmp = jmp0; }
if((my._jmp==jmp0) && (my._mv==0)) {
if((my._ht > 120)
&& (my._aniBlend>=stand)
&& (my._aniBlend!=jump)
&& (my._aniBlend!=fall)) {
my._jmp = jmp3;
my.blendframe = fall;
my._ani2 = 0;
my._aniBlend = blend;
}
}
my.force_z -= my._gravity * time_step;
my.force_z = maxv(-30,my.force_z);
if(my._mv==mv2) { my.force_z = 0; }
}
my.velocity_z += (time_step * my.force_z) - (minv(time_step*0.7,1) * my.velocity_z);
my._moveZ = my.velocity_z * time_step;
}
/******************************
pl1f_cam1
Stable/rigid camera collision
*******************************/
function pl1f_cam1() {
camera.pan -= mouse_force.x * 12 * time_step;
camera.tilt += mouse_force.y * 8 * time_step;
camera.tilt = clamp(camera.tilt,-30,10);
angle1.pan = fcos(camera.tilt,-cam_nDist);
vec_set(camera.x,vector(my.x + fcos(camera.pan,angle1.pan),my.y + fsin(camera.pan,angle1.pan),my.z + 20 + fsin(camera.tilt,-cam_nDist)));
vec_diff(v1.x,camera.x,my.x); //find the vector from the player to the camera
vec_normalize(v1.x,16); //get the magnitude of it's vector to 16 quants and store it in temp
vec_add(v1.x,camera.x); //add the vector (from player to camera) of a magnitude of 16 quants and add it to the camera's position.
c_nResult = c_trace(my.x,v1.x,IGNORE_ME|IGNORE_PASSABLE|IGNORE_MODELS);
if(c_nResult > 0) {
vec_diff(v1.x,my.x,target.x); //find the vector from the point the trace hit to the player
vec_normalize(v1.x,16); //get the magnitude of this vector to 16 quants and store in temp
vec_set(camera.x,target.x); //place the camera at the trace hit point
vec_add(camera.x,v1.x); //move the camera away from the wall by the vector temp, 16 quants towards the player
}
}
/******************************
pl1f_cam2
Smoother camera collision
not used
*******************************/
function pl1f_cam2() {
cam_nPan -= mouse_force.x * 12 * time_step;
cam_nTilt += mouse_force.y * 8 * time_step;
cam_nTilt = clamp(cam_nTilt,-30,10);
camera.pan = cam_nPan;
angle1.pan = fcos(cam_nTilt,-cam_nDist);
vec_set(cam_vMoveTo.x,vector(my.x + fcos(camera.pan,angle1.pan),my.y + fsin(camera.pan,angle1.pan),my.z + 20 + fsin(cam_nTilt,-cam_nDist)));
var temp = minv(1,0.5 * time_step); //changing 0.5 will change how fast the camera moves, at 1 places us at target, this value is what allows the smooth movement
camera.x += temp*(cam_vMoveTo.x - camera.x);
camera.y += temp*(cam_vMoveTo.y - camera.y);
camera.z += temp*(cam_vMoveTo.z - camera.z);
vec_diff(v1.x,camera.x,my.x);
vec_normalize(v1.x,16);
vec_add(v1.x,camera.x);
if (c_trace(my.x,v1.x,IGNORE_ME|IGNORE_PASSABLE|IGNORE_MODELS) > 0) {
vec_diff(v1.x,my.x,target.x);
vec_normalize(v1.x,16);
vec_set(camera.x,target.x);
vec_add(camera.x,v1.x);
}
vec_diff(v1.x,my.x,camera.x);
vec_to_angle(camera.pan,v1.x);
}
/******************************
cf_rotate1
*******************************/
function cf_rotate1(var _nAngle, var _nSp) {
if (c_nRotate == 2) { cf_rotate2(_nAngle, _nSp); }
if(my.pan == _nAngle) { return; }
c_nResult = ang(_nAngle - my.pan);
if (c_nResult > 0) my.pan += _nSp * time_step;
if (c_nResult < 0) my.pan -= _nSp * time_step;
if ((ang(_nAngle - my.pan) < 0) && (c_nResult > 0)) { my.pan = _nAngle; }
if ((ang(_nAngle - my.pan) > 0) && (c_nResult < 0)) { my.pan = _nAngle; }
}
/******************************
cf_rotate2
uses c_rotate
not currenty used
*******************************/
function cf_rotate2(var _angle, _speed) {
if (my.pan == _angle) { return; }
c_nResult = ang(_angle - my.pan);
angle1.pan = minv(abs(c_nResult), time_step * _speed) * sign(c_nResult);
angle1.tilt = 0;
angle1.roll = 0;
c_rotate(me, angle1, IGNORE_ME | IGNORE_PASSABLE);
}
//
/******************************
wp1f_collide
*******************************/
function wp1f_collide() {
you = NULL;
vec_for_vertex(v1.x, pl1_eWp1,274); //sword base
vec_for_vertex(v2.x,pl1_eWp1, 54); //sword tip
c_nResult = c_trace(v1.x,v2.x,IGNORE_ME|IGNORE_PASSABLE|USE_BOX);
if (you != NULL) {
if ((you.entity_type == 2) && (you.hit_by_player == 0)) {
if (pl1_nAirAttack == 1 && my._aniBlend == attack_a) { my._mv = mv2; }
you.hit_by_player = 1;
if (pl1_eTargetEnemy == NULL) {
pl1_eTargetEnemy = you;
pl1_nLockOn = 1;
}
}
}
}
/******************************
pl1a1
*******************************/
action pl1a1() {
pl1f_animInit();
c_setminmax(me); //added to correct ground collisions
wait(1); //added to correct ground collisions
player = me;
my._gravity = 6;
my.z_offset = -my.min_z; //was 6 //added to correct ground collisions
set(my,SHADOW);
ent_create(wp1_md1, my.x, wpa_1);
wait(1);
while(me != NULL) { //the main loop
pl1f_gravity();
pl1f_move();
pl1f_anim(1);
pl1f_cam1();
wait(1);
}
}
#endif