예제 #1
0
파일: spaceship.c 프로젝트: ooonak/cmess
/* Draw ship */
void draw_ship(Spaceship *s)
{
  ALLEGRO_TRANSFORM transform;
  al_identity_transform(&transform);
  al_rotate_transform(&transform, 0);
  al_rotate_transform(&transform, (s->heading * (M_PI/180)));
  al_translate_transform(&transform, s->sx, s->sy);
  al_use_transform(&transform);
  al_draw_line(-8, 9, 0, -11, s->color, 3.0f);
  al_draw_line(0, -11, 8, 9, s->color, 3.0f);
  al_draw_line(-6, 4, -1, 4, s->color, 3.0f);
  al_draw_line(6, 4, 1, 4, s->color, 3.0f);
}
예제 #2
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);
}
예제 #3
0
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);
}
예제 #4
0
/** Applies a rotation transformation to the current transformation. */
void cbeTransformRotate(CBEnchanted *cb) {
	float angle = (cb->popValue().toFloat() / 180.0f) * M_PI;

	ALLEGRO_TRANSFORM t;
	al_identity_transform(&t);
	al_rotate_transform(&t, angle);
	al_use_transform(&t);
	cb->pushValue(0);
}
예제 #5
0
void spaceship_draw(Spaceship *s) {
  ALLEGRO_TRANSFORM transform;
  if(s->gone == DEAD) return;
  al_identity_transform(&transform);
  al_rotate_transform(&transform, DEGREES(s->heading));
  al_translate_transform(&transform, s->sx, s->sy);
  al_use_transform(&transform);
  al_draw_line(-8, 9, 0, -11, s->color, 3.0f);
  al_draw_line(0, -11, 8, 9, s->color, 3.0f);
  al_draw_line(-6, 4, -1, 4, s->color, 3.0f);
  al_draw_line(6, 4, 1, 4, s->color, 3.0f);
}
예제 #6
0
int main(void)
{
	al_init();

	ALLEGRO_DISPLAY *d = al_create_display(W, H);

	ALLEGRO_VERTEX v[POINTS];
	ALLEGRO_COLOR c;

	v[0].x = 0;
	v[0].y = 0;
	c = al_map_rgb(rand()%256, rand()%256, rand()%256);
	v[0].color = al_get_prim_color(c);
	v[1].x = 0+R;
	v[1].y = 0;
	c = al_map_rgb(rand()%256, rand()%256, rand()%256);
	v[1].color = al_get_prim_color(c);

	float a = 0;
	float r = R;
	int i;

	for (i = 2; i < POINTS; i++) {
		v[i].x = 0+cos(a)*r;
		v[i].y = 0+sin(a)*r;
		a += 0.3f;
		r -= 1.5f;
		c = al_map_rgb(rand()%256, rand()%256, rand()%256);
		v[i].color = al_get_prim_color(c);
	}

	int frames = 0;
	ALLEGRO_TRANSFORM t;

	while (true) {
		al_clear_to_color(al_map_rgb(0, 0, 0));
		al_identity_transform(&t);
		al_rotate_transform(&t, frames*0.1f);
		al_translate_transform(&t, W/2, H/2);
		al_use_transform(&t);
		al_draw_prim(v, NULL, 0, POINTS, ALLEGRO_PRIM_TRIANGLE_FAN);
		al_flip_display();
		/* GP2X Wiz is locked to 60FPS using OpenGL */
		frames++;
		if (frames > 400)
			break;
	}

	al_uninstall_system();

	return 0;
}
예제 #7
0
파일: game.c 프로젝트: sergot/asteroids
void draw_ship(game *game) {
    ALLEGRO_TRANSFORM trans;
    al_identity_transform(&trans);
    al_rotate_transform(&trans, game->Ship->angle);
    al_translate_transform(&trans,
                           (int)game->Ship->position->x,
                           (int)game->Ship->position->y);
    al_use_transform(&trans);
    
    float w = game->Ship->time >= 0 ? 1 : 4;
    
    al_draw_line(-8, 20, 0, 0, SHIP_COLOR, w);
    al_draw_line(8, 20, 0, 0, SHIP_COLOR, w);
    al_draw_line(-6, 15, -1, 15, SHIP_COLOR, w);
    al_draw_line(6, 15, 1, 15, SHIP_COLOR, w);
}
void mw2_Rect::Draw(mw2_Camera* camera)
{
	float x = WorldPosition()->x - camera->WorldPosition()->x;
	float y = WorldPosition()->y - camera->WorldPosition()->y;
	float teta = - camera->WorldRotation() * (float) PI / 180;

	float finalAngle = WorldRotation() - camera->WorldRotation();
	float finalX = (x * (float) cos(teta) - y * (float) sin(teta))
					+ mw2_Application::Settings::width / 2;
	float finalY = (x * (float) sin(teta) + y * (float) cos(teta))
					+ mw2_Application::Settings::height / 2;

	ALLEGRO_TRANSFORM T;
	al_identity_transform(&T);
	al_rotate_transform(&T, finalAngle * (float) PI / 180);
	al_translate_transform(&T, finalX, finalY);
	al_use_transform(&T);

	ALLEGRO_COLOR color = al_map_rgba(mColor->x, mColor->y, mColor->z, mColor->t);

	switch (mStyle)
	{
		case FILL:
			al_draw_filled_rectangle(
				- mSize->x /2, - mSize->y /2,
				mSize->x /2, mSize->y /2,
				color
			);
			break;
		case LINE:
			al_draw_rectangle(
				- mSize->x /2, - mSize->y /2,
				mSize->x /2, mSize->y /2,
				color,
				1
			);
			break;
	}

	al_identity_transform(&T);
	al_use_transform(&T);
}
예제 #9
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);
}
예제 #10
0
파일: blast.c 프로젝트: pasoev/blasteroids
void draw_blast(Blast *blast) {
    ALLEGRO_TRANSFORM transform;

    if(al_get_current_transform() == NULL) {
        fprintf(stderr, "no target bitmap.");
    }

    al_identity_transform(&transform);
    al_rotate_transform(&transform, 1.58525 + head2theta(blast->heading));
    al_translate_transform(&transform, blast->sx, blast->sy);
    al_use_transform(&transform);

    /* many small lines will eventually create a dashed line */
    al_draw_line(0, 0, 0, -10, blast->color, 3.0f);
    al_draw_line(0, -15, 0, -25, blast->color, 3.0f);
    al_draw_line(0, -30, 0, -40, blast->color, 3.0f);
    al_draw_line(0, -45, 0, -60, blast->color, 3.0f);
    al_draw_line(0, -65, 0, -80, blast->color, 3.0f);
    al_draw_line(0, -85, 0, -100, blast->color, 3.0f);
    al_draw_line(0, -105, 0, -120, blast->color, 3.0f);
}
예제 #11
0
static void redraw(void)
{
   ALLEGRO_TRANSFORM t;
   int i;

   /* We first draw the Obp background and clear the depth buffer to 1. */

   al_set_render_state(ALLEGRO_ALPHA_TEST, true);
   al_set_render_state(ALLEGRO_ALPHA_FUNCTION, ALLEGRO_RENDER_GREATER);
   al_set_render_state(ALLEGRO_ALPHA_TEST_VALUE, 0);

   al_set_render_state(ALLEGRO_DEPTH_TEST, false);

   al_set_render_state(ALLEGRO_WRITE_MASK, ALLEGRO_MASK_DEPTH | ALLEGRO_MASK_RGBA);

   al_clear_depth_buffer(1);
   al_clear_to_color(al_map_rgb_f(0, 0, 0));

   al_draw_scaled_bitmap(example.obp, 0, 0, 532, 416, 0, 0, 640, 416 * 640 / 532, 0);

   /* Next we draw all sprites but only to the depth buffer (with a depth value
    * of 0).
    */

   al_set_render_state(ALLEGRO_DEPTH_TEST, true);
   al_set_render_state(ALLEGRO_DEPTH_FUNCTION, ALLEGRO_RENDER_ALWAYS);   
   al_set_render_state(ALLEGRO_WRITE_MASK, ALLEGRO_MASK_DEPTH);

   for (i = 0; i < COUNT; i++) {
      struct Sprite *s = example.sprites + i;
      int x, y;
      al_hold_bitmap_drawing(true);
      for (y = -480; y <= 0; y += 480) {
         for (x = -640; x <= 0; x += 640) {
            al_identity_transform(&t);
            al_rotate_transform(&t, s->angle);
            al_translate_transform(&t, s->x + x, s->y + y);
            al_use_transform(&t);
            al_draw_text(example.font, al_map_rgb(0, 0, 0), 0, 0,
               ALLEGRO_ALIGN_CENTER, "Allegro 5");
         }
       }
       al_hold_bitmap_drawing(false);
   }
   al_identity_transform(&t);
   al_use_transform(&t);

   /* Finally we draw Mysha, with depth testing so she only appears where
    * sprites have been drawn before.
    */

   al_set_render_state(ALLEGRO_DEPTH_FUNCTION, ALLEGRO_RENDER_EQUAL);  
   al_set_render_state(ALLEGRO_WRITE_MASK, ALLEGRO_MASK_RGBA);
   al_draw_scaled_bitmap(example.mysha, 0, 0, 320, 200, 0, 0, 320 * 480 / 200, 480, 0);

   /* Finally we draw an FPS counter. */
   al_set_render_state(ALLEGRO_DEPTH_TEST, false);

   al_draw_textf(example.font2, al_map_rgb_f(1, 1, 1), 640, 0,
      ALLEGRO_ALIGN_RIGHT, "%.1f FPS", 1.0 / example.direct_speed_measure);
}
예제 #12
0
파일: transform.c 프로젝트: beoran/ralleg5
VALUE rbal_rotate_transform(VALUE r_, VALUE rtrans, VALUE rtheta) {
  ALLEGRO_TRANSFORM * trans = rbal_transform_unwrap(rtrans);
  float 	      theta = RBH_FLOAT(rtheta);  
  al_rotate_transform(trans, rtheta);
  return rtrans;
}