diff options
| author | Magnus Auvinen <magnus.auvinen@gmail.com> | 2008-09-23 14:10:05 +0000 |
|---|---|---|
| committer | Magnus Auvinen <magnus.auvinen@gmail.com> | 2008-09-23 14:10:05 +0000 |
| commit | 815c55c4ce58995dcc34627bcbed956d1a1bc4dd (patch) | |
| tree | ae33fb8915f06865369208c5402122555b90d905 /src/game | |
| parent | 8f9e2031dcd562e72ac7e5ec9c00b8aed10b53a6 (diff) | |
| download | zcatch-815c55c4ce58995dcc34627bcbed956d1a1bc4dd.tar.gz zcatch-815c55c4ce58995dcc34627bcbed956d1a1bc4dd.zip | |
added death tile
Diffstat (limited to 'src/game')
| -rw-r--r-- | src/game/collision.cpp | 62 | ||||
| -rw-r--r-- | src/game/collision.hpp | 7 | ||||
| -rw-r--r-- | src/game/mapitems.hpp | 1 | ||||
| -rw-r--r-- | src/game/server/entities/character.cpp | 4 | ||||
| -rw-r--r-- | src/game/server/hooks.cpp | 19 |
5 files changed, 41 insertions, 52 deletions
diff --git a/src/game/collision.cpp b/src/game/collision.cpp index c1e08441..6d63091b 100644 --- a/src/game/collision.cpp +++ b/src/game/collision.cpp @@ -7,6 +7,7 @@ #include <engine/e_common_interface.h> #include <game/mapitems.hpp> #include <game/layers.hpp> +#include <game/collision.hpp> static TILE *tiles; static int width = 0; @@ -24,19 +25,22 @@ int col_init() } -int col_is_solid(int x, int y) +int col_get(int x, int y) { - int nx = x/32; - int ny = y/32; - if(nx < 0 || nx >= width || ny >= height) - return 1; - - if(y < 0) - return 0; // up == sky == free + int nx = clamp(x/32, 0, width-1); + int ny = clamp(y/32, 0, height-1); - return tiles[ny*width+nx].index == TILE_SOLID; + if(tiles[ny*width+nx].index > 128) + return 0; + return tiles[ny*width+nx].index; +} + +int col_is_solid(int x, int y) +{ + return col_get(x,y)&COLFLAG_SOLID; } + // TODO: rewrite this smarter! bool col_intersect_line(vec2 pos0, vec2 pos1, vec2 *out) { @@ -57,43 +61,3 @@ bool col_intersect_line(vec2 pos0, vec2 pos1, vec2 *out) *out = pos1; return false; } - -/* - Simple collision rutines! -*/ -/* -struct collision -{ - int w, h; - unsigned char *data; -}; - -static collision col; -static int global_dividor; - -int col_width() -{ - return col.w; -} - -int col_height() -{ - return col.h; -} - -int col_init(int dividor) -{ - mapres_collision *c = (mapres_collision*)map_find_item(MAPRES_COLLISIONMAP,0); - if(!c) - { - dbg_msg("mapres_col", "failed!"); - return 0; - } - col.w = c->width; - col.h = c->height; - global_dividor = dividor; - col.data = (unsigned char *)map_get_data(c->data_index); - return col.data ? 1 : 0; -} - -*/ diff --git a/src/game/collision.hpp b/src/game/collision.hpp index 735e26c5..e98ce6be 100644 --- a/src/game/collision.hpp +++ b/src/game/collision.hpp @@ -4,8 +4,15 @@ #include <base/vmath.hpp> +enum +{ + COLFLAG_SOLID=1, + COLFLAG_DEATH=2, +}; + int col_init(); 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); diff --git a/src/game/mapitems.hpp b/src/game/mapitems.hpp index 8093435a..9c9936d2 100644 --- a/src/game/mapitems.hpp +++ b/src/game/mapitems.hpp @@ -43,6 +43,7 @@ enum TILE_AIR=0, TILE_SOLID, + TILE_DEATH, TILE_NOHOOK, TILEFLAG_VFLIP=1, diff --git a/src/game/server/entities/character.cpp b/src/game/server/entities/character.cpp index 98bfa862..05820102 100644 --- a/src/game/server/entities/character.cpp +++ b/src/game/server/entities/character.cpp @@ -2,6 +2,7 @@ #include <engine/e_server_interface.h> #include <engine/e_config.h> #include <game/server/gamecontext.hpp> +#include <game/mapitems.hpp> #include "character.hpp" #include "laser.hpp" @@ -588,6 +589,9 @@ void CHARACTER::tick() //core.jumped = jumped; core.input = input; core.tick(true); + + if(col_get(pos.x, pos.y)&COLFLAG_DEATH) + die(player->client_id, -1); // handle weapons handle_weapons(); diff --git a/src/game/server/hooks.cpp b/src/game/server/hooks.cpp index 41058dd1..bd2b5f4f 100644 --- a/src/game/server/hooks.cpp +++ b/src/game/server/hooks.cpp @@ -352,9 +352,22 @@ void mods_init() { for(int x = 0; x < tmap->width; x++) { - int index = tiles[y*tmap->width+x].index - ENTITY_OFFSET; - vec2 pos(x*32.0f+16.0f, y*32.0f+16.0f); - game.controller->on_entity(index, pos); + int index = tiles[y*tmap->width+x].index; + + if(index >= ENTITY_OFFSET) + { + 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; + } } } |