added score and time limit. cleaned up the code aswell abit

This commit is contained in:
Magnus Auvinen 2007-07-15 10:47:50 +00:00
parent 60b252c584
commit 8a4cd7627e
7 changed files with 1086 additions and 772 deletions

View file

@ -113,6 +113,11 @@ int client_tick()
return current_tick;
}
int client_tickspeed()
{
return SERVER_TICK_SPEED;
}
void *snap_find_item(int snapid, int type, int id)
{
// TODO: linear search. should be fixed.

View file

@ -734,6 +734,7 @@ int client_send_msg();
int client_tick();
float client_intratick();
int client_tickspeed();
void gfx_pretty_text(float x, float y, float size, const char *text);
float gfx_pretty_text_width(float size, const char *text);

View file

@ -922,6 +922,7 @@ void modc_render()
}
// setup world view
obj_game *gameobj = 0;
{
// 1. fetch local player
// 2. set him to the center
@ -942,9 +943,10 @@ void modc_render()
void *p = snap_find_item(SNAP_PREV, item.type, item.id);
if(p)
local_player_pos = mix(vec2(((obj_player *)p)->x, ((obj_player *)p)->y), local_player_pos, client_intratick());
break;
}
}
else if(item.type == OBJTYPE_GAME)
gameobj = (obj_game *)data;
}
}
@ -981,6 +983,7 @@ void modc_render()
// render map
tilemap_render(32.0f, 0);
// render items
int num = snap_num_items(SNAP_CURRENT);
for(int i = 0; i < num; i++)
@ -1141,8 +1144,42 @@ void modc_render()
}
}
// render goals
if(gameobj)
{
gfx_mapscreen(0,0,400,300);
if(!gameobj->sudden_death)
{
char buf[32];
int time = 0;
if(gameobj->time_limit)
{
time = gameobj->time_limit*60 - ((client_tick()-gameobj->round_start_tick)/client_tickspeed());
if(gameobj->game_over)
time = 0;
}
else
time = (client_tick()-gameobj->round_start_tick)/client_tickspeed();
sprintf(buf, "%d:%02d", time /60, time %60);
float w = gfx_pretty_text_width(16, buf);
gfx_pretty_text(200-w/2, 2, 16, buf);
}
if(gameobj->sudden_death)
{
const char *text = "Sudden Death";
float w = gfx_pretty_text_width(16, text);
gfx_pretty_text(200-w/2, 2, 16, text);
}
}
// render score board
if(inp_key_pressed(baselib::input::tab) || (local_player && local_player->health == -1))
if(inp_key_pressed(baselib::input::tab) || // user requested
(local_player && local_player->health == -1) || // player dead
(gameobj && gameobj->game_over) // game over
)
{
gfx_mapscreen(0, 0, width, height);
@ -1157,12 +1194,23 @@ void modc_render()
gfx_quads_drawTL(x-10.f, y-10.f, 400.0f, 600.0f);
gfx_quads_end();
//gfx_texture_set(current_font->font_texture);
gfx_pretty_text(x, y, 64, "Score Board");
y += 100.0f;
y += 64.0f;
if(gameobj && gameobj->time_limit)
{
char buf[64];
sprintf(buf, "Time Limit: %d min", gameobj->time_limit);
gfx_pretty_text(x, y, 32, buf);
y += 32.0f;
}
if(gameobj && gameobj->score_limit)
{
char buf[64];
sprintf(buf, "Score Limit: %d", gameobj->score_limit);
gfx_pretty_text(x, y, 32, buf);
y += 32.0f;
}
//gfx_texture_set(-1);
//gfx_quads_text(10, 50, 8, "Score Board");
int num = snap_num_items(SNAP_CURRENT);
for(int i = 0; i < num; i++)
{

View file

@ -26,6 +26,7 @@ inline bool col_check_point(baselib::vec2 p) { return col_check_point(p.x, p.y);
enum
{
OBJTYPE_NULL=0,
OBJTYPE_GAME,
OBJTYPE_PLAYER,
OBJTYPE_PROJECTILE,
OBJTYPE_POWERUP,
@ -83,6 +84,17 @@ struct ev_damageind
int angle;
};
struct obj_game
{
int round_start_tick;
int game_over;
int sudden_death;
int paused;
int score_limit;
int time_limit;
};
struct obj_projectile
{
int type;
@ -99,7 +111,6 @@ struct obj_powerup
struct obj_player
{
//int name[8];
int local;
int clientid;
@ -111,12 +122,9 @@ struct obj_player
int vx, vy;
int angle;
// current active weapon
int weapon;
// current active modifier
int weapon; // current active weapon
// num attack ticks left of current attack
int attacktick;
int attacktick; // num attack ticks left of current attack
int score;
int emote;

View file

@ -3,5 +3,6 @@ MACRO_CONFIG_INT(key_move_right, 68, 32, 512)
MACRO_CONFIG_INT(key_jump, 32, 32, 512)
MACRO_CONFIG_INT(key_fire, 384, 32, 512)
MACRO_CONFIG_INT(key_hook, 385, 32, 512)
//MACRO_CONFIG_INT(key_fire, 'E', 32, 512)
//MACRO_CONFIG_INT(key_hook, 'Q', 32, 512)
MACRO_CONFIG_INT(scorelimit, 20, 0, 1000)
MACRO_CONFIG_INT(timelimit, 0, 0, 1000)

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,254 @@
//
class event_handler
{
static const int MAX_EVENTS = 128;
static const int MAX_DATASIZE = 128*4;
int types[MAX_EVENTS]; // TODO: remove some of these arrays
int offsets[MAX_EVENTS];
int sizes[MAX_EVENTS];
char data[MAX_DATASIZE];
int current_offset;
int num_events;
public:
event_handler();
void *create(int type, int size);
void clear();
void snap(int snapping_client);
};
extern event_handler events;
// a basic entity
class entity
{
private:
friend class game_world;
friend class player;
entity *prev_entity;
entity *next_entity;
entity *prev_type_entity;
entity *next_type_entity;
int index;
static int current_id;
protected:
int id;
public:
float proximity_radius;
unsigned flags;
int objtype;
baselib::vec2 pos;
enum
{
FLAG_DESTROY=0x00000001,
FLAG_ALIVE=0x00000002,
};
entity(int objtype);
virtual ~entity();
virtual void reset() {}
virtual void post_reset() {}
void set_flag(unsigned flag) { flags |= flag; }
void clear_flag(unsigned flag) { flags &= ~flag; }
virtual void destroy() { delete this; }
virtual void tick() {}
virtual void tick_defered() {}
virtual void snap(int snapping_client) {}
virtual bool take_damage(baselib::vec2 force, int dmg, int from, int weapon) { return true; }
};
class game_world
{
void reset();
void remove_entities();
public:
enum
{
NUM_ENT_TYPES=10, // TODO: are more exact value perhaps? :)
};
// TODO: two lists seams kinda not good, shouldn't be needed
entity *first_entity;
entity *first_entity_types[NUM_ENT_TYPES];
bool paused;
bool reset_requested;
game_world();
int find_entities(baselib::vec2 pos, float radius, entity **ents, int max);
int find_entities(baselib::vec2 pos, float radius, entity **ents, int max, const int* types, int maxtypes);
void insert_entity(entity *ent);
void destroy_entity(entity *ent);
void remove_entity(entity *ent);
//
void snap(int snapping_client);
void tick();
};
extern game_world world;
// game object
class gameobject : public entity
{
void resetgame();
void startround();
void endround();
int round_start_tick;
int game_over_tick;
int sudden_death;
public:
gameobject();
virtual void post_reset();
virtual void tick();
virtual void snap(int snapping_client);
};
extern gameobject gameobj;
// TODO: move to seperate file
class powerup : public entity
{
public:
static const int phys_size = 14;
int type;
int subtype; // weapon type for instance?
int spawntick;
powerup(int _type, int _subtype = 0);
virtual void reset();
virtual void tick();
virtual void snap(int snapping_client);
};
// projectile entity
class projectile : public entity
{
public:
enum
{
PROJECTILE_FLAGS_EXPLODE = 1 << 0,
};
baselib::vec2 vel;
entity *powner; // this is nasty, could be removed when client quits
int lifespan;
int owner;
int type;
int flags;
int damage;
int sound_impact;
int weapon;
float force;
projectile(int type, int owner, baselib::vec2 pos, baselib::vec2 vel, int span, entity* powner,
int damage, int flags, float force, int sound_impact, int weapon);
virtual void reset();
virtual void tick();
virtual void snap(int snapping_client);
};
// player entity
class player : public entity
{
public:
static const int phys_size = 28;
enum // what are these?
{
WEAPON_PROJECTILETYPE_GUN = 0,
WEAPON_PROJECTILETYPE_ROCKET = 1,
WEAPON_PROJECTILETYPE_SHOTGUN = 2,
};
// weapon info
struct weaponstat
{
bool got;
int ammo;
} weapons[NUM_WEAPONS];
int active_weapon;
int reload_timer;
int attack_tick;
// we need a defered position so we can handle the physics correctly
baselib::vec2 defered_pos;
baselib::vec2 vel;
baselib::vec2 direction;
//
int client_id;
char name[64];
// input
player_input previnput;
player_input input;
int jumped;
int damage_taken_tick;
int health;
int armor;
int score;
bool dead;
int die_tick;
// hooking stuff
enum
{
HOOK_RETRACTED=-1,
HOOK_IDLE=0,
HOOK_FLYING,
HOOK_GRABBED
};
int hook_state;
player *hooked_player;
baselib::vec2 hook_pos;
baselib::vec2 hook_dir;
//
player();
void init();
virtual void reset();
virtual void destroy();
void respawn();
bool is_grounded();
void release_hooked();
void release_hooks();
void handle_weapons();
virtual void tick();
virtual void tick_defered();
void die(int killer, int weapon);
virtual bool take_damage(baselib::vec2 force, int dmg, int from, int weapon);
virtual void snap(int snaping_client);
};
extern player players[MAX_CLIENTS];