Ejemplo n.º 1
0
void SkeletonAI::act(MonsterPtr monster) {
    HeroPtr hero = find_hero(monster);
    TilePtr tile = monster->get_pos();
    Coord coord  = tile->get_coord();
    if (hero) {
        TilePtr hero_tile = hero->get_pos();
        Coord hero_coord  = hero_tile->get_coord();
        if (can_atack(coord, hero_coord)) {
            atack(monster, hero);
        } else {
            Coord coord_to = small_path_search(coord, hero_coord);
            TilePtr tile_to = main_core->get_tile(coord_to);
            MovePtr move = Move::make_Ptr(monster, tile_to);
            main_core->do_action(move);
        }
    } else {
        make_move(monster);
    }
}
Ejemplo n.º 2
0
void Hero::manageState()
{
	switch( state )
	{
	case H_NONE:
		stateManager++;
		justAtack = false;
		if ( stateManager == H_FRAME_SPAN_STEP )
		{
			if ( 0 < step )
			{
				step = 0;
			}
		}
		break;
	case H_ATACK:
		stateManager ++;
		if ( stateManager == 1 ) atack( step );
		if ( stateManager == H_FRAME_SPAN_ATACK )
		{
			step ++;
			setState(H_NONE);
		}
		break;
	case H_DAMAGE:
		stateManager++;
		if ( stateManager == H_FRAME_SPAN_DAMAGE )
		{
			if ( HP <= 0 )	setState( H_DEAD );
			else			setState( H_NONE );
		}
		break;
	case H_DEAD:
		stateManager++;
		if ( stateManager == 1 )
		{
			glMatrixMode( GL_PROJECTION );
			glLoadIdentity();
			gluPerspective(120.0,App::getAspect(), App::getZNear(), App::getZFar()); 
			glMatrixMode( GL_MODELVIEW );

		}
		if ( stateManager == H_FRAME_SPAN_DEAD )
		{
			glMatrixMode( GL_PROJECTION );
			glLoadIdentity();
			gluPerspective(60.0,App::getAspect(), App::getZNear(), App::getZFar() ); 
			glMatrixMode( GL_MODELVIEW );
			vanish();
		}
		if (  stateManager < H_FRAME_SPAN_DEAD/2  )	setRot( rot.x, rot.y + 3, rot.z );
		else										setRot( rot.x, rot.y + 6, rot.z );
		direct = Vector( sin(rot.y*PI/180), 0, cos( rot.y*PI/180) );
		break;
	case H_GUARD:
		stateManager ++;
		break;
	case H_CHARGE:
		break;
	default:
		printf("unexpected hero state\n");
		break;
	}
}
Ejemplo n.º 3
0
void run(struct block * b){
    if(!b->die && (b->energy <= 0 || b->nutrients <= 0 || b->pos > INSTRUCTIONS - 1)){
        die(b);
        return;
    }
    energymean += b->energy;
    if(!b->die){
        switch(b->program[b->pos]){
            case 0:
                if(b->lastRep > 0) break;
                b->pos = (b->pos + 1) % INSTRUCTIONS;
                reproduce(b);
                break;
            case 1:
                getEnegy(b);
                break;
            case 2:
                getNutrients(b);
                break;
            case 3:
                break;
                b->pos = (b->pos + 1) % INSTRUCTIONS;
                switch(b->program[b->pos]){
                    case 0:
                          move(b, 1, 0);
                          b->energy -= 5;
                          break; 
                    case 1:
                          move(b, 1, 0);
                          b->energy -= 5;
                          break;
                    case 2:
                          b->energy -= 5;
                          break; 
                    case 3:
                          move(b, -1, 0);
                          b->energy -= 5;
                          break;
                    case 4:
                          move(b, -1, 0);
                          b->energy -= 5;
                          break; 
                    case 5:
                          move(b, -1, -1);
                          b->energy -= 2;
                          break;
                    case 6:
                          move(b, 0, -1);
                          b->energy += 1;
                          break; 
                    case 7:
                          move(b, 1, -1);
                          b->energy -= 2;
                          break;
                }
                if(b->y > Y_SIZE - 1) kill(b);
                break;
            case 4:
                atack(b);
                break;
            case 5: //Logic Operations
                b->pos = (b->pos + 1) % INSTRUCTIONS;
                switch(b->program[b->pos]){
                        case 0:
                                ++b->ptr;
                                if(b->ptr >= INSTRUCTIONS) die(b);
                                break;
                        case 1:
                                --b->ptr;
                                if(b->ptr < 0) die(b);
                                break;
                        case 2:
                                ++b->memory[b->ptr];
                                break;
                        case 3:
                                --b->memory[b->ptr];
                                if(b->memory[b->ptr] < 0) die(b);
                                break;
                        case 4:
                                if(b->loops >= 19) break;
                                b->loops_adr[b->loops].progPos = b->pos + 1;
                                b->loops_adr[b->loops++].memAdr = b->ptr;
                                break;
                        case 5:
                                if(b->loops > 0 && b->memory[b->loops_adr[b->loops - 1].memAdr]){
                                        b->pos = b->loops_adr[b->loops - 1].progPos;
                                }else if(b->loops > 0){
                                        --b->loops;
                                }else{
                                        die(b);
                                }
                                break;
                }
                break;
            case 6:
                die(b);
                break;
                
        }
    }else{
        switch(b->program[b->pos]){
            case 1:
                getEnegy(b);
                break;
            case 2:
                getNutrients(b);
                break;
        }
    }
    if(b->energy < 10){
        kill(b);
    }
    b->pos = (b->pos + 1) % INSTRUCTIONS;
    ++b->age;
    --b->lastRep;
    b->energy -= b->age / 800.0;
    b->nutrients -= b->age / 800.0;
}