コード例 #1
0
ファイル: bitmap_draw.c プロジェクト: BorisCarvajal/allegro5
static void _draw_tinted_rotated_scaled_bitmap_region(ALLEGRO_BITMAP *bitmap,
   ALLEGRO_COLOR tint, float cx, float cy, float angle,
   float xscale, float yscale,
   float sx, float sy, float sw, float sh, float dx, float dy,
   int flags)
{
   ALLEGRO_TRANSFORM backup;
   ALLEGRO_TRANSFORM t;
   ALLEGRO_BITMAP *parent = bitmap;
   float const orig_sw = sw;
   float const orig_sh = sh;
   ASSERT(bitmap);

   al_copy_transform(&backup, al_get_current_transform());
   al_identity_transform(&t);
   
   if (bitmap->parent) {
      parent = bitmap->parent;
      sx += bitmap->xofs;
      sy += bitmap->yofs;
   }
   
   if (sx < 0) {
      sw += sx;
      al_translate_transform(&t, -sx, 0);
      sx = 0;
   }
   if (sy < 0) {
      sh += sy;
      al_translate_transform(&t, 0, -sy);
      sy = 0;
   }
   if (sx + sw > parent->w)
      sw = parent->w - sx;
   if (sy + sh > parent->h)
      sh = parent->h - sy;

   if (flags & ALLEGRO_FLIP_HORIZONTAL) {
      al_scale_transform(&t, -1, 1);
      al_translate_transform(&t, orig_sw, 0);
      flags &= ~ALLEGRO_FLIP_HORIZONTAL;
   }

   if (flags & ALLEGRO_FLIP_VERTICAL) {
      al_scale_transform(&t, 1, -1);
      al_translate_transform(&t, 0, orig_sh);
      flags &= ~ALLEGRO_FLIP_VERTICAL;
   }

   al_translate_transform(&t, -cx, -cy);
   al_scale_transform(&t, xscale, yscale);
   al_rotate_transform(&t, angle);
   al_translate_transform(&t, dx, dy);
   al_compose_transform(&t, &backup);

   al_use_transform(&t);
   _bitmap_drawer(parent, tint, sx, sy, sw, sh, flags);
   al_use_transform(&backup);
}
コード例 #2
0
ファイル: transform.c プロジェクト: beoran/ralleg5
VALUE rbal_scale_transform(VALUE r_, VALUE rtrans, VALUE rsx, VALUE rsy) {
  ALLEGRO_TRANSFORM * trans = rbal_transform_unwrap(rtrans);
  float 	         sx = RBH_FLOAT(rsx);
  float 	         sy = RBH_FLOAT(rsy);
  al_scale_transform(trans, rsx, rsy);
  return rtrans;
}
コード例 #3
0
ファイル: utils.c プロジェクト: dos1/TickleMonster
void SetupViewport(struct Game *game) {
	game->viewport.width = 320;
	game->viewport.height = 180;

	int resolution = al_get_display_width(game->display) / 320;
	if (al_get_display_height(game->display) / 180 < resolution) resolution = al_get_display_height(game->display) / 180;
	if (resolution < 1) resolution = 1;

	if (atoi(GetConfigOptionDefault(game, "SuperDerpy", "letterbox", "1"))) {
		int clipWidth = 320 * resolution, clipHeight = 180 * resolution;
		int clipX = (al_get_display_width(game->display) - clipWidth) / 2, clipY = (al_get_display_height(game->display) - clipHeight) / 2;
		al_set_clipping_rectangle(clipX, clipY, clipWidth, clipHeight);

		al_build_transform(&game->projection, clipX, clipY, resolution, resolution, 0.0f);
		al_use_transform(&game->projection);

	} else if ((atoi(GetConfigOptionDefault(game, "SuperDerpy", "rotate", "1"))) && (game->viewport.height > game->viewport.width)) {
		al_identity_transform(&game->projection);
		al_rotate_transform(&game->projection, 0.5*ALLEGRO_PI);
		al_translate_transform(&game->projection, game->viewport.width, 0);
		al_scale_transform(&game->projection, resolution, resolution);
		al_use_transform(&game->projection);
		int temp = game->viewport.height;
		game->viewport.height = game->viewport.width;
		game->viewport.width = temp;
	}
	if (game->_priv.console) Console_Unload(game);
	Console_Load(game);
}
コード例 #4
0
ファイル: camera.cpp プロジェクト: kybernetyk/AllegroGame
		void apply_identity() {
			ALLEGRO_TRANSFORM t;
			al_identity_transform(&t);
			al_scale_transform(&t, 1.0, -1.0);
			al_translate_transform(&t, 0, cfg::screen_height);
			al_use_transform(&t);
		}
コード例 #5
0
/** Applies a scale transformation to the current transformation. */
void cbeTransformScale(CBEnchanted *cb) {
	float scaleY = cb->popValue().toFloat();
	float scaleX = cb->popValue().toFloat();

	ALLEGRO_TRANSFORM t;
	al_identity_transform(&t);
	al_scale_transform(&t, scaleX, scaleY);
	al_use_transform(&t);
	cb->pushValue(0);
}
コード例 #6
0
/* set up a transformation such that anything drawn will be as if its 'z'
 * coordinate was at the specified 'z' */
void t3f_3d_transform_z(float z)
{
	float scale = t3f_3d_project_x(1.0, z) - t3f_3d_project_x(0.0, z);
	float offset_x = t3f_3d_project_x(0.0, z);
	float offset_y = t3f_3d_project_y(0.0, z);
	al_identity_transform(&t3f_3d_transform);
	al_scale_transform(&t3f_3d_transform, scale, scale);
	al_translate_transform(&t3f_3d_transform, offset_x, offset_y);
//	al_transform_transform(&t3f_3d_transform, &t3f_current_transform);
	al_use_transform(&t3f_3d_transform);
}
コード例 #7
0
void prepareForScreenGrab1()
{
	prepareForScreenGrabBackupBitmap = al_get_target_bitmap();
	int dx, dy, dw, dh;
	get_screen_offset_size(&dx, &dy, &dw, &dh);
	m_set_target_bitmap(tmpbuffer);
	ALLEGRO_TRANSFORM t;
	al_copy_transform(&prepareForScreenGrabBackup, al_get_current_transform());
	al_identity_transform(&t);
	al_scale_transform(&t, screenScaleX, screenScaleY);
	al_translate_transform(&t, dx, dy);
	al_use_transform(&t);
	preparingForScreenGrab = true;
}
コード例 #8
0
void start_text()
{
	if (!text_draw_on) {
		text_draw_on = true;
		int dx, dy, dw, dh;
		get_screen_offset_size(&dx, &dy, &dw, &dh);
		al_copy_transform(&old_view, al_get_current_transform());
		ALLEGRO_TRANSFORM v;
		al_identity_transform(&v);
		al_scale_transform(&v, textScaleX, textScaleY);
		if (al_get_bitmap_width(al_get_target_bitmap()) == al_get_display_width(display) && al_get_bitmap_height(al_get_target_bitmap()) == al_get_display_height(display)) {
			al_translate_transform(&v, dx, dy);
		}
		al_use_transform(&v);
	}
}
コード例 #9
0
void t3f_3d_select_projection(T3F_3D_STATE * sp)
{
	t3f_3d_current_state = sp;
	float sx = t3f_3d_current_state->width / (float)t3f_virtual_display_width;
	float sy = t3f_3d_current_state->height / (float)t3f_virtual_display_height;
	float dsx = (float)al_get_display_width(t3f_display) / t3f_virtual_display_width;
	float dsy = (float)al_get_display_height(t3f_display) / t3f_virtual_display_height;
	float ox = t3f_3d_current_state->offset_x * dsx;
	float oy = t3f_3d_current_state->offset_y * dsy;
	
	/* apply additional transformations */
	al_copy_transform(&t3f_current_transform, &t3f_base_transform);
	al_scale_transform(&t3f_current_transform, sx, sy);
	al_translate_transform(&t3f_current_transform, t3f_3d_current_state->offset_x * dsx, t3f_3d_current_state->offset_y * dsy);
	al_use_transform(&t3f_current_transform);
	
	/* convert virtual screen coordinates to real display coordinates */
	al_set_clipping_rectangle(ox, oy, t3f_3d_current_state->width * dsx, t3f_3d_current_state->height * dsy);
}
コード例 #10
0
ファイル: asteroid.c プロジェクト: ooonak/cmess
/* Transform asteroid */
static void draw_roid(Asteroid *roid)
{
  ALLEGRO_TRANSFORM transform;
  al_identity_transform(&transform);
  al_rotate_transform(&transform, (roid->twist * (M_PI/180)));
  al_scale_transform(&transform, roid->scale, roid->scale);
  al_translate_transform(&transform, roid->sx, roid->sy);
  al_use_transform(&transform);
  al_draw_line(-22, 20, -18, 4, roid->color, 2.0f);
  al_draw_line(-18, 4, -18, -10, roid->color, 2.0f);
  al_draw_line(-18, -10, -5, -10, roid->color, 2.0f);
  al_draw_line(-5, -10, -10, -22, roid->color, 2.0f);
  al_draw_line(-10, -22, 4, -22, roid->color, 2.0f);
  al_draw_line(4, -22, 20, -10, roid->color, 2.0f);
  al_draw_line(20, -10, 20, -5, roid->color, 2.0f);
  al_draw_line(20, -5, 0, 0, roid->color, 2.0f);
  al_draw_line(0, 0, 20, 10, roid->color, 2.0f);
  al_draw_line(20, 10, 10, 20, roid->color, 2.0f);
  al_draw_line(10, 20, 0, 15, roid->color, 2.0f);
  al_draw_line(0, 15, -22, 20, roid->color, 2.0f);
}
コード例 #11
0
bool DisplayResource::load(void)
{
#ifdef ALLEGRO_IPHONE
   int flags = ALLEGRO_FULLSCREEN_WINDOW;
   al_set_new_display_option(ALLEGRO_SUPPORTED_ORIENTATIONS, ALLEGRO_DISPLAY_ORIENTATION_LANDSCAPE, ALLEGRO_REQUIRE);
#else
   int flags = useFullScreenMode ? ALLEGRO_FULLSCREEN : ALLEGRO_WINDOWED;
#endif
   al_set_new_display_flags(flags);
   display = al_create_display(BB_W, BB_H);
   if (!display)
       return false;

#ifndef ALLEGRO_IPHONE
   ALLEGRO_BITMAP *bmp = al_load_bitmap(getResource("gfx/icon48.png"));
   al_set_display_icon(display, bmp);
   al_destroy_bitmap(bmp);
#endif

   BB_W = al_get_display_width(display);
   BB_H = al_get_display_height(display);
   
#ifdef ALLEGRO_IPHONE
   if (BB_W < 960) {
	BB_W *= 2;
	BB_H *= 2;
	ALLEGRO_TRANSFORM t;
	al_identity_transform(&t);
	al_scale_transform(&t, 0.5, 0.5);
	al_use_transform(&t);
   }
#endif
      
   events = al_create_event_queue();
   al_register_event_source(events, al_get_display_event_source(display));

   return true;
}
コード例 #12
0
ファイル: ScrollableArea.cpp プロジェクト: kruci/rGUI
    void ScrollableArea::Print()
    {
        wd_PrintBegin();

        wd_Print_Background();

        al_identity_transform(&rest);
        if((wd_bf & bf_ZOOMABLE))
        {
            al_scale_transform(&rest, zoom, zoom);
        }
        al_translate_transform(&rest, wd_theme.added_thickness/2, wd_theme.added_thickness/2);
        al_use_transform(&rest);
        al_set_clipping_rectangle(wd_theme.added_thickness/2 + wd_theme.thickness,
                                  wd_theme.added_thickness/2 + wd_theme.thickness,
                                  /*wd_theme.added_thickness/2 + */wd_width - (scb_vertical_active == true ? scb_thickness:0) /*- wd_theme.thickness*/,
                                  /*wd_theme.added_thickness/2 + */wd_height - (scb_horizontal_active == true ? scb_thickness:0) /*- wd_theme.thickness*/);

        for(int a = 0; a < (int)widgets.size();a++)
        {

            if(( (widgets[a]->orig_x1 *zoom >= scb_horizontal->change && widgets[a]->orig_x1 *zoom<= scb_horizontal->change + wd_width)
                 || (widgets[a]->orig_x2 *zoom>= scb_horizontal->change && widgets[a]->orig_x2 *zoom<= scb_horizontal->change + wd_width)
                 || (widgets[a]->orig_x1 *zoom<= scb_horizontal->change && widgets[a]->orig_x2 *zoom>= scb_horizontal->change + wd_width)
                ) && (
                (widgets[a]->orig_y1 *zoom>= scb_vertical->change && widgets[a]->orig_y1 *zoom<= scb_vertical->change + wd_height)
                 || (widgets[a]->orig_y2 *zoom>= scb_vertical->change && widgets[a]->orig_y2 *zoom<= scb_vertical->change + wd_height)
                 || (widgets[a]->orig_y1 *zoom<= scb_vertical->change && widgets[a]->orig_y2 *zoom>= scb_vertical->change + wd_height)))
            {
                if(changec_p == true)
                {
                    widgets[a]->Change_print_coords(widgets[a]->orig_x1 - scb_horizontal->change/zoom,
                    widgets[a]->orig_y1 - scb_vertical->change/zoom, widgets[a]->wd_width, widgets[a]->wd_height);



                    widgets[a]->wd_md->Change_coords(wd_x1 + widgets[a]->orig_x1*zoom - scb_horizontal->change,
                                                     wd_y1 + widgets[a]->orig_y1*zoom - scb_vertical->change,
                                                     (widgets[a]->orig_x2 - widgets[a]->orig_x1)*zoom,
                                                     (widgets[a]->orig_y2 - widgets[a]->orig_y1)*zoom);
                }
                widgets[a]->Print();
            }
        }
        changec_p = false;

        al_identity_transform(&rest);
        al_translate_transform(&rest, wd_theme.added_thickness/2, wd_theme.added_thickness/2);
        al_use_transform(&rest);

        al_set_clipping_rectangle(0,0,
                                  wd_width + wd_theme.added_thickness, wd_height + wd_theme.added_thickness);
        zoomresetb->Print();
        scb_horizontal->Print();
        scb_vertical->Print();


        al_identity_transform(&rest);
        al_use_transform(&rest);
        wd_Print_Frame();

        wd_PrintEnd();
    }
