예제 #1
0
파일: bind_ship.c 프로젝트: Xolgrim/server
static int tolua_ship_set_region(lua_State * L)
{
    ship *self = (ship *)tolua_tousertype(L, 1, 0);
    region *r = (region *)tolua_tousertype(L, 1, 0);
    if (self) {
        move_ship(self, self->region, r, NULL);
    }
    return 0;
}
예제 #2
0
void control_ship(int y, int x) {
    int input;

    change_colors(COLOR_WHITE);
    show_stars();

    while (1) {
        display_hud();
        display_wormhole();
        input = getch();
        move_ship(&y, &x, input);
        //shoot(&y, &x, input);
        shoot(y, x, input);
        check_if_bumped(y, x);
        check_if_wormhole_is_hit(y, x);
        mvprintw(2,2,"x %i - %i", x, COLS);
        mvprintw(3,3,"y %i - %i",y, LINES);
    } 
}
예제 #3
0
void hs_move(dbref executor, char *arg_left, char *arg_right)
{
  huniverse *uid;
  hcelestial *cel;
  hship *dship;
  hship *ship;
  int i, dx, dy, dz;
  dbref obj;
  dbref udb, ndb;
  char *r, *s;
  int len;
  dbref bot, top;

  obj = match_result(executor, arg_left, TYPE_THING, MAT_EVERYTHING);
  if (!IsShip(obj) && !IsCelestial(obj) && !IsConsole(obj))
  {
    notify(executor, "HSPACE: Unable to move that object.");
    return;
  }
  
  s = arg_right;
  r = split_token(&s, '/');
  if (!r || !*r)
  {
    notify(executor, "HSPACE: No destination specified.");
    return;
  }
  
  len = strlen(r);
  
  ndb = match_result(executor, r, TYPE_THING, MAT_EVERYTHING);
  
  if (!RealGoodObject(ndb))
  {
    ndb = parse_dbref(r);
  }
  
  if (!RealGoodObject(ndb))
  {
    bot = 0;
    top = db_top;
  } else {
    bot = ndb;
    top = bot + 1;
  }
  
  uid = NULL;
  /* cycle through the db and try to match a space object */
  for (udb = bot; udb < top; udb++)
  {
    if (strncasecmp(Name(udb), r, len) && udb != ndb)
      continue;
    
    if (IsUniverse(udb))
    {
      uid = find_universe(udb);
    }
    else if (IsCelestial(udb))
    {
      cel = find_celestial(udb);
      if (cel)
      {
        uid = cel->uid;
        dx = cel->x;
        dy = cel->y;
        dz = cel->z;
      }
    }
    else if (IsShip(udb) || IsShipObj(udb))
    {
      dship = find_ship(udb);
      if (dship)
      {
        dx = dship->x;
        dy = dship->y;
        dz = dship->z;
        uid = dship->uid;
      }
    }
    else
    {
      /* false positive */
      continue;
    }
  
    break;
  }
  
  if (!uid)
  {
    notify(executor, "HSPACE: Unable to locate destination.");
    return;
  }
  
  if (s)
  {
    r = split_token(&s, ' ');
    if (r)
    {
      dx = parse_integer(r);
    
      r = split_token(&s, ' ');
      if (!r || !*r)
      {
        dy = 0;
        dz = 0;
      } else {
        dy = parse_integer(r);
    
        r = split_token(&s, ' ');
        if (!r || !*r)
          dz = 0;
        else
          dz = parse_integer(r);
      }
    } else {
      /* all blanks */
      dx = 0;
      dy = 0;
      dz = 0;
    }
  }
  
  if (IsShip(obj) || IsConsole(obj))
  {
    ship = find_ship(obj);
    move_ship(ship, uid, dx, dy, dz);
  }
  else if (IsCelestial(obj))
  {
    cel = find_celestial(obj);
    move_celestial(cel, uid, dx, dy, dz);
  }
  
  notify(executor, "HSPACE: Moved.");
}
예제 #4
0
파일: randenc.c 프로젝트: hochl/server
static void move_iceberg(region * r)
{
  attrib *a;
  direction_t dir;
  region *rc;

  a = a_find(r->attribs, &at_iceberg);
  if (!a) {
    dir = (direction_t) (rng_int() % MAXDIRECTIONS);
    a = a_add(&r->attribs, make_iceberg(dir));
  } else {
    if (rng_int() % 100 < 20) {
      dir = (direction_t) (rng_int() % MAXDIRECTIONS);
      a->data.i = dir;
    } else {
      dir = (direction_t) a->data.i;
    }
  }

  rc = rconnect(r, dir);

  if (rc && !fval(rc->terrain, ARCTIC_REGION)) {
    if (fval(rc->terrain, SEA_REGION)) {        /* Eisberg treibt */
      ship *sh, *shn;
      unit *u;
      int x, y;

      for (u = r->units; u; u = u->next)
        freset(u->faction, FFL_SELECT);
      for (u = r->units; u; u = u->next)
        if (!fval(u->faction, FFL_SELECT)) {
          fset(u->faction, FFL_SELECT);
          ADDMSG(&u->faction->msgs, msg_message("iceberg_drift",
              "region dir", r, dir));
        }

      x = r->x;
      y = r->y;

      runhash(r);
      runhash(rc);
      r->x = rc->x;
      r->y = rc->y;
      rc->x = x;
      rc->y = y;
      rhash(rc);
      rhash(r);

      /* rc ist der Ozean (Ex-Eisberg), r der Eisberg (Ex-Ozean) */

      /* Schiffe aus dem Zielozean werden in den Eisberg transferiert
       * und nehmen Schaden. */

      for (sh = r->ships; sh; sh = sh->next)
        freset(sh, SF_SELECT);

      for (sh = r->ships; sh; sh = sh->next) {
        /* Meldung an Kapitän */
        float dmg =
          get_param_flt(global.parameters, "rules.ship.damage.intoiceberg",
          0.10F);
        damage_ship(sh, dmg);
        fset(sh, SF_SELECT);
      }

      /* Personen, Schiffe und Gebäude verschieben */
      while (rc->buildings) {
        rc->buildings->region = r;
        translist(&rc->buildings, &r->buildings, rc->buildings);
      }
      while (rc->ships) {
        float dmg =
          get_param_flt(global.parameters, "rules.ship.damage.withiceberg",
          0.10F);
        fset(rc->ships, SF_SELECT);
        damage_ship(rc->ships, dmg);
        move_ship(rc->ships, rc, r, NULL);
      }
      while (rc->units) {
        building *b = rc->units->building;
        u = rc->units;
        u->building = 0; /* prevent leaving in move_unit */
        move_unit(rc->units, r, NULL);
        u_set_building(u, b); /* undo leave-prevention */
      }

      /* Beschädigte Schiffe können sinken */

      for (sh = r->ships; sh;) {
        shn = sh->next;
        if (fval(sh, SF_SELECT)) {
          u = ship_owner(sh);
          if (sh->damage >= sh->size * DAMAGE_SCALE) {
            if (u != NULL) {
              ADDMSG(&u->faction->msgs, msg_message("overrun_by_iceberg_des",
                  "ship", sh));
            }
            remove_ship(&sh->region->ships, sh);
          } else if (u != NULL) {
            ADDMSG(&u->faction->msgs, msg_message("overrun_by_iceberg",
                "ship", sh));
          }
        }
        sh = shn;
      }

    } else if (rng_int() % 100 < 20) {  /* Eisberg bleibt als Gletscher liegen */
      unit *u;

      rsetterrain(r, T_GLACIER);
      a_remove(&r->attribs, a);

      for (u = r->units; u; u = u->next)
        freset(u->faction, FFL_SELECT);
      for (u = r->units; u; u = u->next)
        if (!fval(u->faction, FFL_SELECT)) {
          fset(u->faction, FFL_SELECT);
          ADDMSG(&u->faction->msgs, msg_message("iceberg_land", "region", r));
        }
    }
  }
}
예제 #5
0
int main (int argc, char *argv[])
{
    Ship* ship = NULL;
    ALLEGRO_TIMER *main_timer = NULL;
    ALLEGRO_DISPLAY *display = NULL;
    ALLEGRO_COLOR cyan = al_map_rgb(0,255,255);
    ALLEGRO_BITMAP *space_background = NULL;
    ALLEGRO_EVENT_QUEUE *event_queue = NULL;
    bool redraw = true;
    ALLEGRO_EVENT ev;

    if(!al_init())
    {
        fprintf(stderr, "Error initializing Allegro");
        exit(EXIT_FAILURE);
    }
    if(!al_init_image_addon())
    {
        fprintf(stderr, "Error initializing Allegro");
        exit(EXIT_FAILURE);
    }
    if(!al_install_keyboard())
    {
        fprintf(stderr, "Error initializing keyboard\n");
        exit(EXIT_FAILURE);
    }
    display=al_create_display(W, H);

    if(display == NULL)
    {
        fprintf(stderr, "Error creating main display");
        exit(EXIT_FAILURE);
    }

    space_background = al_load_bitmap(BACKGROUND_FILE);
    if(space_background == NULL)
    {
        fprintf(stderr, "Error loading background\n");
        exit(EXIT_FAILURE);
    }
    ship=create_new_ship("../data/spaceship.png");
    ship->current_dir = DOWN;
    al_set_target_backbuffer(display);
    al_draw_bitmap(space_background, 0, 0, 0);
    print_ship_on_screen(ship);
    al_flip_display();

    main_timer=al_create_timer(1.0/FPS);
    if(main_timer == NULL)
    {
        fprintf(stderr, "Error creating main timer\n");
        exit(EXIT_FAILURE);
    }

    event_queue = al_create_event_queue();
    al_register_event_source(event_queue, al_get_timer_event_source(main_timer));
    al_register_event_source(event_queue, al_get_display_event_source(display));
    al_register_event_source(event_queue, al_get_keyboard_event_source());
    al_start_timer(main_timer);

    while(1)
    {
        al_wait_for_event(event_queue, &ev);

        if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
        {
            break;
        }
        else
        {
            switch (ev.type)
            {
                case ALLEGRO_EVENT_TIMER:
                    redraw = true;
                    break;
                case ALLEGRO_EVENT_KEY_DOWN:
                    switch(ev.keyboard.keycode)
                    {
                        case ALLEGRO_KEY_UP:
                            ship->is_moving = 1;
                            ship->current_dir = UP;
                            break;
                        case ALLEGRO_KEY_DOWN:
                            ship->is_moving = 1;
                            ship->current_dir = DOWN;
                            break;
                        case ALLEGRO_KEY_LEFT:
                            ship->is_moving = 1;
                            ship->current_dir = LEFT;
                            break;
                        case ALLEGRO_KEY_RIGHT:
                            ship->is_moving = 1;
                            ship->current_dir = RIGHT;
                            break;
                        default:
                            break;
                    }
                    break;
                case ALLEGRO_EVENT_KEY_UP:
                    ship->is_moving = 0;
                    break;
                default:
                    break;
            }
        }

        if(redraw && al_event_queue_is_empty(event_queue))
        {
            redraw = false;
            al_clear_to_color(al_map_rgb(0,0,0));
            al_draw_bitmap(space_background, 0, 0, 0);
            move_ship(ship);
            animate_ship(ship);
            print_ship_on_screen(ship);
            al_flip_display();
        }
    }
    al_destroy_timer(main_timer);
    al_destroy_display(display);
    al_destroy_event_queue(event_queue);

	return 0;
}
예제 #6
0
파일: game.c 프로젝트: ooonak/cmess
int main(int argc, char **argv)
{
  ALLEGRO_DISPLAY *display = NULL;
  ALLEGRO_EVENT_QUEUE *event_queue = NULL;
  ALLEGRO_TIMER *timer = NULL;
  ALLEGRO_FONT *font_arial_36 = NULL;
  ALLEGRO_FONT *font_arial_24 = NULL;
  ALLEGRO_TRANSFORM transform;
  bool key[6] = { false, false, false, false, false, true };
  bool redraw = true;
  bool doexit = false;
  char display_score[20];
  char display_lives[20];
  char display_ammo[20];
  char display_countdown[20];
  int ammo = 99;

  if(!al_init()) {
    fprintf(stderr, "failed to initialize allegro!\n");
    return -1;
  }

  al_init_font_addon();
  if (!al_init_ttf_addon()) {
    fprintf(stderr, "failed to initialize ttf addon!\n");
    return -1;
  }

  if(!al_install_keyboard()) {
    fprintf(stderr, "failed to initialize the keyboard!\n");
    return -1;
  }

  timer = al_create_timer(1.0 / FPS);
  if(!timer) {
    fprintf(stderr, "failed to create timer!\n");
    return -1;
  }

  display = al_create_display(SCREEN_W, SCREEN_H);
  if(!display) {
    fprintf(stderr, "failed to create display!\n");
    al_destroy_timer(timer);
    return -1;
  }

  event_queue = al_create_event_queue();
    if(!event_queue) {
      fprintf(stderr, "failed to create event_queue!\n");
      al_destroy_display(display);
      al_destroy_timer(timer);
      return -1;
    }

  font_arial_36 = al_load_ttf_font("arial.ttf", 36, 0);
  if (!font_arial_36){
    fprintf(stderr, "arial 36 not loaded!\n" );
    return -1;
  }

  font_arial_24 = al_load_ttf_font("arial.ttf", 24, 0);
  if (!font_arial_36){
    fprintf(stderr, "arial 24 not loaded!\n" );
    return -1;
  }

  al_init_primitives_addon();

  al_register_event_source(event_queue, al_get_display_event_source(display));
  al_register_event_source(event_queue, al_get_timer_event_source(timer));
  al_register_event_source(event_queue, al_get_keyboard_event_source());

  /* Start game */
  Spaceship* ship = new_ship();
  last = make_roids(ROIDS);
  Blast **blasts = new_blasts();
  
  int countdown = 10;
  while(countdown && !DEBUG_MODE) {
    al_clear_to_color(al_map_rgb(0,0,0));
    /* Welcome - Ugly code, write nicer function. */
    al_identity_transform(&transform);
    al_use_transform(&transform);
    al_draw_text(font_arial_36, 
                 al_map_rgb(255,0,0), 
                 SCREEN_W/2, 
                 100,
                 ALLEGRO_ALIGN_CENTRE, 
                 "Welcome to Casper's BLASTEROIDS!");
    al_identity_transform(&transform);
    al_use_transform(&transform);
    al_draw_text(font_arial_24, 
                 al_map_rgb(230,230,230), 
                 SCREEN_W/2, 
                 150,
                 ALLEGRO_ALIGN_CENTRE, 
                 "You got three lives, 100 shots and a lot of asteroids to blast.");
    al_identity_transform(&transform);
    al_use_transform(&transform);
    al_draw_text(font_arial_24, 
                 al_map_rgb(230,230,230), 
                 SCREEN_W/2, 
                 170,
                 ALLEGRO_ALIGN_CENTRE, 
                 "Fire with space, steer with the arrow keys and hit escape");
    al_identity_transform(&transform);
    al_use_transform(&transform);
    al_draw_text(font_arial_24, 
                 al_map_rgb(230,230,230), 
                 SCREEN_W/2, 
                 190,
                 ALLEGRO_ALIGN_CENTRE, 
                 "if you don't dare to play to the end...");
    al_identity_transform(&transform);
    al_use_transform(&transform);
    al_draw_text(font_arial_24, 
                 al_map_rgb(230,230,230), 
                 SCREEN_W/2, 
                 230,
                 ALLEGRO_ALIGN_CENTRE, 
                 "(If you get hit by and asteroid, you will die,"); 
    al_identity_transform(&transform);
    al_use_transform(&transform);
    al_draw_text(font_arial_24, 
                 al_map_rgb(230,230,230), 
                 SCREEN_W/2, 
                 250,
                 ALLEGRO_ALIGN_CENTRE, 
                 "the first five seconds of a new life, they won't hurt you.)");
    sprintf(display_countdown, "%d", countdown);
    al_identity_transform(&transform);
    al_use_transform(&transform);
    al_draw_text(font_arial_24, 
                 al_map_rgb(230,230,230), 
                 SCREEN_W/2, 
                 300,
                 ALLEGRO_ALIGN_CENTRE, 
                 display_countdown);

    al_flip_display();
    sleep(1);
    countdown--;
  }

  al_start_timer(timer);

  while(!doexit) {
    ALLEGRO_EVENT ev;
    al_wait_for_event(event_queue, &ev);
    if(ev.type == ALLEGRO_EVENT_TIMER) {
      redraw = true;
      if(ship->timer > 0)
      ship->timer--;
    }

    else if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) {
      break;
    }

    else if(ev.type == ALLEGRO_EVENT_KEY_DOWN) {
      switch(ev.keyboard.keycode) {
        case ALLEGRO_KEY_K:
        case ALLEGRO_KEY_UP:
          key[KEY_UP] = true;
          move_ship(ship, KEY_UP);
          break;
        case ALLEGRO_KEY_J:
        case ALLEGRO_KEY_DOWN:
          key[KEY_DOWN] = true;
          move_ship(ship, KEY_DOWN);
          break;
        case ALLEGRO_KEY_H:
        case ALLEGRO_KEY_LEFT:
          key[KEY_LEFT] = true;
          move_ship(ship, KEY_LEFT);
          break;
        case ALLEGRO_KEY_L:
        case ALLEGRO_KEY_RIGHT:
          key[KEY_RIGHT] = true;
          move_ship(ship, KEY_RIGHT);
          break;
        case ALLEGRO_KEY_SPACE:
          key[KEY_SPACE] = true;
          if (ammo>0) {
            shoot_blast(blasts[ammo], ship);
            ammo--;
          }
          break;
        case ALLEGRO_KEY_ESCAPE:
          doexit = true;
          break;
      }
    }

    if(redraw && al_is_event_queue_empty(event_queue)) {
      redraw = false;
      al_clear_to_color(al_map_rgb(0,0,0));

      move_ship(ship, NONE);
      draw_ship(ship);

      move_blasts(blasts);
      draw_blasts(blasts);

      check_collision(last, ship, blasts);

      move_roids(last);
      draw_roids(last);

      if(!ship->lives || !ammo) {
        /* Game over. */
        al_identity_transform(&transform);
        al_use_transform(&transform);
        al_draw_text(font_arial_36, 
                     al_map_rgb(200,200,200), 
                     SCREEN_W/2, 
                     SCREEN_H/2-100, 
                     ALLEGRO_ALIGN_CENTRE, 
                     "GAME OVER");
        doexit = "true";
      }

      if(!ROIDS_ALIVE) {
        /* You Won. */
        al_identity_transform(&transform);
        al_use_transform(&transform);
        al_draw_text(font_arial_36, 
                     al_map_rgb(200,200,200), 
                     SCREEN_W/2, 
                     SCREEN_H/2-100, 
                     ALLEGRO_ALIGN_CENTRE, 
                     "YOU WON");
        doexit = "true";
      }

      /* Score */
      al_identity_transform(&transform);
      al_use_transform(&transform);

      sprintf(display_score, "%d", score);
      al_draw_text(font_arial_24, 
                   al_map_rgb(200,200,200), 
                   50, 
                   10, 
                   ALLEGRO_ALIGN_CENTRE, 
                   display_score);
      /* Lives */
      sprintf(display_lives, "%d", ship->lives);
      al_draw_text(font_arial_24, 
                   al_map_rgb(200,200,200), 
                   SCREEN_W-50, 
                   10, 
                   ALLEGRO_ALIGN_CENTRE, 
                   display_lives);
      /* Ammo */
      al_identity_transform(&transform);
      al_use_transform(&transform);

      sprintf(display_ammo, "%d", ammo);
      al_draw_text(font_arial_24, 
                   al_map_rgb(200,200,200), 
                   50, 
                   SCREEN_H-50,
                   ALLEGRO_ALIGN_CENTRE, 
                   display_ammo);

      al_flip_display();
      if (doexit)
        sleep(3);
    }
  }

  destroy_ship(ship);
  destroy_roids(last);
  destroy_blasts(blasts);

  /* End game. */

  al_shutdown_primitives_addon();
  al_destroy_timer(timer);
  al_destroy_display(display);
  al_destroy_event_queue(event_queue);

  return 0;
}