Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1664 pj 1
void InitialiseLeafPositions()
2
{
3
  int iNumOfColumns = 3;
4
  int iNumOfRows = 3;
5
  int i_;
6
  for ( i_ = 0;i_ < Max_Leaves;++i_)
7
    {
8
      mutex_lock(&leaves_mutex[i_]);
9
      leaves[i_].x0 = (240 * (i_ % iNumOfColumns ) );
10
      leaves[i_].y0 = (240 + ((i_ / iNumOfRows)  * 120 ));
11
      mutex_unlock(&leaves_mutex[i_]);
12
    }
13
 
14
}
15
 
16
TASK Leaf(void* arg)
17
{
18
  int iIndex = arg;
19
  int iLineNumber = iIndex / 3;
20
 
21
  int iDiff;
22
 
23
    if (iLineNumber % 2 )
24
    {
25
      iDiff = -5;
26
    }
27
    else
28
    {
29
      iDiff = 5;
30
    }
31
 
32
    int oldx = 0,oldy = 0;
33
    int tempx,tempy;
34
 
35
    while(1)
36
    {
37
      tempx = oldx + leaf_image_width;
38
      tempy = oldy + leaf_image_height;
39
 
40
      mutex_lock(&grx_mutex);
41
 
42
      if (tempx > 800)
43
        {
44
           FAB_image_put_within(image_bg,0,0,0,oldy,tempx - 800,tempy);
45
 
46
           tempx = 800;
47
        }
48
 
49
      FAB_image_put_within(image_bg,0,0,oldx,oldy,tempx,tempy);
50
 
51
      mutex_lock(&player_mutex);
52
      mutex_lock(&leaves_mutex[iIndex]);
53
 
54
      FAB_image_put(image_leaf,leaves[iIndex].x0,leaves[iIndex].y0);
55
      if (player.iLeaf == iIndex)
56
        {
57
          int oldPX = player.x;
58
          int oldPY = player.y;
59
 
60
 
61
          FAB_image_put_within(image_bg,0,0,player.x,player.y,player.x +                                player_image_width, player.y +
62
                               player_image_height);
63
 
64
 
65
          player.x = player.x + iDiff;
66
 
67
          FAB_image_put_within(image_bg,0,0,oldPX,oldPY
68
                               +IMAGE_OFFSET,oldPX +                                                    player_image_width, oldPY+
69
                               player_image_height + IMAGE_OFFSET);
70
 
71
          FAB_image_put(image_player,player.x,player.y + IMAGE_OFFSET);
72
 
73
            if((player.x + player_image_width > 800) || (player.x <  0))
74
            {
75
               mutex_unlock(&leaves_mutex[iIndex]);
76
               mutex_unlock(&player_mutex);
77
               mutex_unlock(&grx_mutex);
78
               sys_end();
79
            }
80
        }
81
 
82
      mutex_unlock(&leaves_mutex[iIndex]);
83
      mutex_unlock(&player_mutex);
84
 
85
      mutex_unlock(&grx_mutex);
86
 
87
      task_endcycle();
88
 
89
      mutex_lock(&leaves_mutex[iIndex]);
90
      oldx= leaves[iIndex].x0;
91
      oldy = leaves[iIndex].y0;
92
 
93
      leaves[iIndex].x0 += iDiff;
94
      leaves[iIndex].x1 += iDiff;
95
 
96
      if (leaves[iIndex].x0 >= PLAY_AREA_WIDTH)
97
      {
98
        leaves[iIndex].x0 = 0;
99
      }
100
 
101
      if ( leaves[iIndex].x0  < 0 )
102
      {
103
        leaves[iIndex].x0 = PLAY_AREA_WIDTH;
104
      }
105
      mutex_unlock(&leaves_mutex[iIndex]);
106
 
107
    }
108
 
109
}
110
 
111
int CheckIfonAnyLeaf(int iLevel)
112
{
113
 
114
  int iStartLeaf = iLevel * 3;
115
 
116
 
117
  int i_,iLeafIndex;
118
  iLeafIndex = -1;
119
 
120
  for(i_ = iStartLeaf; i_ <= iStartLeaf +2; ++i_)
121
    {
122
      //Allready have player mutex so can saely take leaves mutex
123
      mutex_lock(&leaves_mutex[i_]);
124
      if (
125
            (
126
                (player.x > leaves[i_].x0 )
127
                        &&
128
                (player.x < (leaves[i_].x0 + leaf_image_width) )
129
            )
130
                                      ||
131
            (
132
                (player.x + player_image_width > leaves[i_].x0)
133
                        &&
134
                (player.x + player_image_width < (leaves[i_].x0
135
                                                 + leaf_image_width))
136
            )
137
         )
138
         {
139
           mutex_unlock(&leaves_mutex[i_]);
140
           iLeafIndex = i_;
141
           break;
142
         }
143
         mutex_unlock(&leaves_mutex[i_]);
144
     }
145
 
146
 
147
    return iLeafIndex;
148
 
149
}