Ejemplo n.º 1
0
void
wall_extends(int x1, int y1, int x2, int y2)
{
    uchar type;
    register int x,y;
    struct rm *lev;
    int bits;
    int locale[3][3];	/* rock or wall status surrounding positions */

    /*
     * Value 0 represents a free-standing wall.  It could be anything,
     * so even though this table says VWALL, we actually leave whatever
     * typ was there alone.
     */
    static xchar spine_array[16] = {
        VWALL,	HWALL,		HWALL,		HWALL,
        VWALL,	TRCORNER,	TLCORNER,	TDWALL,
        VWALL,	BRCORNER,	BLCORNER,	TUWALL,
        VWALL,	TLWALL,		TRWALL,		CROSSWALL
    };

    /* sanity check on incoming variables */
    if (x1<0 || x2>=COLNO || x1>x2 || y1<0 || y2>=ROWNO || y1>y2)
        panic("wall_extends: bad bounds (%d,%d) to (%d,%d)",x1,y1,x2,y2);

    for(x = x1; x <= x2; x++)
        for(y = y1; y <= y2; y++) {
            lev = &levl[x][y];
            type = lev->typ;
            if ( !(IS_WALL(type) && type != DBWALL)) continue;

            /* set the locations TRUE if rock or wall or out of bounds */
            locale[0][0] = iswall_or_stone(x-1,y-1);
            locale[1][0] = iswall_or_stone(  x,y-1);
            locale[2][0] = iswall_or_stone(x+1,y-1);

            locale[0][1] = iswall_or_stone(x-1,  y);
            locale[2][1] = iswall_or_stone(x+1,  y);

            locale[0][2] = iswall_or_stone(x-1,y+1);
            locale[1][2] = iswall_or_stone(  x,y+1);
            locale[2][2] = iswall_or_stone(x+1,y+1);

            /* determine if wall should extend to each direction NSEW */
            bits =    (extend_spine(locale, iswall(x,y-1),  0, -1) << 3)
                      | (extend_spine(locale, iswall(x,y+1),  0,  1) << 2)
                      | (extend_spine(locale, iswall(x+1,y),  1,  0) << 1)
                      |  extend_spine(locale, iswall(x-1,y), -1,  0);

            /* don't change typ if wall is free-standing */
            if (bits) lev->typ = spine_array[bits];
        }
}
Ejemplo n.º 2
0
int main(int argc, char *args[]) {
    int eaten = 0;


    srand (time(NULL));
    printf("Start test...\n");

    initEngine(0, 0, boardwidth, boardlength, color(255,255,255), fps, &renderBoard);
    init_snake();

    newapple();
    registerKey(&keydown);

    while(stepEngine() && end == false){
        for(int i = 1; i < snake.digit+1; i++){
            snake.xpos[i] = snake.xpos[i - 1]-(snake.xdir[i - 1]) * blockwidth;
            snake.ypos[i] = snake.ypos[i - 1]-(snake.ydir[i - 1]) * blocklength;
        }
        if(snake.xdir[head] != snake.xdir[head+1] || snake.ydir[head] != snake.ydir[head+1]){ 
            for(int i = 1; i < snake.digit+1; i++){
                snake.xdir[i] = snake.xdir[i - 1];
                snake.ydir[i] = snake.ydir[i - 1];
            }
        }

        snake.xpos[head] = snake.xpos[head] + (snake.xdir[head])*vel;
        snake.ypos[head] = snake.ypos[head] + (snake.ydir[head])*vel;


        if(iswall()){
            stop();
        }
        if(eatapple()){
            newapple();
            addtosnake();
            eaten++;
        } 


        //        printf("snake.digit:%d\n",snake.digit);
        printf("head.xpos   %d  head.ypos:  %d\n",snake.xpos[head],snake.ypos[head]);
        for(int i = 1; i < snake.digit+1; i++){
            printf("digit(%d).xpos: %d  digit(%d).ypos: %d  xdir: %d  ydir: %d\n",i,snake.xpos[i],i,snake.ypos[i],snake.xdir[i],snake.ydir[i]);
        }
    }

    printf("Eaten: %d\n", eaten);
    printf("Closing program...\n");
    obliterate();

    return 0;
}
Ejemplo n.º 3
0
/*
 * move_drone:
 *	Move the drone to the next square
 *	Returns FALSE if the drone need no longer be tracked.
 */
