示例#1
0
// Returns 1 if the source sees the target
int isVisible( Object* source, Object* target )
{
    if (target->y + CELL_SIZE > source->y + CELL_HALF &&
        target->y < source->y + CELL_HALF) {
        int x1, x2;
        if (target->x < source->x && source->anim.direction < 0) {
            x1 = target->x;
            x2 = source->x;
        } else if (target->x > source->x && source->anim.direction > 0) {
            x1 = source->x;
            x2 = target->x;
        } else {
            return 0;
        }
        const int r = (source->y + CELL_HALF) / CELL_SIZE;
        for (x1 = x1 + CELL_HALF; x1 < x2; x1 += CELL_SIZE) {
            const int c = x1 / CELL_SIZE;
            if (isSolid(r, c, SOLID_LEFT | SOLID_RIGHT)) {
                return 0;
            }
        }
        return 1;
    }
    return 0;
}
示例#2
0
// checks if there is a platform for placing something somewhere
// check in a square that there is _AIR from y and above
// and check that there is solid ground at y-1
bool coretest(int x, int y, int z, int ground_rad, int air_rad, int height)
{
	int maxrad = ground_rad * ground_rad;
	for (int dx = -ground_rad; dx <= ground_rad; dx++)
	for (int dz = -ground_rad; dz <= ground_rad; dz++)
	{
		if (dx*dx + dz*dz <= maxrad)
		{
			// ground test: exit when AIR
			block_t block = getblock(x + dx, y-1, z + dz);
			if (block <= air_end || block >= halfblock_start) return false;
		}
	}
	
	for (int dy = 0; dy < height; dy++)
	{
		maxrad = air_rad * air_rad;
		for (int dx = -air_rad; dx <= air_rad; dx++)
		for (int dz = -air_rad; dz <= air_rad; dz++)
		{
			if (dx*dx + dz*dz <= maxrad)
			{
				// air test: exit when not AIR or fluid
				block_t block = getblock(x + dx, y + dy, z + dz);
				if (isSolid(block) || isFluid(block)) return false;
			}
		}
	}
	return true;
}
示例#3
0
void SideScroller::collisionY(Entity *entity) {
	int tileX;
	int tileY;
	worldToTileCoordinates(entity->x, entity->y - entity->height*0.5, &tileX, &tileY);

	if (isSolid(levelData[tileY][tileX])) {
		entity->y = -2.5f;
		entity->collidedBottom = true;
	}
}
示例#4
0
void SPGradient::setSwatch( bool swatch )
{
    if ( swatch != isSwatch() ) {
        this->swatch = swatch; // to make isSolid() work, this happens first
        gchar const* paintVal = swatch ? (isSolid() ? "solid" : "gradient") : 0;
        setAttribute( "osb:paint", paintVal, 0 );

        requestModified( SP_OBJECT_MODIFIED_FLAG );
    }
}
示例#5
0
void Teleporting_onFrame( Object* e )
{
    const int STATE_MOVING = MS_TO_FRAMES(4000);
    const int STATE_TELEPORTING = MS_TO_FRAMES(7000);
    const int STATE_WAITING = MS_TO_FRAMES(7000);

    if (e->state <= STATE_MOVING) {
        if (move(e, e->vx, e->vy, 1)) {
            e->vx = -e->vx;
            e->anim.direction = -e->anim.direction;
        }
        setAnimation(e, 1, 2, 24);

    } else if (e->state < STATE_TELEPORTING) {
        setAnimation(e, 2, 2, 24);

    } else if (e->state == STATE_TELEPORTING) {
        int r, c;
        int prevr = (e->y + CELL_HALF) / CELL_SIZE;
        int count = CELL_COUNT;
        while (count --) {
            r = rand() % (ROW_COUNT - 1);
            c = rand() % COLUMN_COUNT;
            if (isSolid(r + 1, c, SOLID_TOP) && !isSolid(r, c, SOLID_ALL) && r != prevr) {
                e->y = CELL_SIZE * r;
                e->x = CELL_SIZE * c;
            }
        }

    } else if (e->state <= STATE_WAITING) {
        setAnimation(e, 2, 2, 24);

    } else {
        e->state = -rand() % MS_TO_FRAMES(2000);
    }

    e->state += 1;
}
示例#6
0
// Moves the object by dx and dy, checking the floor if checkFloor != 0.
// Returns 0 on success, otherwise returns flags indicating if object
// could not move by dx (flag DIRECTION_X) or dy (flag DIRECTION_Y).
int move( Object* object, int dx, int dy, int checkFloor )
{
    int r, c, cell[4], body[4];
    int result = 0;

    object->x += dx;
    object->y += dy;
    getObjectPos(object, &r, &c, cell, body);

    if (isSolid(r, c, SOLID_ALL)) {
        object->x -= dx;
        object->y -= dy;
        return DIRECTION_XY;
    }
    if (dx > 0 && body[1] > cell[1]) {
        if (isSolid(r, c + 1, SOLID_LEFT) || body[1] > LEVEL_WIDTH || (checkFloor && !isSolidOrLadder(r + 1, c + 1))) {
            object->x -= dx;
            result |= DIRECTION_X;
        }
    } else if (dx < 0 && body[0] < cell[0]) {
        if (isSolid(r, c - 1, SOLID_RIGHT) || body[0] < 0 || (checkFloor && !isSolidOrLadder(r + 1, c - 1))) {
            object->x -= dx;
            result |= DIRECTION_X;
        }
    }
    if (dy > 0 && body[3] > cell[3]) {
        if (isSolid(r + 1, c, SOLID_TOP) || body[3] > LEVEL_HEIGHT) {
            object->y -= dy;
            result |= DIRECTION_Y;
        }
    } else if (dy < 0 && body[2] < cell[2]) {
        if (isSolid(r - 1, c, SOLID_BOTTOM) || body[2] < 0) {
            object->y -= dy;
            result |= DIRECTION_Y;
        }
    }
    return result;
}
示例#7
0
float GameApp::checkPointForGridCollisionsX(float x, float y)
{
	int gridX, gridY;
	worldToTileCoordinates(x, y, &gridX, &gridY);
	if (gridX < 0 || gridX > 128 || gridY < 0 || gridY > 40)
		return 0.0f;

	if (isSolid(levelData[gridY][gridX]))
	{
		float xCoord = (gridX * TILE_SIZE) - (TILE_SIZE*0.0f);
		return x - xCoord;
	}
	return 0.0;
}
示例#8
0
// simple collision checks
// if colliding, move player to diff location, in this case, right next to the tile
void SideScroller::collisionX(Entity *entity) {
	int tileX;
	int tileY;

	// left
	worldToTileCoordinates(entity->x - entity->width*0.5, entity->y, &tileX, &tileY);
	if (isSolid(levelData[tileY][tileX])) {
		entity->x = -6.3f;
		entity->collidedLeft = true;
	}
	else {
		entity->collidedLeft = false;
	}

	// right
	worldToTileCoordinates(entity->x + entity->width*0.5, entity->y, &tileX, &tileY);
	if (isSolid(levelData[tileY][tileX])) {
		entity->x = 9.1f;
		entity->collidedRight = true;
	}
	else {
		entity->collidedRight = false;
	}
}
示例#9
0
文件: Chunk.cpp 项目: ud1/CyberCubes
bool Chunk::hasEdge(const math::ivec3 &p, Dir dir, bool ignore_neib_chunks) const
{
	CubeType t = rawCubeAt(p);
	if (!isSolid(t))
		return false;
	
	math::ivec3 p2 = p;
	if (dir == Dir::XN)
	{
		--p2.x;
		if (ignore_neib_chunks && p2.x == -1)
			return true;
	}
	else if (dir == Dir::XP)
	{
		++p2.x;
		if (ignore_neib_chunks && p2.x == CHUNK_SIZE)
			return true;
	}
	else if (dir == Dir::YN)
	{
		--p2.y;
		if (ignore_neib_chunks && p2.y == -1)
			return true;
	}
	else if (dir == Dir::YP)
	{
		++p2.y;
		if (ignore_neib_chunks && p2.y == CHUNK_SIZE)
			return true;
	}
	else if (dir == Dir::ZN)
	{
		--p2.z;
		if (ignore_neib_chunks && p2.z == -1)
			return true;
	}
	else if (dir == Dir::ZP)
	{
		++p2.z;
		if (ignore_neib_chunks && p2.z == CHUNK_SIZE)
			return true;
	}
	
	CubeType t2 = cubeAt(p2);
	return t2 != t && !isOpaque(t2);
}
示例#10
0
bool RS_Hatch::isContainer() const {
	return !isSolid();
}
示例#11
0
文件: Map.cpp 项目: maurigre/SdlGame
bool Map::isSolid(int x, int y) const {
	return isSolid(Vector2I(x,y));
}
示例#12
0
void updateObject(Game* game){

    int i;

    for(i=0; i<game->objectNumber; i++){

        switch (game->map->objects[i].type){


            case FLY :

            if(game->map->objects[i].initialized == 0) initializeMonster(&(game->map->objects[i]),game->map->objects[i].x,game->map->objects[i].y);

            if(game->map->objects[i].initialized == 1) updateMonsters(game, &(game->map->objects[i]));

            break;

            case COIN :

                if((collideObject(game->player,&(game->map->objects[i])) == 1) && (game->map->objects[i].initialized == 0))
                {
                    getItem(game);
                    game->map->objects[i].initialized =1 ;
                }

                break;

            case DOOR :

                if((collideObject(game->player,&(game->map->objects[i])) == 1) && (game->map->objects[i].initialized == 0)){

                    game->level++;

                    endLevel(game);
                }

                break;

            case BLUE_BLOCK :

                if((collideObject(game->player,&(game->map->objects[i])) == 1) && (game->map->objects[i].initialized == 0)){
                    isSolid(game->player,&(game->map->objects[i]));
                }

                break;

            case GREEN_BLOCK :

                if((collideObject(game->player,&(game->map->objects[i])) == 1) && (game->map->objects[i].initialized == 0)){
                    isSolid(game->player,&(game->map->objects[i]));
                }

                break;

            case YELLOW_BLOCK :


                if((collideObject(game->player,&(game->map->objects[i])) == 1) && (game->map->objects[i].initialized == 0)){
                    isSolid(game->player,&(game->map->objects[i]));
                }

                break;

            case RED_BLOCK :

                if((collideObject(game->player,&(game->map->objects[i])) == 1) && (game->map->objects[i].initialized == 1)){
                    isSolid(game->player,&(game->map->objects[i]));
                }

                break;


            case PICK :

                if((collidePick(game->player,&(game->map->objects[i])) == 1) && (game->map->objects[i].initialized == 0)){
                    if(game->life > 0)
                    {
                        game->life--;
                        game->player->timerMort = 1;
                        if(game->life<1) playerGameover(game);
                    }
                }

                break;

            case ELEVATOR_BLOCK :


                if((collideObject(game->player,&(game->map->objects[i])) == 1) && (game->map->objects[i].initialized == 1)){
                    isSolid(game->player,&(game->map->objects[i]));
                }

                break;

            case ELEVATOR_SWITCH :


                if((collideObject(game->player,&(game->map->objects[i])) == 1) && (game->map->objects[i].initialized == 0) && (game->input->use == 1)){
                    activateSwitch(ELEVATOR_BLOCK,game);
                    game->map->objects[i].initialized = 1;
                    game->input->use =0;
                    playSoundFx(SWITCHSOUND,game);
                    break;
                }

                if((collideObject(game->player,&(game->map->objects[i])) == 1) && (game->map->objects[i].initialized == 1) && (game->input->use == 1)){
                    desactivateSwitch(ELEVATOR_BLOCK,game);
                    game->map->objects[i].initialized = 0;
                    game->input->use = 0;
                    playSoundFx(SWITCHSOUND,game);
                    break;
                }

                break;

            case BLUE_SWITCH :

                if((collideObject(game->player,&(game->map->objects[i])) == 1) && (game->map->objects[i].initialized == 0) && (game->input->use == 1)){
                    activateSwitch(BLUE_BLOCK,game);
                    game->map->objects[i].initialized = 1;
                    game->input->use =0;
                    playSoundFx(SWITCHSOUND,game);
                    break;
                }

                if((collideObject(game->player,&(game->map->objects[i])) == 1) && (game->map->objects[i].initialized == 1) && (game->input->use == 1)){
                    desactivateSwitch(BLUE_BLOCK,game);
                    game->map->objects[i].initialized = 0;
                    game->input->use = 0;
                    playSoundFx(SWITCHSOUND,game);
                    break;
                }

                break;

            case GREEN_SWITCH :

                if((collideObject(game->player,&(game->map->objects[i])) == 1) && (game->map->objects[i].initialized == 0) && (game->input->use == 1)){
                    activateSwitch(GREEN_BLOCK,game);
                    game->map->objects[i].initialized = 1;
                    game->input->use =0;
                    playSoundFx(SWITCHSOUND,game);
                    break;
                }

                if((collideObject(game->player,&(game->map->objects[i])) == 1) && (game->map->objects[i].initialized == 1) && (game->input->use == 1)){
                    desactivateSwitch(GREEN_BLOCK,game);
                    game->map->objects[i].initialized = 0;
                    game->input->use = 0;
                    playSoundFx(SWITCHSOUND,game);
                    break;
                }

                break;

            case YELLOW_SWITCH :

                 if((collideObject(game->player,&(game->map->objects[i])) == 1) && (game->map->objects[i].initialized == 0) && (game->input->use == 1)){
                    activateSwitch(YELLOW_BLOCK,game);
                    game->map->objects[i].initialized = 1;
                    game->input->use =0;
                    playSoundFx(SWITCHSOUND,game);
                    break;
                }

                if((collideObject(game->player,&(game->map->objects[i])) == 1) && (game->map->objects[i].initialized == 1) && (game->input->use == 1)){
                    desactivateSwitch(YELLOW_BLOCK,game);
                    game->map->objects[i].initialized = 0;
                    game->input->use = 0;
                    playSoundFx(SWITCHSOUND,game);
                    break;
                }

                break;

            case RED_SWITCH :

                 if((collideObject(game->player,&(game->map->objects[i])) == 1) && (game->map->objects[i].initialized == 0) && (game->input->use == 1)){
                    activateSwitch(RED_BLOCK,game);
                    game->map->objects[i].initialized = 1;
                    game->input->use =0;
                    playSoundFx(SWITCHSOUND,game);
                    break;
                }

                if((collideObject(game->player,&(game->map->objects[i])) == 1) && (game->map->objects[i].initialized == 1) && (game->input->use == 1)){
                    desactivateSwitch(RED_BLOCK,game);
                    game->map->objects[i].initialized = 0;
                    game->input->use = 0;
                    playSoundFx(SWITCHSOUND,game);
                    break;
                }

                break;

            default :

                break;
        }
    }
}
示例#13
0
/**
 * Constructs a tile. Use this over setTile if a tile has not been generated
 * for the position yet.
 *
 * @param pType Type of the tile to create.
 */
Tile::Tile(const Vector2i& tilePosition, Type type) :
		Rectangle(toPosition(tilePosition),
				CATEGORY_WORLD,	(isSolid(type)) ? 0xffff : 0,
				Yaml(getConfig(type))),	mType(type) {
}