Esempio n. 1
0
File: main.c Progetto: odrevet/GE
game_status state_game_over(SDL_Surface *screen, game* p_game)
{
  bool done=false;
  image* game_over;
  game_over = image_load("./res/images/game_over.png");

  SDL_Rect srcrect = {0,0,160,144};
  SDL_Rect dstrect = set_rect(0,0,SCREEN_HEIGHT,SCREEN_WIDTH);

  while (!done)
    {
      //events
      SDL_Event event;
      while (SDL_PollEvent(&event))
        {
	  switch ( event.type )
            {
            case SDL_QUIT:
	      done = true;
	      break;
            case SDL_KEYUP:
	      switch ( event.key.keysym.sym )
                {
                default:break;
                }
            default:break;
            }
        }
      image_draw(game_over, get_backbuffer_surface(), 0, 0);
      SDL_SoftStretch(get_backbuffer_surface(), &srcrect, screen, &dstrect);
      SDL_Flip(screen);
    }

  return MAIN_MENU;
}
Esempio n. 2
0
ButtonPanel::ButtonPanel(Server* s, const Vector2i& pos) :
  RectComponent(Rect()),
  server(s),
  background("core/buttons/buttonbackground"),
  highlight("core/buttons/buttonbackgroundhl"),
  buttons(),
  current_button(0),
  show_tip(false),
  tip_button(0)
{
  ActionHolder* aholder = server->get_action_holder();

  std::vector<ActionName::Enum> actions = aholder->get_available_actions();

  set_rect(Rect(Vector2i(pos.x, pos.y - (actions.size() * 38)/2),
                Size(60, actions.size() * 38)));

  // Sort the action so that they always have the same order in the panel
  std::sort(actions.begin(), actions.end());

  for(std::vector<ActionName::Enum>::size_type i = 0; i < actions.size(); ++i)
  {
    ActionButton button;
    button.name   = actions[i];
    button.sprite = Sprite("pingus/player0/" + ActionName::to_string(button.name) + "/right");
    button.sprite.set_hotspot(origin_center, 0, 0);
    button.sprite.set_play_loop(true);
    buttons.push_back(button);
  }
}
	ground(const sf::Vector2f& windims, const float divis, const sf::Color& color)
		: m_windims(windims), m_divis(divis), m_side(m_windims.y/m_divis),
		  m_posit(0.0f, m_windims.y - m_side), m_dims(m_windims.x, m_side), m_color(color),
		  m_rect()
	{
		  set_rect();
	}
Esempio n. 4
0
File: event.c Progetto: odrevet/GE
bool event_exec_text(event *p_event, struct t_game* p_game)
{
  event_text *data = (event_text*)p_event->data;

  bool done=false;
  SDL_Event event;
  SDL_Rect srcrect = {0,0,160,144};                               //the part of the screen to be stretched, must be sup 0 and inf screen surface Height and Width
  SDL_Rect dstrect = set_rect(0,0,SCREEN_HEIGHT,SCREEN_WIDTH);    //equals screen resolution

  message_box* p_message_box = NULL;
  p_message_box = gui_new_message_box(p_message_box, data->text, 0, 144-32, 32, 160, 0, 146, 30);
  p_message_box->p_font = font_load("res/fonts/saxmono.ttf", 10);
  p_message_box->border = 0;
  p_message_box->border_color = 999;
  p_message_box->radius = 0;

  while (!done){
    while (SDL_PollEvent (&event)){
      switch (event.type){
      case SDL_KEYDOWN:
	if(event.key.keysym.sym==SDLK_SPACE){
	  done = true;
	}
	break;
      case SDL_QUIT:
	exit(0);
	break;
      case SDL_JOYBUTTONDOWN:
	switch(event.jbutton.button)
	  {
	  case 0:
	    break;
	  case 1:
	    break;
	  case 2:
	    break;
	  case 3:
	    done = true;
	    break;
	  case 4:
	    break;
	  case 5:
	    break;
	  case 6:
	    break;
	  }
      }
    }

    gui_message_box_draw(p_message_box, get_backbuffer_surface());
    SDL_SoftStretch(backbuffer,&srcrect,SDL_GetVideoSurface(),&dstrect);
    SDL_Flip(SDL_GetVideoSurface());
  }

  gui_message_box_free(p_message_box);

  return true;
}
Esempio n. 5
0
File: item.c Progetto: odrevet/GE
interro_block* interro_block_new(item_type type, int number)
{
  interro_block* p_ib = malloc(sizeof(interro_block));
  p_ib->item = type;
  p_ib->number = number;
  p_ib->p_sprite = malloc(sizeof(anim_sprite));
  p_ib->p_sprite->p_image = gfx_item;
  anim_sprite_init(p_ib->p_sprite, 80, TILE_HEIGHT * 9 + 8, 3, 1, 0, 0, 1);

  p_ib->p_sprite->v_anim = malloc(p_ib->p_sprite->animation_nb * sizeof(animation));
  animation_init(p_ib->p_sprite->v_anim+0, 1, 3, 20, 0);
  p_ib->p_sprite->v_anim[0].v_frame = malloc( p_ib->p_sprite->v_anim[0].frame_nb * sizeof(SDL_Rect));
  p_ib->p_sprite->v_anim[0].v_frame[0] = set_rect(0, 0, 16, 16);
  p_ib->p_sprite->v_anim[0].v_frame[1] = set_rect(16, 0, 16, 16);
  p_ib->p_sprite->v_anim[0].v_frame[2] = set_rect(32, 0, 16, 16);

  return p_ib;
}
Esempio n. 6
0
File: main.c Progetto: odrevet/GE
int eventFilter( const SDL_Event *e )
{
  if( e->type == SDL_VIDEORESIZE )
    {
      SDL_SetVideoMode(e->resize.w,e->resize.h,0,SDL_ANYFORMAT);

      dstrect = set_rect(0,0,e->resize.h,e->resize.w);
    }
  return 1;
}
Esempio n. 7
0
void sbox_set_mid_rect(control_t *p_ctrl,
  s16 left, s16 top, s16 right, s16 bottom)
{
  ctrl_sbox_data_t *p_data = NULL;

  MT_ASSERT(p_ctrl != NULL);

  p_data = (ctrl_sbox_data_t *)p_ctrl->priv_data;
  set_rect(&p_data->mid_rect, left, top, right, bottom);
}
Esempio n. 8
0
File: ennemie.c Progetto: odrevet/GE
void ennemie_init(ennemie* p_ennemie, ennemie_type type, int x, int y)
{
  p_ennemie->type = type;
  p_ennemie->p_sprite = malloc(sizeof(anim_sprite));

  p_ennemie->p_sprite->vel_x = -1;
  p_ennemie->p_sprite->vel_y = 0;
  
  p_ennemie->speed = 1;
  p_ennemie->dir = LEFT;

  p_ennemie->p_sprite->p_image = gfx_ennemie;

  p_ennemie->p_sprite->x = x * TILE_WIDTH;
  p_ennemie->p_sprite->y = y * TILE_HEIGHT;

  p_ennemie->p_sprite->offset.x = 0;
  p_ennemie->p_sprite->offset.y = 4;
  p_ennemie->p_sprite->offset.h = 12;
  p_ennemie->p_sprite->offset.w = 16;

  p_ennemie->p_sprite->animation_nb = 1;
  p_ennemie->p_sprite->v_anim = malloc(p_ennemie->p_sprite->animation_nb * sizeof(animation));
  p_ennemie->p_sprite->animation_current = 0;

  p_ennemie->p_sprite->v_anim[0].frame_nb = 2;
  p_ennemie->p_sprite->v_anim[0].frame_delay = 8;
  p_ennemie->p_sprite->v_anim[0].frame_trigger = 0;
  p_ennemie->p_sprite->v_anim[0].frame_default = 1;
  p_ennemie->p_sprite->v_anim[0].frame_current = 1;
  p_ennemie->p_sprite->v_anim[0].v_frame = malloc(p_ennemie->p_sprite->v_anim[0].frame_nb * sizeof(SDL_Rect));
  p_ennemie->p_sprite->v_anim[0].v_frame[0] = set_rect(0, 0, 16, 16);
  p_ennemie->p_sprite->v_anim[0].v_frame[1] = set_rect(16, 0, 16, 16);

  p_ennemie->p_sprite->tile_height=16;
  p_ennemie->p_sprite->tile_width=16;

  p_ennemie->p_sprite->frame_nb_x = p_ennemie->p_sprite->p_image->width / p_ennemie->p_sprite->tile_width;
  p_ennemie->p_sprite->frame_nb_y = p_ennemie->p_sprite->p_image->height / p_ennemie->p_sprite->tile_height;

}
Esempio n. 9
0
File: unit.c Progetto: odrevet/GE
struct bomb_t* unit_put_bomb(unit *p_unit, map *p_map)
{
    int index_x = unit_get_bounding_index_center_x(p_unit);
    int index_y = unit_get_bounding_index_center_y(p_unit);

    //Create the bomb
    bomb *p_bomb = malloc(sizeof(bomb));
    p_bomb->power = p_unit->power;
    p_bomb->time_left = BOMB_TIMER;
    p_bomb->type = NORMAL;
    p_bomb->p_owner = p_unit;
    p_bomb->p_sprite = malloc(sizeof(anim_sprite));
    //p_bomb->p_sprite->p_image = image_load("res/bomb.png");
    p_bomb->p_sprite->p_image = (image*)res_get(images, "bomb")->data;

    p_bomb->p_sprite->frame_nb_x = 3;
    p_bomb->p_sprite->frame_nb_y = 1;
    p_bomb->p_sprite->animation_nb = 0;
    p_bomb->p_sprite->animation_current = 0;

    p_bomb->p_sprite->v_anim = malloc(p_unit->p_sprite->animation_nb * sizeof(animation));

    p_bomb->p_sprite->v_anim[0].frame_current = 0;
    p_bomb->p_sprite->v_anim[0].frame_nb = 4;
    p_bomb->p_sprite->v_anim[0].frame_delay = BOMB_TIMER / 9;       //Breath 3 times
    p_bomb->p_sprite->v_anim[0].frame_trigger = 0;
    p_bomb->p_sprite->v_anim[0].v_frame = malloc(p_bomb->p_sprite->v_anim[0].frame_nb * sizeof(SDL_Rect));
    p_bomb->p_sprite->v_anim[0].v_frame[0] = set_rect(0, 0, 32, 32);
    p_bomb->p_sprite->v_anim[0].v_frame[1] = set_rect(32, 0, 32, 32);
    p_bomb->p_sprite->v_anim[0].v_frame[2] = set_rect(64, 0, 32, 32);
    p_bomb->p_sprite->v_anim[0].v_frame[3] = set_rect(32, 0, 32, 32);


    //image_set_transp_color(p_bomb->p_sprite->p_image, 255, 0, 255);
    p_bomb->p_sprite->x = index_x * TILE_SIZE;
    p_bomb->p_sprite->y = index_y * TILE_SIZE;

    p_map->pp_tile[index_y][index_x].type = BOMB;

