Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1664 pj 1
TASK Enemy(void* arg)
2
{
3
  int iDiff = 10;
4
  int oldx = 0,oldy =0;
5
  while(1)
6
  {
7
    mutex_lock(&grx_mutex);
8
    FAB_image_put_within(image_bg,0,0,
9
                         oldx,oldy,oldx +enemy_image_width,
10
                         oldy + enemy_image_height);
11
    FAB_image_put(image_enemy,enemy.x,enemy.y);
12
    mutex_unlock(&grx_mutex);
13
 
14
    mutex_lock(&player_mutex);
15
    if ( 0 == player.iLevel )
16
    {
17
      if ((player.x > enemy.x ) && (player.x < (enemy.x + enemy_image_width)))
18
      {
19
      mutex_unlock(&player_mutex);
20
      sys_end();
21
      }
22
 
23
      if(
24
             ((player.x + player_image_width) > enemy.x)
25
              &&
26
             ( (player.x + player_image_width) < (enemy.x +enemy_image_width)               )
27
        )
28
 
29
      {
30
      mutex_unlock(&player_mutex);
31
      sys_end();
32
      }
33
    }
34
    mutex_unlock(&player_mutex);
35
    oldx =enemy.x;
36
    oldy =enemy.y;
37
 
38
    enemy.x += iDiff;
39
 
40
 
41
    if (enemy.x > 700)
42
    {
43
       iDiff = -10;
44
    }
45
    if (enemy.x < 50)
46
    {
47
      iDiff = +10;
48
    }
49
    task_endcycle();
50
  }
51
 
52
}
53
 
54
void createandactivateenemytask()
55
{
56
    PID p;
57
    enemy.x = ENEMY_INITIAL_POSITION_X;
58
    enemy.y = ENEMY_INITIAL_POSITION_Y;
59
 
60
    SOFT_TASK_MODEL m;
61
    soft_task_default_model(m);
62
    soft_task_def_level(m,0);
63
    soft_task_def_periodic(m);
64
    soft_task_def_period(m,50000);
65
    soft_task_def_wcet(m, 500);
66
    soft_task_def_met(m,100);
67
    p = task_create("ENEMY", Enemy, &m, NULL);
68
    task_activate(p);
69
}
70