static int
move_drone(BULLET *bp)
{
    int	mask, count;
    int	n, dir = -1;
    PLAYER	*pp;

    /* See if we can give someone a blast: */
    if (is_player(Maze[bp->b_y][bp->b_x - 1])) {
        dir = WEST;
        goto drone_move;
    }
    if (is_player(Maze[bp->b_y - 1][bp->b_x])) {
        dir = NORTH;
        goto drone_move;
    }
    if (is_player(Maze[bp->b_y + 1][bp->b_x])) {
        dir = SOUTH;
        goto drone_move;
    }
    if (is_player(Maze[bp->b_y][bp->b_x + 1])) {
        dir = EAST;
        goto drone_move;
    }

    /* Find out what directions are clear and move that way: */
    mask = count = 0;
    if (!iswall(bp->b_y, bp->b_x - 1))
        mask |= WEST, count++;
    if (!iswall(bp->b_y - 1, bp->b_x))
        mask |= NORTH, count++;
    if (!iswall(bp->b_y + 1, bp->b_x))
        mask |= SOUTH, count++;
    if (!iswall(bp->b_y, bp->b_x + 1))
        mask |= EAST, count++;

    /* All blocked up, just wait: */
    if (count == 0)
        return TRUE;

    /* Only one way to go: */
    if (count == 1) {
        dir = mask;
        goto drone_move;
    }

    /* Avoid backtracking, and remove the direction we came from: */
    switch (bp->b_face) {
    case LEFTS:
        if (mask & EAST)
            mask &= ~EAST, count--;
        break;
    case RIGHT:
        if (mask & WEST)
            mask &= ~WEST, count--;
        break;
    case ABOVE:
        if (mask & SOUTH)
            mask &= ~SOUTH, count--;
        break;
    case BELOW:
        if (mask & NORTH)
            mask &= ~NORTH, count--;
        break;
    }

    /* Pick one of the remaining directions: */
    n = rand_num(count);
    if (n >= 0 && mask & NORTH)
        dir = NORTH, n--;
    if (n >= 0 && mask & SOUTH)
        dir = SOUTH, n--;
    if (n >= 0 && mask & EAST)
        dir = EAST, n--;
    if (n >= 0 && mask & WEST)
        dir = WEST, n--;

drone_move:
    /* Move the drone: */
    switch (dir) {
    case -1:
    /* no move */
    case WEST:
        bp->b_x--;
        bp->b_face = LEFTS;
        break;
    case EAST:
        bp->b_x++;
        bp->b_face = RIGHT;
        break;
    case NORTH:
        bp->b_y--;
        bp->b_face = ABOVE;
        break;
    case SOUTH:
        bp->b_y++;
        bp->b_face = BELOW;
        break;
    }

    /* Look at what the drone moved onto: */
    switch (Maze[bp->b_y][bp->b_x]) {
    case LEFTS:
    case RIGHT:
    case BELOW:
    case ABOVE:
        /*
         * Players have a 1% chance of absorbing a drone,
         * if they are facing it.
         */
        if (rand_num(100) < conf_pdroneabsorb && opposite(bp->b_face,
                Maze[bp->b_y][bp->b_x])) {

            /* Feel the power: */
            pp = play_at(bp->b_y, bp->b_x);
            pp->p_ammo += bp->b_charge;
            message(pp, "**** Absorbed drone ****");

            /* Release drone storage: */
            free(bp);

            /* Update ammo: */
            ammo_update(pp);

            /* No need for caller to keep tracking drone: */
            return FALSE;
        }
        /* Detonate the drone: */
        bp->b_expl = TRUE;
        break;
    }

    /* Keep tracking the drone. */
    return TRUE;
}
Ejemplo n.º 4
0
/*
 * move_slime:
 *	move the given slime shot speed times and add it back if
 *	it hasn't fizzled yet
 */