    return (struct bomb_t*)p_bomb;
}
Esempio n. 10
0
File: unit.c Progetto: odrevet/GE
void unit_calc_bounding_box(unit *p_unit)
{
    int x = unit_get_x(p_unit);
    int y = unit_get_y(p_unit);
    int offset_x = p_unit->p_sprite->offset.x;
    int offset_y = p_unit->p_sprite->offset.y;
    int offset_h = p_unit->p_sprite->offset.h;
    int offset_w = p_unit->p_sprite->offset.w;

    p_unit->p_sprite->bounding_box = set_rect(offset_x + x,
					      offset_y + y,
					      offset_h,
					      offset_w);
}
Esempio n. 11
0
File: main.c Progetto: odrevet/GE
game_status state_main_menu(SDL_Surface *screen, game* p_game)
{
  bool done=false;
  image* main_title;
  main_title = image_load("./res/images/main_title.png");
  SDL_Rect srcrect = {0,0,160,144};
  SDL_Rect dstrect = set_rect(0,0,SCREEN_HEIGHT,SCREEN_WIDTH);
  int next_state=STAY;
  while (!done)
    {
      //events
      SDL_Event event;
      while (SDL_PollEvent(&event))
        {
	  switch ( event.type )
            {
            case SDL_QUIT:
	      done = true;
	      break;
            default:
	      break;
            }
        }

      image_draw(main_title, get_backbuffer_surface(), 0, 0);
      SDL_SoftStretch(get_backbuffer_surface(), &srcrect, screen, &dstrect);
      SDL_Flip(screen);

      if(next_state == STAY)next_state = menu_main(screen, p_game);
      else if(next_state!=QUIT){
	switch(next_state){
	case LOAD:
	  menu_load(screen, &p_game);
	  next_state = state_in_game(screen, p_game);
	  break;
	case 1:
	  p_game = game_load("./res/scripts/state.xml");
	  next_state = state_in_game(screen, p_game);
	  break;
	default:
	  break;
	}
      }
      else if(next_state==QUIT)done=true;
    }

  image_free(main_title);

  return QUIT;
}
Esempio n. 12
0
void text_set_mid_rect(control_t *p_ctrl,
  s16 left, s16 top, u16 width, u16 height)
{
  ctrl_text_data_t *p_data = NULL;
  rect_t frame;

  MT_ASSERT(p_ctrl != NULL);

  ctrl_get_frame(p_ctrl, &frame);

  MT_ASSERT((left + width) <= RECTW(frame));
  MT_ASSERT((top + height) <= RECTH(frame));

  p_data = (ctrl_text_data_t *)p_ctrl->priv_data;
  set_rect(&p_data->mid_rect, left, top, (s16)(left + width),
           (s16)(top + height));
}
Esempio n. 13
0
void unlccomp_rect(VRaster *r,void *ucbuf, LONG pixsize,
			Coor xorg, Coor yorg, Ucoor width, Ucoor height)
{
/*
   Uncompress data into a rectangular area inside raster using
   byte-run-length/delta compression scheme used in Autodesk Animator 1.0
   for most frames except the first.
   (Unclipped.)
*/

static short   x,y;
static short   lines;
static char    opcount;
static short   psize;
static char    *cpt;
static short   *wpt;


    wpt = (short *) ucbuf;
    cpt = (char *)(wpt+2); /* Data starts with 2 16 bit quantities then bytes */
    y = yorg + *wpt++;

    lines = *wpt++;
    while (--lines >= 0) {
	x = xorg;
	opcount = *cpt++;
	while (opcount > 0) {
	    x += *cpt++;
	    psize = *cpt++;
	    if (psize & 0x80) {
		psize = 256 - psize;
		set_rect(r, *cpt++, x, y, psize, 1);
		x += psize;
		opcount -= 1;
	    } else {
		put_rectpix(r, cpt, x, y, psize, 1);
		cpt += psize;
		x += psize;
		opcount -= 1;
	    }
	}
	y++;
    }
}
Esempio n. 14
0
static BOOL _sbox_get_item_rect(control_t *p_ctrl, u16 index, rect_t *p_rect)
{
  ctrl_sbox_data_t *p_data = NULL;
  u16 left = 0, top = 0, height = 0, width = 0;

  MT_ASSERT(p_ctrl != NULL);

  p_data = (ctrl_sbox_data_t *)p_ctrl->priv_data;

  if(index >= p_data->total)
  {
    return FALSE;
  }

  left = *(p_data->p_left + index);
  top = p_data->mid_rect.top;
  height = (p_data->mid_rect.bottom - p_data->mid_rect.top);
  width = *(p_data->p_width + index);

  set_rect(p_rect, left, top, (s16)(left + width), (s16)(top + height));
  return TRUE;
}
Esempio n. 15
0
static void test_color_brush(void)
{
    D2D1_MATRIX_3X2_F matrix, tmp_matrix;
    D2D1_BRUSH_PROPERTIES brush_desc;
    D2D1_COLOR_F color, tmp_color;
    ID2D1SolidColorBrush *brush;
    IDXGISwapChain *swapchain;
    ID2D1RenderTarget *rt;
    ID3D10Device1 *device;
    IDXGISurface *surface;
    D2D1_RECT_F rect;
    float opacity;
    HWND window;
    HRESULT hr;

    if (!(device = create_device()))
    {
        skip("Failed to create device, skipping tests.\n");
        return;
    }
    window = CreateWindowA("static", "d2d1_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
            0, 0, 640, 480, NULL, NULL, NULL, NULL);
    swapchain = create_swapchain(device, window, TRUE);
    hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_IDXGISurface, (void **)&surface);
    ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
    rt = create_render_target(surface);
    ok(!!rt, "Failed to create render target.\n");

    ID2D1RenderTarget_SetDpi(rt, 192.0f, 48.0f);
    ID2D1RenderTarget_SetAntialiasMode(rt, D2D1_ANTIALIAS_MODE_ALIASED);

    set_color(&color, 0.0f, 0.0f, 0.0f, 0.0f);
    hr = ID2D1RenderTarget_CreateSolidColorBrush(rt, &color, NULL, &brush);
    ok(SUCCEEDED(hr), "Failed to create brush, hr %#x.\n", hr);
    opacity = ID2D1SolidColorBrush_GetOpacity(brush);
    ok(opacity == 1.0f, "Got unexpected opacity %.8e.\n", opacity);
    set_matrix_identity(&matrix);
    ID2D1SolidColorBrush_GetTransform(brush, &tmp_matrix);
    ok(!memcmp(&tmp_matrix, &matrix, sizeof(matrix)),
            "Got unexpected matrix {%.8e, %.8e, %.8e, %.8e, %.8e, %.8e}.\n",
            tmp_matrix._11, tmp_matrix._12, tmp_matrix._21,
            tmp_matrix._22, tmp_matrix._31, tmp_matrix._32);
    tmp_color = ID2D1SolidColorBrush_GetColor(brush);
    ok(!memcmp(&tmp_color, &color, sizeof(color)),
            "Got unexpected color {%.8e, %.8e, %.8e, %.8e}.\n",
            tmp_color.r, tmp_color.g, tmp_color.b, tmp_color.a);
    ID2D1SolidColorBrush_Release(brush);

    set_color(&color, 0.0f, 1.0f, 0.0f, 0.8f);
    brush_desc.opacity = 0.3f;
    set_matrix_identity(&matrix);
    scale_matrix(&matrix, 2.0f, 2.0f);
    brush_desc.transform = matrix;
    hr = ID2D1RenderTarget_CreateSolidColorBrush(rt, &color, &brush_desc, &brush);
    ok(SUCCEEDED(hr), "Failed to create brush, hr %#x.\n", hr);
    opacity = ID2D1SolidColorBrush_GetOpacity(brush);
    ok(opacity == 0.3f, "Got unexpected opacity %.8e.\n", opacity);
    ID2D1SolidColorBrush_GetTransform(brush, &tmp_matrix);
    ok(!memcmp(&tmp_matrix, &matrix, sizeof(matrix)),
            "Got unexpected matrix {%.8e, %.8e, %.8e, %.8e, %.8e, %.8e}.\n",
            tmp_matrix._11, tmp_matrix._12, tmp_matrix._21,
            tmp_matrix._22, tmp_matrix._31, tmp_matrix._32);
    tmp_color = ID2D1SolidColorBrush_GetColor(brush);
    ok(!memcmp(&tmp_color, &color, sizeof(color)),
            "Got unexpected color {%.8e, %.8e, %.8e, %.8e}.\n",
            tmp_color.r, tmp_color.g, tmp_color.b, tmp_color.a);

    ID2D1RenderTarget_BeginDraw(rt);

    set_color(&color, 0.0f, 0.0f, 1.0f, 1.0f);
    ID2D1RenderTarget_Clear(rt, &color);

    ID2D1SolidColorBrush_SetOpacity(brush, 1.0f);
    set_rect(&rect, 40.0f, 120.0f, 120.0f, 360.0f);
    ID2D1RenderTarget_FillRectangle(rt, &rect, (ID2D1Brush *)brush);

    set_matrix_identity(&matrix);
    scale_matrix(&matrix, 0.5f, 2.0f);
    translate_matrix(&matrix, 320.0f, 240.0f);
    rotate_matrix(&matrix, M_PI / 4.0f);
    ID2D1RenderTarget_SetTransform(rt, &matrix);
    set_color(&color, 1.0f, 0.0f, 0.0f, 0.625f);
    ID2D1SolidColorBrush_SetColor(brush, &color);
    ID2D1SolidColorBrush_SetOpacity(brush, 0.75f);
    set_rect(&rect, -80.0f, -60.0f, 80.0f, 60.0f);
    ID2D1RenderTarget_FillRectangle(rt, &rect, (ID2D1Brush *)brush);

    hr = ID2D1RenderTarget_EndDraw(rt, NULL, NULL);
    ok(SUCCEEDED(hr), "Failed to end draw, hr %#x.\n", hr);
    ok(compare_surface(surface, "6d1218fca5e21fb7e287b3a439d60dbc251f5ceb"), "Surface does not match.\n");

    ID2D1SolidColorBrush_Release(brush);
    ID2D1RenderTarget_Release(rt);
    IDXGISurface_Release(surface);
    IDXGISwapChain_Release(swapchain);
    ID3D10Device1_Release(device);
    DestroyWindow(window);
}
Esempio n. 16
0
File: menu.c Progetto: odrevet/GE
int menu_main(SDL_Surface* destination, game *p_game){
  bool menu_done=false;
  SDL_Event event;
  int choice_current=0;
  int choice_nb = 2;
  message_box* p_menu = NULL;
  p_menu = gui_new_message_box(p_menu, "  Load\n  New Game\n", 30, 70, 40, 100, 0, 0, 30);
  p_menu->p_font = font_load("res/fonts/saxmono.ttf", 12);
  p_menu->border = 5;
  p_menu->border_color = 342;
  p_menu->radius = 10;

  image* p_cursor=image_load("./res/chipsets/cursor.png");
  image_set_transp_color(p_cursor, 255, 0, 255);

  SDL_Joystick* joystick;
  joystick = SDL_JoystickOpen(0);
  //cursor coords
  int src_x = 0;
  int src_y = 0;
  int dest_x = p_menu->x + 2;
  int dest_y = p_menu->y + 5;

  while(!menu_done){
    SDL_Rect srcrect = {0,0,160,144};                               //the part of the screen to be stretched, must be sup 0 and inf screen surface Height and Width
    SDL_Rect dstrect = set_rect(0,0,SCREEN_HEIGHT,SCREEN_WIDTH);    //equals screen resolution
    gui_message_box_draw(p_menu, get_backbuffer_surface());
    image_draw_part(p_cursor, get_backbuffer_surface(), dest_x, dest_y, src_x, src_y, 16, 16);
    SDL_SoftStretch(backbuffer,&srcrect,SDL_GetVideoSurface(),&dstrect);
    SDL_Flip(destination);

    while (SDL_PollEvent(&event)){
      switch ( event.type ){

      case SDL_JOYBUTTONDOWN:
	switch(event.jbutton.button)
	  {
	  case 0:
	    break;
	  case 1:
	    break;
	  case 2:
	    src_x = 16;
	    menu_done = true;
	    image_draw_part(p_cursor, get_backbuffer_surface(), dest_x, dest_y, src_x, src_y, 16, 16);
	    SDL_SoftStretch(backbuffer,&srcrect,SDL_GetVideoSurface(),&dstrect);
	    SDL_Flip(SDL_GetVideoSurface());
	    SDL_Delay(200);
	    break;
	  case 3:
	    break;
	  case 4:
	    break;
	  case 5:
	    break;
	  case 6:
	    break;
	  }

      case SDL_KEYUP:
	switch ( event.key.keysym.sym ){
	case SDLK_RETURN:
	  src_x = 16;
	  menu_done = true;
	  image_draw_part(p_cursor, get_backbuffer_surface(), dest_x, dest_y, src_x, src_y, 16, 16);
	  SDL_SoftStretch(backbuffer,&srcrect,SDL_GetVideoSurface(),&dstrect);
	  SDL_Flip(SDL_GetVideoSurface());
	  SDL_Delay(200);
	  break;
	case SDLK_UP:
	  if (choice_current > 0){
	    choice_current--;
	    dest_y -= TTF_FontLineSkip(p_menu->p_font);
	  }
	  else{
	    //play sound error
	  }
	  break;
	case SDLK_DOWN:
	  if (choice_current < choice_nb-1){
	    choice_current++;
	    dest_y += TTF_FontLineSkip(p_menu->p_font);
	  }
	  else{
	    //play sound error
	  }
	  break;
	default:
	  break;


	}
	break;
      default:
	break;
      }
    }

    int joystate = SDL_JoystickGetHat(joystick, 0);
    switch (joystate){
    case SDL_HAT_DOWN:
      if (choice_current < choice_nb-1){
	choice_current++;
	dest_y += TTF_FontLineSkip(p_menu->p_font);
      }
      else{
	//play sound error
      }

      break;
    case SDL_HAT_UP:
      if (choice_current > 0){
	choice_current--;
	dest_y -= TTF_FontLineSkip(p_menu->p_font);
      }
      else{
	//play sound error
      }
      break;
    }

  }

  if(choice_current==0)choice_current=LOAD;       //index to next state

  SDL_JoystickClose(joystick);
  image_free(p_cursor);
  gui_message_box_free(p_menu);

  return choice_current;
}
Esempio n. 17
0
File: menu.c Progetto: odrevet/GE
int menu_start(SDL_Surface* destination, game *p_game)
{
  bool menu_done=false;
  bool timerset = false;

  SDL_Event event;
  int choice_current=0;
  int choice_nb = 3;
  message_box* p_menu = NULL;
  p_menu = gui_new_message_box(p_menu, "  Status\n  Save\n  Load", 12, 16, 70, 100, 0, 0, 30);
  //p_menu = gui_new_message_box(p_menu, "  Item\n  Status\n  Options\n  Save\n  Load", 12, 16, 70, 100, 0, 0, 30);
  p_menu->p_font = font_load("res/fonts/saxmono.ttf", 12);
  p_menu->border = 5;
  p_menu->border_color = 342;
  p_menu->radius = 10;

  image* p_cursor=image_load("./res/chipsets/cursor.png");
  image_set_transp_color(p_cursor, 255, 0, 255);

  //cursor coords
  int src_x = 0;
  int src_y = 0;
  int dest_x = p_menu->x + 2;
  int dest_y = p_menu->y + 5;

  while(!menu_done){
    SDL_Rect srcrect = {0,0,160,144};                               //the part of the screen to be stretched, must be sup 0 and inf screen surface Height and Width
    SDL_Rect dstrect = set_rect(0,0,SCREEN_HEIGHT,SCREEN_WIDTH);    //equals screen resolution
    gui_message_box_draw(p_menu, get_backbuffer_surface());
    image_draw_part(p_cursor, get_backbuffer_surface(), dest_x, dest_y, src_x, src_y, 16, 16);
    SDL_SoftStretch(backbuffer,&srcrect,SDL_GetVideoSurface(),&dstrect);
    SDL_Flip(SDL_GetVideoSurface());
    SDL_EnableKeyRepeat(10, 10);
    while (SDL_PollEvent(&event))
      {
	switch ( event.type )
	  {
	  case SDL_KEYUP:
	    switch ( event.key.keysym.sym ){
	    case SDLK_RETURN:
	      src_x = 16;
	      menu_done = true;
	      image_draw_part(p_cursor, get_backbuffer_surface(), dest_x, dest_y, src_x, src_y, 16, 16);
	      SDL_SoftStretch(backbuffer,&srcrect,SDL_GetVideoSurface(),&dstrect);
	      SDL_Flip(SDL_GetVideoSurface());
	      SDL_Delay(200);
	      break;
	    case SDLK_UP:
	      if (choice_current > 0){
		choice_current--;
		dest_y -= TTF_FontLineSkip(p_menu->p_font);
	      }
	      else{
		//play sound error
	      }
	      break;
	    case SDLK_DOWN:
	      if (choice_current < choice_nb-1){
		choice_current++;
		dest_y += TTF_FontLineSkip(p_menu->p_font);
	      }
	      else{
		//play sound error
	      }
	      break;
	    default:
	      break;
	    }
	  case SDL_JOYBUTTONDOWN:
	    switch(event.jbutton.button)
	      {
	      case 0:
		break;
	      case 1:
		break;
	      case 2:
		src_x = 16;
		menu_done = true;
		image_draw_part(p_cursor, get_backbuffer_surface(), dest_x, dest_y, src_x, src_y, 16, 16);
		SDL_SoftStretch(backbuffer,&srcrect,SDL_GetVideoSurface(),&dstrect);
		SDL_Flip(SDL_GetVideoSurface());
		SDL_Delay(200);
		break;
	      case 3:
		break;
	      case 4:
		break;
	      case 5:
		break;
	      case 6:
		break;
	      }

	    break;
	  default:
	    break;
	  }
      }


    unsigned int start;
    if (!timerset) {
      timerset=true;
      start=SDL_GetTicks();
    }

    unsigned int now=SDL_GetTicks();
    if ((now-start)>100) {
      timerset=false;
      SDL_JoystickUpdate();
      int joystate = SDL_JoystickGetHat(p_game->p_unit->joystick, 0);
      switch (joystate){
      case SDL_HAT_DOWN:
	if (choice_current < choice_nb-1){
	  choice_current++;
	  dest_y += TTF_FontLineSkip(p_menu->p_font);
	}
	else{
	  //play sound error
	}
	break;
      case SDL_HAT_UP:
	if (choice_current > 0){
	  choice_current--;
	  dest_y -= TTF_FontLineSkip(p_menu->p_font);
	}
	else{
	  //play sound error
	}
	break;
      }
    }

  }

  image_free(p_cursor);

  return choice_current;
}
Esempio n. 18
0
File: menu.c Progetto: odrevet/GE
int menu_status(SDL_Surface* destination, game *p_game){
  bool menu_done=false;
  SDL_Event event;

  char text[255];

  sprintf(text, "Name %s\nXP %d\n",  p_game->p_unit->name, p_game->p_unit->XP);
  message_box* p_menu = NULL;
  p_menu = gui_new_message_box(p_menu, text, 12, 16, 70, 100, 0, 0, 30);
  p_menu->p_font = font_load("res/fonts/saxmono.ttf", 12);
  p_menu->border = 5;
  p_menu->border_color = 342;
  p_menu->radius = 10;

  while(!menu_done){
    SDL_Rect srcrect = {0,0,160,144};                               //the part of the screen to be stretched, must be sup 0 and inf screen surface Height and Width
    SDL_Rect dstrect = set_rect(0,0,SCREEN_HEIGHT,SCREEN_WIDTH);    //equals screen resolution
    gui_message_box_draw(p_menu, get_backbuffer_surface());
    SDL_SoftStretch(backbuffer,&srcrect,SDL_GetVideoSurface(),&dstrect);
    SDL_Flip(SDL_GetVideoSurface());

    while (SDL_PollEvent(&event))
      {
	switch ( event.type )
	  {
	  case SDL_KEYUP:
	    switch ( event.key.keysym.sym ){
	    case SDLK_RETURN:
	      menu_done = true;
	      break;
	    default:
	      break;

	    }
	    break;
	  case SDL_JOYBUTTONDOWN:
	    switch(event.jbutton.button)
	      {
	      case 0:
		break;
	      case 1:
		menu_done = true;
		break;
	      case 2:
		break;
	      case 3:
		break;
	      case 4:
		break;
	      case 5:
		break;
	      case 6:
		break;
	      }
	  default:
	    break;
	  }
      }
  }
  return 1;
}
Esempio n. 19
0
File: main.c Progetto: odrevet/GE
game_status state_in_game(SDL_Surface *screen, game* p_game)
{
  int i=0;
  bool done=false;

  game_status ret_code = GAME_OVER;
  SDL_Rect srcrect = {0,0,160,144};
  dstrect = set_rect(0,0,SCREEN_HEIGHT,SCREEN_WIDTH);

#ifdef USE_LUA
  lua_State *L;
  L = lua_open();
  luaopen_base(L);
  luaL_openlibs(L);
  luaopen_globals(L);
  luaopen_game(L);
  luaopen_unit(L);
  luaopen_sprite(L);
  luaopen_var(L);
  luaopen_map(L);

  //register lua functions
  lua_register(L ,"say", script_lua_unit_say);
  lua_register(L ,"unit_get_x", script_lua_unit_get_x);
  lua_register(L ,"unit_get_y", script_lua_unit_get_y);
  lua_register(L ,"unit_set_index_x", script_lua_unit_set_index_x);
  lua_register(L ,"unit_set_index_y", script_lua_unit_set_index_y);
  lua_register(L ,"event_text", script_lua_event_exec_text);
  lua_register(L ,"event_teleport", script_lua_event_exec_teleport);
  lua_register(L ,"unit_set_life", script_lua_unit_set_life);
  lua_register(L ,"unit_set_speed", script_lua_unit_set_speed);

  p_game->L = L;
  g_game = p_game;
#endif


  long timelastcall=SDL_GetTicks();

  if(map_get_current(p_game->p_map, p_game->cur_map)->music != NULL){
    char* music = strdup(map_get_current(p_game->p_map, p_game->cur_map)->music);
    Mix_Music* ingame_music = music_load(music);
    music_play(ingame_music);
  }

  message_box* p_menu = NULL;
  p_menu = menu_ingame_create(p_game);
  bool action;

  while (!done)
    {
      action = false;
      SDL_Event event;
      SDL_JoystickUpdate();
      while (SDL_PollEvent(&event)){
	switch ( event.type ){
	case SDL_QUIT:
	  ret_code = QUIT;
	  done = true;
	  break;
	case SDL_KEYUP:
	  switch ( event.key.keysym.sym ){
	  case SDLK_RETURN:
	    switch(menu_start(get_backbuffer_surface(), p_game)){
	    case 0:
	      menu_status(get_backbuffer_surface(), p_game);
	      break;
	    case 1:
	      menu_save(get_backbuffer_surface(), p_game);
	      break;
	    case 2:
	      ret_code = LOAD;
	      done=true;
	      break;
	    }
	    break;
	  default:break;
	  }
	  break;
	case SDL_JOYBUTTONDOWN:
	  switch(event.jbutton.button){
	  case 0:
	    switch(menu_start(get_backbuffer_surface(), p_game)){
	    case 0:
	      menu_status(get_backbuffer_surface(), p_game);
	      break;
	    case 1:
	      menu_save(get_backbuffer_surface(), p_game);
	      break;
	    case 2:
	      ret_code = LOAD;
	      done=true;
	      break;
	    }
	    break;
	  case 2:
	    action = true;
	    break;
	  }
	  break;
	default:break;
	}

	unit_handle_key(p_game->p_unit, &event, p_game);
      }

      int joystate = SDL_JoystickGetHat(p_game->p_unit->joystick, 0);
      switch (joystate){
      case SDL_HAT_DOWN:
	unit_set_vel_y(p_game->p_unit, p_game->p_unit->speed);
	unit_set_vel_x(p_game->p_unit, 0);
	p_game->p_unit->p_sprite->animation_current = DOWN;
	p_game->p_unit->dir = DOWN;
	p_game->p_unit->current_action = NOTHING;

	break;
      case SDL_HAT_UP:
	unit_set_vel_y(p_game->p_unit, -p_game->p_unit->speed);
	unit_set_vel_x(p_game->p_unit, 0);
	p_game->p_unit->p_sprite->animation_current = UP;
	p_game->p_unit->dir = UP;
	p_game->p_unit->current_action = NOTHING;
	break;
      case SDL_HAT_RIGHT:
	unit_set_vel_x(p_game->p_unit, p_game->p_unit->speed);
	unit_set_vel_y(p_game->p_unit, 0);
	p_game->p_unit->p_sprite->animation_current = RIGHT;
	p_game->p_unit->dir = RIGHT;
	p_game->p_unit->current_action = NOTHING;
	break;
      case SDL_HAT_LEFT:
	unit_set_vel_x(p_game->p_unit, -p_game->p_unit->speed);
	unit_set_vel_y(p_game->p_unit, 0);
	p_game->p_unit->p_sprite->animation_current = LEFT;
	p_game->p_unit->dir = LEFT;
	p_game->p_unit->current_action = NOTHING;
	break;
      default:
	break;
      }

      //drawing
      SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0));
      map_draw(map_get_current(p_game->p_map, p_game->cur_map), backbuffer);

      if(p_game->p_unit->current_action == FIGHT){
	anim_sprite_draw(p_game->p_unit->weapon, get_backbuffer_surface());
      }

      anim_sprite_draw(p_game->p_unit->p_sprite, backbuffer);

      for(i=0;i<p_game->NPC_nb;i++){
	NPC_update(p_game->p_NPC+i, map_get_current(p_game->p_map, p_game->cur_map), p_game->p_unit);
	anim_sprite_draw(p_game->p_NPC[i].p_sprite, backbuffer);
      }

      for(i=0;i<p_game->ennemie_nb;i++){
	ennemie_update(p_game->p_ennemie+i, map_get_current(p_game->p_map, p_game->cur_map), p_game->p_unit);
	anim_sprite_draw(p_game->p_ennemie[i].p_sprite, backbuffer);
      }

      Uint8* key = SDL_GetKeyState(NULL);
      if(key[p_game->p_unit->key_b] || action){
	for(i=0;i<p_game->NPC_nb;i++){

	  if(sprite_intersect((sprite*)p_game->p_unit->p_sprite, (sprite*)p_game->p_NPC[i].p_sprite)){
	    struct t_event* p_event = malloc(sizeof(struct t_event));
	    p_event->is_auto = true;
	    p_event->p_next = NULL;
	    p_event->type = EVENT_SCRIPT;

	    event_script* p_event_script = malloc(sizeof(event_script));
	    p_event_script->language = strdup("lua");
	    p_event_script->script = strdup(p_game->p_NPC[i].script);
	    p_event_script->version = strdup("1.0");

	    p_event->data = p_event_script;
	    event_exec_script(p_event, p_game);

	    event_free(p_event);
	  }
	}
      }


      //logic
      sprite_calc_bounding_box((sprite*)p_game->p_unit->p_sprite, true);



      //events when entering a tile
      point* p_point_enter = unit_check_on_tile_enter(p_game->p_unit, map_get_current(p_game->p_map, p_game->cur_map));
      if( p_point_enter != NULL &&
	  map_get_current(p_game->p_map, p_game->cur_map)->pp_tile[p_point_enter->y][p_point_enter->x].p_event != NULL &&
	  map_get_current(p_game->p_map, p_game->cur_map)->pp_tile[p_point_enter->y][p_point_enter->x].p_event->is_auto){

	p_game->p_unit->p_sprite->v_anim[p_game->p_unit->p_sprite->animation_current].frame_current = 1;
	event_dispatch(map_get_current(p_game->p_map, p_game->cur_map)->pp_tile[p_point_enter->y][p_point_enter->x].p_event, p_game);
	free(p_point_enter);

      }

      map* p_cur_map = map_get_current(p_game->p_map, p_game->cur_map);

      if(SDL_GetTicks() - timelastcall>1000/40) {

	unit_update(p_game->p_unit, p_cur_map);

	for(i=0;i<p_game->ennemie_nb;i++){

	  //Check weapon / ennemie collides
	  if(p_game->p_unit->current_action == FIGHT){
	    if(sprite_intersect((sprite*)p_game->p_unit->weapon, (sprite*)p_game->p_ennemie[i].p_sprite)){
	      p_game->p_ennemie[i].HP--;
	      if(p_game->p_ennemie[i].HP <= 0){                       //ennemie dead
		//sound dead
		//animation dead
		p_game->p_unit->XP += p_game->p_ennemie[i].XP;      //increase unit status
		p_game->p_unit->gold += p_game->p_ennemie[i].gold;

		ennemie_remove(p_game->p_ennemie, i, &p_game->ennemie_nb);      //remove ennemie
		break;
	      }
	    }
	  }

	  //Check unit / ennemie collides
	  if(p_game->p_unit->invincible_time <= 0 && sprite_intersect((sprite*)p_game->p_unit->p_sprite, (sprite*)p_game->p_ennemie[i].p_sprite)){
	    //sample_play(unit_hitted);
	    p_game->p_unit->invincible_time = 40;
	    unit_hitted(p_game->p_unit, p_game->p_ennemie+i, p_cur_map);
	    if(p_game->p_unit->HP <= 0){
	      //sound dead
	      //animation dead
	      //message game over
	      ret_code = GAME_OVER;
	      done = true;
	      break;
	    }
	  }
	}

	//Game events
	menu_ingame_update(get_backbuffer_surface(), p_menu, p_game);

	//update timer
	timelastcall=SDL_GetTicks();
      }

