///////////////////////////////
#include <acknex.h>
#include <default.c>
/////////////////////////////////////////////////////
var video_mode = 8;
var video_depth = 32;
var video_screen = 2;
var fps_max = 125;
bmap bmp_toonlookup=<toonlookup.tga>;//that little grey scale image for toon shader
bmap bmp_crosshair= <crosshair.pcx>; // the bitmap used for crosshair
/////////////////////////////////////////////////////
//vector temp[3]; //vector gives ERROR, it says unknown keyword, ANGLE gives the same error, why?
Var movement_speed[3]; // player's movement speed, it was a vector too, but didnīt work.
var anim_percentage; // animation percentage
var jump_percentage; // animation percentage for jumping
var distance_to_ground; // the distance between player's origin and the ground
var jump_height;
var reached_height;
ANGLE bone_angle; // a vector that holds the pan, tilt and roll angles, i wanted this for rotate the modelīs head to always
//look at the crosshair, but it says that ANGLE is not a keyword, tought it works ok in the code from lite-c workshop 23.
//whatīs wrong with it?
//////////////////////////////////////////////////////
var camera_move_to[3];
var camera_distance = 200; //these are used for the Kingdom Hearts camera that i took from a tutorial.
var camera_pan;
var camera_tilt;
/////////////////////////////////////////////////////
material mtl_toon //it works fine no problems with this, (I think...)
{
skin1=bmp_toonlookup;
effect =
"
matrix matWorldViewProj;
matrix matWorld;vector vecSunDir;
texture entSkin1;texture mtlSkin1;
technique t0{
pass p0 // shade it
{
zwriteenable= true;
zenable = true;
Texture[0]=<mtlSkin1>;
ColorOp[0]=Modulate;
ColorArg1[0]=Texture;
ColorArg2[0]=Texture;
AddressU[0]=Clamp;
AddressV[0]=Clamp;
AddressW[0]=Clamp;
TexCoordIndex[0]=0;
Texture[1]=<entSkin1>;
ColorOp[1]=Modulate;
ColorArg1[1]=Texture;
ColorArg2[1]=Current;
TexCoordIndex[1]=1;
VertexShaderConstant[0] = <matWorldViewProj>;
VertexShaderConstant[4] = <matWorld>;
VertexShaderConstant[7] = <vecSunDir>;
VertexShader = asm
{
vs_1_0
dcl_position v0
dcl_normal v3
dcl_texcoord0 v7
dcl_texcoord1 v8
mov oT2.xy, v7
dp4 oPos.x, c0, v0
dp4 oPos.y, c1, v0
dp4 oPos.z, c2, v0
dp4 oPos.w, c3, v0
dp3 r0.x, c4.xyz, v3.xyz
dp3 r0.y, c5.xyz, v3.xyz
dp3 r0.z, c6.xyz, v3.xyz
dp3 oT0.x, r0.xyz, -c7.xyz
mov oT1.xyz, v8
};
}
pass p1 // ink it
{
CULLMODE=CW;
vertexShaderConstant[0]=<matWorldViewProj>;
vertexShaderConstant[16]=0.6; // outline thickness
vertexShader = asm
{
vs_1_0
dcl_position v0
dcl_normal v3
dcl_texcoord v7
mov r0,v0
mul r1,c16.x,v3
// Scale the normal
add r0.xyz,r0.xyz,r1.xyz
m4x4 oPos,r0,c0
// Transorm position to clip space
mov oD0, c0
mov r0,c0
};
}
}
";
}
action toon
{
my.material=mtl_toon; //to attach to the map models that need to be toon shaded. (i guess...)
}
//////////////////////////////////////////////////////
sky nebula_cube // a sky I took from an outdoors contest participantīs code. works great.
{
type = <sky_day2+6.tga>;
z = -10; // move it 10 pixels upwards
layer = 5;
flags = cube, visible;
}
//////////////////////////////////////////////////////
function main()
{
level_load ("testroom.wmb");
mouse_map = bmp_crosshair; // set the bitmap that is going to be used by the mouse pointer
mouse_mode = 1; // now show the pointer
while (1)
{
vec_set(mouse_pos, mouse_cursor); // update the mouse pointer position at all times
wait (1);
}
wait (3);
}
action skysphere_rotate
{
while(1)
{
vec_set(my.x, camera.x);
my.pan +=0.03 * time;
wait(1);
}
}
action post()
{my.polygon =on;
my.shadow = on;
my.material =mtl_toon; //just a test action for a map model, i want to make it "destroyable" later...
}
action Kuro() //the playerīs action, took from an AUM.
{
player = my; // I'm the player (nope, youīre just a model, the player is me!!)
my.polygon = on;
my.shadow = on;
while (1) //main loop
{
my.pan -= 12 * mouse_force.x * time_step; //to rotate the player with the mouse
vec_set (temp.x, my.x); // copy player's position to temp
temp.z -= 10000; // set temp.z 10000 quants below player's origin, is this gravity or what?
distance_to_ground = c_trace (my.x, temp.x, IGNORE_ME | USE_BOX);
movement_speed.x = 30 * (key_w - key_s) * time_step; // move the player using "W" and "S"
movement_speed.y = 25 * (key_a - key_d) * time_step; //strife with "A" and "D" so i can aim, shoot a rotate with the mouse!
////////////////////////////////////////////////////JUMP, from AUM//////////////////////////////////////////////////////////////////
if (key_space && !reached_height)
{
jump_height = minv(150, jump_height + 50 * time_step); // 150 sets the height, 50 sets the ascending speed
if (jump_height == 150) // reached the maximum height? Then start descending!
{
reached_height = 1;
jump_height = maxv(0, jump_height - 100 * time_step); // 100 sets the falling speed, shouldnīt be set by GRAVITY?
}
}
else // space isn't pressed anymore?
{
jump_height = maxv(0, jump_height - 30 * time_step); // use a smaller falling speed (3) for smaller jumps, nah, doesnīt work at all!
if (!jump_height && !key_space) // the player has touched the ground?
{
reached_height = 0; // then allow it to jump again
}
}
// ok, i like this but, the modelīs animation has some frames for landing that are not being shown when jumping, also
// iīd like if, when the model falls from some altitud, the model plays the "falling" frames from its jumping
// animation, i think it could be made scanning for the ground,and when it finds that the ground is far away, start
// playing jump from frame 3 to 4 or something like that...
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////Gravity
movement_speed.z = -(distance_to_ground - 0) + jump_height; // 0 = experimental value, (the z offset)
movement_speed.z = maxv(-30 * time_step, movement_speed.z); // 30 = falling speed (so why do i need falling speed on jumping code?)
c_move (my, movement_speed.x, nullvector, GLIDE); // move the player
if (!jump_height) // the player isn't jumping?
{
if (!key_w && !key_s) // the player isn't moving?
{
ent_animate(my, "stand", anim_percentage, ANM_CYCLE); // play the "stand" animation
anim_percentage += 2 * time_step; // 5 = animation speed
}
else // the player is moving?
{ ent_animate(me,NULL,0,0); //it is supposed to reset all bones, so i can ANM_ADD the shooting animation
//but i doesnīt work, the new bone angles are just added to the old ones.
ent_animate(my, "run", anim_percentage, ANM_CYCLE); // plays the "run" animation
anim_percentage += 8 * time_step; // 8 = animation speed
}
if (mouse_left == 1)// press mouse left?
{
ent_Animate(my,"attack", 4* time_step,ANM_ADD); //it makes a total mess! īcause the the new angles are added,
//i know that i have to reset all the animations somewere in the
//loop but Iīve tried in many places and doesnīt work, where could it be?
}
else {}
//anim_percentage += 10 * time_step; // 10 = animation speed (I have no idea of this line, i think it gives a common speed for all the animations)
jump_percentage = 0; // always start jumping with the first frame (yeah, but it should end in the last frame too. like
// player has landed? ent_animate the last two frames of "jump" HOW CAN I DO THAT?)
}
else // the player is jumping
{
jump_percentage += 5 * time_step; // 5 = jump animation speed
ent_animate(my, "jump", jump_percentage, ANM_CYCLE); // play the "jump" animation
}
if (key_C)// press duck?
{
ent_animate(my,"duck", anim_percentage, ANM_CYCLE); //play "duck" ani but it looks weird īcause the transition is
//too violent, how can i blend between animations to get smooth
//transitions?
}
else {}
//these are some camera codes iīm trying, i really like the smooth camera collision wich is a mod of Kingdom Hearts tutorial.
//in fact the only mod is that the camera follows the model from behind.
//the problem here is that the camera moves INSIDE the ground when the character is near a wall and the camera has to move
//between the model and the wall, and i need to move the camera position UP, īcause i canīt see the sky, it works neat on the
//tutorial level, but here... >_<
camera.pan -= mouse_force.x * 12 * time;
camera.tilt += mouse_force.y * 8 * time;
camera.tilt = clamp(camera.tilt,-30,3);
temp = fcos(camera.tilt,-camera_distance);
vec_set(camera.x,vector(my.x + fcos(camera.pan,temp),my.y + fsin(camera.pan,temp),my.z + 20 + fsin(camera.tilt,-camera_distance)));
vec_diff(temp.x,camera.x,my.x); //find the vector from the player to the camera
vec_normalize(temp.x,16); //get the magnitude of it's vector to 16 quants and store it in temp
vec_add(temp.x,camera.x); //add the vector (from player to camera) of a magnitude of 16 quants and add it to the camera's position.
trace_mode = ignore_me+ignore_passable+ignore_models;
result = trace(my.x,temp.x); //trace from the player to 16 quants behind the camera.
IF (result > 0) {
vec_diff(temp.x,my.x,target.x); //find the vector from the point the trace hit to the player
vec_normalize(temp.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,temp.x); //move the camera away from the wall by the vector temp, 16 quants towards the player
}
wait (1);}
//////////////////////////////
//Smooth camera collision
//////////////////////////////
// camera_pan -= mouse_force.x * 12 * time;
// camera_tilt += mouse_force.y * 8 * time;
// camera_tilt = clamp(camera_tilt,-30,30);
//
// camera.pan = camera_pan;
// temp = fcos(camera_tilt,-camera_distance);
// vec_set(camera_move_to.x,vector(my.x + fcos(camera.pan,temp),my.y + fsin(camera.pan,temp),my.z + 20 + fsin(camera_tilt,-camera_distance)));
//
//
//
// temp = min(1,0.5 * time); //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*(camera_move_to.x - camera.x);
// camera.y += temp*(camera_move_to.y - camera.y);
// camera.z += temp*(camera_move_to.z - camera.z);
//
// vec_diff(temp.x,camera.x,my.x);
// vec_normalize(temp.x,16);
// vec_add(temp.x,camera.x);
//
// trace_mode = ignore_me + ignore_passable + ignore_models;
// IF (trace(my.x,temp.x) > 10) {
// vec_diff(temp.x,my.x,target.x);
// vec_normalize(temp.x,16);
// vec_set(camera.x,target.x);
// vec_add(camera.x,temp.x);
// }
//
// vec_diff(temp.x,my.x,camera.x);
// vec_to_angle(camera.pan,temp.x);
// wait (1);
//}
// camera code, very simple iīd prefer the one above.
// camera.x = player.x - 300 * cos(player.pan); // 90 = distance
//
// camera.y = player.y - 300 * sin(player.pan); // same value here
//
// camera.z = player.z + 60; // above the player
//
// camera.pan = player.pan ;
//
// camera.tilt += mouse_force.y * 8 * time;//mouse tilt
//
// camera.roll = 0;
//
// wait (1);
//
// }
}