Exemplo n.º 1
0
void loadavg_init()
{
	color_t c = { 0, COLOR_MAX/2, COLOR_MAX/2 };
	base_set(c, LED_LOAD_1);

	load_update(&Load_update, 0);
	load_blink(&Load_blink, 0);
}
Exemplo n.º 2
0
void collision() // Check for collisions of tanks and bullets, respectively bullets and bullets
{
    int i, j, di, dj;
    bool empty;
    //check for tank-bullet colisions
    for (i = 0; i < MAX_SPRITES; i++)
        for (j = 0; j < MAX_SPRITES; j++) if (tanks[i].alive && bullets[j].alive )
        {
            if ( bullets[j].source == 0 ) continue;
            bool hit = false;
            for( di = 0; di < 3; di++) for( dj = 0; dj < 3; dj++){

                if ( ( tanks[ i ].x + di == bullets[ j ].x ) && ( tanks[ i ].y + dj == bullets[ j ].y ) ) hit = true;
            }
            if ( hit )
            {
                tanks[i].hit_points--;
                bullets[ j ].alive = false;
                if (tanks[i].hit_points <= 0)
                {
                    tanks[i].alive = false;
                    if ( tanks[i].power_type != NORMAL )
                    {
                        power_up.type = tanks[i].power_type;
                        while ( 1 )
                        {
                            power_up.x = rand ( ) % ( MAP_SIZE - 3 );
                            power_up.y = rand ( ) % ( MAP_SIZE - 3 );
                            if (demo) empty = true;
                            else empty = false;
                            for(di=0;di<3;di++)
                                for(dj=0;dj<3;dj++)
                                {
                                    if (!demo) {
                                            if (map[ power_up.x + di ][ power_up.y + dj ] == EMPTY ) empty = true;
                                    }
                                    else{
                                            if (map[ power_up.x + di ][ power_up.y + dj ] != EMPTY ) empty = false;
                                    }
                                }
                            if(empty) break;
                        }
                    }
                    for ( di = 0; di < 3; di++ ) for ( dj = 0; dj < 3; dj++ )
                        if ( map[ tanks[i].x + di ][ tanks[i].y + dj ] == GRASS )
                        map[ tanks[i].x + di ][ tanks[i].y + dj ] = EXPLOSION_GRASS;
                        else if ( map[tanks[i].x + di][tanks[i].y + dj] == WATER )
                                  map[tanks[i].x + di][tanks[i].y + dj] = EXPLOSION_WATER;
                             else map[ tanks[i].x + di ][ tanks[i].y + dj ] = EXPLOSION;
                    sound_explosion();

                    score += tanks[i].value;
                    cntKilled++;
                    numberOfTanks--;

                    CNT_KILLED[tanks[i].type]++;
                }
            }
    }

    // tank powerUP collision
    if ( fabs ( power_up.x - player1.x ) <= 2 && fabs ( power_up.y - player1.y ) <= 2  && power_up.type !=NORMAL)
    {
        switch ( power_up.type )
        {
        case BOMB:
            for ( i = 0; i < MAX_SPRITES; i++ ) if (tanks[ i ].alive){
                cntKilled++;
                tanks[ i ].alive= 0;
            }
            sound_explosion();
            break;
        case HELMET:
            player1.invulnerable = FRAMES_PER_SEC * HELMET_SECS;
            break;
        case SHOVEL:
            power_up.time = - FRAMES_PER_SEC * SHOVEL_SECS;
            base_set(STEEL);
            break;
        case STAR:
            if (fabs(player1.stars) < 3) {
                    player1.stars++;
                    switch(player1.stars){
                    case 1:
                        player1.shoot_rate = 2;
                        break;
                    case -1:
                        player1.stars = 3;
                        break;
                    }
            }
            break;
        case LIFE:
            if (player1.hit_points<9) player1.hit_points++;
            break;
        case TIMER:
            power_up.time = - FRAMES_PER_SEC * TIMER_SECS;
            break;
        }

        score += 500;
        player1.power_type = power_up.type;
        power_up.type = NORMAL;
    }
    //check for bullet-bullet colisions
    for ( i = 0; i < MAX_SPRITES; i++ )
        for ( j = 0; j < MAX_SPRITES; j++ )
            if (bullets[ i ].alive && bullets[ j ].alive)
            if (  ( i != j ) && bullets_collision( bullets[ i ], bullets[ j ] ) )
            {
                if (bullets[i].source == 0 && bullets[j].source == 0) continue;
                if (bullets[i].source > 0 && bullets[j].source > 0) continue;
                bullets[ i ].alive = 0;
                bullets[ j ].alive = 0;
                if ( map[ bullets[ i ].x ][ bullets[ i ].y ] == WATER ) map[ bullets[ i ].x ][ bullets[ i ].y ] = EXPLOSION_WATER;
                else if ( map[ bullets[ i ].x ][ bullets[ i ].y ] == GRASS ) map[ bullets[ i ].x ][ bullets[ i ].y ] = EXPLOSION_GRASS;
                else map[ bullets[ i ].x ][ bullets[ i ].y ] = EXPLOSION;
            }


    //check for bullet-frame collisions
    for ( i = 0; i < MAX_SPRITES; i++ ) if (bullets[ i ].alive)
        if ( bullets[ i ].x < 0 || bullets[ i ].y < 0 || bullets[ i ].x >= MAP_SIZE || bullets[ i ].y >= MAP_SIZE  )
        {
            bullets[ i ].alive = 0;
        }

    //check for bullet-wall collisions
    for ( i = 0; i < MAX_SPRITES; i++ ) if (bullets[ i ].alive )
    {
        if ( bullet_can_collide(bullets[ i ].x, bullets[ i ].y ) )
        {
            map[ bullets[ i ].x ][ bullets[ i ].y ] = EXPLOSION;
            bullets[ i ].alive = 0;
            // should actually destroy 1x3 instead of 1x1
            switch (bullets[i].dir)
            {
            case UP:
            case DOWN:
                if ( bullet_can_collide( bullets[i].x ,bullets[i].y - 1) ) map[bullets[i].x][bullets[i].y - 1] = EXPLOSION;
                if ( bullet_can_collide( bullets[i].x ,bullets[i].y + 1) ) map[bullets[i].x][bullets[i].y + 1] = EXPLOSION;
                break;
            case LEFT:
            case RIGHT:
                if ( bullet_can_collide( bullets[i].x - 1 ,bullets[i].y) ) map[bullets[i].x - 1][bullets[i].y] = EXPLOSION;
                if ( bullet_can_collide( bullets[i].x + 1 ,bullets[i].y) ) map[bullets[i].x + 1][bullets[i].y] = EXPLOSION;
                break;
            }
        }
        if ( map[ bullets[ i ].x ][ bullets[ i ].y ] == STEEL ) bullets[ i ].alive = 0;
    }

    //check for bullet-base collisions
    for ( i = 0; i < MAX_SPRITES; i++ ) if (bullets[ i ].alive )
    {
        if (map[ bullets[ i ].x ][ bullets[ i ].y ] == BASE){
            //game end
            gameOver = 1;
        }
    }

    // check for bullet-player_1 collisions
    for (i = 0; i < MAX_SPRITES; i++)
    {
        if (bullets[i].alive == 0) continue;
        if (player1.x <= bullets[i].x && bullets[i].x <= player1.x + 2 && player1.y <= bullets[i].y && bullets[i].y <= player1.y + 2)
        {
            bullets[i].alive = 0;
            if ( player1.invulnerable == 0 )
            {
                player1.stars = 0;
                player1.shoot_rate =1 ;
                player1.hit_points--;
                player1.x = 36;
                player1.y = 12;
                player1.dir = UP;
                player1.invulnerable = FRAMES_PER_SEC * INVULNERABLE_SECS;
                sound_explosion();
            }
        }
    }
}
Exemplo n.º 3
0
void update_states() // Updating bullets states and moving them, and tank shooting states, and tank moving states
{
    int i,j;

    //update the tanks shoot state and move_state
    for(i=0; i < MAX_SPRITES ; i++){
        if (tanks[ i ].alive == true){

            if (tanks[ i ].move_state < tanks[i].move_speed){
                tanks[ i ].move_state += tanks[i].move_rate;
            }

            if (tanks[ i ].shoot_state < tanks[ i ].shoot_speed){
                tanks[ i ].shoot_state += tanks[i].shoot_rate;
            }

        }


    }
    //also for player_1
    if (player1.shoot_state < player1.shoot_speed) player1.shoot_state += player1.shoot_rate;
    if (player1.move_state < player1.move_speed) player1.move_state += player1.move_rate;



    //update power up state
    if (power_up.time) {
        power_up.time++;
        switch(player1.power_type){
        case TIMER:
            for(i=0; i < MAX_SPRITES ; i++)
                if (tanks[ i ].alive == true)
                    tanks[ i ].move_state = 0;
                    tanks[ i ].shoot_state =0 ;
        }

    }

    else {
        switch(player1.power_type){
        case SHOVEL:
            base_set(BRICK);
            break;
        }
        player1.power_type = NORMAL;
    }


    for ( i = 0; i < MAX_SPRITES; i++ )
        if ( bullets[ i ].alive == true )
        {
            bullets[ i ].state++;
            if ( bullets[ i ].state == BULLET_SPEED )
            {
                switch ( bullets[ i ].dir )
                {
                    case ( UP ):
                        bullets[ i ].x--;
                        break;
                    case ( DOWN ):
                        bullets[ i ].x++;
                        break;
                    case ( LEFT ):
                        bullets[ i ].y--;
                        break;
                    case ( RIGHT ):
                        bullets[ i ].y++;
                        break;
                }
                bullets[ i ].state = 0;
            }
        }
}