Subversion Repositories shark

Rev

Blame | Last modification | View Log | RSS feed

// *** Library S.Ha.R.K ***
#include <kernel/kern.h>
#include <drivers/keyb.h>
#include <ll/i386/cons.h>
#include <drivers/glib.h>

// *** Library Standard C ***
#include <stdlib.h>

// *** Library FAB ***
#include "fab_lib/fab_msg.h"
#include "fab_lib/fab_show.h"
#include "fab_lib/fab_tool.h"
#include "fab_lib/fab_grx.h"

// *** Library ILLA ***
#include "Illa.h"
#include "player.c"
#include "enemy.c"
#include "leaf.c"
#include "scorer.c"

void my_close(void *arg)
{

 FAB_grx_close();
 cprintf("Your Score Was %d \n",iScore);
}

void end_fun(KEY_EVT* k)
{
  cprintf("Ending...\n");
  sys_end();
}
void moveup(KEY_EVT* k)
{
  mutex_lock(&player_mutex);
  if(player.iLevel > 0 )
    {
      if( (!bUp) && (!bDown))
      {
        task_activate(g_UpPlayer);
       }
    }
    mutex_unlock(&player_mutex);
  return;

}



void movedown(KEY_EVT* k)
{

  mutex_lock(&player_mutex);
  if(player.iLevel < MAX_DOWN_LEVELS )
    {
       if ((!bUp) && (!bDown) )
       {
        task_activate(g_DownPlayer);
        }
    }
    else
    {
      sys_end();
    }
    mutex_unlock(&player_mutex);
  return;
}

int main(int argc, char **argv)
{
    PID pid;

    int i_;
    KEY_EVT k;
    k.flag = 0;
    k.scan = KEY_ENT;
    k.ascii = ESC;
    keyb_hook(k,end_fun);

    k.flag = 0;
    k.ascii = 'A';
    k.scan = KEY_A;
    keyb_hook(k,moveleft);

    k.ascii = 75;
    k.scan = PAD_LEFT;
    keyb_hook(k,moveleft);


    k.flag = 0;
    k.ascii ='D';
    k.scan = KEY_D;
    keyb_hook(k,moveright);

    k.ascii = 77;
    k.scan = PAD_RIGHT;
    keyb_hook(k,moveright);


    k.flag = 0;
    k.ascii = 'W';
    k.scan = KEY_W;
    keyb_hook(k,moveup);

    k.ascii = 72;
    k.scan = PAD_UP;
    keyb_hook(k,moveup);



    k.flag = 0;
    k.ascii = 'S';
    k.scan = KEY_S;
    keyb_hook(k,movedown);

    k.ascii = 80;
    k.scan = PAD_DOWN;
    keyb_hook(k,movedown);

    bUp = 0;
    bDown = 0;

    sys_atrunlevel(my_close, NULL, RUNLEVEL_BEFORE_EXIT);


    FAB_grx_open(PLAY_AREA_WIDTH,PLAY_AREA_HEIGHT);

    app_mutex_init(&grx_mutex);
    app_mutex_init(&player_mutex);

    CreatePlayerMoveTask();

    for( i_ = 0; i_ < Max_Leaves;++i_ )
      {
        app_mutex_init(&leaves_mutex[i_]);
      }

    mutex_lock(&grx_mutex);

    FAB_image_put(image_bg,0,0);



    mutex_lock(&player_mutex);
    player.x = PLAYER_INITIAL_POSITION_X;
    player.y = PLAYER_INITIAL_POSITION_Y;
    player.iLevel = 0;
    player.iLeaf = -1;
    iScore = 0;
    iScoreLevel = 0;
    iScoreDown = 1;

    //FRAME_BCA
    FAB_image_put(image_player,player.x,player.y);
    mutex_unlock(&player_mutex);
    mutex_unlock(&grx_mutex);



    InitialiseLeafPositions();

    CreateAndActivateScorerTask();
 
    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, 5000);
    soft_task_def_met(m,1000);

    for( i_ = 0;i_ < Max_Leaves;++i_)
      {
       soft_task_def_arg(m,(void*)i_);
       pid = task_create("Leaves", Leaf, &m, NULL);
       task_activate(pid);
      }

      createandactivateenemytask();
      task_join(pid,NULL);
      return 0;
}