コード例 #13
0
ファイル: engine.c プロジェクト: eliasYFGM/allegro-templates
int engine_init(struct Engine_Conf *conf)
{
  if (engine.initialized)
  {
    puts("WARNING: Calling game_init() more than once");
    return 1;
  }

  // Initialize Allegro and stuff
  al_init();

  if (!al_install_keyboard())
  {
    puts("ERROR: Could not initialize the keyboard...");
    return 0;
  }

  if (conf->audio)
  {
    if (!al_install_audio())
    {
      puts("ERROR: Could not initialize audio...");
      return 0;
    }

    if (!al_init_acodec_addon())
    {
      puts("ERROR: Could not initialize acodec addon...");
      return 0;
    }
  }

  // Add-ons
  if (!al_init_image_addon())
  {
    puts("ERROR: Could not initialize image addon...");
    return 0;
  }

  al_init_font_addon();
  al_init_primitives_addon();

  // Find how much the game will be scaled when conf->scale <= 0
  if (conf->scale <= 0)
  {
    ALLEGRO_MONITOR_INFO info;
    al_get_monitor_info(0, &info);

    int monitor_w = info.x2 - info.x1;
    int monitor_h = info.y2 - info.y1;

    float new_monitor_w = (monitor_w - (monitor_w * SCREEN_RES_OVERRIDE));
    float new_monitor_h = (monitor_h - (monitor_h * SCREEN_RES_OVERRIDE));

    conf->scale = 2;

    // Keep scaling until a suitable scale factor is found
    while (1)
    {
      int scale_w = conf->width * conf->scale;
      int scale_h = conf->height * conf->scale;

      if (scale_w > new_monitor_w || scale_h > new_monitor_h)
      {
        --conf->scale;
        break;
      }

      ++conf->scale;
    }
  }
  else if (conf->scale < 2)
  {
    conf->scale = 2;
  }

  engine.display = al_create_display(conf->width * conf->scale,
    conf->height * conf->scale);

  if (!engine.display)
  {
    puts("ERROR: Could not create a display window...");
    return 0;
  }

  al_set_window_title(engine.display, conf->title);

  font = al_create_builtin_font();

  engine.timer = al_create_timer(1.0 / conf->framerate);
  engine.event_queue = al_create_event_queue();

  mainconf = conf;
  set_bg_color(BG_COLOR_DEFAULT);

  ALLEGRO_TRANSFORM trans;
  al_identity_transform(&trans);
  al_scale_transform(&trans, conf->scale, conf->scale);
  al_use_transform(&trans);

  engine.initialized = TRUE;

  return 1;
}
コード例 #14
0
ファイル: Main.cpp プロジェクト: kckrepo/kck-repo
int main(int argc, char **argv)
{
	bool done = false;
	bool render = false;

	float gameTime = 0;
	int frames = 0;
	int gameFPS = 0;

	float evTimer = 0;

	tractor = new Tractor();
	Xml = new xml();

	int state = -1;

	ALLEGRO_BITMAP *icon;
	ALLEGRO_BITMAP *map = NULL;
	ALLEGRO_BITMAP *panel = NULL;
	ALLEGRO_BITMAP *tractorImage = NULL;
	ALLEGRO_BITMAP *titleImage = NULL;
	ALLEGRO_BITMAP *lostImage = NULL;
	ALLEGRO_SAMPLE *titleSong = NULL;
	ALLEGRO_SAMPLE *gameSong = NULL;
	ALLEGRO_SAMPLE *lostSong = NULL;
	ALLEGRO_SAMPLE *cash = NULL;

	ALLEGRO_BITMAP *L1 = NULL;
	ALLEGRO_BITMAP *L2 = NULL;
	ALLEGRO_BITMAP *L3 = NULL;
	ALLEGRO_BITMAP *L4 = NULL;
	ALLEGRO_BITMAP *L5 = NULL;
	ALLEGRO_BITMAP *L6 = NULL;
	ALLEGRO_BITMAP *L7 = NULL;

	ALLEGRO_DISPLAY *display = NULL;
	ALLEGRO_DISPLAY_MODE   disp_data;
	ALLEGRO_EVENT_QUEUE *event_queue = NULL;
	ALLEGRO_TIMER *timer;
	ALLEGRO_FONT *font;
	ALLEGRO_FONT *score;

	if (!al_init())
		return -1;

	al_install_keyboard();
	al_install_mouse();
	al_init_image_addon();
	al_init_font_addon();
	al_init_ttf_addon();
	al_init_primitives_addon();
	al_install_audio();
	al_init_acodec_addon();

	al_get_display_mode(al_get_num_display_modes() - 1, &disp_data);

	//al_set_new_display_flags(ALLEGRO_FULLSCREEN);
	al_set_new_display_option(ALLEGRO_VSYNC, 1, ALLEGRO_REQUIRE);

	display = al_create_display(disp_data.width, disp_data.height);

	icon = al_load_bitmap("icon.png");
	al_set_display_icon(display, icon);

	float sx = (float)disp_data.width / WIDTH;
	float sy = (float)disp_data.height / HEIGHT;

	ALLEGRO_TRANSFORM trans;
	al_identity_transform(&trans);
	al_scale_transform(&trans, sx, sy);
	al_use_transform(&trans);

	if (!display)
		return -1;

	font = al_load_font("arial.ttf", 20, 0);
	score = al_load_font("score.ttf", 45, 0);
	al_reserve_samples(15);

	map = al_load_bitmap("map2.png");
	panel = al_load_bitmap("panel.png");

	L1 = al_load_bitmap("l1.png");
	L2 = al_load_bitmap("l2.png");
	L3 = al_load_bitmap("l3.png");
	L4 = al_load_bitmap("l4.png");
	L5 = al_load_bitmap("l5.png");
	L6 = al_load_bitmap("l6.png");
	L7 = al_load_bitmap("l7.png");

	Background *Map = new Background(map);
	objects.push_back(Map);

	TextBox *Task = new TextBox;

	Field *field1 = new Field(L1, L2, L3, L4, L5, L6, L7, 50, 50);
	objects.push_back(field1);
	Field *field2 = new Field(L1, L2, L3, L4, L5, L6, L7, 450, 50);
	objects.push_back(field2);
	Field *field3 = new Field(L1, L2, L3, L4, L5, L6, L7, 50, 450);
	objects.push_back(field3);
	Field *field4 = new Field(L1, L2, L3, L4, L5, L6, L7, 450, 450);
	objects.push_back(field4);

	tractorImage = al_load_bitmap("tractor.png");
	cash = al_load_sample("cash.ogg");
	tractor->Init(tractorImage, cash);
	objects.push_back(tractor);

	titleImage = al_load_bitmap("screen_Title.png");
	lostImage = al_load_bitmap("screen_Lost.png");

	titleScreen = new Background(titleImage);
	lostScreen = new Background(lostImage);

	titleSong = al_load_sample("title.ogg");
	gameSong = al_load_sample("game.ogg");
	lostSong = al_load_sample("lost.ogg");

	songInstance = al_create_sample_instance(titleSong);
	al_set_sample_instance_playmode(songInstance, ALLEGRO_PLAYMODE_LOOP);

	songInstance2 = al_create_sample_instance(gameSong);
	al_set_sample_instance_playmode(songInstance2, ALLEGRO_PLAYMODE_LOOP);

	songInstance3 = al_create_sample_instance(lostSong);
	al_set_sample_instance_playmode(songInstance3, ALLEGRO_PLAYMODE_LOOP);

	al_attach_sample_instance_to_mixer(songInstance, al_get_default_mixer());
	al_attach_sample_instance_to_mixer(songInstance2, al_get_default_mixer());
	al_attach_sample_instance_to_mixer(songInstance3, al_get_default_mixer());

	ChangeState(state, TITLE);

	event_queue = al_create_event_queue();
	timer = al_create_timer(1.0 / 60);

	al_register_event_source(event_queue, al_get_timer_event_source(timer));
	al_register_event_source(event_queue, al_get_keyboard_event_source());
	al_register_event_source(event_queue, al_get_mouse_event_source());

	al_start_timer(timer);
	gameTime = al_current_time();

	while (!done)
	{
		ALLEGRO_EVENT ev;
		al_wait_for_event(event_queue, &ev);

		if (ev.type == ALLEGRO_EVENT_KEY_DOWN)
		{
			switch (ev.keyboard.keycode)
			{
			case ALLEGRO_KEY_ESCAPE:
				done = true;
				break;
			case ALLEGRO_KEY_LEFT:
				keys[LEFT] = true;
				break;
			case ALLEGRO_KEY_RIGHT:
				keys[RIGHT] = true;
				break;
			case ALLEGRO_KEY_UP:
				keys[UP] = true;
				break;
			case ALLEGRO_KEY_DOWN:
				keys[DOWN] = true;
				break;
			case ALLEGRO_KEY_ENTER:
				keys[ENTER] = true;
				if (state == TITLE)
					ChangeState(state, PLAYING);
				else if (state == PLAYING && Task->CheckText())
				{
					TextBox *text = new TextBox();
					text->SetText(Task->Send());
					history.push_back(text);

					for (iter2 = history.begin(); iter2 != history.end(); iter2++)
					{
						if ((*iter2)->GetY() < 400)
						{
							delete (*iter2);
							iter2 = history.erase(iter2);
						}
						(*iter2)->UpdateY();
					}

					Xml->interpreter(Task->GetLast(), tractor);

					TextBox *txtxml = new TextBox();
					txtxml->SetText(Xml->wyslij());
					history.push_back(txtxml);

					for (iter2 = history.begin(); iter2 != history.end(); iter2++)
					{
						if ((*iter2)->GetY() < 300)
						{
							delete (*iter2);
							iter2 = history.erase(iter2);
						}
						(*iter2)->UpdateY();
					}
				}
				else if (state == LOST)
					ChangeState(state, PLAYING);
				break;
			case ALLEGRO_KEY_TAB:
				keys[TAB] = true;
				if (state == PLAYING)
				{

					Task->SetStatus();
					if (Task->GetStatus())
					{
						TextBox *text = new TextBox();
						text->SetText("Konsola zostala wlaczona");
						history.push_back(text);
					}
					else
					{
						TextBox *text = new TextBox();
						text->SetText("Konsola zostala wylaczona");
						history.push_back(text);
					}

					for (iter2 = history.begin(); iter2 != history.end(); iter2++)
					{
						if ((*iter2)->GetY() < 300)
						{
							delete (*iter2);
							iter2 = history.erase(iter2);
						}
						(*iter2)->UpdateY();
					}

					setTimer(evTimer);
				}
				tractor->Sell();
				break;
			case ALLEGRO_KEY_SPACE:
				keys[SPC] = true;
				if (state == PLAYING)
					Task->Add(" ");
				break;
			case ALLEGRO_KEY_BACKSPACE:
				if (state == PLAYING && Task->CheckText())
					Task->Backspace();
				break;
			case ALLEGRO_KEY_COMMA:
				keys[COM] = true;
				if (state == PLAYING && Task->GetStatus())
					Task->Add(",");
				break;
			case ALLEGRO_KEY_0:
				numb[N0] = true;
				if (state == PLAYING && Task->GetStatus())
					Task->Add("0");
				break;
			case ALLEGRO_KEY_1:
				numb[N1] = true;
				if (state == PLAYING && Task->GetStatus())
					Task->Add("1");
				break;
			case ALLEGRO_KEY_2:
				numb[N2] = true;
				if (state == PLAYING && Task->GetStatus())
					Task->Add("2");
				break;
			case ALLEGRO_KEY_3:
				numb[N3] = true;
				if (state == PLAYING && Task->GetStatus())
					Task->Add("3");
				break;
			case ALLEGRO_KEY_4:
				numb[N4] = true;
				if (state == PLAYING && Task->GetStatus())
					Task->Add("4");
				break;
			case ALLEGRO_KEY_5:
				numb[N5] = true;
				if (state == PLAYING && Task->GetStatus())
					Task->Add("5");
				break;
			case ALLEGRO_KEY_6:
				numb[N6] = true;
				if (state == PLAYING && Task->GetStatus())
					Task->Add("6");
				break;
			case ALLEGRO_KEY_7:
				numb[N7] = true;
				if (state == PLAYING && Task->GetStatus())
					Task->Add("7");
				break;
			case ALLEGRO_KEY_8:
				numb[N8] = true;
				if (state == PLAYING && Task->GetStatus())
					Task->Add("8");
				break;
			case ALLEGRO_KEY_9:
				numb[N9] = true;
				if (state == PLAYING && Task->GetStatus())
					Task->Add("9");
				break;
			case ALLEGRO_KEY_A:
				letters[A] = true;
				if (state == PLAYING && Task->GetStatus())
					Task->Add("a");
				break;
			case ALLEGRO_KEY_B:
				letters[B] = true;
				if (state == PLAYING && Task->GetStatus())
					Task->Add("b");
				break;
			case ALLEGRO_KEY_C:
				letters[C] = true;
				if (state == PLAYING && Task->GetStatus())
					Task->Add("c");
				break;
			case ALLEGRO_KEY_D:
				letters[D] = true;
				if (state == PLAYING && Task->GetStatus())
					Task->Add("d");
				break;
			case ALLEGRO_KEY_E:
				letters[E] = true;
				if (state == PLAYING && Task->GetStatus())
					Task->Add("e");
				break;
			case ALLEGRO_KEY_F:
				letters[F] = true;
				if (state == PLAYING && Task->GetStatus())
					Task->Add("f");
				break;
			case ALLEGRO_KEY_G:
				letters[G] = true;
				if (state == PLAYING && Task->GetStatus())
					Task->Add("g");
				break;
			case ALLEGRO_KEY_H:
				letters[H] = true;
				if (state == PLAYING && Task->GetStatus())
					Task->Add("h");
				break;
			case ALLEGRO_KEY_I:
				letters[I] = true;
				if (state == PLAYING && Task->GetStatus())
					Task->Add("i");
				break;
			case ALLEGRO_KEY_J:
				letters[J] = true;
				if (state == PLAYING && Task->GetStatus())
					Task->Add("j");
				break;
			case ALLEGRO_KEY_K:
				letters[K] = true;
				if (state == PLAYING && Task->GetStatus())
					Task->Add("k");
				break;
			case ALLEGRO_KEY_L:
				letters[L] = true;
				if (state == PLAYING && Task->GetStatus())
					Task->Add("l");
				break;
			case ALLEGRO_KEY_M:
				letters[M] = true;
				if (state == PLAYING && Task->GetStatus())
					Task->Add("m");
				break;
			case ALLEGRO_KEY_N:
				letters[N] = true;
				if (state == PLAYING && Task->GetStatus())
					Task->Add("n");
				break;
			case ALLEGRO_KEY_O:
				letters[O] = true;
				if (state == PLAYING && Task->GetStatus())
					Task->Add("o");
				break;
			case ALLEGRO_KEY_P:
				letters[P] = true;
				if (state == PLAYING && Task->GetStatus())
					Task->Add("p");
				break;
			case ALLEGRO_KEY_Q:
				letters[Q] = true;
				if (state == PLAYING && Task->GetStatus())
					Task->Add("q");
				break;
			case ALLEGRO_KEY_R:
				letters[R] = true;
				if (state == PLAYING && Task->GetStatus())
					Task->Add("r");
				break;
			case ALLEGRO_KEY_S:
				letters[S] = true;
				if (state == PLAYING && Task->GetStatus())
					Task->Add("s");
				break;
			case ALLEGRO_KEY_T:
				letters[T] = true;
				if (state == PLAYING && Task->GetStatus())
					Task->Add("t");
				break;
			case ALLEGRO_KEY_U:
				letters[U] = true;
				if (state == PLAYING && Task->GetStatus())
					Task->Add("u");
				break;
			case ALLEGRO_KEY_V:
				letters[V] = true;
				if (state == PLAYING && Task->GetStatus())
					Task->Add("v");
				break;
			case ALLEGRO_KEY_W:
				letters[W] = true;
				if (state == PLAYING && Task->GetStatus())
					Task->Add("w");
				break;
			case ALLEGRO_KEY_X:
				letters[X] = true;
				if (state == PLAYING && Task->GetStatus())
					Task->Add("x");
				break;
			case ALLEGRO_KEY_Y:
				letters[Y] = true;
				if (state == PLAYING && Task->GetStatus())
					Task->Add("y");
				break;
			case ALLEGRO_KEY_Z:
				letters[Z] = true;
				if (state == PLAYING && Task->GetStatus())
					Task->Add("z");
				break;
			}
		}
		else if (ev.type == ALLEGRO_EVENT_KEY_UP)
		{
			switch (ev.keyboard.keycode)
			{
			case ALLEGRO_KEY_ESCAPE:
				done = true;
				break;
			case ALLEGRO_KEY_LEFT:
				keys[LEFT] = false;
				break;
			case ALLEGRO_KEY_RIGHT:
				keys[RIGHT] = false;
				break;
			case ALLEGRO_KEY_UP:
				keys[UP] = false;
				break;
			case ALLEGRO_KEY_DOWN:
				keys[DOWN] = false;
				break;
			case ALLEGRO_KEY_ENTER:
				keys[ENTER] = false;
				break;
			case ALLEGRO_KEY_TAB:
				keys[TAB] = false;
				break;
			case ALLEGRO_KEY_BACKSPACE:
				keys[BSPC] = false;
				break;
			case ALLEGRO_KEY_COMMA:
				keys[COM] = false;
				break;
			case ALLEGRO_KEY_0:
				numb[N0] = false;
				break;
			case ALLEGRO_KEY_1:
				numb[N1] = false;
				break;
			case ALLEGRO_KEY_2:
				numb[N2] = false;
				break;
			case ALLEGRO_KEY_3:
				numb[N3] = false;
				break;
			case ALLEGRO_KEY_4:
				numb[N4] = false;
				break;
			case ALLEGRO_KEY_5:
				numb[N5] = false;
				break;
			case ALLEGRO_KEY_6:
				numb[N6] = false;
				break;
			case ALLEGRO_KEY_7:
				numb[N7] = false;
				break;
			case ALLEGRO_KEY_8:
				numb[N8] = false;
				break;
			case ALLEGRO_KEY_9:
				numb[N9] = false;
				break;
			case ALLEGRO_KEY_A:
				letters[A] = false;
				break;
			case ALLEGRO_KEY_B:
				letters[B] = false;
				break;
			case ALLEGRO_KEY_C:
				letters[C] = false;
				break;
			case ALLEGRO_KEY_D:
				letters[D] = false;
				break;
			case ALLEGRO_KEY_E:
				letters[E] = false;
				break;
			case ALLEGRO_KEY_F:
				letters[F] = false;
				break;
			case ALLEGRO_KEY_G:
				letters[G] = false;
				break;
			case ALLEGRO_KEY_H:
				letters[H] = false;
				break;
			case ALLEGRO_KEY_I:
				letters[I] = false;
				break;
			case ALLEGRO_KEY_J:
				letters[J] = false;
				break;
			case ALLEGRO_KEY_K:
				letters[K] = false;
				break;
			case ALLEGRO_KEY_L:
				letters[L] = false;
				break;
			case ALLEGRO_KEY_M:
				letters[M] = false;
				break;
			case ALLEGRO_KEY_N:
				letters[N] = false;
				break;
			case ALLEGRO_KEY_O:
				letters[O] = false;
				break;
			case ALLEGRO_KEY_P:
				letters[P] = false;
				break;
			case ALLEGRO_KEY_Q:
				letters[Q] = false;
				break;
			case ALLEGRO_KEY_R:
				letters[R] = false;
				break;
			case ALLEGRO_KEY_S:
				letters[S] = false;
				break;
			case ALLEGRO_KEY_T:
				letters[T] = false;
				break;
			case ALLEGRO_KEY_U:
				letters[U] = false;
				break;
			case ALLEGRO_KEY_V:
				letters[V] = false;
				break;
			case ALLEGRO_KEY_W:
				letters[W] = false;
				break;
			case ALLEGRO_KEY_X:
				letters[X] = false;
				break;
			case ALLEGRO_KEY_Y:
				letters[Y] = false;
				break;
			case ALLEGRO_KEY_Z:
				letters[Z] = false;
				break;
			}
		}

		else if (ev.type == ALLEGRO_EVENT_TIMER)
		{
			render = true;

			frames++;

			if (al_current_time() - gameTime >= 1)
			{
				gameTime = al_current_time();
				gameFPS = frames;
				frames = 0;
			}

			if (state == PLAYING)
			{
				if (keys[UP])
				{
					if (Map->GetY() + Map->frameHeight > disp_data.height)
					{
						for (iter = objects.begin(); iter != objects.end(); ++iter)
						{
							(*iter)->SetY((*iter)->GetY() - 10);
						}
						tractor->SetDistY((tractor->GetDistY() - 10));
					}
				}
				else if (keys[DOWN])
				{
					if (Map->GetY() < 0)
					{
						for (iter = objects.begin(); iter != objects.end(); ++iter)
						{
							(*iter)->SetY((*iter)->GetY() + 10);
						}
						tractor->SetDistY(tractor->GetDistY() + 10);
					}
				}

				if (keys[LEFT])
				{
					if (Map->GetWidth() > (disp_data.width - al_get_bitmap_width(panel)))
					{
						for (iter = objects.begin(); iter != objects.end(); ++iter)
						{
							(*iter)->SetX((*iter)->GetX() - 10);
						}
						tractor->SetDistX(tractor->GetDistX() - 10);
					}
				}
				else if (keys[RIGHT])
				{
					if (Map->GetX() < 0)
					{
						for (iter = objects.begin(); iter != objects.end(); ++iter)
						{
							(*iter)->SetX((*iter)->GetX() + 10);
						}
						tractor->SetDistX(tractor->GetDistX() + 10);
					}
				}

				for (iter = objects.begin(); iter != objects.end(); ++iter)
					(*iter)->Update();

				if (tractor->GetStatus())
					tractor->Move();

				field1->Change_Field();
				field1->Grow_Field();
				field2->Change_Field();
				field2->Grow_Field();
				field3->Change_Field();
				field3->Grow_Field();
				field4->Change_Field();
				field4->Grow_Field();
				field1->Action_On_Field(tractor);
				field2->Action_On_Field(tractor);
				field3->Action_On_Field(tractor);
				field4->Action_On_Field(tractor);

				if (!tractor->Get_Iminwork()){
					Xml->ZKolejki(field1, field2, field3, field4, tractor);
					if (Xml->wyslij() != ""){
						TextBox *txtxml = new TextBox();
						txtxml->SetText(Xml->wyslij());
						history.push_back(txtxml);

						for (iter2 = history.begin(); iter2 != history.end(); iter2++)
						{
							if ((*iter2)->GetY() < 300)
							{
								delete (*iter2);
								iter2 = history.erase(iter2);
							}

							(*iter2)->UpdateY();
						}
					}
				}
				if (evTimer < 60)
				{
					evTimer += 0.1;
				}
				else
				{
					if (tractor->GetPodpowiedz() == 0)
					{
						Xml->podpowiedz(field1, field2, field3, field4, tractor);
						evTimer = 0;

						TextBox *txtxml = new TextBox();
						txtxml->SetText(Xml->wyslij());
						history.push_back(txtxml);

						for (iter2 = history.begin(); iter2 != history.end(); iter2++)
						{
							if ((*iter2)->GetY() < 300)
							{
								delete (*iter2);
								iter2 = history.erase(iter2);
							}

							(*iter2)->UpdateY();
						}
					}
					
				}
			}

			if (tractor->GetMoney() <= 0)
				ChangeState(state, LOST);
		}

		for (iter = objects.begin(); iter != objects.end();)
		{
			if (!(*iter)->GetAlive())
			{
				delete (*iter);
				iter = objects.erase(iter);
			}
			else
				iter++;
		}

		if (render && al_is_event_queue_empty(event_queue))
		{
			render = false;

			if (state == TITLE)
			{
				titleScreen->Render();
			}
			else if (state == PLAYING)
			{
				for (iter = objects.begin(); iter != objects.end(); ++iter)
					(*iter)->Render();

				al_draw_bitmap(panel, WIDTH - al_get_bitmap_width(panel), 0, 0);
				al_draw_textf(font, al_map_rgb(255, 255, 255), Task->GetX(), Task->GetY(), 0, Task->ShowText());

				for (iter2 = history.begin(); iter2 != history.end(); iter2++)
				{
					al_draw_textf(font, al_map_rgb(255, 255, 255), (*iter2)->GetX(), (*iter2)->GetY(), 0, (*iter2)->ShowText());
				}

				if (tractor->GetHealth() < 20)
					al_draw_textf(score, RED, WIDTH - 430, 15, 0, "%i", tractor->GetHealth());
				else
					al_draw_textf(score, BLACK, WIDTH - 430, 15, 0, "%i", tractor->GetHealth());
				
				if (tractor->GetFuel() < 20)
					al_draw_textf(score, RED, WIDTH - 260, 15, 0, "%i", tractor->GetFuel());
				else
					al_draw_textf(score, BLACK, WIDTH - 260, 15, 0, "%i", tractor->GetFuel());
				
				if (tractor->GetMoney() < 200)
					al_draw_textf(score, RED, WIDTH - 400, 100, 0, "%i", tractor->GetMoney());
				else
					al_draw_textf(score, BLACK, WIDTH - 400, 100, 0, "%i", tractor->GetMoney());

				al_draw_textf(score, BLACK, WIDTH - 70, 15, 0, "%i", tractor->GetWater());

				for (int j = 0; j < 5; j++)
				{
					al_draw_textf(font, BLACK, WIDTH - 170, 85 + j * 20, 0, "%i", tractor->GetSupply(0, j));
				}

				for (int j = 0; j < 5; j++)
				{
					al_draw_textf(font, BLACK, WIDTH - 150, 85 + j * 20, 0, "%i", tractor->GetSupply(1, j));
				}

				al_draw_textf(font, al_map_rgb(255, 0, 255), 5, 5, 0, "FPS: %i", WIDTH - al_get_bitmap_width(panel) /*gameFPS*/);
			}
			else if (state == LOST)
				lostScreen->Render();

			al_flip_display();
			al_clear_to_color(al_map_rgb(0, 0, 0));
		}
	}

	for (iter = objects.begin(); iter != objects.end();)
	{
		(*iter)->Destroy();
		delete (*iter);
		iter = objects.erase(iter);
	}

	for (iter2 = history.begin(); iter2 != history.end();)
	{
		(*iter2)->Destroy();
		delete (*iter2);
		iter2 = history.erase(iter2);
	}

	//tractor->Destroy();
	Task->Destroy();
	titleScreen->Destroy();
	lostScreen->Destroy();
	delete titleScreen;
	delete lostScreen;
	al_destroy_sample(cash);
	al_destroy_sample_instance(songInstance);
	al_destroy_sample_instance(songInstance2);
	al_destroy_sample_instance(songInstance3);

	al_destroy_font(score);
	al_destroy_font(font);
	al_destroy_timer(timer);
	al_destroy_event_queue(event_queue);
	al_destroy_display(display);
			
	return 0;
}
コード例 #15
0
ファイル: exp1.cpp プロジェクト: kruci/rGUI
int main(int argc, char **argv)
{
    char cCurrentPath[FILENAME_MAX];

    if (!GetCurrentDir(cCurrentPath, sizeof(cCurrentPath)))
    {
        return errno;
    }

    cCurrentPath[sizeof(cCurrentPath) - 1] = '\0'; /* not really required */

    std::cout << cCurrentPath << std::endl;

    int newsw = 771 , newsh = 600;
    float _sx = (float)newsw / (float)SCREEN_W, _sy = (float)newsh / (float)SCREEN_H;
    float _offx = (SCREEN_W - newsw)/2, _offy = (SCREEN_H - newsh)/2;

    rGUI::Init_Allegro();
    rGUI::Init_rGUI();
    //rGUI::Init_rGUI(_sx, _sy, _offx, _offy);

    ALLEGRO_DISPLAY *display = NULL;
    ALLEGRO_EVENT_QUEUE *event_queue = NULL;
    ALLEGRO_TIMER *timer = NULL;
    ALLEGRO_BITMAP *bouncer = NULL;
    float bouncer_x = SCREEN_W / 2.0 - BOUNCER_SIZE / 2.0;
    float bouncer_y = SCREEN_H / 2.0 - BOUNCER_SIZE / 2.0;
    bool redraw = true;
    ALLEGRO_FONT *font = al_load_font("Calibri.ttf", 35, 0);

    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);
    //display = al_create_display(newsw, newsh);

    al_set_new_bitmap_flags(ALLEGRO_MIN_LINEAR | ALLEGRO_MAG_LINEAR);
    if(!display)
    {
        fprintf(stderr, "failed to create display!\n");
        al_destroy_timer(timer);
        return -1;
    }

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

    al_set_target_bitmap(bouncer);

    al_clear_to_color(al_map_rgb(255, 0, 255));

    al_set_target_bitmap(al_get_backbuffer(display));

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

    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_mouse_event_source());
    al_register_event_source(event_queue, al_get_keyboard_event_source());


    al_clear_to_color(al_map_rgb(0,0,0));

    al_flip_display();

    al_start_timer(timer);

    tmh.c_text = al_map_rgba(255,255,255,0);
    tmh.c_outline = al_map_rgba(0,200,0,255);
    tmh.c_background = al_map_rgba(255,0,0,255);
    tmh.c_movablepart = al_map_rgb(200,0,0);
    tmh.c_clicking = al_map_rgba(0,0,0,125);
    tmh.thickness = 2;
    tmh.added_thickness = 2;
    tmh.roundx = 0;
    tmh.roundy = 0;
    ALLEGRO_FONT *fnt = al_load_ttf_font("Calibri.ttf",30,0);



    widgets.push_back(new rGUI::Button(10,40,100,50,"wwwLong text", "Calibri.ttf",&tmh));
    tmh.roundx = 3;
    tmh.roundy = 3;
    widgets.push_back(new rGUI::CheckBox(160, 40, 50,50,&tmh, false));
    widgets.push_back(new rGUI::SlideBar(10,100,100,30,0,1,&tmh, (rGUI::bf_HORIZONTAL | rGUI::bf_HAS_FRAME) ));
    widgets.push_back(new rGUI::SlideBar(115,40,30,50,0,5, &tmh, (rGUI::bf_VERTICAL | rGUI::bf_HAS_FRAME) ));
    widgets.push_back(new rGUI::BitmapButton(10,140,100,45, "button.png",&tmh, 0));
    widgets.push_back(new rGUI::ScrollBar(220, 5, 30, 185, 800, &tmh, (rGUI::bf_VERTICAL)));
    widgets.push_back(new rGUI::ScrollBar(10, 195, 240, 30, 800, &tmh, (rGUI::bf_HORIZONTAL)));
    widgets.push_back(new rGUI::InputField(115,100,95,40, "Calibri.ttf",&tmh, FPS));
    widgets.push_back(new rGUI::SingleKeyInputField(115,145,95,40, ALLEGRO_KEY_BACKQUOTE, "Calibri.ttf",&tmh));

    //Callback example
    int progressbar = widgets.size();
    widgets.push_back(new rGUI::ProgressBar(10,5,200,30,0,&tmh));
    widgets[progressbar]->wd_md->md_callback_data = widgets[progressbar];
    widgets[progressbar]->wd_md->Just_clicked_callback = pbar_callback;


    widgets.push_back(new rGUI::ScrollableArea(10,240,440,440,2000,2000,&tmh,20, (rGUI::bf_VERTICAL | rGUI::bf_HORIZONTAL | rGUI::bf_ZOOMABLE)));
    int scbapoz = widgets.size()-1;
    widgets[scbapoz]->widgets.push_back(new rGUI::Button(10,10,100,30, "Text", "Calibri.ttf", &tmh));
    widgets[scbapoz]->widgets.push_back(new rGUI::BitmapButton(10,50,100,45, "button.png",&tmh, 0));
    widgets[scbapoz]->widgets.push_back(new rGUI::CheckBox(120, 30, 50,50,&tmh, false));
    widgets[scbapoz]->widgets.push_back(new rGUI::SlideBar(10,100,120,30,0,300,&tmh, (rGUI::bf_HORIZONTAL | rGUI::bf_HAS_FRAME) ));
    widgets[scbapoz]->widgets.push_back(new rGUI::ScrollBar(10, 160, 120, 30, 800, &tmh, (rGUI::bf_HORIZONTAL)));
    widgets[scbapoz]->widgets.push_back(new rGUI::InputField(10,2000,100,40, "Calibri.ttf",&tmh, FPS));
    widgets[scbapoz]->widgets.push_back(new rGUI::TextBox(2000,1200,300,120, "Big box", "Calibri.ttf", 200,&tmh,
                                                          (rGUI::bf_HAS_FRAME | rGUI::bf_RESIZE_CONTENT)));
    widgets[scbapoz]->widgets.push_back(new rGUI::SlideBar(1000,100,200,40,0,20,&tmh, (rGUI::bf_HORIZONTAL | rGUI::bf_HAS_FRAME) ));
    widgets[scbapoz]->widgets.push_back(new rGUI::BitmapButton(300,300,0,0, "image.jpg",&tmh, (rGUI::bf_RESIZE_WIDGET | rGUI::bf_DISABLE_CLICKING_SHADOW)));
    ((rGUI::ScrollableArea*)widgets[scbapoz])->I_added_new_widgets();

    //roundXY
    widgets.push_back(new rGUI::TextBox(680,5,300,40, "RoundXY",  "Calibri.ttf",15, &tmh, (rGUI::bf_HAS_FRAME)));
    int poz_roundXY = widgets.size();
    widgets.push_back(new rGUI::SlideBar(800,10,100,30,0,10,&tmh, (rGUI::bf_HORIZONTAL)));
    //Thickness
    widgets.push_back(new rGUI::TextBox(680,50,300,40, "Thickness",  "Calibri.ttf",15, &tmh, (rGUI::bf_HAS_FRAME)));
    int poz_thickness = widgets.size();
    widgets.push_back(new rGUI::SlideBar(800,55,100,30,0,10,&tmh, (rGUI::bf_HORIZONTAL)));

    //Added thickness
    widgets.push_back(new rGUI::TextBox(680,95,300,40, "Added Thickness",  "Calibri.ttf",10, &tmh, (rGUI::bf_HAS_FRAME)));
    int poz_addedthickness = widgets.size();
    widgets.push_back(new rGUI::SlideBar(800,100,100,30,0,10,&tmh, (rGUI::bf_HORIZONTAL)));

    //Update Button
    int poz_updatebutton = widgets.size();
    widgets.push_back(new rGUI::Button(680,140,180,40,"Update Theme","Calibri.ttf", &tmh));

    //Reset Button
    int poz_rb = widgets.size();
    widgets.push_back(new rGUI::TextBox(862,140,36,40,"Reset theme","Calibri.ttf", 12, &tmh,
                                        (rGUI::bf_AS_BUTTON | rGUI::bf_HAS_FRAME | rGUI::bf_MULTILINE)));
    //widgets.push_back(new rGUI::Button(865,140,30,40,"Reset colors","Calibri.ttf", &tmh));

    //Color selector
    int poz_colscba = widgets.size();
    widgets.push_back(new rGUI::ScrollableArea(400,5,275,180,2000,2000,&tmh,0,0));
        //red
        int poz_colsba_R =  widgets[poz_colscba]->widgets.size();
        widgets[poz_colscba]->widgets.push_back(new rGUI::SlideBar(5,5,30,140,0,255,&tmh, rGUI::bf_VERTICAL));
        //Green
        int poz_colsba_G =  widgets[poz_colscba]->widgets.size();
        widgets[poz_colscba]->widgets.push_back(new rGUI::SlideBar(40,5,30,140,0,255,&tmh, rGUI::bf_VERTICAL));
        //Blue
        int poz_colsba_B =  widgets[poz_colscba]->widgets.size();
        widgets[poz_colscba]->widgets.push_back(new rGUI::SlideBar(75,5,30,140,0,255,&tmh, rGUI::bf_VERTICAL));
        //Alpha
        int poz_colsba_A =  widgets[poz_colscba]->widgets.size();
        widgets[poz_colscba]->widgets.push_back(new rGUI::SlideBar(110,5,30,140,0,255,&tmh, rGUI::bf_VERTICAL));
        //cols
        int poz_colsba_cols =  widgets[poz_colscba]->widgets.size();
        widgets[poz_colscba]->widgets.push_back(new rGUI::TextBox(15,150,120,20, "R    G     B     A", "Calibri.ttf", 20, &tmh, rGUI::bf_HAS_FRAME));

        //TextC
        int poz_colsba_c_T =  widgets[poz_colscba]->widgets.size();
        widgets[poz_colscba]->widgets.push_back(new rGUI::Button(150,5,120,30, "Text color", "Calibri.ttf", &tmh));
        //BackgroundC
        int poz_colsba_c_B =  widgets[poz_colscba]->widgets.size();
        widgets[poz_colscba]->widgets.push_back(new rGUI::Button(150,40,120,30, "Background color", "Calibri.ttf", &tmh));
        //OutlineC
        int poz_colsba_c_O =  widgets[poz_colscba]->widgets.size();
        widgets[poz_colscba]->widgets.push_back(new rGUI::Button(150,75,120,30, "Outline color", "Calibri.ttf", &tmh));
        //ClickingC
        int poz_colsba_c_C =  widgets[poz_colscba]->widgets.size();
        widgets[poz_colscba]->widgets.push_back(new rGUI::Button(150,110,120,30, "Clicking color", "Calibri.ttf", &tmh));

    ((rGUI::ScrollableArea*)widgets[poz_colscba])->I_added_new_widgets();



    //Drag&drop
    int poz_dbm = widgets.size();
    widgets.push_back(new rGUI::DropBoxManager());
    rGUI::DropBox_Item dpi;
    dpi.load_bmp_fom_file = true;
    dpi.bmp_str = "button.png";
    dpi.print_x = 10;
    dpi.print_y = 10;
    dpi.print_w = 30;
    dpi.print_h = 30;
    widgets.push_back(new rGUI::DropBox(600,400,50,50,&tmh, (rGUI::DropBoxManager*)widgets[poz_dbm],&dpi));
    dpi.load_bmp_fom_file = false;
    dpi.bmp = al_load_bitmap("button.png");

    al_set_target_bitmap(dpi.bmp);
    al_draw_tinted_bitmap(dpi.bmp, al_map_rgba(255,0,0,100),0,0,0);

    std::vector<ALLEGRO_COLOR*> colvect;

    widgets[scbapoz]->widgets.push_back(new rGUI::DropBox(600,400,50,50,&tmh, (rGUI::DropBoxManager*)widgets[poz_dbm],&dpi));
    for(int a = 0;a < 5;a++)
    {
        for(int b = 0;b < 5;b++)
        {
            if(a == 0 && b == 0)
            {
                continue;
            }
            ALLEGRO_COLOR tmpc = al_map_rgba(rand()%256,rand()%256,rand()%256,255);
            colvect.push_back(new ALLEGRO_COLOR);
            colvect[colvect.size()-1]->r = tmpc.r;
            colvect[colvect.size()-1]->g = tmpc.g;
            colvect[colvect.size()-1]->b = tmpc.b;
            colvect[colvect.size()-1]->a = tmpc.a;
            al_clear_to_color(tmpc);
            dpi.data = colvect[colvect.size()-1];
            widgets.push_back(new rGUI::DropBox(600 + a*55,400 + b*55,50,50,&tmh, (rGUI::DropBoxManager*)widgets[poz_dbm], nullptr));
            widgets[scbapoz]->widgets.push_back(new rGUI::DropBox(600 + a*55,400 + b*55,50,50,&tmh, (rGUI::DropBoxManager*)widgets[poz_dbm], &dpi));
        }
    }
    al_set_target_backbuffer(display);
    int poz_backgroundDB = widgets.size();
    widgets.push_back(new rGUI::DropBox(710,345,50,50,&tmh, (rGUI::DropBoxManager*)widgets[poz_dbm], nullptr));
    int poz_scba_DP = widgets[scbapoz]->widgets.size();
    widgets[scbapoz]->widgets.push_back(new rGUI::DropBox(710,345,50,50,&tmh, (rGUI::DropBoxManager*)widgets[poz_dbm], nullptr));
    ((rGUI::ScrollableArea*)widgets[scbapoz])->I_added_new_widgets();

    //Group
    int poz_ext = widgets.size();
    widgets.push_back(new rGUI::Button(SCREEN_W - 50, SCREEN_H - 17,40,12,"Exit", "Calibri.ttf", &tmh));
    int poz_group = widgets.size();
    widgets.push_back(new rGUI::Group());
    ((rGUI::Group*)widgets[poz_group])->Add_Widgets(widgets, 0, widgets.size()-1);

    int poz_ext_scba = widgets.size();
    widgets.push_back(new rGUI::ScrollableArea( (SCREEN_W/2)-200, (SCREEN_H/2)-100, 400, 200,400,200,&tmh,14, 0));
    widgets[poz_ext_scba]->widgets.push_back(new rGUI::Button(10,150,100,45,"Yes", "Calibri.ttf", &tmh));
    widgets[poz_ext_scba]->widgets.push_back(new rGUI::Button(290,150,100,45,"No", "Calibri.ttf", &tmh));
    widgets[poz_ext_scba]->widgets.push_back(new rGUI::TextBox(0,0,400,120, "Do you rly wanna go ?", "Calibri.ttf",100, &tmh,
        (rGUI::bf_HORIZONTAL_CENTER | rGUI::bf_VERTICAL_CENTER | rGUI::bf_RESIZE_CONTENT) ));
    ((rGUI::ScrollableArea*)widgets[poz_ext_scba])->I_added_new_widgets();

    int poz_ext_group = widgets.size();
    widgets.push_back(new rGUI::Group());
    ((rGUI::Group*)widgets[poz_ext_group])->Add_Widgets(widgets, poz_ext_scba, widgets.size()-1);
    ((rGUI::Group*)widgets[poz_ext_group])->Set_all_Inputing(false);
    ((rGUI::Group*)widgets[poz_ext_group])->Set_all_Printing(false);

    ALLEGRO_TRANSFORM trans;
    al_identity_transform(&trans);
    al_scale_transform(&trans, _sx, _sy);
    al_translate_transform(&trans, _offx, _offy);
    //al_use_transform(&trans);
    int progresval = 0, progressadd = 1;
    ALLEGRO_COLOR backgroundcollor = al_map_rgb(255,255,255);

    float scale = 1.0f;
    while(1)
    {
        ALLEGRO_EVENT ev;
        al_wait_for_event(event_queue, &ev);

        rGUI::GetStatesAdnEvents(ev);

        if(ev.type == ALLEGRO_EVENT_TIMER)
        {
            progresval++;
            redraw = true;
            if(progresval >= 3)
            {
                progresval = 0;
                ((rGUI::ProgressBar*)widgets[progressbar])->Set_value(
                ((rGUI::ProgressBar*)widgets[progressbar])->Get_value() + progressadd);
            }

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

            bouncer_x = ev.mouse.x;
            bouncer_y = ev.mouse.y;
        }


        for(int a = 0;a < (int)widgets.size();a++)
        {
            widgets[a]->Input();
        }

        if(widgets[poz_ext]->wd_md->md_clicked == true)
        {
            widgets[poz_ext]->wd_md->md_clicked = false;
            ((rGUI::Group*)widgets[poz_group])->Set_all_Inputing(false);
            ((rGUI::Group*)widgets[poz_group])->Set_all_Printing(false);

            ((rGUI::Group*)widgets[poz_ext_group])->Set_all_Inputing(true);
            ((rGUI::Group*)widgets[poz_ext_group])->Set_all_Printing(true);
        }

        if(widgets[poz_ext_scba]->widgets[0]->wd_md->md_clicked == true)
        {
            break;
        }
        else if(widgets[poz_ext_scba]->widgets[1]->wd_md->md_clicked == true)
        {
            widgets[poz_ext_scba]->widgets[1]->wd_md->md_clicked = false;
            ((rGUI::Group*)widgets[poz_group])->Set_all_Inputing(true);
            ((rGUI::Group*)widgets[poz_group])->Set_all_Printing(true);

            ((rGUI::Group*)widgets[poz_ext_group])->Set_all_Inputing(false);
            ((rGUI::Group*)widgets[poz_ext_group])->Set_all_Printing(false);
        }

        if(widgets[poz_updatebutton]->wd_md->md_clicked == true || widgets[poz_rb]->wd_md->md_clicked == true)
        {
            widgets[poz_updatebutton]->wd_md->md_clicked = false;
            tmh.thickness = ((rGUI::SlideBar*)widgets[poz_thickness])->value;
            tmh.added_thickness = ((rGUI::SlideBar*)widgets[poz_addedthickness])->value;
            tmh.roundx = tmh.roundy = ((rGUI::SlideBar*)widgets[poz_roundXY])->value;

            if(widgets[poz_rb]->wd_md->md_clicked == true)
            {
                widgets[poz_rb]->wd_md->md_clicked = false;
                thmreset();
            }

            for(int a = 0;a < (int)widgets.size();a++)
            {
                widgets[a]->Update_theme(&tmh);
            }
            widgets[poz_colscba]->widgets[poz_colsba_cols]->wd_theme.c_background =
                al_premul_rgba(((rGUI::SlideBar*)widgets[poz_colscba]->widgets[poz_colsba_R])->Get_value(),
                            ((rGUI::SlideBar*)widgets[poz_colscba]->widgets[poz_colsba_G])->Get_value(),
                            ((rGUI::SlideBar*)widgets[poz_colscba]->widgets[poz_colsba_B])->Get_value(),
                            ((rGUI::SlideBar*)widgets[poz_colscba]->widgets[poz_colsba_A])->Get_value());
        }
        else if(widgets[poz_colscba]->widgets[poz_colsba_R]->wd_md->md_mouse_on_it == true ||
                widgets[poz_colscba]->widgets[poz_colsba_G]->wd_md->md_mouse_on_it == true ||
                widgets[poz_colscba]->widgets[poz_colsba_B]->wd_md->md_mouse_on_it == true ||
                widgets[poz_colscba]->widgets[poz_colsba_A]->wd_md->md_mouse_on_it == true)
        {
            widgets[poz_colscba]->widgets[poz_colsba_cols]->wd_theme.c_background =
                al_premul_rgba(((rGUI::SlideBar*)widgets[poz_colscba]->widgets[poz_colsba_R])->Get_value(),
                            ((rGUI::SlideBar*)widgets[poz_colscba]->widgets[poz_colsba_G])->Get_value(),
                            ((rGUI::SlideBar*)widgets[poz_colscba]->widgets[poz_colsba_B])->Get_value(),
                            ((rGUI::SlideBar*)widgets[poz_colscba]->widgets[poz_colsba_A])->Get_value());
        }
        else if(widgets[poz_colscba]->widgets[poz_colsba_c_T]->wd_md->md_clicked == true)
        {
            tmh.c_text = widgets[poz_colscba]->widgets[poz_colsba_cols]->wd_theme.c_background;
            widgets[poz_colscba]->widgets[poz_colsba_c_T]->wd_md->md_clicked = false;
        }
        else if(widgets[poz_colscba]->widgets[poz_colsba_c_O]->wd_md->md_clicked == true)
        {
            tmh.c_outline = widgets[poz_colscba]->widgets[poz_colsba_cols]->wd_theme.c_background;
            widgets[poz_colscba]->widgets[poz_colsba_c_O]->wd_md->md_clicked = false;
        }
        else if(widgets[poz_colscba]->widgets[poz_colsba_c_B]->wd_md->md_clicked == true)
        {
            tmh.c_background = widgets[poz_colscba]->widgets[poz_colsba_cols]->wd_theme.c_background;
            widgets[poz_colscba]->widgets[poz_colsba_c_B]->wd_md->md_clicked = false;
        }
        else if(widgets[poz_colscba]->widgets[poz_colsba_c_C]->wd_md->md_clicked == true)
        {
            tmh.c_clicking = widgets[poz_colscba]->widgets[poz_colsba_cols]->wd_theme.c_background;
            widgets[poz_colscba]->widgets[poz_colsba_c_C]->wd_md->md_clicked = false;
        }



        if(((rGUI::DropBox*)widgets[poz_backgroundDB])->changed)
        {
            if(((rGUI::DropBox*)widgets[poz_backgroundDB])->db_item != nullptr && ((rGUI::DropBox*)widgets[poz_backgroundDB])->db_item->data != nullptr)
            {
                ((rGUI::DropBox*)widgets[poz_backgroundDB])->changed = false;
                rGUI::DropBox *tmpdb = ((rGUI::DropBox*)widgets[poz_backgroundDB]);
                backgroundcollor.r = ((ALLEGRO_COLOR*)(tmpdb->db_item->data))->r;
                backgroundcollor.g = ((ALLEGRO_COLOR*)(tmpdb->db_item->data))->g;
                backgroundcollor.b = ((ALLEGRO_COLOR*)(tmpdb->db_item->data))->b;
                backgroundcollor.a = ((ALLEGRO_COLOR*)(tmpdb->db_item->data))->a;
            }
            else
            {
                backgroundcollor = al_map_rgb(255,255,255);
            }


        }
        if(((rGUI::DropBox*)(widgets[scbapoz]->widgets[poz_scba_DP]))->db_item != nullptr &&
           ((rGUI::DropBox*)(widgets[scbapoz]->widgets[poz_scba_DP]))->db_item->data != nullptr &&
           ((rGUI::DropBox*)(widgets[scbapoz]->widgets[poz_scba_DP]))->changed)
        {
            ((rGUI::DropBox*)(widgets[scbapoz]->widgets[poz_scba_DP]))->changed = false;
            rGUI::DropBox *tmpdb = ((rGUI::DropBox*)(widgets[scbapoz]->widgets[poz_scba_DP]));
            widgets[scbapoz]->wd_theme.c_background.r = ((ALLEGRO_COLOR*)(tmpdb->db_item->data))->r;
            widgets[scbapoz]->wd_theme.c_background.g = ((ALLEGRO_COLOR*)(tmpdb->db_item->data))->g;
            widgets[scbapoz]->wd_theme.c_background.b = ((ALLEGRO_COLOR*)(tmpdb->db_item->data))->b;
            widgets[scbapoz]->wd_theme.c_background.a = ((ALLEGRO_COLOR*)(tmpdb->db_item->data))->a;
        }

        if(redraw && al_is_event_queue_empty(event_queue))
        {
            redraw = false;

            al_clear_to_color(backgroundcollor);

            al_draw_bitmap(bouncer, bouncer_x, bouncer_y, 0);

            for(int a = 0;a < (int)widgets.size();a++)
            {
                widgets[a]->Print();
            }
            widgets[poz_dbm]->Print();

            al_flip_display();
        }
    }


    for(int a = 0;a < (int)widgets.size();a++)
    {
        delete widgets[a];
    }
    widgets.clear();
    for(int a = 0;a < (int)colvect.size();a++)
    {
        delete colvect[a];
    }
    colvect.clear();

    rGUI::End();

    al_destroy_bitmap(bouncer);
    al_destroy_timer(timer);
    al_destroy_display(display);
    al_destroy_event_queue(event_queue);
    al_destroy_font(fnt);
    al_destroy_font(font);

    return 0;
}
コード例 #16
0
ファイル: ex_audio_timer.c プロジェクト: gitustc/d2imdev
int main(void)
{
   ALLEGRO_TRANSFORM trans;
   ALLEGRO_EVENT event;
   int bps = 4;
   bool redraw = false;
   unsigned int last_timer = 0;

   if (!al_init()) {
      abort_example("Could not init Allegro.\n");
   }

   open_log();

   al_install_keyboard();

   display = al_create_display(640, 480);
   if (!display) {
      abort_example("Could not create display\n");
   }

   font = al_create_builtin_font();
   if (!font) {
      abort_example("Could not create font\n");
   }

   if (!al_install_audio()) {
      abort_example("Could not init sound\n");
   }

   if (!al_reserve_samples(RESERVED_SAMPLES)) {
      abort_example("Could not set up voice and mixer\n");
   }

   ping = generate_ping();
   if (!ping) {
      abort_example("Could not generate sample\n");
   }

   timer = al_create_timer(1.0 / bps);
   al_set_timer_count(timer, -1);

   event_queue = al_create_event_queue();
   al_register_event_source(event_queue, al_get_keyboard_event_source());
   al_register_event_source(event_queue, al_get_timer_event_source(timer));

   al_identity_transform(&trans);
   al_scale_transform(&trans, 16.0, 16.0);
   al_use_transform(&trans);

   al_start_timer(timer);

   while (true) {
      al_wait_for_event(event_queue, &event);
      if (event.type == ALLEGRO_EVENT_TIMER) {
         const float speed = pow(21.0/20.0, (event.timer.count % PERIOD));
         if (!al_play_sample(ping, 1.0, 0.0, speed, ALLEGRO_PLAYMODE_ONCE, NULL)) {
            log_printf("Not enough reserved samples.\n");
         }
         redraw = true;
         last_timer = event.timer.count;
      }
      else if (event.type == ALLEGRO_EVENT_KEY_CHAR) {
         if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) {
            break;
         }
         if (event.keyboard.unichar == '+' || event.keyboard.unichar == '=') {
            if (bps < 32) {
               bps++;
               al_set_timer_speed(timer, 1.0 / bps);
            }
         }
         else if (event.keyboard.unichar == '-') {
            if (bps > 1) {
               bps--;
               al_set_timer_speed(timer, 1.0 / bps);
            }
         }
      }

      if (redraw && al_is_event_queue_empty(event_queue)) {
         ALLEGRO_COLOR c;
         if (last_timer % PERIOD == 0)
            c = al_map_rgb_f(1, 1, 1);
         else
            c = al_map_rgb_f(0.5, 0.5, 1.0);

         al_clear_to_color(al_map_rgb(0, 0, 0));
         al_draw_textf(font, c, 640/32, 480/32 - 4, ALLEGRO_ALIGN_CENTRE,
            "%u", last_timer);
         al_flip_display();
      }
   }

   close_log(false);

   return 0;
}
コード例 #17
0
ファイル: main.cpp プロジェクト: kruci/Juicy-Plebs
int main(int argc, char *argv[])
{
    bool windowed = false;
    float rescale = 1.0f;
    std::string arg;
    if(argc > 1)
    {
        arg = argv[1];
        if(arg == "--help")
        {
            std::cout << "-s {scale} for running in windowed mode and scaled (standart size is 1440*810)" << std::endl;
            return 0;
        }
        else if(arg == "-s")
        {
            if( argc > 2)
            {
                arg = argv[2];
                rescale = atof(argv[2]);
            }
            windowed = true;
        }
    }


    /**initialize allegro*/
    if(!al_init()){error_message("al_init()");return 33;}
    if(!al_init_primitives_addon()){error_message("al_init_primitives_addon()");return 33;}
    //if(!al_install_keyboard()){error_message("al_install_keyboard()");return 33;} //no use for keyboard in this game
    if(!al_install_mouse()){error_message("al_install_mouse()");return 33;}
    if(!al_init_image_addon()){error_message("al_init_image_addon()");return 33;}
    al_init_font_addon(); // returns void
    if(!al_init_ttf_addon()){error_message("al_init_ttf_addon()");return 33;}
    //audio
    if(al_install_audio() == true)
    {
        if(al_init_acodec_addon() == true){}
        else
        {
            error_message("al_init_acodec_addon() - cant initialize audio codec");
            global::audio = false;
            global::sound_card = false;
        }
    }
    else
    {
        error_message("al_install_audio() - cant found sound device");
        global::audio = false;
        global::sound_card = false;
    }

    /**Some allegro variables*/
    ALLEGRO_DISPLAY *display = nullptr;
    ALLEGRO_EVENT_QUEUE *event_queue = nullptr;
    ALLEGRO_TIMER *timer = nullptr;
    ALLEGRO_BITMAP *logo = nullptr;

    /**Display preparation*/
    bool supported_ratio = true;
    ALLEGRO_MONITOR_INFO mon_info;
    al_get_monitor_info(0, &mon_info);
    global::sHeight = mon_info.y2 - mon_info.y1; //gets monitor size in pixels
    global::sWidth = mon_info.x2 - mon_info.x1;
    global::aspectratio = round( ((float)global::sWidth / (float)global::sHeight) * 100.0f) / 100.0f; //gets aspectratio
    if(global::aspectratio == 1.78f){global::xratio = 16; global::yratio = 9;}      // 16:9 screen ration
    else if(global::aspectratio == 1.6f){global::xratio = 16; global::yratio = 10;} // 16:10
    else if(global::aspectratio == 1.33f){global::xratio = 4; global::yratio = 3;}  // 4:3
    else{supported_ratio = false;}
    global::dHeight = global::dWidth  / global::xratio * global::yratio;
    global::xscale = (float)global::sWidth / (float)global::dWidth;
    global::yscale = (float)global::sHeight / (float)global::dHeight;

    /**display creation*/
    al_set_new_bitmap_flags(ALLEGRO_MAG_LINEAR | ALLEGRO_MIN_LINEAR); // Thanks to this, magnified fonts dont look retarted, and game is fast (hopefully) :D
    if(windowed == true || supported_ratio == false)
    {
        supported_ratio = true;
        al_set_new_display_flags(ALLEGRO_WINDOWED | ALLEGRO_OPENGL);
        global::xscale = rescale;
        global::yscale = rescale;
        global::dWidth = 1440;
        global::dHeight = 810;
        display = al_create_display(global::dWidth*rescale, global::dHeight*rescale);
    }
    else
    {
        al_set_new_display_flags(ALLEGRO_FULLSCREEN_WINDOW | ALLEGRO_OPENGL);
        display = al_create_display(global::dWidth, global::dHeight);
    }
    if(display == nullptr){error_message("al_create_display()"); return 1;}
    al_set_window_title(display, "Este neviem meno, ale asi neco so zemiakom");

    /**logo*/
    logo = al_load_bitmap("resources/graphics/logo.png");
    if(logo == nullptr){error_message("resources/graphics/logo.png not found");}
    else{ al_set_display_icon(display, logo);}


    /**Transformation*/
    al_identity_transform(&global::trans);
    if(supported_ratio == true)
    {
        al_scale_transform(&global::trans, global::xscale, global::yscale);
    }
    else
    {
        error_message("Unsupported monitor type - upgrade you monitor pls");
        float scale_backup_plan = (global::xscale > global::yscale ? global::yscale : global::xscale);
        global::xscale = scale_backup_plan;
        global::yscale = scale_backup_plan;
        al_scale_transform(&global::trans, global::xscale, global::yscale);
    }
    al_use_transform(&global::trans);

    /**timer*/
    timer = al_create_timer(1.0f/global::FPS);
    if(timer == nullptr){error_message("al_create_timer()"); return 44;}
    bool redraw = true;

    /**even que*/
    event_queue = al_create_event_queue();
    if(event_queue == nullptr){error_message("al_create_event_queue()"); return 44;}

    /**registering event sources*/
    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_mouse_event_source());

    al_start_timer(timer);

    rguil::mouse_state = &global::mouse_state;

    global::audio_player = new AudioHandler(10);

    #ifdef _SOUND_TEST
    ALLEGRO_SAMPLE *s = al_load_sample("resources/music/Fuck_This_Shit_Im_Out.wav");
    ALLEGRO_SAMPLE_INSTANCE *si = al_create_sample_instance(s);
    global::audio_player->global_sounds.push_back(si);
    global::audio_player->Play_sample_instance(&si, ALLEGRO_PLAYMODE_LOOP);
    #endif // _SOUND_TEST

    #ifdef _FPS
    ALLEGRO_FONT *fps_font = nullptr;
    fps_font = al_load_font("resources/fonts/Asimov.otf", 12,0);
    int counter = 0;
    time_t tsttme2 = time(nullptr), tsttme = time(nullptr);
    int fps = 0;
    #endif // FPS

    global::save = new GameSave();
    ScreenMain *SCMain = new ScreenMain();
    global::audio_b = new Button("resources/fonts/Calibri.ttf", 1240, global::dHeight -65, 1240 + 40, global::dHeight - 25,
                                 "", al_map_rgba(0,0,0,0),
                                 ( global::audio == true ? MusicON : MusicOFF));

    /**Main loop*/ //forced 30 FPS, drawing and computing in same thread
    while(global::loop == true)
    {
        ALLEGRO_EVENT ev;
        al_wait_for_event(event_queue, &ev);

        al_get_mouse_state(&global::mouse_state);

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

        /**Take event input here*/
        if(global::audio_b->Input(ev, global::xscale, global::yscale) == 2)
        {
            global::audio_b->unclick();
            global::audio = (global::audio == true ? false : true);

            if(global::audio == true)
            {
                al_destroy_bitmap(global::audio_b->bmp);
                global::audio_b->bmp = al_load_bitmap(MusicON);
                global::audio_player->Mute_sample_instances(false);
            }
            else
            {
                al_destroy_bitmap(global::audio_b->bmp);
                global::audio_b->bmp = al_load_bitmap(MusicOFF);
                global::audio_player->Mute_sample_instances(true);
            }
        }

        SCMain->Input(ev, global::xscale, global::yscale);
        /**---------------------*/

        #ifdef _FPS
        tsttme2 = time(&tsttme2);
        if(difftime(tsttme2,tsttme) >= 1.0f)
        {
            tsttme = time(&tsttme);
            fps = counter;
            counter = 0;
        }
        #endif // FPS


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


            /**Draw and compute here*/
            SCMain->Print();
            global::audio_b->Print();
            /**---------------------*/

            #ifdef _FPS
            counter++;
            al_draw_text(fps_font, al_map_rgb(255,0,0), 0.0f,0.0f, 0, std::to_string(fps).c_str());
            #endif // FPS
            al_flip_display();
        }
    }
    #ifdef _SOUND_TEST
    global::audio_player->Stop_sample_instances();
    global::audio_player->global_sounds.erase(global::audio_player->global_sounds.begin());
    al_destroy_sample_instance(si);
    al_destroy_sample(s);
    #endif // _SOUND_TEST

    delete global::audio_b;
    delete SCMain;
    delete global::save;
    delete global::audio_player;

    al_destroy_timer(timer);
    al_destroy_display(display);
    al_destroy_event_queue(event_queue);
    if(logo != nullptr)
        al_destroy_bitmap(logo);
    #ifdef _FPS
    al_destroy_font(fps_font);
    #endif // FPS

    return 0;
}
コード例 #18
0
ファイル: menu.cpp プロジェクト: ADSgames/RobotFlier
// Update loop
void menu::update(){
  //Menu animations
  if( animation_pos < 100 && !startClicked)
    animation_pos += 4;
  if( animation_pos > 0 && startClicked)
    animation_pos -= 4;

  // Start the game
  if( startClicked && animation_pos <= 0)
    set_next_state( STATE_GAME);

  // Open submenu or start game
  if( mini_screen == MINISTATE_MENU){
    // Start game with controller
    if( joystickListener::buttonPressed[JOY_XBOX_START] || joystickListener::buttonPressed[JOY_XBOX_A]){
      startClicked = true;
    }
    // Buttons
    if( mouseListener::mouse_pressed & 1){
      // Start game
      if( collision( mouseListener::mouse_x, mouseListener::mouse_x, 40, 40 + al_get_bitmap_width(start), mouseListener::mouse_y, mouseListener::mouse_y, 410, 410 + al_get_bitmap_height(start))){
        startClicked = true;
      }
      // Scores
      else if( collision( mouseListener::mouse_x, mouseListener::mouse_x, 660, 660 + al_get_bitmap_width(highscores_button), mouseListener::mouse_y, mouseListener::mouse_y, 30, 30 + al_get_bitmap_height(highscores_button))){
        updateScores( scores);
        mini_screen = MINISTATE_SCORES;
      }
      // Credits menu
      else if( collision( mouseListener::mouse_x, mouseListener::mouse_x, 542, 644, mouseListener::mouse_y, mouseListener::mouse_y, 548, 600)){
        mini_screen = MINISTATE_CREDITS;
      }
      // Controls menu
      else if( collision( mouseListener::mouse_x, mouseListener::mouse_x, 644, 696, mouseListener::mouse_y, mouseListener::mouse_y, 548 ,600)){
        mini_screen = MINISTATE_CONTROLS;
      }
      // Help screen
      else if( collision( mouseListener::mouse_x, mouseListener::mouse_x, 696, 749, mouseListener::mouse_y, mouseListener::mouse_y, 548, 600)){
        mini_screen = MINISTATE_TUTORIAL;
      }
      // Options menu
      else if( collision( mouseListener::mouse_x, mouseListener::mouse_x, 749, 800, mouseListener::mouse_y, mouseListener::mouse_y, 548, 600)){
        mini_screen = MINISTATE_OPTIONS;
      }
    }
  }
  // Exit menus
  else if( mini_screen == MINISTATE_TUTORIAL || mini_screen == MINISTATE_CREDITS || mini_screen == MINISTATE_CONTROLS || mini_screen == MINISTATE_SCORES ){
    if( keyListener::lastKeyPressed != -1  || mouseListener::mouse_pressed & 1 || joystickListener::lastButtonPressed != -1){
			mini_screen = MINISTATE_MENU;
			draw();
    }
  }
  // Options
  else if( mini_screen == MINISTATE_OPTIONS && mouseListener::mouse_pressed & 1){
    // Particles toggle
    if( collision( 280, 360, mouseListener::mouse_x, mouseListener::mouse_x, 400, 480, mouseListener::mouse_y, mouseListener::mouse_y)){
      settings[SETTING_PARTICLE_TYPE] = (settings[SETTING_PARTICLE_TYPE] + 1) % 4;
    }
    // Sound button toggle
    else if( collision( 120, 200, mouseListener::mouse_x, mouseListener::mouse_x, 180, 260, mouseListener::mouse_y, mouseListener::mouse_y)){
      settings[SETTING_SOUND] = (settings[SETTING_SOUND] + 1) % 2;
    }
    // Music button toggle
    else if( collision( 280, 360, mouseListener::mouse_x, mouseListener::mouse_x, 180, 260, mouseListener::mouse_y, mouseListener::mouse_y)){
      settings[SETTING_MUSIC] = (settings[SETTING_MUSIC] + 1) % 2;
      if( settings[SETTING_MUSIC] == 0)
        al_stop_sample( &currentMusic);
      else
        al_play_sample( music_mainmenu, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, &currentMusic);

    }
    // Fullscreen toggle
    else if( collision( 120, 200, mouseListener::mouse_x, mouseListener::mouse_x, 400, 480, mouseListener::mouse_y, mouseListener::mouse_y)){
      settings[SETTING_FULLSCREEN] = (settings[SETTING_FULLSCREEN] + 1) % 2;

      if( settings[SETTING_FULLSCREEN]){
        // Fullscreen stuff
        al_destroy_display( display);
        al_set_new_display_flags(ALLEGRO_FULLSCREEN_WINDOW);
        display = al_create_display( SCREEN_W, SCREEN_H);

        ALLEGRO_DISPLAY_MODE disp_data;
        al_get_display_mode(al_get_num_display_modes() - 1, &disp_data);
        float sx = disp_data.width / (float)SCREEN_W;
        float sy = disp_data.height / (float)SCREEN_H;

        ALLEGRO_TRANSFORM trans;
        al_identity_transform(&trans);
        al_scale_transform(&trans, sx, sy);
        al_use_transform(&trans);
        al_hide_mouse_cursor( display);
      }
      else{
        al_destroy_display( display);
        al_set_new_display_flags(ALLEGRO_WINDOWED);
        display = al_create_display( SCREEN_W, SCREEN_H);
        al_hide_mouse_cursor( display);
      }
    }
    //Screen shake
    else if( collision( 280, 360, mouseListener::mouse_x, mouseListener::mouse_x, 290, 370, mouseListener::mouse_y, mouseListener::mouse_y)){
      settings[SETTING_SCREENSHAKE] = (settings[SETTING_SCREENSHAKE] + 1) % 4;
    }
    // Control Toggle
    else if( collision( 120, 200, mouseListener::mouse_x, mouseListener::mouse_x, 290, 370, mouseListener::mouse_y, mouseListener::mouse_y)){
      settings[SETTING_CONTROLMODE] = ((settings[SETTING_CONTROLMODE] + 1) % 3);
    }
    // Power off
    else if( collision( 540, 620, mouseListener::mouse_x, mouseListener::mouse_x, 180, 260, mouseListener::mouse_y, mouseListener::mouse_y)){
      write_settings();
      set_next_state( STATE_EXIT);
    }
    // Exit menu
    else if( collision( 540, 620, mouseListener::mouse_x, mouseListener::mouse_x, 407, 487, mouseListener::mouse_y, mouseListener::mouse_y)){
      mini_screen = MINISTATE_MENU;
      write_settings();
    }
  }

  // Update mouse particles
  if( settings[SETTING_PARTICLE_TYPE] != 3 && mouse_rocket_up){
    for( int i = 0; i < 500; i++){
      if( random( 1, 10) == 1){
        ALLEGRO_COLOR part_color = al_map_rgb( 255, random(0,255), 0);
        if( settings[SETTING_CHRISTMAS]){
          int red_or_green = random( 0, 1) * 255;
          part_color = al_map_rgb( red_or_green, 255 - red_or_green, 0);
        }
        particle newParticle( mouseListener::mouse_x, mouseListener::mouse_y + 16, part_color, random( -2, 2), random( 8, 20), 1, settings[SETTING_PARTICLE_TYPE]);
        mousePart.push_back( newParticle);
      }
    }
  }
  for( unsigned int i = 0; i < mousePart.size(); i++){
    mousePart.at(i).logic();
    if( random( 0, 10) == 0)
      mousePart.erase( mousePart.begin() + i);
  }

  // Close game
  if( keyListener::key[ALLEGRO_KEY_ESCAPE])
    set_next_state( STATE_EXIT);

  // Check if mouse is going up
  mouse_rocket_up = ( mouseListener::mouse_y < mouseMove);
  mouseMove = mouseListener::mouse_y;
}