Пример #1
0
t_map_click		click_map(t_prog *prog, t_bunny_position *mouse_pos,
				  float percent)
{
  t_grille		grille;
  t_map_click		click;
  t_scene		*scene;

  scene = prog->scene;
  click.x = -1;
  click.y = -1;
  click.mouse_pos = mouse_pos;
  click.npc = NULL;
  click.decors = NULL;
  grille = get_grille_with_place(scene);
  get_npc_clicked(scene->ground, &grille, &click, percent);
  if (click.x == -1)
    get_decors_clicked(scene->ground, &grille, &click, percent);
  else
    get_decors_wnpc(scene->ground, &grille, &click, percent);
  if (is_near((int)prog->player->x, (int)prog->player->y,
	      click.x, click.y) != 1)
    {
      click.x = -1;
      click.y = -1;
      click.npc = NULL;
      click.decors = NULL;
    }
  return (click);
}
Пример #2
0
void
aoi_update(struct aoi_space * space , uint32_t id, const char * modestring , float pos[3]) {
	struct object * obj = map_query(space, space->object,id);
	int i;
	bool set_watcher = false;
	bool set_marker = false;

	for (i=0;modestring[i];++i) {
		char m = modestring[i];
		switch(m) {
		case 'w':
			set_watcher = true;
			break;
		case 'm':
			set_marker = true;
			break;
		case 'd':
			obj->mode = MODE_DROP;
			drop_object(space, obj);
			return;
		}
	}
	obj->mode &= ~MODE_DROP;

	bool changed = change_mode(obj, set_watcher, set_marker);

	copy_position(obj->position, pos);
	if (changed || !is_near(pos, obj->last)) {
		// new object or change object mode
		// or position changed
		copy_position(obj->last , pos);
		obj->mode |= MODE_MOVE;
		++obj->version;
	} 
}
Пример #3
0
void
enter_fight_logic (struct anim *k)
{
  /* non-fightable characters don't fight */
  if (! is_fightable_anim (k)) return;

  /* has an enemy, no need to get another */
  if (k->enemy_id != -1 && k->enemy_refraction < 0)
    return;

  /* dead character doesn't fight */
  if (k->current_lives <= 0) return;

  /* non-fighter doesn't fight */
  if (! k->fight) return;

  int i;
  for (i = 0; i < anima_nmemb; i++) {
    struct anim *a = &anima[i];

    /* no dead character is a valid oponent */
    if (a->current_lives <= 0) continue;

    /* only valid opponents matter */
    if (! are_valid_opponents (k, a)) continue;

    /* if seeing the character consider him an enemy */
    if (is_anim_seeing (k, a, k->f.dir)) {
      consider_enemy (k, a);
      return;
    }

    /* if hearing the character on the back, turn */
    if (! k->controllable && is_hearing (k, a)
        && is_on_back (k, a)
        && abs (anim_cycle - k->alert_cycle) > 24) {
      k->f.dir = (k->f.dir == LEFT) ? RIGHT : LEFT;
      k->alert_cycle = anim_cycle;
      return;
    }

    /* if feeling the character's presence consider him an enemy */
    if (is_near (k, a)) {
      consider_enemy (k, a);
      return;
    }
  }
}
Пример #4
0
static Tile get_tile(GameState *game, int x, int y)
{
     if (!in_bounds(x, y))
         return TILE_UNKNOWN;

     if (is_visible(game, x, y)) {
         if (is_near(game->player.pos, x, y)) {
             return game->map[y][x];
         } else {
             return get_tile_dark(game->map[y][x]);
         }
     }

     if (game->seen[y][x])
         return get_tile_dark(game->map[y][x]);

     return TILE_UNKNOWN;
}
Пример #5
0
void main(void)
{
unsigned int prev_r_v = 0, r_v = 0, tick_count;
unsigned int time_zummer = TIME_ZUMMER;
unsigned int chs = COUNT_CHANGE_STOP; 
uchar clean = 0, i = 0;
Stage stage;
stage = S_NONE; 


// Input/Output Ports initialization
// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=P 
PORTB=0x01;
DDRB=0x00;

// Port C initialization
// Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
// State6=T State5=T State4=T State3=T State2=T State1=P State0=P 
PORTC=0b0001011;
DDRC=0x00;

// Port D initialization
// Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out 
// State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=0 
PORTD=0x00;
DDRD=0xFF;

// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
TCCR0=0x00;
TCNT0=0x00;

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer1 Stopped
// Mode: Normal top=0xFFFF
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;

// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer2 Stopped
// Mode: Normal top=0xFF
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;

// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
MCUCR=0x00;

// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;

// USART initialization
// USART disabled
UCSRB=0x00;

// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;

// ADC initialization
// ADC Clock frequency: 500,000 kHz
// ADC Voltage Reference: AREF pin
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0x81;

// SPI initialization
// SPI disabled
SPCR=0x00;

// TWI initialization
// TWI disabled
TWCR=0x00;
tick_count = 0; 
clean = 0;

    for( i = 0; i < 1; i++)
    {

        LED = 0; 
        delay_ms(250);
        LED = 1;
        delay_ms(150);
    }

while (1)
    {       
        tick_count++;           
        if(0 == PROG_BUTTON)
        { 
            if(1 == clean)
            {                   
                min_sensor_value = 512; //приблизно половина 
                max_sensor_value = 512; //приблизно половина
                clean = 0;
            }
                       
            if (0 == tick_count%50)
                LED = 1;
            if (0 == tick_count%100)
                LED = 0;

            //режим програмування                 
			r_v = read_adc(5);         
            
            if (0 == min_sensor_value || min_sensor_value > 1024 || r_v < min_sensor_value )
            {   
                min_sensor_value = r_v; 
            } 

            if (0 == max_sensor_value || max_sensor_value > 1024 || r_v > max_sensor_value)
            {   
                max_sensor_value = r_v; 
            }                   
        }                        
        else
        {  
            clean = 1;
             
            if (0 == min_sensor_value || min_sensor_value > 1024 || 0 == max_sensor_value || max_sensor_value > 1024)
            {
                //якщо не запрограмовано, то нічого непрацює
                LED = 1;
                delay_ms(1000);
                
                LED = 0; 
                delay_ms(500);
                
                LED = 1;
                delay_ms(250);
                
                LED = 0; 
                delay_ms(2000);

                continue;
            } 
            else
            if (is_near(min_sensor_value, max_sensor_value))
            {
                LED = 1;
                delay_ms(1000);
                
                LED = 0; 
                delay_ms(250);
                
                LED = 1;
                delay_ms(150);

                LED = 0; 
                delay_ms(250);

                LED = 1;
                delay_ms(150);
                
                LED = 0; 
                delay_ms(2000);

                continue;
            
            }   
            else
                LED = 0;
                  
			if(0 == CLOSE_BUTTON)
			{  
				while(0 == CLOSE_BUTTON) delay_ms(10);
                delay_ms(10);
				while(0 == CLOSE_BUTTON) delay_ms(10);   
                
            
                time_zummer--;
              if(0 == time_zummer)
                {
                  ZUMMER_PIN = !ZUMMER_PIN;  
                    time_zummer = TIME_ZUMMER; 
              }        
                  delay_ms(1000);//затримка перед закриванням  
				//Stop();
                
                
                
				StartClose();   
                stage = S_CLOSE;
				  
                 
                   
			}
			    
			if(0 == CENTRAL_BUTTON && END_BUTTON_CLOSE == END_BUTTON)
			{                      
				while(0 == CENTRAL_BUTTON) delay_ms(10);
				
				Stop();
				StartOpen();
				stage = S_OPEN;   
                  time_zummer--;
               
			}                 
			                 
			if (S_OPEN == stage)
			{   
                time_zummer--;
              if(0 == time_zummer)
                {
                  ZUMMER_PIN = !ZUMMER_PIN;  
                    time_zummer = TIME_ZUMMER; 
              }        
				r_v = read_adc(5);
				if (r_v > max_sensor_value - max_sensor_value*ACCURACY_PER/100.0+free_up)
				{
					stage = S_NONE;   
                    //blink();
					Stop();            
				}
			}

			if (S_CLOSE == stage)
			{       
               time_zummer--;
               if(0 == time_zummer)
                {
                    ZUMMER_PIN = !ZUMMER_PIN;  
                    time_zummer = TIME_ZUMMER; 
                }   
                
				r_v = read_adc(5);
				if (r_v < min_sensor_value)
				{       
					Stop();            
				}
                
                if (r_v == prev_r_v)
                {
                    chs --;
                    if(0 == chs)
                    {
                        Stop();           
                        chs = COUNT_CHANGE_STOP;  
                        StartOpen();
				        stage = S_OPEN;
                        
                    }
                }
                else
                {
                    prev_r_v = r_v;
                    chs = COUNT_CHANGE_STOP; 
                }               
                
                if(END_BUTTON_CLOSE == END_BUTTON)
                {          
                    Stop();
                }
			}
            
            if (END_BUTTON_CLOSE == END_BUTTON)
            {
                //значить закрився капот
                Stop(); // це про всяк випадок :)
                stage = S_NONE;     
            }
            
            if (S_NONE == stage && END_BUTTON_OPEN == END_BUTTON) //захист від падіння
            {
				r_v = read_adc(5);
				if (r_v < max_sensor_value - max_sensor_value*ACCURACY_PER/100.0-free_runnig)  
				{
    				Stop();
    				StartOpen();
    				stage = S_OPEN;
				}
            }
        }
    }
}
Пример #6
0
void
leave_fight_logic (struct anim *k)
{
  /* dead character doesn't fight */
  if (k->current_lives <= 0) {
    k->enemy_refraction = 0;
    forget_enemy (k);
    return;
  }

  /* non-fightable characters don't fight */
  if (! is_fightable_anim (k)) return;

  /* no enemy, no need to forget */
  if (k->enemy_id == -1) return;

  /* non-fighter doesn't fight */
  if (! k->fight) return;

  /* character that went upstairs doesn't fight */
  if (is_kid_stairs (&k->f)) {
    k->enemy_refraction = 0;
    forget_enemy (k);
    return;
  }

  /* who's the enemy? */
  struct anim *ke = get_anim_by_id (k->enemy_id);

  /* if the enemy doesn't exist, forget about it */
  if (! ke) {
    k->enemy_refraction = 0;
    forget_enemy (k);
    return;
  }

  /* if the enemy is dead no need to worry about him */
  if (ke->current_lives <= 0) {
    k->enemy_refraction = 0;
    forget_enemy (k);
    return;
  }

  /* if the enemy went up stairs, forget about him */
  if (is_kid_stairs (&ke->f)) {
    k->enemy_refraction = 0;
    forget_enemy (k);
    return;
  }

  /* if the enemy is not reachable, forget about him */
  enum dir odir = (k->f.dir == LEFT) ? RIGHT : LEFT;
  struct pos p, pe;
  survey (_m, pos, &k->f, NULL, &p, NULL);
  survey (_m, pos, &ke->f, NULL, &pe, NULL);
  pos2room (&pe, p.room, &pe);
  if (! is_anim_seeing (k, ke, k->f.dir)
      && ! is_near (k, ke)
      && ! is_safe_to_follow (k, ke, k->f.dir)
      && ! (is_on_back (k, ke) && is_anim_seeing (k, ke, odir)
            && p.floor == pe.floor)) {
    forget_enemy (k);
    return;
  }
}