#if RENDER == 3 && !GEKKO
      SDL_GL_SwapBuffers();
#else
      SDL_SoftStretch(backbuffer, &srcrect, screen, &dstrect);
      SDL_Flip(screen);
#endif

    }

  game_free(p_game);
  return ret_code;
}
Esempio n. 20
0
unit2::unit2(mkwin_controller& controller, mkwin_display& disp, unit_map& units, int type, unit* parent, const SDL_Rect& rect)
	: unit(controller, disp, units, type, parent, -1)
{
	set_rect(rect);
}
Esempio n. 21
0
File: d2d1.c Progetto: noruya/wine
static void test_bitmap_brush(void)
{
    D2D1_BITMAP_INTERPOLATION_MODE interpolation_mode;
    D2D1_MATRIX_3X2_F matrix, tmp_matrix;
    D2D1_BITMAP_PROPERTIES bitmap_desc;
    ID2D1Bitmap *bitmap, *tmp_bitmap;
    D2D1_RECT_F src_rect, dst_rect;
    D2D1_EXTEND_MODE extend_mode;
    IDXGISwapChain *swapchain;
    ID2D1BitmapBrush *brush;
    ID2D1RenderTarget *rt;
    ID3D10Device1 *device;
    IDXGISurface *surface;
    D2D1_COLOR_F color;
    D2D1_SIZE_U size;
    ULONG refcount;
    float opacity;
    HWND window;
    HRESULT hr;

    static const DWORD bitmap_data[] =
    {
        0xffff0000, 0xffffff00, 0xff00ff00, 0xff00ffff,
        0xff0000ff, 0xffff00ff, 0xff000000, 0xff7f7f7f,
        0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
        0xffffffff, 0xff000000, 0xff000000, 0xff000000,
    };

    if (!(device = create_device()))
    {
        skip("Failed to create device, skipping tests.\n");
        return;
    }
    window = CreateWindowA("static", "d2d1_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
            0, 0, 640, 480, NULL, NULL, NULL, NULL);
    swapchain = create_swapchain(device, window, TRUE);
    hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_IDXGISurface, (void **)&surface);
    ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
    rt = create_render_target(surface);
    ok(!!rt, "Failed to create render target.\n");

    ID2D1RenderTarget_SetDpi(rt, 192.0f, 48.0f);
    ID2D1RenderTarget_SetAntialiasMode(rt, D2D1_ANTIALIAS_MODE_ALIASED);

    set_size_u(&size, 4, 4);
    bitmap_desc.pixelFormat.format = DXGI_FORMAT_B8G8R8A8_UNORM;
    bitmap_desc.pixelFormat.alphaMode = D2D1_ALPHA_MODE_IGNORE;
    bitmap_desc.dpiX = 96.0f;
    bitmap_desc.dpiY = 96.0f;
    hr = ID2D1RenderTarget_CreateBitmap(rt, size, bitmap_data, 4 * sizeof(*bitmap_data), &bitmap_desc, &bitmap);
    ok(SUCCEEDED(hr), "Failed to create bitmap, hr %#x.\n", hr);

    /* Creating a brush with a NULL bitmap crashes on Vista, but works fine on
     * Windows 7+. */
    hr = ID2D1RenderTarget_CreateBitmapBrush(rt, bitmap, NULL, NULL, &brush);
    ok(SUCCEEDED(hr), "Failed to create brush, hr %#x.\n", hr);
    ID2D1BitmapBrush_GetBitmap(brush, &tmp_bitmap);
    ok(tmp_bitmap == bitmap, "Got unexpected bitmap %p, expected %p.\n", tmp_bitmap, bitmap);
    ID2D1Bitmap_Release(tmp_bitmap);
    opacity = ID2D1BitmapBrush_GetOpacity(brush);
    ok(opacity == 1.0f, "Got unexpected opacity %.8e.\n", opacity);
    set_matrix_identity(&matrix);
    ID2D1BitmapBrush_GetTransform(brush, &tmp_matrix);
    ok(!memcmp(&tmp_matrix, &matrix, sizeof(matrix)),
            "Got unexpected matrix {%.8e, %.8e, %.8e, %.8e, %.8e, %.8e}.\n",
            tmp_matrix._11, tmp_matrix._12, tmp_matrix._21,
            tmp_matrix._22, tmp_matrix._31, tmp_matrix._32);
    extend_mode = ID2D1BitmapBrush_GetExtendModeX(brush);
    ok(extend_mode == D2D1_EXTEND_MODE_CLAMP, "Got unexpected extend mode %#x.\n", extend_mode);
    extend_mode = ID2D1BitmapBrush_GetExtendModeY(brush);
    ok(extend_mode == D2D1_EXTEND_MODE_CLAMP, "Got unexpected extend mode %#x.\n", extend_mode);
    interpolation_mode = ID2D1BitmapBrush_GetInterpolationMode(brush);
    ok(interpolation_mode == D2D1_BITMAP_INTERPOLATION_MODE_LINEAR,
            "Got unexpected interpolation mode %#x.\n", interpolation_mode);
    ID2D1BitmapBrush_Release(brush);

    hr = ID2D1RenderTarget_CreateBitmapBrush(rt, bitmap, NULL, NULL, &brush);
    ok(SUCCEEDED(hr), "Failed to create brush, hr %#x.\n", hr);
    set_matrix_identity(&matrix);
    translate_matrix(&matrix, 40.0f, 120.0f);
    scale_matrix(&matrix, 20.0f, 60.0f);
    ID2D1BitmapBrush_SetTransform(brush, &matrix);
    ID2D1BitmapBrush_SetInterpolationMode(brush, D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR);

    ID2D1RenderTarget_BeginDraw(rt);

    set_color(&color, 0.0f, 0.0f, 1.0f, 1.0f);
    ID2D1RenderTarget_Clear(rt, &color);

    set_rect(&dst_rect, 40.0f, 120.0f, 120.0f, 360.0f);
    ID2D1RenderTarget_FillRectangle(rt, &dst_rect, (ID2D1Brush *)brush);

    set_matrix_identity(&matrix);
    scale_matrix(&matrix, 0.5f, 2.0f);
    translate_matrix(&matrix, 320.0f, 240.0f);
    rotate_matrix(&matrix, M_PI / 4.0f);
    ID2D1RenderTarget_SetTransform(rt, &matrix);
    set_matrix_identity(&matrix);
    translate_matrix(&matrix, -80.0f, -60.0f);
    scale_matrix(&matrix, 40.0f, 30.0f);
    ID2D1BitmapBrush_SetTransform(brush, &matrix);
    ID2D1BitmapBrush_SetOpacity(brush, 0.75f);
    set_rect(&dst_rect, -80.0f, -60.0f, 80.0f, 60.0f);
    ID2D1RenderTarget_FillRectangle(rt, &dst_rect, (ID2D1Brush *)brush);

    set_matrix_identity(&matrix);
    translate_matrix(&matrix, 200.0f, 120.0f);
    scale_matrix(&matrix, 20.0f, 60.0f);
    ID2D1RenderTarget_SetTransform(rt, &matrix);
    ID2D1RenderTarget_DrawBitmap(rt, bitmap, NULL, 0.25f,
            D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR, NULL);
    set_rect(&dst_rect, -4.0f, 12.0f, -8.0f, 8.0f);
    ID2D1RenderTarget_DrawBitmap(rt, bitmap, &dst_rect, 0.75f,
            D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR, NULL);
    set_rect(&dst_rect, 0.0f, 8.0f, 4.0f, 12.0f);
    set_rect(&src_rect, 2.0f, 1.0f, 4.0f, 3.0f);
    ID2D1RenderTarget_DrawBitmap(rt, bitmap, &dst_rect, 1.0f,
            D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR, &src_rect);

    hr = ID2D1RenderTarget_EndDraw(rt, NULL, NULL);
    ok(SUCCEEDED(hr), "Failed to end draw, hr %#x.\n", hr);
    ok(compare_surface(surface, "393636185359a550d459e1e5f0e25411814f724c"), "Surface does not match.\n");

    ID2D1BitmapBrush_Release(brush);
    refcount = ID2D1Bitmap_Release(bitmap);
    ok(!refcount, "Bitmap has %u references left.\n", refcount);
    ID2D1RenderTarget_Release(rt);
    IDXGISurface_Release(surface);
    IDXGISwapChain_Release(swapchain);
    ID3D10Device1_Release(device);
    DestroyWindow(window);
}
Esempio n. 22
0
File: unit.c Progetto: odrevet/GE
void unit_init(unit *v_unit, int unit_nb)
{
    int k;
    char sz_charset_name[32];
    for (k=0;k<unit_nb;k++)
    {
        sprintf(sz_charset_name, "res/Charset_%d.png", k);

        v_unit[k].p_sprite = malloc(sizeof(anim_sprite));
        v_unit[k].p_sprite->p_image = image_load(sz_charset_name);
        image_set_transp_color(v_unit[k].p_sprite->p_image, 255, 0, 255);

        v_unit[k].victory = 0;

        v_unit[k].p_sprite->offset.x = 6;
        v_unit[k].p_sprite->offset.y = 16;
        v_unit[k].p_sprite->offset.h = 24;
        v_unit[k].p_sprite->offset.w = 22;

        v_unit[k].p_sprite->animation_nb = 4;
        v_unit[k].p_sprite->frame_nb_x = 3;
        v_unit[k].p_sprite->frame_nb_y = 4;
        v_unit[k].p_sprite->v_anim = malloc(v_unit[k].p_sprite->animation_nb * sizeof(animation));

        v_unit[k].p_sprite->v_anim[UP].frame_nb = 4;
        v_unit[k].p_sprite->v_anim[UP].frame_delay = 5;
        v_unit[k].p_sprite->v_anim[UP].frame_trigger = 0;
        v_unit[k].p_sprite->v_anim[UP].frame_current = 1;
        v_unit[k].p_sprite->v_anim[UP].v_frame = malloc(v_unit[k].p_sprite->v_anim[UP].frame_nb * sizeof(SDL_Rect));
        v_unit[k].p_sprite->v_anim[UP].v_frame[0] = set_rect(6, 18, 34, 44);
        v_unit[k].p_sprite->v_anim[UP].v_frame[1] = set_rect(56, 18, 34, 44);
        v_unit[k].p_sprite->v_anim[UP].v_frame[2] = set_rect(104, 18, 34, 44);
        v_unit[k].p_sprite->v_anim[UP].v_frame[3] = set_rect(56, 18, 34, 44);

        v_unit[k].p_sprite->v_anim[DOWN].frame_nb = 4;
        v_unit[k].p_sprite->v_anim[DOWN].frame_delay = 5;
        v_unit[k].p_sprite->v_anim[DOWN].frame_trigger = 0;
        v_unit[k].p_sprite->v_anim[DOWN].frame_current = 1;
        v_unit[k].p_sprite->v_anim[DOWN].v_frame = malloc(v_unit[k].p_sprite->v_anim[DOWN].frame_nb * sizeof(SDL_Rect));
        v_unit[k].p_sprite->v_anim[DOWN].v_frame[0] = set_rect(8, 146, 34, 44);
        v_unit[k].p_sprite->v_anim[DOWN].v_frame[1] = set_rect(56, 146, 34, 44);
        v_unit[k].p_sprite->v_anim[DOWN].v_frame[2] = set_rect(102, 146, 34, 44);
        v_unit[k].p_sprite->v_anim[DOWN].v_frame[3] = set_rect(56, 146, 34, 44);

        v_unit[k].p_sprite->v_anim[LEFT].frame_nb = 4;
        v_unit[k].p_sprite->v_anim[LEFT].frame_delay = 5;
        v_unit[k].p_sprite->v_anim[LEFT].frame_trigger = 0;
        v_unit[k].p_sprite->v_anim[LEFT].frame_current = 1;
        v_unit[k].p_sprite->v_anim[LEFT].v_frame = malloc(v_unit[k].p_sprite->v_anim[LEFT].frame_nb * sizeof(SDL_Rect));
        v_unit[k].p_sprite->v_anim[LEFT].v_frame[0] = set_rect(6, 210, 36, 44);
        v_unit[k].p_sprite->v_anim[LEFT].v_frame[1] = set_rect(56, 210, 36, 44);
        v_unit[k].p_sprite->v_anim[LEFT].v_frame[2] = set_rect(104, 210, 34, 44);
        v_unit[k].p_sprite->v_anim[LEFT].v_frame[3] = set_rect(56, 210, 36, 44);

        v_unit[k].p_sprite->v_anim[RIGHT].frame_nb = 4;
        v_unit[k].p_sprite->v_anim[RIGHT].frame_delay = 5;
        v_unit[k].p_sprite->v_anim[RIGHT].frame_trigger = 0;
        v_unit[k].p_sprite->v_anim[RIGHT].frame_current = 1;
        v_unit[k].p_sprite->v_anim[RIGHT].v_frame = malloc(v_unit[k].p_sprite->v_anim[RIGHT].frame_nb * sizeof(SDL_Rect));
        v_unit[k].p_sprite->v_anim[RIGHT].v_frame[0] = set_rect(6, 82, 34, 44);
        v_unit[k].p_sprite->v_anim[RIGHT].v_frame[1] = set_rect(52, 82, 36, 44);
        v_unit[k].p_sprite->v_anim[RIGHT].v_frame[2] = set_rect(102, 82, 36, 44);
        v_unit[k].p_sprite->v_anim[RIGHT].v_frame[3] = set_rect(52, 82, 36, 44);

	v_unit[k].p_sprite->h_flip = false;

        snprintf(v_unit[k].name, 10, "Guy %d", k+1);		//sNprintf to avoid blastguy's stack overflow exploit ;)

        #ifdef GEKKO
            v_unit[k].use_keyboard = false;
            v_unit[k].joystick = SDL_JoystickOpen(k);

        #else
            v_unit[k].use_keyboard = true;
        #endif

        //Key bind
        if (k == 0)
        {
            v_unit[k].key_left = SDLK_LEFT;
            v_unit[k].key_right = SDLK_RIGHT;
            v_unit[k].key_up = SDLK_UP;
            v_unit[k].key_down = SDLK_DOWN;
            v_unit[k].key_bomb = SDLK_SPACE;
            v_unit[k].key_boxe = SDLK_b;
        }
        else if (k == 1)
        {
            v_unit[k].key_left = SDLK_s;
            v_unit[k].key_right = SDLK_f;
            v_unit[k].key_up = SDLK_e;
            v_unit[k].key_down = SDLK_d;
            v_unit[k].key_bomb = SDLK_r;
            v_unit[k].key_boxe = SDLK_a;
        }
        else if (k == 2)
        {
            v_unit[k].key_left = SDLK_g;
            v_unit[k].key_right = SDLK_j;
            v_unit[k].key_up = SDLK_y;
            v_unit[k].key_down = SDLK_h;
            v_unit[k].key_bomb = SDLK_u;
            v_unit[k].key_boxe = SDLK_t;
        }
        else if (k == 3)
        {
            v_unit[k].key_left = SDLK_k;
            v_unit[k].key_right = SDLK_SEMICOLON;
            v_unit[k].key_up = SDLK_o;
            v_unit[k].key_down = SDLK_l;
            v_unit[k].key_bomb = SDLK_p;
            v_unit[k].key_boxe = SDLK_i;
        }
    }
}
Esempio n. 23
0
File: main.c Progetto: odrevet/GE
int state_in_game(SDL_Surface *screen)
{
    SDL_Rect srcrect = {0, 0, 480, 480};                      //the part of the screen to be stretched, must be sup 0 and inf screen surface Height and Width
    SDL_Rect dstrect = set_rect(0, 0, SCREEN_HEIGHT, SCREEN_WIDTH);    //equals screen resolution

    int bomb_nb=0;
    int flame_nb=0;
    bool done = false;
    int i=0;                     //generic accumulator 1
    int j=0;                     //generic accumulator 2
    int k=0;                     //unit accumulator
    int tick_count=0;
    int tick_trigger=0;
    int time_elapsed=0;         //time elapsed in this round (in secondes)
    int last_time=0;
    int current_game_status=-1;

    timer *timer_battle = timer_init();
    timer_start(timer_battle);

    // load sample.wav in to sample
    Mix_Chunk *sample = sample_load("res/boom.wav");
    Mix_Music* music = music_load("res/music.xm");
    music_play(music);

    //initialize map
    map *p_map = malloc(sizeof(map));
    p_map->tile_height = 32;
    p_map->tile_width = 32;
    map_load_level(p_map, "res/level_01.map");
    p_map->p_chipset = image_load("res/classic.png");
    SDL_Surface* surface_menu = IMG_Load("./res/menu.png");
    SDL_SetColorKey(surface_menu, SDL_SRCCOLORKEY, SDL_MapRGB(surface_menu->format, 255, 0, 255));

    for (k=0;k<g_game.unit_nb;k++)
    {
        unit_tile_protect(g_game.v_unit+k, p_map);
    }

    int block_nb = map_block_add(p_map, g_game.block_fill, .5);         ///@todo the disp % is not implemented yet
    int panel_nb = panel_add(g_game.v_panel, p_map, block_nb);

    int random_comment = rand() % 9;
    char sz_comment[32];
    SDL_Rect pos_comment = set_rect(10, 465, 0, 0);
    int comment_time_elapsed;
    timer *timer_comment = timer_init();

    //Menu
    TTF_Font *font_menu = font_load("res/asia.ttf", 20);
    TTF_Font *font_result = font_load("res/asia.ttf", 75);

    SDL_Rect cur_pos;
    cur_pos.x = 42;
    cur_pos.y = 425;

    char sz_time[10];

    while (!done)
    {
        SDL_Event event;
        SDL_JoystickUpdate();
        while(SDL_PollEvent(&event)){
            for (k=0;k<g_game.unit_nb;k++)
            {
                if (!g_game.v_unit[k].is_dead)
                {
                    unit_handle_key(g_game.v_unit+k, &event, k, g_game.v_bomb, p_map, &bomb_nb);
                }
            }
           if(event.type == SDL_QUIT || ((event.type == SDL_KEYDOWN) && (event.key.keysym.sym == SDLK_ESCAPE)) || (event.type == SDL_JOYBUTTONDOWN && event.jbutton.button == 6)){
                    done = true;
                    current_game_status = MAIN_MENU;
            }
            else if((event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_RETURN)|| (event.type == SDL_JOYBUTTONDOWN && event.jbutton.button == 5)){
                    Mix_PauseMusic();
                    state_paused(screen);
                    Mix_ResumeMusic();
            }
        }

        for (k=0;k<g_game.unit_nb;k++){
            if(!g_game.v_unit[k].use_keyboard){
                int joystate = SDL_JoystickGetHat(g_game.v_unit[k].joystick, 0);
                switch (joystate){
                    case SDL_HAT_DOWN:
                        unit_set_vel_y(g_game.v_unit+k, g_game.v_unit[k].speed);
                        unit_set_vel_x(g_game.v_unit+k, 0);
                        g_game.v_unit[k].p_sprite->animation_current = DOWN;
                    break;
                    case SDL_HAT_UP:
                        unit_set_vel_y(g_game.v_unit+k, -g_game.v_unit[k].speed);
                        unit_set_vel_x(g_game.v_unit+k, 0);
                        g_game.v_unit[k].p_sprite->animation_current = UP;
                    break;
                    case SDL_HAT_RIGHT:
                        unit_set_vel_x(g_game.v_unit+k, g_game.v_unit[k].speed);
                        unit_set_vel_y(g_game.v_unit+k, 0);
                        g_game.v_unit[k].p_sprite->animation_current = RIGHT;
                    break;
                    case SDL_HAT_LEFT:
                        unit_set_vel_x(g_game.v_unit+k, -g_game.v_unit[k].speed);
                        unit_set_vel_y(g_game.v_unit+k, 0);
                        g_game.v_unit[k].p_sprite->animation_current = LEFT;
                    break;
                    default:
                        if ( g_game.v_unit[k].vel_x != 0 ){
                            unit_set_vel_x(g_game.v_unit+k, 0);
                            g_game.v_unit[k].p_sprite->v_anim[g_game.v_unit[k].p_sprite->animation_current].frame_current = 1;
                        }
                        if ( g_game.v_unit[k].vel_y != 0 ){
                            unit_set_vel_y(g_game.v_unit+k, 0);
                            g_game.v_unit[k].p_sprite->v_anim[g_game.v_unit[k].p_sprite->animation_current].frame_current = 1;
                        }

                    break;
                }
            }
        }

        tick_count = SDL_GetTicks();
        if (tick_count > tick_trigger / 60){
            tick_trigger = tick_count;
            SDL_FillRect(backbuffer, 0, SDL_MapRGB(backbuffer->format, 10, 20, 80));


            //draw the map
            map_draw(p_map, backbuffer);
            for (i=0;i<panel_nb;i++)
            {
                if(p_map->pp_tile[g_game.v_panel[i]->p_sprite->y / TILE_SIZE][g_game.v_panel[i]->p_sprite->x / TILE_SIZE].type != BLOCK)panel_draw(g_game.v_panel[i], backbuffer);
            }


            //check panels
            for (i=0;i<panel_nb;i++)
            {
                // for all units
                for (k=0;k<g_game.unit_nb;k++)
                {
                    //Check for bonus
                    if (g_game.v_panel[i]->p_sprite->y / TILE_SIZE == unit_get_bounding_index_center_y(g_game.v_unit+k)
                            && (g_game.v_panel[i]->p_sprite->x / TILE_SIZE == unit_get_bounding_index_center_x(g_game.v_unit+k)))
                    {
                        panel_apply(g_game.v_panel[i], g_game.v_unit+k);

                        panel_free(g_game.v_panel[i]);
                        panel_nb--;

                        //Left shift the vector
                        for (j=i;j<panel_nb;j++)
                        {
                            g_game.v_panel[j] = g_game.v_panel[j+1];
                        }
                    }
                }
            }

            //Draw and update bombs
            for (i=0;i<bomb_nb;i++)
            {
                bomb_draw(g_game.v_bomb[i], backbuffer);
                anim_sprite_update_frame(g_game.v_bomb[i]->p_sprite);
                bomb_update_timer(g_game.v_bomb[i]);

                if ((g_game.v_bomb[i]->time_left <= 0) || (p_map->pp_tile[g_game.v_bomb[i]->p_sprite->y / TILE_SIZE][g_game.v_bomb[i]->p_sprite->x / TILE_SIZE].type == FLAME))
                {
                    sample_play(sample);
                    bomb_explode(g_game.v_bomb[i], p_map, g_game.v_flame, &flame_nb);
                    bomb_nb--;

                    bomb_free(g_game.v_bomb[i]);

                    //Left shift the vector
                    for (j=i;j<bomb_nb;j++)
                    {
                        g_game.v_bomb[j] = g_game.v_bomb[j+1];
                    }
                }
            }

            //Check flame
            for (i=0;i<p_map->height;i++)
            {
                for (j=0;j<p_map->width[i];j++)
                {
                    // for all units, check if hitten (if unit center is on a tile with a flame flag)
                    for (k=0;k<g_game.unit_nb;k++)
                    {
                        if ((p_map->pp_tile[i][j].type == FLAME) &&
                                ((unit_get_index_x(g_game.v_unit+k) == j) &&
                                (unit_get_index_y(g_game.v_unit+k) == i)) &&
                                g_game.v_unit[k].is_dead == false)
                        {
                            g_game.v_unit[k].is_dead = true;
                            timer_start(timer_comment);

                            switch(random_comment)
                            {
                                case(0):sprintf(sz_comment, "Say goodbye, %s ", g_game.v_unit[k].name);
                                break;
                                case(1):sprintf(sz_comment, "burn %s, burn ! ", g_game.v_unit[k].name);
                                break;
                                case(2):sprintf(sz_comment, "%s vanished !!!!!! ", g_game.v_unit[k].name);
                                break;
                                case(3):sprintf(sz_comment, "unit_free(%s); //^^ ", g_game.v_unit[k].name);
                                break;
                                case(4):sprintf(sz_comment, "%s ? Where are you ? ", g_game.v_unit[k].name);
                                break;
                                case(5):sprintf(sz_comment, "%s was a good guy ", g_game.v_unit[k].name);
                                break;
                                case(6):sprintf(sz_comment, "HE says : \"HELLO, %s\" ", g_game.v_unit[k].name);
                                break;
                                case(7):sprintf(sz_comment, "%s has meet his programmer ", g_game.v_unit[k].name);
                                break;
                                case(8):sprintf(sz_comment, "$ %s>/dev/null ", g_game.v_unit[k].name);
                                break;
                                case(9):sprintf(sz_comment, "%s was not ignifugated ", g_game.v_unit[k].name);
                                break;
                            }
                        }
                    }
                }
            }

            //Draw and update flames
            for (i=0;i<flame_nb;i++)
            {
                flame_draw(g_game.v_flame[i], p_map, backbuffer);
                g_game.v_flame[i]->time_left--;
                if (g_game.v_flame[i]->time_left <= 0)
                {
                    flame_free(g_game.v_flame[i], p_map);
                    flame_nb--;

                    //Left shift the vector
                    for (j=i;j<flame_nb;j++)
                    {
                        g_game.v_flame[j] = g_game.v_flame[j+1];
                    }
                }
            }



            for (k=0;k<g_game.unit_nb;k++)
            {
                if (!g_game.v_unit[k].is_dead)
                {
                    unit_calc_bounding_box(g_game.v_unit+k);
                    unit_update(g_game.v_unit+k, p_map);
                }
            }
            // draw and update units
            unit_draw_from_z_index(g_game.v_unit, g_game.unit_nb, backbuffer);

            //Change every 1 second
            time_elapsed = timer_get_ticks (timer_battle) / 1000;
            if (time_elapsed != last_time){
                last_time = time_elapsed;       //Update current time

        /* Check if any unit won
                    This function is performed every second in order to dont call it to often, and
                    have a little delay if two or more units died almost in the same time (even ms, in the case
                    a unit is at the left of a bomb and an other at the right, the right unit win because the
                    flame is first put to the left...)
                */

                int unit_win;
                unit_win = unit_check_victory(g_game.v_unit, g_game.unit_nb);

                if (unit_win >= 0)
                {
                    //print win, sound, etc
                    g_game.v_unit[unit_win].victory++;
                    time_elapsed = 0;
                    ///@todo set a victories limit (from 1 to 5) and display a special image if win... for the moment, another battle
                    font_printf(font_result, TILE_SIZE * 2, TILE_SIZE * 5, 50, 150, 100, backbuffer, "%s wins", g_game.v_unit[unit_win].name);
                    done = true;
                    current_game_status = IN_GAME;
                    SDL_SoftStretch(backbuffer, &srcrect, screen, &dstrect);
                    SDL_Flip(screen);
                    SDL_Delay(2000);
                    break;
                }
                else if (unit_win == -1)
                {
                    font_printf(font_result, (3)*TILE_SIZE, (6)*TILE_SIZE, 50, 150, 100, backbuffer, "DRAW !");
                    done = true;
                    current_game_status = IN_GAME;
                    SDL_SoftStretch(backbuffer, &srcrect, screen, &dstrect);
                    SDL_Flip(screen);
                    SDL_Delay(2000);
                }

                if (g_game.time - time_elapsed <= 0)
                {
                    cur_pos.x = 240;
                    cur_pos.y = 140;
                    font_printf(font_result, (3)*TILE_SIZE, (6)*TILE_SIZE, 50, 150, 100, backbuffer, "TIMES UP !");
                    done = true;
                    ///@todo select action in times up (blocks falling, etc) for the moment, just a draw...
                    current_game_status = IN_GAME;
                    SDL_SoftStretch(backbuffer, &srcrect, screen, &dstrect);
                    SDL_Flip(screen);
                    SDL_Delay(2000);
                }

            }

            ////////////////////  MENU  ////////////////////
            //TIME
            sprintf(sz_time, "%.3d", g_game.time - time_elapsed);
            SDL_Surface *surface_time = font_create_surface(font_menu, 200, 200, 200, 10, 100, 100, 100, 0, sz_time, SOLID);
            SDL_BlitSurface(surface_time, NULL, backbuffer, &cur_pos);
            SDL_FreeSurface(surface_time);
            SDL_Rect menu_src, menu_dest;
            menu_src.h = 32;
            menu_src.w = 32;
            menu_src.x = 0;
            menu_src.y = 0;

            menu_dest.x = 5;
            menu_dest.y = 420;

            SDL_BlitSurface(surface_menu, &menu_src, backbuffer, &menu_dest);

            //VICTORIES
            for (k=0;k<g_game.unit_nb;k++)
            {
                char sz_victory_nb[20];
                SDL_Rect vic_pos = set_rect(10, 450, 0, 0);
                sprintf(sz_victory_nb, "%s: %d", g_game.v_unit[k].name, g_game.v_unit[k].victory);

                vic_pos.x += k * 100;
                SDL_Surface *surface_victory = font_create_surface(font_menu, 200, 200, 200, 10, 100, 100, 100, 0, sz_victory_nb, SOLID);
                SDL_BlitSurface(surface_victory, NULL, backbuffer, &vic_pos);
                SDL_FreeSurface(surface_victory);
            }

            //Comment
            if(timer_comment->started){
                comment_time_elapsed = timer_get_ticks(timer_comment) / 1000;
                if (comment_time_elapsed < 3)   //Display the comment 3 seconds
                {
                    font_printf(font_menu, pos_comment.x, pos_comment.y, 200, 200, 200, backbuffer, sz_comment);
                }
                else{   //done
                    timer_stop(timer_comment);
                    random_comment = rand() % 9;

                }
            }

            //DEBUG
#ifdef DEBUG
            font_printf(font_menu, 10, 10, 255, 255, 200, backbuffer, "flame nb : %d", flame_nb);
            font_printf(font_menu, 10, 30, 255, 255, 200, backbuffer, "bomb nb : %d", bomb_nb);
            font_printf(font_menu, 10, 50, 255, 255, 200, backbuffer, "unit nb : %d", g_game.unit_nb);
            font_printf(font_menu, 10, 70, 255, 255, 200, backbuffer, "fill nb : %.2f", g_game.block_fill);
            font_printf(font_menu, 10, 90, 255, 255, 200, backbuffer, "Blocks at startup : %d", block_nb);
            font_printf(font_menu, 10, 110, 255, 255, 200, backbuffer, "Time elapsed : %d", timer_get_ticks(timer_battle)/1000);
            font_printf(font_menu, 10, 130, 255, 255, 200, backbuffer, "unit 1 index: %d %d", unit_get_bounding_index_center_x(g_game.v_unit+0), unit_get_bounding_index_center_y(g_game.v_unit+0));


            SDL_Rect rect = unit_get_bounding_box(g_game.v_unit+0);
            SDL_FillRect(backbuffer, &rect, SDL_MapRGB(backbuffer->format, 255, 255, 0));
#endif

            SDL_SoftStretch(backbuffer, &srcrect, screen, &dstrect);
            SDL_Flip(screen);
        }//end thick
    }   //end while



    //Free the memory
    for (i=0;i<bomb_nb;i++)
    {
        bomb_free(g_game.v_bomb[i]);
    }
    for (i=0;i<panel_nb;i++)
    {
        panel_free(g_game.v_panel[i]);
    }
    for (i=0;i<flame_nb;i++)
    {
        flame_free(g_game.v_flame[i], p_map);
    }
    map_free(p_map);

    free(timer_battle);
    free(timer_comment);

    Mix_FreeChunk(sample);
    Mix_FreeMusic(music);

    TTF_CloseFont(font_menu);
    font_menu=NULL; // to be safe...

    TTF_CloseFont(font_result);
    font_result=NULL; // to be safe...

    return current_game_status;

}
Esempio n. 24
0
void gui_create_rsurf(rsurf_ceate_t *p_rsurf, roll_param_t *p_param)
{
  rsc_fstyle_t *p_fstyle = NULL;
  u16 width = 0, height = 0, data_width = 0;
  s16 str_offset = 0;
  handle_t handle = 0;
  rect_t str_rect = {0};
  hdc_t hdc = 0;
  u32 color_key = 0, addr = 0;
  u16 str_drawed = 0;
  roll_sept_t sept = {0};
  u32 draw_style = 0;
  roll_param_t saved_param = {0};
  roll_param_t *p_roll_param = NULL;
  gui_roll_t *p_info = NULL;
  roll_node_t *p_node = NULL;

  p_roll_param = p_param;

  p_info = (gui_roll_t *)class_get_handle_by_id(ROLL_CLASS_ID);
  MT_ASSERT(p_info != NULL);

  if(p_roll_param == NULL)
  {
    if(p_info->p_saved == NULL)
    {
      //nothing saved, so just return.
      return;
    }

    //use the saved parameters to create roll surface.
    memcpy(&saved_param, &(p_info->p_saved->param), sizeof(roll_param_t));
  
    str_drawed = p_info->p_saved->str_drawed;
    str_offset = p_info->p_saved->str_off;

    p_roll_param = &saved_param;
  }
  
  //if((p_rsurf == NULL) || (p_param == NULL))
  if(p_rsurf == NULL)
  {
    return;
  }
  
  if(p_rsurf->is_pic)
  {
    color_key = 0;

    //if(!p_rsurf->is_pic_rawdata)
    {
      gui_get_bmp_attr(p_rsurf->pic_data, p_rsurf->is_pic_rawdata, &width, &height);
    }
  }
  else
  {
    if(p_rsurf->p_str == NULL)
    {
      p_node = gui_roll_add(p_rsurf->p_ctrl, p_roll_param,
        handle, addr, 0, RECTH(p_rsurf->rect), &p_rsurf->rect, p_rsurf->context, NULL);      

      MT_ASSERT(p_node != NULL);

      //reset the node by saved parameters.
      if(p_info->p_saved != NULL)
      {
        p_node->blt_x = p_info->p_saved->blt_x;
        p_node->blt_y = p_info->p_saved->blt_y;
        p_node->curn = p_info->p_saved->curn;
        p_node->curn_times = p_info->p_saved->curn_times;
        p_node->is_pause = p_info->p_saved->is_pause;
        p_node->p_list = p_info->p_saved->p_list;
      }
      
      return;
    }

    p_fstyle = rsc_get_fstyle(gui_get_rsc_handle(), p_rsurf->fstyle_idx);

    color_key = (p_fstyle->color ? 0 : 1);

    rsc_get_string_attr(gui_get_rsc_handle(), p_rsurf->p_str, p_fstyle, &width, &height);
  }

  if((width <= RECTW(p_rsurf->rect)) && (p_roll_param->is_force == FALSE))
  {
    p_node = gui_roll_add(p_rsurf->p_ctrl, p_roll_param,
      handle, addr, width, RECTH(p_rsurf->rect), &p_rsurf->rect, p_rsurf->context, NULL);  

    MT_ASSERT(p_node != NULL);
    p_node->sept.is_pic = p_rsurf->is_pic;
    p_node->sept.is_pic_rawdata = p_rsurf->is_pic_rawdata;

    //reset the node by saved parameters.
    if(p_info->p_saved != NULL)
    {
      p_node->blt_x = p_info->p_saved->blt_x;
      p_node->blt_y = p_info->p_saved->blt_y;
      p_node->curn = p_info->p_saved->curn;
      p_node->curn_times = p_info->p_saved->curn_times;
      p_node->is_pause = p_info->p_saved->is_pause;
      p_node->p_list = p_info->p_saved->p_list;
    }
      
    return;
  }

  data_width = width;

  if(p_rsurf->is_pic)
  {
    if(data_width > RECTW(p_rsurf->rect))
    {
      p_rsurf->rect.right = p_rsurf->rect.left + data_width;
    }
  }
  
  width = RECTW(p_rsurf->rect);

  //create roll surface.
  handle = gdi_create_rsurf(p_rsurf->is_topmost,
    RECTW(p_rsurf->rect), RECTH(p_rsurf->rect), &addr);

  MT_ASSERT(handle != 0);
  MT_ASSERT(addr != 0);

  flinger_set_colorkey((void *)handle, color_key);

  //fill roll surface.
  set_rect(&str_rect, 0, 0, RECTW(p_rsurf->rect), RECTH(p_rsurf->rect));

  if(p_roll_param->use_bg)
  {
    flinger_fill_rect((void *)handle, &str_rect, p_roll_param->bg_color);
  }
  else
  {
    flinger_fill_rect((void *)handle, &str_rect, color_key);
  }
  
  hdc = gdi_get_roll_dc(&str_rect, handle);
  MT_ASSERT(hdc != HDC_INVALID);
 
  if(p_rsurf->is_pic)
  {
    str_drawed = gui_draw_picture_offset(hdc, &str_rect, 
    p_rsurf->pic_data, p_rsurf->is_pic_rawdata, str_drawed, data_width, height, (s16 *)&str_offset);
  }
  else
  {  
    draw_style = (p_rsurf->draw_style | MAKE_DRAW_STYLE(STRDRAW_IGNORE_NLINE, 0));

    str_drawed = gui_draw_unistr_offset(hdc, &str_rect, 
      p_rsurf->p_str, p_rsurf->fstyle_idx,
      draw_style, str_drawed, data_width, height, (s16 *)&str_offset);
  }
  gdi_release_roll_dc(hdc);    

  sept.p_str = p_rsurf->p_str;
  sept.str_drawed = str_drawed;
  sept.str_off = str_offset;
  sept.str_width = data_width;
  sept.str_height = height;
  sept.fstyle_id = p_rsurf->fstyle_idx;
  sept.draw_style = draw_style;
  sept.is_pic = p_rsurf->is_pic;
  sept.is_pic_rawdata = p_rsurf->is_pic_rawdata;
  sept.pic_data = p_rsurf->pic_data;
  sept.is_pic = p_rsurf->is_pic;
  sept.is_pic_rawdata = p_rsurf->is_pic_rawdata;
  
  p_node = gui_roll_add(p_rsurf->p_ctrl, p_roll_param, 
    handle, addr, width, RECTH(p_rsurf->rect), &p_rsurf->rect, p_rsurf->context, &sept);

  MT_ASSERT(p_node != NULL);

  if(p_param->style == ROLL_LB)
  {
    p_node->blt_x = RECTW(p_rsurf->rect);
  }

  //reset the node by saved parameters.
  if(p_info->p_saved != NULL)
  {
    p_node->blt_x = p_info->p_saved->blt_x;
    p_node->blt_y = p_info->p_saved->blt_y;
    p_node->curn = p_info->p_saved->curn;
    p_node->curn_times = p_info->p_saved->curn_times;
    p_node->is_pause = p_info->p_saved->is_pause;
    p_node->p_list = p_info->p_saved->p_list;
  }

  return;
}
Esempio n. 25
0
void PaintWindow::createMenu() {
    // Adding the drop down menu to the menubar
    m_menu_app = menuBar()->addMenu(tr("&Application"));
    m_menu_tools = menuBar()->addMenu(tr("&Tools"));
    m_menu_colour = menuBar()->addMenu(tr("&Colour"));
    m_menu_help = menuBar()->addMenu(tr("&Help"));

    // Adding the menu items for each drop down menu
    QAction* quitAct = new QAction(tr("&Quit"), this);
    quitAct->setShortcuts(QKeySequence::Quit);
    quitAct->setStatusTip(tr("Exits the program"));
    connect(quitAct, SIGNAL(triggered()), this, SLOT(close()));
    m_menu_app->addAction(quitAct);
    
    QAction* clearAct = new QAction(tr("&Clear"), this);
    clearAct->setShortcut(QKeySequence(Qt::Key_C));
    connect(clearAct, SIGNAL(triggered()), m_canvas, SLOT(clearCanvas()));
    m_menu_app->addAction(clearAct);

    QAction* drawLineAct = new QAction(tr("&Line"), this);
    drawLineAct->setStatusTip(tr("Draws a line"));
    drawLineAct->setShortcut(QKeySequence(Qt::Key_L));
    drawLineAct->setCheckable(true);
    connect(drawLineAct, SIGNAL(triggered()), this, SLOT(set_line()));

    QAction* drawOvalAct = new QAction(tr("&Oval"), this);
    drawOvalAct->setStatusTip(tr("Draws an Oval"));
    drawOvalAct->setShortcut(QKeySequence(Qt::Key_O));
    drawOvalAct->setCheckable(true);
    connect(drawOvalAct, SIGNAL(triggered()), this, SLOT(set_oval()));

    QAction* drawRectangleAct = new QAction(tr("&Rectangle"), this);
    drawRectangleAct->setStatusTip(tr("Draws a rectangle"));
    drawRectangleAct->setShortcut(QKeySequence(Qt::Key_R));
    drawRectangleAct->setCheckable(true);
    connect(drawRectangleAct, SIGNAL(triggered()), this, SLOT(set_rect()));
    
	QActionGroup *toolsActionGroup = new QActionGroup(this);
	toolsActionGroup->addAction(drawLineAct);
	toolsActionGroup->addAction(drawOvalAct);
	toolsActionGroup->addAction(drawRectangleAct);
	toolsActionGroup->setExclusive(true);
	drawLineAct->setChecked(true);
	
    m_menu_tools->addAction(drawLineAct);
    m_menu_tools->addAction(drawOvalAct);
    m_menu_tools->addAction(drawRectangleAct);

    QAction* setColourBlackAct = new QAction(tr("&Black"), this);
    connect(setColourBlackAct, SIGNAL(triggered()), this, SLOT(setColourBlack()));
    
    QAction* setColourRedAct = new QAction(tr("&Red"), this);
    connect(setColourRedAct, SIGNAL(triggered()), this, SLOT(setColourRed()));
    
    QAction* setColourGreenAct = new QAction(tr("&Green"), this);
    connect(setColourGreenAct, SIGNAL(triggered()), this, SLOT(setColourGreen()));
    
    QAction* setColourBlueAct = new QAction(tr("&Blue"), this);
    connect(setColourBlueAct, SIGNAL(triggered()), this, SLOT(setColourBlue()));
    
    m_menu_colour->addAction(setColourBlackAct);
    m_menu_colour->addAction(setColourRedAct);
    m_menu_colour->addAction(setColourGreenAct);
    m_menu_colour->addAction(setColourBlueAct);

    QAction* helpLineAct = new QAction(tr("&Line Help"), this);
    helpLineAct->setStatusTip(tr("Help Instructions"));
    connect(helpLineAct, SIGNAL(triggered()), this, SLOT(help_line()));
    m_menu_help->addAction(helpLineAct);
    
    QAction* helpRectangleAct = new QAction(tr("&Rectangle Help"), this);
    helpRectangleAct->setStatusTip(tr("Help Instructions for rectangles"));
    connect(helpRectangleAct, SIGNAL(triggered()), this, SLOT(help_rectangle()));
    m_menu_help->addAction(helpRectangleAct);

    QAction* helpOvalAct = new QAction(tr("&Oval Help"), this);
    helpOvalAct->setStatusTip(tr("Help Instructions for ovals"));
    connect(helpOvalAct, SIGNAL(triggered()), this, SLOT(help_oval()));
    m_menu_help->addAction(helpOvalAct);
}
Esempio n. 26
0
File: main.c Progetto: odrevet/GE
int main(int argc, char** argv){
  SDL_Surface *screen=NULL;
  srand(time(NULL));

  sdl_init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK);

  SDL_EnableKeyRepeat(200, 200);

  SDL_WM_SetCaption("Game Engine demo", NULL);

  atexit(SDL_Quit);
  SDL_ShowCursor(SDL_DISABLE);

  dstrect = set_rect(0,0,WINDOW_HEIGHT,WINDOW_WIDTH);
  srcrect = set_rect(0, 0, SCREEN_HEIGHT, SCREEN_WIDTH);
  
  // create a new window
  int flags = SDL_HWSURFACE;
  screen = sdl_set_video(WINDOW_WIDTH, WINDOW_HEIGHT, 16, flags);
  backbuffer = SDL_DisplayFormat(screen);

  //create a new game
  game o_game;

  //create sprites
  int i;
  for(i=0;i<SPRITE_NUMBER;i++){    
    anim_sprite* p_sprite = malloc(sizeof(anim_sprite));
    p_sprite->p_image = image_load("./res/coin.png");
    image_set_transp_color(p_sprite->p_image, 0xFF, 0x00, 0xFF);

    //init sprite animation
    anim_sprite_init(p_sprite, 80, 16, 3, 1, 0, 0, 1);
    p_sprite->v_anim = malloc(p_sprite->animation_nb * sizeof(animation));
    animation_init(p_sprite->v_anim+0, 1, 3, 25, 0);   //one animation of three frames

    p_sprite->v_anim[0].v_frame = malloc(p_sprite->v_anim[0].frame_nb * sizeof(SDL_Rect));
    p_sprite->v_anim[0].v_frame[0] = set_rect(0, 0, 5, 8);
    p_sprite->v_anim[0].v_frame[1] = set_rect(5, 0, 5, 8);
    p_sprite->v_anim[0].v_frame[2] = set_rect(10, 0, 5, 8);

    //init sprite position and velocity
    int x = rand() % WINDOW_WIDTH;
    int y = rand() % WINDOW_HEIGHT;
    int vel_x = rand() % 2;
    int vel_y = rand() % 2;
    p_sprite->x = x;
    p_sprite->y = y;
    p_sprite->vel_x = vel_x;
    p_sprite->vel_y = vel_y;   

    
    o_game.p_sprite[i] = p_sprite;
  }
  
  //game stats
  game_status ret_code = IN_GAME;
  while(ret_code != QUIT){
    switch(ret_code){
    case IN_GAME:
      ret_code = state_in_game(screen, &o_game);
      break;
    default:
      break;
    }
  }

  SDL_Quit();
  return EXIT_SUCCESS;
}
Esempio n. 27
0
static void test_clip(void)
{
    IDXGISwapChain *swapchain;
    D2D1_MATRIX_3X2_F matrix;
    D2D1_SIZE_U pixel_size;
    ID2D1RenderTarget *rt;
    ID3D10Device1 *device;
    IDXGISurface *surface;
    D2D1_POINT_2F point;
    D2D1_COLOR_F color;
    float dpi_x, dpi_y;
    D2D1_RECT_F rect;
    D2D1_SIZE_F size;
    HWND window;
    HRESULT hr;
    static const D2D1_MATRIX_3X2_F identity =
    {
        1.0f, 0.0f,
        0.0f, 1.0f,
        0.0f, 0.0f,
    };

    if (!(device = create_device()))
    {
        skip("Failed to create device, skipping tests.\n");
        return;
    }
    window = CreateWindowA("static", "d2d1_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
            0, 0, 640, 480, NULL, NULL, NULL, NULL);
    swapchain = create_swapchain(device, window, TRUE);
    hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_IDXGISurface, (void **)&surface);
    ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
    rt = create_render_target(surface);
    ok(!!rt, "Failed to create render target.\n");

    ID2D1RenderTarget_GetDpi(rt, &dpi_x, &dpi_y);
    ok(dpi_x == 96.0f, "Got unexpected dpi_x %.8e.\n", dpi_x);
    ok(dpi_y == 96.0f, "Got unexpected dpi_x %.8e.\n", dpi_y);
    size = ID2D1RenderTarget_GetSize(rt);
    ok(size.width == 640.0f, "Got unexpected width %.8e.\n", size.width);
    ok(size.height == 480.0f, "Got unexpected height %.8e.\n", size.height);
    pixel_size = ID2D1RenderTarget_GetPixelSize(rt);
    ok(pixel_size.width == 640, "Got unexpected width %u.\n", pixel_size.width);
    ok(pixel_size.height == 480, "Got unexpected height %u.\n", pixel_size.height);

    ID2D1RenderTarget_GetTransform(rt, &matrix);
    ok(!memcmp(&matrix, &identity, sizeof(matrix)),
            "Got unexpected matrix {%.8e, %.8e, %.8e, %.8e, %.8e, %.8e}.\n",
            matrix._11, matrix._12, matrix._21, matrix._22, matrix._31, matrix._32);

    ID2D1RenderTarget_BeginDraw(rt);

    set_color(&color, 1.0f, 1.0f, 0.0f, 1.0f);
    ID2D1RenderTarget_Clear(rt, &color);

    ID2D1RenderTarget_SetDpi(rt, 48.0f, 192.0f);
    ID2D1RenderTarget_GetDpi(rt, &dpi_x, &dpi_y);
    ok(dpi_x == 48.0f, "Got unexpected dpi_x %.8e.\n", dpi_x);
    ok(dpi_y == 192.0f, "Got unexpected dpi_x %.8e.\n", dpi_y);
    size = ID2D1RenderTarget_GetSize(rt);
    ok(size.width == 1280.0f, "Got unexpected width %.8e.\n", size.width);
    ok(size.height == 240.0f, "Got unexpected height %.8e.\n", size.height);
    pixel_size = ID2D1RenderTarget_GetPixelSize(rt);
    ok(pixel_size.width == 640, "Got unexpected width %u.\n", pixel_size.width);
    ok(pixel_size.height == 480, "Got unexpected height %u.\n", pixel_size.height);

    /* The effective clip rect is the intersection of all currently pushed
     * clip rects. Clip rects are in DIPs. */
    set_rect(&rect, 0.0f, 0.0f, 1280.0f, 80.0f);
    ID2D1RenderTarget_PushAxisAlignedClip(rt, &rect, D2D1_ANTIALIAS_MODE_ALIASED);
    set_rect(&rect, 0.0f, 0.0f, 426.0f, 240.0f);
    ID2D1RenderTarget_PushAxisAlignedClip(rt, &rect, D2D1_ANTIALIAS_MODE_ALIASED);

    set_color(&color, 0.0f, 1.0f, 0.0f, 1.0f);
    ID2D1RenderTarget_Clear(rt, &color);
    ID2D1RenderTarget_PopAxisAlignedClip(rt);
    ID2D1RenderTarget_PopAxisAlignedClip(rt);

    ID2D1RenderTarget_SetDpi(rt, 0.0f, 0.0f);
    ID2D1RenderTarget_GetDpi(rt, &dpi_x, &dpi_y);
    ok(dpi_x == 96.0f, "Got unexpected dpi_x %.8e.\n", dpi_x);
    ok(dpi_y == 96.0f, "Got unexpected dpi_y %.8e.\n", dpi_y);

    /* Transformations apply to clip rects, the effective clip rect is the
     * (axis-aligned) bounding box of the transformed clip rect. */
    set_point(&point, 320.0f, 240.0f);
    D2D1MakeRotateMatrix(30.0f, point, &matrix);
    ID2D1RenderTarget_SetTransform(rt, &matrix);
    set_rect(&rect, 215.0f, 208.0f, 425.0f, 272.0f);
    ID2D1RenderTarget_PushAxisAlignedClip(rt, &rect, D2D1_ANTIALIAS_MODE_ALIASED);
    set_color(&color, 1.0f, 1.0f, 1.0f, 1.0f);
    ID2D1RenderTarget_Clear(rt, &color);
    ID2D1RenderTarget_PopAxisAlignedClip(rt);

    /* Transformations are applied when pushing the clip rect, transformations
     * set afterwards have no effect on the current clip rect. This includes
     * SetDpi(). */
    ID2D1RenderTarget_SetTransform(rt, &identity);
    set_rect(&rect, 427.0f, 320.0f, 640.0f, 480.0f);
    ID2D1RenderTarget_PushAxisAlignedClip(rt, &rect, D2D1_ANTIALIAS_MODE_ALIASED);
    ID2D1RenderTarget_SetTransform(rt, &matrix);
    ID2D1RenderTarget_SetDpi(rt, 48.0f, 192.0f);
    set_color(&color, 1.0f, 0.0f, 0.0f, 1.0f);
    ID2D1RenderTarget_Clear(rt, &color);
    ID2D1RenderTarget_PopAxisAlignedClip(rt);

    hr = ID2D1RenderTarget_EndDraw(rt, NULL, NULL);
    ok(SUCCEEDED(hr), "Failed to end draw, hr %#x.\n", hr);
    ok(compare_surface(surface, "035a44d4198d6e422e9de6185b5b2c2bac5e33c9"), "Surface does not match.\n");

    ID2D1RenderTarget_Release(rt);
    IDXGISurface_Release(surface);
    IDXGISwapChain_Release(swapchain);
    ID3D10Device1_Release(device);
    DestroyWindow(window);
}
Esempio n. 28
0
File: tft.c Progetto: bionllo/myarm
/**
 * @brief 将字体的点阵模显示出来
 * @param index_word_lib 该字体的模所在的首地址
 *  这个参数可以取得到以下的值:\n
 *  	@arg
 * @param x0 该字体的模显示的横坐标
 * @param y0 该字体的模显示的纵坐标
 * @retval none
 * \date 2012-3-31 下午4:55:52
 * @note 不足的是不能显示不够整数方框个数的字模,如果能显示也会有安全隐患
 */
