Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1664 pj 1
// *** Library S.Ha.R.K ***
2
#include <kernel/kern.h>
3
#include <drivers/keyb.h>
4
#include <ll/i386/cons.h>
5
#include <drivers/glib.h>
6
 
7
// *** Library Standard C ***
8
#include <stdlib.h>
9
 
10
// *** Library FAB ***
11
#include "fab_lib/fab_msg.h"
12
#include "fab_lib/fab_show.h"
13
#include "fab_lib/fab_tool.h"
14
#include "fab_lib/fab_grx.h"
15
 
16
// *** Library ILLA ***
17
#include "Illa.h"
18
#include "player.c"
19
#include "enemy.c"
20
#include "leaf.c"
21
#include "scorer.c"
22
 
23
void my_close(void *arg)
24
{
25
 
26
 FAB_grx_close();
27
 cprintf("Your Score Was %d \n",iScore);
28
}
29
 
30
void end_fun(KEY_EVT* k)
31
{
32
  cprintf("Ending...\n");
33
  sys_end();
34
}
35
void moveup(KEY_EVT* k)
36
{
37
  mutex_lock(&player_mutex);
38
  if(player.iLevel > 0 )
39
    {
40
      if( (!bUp) && (!bDown))
41
      {
42
        task_activate(g_UpPlayer);
43
       }
44
    }
45
    mutex_unlock(&player_mutex);
46
  return;
47
 
48
}
49
 
50
 
51
 
52
void movedown(KEY_EVT* k)
53
{
54
 
55
  mutex_lock(&player_mutex);
56
  if(player.iLevel < MAX_DOWN_LEVELS )
57
    {
58
       if ((!bUp) && (!bDown) )
59
       {
60
        task_activate(g_DownPlayer);
61
        }
62
    }
63
    else
64
    {
65
      sys_end();
66
    }
67
    mutex_unlock(&player_mutex);
68
  return;
69
}
70
 
71
int main(int argc, char **argv)
72
{
73
    PID pid;
74
 
75
    int i_;
76
    KEY_EVT k;
77
    k.flag = 0;
78
    k.scan = KEY_ENT;
79
    k.ascii = ESC;
80
    keyb_hook(k,end_fun);
81
 
82
    k.flag = 0;
83
    k.ascii = 'A';
84
    k.scan = KEY_A;
85
    keyb_hook(k,moveleft);
86
 
87
    k.ascii = 75;
88
    k.scan = PAD_LEFT;
89
    keyb_hook(k,moveleft);
90
 
91
 
92
    k.flag = 0;
93
    k.ascii ='D';
94
    k.scan = KEY_D;
95
    keyb_hook(k,moveright);
96
 
97
    k.ascii = 77;
98
    k.scan = PAD_RIGHT;
99
    keyb_hook(k,moveright);
100
 
101
 
102
    k.flag = 0;
103
    k.ascii = 'W';
104
    k.scan = KEY_W;
105
    keyb_hook(k,moveup);
106
 
107
    k.ascii = 72;
108
    k.scan = PAD_UP;
109
    keyb_hook(k,moveup);
110
 
111
 
112
 
113
    k.flag = 0;
114
    k.ascii = 'S';
115
    k.scan = KEY_S;
116
    keyb_hook(k,movedown);
117
 
118
    k.ascii = 80;
119
    k.scan = PAD_DOWN;
120
    keyb_hook(k,movedown);
121
 
122
    bUp = 0;
123
    bDown = 0;
124
 
125
    sys_atrunlevel(my_close, NULL, RUNLEVEL_BEFORE_EXIT);
126
 
127
 
128
    FAB_grx_open(PLAY_AREA_WIDTH,PLAY_AREA_HEIGHT);
129
 
130
    app_mutex_init(&grx_mutex);
131
    app_mutex_init(&player_mutex);
132
 
133
    CreatePlayerMoveTask();
134
 
135
    for( i_ = 0; i_ < Max_Leaves;++i_ )
136
      {
137
        app_mutex_init(&leaves_mutex[i_]);
138
      }
139
 
140
    mutex_lock(&grx_mutex);
141
 
142
    FAB_image_put(image_bg,0,0);
143
 
144
 
145
 
146
    mutex_lock(&player_mutex);
147
    player.x = PLAYER_INITIAL_POSITION_X;
148
    player.y = PLAYER_INITIAL_POSITION_Y;
149
    player.iLevel = 0;
150
    player.iLeaf = -1;
151
    iScore = 0;
152
    iScoreLevel = 0;
153
    iScoreDown = 1;
154
 
155
    //FRAME_BCA
156
    FAB_image_put(image_player,player.x,player.y);
157
    mutex_unlock(&player_mutex);
158
    mutex_unlock(&grx_mutex);
159
 
160
 
161
 
162
    InitialiseLeafPositions();
163
 
164
    CreateAndActivateScorerTask();
165
 
166
    SOFT_TASK_MODEL m;
167
    soft_task_default_model(m);
168
    soft_task_def_level(m,0);
169
    soft_task_def_periodic(m);
170
    soft_task_def_period(m,50000);
171
    soft_task_def_wcet(m, 5000);
172
    soft_task_def_met(m,1000);
173
 
174
    for( i_ = 0;i_ < Max_Leaves;++i_)
175
      {
176
       soft_task_def_arg(m,(void*)i_);
177
       pid = task_create("Leaves", Leaf, &m, NULL);
178
       task_activate(pid);
179
      }
180
 
181
      createandactivateenemytask();
182
      task_join(pid,NULL);
183
      return 0;
184
}
185
 
186
 
187