/*
-------------------------------------------------------
---=[ phXhero.c ]=-------------------------------------
-------------------------------------------------------
lite-C A8 example of "hero / player - controller" using
"PhysX engine" featuring vertex / frame / bone based
animations + simple "die and blend out" - script
note: all cam stuff is optional of course
-------------------------------------------------------
free contribution quick written by rayp 04.2015 germany
-------------------------------------------------------
*/
#define animation_frame skill10 // animation percentage 0 - 100
#define health skill11 // health points
#define speed skill12 // ent's - speed factor * time_step = movement speed ( see mov_dist )
ENTITY* myplayer; // ent pointer holding "hero aka player"
VECTOR mov_dist; // player is moved via this vector mov_dist.x / mov_dist.y ( use WASD )
STRING* str_walk = "walk"; // framenames of animation ( open MED 2see them 4ex, guess u know :D )
var cam_mode = 0; // 0 = player visible, 1 = invisible ( FPS-mode 4ex ).
void _mostbasicFPScam(){
proc_mode = PROC_LATE; // maybe not. pls try.
my.pan += (mickey.x * 0.5) * time_step;// if cam-movment sucks swap X and Y of mickey for pan and tilt vectors!
my.tilt += (mickey.y * 0.5) * time_step;// ...as said above ... uneed2 test it
vec_set (camera.pan, my.pan);
vec_set (camera.x, my.x);
if ( cam_mode && !is (my, INVISIBLE)) set (my, INVISIBLE);
if (!cam_mode && is (my, INVISIBLE)) reset (my, INVISIBLE);
}
action playerWED(){
my.health = 100; // player starts with 100 health points
my.speed = 2; // movement speed
pXent_settype (me, PH_CHAR, PH_CAPSULE); // register ent as physic object ... used it only one time, maybe change to PH_BOX?
// change bbox here if u want ( be4 the while! ) or something like:
// c_setminmax (me);
// set (my, POLYGON); // or use vec_set min / max stuff see manual
// wait (1); // use if u changed bbox be4
myplayer = me; // pointer to our hero ( u can use "player" instead )
//my.frame = Startframe of walking-anm; // if using frame - anm
while (my){
// --------------------------------------------------------------------------------------------------------
// ---=[ physic - movement - part ]=-----------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------
mov_dist.x = (my.speed * (key_w - key_s)) * time_step; // prepare players X movement- ( WASD ) vector...
mov_dist.y = (my.speed * (key_a - key_d)) * time_step; // ...same4 Y of course!
//mov_dist.z <- guess we dont need2 use ... only used physics one time, as i wrote already above
pXent_movechar (me, mov_dist, NULL, 0); // finally move the player entity with our mov_dist - vector!
// --------------------------------------------------------------------------------------------------------
// ---=[ animation part ( vertex and bone ) ]=-------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------
my.animation_frame += time_step * my.speed; // animate time corrected in (my.)speed
my.animation_frame %= 100; // 0 - 100 ( if anm "flickers" try without this line )
ent_animate (me, str_walk, my.animation_frame, ANM_CYCLE); // finally ... cycle - animate me
// ---=[ oldschool frame animation ... animates smooth from frame 20 to 30 ]=------------------------------
/*
my.frame += time_step * my.speed;
if (my.frame > 30) my.next_frame = 20; // interpolate2 start frame...
else my.next_frame = 0; // ...interpolate again
if (my.frame >= 31) my.frame -= 10; // 30 - 10 = 20 :D
*/
if (my.health <= 0) break; // no health? die!
_mostbasicFPScam(); // xtreme simple cam-handle function ( cam_mode = 1 means player is INVISIBLE )
wait (1);
}
// new school anm style again
my.animation_frame = 0; // using frames? then take my.frame = Start frame;
while (my.animation_frame < 100){
my.animation_frame += time_step * 4;
ent_animate (me, "die", my.animation_frame, NULL);
wait (1);
}
// end of new school anm die part...if you wanna use oldschool stuff:
// copy n paste vertex - frame - stuff from above, delete my.animation_frame=0+the while, adjust frame numbers = done!
set (my, TRANSLUCENT | PASSABLE);
my.alpha = 100; while (my.alpha > 0) { my.alpha -= time_step; wait (1); } // TRANSLUCENT and while = optional of course
wait (1);
ptr_remove (me);
}