void display_word_mode(INT8U* index_word_lib , INT16U x0 , INT16U y0)
{
#if LIB_FONT == POINT_LIB
	INT32U word_mode_size = WORD_FONT_SIZE ;                    //为了确认到字模什么时候能够写完
	INT8U temp ;
	INT16U count = 0 ;
	INT16U x0_no_change = x0 ;
	INT16U x = x0 ;
	INT16U y = y0 ;                    //这两个变量是为了方便控制x0,y0。
#ifdef __DEBUG__
	printfs("index_word_lib:") ;
	printf_num((INT32U) index_word_lib, 'h') ;
	printfs("\r\n") ;
#endif
	/*
	 * 假设下面是一个点阵汉字,取模由4个8*8的方框按顺序组成
	 *
	 *
	 *	一开始的时候
	 *		 |x=x0,count指的是字库里面的原始数据,x0_no_change,这个变量不会变,如果y>8的适合将x0被这个变量置位
	 *	 	 |
	 *	 	 V
	 y=y0--> ******************************
	 *			   *			  *
	 *			   *			  *
	 *	1		   *		2	  *
	 *	 		   *			  *
	 *			   *			  *
	 ******************************
	 *			   *			  *
	 *			   *			  *
	 *	3		   *		4	  *
	 *			   * 			  *
	 *			   *			  *
	 ******************************
	 *	当一个字节写好后
	 *		 |x
	 *		 |x0_no_change |count
	 *		 |			   |x0
	 *	 	 |			   |
	 *	 	 V			   v
	 y-->  ******************************
	 y0--> *			   *			  *				y0指向下一行的时候,x0将会被x置位,即x0,又回到一开始的位置
	 *			   *			  *
	 *	1		   *		2	  *
	 *	 		   *			  *
	 *			   *			  *
	 ******************************
	 *			   *			  *
	 *			   *			  *
	 *	3		   *		4	  *
	 *			   * 			  *
	 *			   *			  *
	 ******************************
	 *	当八个字节写好后,x,y的坐标将会指向下一个方框的首地址,都是被x,y值重置了,因为到了同一行的另外一个字框,所以x的指向会被修改为x+8,而count是只管增加就行了
	 *		 |
	 *		 |x0_no_change  |count
	 *		 |			    |x
	 *	 	 |			    |x0
	 *	 	 V			    v
	 y0=y--> ******************************
	 *			   *			  *
	 *			   *			  *
	 *	1		   *		2	  *
	 *	 		   *			  *
	 *			   *			  *
	 ******************************
	 *			   *			  *
	 *			   *			  *
	 *	3		   *		4	  *
	 *			   * 			  *
	 *			   *			  *
	 ******************************
	 *第一行的方框全部写完后,x0,x将会被原本的x0_no_change改变,重新修改为指向第一列
	 *		 |x0
	 *		 |x0_no_change  |
	 *		 |x			    |
	 *	 	 |			    |
	 *	 	 V			    v
	 ******************************
	 *			   *			  *
	 *			   *			  *
	 *	1		   *		2	  *
	 *	 		   *			  *
	 *			   *			  *
	 y0=y-->	 ******************************
	 * <--count	   *			  *
	 *			   *			  *
	 *	3		   *		4	  *
	 *			   * 			  *
	 *			   *			  *
	 ******************************
	 */
	while(word_mode_size --)
	{
		temp = *(index_word_lib + count) ;
		count ++ ;
		if (temp == 0)
		{
			y0 ++ ;
		}
		else
		{
			while(temp)
			{
				if (temp & 0x80)
				{
					draw_word_point(x0 , y0) ;
					x0 ++ ;
				}
				else
				{
					x0 ++ ;
				}
				temp <<= 1 ;
			}
			y0 ++ ;
			x0 = x ;
		}

		if (count % 8 == 0)
		{
			y0 = y ;
			x += 8 ;
			x0 = x ;
		}
		if (count % WORD_FONT_WIDTH == 0)
		{
			y += 8 ;
			y0 = y ;
			x = x0_no_change ;
			x0 = x0_no_change ;
		}

	}
#elif LIB_FONT == IMAGE_LIB
#ifdef __DEBUG__
	printf_num((INT32U) index_word_lib, 'h') ;
#endif
	set_rect(x0, y0,WORD_FONT_WIDTH,WORD_FONT_HIGH) ;
	write_to_FramRam((INT16U*)index_word_lib,WORD_FONT_WIDTH,WORD_FONT_HIGH) ;
#endif
}
Esempio n. 29
0
void region_tt::set_rect( const RECT& rect )
{
    return set_rect( rect.left, rect.top, rect.right, rect.bottom );
}
Esempio n. 30
0
void
ButtonPanel::set_pos(const Vector2i& pos)
{
  set_rect(Rect(Vector2i(pos.x, pos.y - (buttons.size() * 38)/2),
                Size(60, buttons.size() * 38)));
}