#include "RakGS.h"
#include <acknex.h>
#include <default.c>
FONT* arial_font = "Arial#20";
TEXT* messages_txt =
{
pos_x = 10;
pos_y = 10;
layer = 10;
font(arial_font);
string (messages_str);
flags = visible;
}
//---------------------------------------------------------------------------------------------||
// some global vars, defines...
//---------------------------------------------------------------------------------------------||
#define force_x skill1
#define force_y skill2
#define force_z skill3
#define force_pan skill4
#define MAX_CONNECTIONS 8
VECTOR camVel;
var force[3];
var vecFrom[3];
var vecTo[3];
var people_connected;
var player_number;
//---------------------------------------------------------------------------------------------||
// function prototypes
//---------------------------------------------------------------------------------------------||
function playerAct();
function inputs();
//---------------------------------------------------------------------------------------------||
// main function
//---------------------------------------------------------------------------------------------||
function main()
{
video_mode = 8;
video_depth = 32;
video_screen = 2;
fps_max = 60; // lock fps at 60 for all players
fps_lock = ON;
dplay_smooth = 0; // dplay_smooth is causing too much overshoot and jerks
wait(-.3);
if(connection == 3){
people_connected = 1;
str_cpy(messages_str, "Connected as a HOST...");
}
if(connection == 2){
people_connected += 1;
send_var(people_connected);
str_cpy(messages_str, "Connected as a CLIENT...");
}
level_load("test.wmb");
wait(-.3);
player = ent_create("aim.mdl", vector(0,0,100), playerAct);
wait(-.3);
inputs();
while(!player)
{
wait(1);
}
}
//---------------------------------------------------------------------------------------------||
// function for handling inputs
//---------------------------------------------------------------------------------------------||
function inputs()
{
while(1){
player.force_x = (key_w - key_s) * time_step * 15;
player.force_y = (key_a - key_d) * time_step * 15;
player.force_pan -= mouse_force.x * 15 * time_step;
if(connection == 2){
send_skill(player.force_x, SEND_VEC);
send_skill(player.force_pan, 0);
}
wait(1);
}
}
//---------------------------------------------------------------------------------------------||
// move player function
//---------------------------------------------------------------------------------------------||
function movePl()
{
while(1){
my.pan = my.force_pan;
force[0] = my.force_x * 15 * time_step;
force[1] = my.force_y * 10 * time_step;
force[2] = 0;
move_mode = GLIDE|IGNORE_PASSABLE|IGNORE_PASSENTS|IGNORE_YOU;
c_move(my, force, nullvector,move_mode);
// scan for floor if we are moving
if (my.force_x || my.force_y || my.force_z)
{
//Scan floor
trace_mode = IGNORE_SPRITES|IGNORE_PASSENTS|IGNORE_PASSABLE|IGNORE_MODELS|USE_BOX;
vec_set(vecFrom,my.x);
vec_set(vecTo,my.x);
vecTo[2] -= 400;
result = c_trace(vecFrom,vecTo,trace_mode);
my.z = target.z + ((my.max_z - my.min_z)/2);//Set to the floor
}
wait(1);
}
}
//---------------------------------------------------------------------------------------------||
// player action
//---------------------------------------------------------------------------------------------||
action playerAct()
{
my.emask |= ENABLE_DISCONNECT;
my.smask |= NOSEND_FRAME;
c_setminmax(my);
wait(-3);
ent_sendnow(my);
wait(-3);
movePl();
}