added non-hookable tile

This commit is contained in:
Magnus Auvinen 2008-09-23 14:38:13 +00:00
parent 815c55c4ce
commit c94b1f22ab
9 changed files with 41 additions and 16 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 52 KiB

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

View file

@ -683,6 +683,7 @@ void GAMECLIENT::on_predict()
//if(events&COREEVENT_HOOK_LAUNCH) snd_play_random(CHN_WORLD, SOUND_HOOK_LOOP, 1.0f, pos);
//if(events&COREEVENT_HOOK_ATTACH_PLAYER) snd_play_random(CHN_WORLD, SOUND_HOOK_ATTACH_PLAYER, 1.0f, pos);
if(events&COREEVENT_HOOK_ATTACH_GROUND) gameclient.sounds->play(SOUNDS::CHN_WORLD, SOUND_HOOK_ATTACH_GROUND, 1.0f, pos);
if(events&COREEVENT_HOOK_HIT_NOHOOK) gameclient.sounds->play(SOUNDS::CHN_WORLD, SOUND_HOOK_LOOP, 1.0f, pos);
//if(events&COREEVENT_HOOK_RETRACT) snd_play_random(CHN_WORLD, SOUND_PLAYER_JUMP, 1.0f, pos);
}
}

View file

@ -21,6 +21,24 @@ int col_init()
width = layers_game_layer()->width;
height = layers_game_layer()->height;
tiles = (TILE *)map_get_data(layers_game_layer()->data);
for(int i = 0; i < width*height; i++)
{
int index = tiles[i].index;
if(index > 128)
continue;
if(index == TILE_DEATH)
tiles[i].index = COLFLAG_DEATH;
else if(index == TILE_SOLID)
tiles[i].index = COLFLAG_SOLID;
else if(index == TILE_NOHOOK)
tiles[i].index = COLFLAG_SOLID|COLFLAG_NOHOOK;
else
tiles[i].index = 0;
}
return 1;
}
@ -42,7 +60,7 @@ int col_is_solid(int x, int y)
// TODO: rewrite this smarter!
bool col_intersect_line(vec2 pos0, vec2 pos1, vec2 *out)
int col_intersect_line(vec2 pos0, vec2 pos1, vec2 *out)
{
float d = distance(pos0, pos1);
@ -54,10 +72,10 @@ bool col_intersect_line(vec2 pos0, vec2 pos1, vec2 *out)
{
if(out)
*out = pos;
return true;
return col_get((int)pos.x, (int)pos.y);
}
}
if(out)
*out = pos1;
return false;
return 0;
}

View file

@ -8,6 +8,7 @@ enum
{
COLFLAG_SOLID=1,
COLFLAG_DEATH=2,
COLFLAG_NOHOOK=4,
};
int col_init();
@ -15,6 +16,6 @@ int col_is_solid(int x, int y);
int col_get(int x, int y);
int col_width();
int col_height();
bool col_intersect_line(vec2 pos0, vec2 pos1, vec2 *out);
int col_intersect_line(vec2 pos0, vec2 pos1, vec2 *out);
#endif

View file

@ -301,8 +301,15 @@ void CHARACTER_CORE::tick(bool use_input)
// make sure that the hook doesn't go though the ground
bool going_to_hit_ground = false;
if(col_intersect_line(hook_pos, new_pos, &new_pos))
going_to_hit_ground = true;
bool going_to_retract = false;
int hit = col_intersect_line(hook_pos, new_pos, &new_pos);
if(hit)
{
if(hit&COLFLAG_NOHOOK)
going_to_retract = true;
else
going_to_hit_ground = true;
}
// Check against other players first
if(world)
@ -332,6 +339,11 @@ void CHARACTER_CORE::tick(bool use_input)
triggered_events |= COREEVENT_HOOK_ATTACH_GROUND;
hook_state = HOOK_GRABBED;
}
else if(going_to_retract)
{
triggered_events |= COREEVENT_HOOK_HIT_NOHOOK;
hook_state = HOOK_RETRACT_START;
}
hook_pos = new_pos;
}

View file

@ -107,7 +107,8 @@ enum
COREEVENT_HOOK_LAUNCH=0x04,
COREEVENT_HOOK_ATTACH_PLAYER=0x08,
COREEVENT_HOOK_ATTACH_GROUND=0x10,
COREEVENT_HOOK_RETRACT=0x20,
COREEVENT_HOOK_HIT_NOHOOK=0x20,
COREEVENT_HOOK_RETRACT=0x40,
};
class WORLD_CORE

View file

@ -657,6 +657,7 @@ void CHARACTER::tick_defered()
//if(events&COREEVENT_HOOK_LAUNCH) snd_play_random(CHN_WORLD, SOUND_HOOK_LOOP, 1.0f, pos);
if(events&COREEVENT_HOOK_ATTACH_PLAYER) game.create_sound(pos, SOUND_HOOK_ATTACH_PLAYER, cmask_all());
if(events&COREEVENT_HOOK_ATTACH_GROUND) game.create_sound(pos, SOUND_HOOK_ATTACH_GROUND, mask);
if(events&COREEVENT_HOOK_HIT_NOHOOK) game.create_sound(pos, SOUND_HOOK_LOOP, mask);
//if(events&COREEVENT_HOOK_RETRACT) snd_play_random(CHN_WORLD, SOUND_PLAYER_JUMP, 1.0f, pos);
//}

View file

@ -359,15 +359,6 @@ void mods_init()
vec2 pos(x*32.0f+16.0f, y*32.0f+16.0f);
game.controller->on_entity(index-ENTITY_OFFSET, pos);
}
else
{
if(index == TILE_DEATH)
tiles[y*tmap->width+x].index = COLFLAG_DEATH;
else if(index == TILE_SOLID)
tiles[y*tmap->width+x].index = COLFLAG_SOLID;
else
tiles[y*tmap->width+x].index = 0;
}
}
}