Serious User
Joined: Nov 2007
Posts: 1,032
Croatia
|
i don't know if you saw my previous post...but anyway i'll post my code here: game.c
#include <acknex.h>
#include <default.c>
#include "status.c"
#include "windows.h"
#include "d3d9.h"
//---------------------------------------------------------------------------------------------||
// 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];
//---------------------------------------------------------------------------------------------||
// function prototypes
//---------------------------------------------------------------------------------------------||
void playerAct();
void inputs();
void server_called();
void client_called();
void donothing(){wait(1);}
//---------------------------------------------------------------------------------------------||
// main function
//---------------------------------------------------------------------------------------------||
int 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
on_server = server_called; // on server event, call server_called()
on_esc = donothing;
wait(-.3);
if(connection == 3){
people_connected = 1;
str_cpy(messages_str, "Connecting as a HOST...");
wait(-3);
reset(messages_txt, VISIBLE);
set(connected, VISIBLE);
set(status, VISIBLE);
video_window(NULL,NULL,16,"HOST...");
}
if(connection == 2){
str_cpy(messages_str, "Connecting as a CLIENT...");
wait(-3);
reset(messages_txt, VISIBLE);
set(connected, VISIBLE);
set(status, VISIBLE);
video_window(NULL,NULL,16,"CLIENT...");
}
level_load("test.wmb");
wait(-.3);
player = ent_create("aim.mdl", vector(0,0,100), playerAct);
wait(-.3);
inputs();
while(1)
{
again:
// constantly checks if server is still online
if(dplay_bps == 0 && dplay_latency == 0 && connection == 2) {
if (MessageBox(NULL, "Server is offline and the game will shutdown.", "Error", MB_OK | MB_ICONSTOP) == IDOK){
sys_exit(NULL);
}
}
if(key_esc){
while(key_esc){wait(1);}
if(MessageBox(NULL, "Do you really want to quit?", "Quit?", MB_YESNO | MB_ICONQUESTION) == IDYES){sys_exit(NULL);}
else{wait(1);goto again;}
}
wait(1);
}
}
//---------------------------------------------------------------------------------------------||
// function for handling inputs
//---------------------------------------------------------------------------------------------||
void 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
//---------------------------------------------------------------------------------------------||
void 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);
if (my.force_x || my.force_y || my.force_z)
{
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);
set(me, SHADOW);
movePl();
}
//---------------------------------------------------------------------------------------------||
// function Server_Called(): server was called
//---------------------------------------------------------------------------------------------||
void server_called()
{
if ((event_type == EVENT_JOIN) && (people_connected < MAX_CONNECTIONS))
{
people_connected += 1; // another person connected
send_var(people_connected); // send number of people connected
}
if (event_type == EVENT_LEAVE)
{
people_connected -= 1; // one less person connected to server
send_var(people_connected); // send number of people connected
}
}
//--------------------------------------------------------------------
// player events
//--------------------------------------------------------------------
void player_events()
{
if (event_type == EVENT_DISCONNECT)
{
ent_remove(me); // remove ent of player that quit
}
}
status.c
STRING* messages_str = "#50";
var people_connected;
#define player_number skill20
var number_of_players;
FONT* arial_font = "Arial#20";
TEXT* messages_txt =
{
pos_x = 400;
pos_y = 300;
layer = 10;
font(arial_font);
string (messages_str);
flags = visible;
}
PANEL* connected =
{
pos_x = 10; pos_y = 10;
digits(0,0,"People connected: %.f",arial_font,1,people_connected);
digits(0,20,"Player name: %s",arial_font,1,player_name);
}
PANEL* status =
{
pos_x = 10; pos_y = 10;
digits(800,0,"x: %.1f",arial_font,1,player.x);
digits(800,20,"y: %.1f",arial_font,1,player.y);
digits(800,40,"z: %.1f",arial_font,1,player.z);
digits(800,60,"pan: %.1f",arial_font,1,player.pan);
}
you'll need d3d9.h and windows.h header files in that projet folder one more time, try what i told you in my post two posts before this one , try forwarding 2300 port...
Last edited by cerberi_croman; 07/01/08 14:50.
Ubi bene, ibi Patria.
|