Пример #1
0
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);
}
Пример #2
0
void gdp_update_camera(Char *tchar, float theight, float twidth, float tscale)
{
    ALLEGRO_TRANSFORM camera;
    al_identity_transform(&camera);

    float charX,charY, scaledCharX, scaledCharY,
        charW, charH;

    charW = (float)tchar->obj.wd;
    charH = (float)tchar->obj.hd;

    charX=(float)tchar->obj.x;
    charY=(float)tchar->obj.y;

    scaledCharX= -((charX*tscale )-(ambient->wd/2.0) + (charW/2) );
    scaledCharY= -((charY*tscale )-(ambient->hd/2.0) + (charH/2));

    if (scaledCharX > 0)
        scaledCharX = 0;

    if (scaledCharY > ambient->info->h)
        scaledCharY = ambient->info->h;

    if (scaledCharY <= -( (tscale-1)*(ambient->hd) ) )
        scaledCharY = -( (tscale-1)*(ambient->hd) ) ;

    if (scaledCharX <= -( (tscale-1)*(ambient->wd) ) )
        scaledCharX = -( (tscale-1)*(ambient->wd) ) ;

     al_build_transform(&camera, scaledCharX, scaledCharY, tscale,tscale,0);
     al_use_transform(&camera);
}
Пример #3
0
static void IndexedFilledPrimitives(int mode)
{
   static ALLEGRO_VERTEX vtx[21];
   static int indices1[] = {12, 13, 14, 16, 17, 18};
   static int indices2[] = {6, 7, 8, 9, 10, 11};
   static int indices3[] = {0, 1, 2, 3, 4, 5};
   if (mode == INIT) {
      int ii = 0;
      for (ii = 0; ii < 21; ii++) {
         float x, y;
         ALLEGRO_COLOR color;
         if (ii % 2 == 0) {
            x = 150 * cosf((float)ii / 20 * 2 * ALLEGRO_PI);
            y = 150 * sinf((float)ii / 20 * 2 * ALLEGRO_PI);
         } else {
            x = 200 * cosf((float)ii / 20 * 2 * ALLEGRO_PI);
            y = 200 * sinf((float)ii / 20 * 2 * ALLEGRO_PI);
         }
         
         if (ii == 0) {
            x = y = 0;
         }
         
         color = al_map_rgb((7 * ii + 1) % 3 * 64, (2 * ii + 2) % 3 * 64, (ii) % 3 * 64);
         
         vtx[ii].x = x; vtx[ii].y = y; vtx[ii].z = 0;
         vtx[ii].color = color;
      }
   } else if (mode == LOGIC) {
      int ii;
      Theta += Speed;
      for (ii = 0; ii < 6; ii++) {
         indices1[ii] = ((int)al_get_time() + ii) % 20 + 1;
         indices2[ii] = ((int)al_get_time() + ii + 6) % 20 + 1;
         if (ii > 0)
            indices3[ii] = ((int)al_get_time() + ii + 12) % 20 + 1;
      }
      
      al_build_transform(&MainTrans, ScreenW / 2, ScreenH / 2, 1, 1, Theta);
   } else if (mode == DRAW) {
      if (Blend)
         al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ONE);
      else
         al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO);
      
      al_use_transform(&MainTrans);
      
      al_draw_indexed_prim(vtx, 0, 0, indices1, 6, ALLEGRO_PRIM_TRIANGLE_LIST);
      al_draw_indexed_prim(vtx, 0, 0, indices2, 6, ALLEGRO_PRIM_TRIANGLE_STRIP);
      al_draw_indexed_prim(vtx, 0, 0, indices3, 6, ALLEGRO_PRIM_TRIANGLE_FAN);
      
      al_use_transform(&Identity);
   }
}
Пример #4
0
VALUE rbal_build_transform(VALUE r_, VALUE rtrans, VALUE rx, 
			   VALUE ry, VALUE rsx, VALUE rsy, VALUE rtheta) {
  ALLEGRO_TRANSFORM * trans = rbal_transform_unwrap(rtrans);
  float 	          x = RBH_FLOAT(rx);
  float 	          y = RBH_FLOAT(ry);
  float 	         sx = RBH_FLOAT(rsx);
  float 	         sy = RBH_FLOAT(rsy);
  float 	      theta = RBH_FLOAT(rtheta);  
  al_build_transform(trans, rx, ry, rsx, rsy, rtheta);
  return rtrans;
}
Пример #5
0
/** Applies a scale, rotate and translate transformation to all future drawing operations. */
void cbeTransformBuild(CBEnchanted *cb) {
	float angle = (cb->popValue().toFloat() / 180.0f) * M_PI;
	float scaleY = cb->popValue().toFloat();
	float scaleX = cb->popValue().toFloat();
	float transY = cb->popValue().toFloat();
	float transX = cb->popValue().toFloat();

	ALLEGRO_TRANSFORM t;
	al_identity_transform(&t);
	al_build_transform(&t, transX, transY, scaleX, scaleY, angle);
	al_use_transform(&t);
	cb->pushValue(0);
}
Пример #6
0
static void IndexedPrimitives(int mode)
{
   static int indices1[] = {0, 1, 3, 4};
   static int indices2[] = {5, 6, 7, 8};
   static int indices3[] = {9, 10, 11, 12};
   static ALLEGRO_VERTEX vtx[13];
   static ALLEGRO_VERTEX vtx2[13];
   if (mode == INIT) {
      int ii = 0;
      ALLEGRO_COLOR color;
      for (ii = 0; ii < 13; ii++) {
         float x, y;
         x = 200 * cosf((float)ii / 13.0f * 2 * ALLEGRO_PI);
         y = 200 * sinf((float)ii / 13.0f * 2 * ALLEGRO_PI);
         
         color = al_map_rgb((ii + 1) % 3 * 64, (ii + 2) % 3 * 64, (ii) % 3 * 64);
         
         vtx[ii].x = x; vtx[ii].y = y; vtx[ii].z = 0;
         vtx2[ii].x = 0.1 * x; vtx2[ii].y = 0.1 * y;
         vtx[ii].color = color;
         vtx2[ii].color = color;
      }
   } else if (mode == LOGIC) {
      int ii;
      Theta += Speed;
      for (ii = 0; ii < 4; ii++) {
         indices1[ii] = ((int)al_get_time() + ii) % 13;
         indices2[ii] = ((int)al_get_time() + ii + 4) % 13;
         indices3[ii] = ((int)al_get_time() + ii + 8) % 13;
      }
      
      al_build_transform(&MainTrans, ScreenW / 2, ScreenH / 2, 1, 1, Theta);
   } else if (mode == DRAW) {
      if (Blend)
         al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ONE);
      else
         al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO);
      
      al_use_transform(&MainTrans);
      
      al_draw_indexed_prim(vtx, 0, 0, indices1, 4, ALLEGRO_PRIM_LINE_LIST);
      al_draw_indexed_prim(vtx, 0, 0, indices2, 4, ALLEGRO_PRIM_LINE_STRIP);
      al_draw_indexed_prim(vtx, 0, 0, indices3, 4, ALLEGRO_PRIM_LINE_LOOP);
      al_draw_indexed_prim(vtx2, 0, 0, indices3, 4, ALLEGRO_PRIM_POINT_LIST);
      
      al_use_transform(&Identity);
   }
}
Пример #7
0
static void FilledTexturePrimitives(int mode)
{
   static ALLEGRO_VERTEX vtx[21];
   if (mode == INIT) {
      int ii = 0;
      for (ii = 0; ii < 21; ii++) {
         float x, y;
         ALLEGRO_COLOR color;
         if (ii % 2 == 0) {
            x = 150 * cosf((float)ii / 20 * 2 * ALLEGRO_PI);
            y = 150 * sinf((float)ii / 20 * 2 * ALLEGRO_PI);
         } else {
            x = 200 * cosf((float)ii / 20 * 2 * ALLEGRO_PI);
            y = 200 * sinf((float)ii / 20 * 2 * ALLEGRO_PI);
         }
         
         if (ii == 0) {
            x = y = 0;
         }
         
         color = al_map_rgb((7 * ii + 1) % 3 * 64, (2 * ii + 2) % 3 * 64, (ii) % 3 * 64);
         
         vtx[ii].x = x; vtx[ii].y = y; vtx[ii].z = 0;
         vtx[ii].u = 64 * x / 100; vtx[ii].v = 64 * y / 100;
         if(ii < 10)
            vtx[ii].color = al_map_rgba_f(1, 1, 1, 1);
         else
            vtx[ii].color = color;
      }
   } else if (mode == LOGIC) {
      Theta += Speed;
      al_build_transform(&MainTrans, ScreenW / 2, ScreenH / 2, 1, 1, Theta);
   } else if (mode == DRAW) {
      if (Blend)
         al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ONE);
      else
         al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO);
  
      al_use_transform(&MainTrans);
      
      al_draw_prim(vtx, 0, Texture, 0, 6, ALLEGRO_PRIM_TRIANGLE_FAN);
      al_draw_prim(vtx, 0, Texture, 7, 13, ALLEGRO_PRIM_TRIANGLE_LIST);
      al_draw_prim(vtx, 0, Texture, 14, 20, ALLEGRO_PRIM_TRIANGLE_STRIP);
      
      al_use_transform(&Identity);
   }
}
Пример #8
0
static void TexturePrimitives(int mode)
{
   static ALLEGRO_VERTEX vtx[13];
   static ALLEGRO_VERTEX vtx2[13];
   if (mode == INIT) {
      int ii = 0;
      ALLEGRO_COLOR color;
      for (ii = 0; ii < 13; ii++) {
         float x, y;
         x = 200 * cosf((float)ii / 13.0f * 2 * ALLEGRO_PI);
         y = 200 * sinf((float)ii / 13.0f * 2 * ALLEGRO_PI);
         
         color = al_map_rgb((ii + 1) % 3 * 64, (ii + 2) % 3 * 64, (ii) % 3 * 64);
         
         vtx[ii].x = x; vtx[ii].y = y; vtx[ii].z = 0;
         vtx2[ii].x = 0.1 * x; vtx2[ii].y = 0.1 * y;
         vtx[ii].u = 64 * x / 100; vtx[ii].v = 64 * y / 100;
         vtx2[ii].u = 64 * x / 100; vtx2[ii].v = 64 * y / 100;
         if(ii < 10)
            vtx[ii].color = al_map_rgba_f(1, 1, 1, 1);
         else
            vtx[ii].color = color;
         vtx2[ii].color = vtx[ii].color;
      }
   } else if (mode == LOGIC) {
      Theta += Speed;
      al_build_transform(&MainTrans, ScreenW / 2, ScreenH / 2, 1, 1, Theta);
   } else if (mode == DRAW) {
      if (Blend)
         al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ONE);
      else
         al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO);
      
      al_use_transform(&MainTrans);
      
      al_draw_prim(vtx, 0, Texture, 0, 4, ALLEGRO_PRIM_LINE_LIST);
      al_draw_prim(vtx, 0, Texture, 4, 9, ALLEGRO_PRIM_LINE_STRIP);
      al_draw_prim(vtx, 0, Texture, 9, 13, ALLEGRO_PRIM_LINE_LOOP);
      al_draw_prim(vtx2, 0, Texture, 0, 13, ALLEGRO_PRIM_POINT_LIST);
      
      al_use_transform(&Identity);
   }
}
Пример #9
0
// Updates the aspect ratio when going full-screen or windowed
static void
aspect_ratio_transform(void)
{
  int window_w = al_get_display_width(engine.display);
  int window_h = al_get_display_height(engine.display);

  float sw = (window_w / (float) GAME_W);
  float sh = (window_h / (float) GAME_H);
  float scale = (sw < sh ? sw : sh);

  float scale_w = ((float) GAME_W * scale);
  float scale_h = ((float) GAME_H * scale);
  int scale_x_pos = (window_w - scale_w) / 2;
  int scale_y_pos = (window_h - scale_h) / 2;

  ALLEGRO_TRANSFORM trans;
  al_identity_transform(&trans);
  al_build_transform(&trans, scale_x_pos, scale_y_pos, scale, scale, 0);
  al_use_transform(&trans);
}
Пример #10
0
static void draw_square(Square *sq)
{
   ALLEGRO_TRANSFORM trans;
   float alpha;
   float size;
   ALLEGRO_COLOR tint;

   al_build_transform(&trans, sq->cx, sq->cy, 1.0, 1.0, sq->rot);
   al_use_transform(&trans);

   alpha = sin(sq->life);
   al_set_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_ONE);
   tint = al_map_rgba_f(0.5, 0.3, 0, alpha);

   size = sq->size;
   al_draw_filled_rounded_rectangle(-size, -size, size, size, 3, 3, tint);

   size *= 1.1;
   al_draw_rounded_rectangle(-size, -size, size, size, 3, 3, tint, 2);
}
Пример #11
0
static void CustomVertexFormatPrimitives(int mode)
{
   static CUSTOM_VERTEX vtx[4];
   static ALLEGRO_VERTEX_DECL* decl;
   if (mode == INIT) {
      int ii = 0;
      ALLEGRO_VERTEX_ELEMENT elems[] = {
         {ALLEGRO_PRIM_POSITION, ALLEGRO_PRIM_SHORT_2, offsetof(CUSTOM_VERTEX, x)},
         {ALLEGRO_PRIM_TEX_COORD_PIXEL, ALLEGRO_PRIM_SHORT_2, offsetof(CUSTOM_VERTEX, u)},
         {ALLEGRO_PRIM_COLOR_ATTR, 0, offsetof(CUSTOM_VERTEX, color)},
         {0, 0, 0}
      };
      decl = al_create_vertex_decl(elems, sizeof(CUSTOM_VERTEX));

      for (ii = 0; ii < 4; ii++) {
         float x, y;
         x = 200 * cosf((float)ii / 4.0f * 2 * ALLEGRO_PI);
         y = 200 * sinf((float)ii / 4.0f * 2 * ALLEGRO_PI);
         
         vtx[ii].x = x; vtx[ii].y = y;
         vtx[ii].u = 64 * x / 100; vtx[ii].v = 64 * y / 100;
         vtx[ii].color = al_map_rgba_f(1, 1, 1, 1);
      }
   } else if (mode == LOGIC) {
      Theta += Speed;
      al_build_transform(&MainTrans, ScreenW / 2, ScreenH / 2, 1, 1, Theta);
   } else if (mode == DRAW) {
      if (Blend)
         al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ONE);
      else
         al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO);
      
      al_use_transform(&MainTrans);
      
      al_draw_prim(vtx, decl, Texture, 0, 4, ALLEGRO_PRIM_TRIANGLE_FAN);
      
      al_use_transform(&Identity);
   }
}
Пример #12
0
static void TransformationsPrimitives(int mode)
{
   float t = al_get_time();
   if (mode == INIT) {
   
   } else if (mode == LOGIC) {
      Theta += Speed;
      al_build_transform(&MainTrans, ScreenW / 2, ScreenH / 2, sinf(t / 5), cosf(t / 5), Theta);
   } else if (mode == DRAW) {
      float points[8] = {
         -300, -200,
         700, 200,
         -700, 200,
         300, -200
      };
      
      if (Blend)
         al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ONE);
      else
         al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO);
      
      al_use_transform(&MainTrans);
      
      al_draw_line(-300, -200, 300, 200, al_map_rgba_f(0, 0.5, 0.5, 1), Thickness);
      al_draw_triangle(-150, -250, 0, 250, 150, -250, al_map_rgba_f(0.5, 0, 0.5, 1), Thickness);
      al_draw_rectangle(-300, -200, 300, 200, al_map_rgba_f(0.5, 0, 0, 1), Thickness);
      al_draw_rounded_rectangle(-200, -125, 200, 125, 50, 100, al_map_rgba_f(0.2, 0.2, 0, 1), Thickness);
      
      al_draw_ellipse(0, 0, 300, 150, al_map_rgba_f(0, 0.5, 0.5, 1), Thickness);
      al_draw_elliptical_arc(-20, 0, 300, 200, -ALLEGRO_PI / 2, -ALLEGRO_PI, al_map_rgba_f(0.25, 0.25, 0.5, 1), Thickness);
      al_draw_arc(0, 0, 200, -ALLEGRO_PI / 2, ALLEGRO_PI, al_map_rgba_f(0.5, 0.25, 0, 1), Thickness);
      al_draw_spline(points, al_map_rgba_f(0.1, 0.2, 0.5, 1), Thickness);
      al_draw_pieslice(0, 25, 150, ALLEGRO_PI * 3 / 4, -ALLEGRO_PI / 2, al_map_rgba_f(0.4, 0.3, 0.1, 1), Thickness);
      
      al_use_transform(&Identity);
   }
}
Пример #13
0
static void HighFilledPrimitives(int mode)
{
   if (mode == INIT) {
   
   } else if (mode == LOGIC) {
      Theta += Speed;
      al_build_transform(&MainTrans, ScreenW / 2, ScreenH / 2, 1, 1, Theta);
   } else if (mode == DRAW) {
      if (Blend)
         al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ONE);
      else
         al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO);
      
      al_use_transform(&MainTrans);
      
      al_draw_filled_triangle(-100, -100, -150, 200, 100, 200, al_map_rgb_f(0.5, 0.7, 0.3));
      al_draw_filled_rectangle(20, -50, 200, 50, al_map_rgb_f(0.3, 0.2, 0.6));
      al_draw_filled_ellipse(-250, 0, 100, 150, al_map_rgb_f(0.3, 0.3, 0.3));
      al_draw_filled_rounded_rectangle(50, -250, 350, -75, 50, 70, al_map_rgb_f(0.4, 0.2, 0));
      al_draw_filled_pieslice(200, 125, 50, ALLEGRO_PI / 4, 3 * ALLEGRO_PI / 2, al_map_rgb_f(0.3, 0.3, 0.1));
      
      al_use_transform(&Identity);
   }
}