diff options
| author | Magnus Auvinen <magnus.auvinen@gmail.com> | 2008-09-23 14:38:13 +0000 |
|---|---|---|
| committer | Magnus Auvinen <magnus.auvinen@gmail.com> | 2008-09-23 14:38:13 +0000 |
| commit | c94b1f22ab5d1522abfcedef8cf3a62848c370c1 (patch) | |
| tree | 4eb58340a78bd605d722d951b307bf1a7b476b2c /src/game | |
| parent | 815c55c4ce58995dcc34627bcbed956d1a1bc4dd (diff) | |
| download | zcatch-c94b1f22ab5d1522abfcedef8cf3a62848c370c1.tar.gz zcatch-c94b1f22ab5d1522abfcedef8cf3a62848c370c1.zip | |
added non-hookable tile
Diffstat (limited to 'src/game')
| -rw-r--r-- | src/game/client/gameclient.cpp | 1 | ||||
| -rw-r--r-- | src/game/collision.cpp | 24 | ||||
| -rw-r--r-- | src/game/collision.hpp | 3 | ||||
| -rw-r--r-- | src/game/gamecore.cpp | 16 | ||||
| -rw-r--r-- | src/game/gamecore.hpp | 3 | ||||
| -rw-r--r-- | src/game/server/entities/character.cpp | 1 | ||||
| -rw-r--r-- | src/game/server/hooks.cpp | 9 |
7 files changed, 41 insertions, 16 deletions
diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index 43627669..920d874b 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -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); } } diff --git a/src/game/collision.cpp b/src/game/collision.cpp index 6d63091b..2747b22f 100644 --- a/src/game/collision.cpp +++ b/src/game/collision.cpp @@ -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; } diff --git a/src/game/collision.hpp b/src/game/collision.hpp index e98ce6be..676a477a 100644 --- a/src/game/collision.hpp +++ b/src/game/collision.hpp @@ -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 diff --git a/src/game/gamecore.cpp b/src/game/gamecore.cpp index cc0f3748..c4a3392b 100644 --- a/src/game/gamecore.cpp +++ b/src/game/gamecore.cpp @@ -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; } diff --git a/src/game/gamecore.hpp b/src/game/gamecore.hpp index 08634909..0e0c1c4a 100644 --- a/src/game/gamecore.hpp +++ b/src/game/gamecore.hpp @@ -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 diff --git a/src/game/server/entities/character.cpp b/src/game/server/entities/character.cpp index 05820102..8f47fbe7 100644 --- a/src/game/server/entities/character.cpp +++ b/src/game/server/entities/character.cpp @@ -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); //} diff --git a/src/game/server/hooks.cpp b/src/game/server/hooks.cpp index bd2b5f4f..3b16c422 100644 --- a/src/game/server/hooks.cpp +++ b/src/game/server/hooks.cpp @@ -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; - } } } |