Subversion Repositories shark

Rev

Blame | Last modification | View Log | RSS feed

TASK Enemy(void* arg)
{
  int iDiff = 10;
  int oldx = 0,oldy =0;
  while(1)
  {
    mutex_lock(&grx_mutex);
    FAB_image_put_within(image_bg,0,0,
                         oldx,oldy,oldx +enemy_image_width,
                         oldy + enemy_image_height);
    FAB_image_put(image_enemy,enemy.x,enemy.y);
    mutex_unlock(&grx_mutex);

    mutex_lock(&player_mutex);
    if ( 0 == player.iLevel )
    {
      if ((player.x > enemy.x ) && (player.x < (enemy.x + enemy_image_width)))
      {
      mutex_unlock(&player_mutex);
      sys_end();
      }

      if(
             ((player.x + player_image_width) > enemy.x)
              &&
             ( (player.x + player_image_width) < (enemy.x +enemy_image_width)               )
        )

      {
      mutex_unlock(&player_mutex);
      sys_end();
      }
    }
    mutex_unlock(&player_mutex);
    oldx =enemy.x;
    oldy =enemy.y;

    enemy.x += iDiff;


    if (enemy.x > 700)
    {
       iDiff = -10;
    }
    if (enemy.x < 50)
    {
      iDiff = +10;
    }
    task_endcycle();
  }

}

void createandactivateenemytask()
{
    PID p;
    enemy.x = ENEMY_INITIAL_POSITION_X;
    enemy.y = ENEMY_INITIAL_POSITION_Y;

    SOFT_TASK_MODEL m;
    soft_task_default_model(m);
    soft_task_def_level(m,0);
    soft_task_def_periodic(m);
    soft_task_def_period(m,50000);
    soft_task_def_wcet(m, 500);
    soft_task_def_met(m,100);
    p = task_create("ENEMY", Enemy, &m, NULL);
    task_activate(p);
}