static void
move_slime(BULLET *bp, int speed, BULLET *next)
{
    int	i, j, dirmask, count;
    PLAYER	*pp;
    BULLET	*nbp;

    if (speed == 0) {
        if (bp->b_charge <= 0)
            free(bp);
        else
            save_bullet(bp);
        return;
    }

    /* Draw it: */
    showexpl(bp->b_y, bp->b_x, bp->b_type == LAVA ? LAVA : '*');

    switch (Maze[bp->b_y][bp->b_x]) {
    /* Someone got hit by slime or lava: */
    case LEFTS:
    case RIGHT:
    case ABOVE:
    case BELOW:
    case FLYER:
        pp = play_at(bp->b_y, bp->b_x);
        message(pp, "You've been slimed.");
        checkdam(pp, bp->b_owner, bp->b_score, conf_mindam, bp->b_type);
        break;
    /* Bullets detonate in slime and lava: */
    case SHOT:
    case GRENADE:
    case SATCHEL:
    case BOMB:
    case DSHOT:
        explshot(next, bp->b_y, bp->b_x);
        explshot(Bullets, bp->b_y, bp->b_x);
        break;
    }


    /* Drain the slime/lava of some energy: */
    if (--bp->b_charge <= 0) {
        /* It fizzled: */
        free(bp);
        return;
    }

    /* Figure out which way the slime should flow: */
    dirmask = 0;
    count = 0;
    switch (bp->b_face) {
    case LEFTS:
        if (!iswall(bp->b_y, bp->b_x - 1))
            dirmask |= WEST, count++;
        if (!iswall(bp->b_y - 1, bp->b_x))
            dirmask |= NORTH, count++;
        if (!iswall(bp->b_y + 1, bp->b_x))
            dirmask |= SOUTH, count++;
        if (dirmask == 0)
            if (!iswall(bp->b_y, bp->b_x + 1))
                dirmask |= EAST, count++;
        break;
    case RIGHT:
        if (!iswall(bp->b_y, bp->b_x + 1))
            dirmask |= EAST, count++;
        if (!iswall(bp->b_y - 1, bp->b_x))
            dirmask |= NORTH, count++;
        if (!iswall(bp->b_y + 1, bp->b_x))
            dirmask |= SOUTH, count++;
        if (dirmask == 0)
            if (!iswall(bp->b_y, bp->b_x - 1))
                dirmask |= WEST, count++;
        break;
    case ABOVE:
        if (!iswall(bp->b_y - 1, bp->b_x))
            dirmask |= NORTH, count++;
        if (!iswall(bp->b_y, bp->b_x - 1))
            dirmask |= WEST, count++;
        if (!iswall(bp->b_y, bp->b_x + 1))
            dirmask |= EAST, count++;
        if (dirmask == 0)
            if (!iswall(bp->b_y + 1, bp->b_x))
                dirmask |= SOUTH, count++;
        break;
    case BELOW:
        if (!iswall(bp->b_y + 1, bp->b_x))
            dirmask |= SOUTH, count++;
        if (!iswall(bp->b_y, bp->b_x - 1))
            dirmask |= WEST, count++;
        if (!iswall(bp->b_y, bp->b_x + 1))
            dirmask |= EAST, count++;
        if (dirmask == 0)
            if (!iswall(bp->b_y - 1, bp->b_x))
                dirmask |= NORTH, count++;
        break;
    }
    if (count == 0) {
        /*
         * No place to go.  Just sit here for a while and wait
         * for adjacent squares to clear out.
         */
        save_bullet(bp);
        return;
    }
    if (bp->b_charge < count) {
        /* Only bp->b_charge paths may be taken */
        while (count > bp->b_charge) {
            if (dirmask & WEST)
                dirmask &= ~WEST;
            else if (dirmask & EAST)
                dirmask &= ~EAST;
            else if (dirmask & NORTH)
                dirmask &= ~NORTH;
            else if (dirmask & SOUTH)
                dirmask &= ~SOUTH;
            count--;
        }
    }

    /* Spawn little slimes off in every possible direction: */
    i = bp->b_charge / count;
    j = bp->b_charge % count;
    if (dirmask & WEST) {
        count--;
        nbp = create_shot(bp->b_type, bp->b_y, bp->b_x - 1, LEFTS,
                          i, bp->b_size, bp->b_owner, bp->b_score, TRUE, SPACE);
        move_slime(nbp, speed - 1, next);
    }
    if (dirmask & EAST) {
        count--;
        nbp = create_shot(bp->b_type, bp->b_y, bp->b_x + 1, RIGHT,
                          (count < j) ? i + 1 : i, bp->b_size, bp->b_owner,
                          bp->b_score, TRUE, SPACE);
        move_slime(nbp, speed - 1, next);
    }
    if (dirmask & NORTH) {
        count--;
        nbp = create_shot(bp->b_type, bp->b_y - 1, bp->b_x, ABOVE,
                          (count < j) ? i + 1 : i, bp->b_size, bp->b_owner,
                          bp->b_score, TRUE, SPACE);
        move_slime(nbp, speed - 1, next);
    }
    if (dirmask & SOUTH) {
        count--;
        nbp = create_shot(bp->b_type, bp->b_y + 1, bp->b_x, BELOW,
                          (count < j) ? i + 1 : i, bp->b_size, bp->b_owner,
                          bp->b_score, TRUE, SPACE);
        move_slime(nbp, speed - 1, next);
    }

    free(bp);
}
Ejemplo n.º 5
0
	double Foothold::getslope() const
	{ 
		return iswall() ? 0.0f : static_cast<double>(getvdelta()) / gethdelta();
	}