ctf flags

This commit is contained in:
Jakob Fries 2007-07-26 09:21:47 +00:00
parent c1da3b23b6
commit 3769853ba4
4 changed files with 148 additions and 1 deletions

View file

@ -657,6 +657,32 @@ static void render_powerup(obj_powerup *prev, obj_powerup *current)
gfx_quads_end();
}
static void render_flag(obj_flag *prev, obj_flag *current)
{
float angle = 0.0f;
float size = 64.0f;
gfx_blend_normal();
gfx_texture_set(0);
gfx_quads_begin();
gfx_quads_setrotation(angle);
vec2 pos = mix(vec2(prev->x, prev->y), vec2(current->x, current->y), client_intratick());
float offset = pos.y/32.0f + pos.x/32.0f;
pos.x += cosf(client_localtime()*2.0f+offset)*2.5f;
pos.y += sinf(client_localtime()*2.0f+offset)*2.5f;
gfx_quads_setcolor(current->team ? 1 : 0,0,current->team ? 0 : 1,1);
gfx_quads_setsubset(
0, // startx
0, // starty
1, // endx
1); // endy
gfx_quads_drawTL(pos.x,pos.y,size,size);
gfx_quads_end();
}
static void anim_seq_eval(sequence *seq, float time, keyframe *frame)
{
if(seq->num_frames == 0)
@ -1302,7 +1328,13 @@ void modc_render()
{
void *prev = snap_find_item(SNAP_PREV, item.type, item.id);
if(prev)
render_powerup((obj_powerup*)prev, (obj_powerup *)data);
render_powerup((obj_powerup *)prev, (obj_powerup *)data);
}
else if(item.type == OBJTYPE_FLAG)
{
void *prev = snap_find_item(SNAP_PREV, item.type, item.id);
if (prev)
render_flag((obj_flag *)prev, (obj_flag *)data);
}
}

View file

@ -34,6 +34,7 @@ enum
OBJTYPE_PLAYER,
OBJTYPE_PROJECTILE,
OBJTYPE_POWERUP,
OBJTYPE_FLAG,
EVENT_EXPLOSION,
EVENT_DAMAGEINDICATION,
EVENT_SOUND,
@ -130,6 +131,12 @@ struct obj_powerup
int subtype;
};
struct obj_flag
{
int x, y;
int team;
};
struct obj_player
{
int local;

View file

@ -1458,6 +1458,95 @@ void powerup::snap(int snapping_client)
// POWERUP END ///////////////////////
//////////////////////////////////////////////////
// FLAG
//////////////////////////////////////////////////
flag::flag(int _team)
: entity(OBJTYPE_FLAG)
{
team = _team;
proximity_radius = phys_size;
carrying_player = 0x0;
reset();
// TODO: should this be done here?
world.insert_entity(this);
}
void flag::reset()
{
spawntick = -1;
}
void flag::tick()
{
// wait for respawn
if(spawntick > 0)
{
if(server_tick() > spawntick)
spawntick = -1;
else
return;
}
// Check if a player intersected us
vec2 meh;
player* pplayer = intersect_player(pos, pos + vel, meh, 0);
if (pplayer)
{
if (!carrying_player)
carrying_player = pplayer;
// TODO: something..?
}
if (carrying_player)
{
if (carrying_player->dead)
carrying_player = 0x0;
else
{
vel = carrying_player->pos - pos;
pos = carrying_player->pos;
}
}
if (!carrying_player)
{
vel.y += 0.25f;
vec2 new_pos = pos + vel;
col_intersect_line(pos, new_pos, &new_pos);
pos = new_pos;
if (is_grounded())
vel.x = vel.y = 0;
}
}
bool flag::is_grounded()
{
if(col_check_point((int)(pos.x+phys_size/2), (int)(pos.y+phys_size/2+5)))
return true;
if(col_check_point((int)(pos.x-phys_size/2), (int)(pos.y+phys_size/2+5)))
return true;
return false;
}
void flag::snap(int snapping_client)
{
if(spawntick != -1)
return;
obj_flag *flag = (obj_flag *)snap_new_item(OBJTYPE_FLAG, id, sizeof(obj_flag));
flag->x = (int)pos.x;
flag->y = (int)pos.y;
flag->team = team;
}
// FLAG END ///////////////////////
player *get_player(int index)
{
return &players[index];

View file

@ -294,3 +294,22 @@ public:
};
extern player players[MAX_CLIENTS];
// TODO: move to seperate file
class flag : public entity
{
public:
static const int phys_size = 14;
player *carrying_player;
baselib::vec2 vel;
int team;
int spawntick;
flag(int _team);
bool is_grounded();
virtual void reset();
virtual void tick();
virtual void snap(int snapping_client);
};