コード例 #1
0
ファイル: megamaniac.c プロジェクト: trjstewart/qut-cab202
void GameOver(Game * game) {
	clear_screen();
	draw_string((screen_width()/2)-11,screen_height()/2-2,"----------------------");
    draw_string((screen_width()/2)-11,screen_height()/2-1,"|     You Died :(    |");
    draw_string((screen_width()/2)-11,screen_height()/2,  "|   Press Q to Quit  |");
    draw_string((screen_width()/2)-11,screen_height()/2+1,"| Press R to Restart |");
    draw_string((screen_width()/2)-11,screen_height()/2+2,"----------------------");
	show_screen();
}
コード例 #2
0
ファイル: bue2jsUs.C プロジェクト: micabressan/trabajo_final
void info() {
        int x = screen_width()/2;
        draw_string(x - 5, screen_height() -1, "Level: 1" );
        draw_string(0, screen_height()-2, "Georgina Hine (n8872597)");
        draw_string(screen_width() - 9, screen_height() - 2, "Lives:");
        draw_string(screen_width()-18, screen_height() - 2, "Score:"); 
        draw_line(0, screen_height() - 3, screen_width(), screen_height() - 3, '-');
 
        show_screen();
}
コード例 #3
0
ファイル: raster.cpp プロジェクト: jamesjrg/frogatto-vs
	void prepare_raster()
	{
		//	int real_w, real_h;
		//	bool rotated;
		
#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
		//	real_w = 320;
		//	real_h = 480;
		//	rotated = true;
#else
		const SDL_Surface* fb = SDL_GetVideoSurface();
		if(fb == NULL) {
			std::cerr << "Framebuffer was null in prepare_raster\n";
			return;
		}
		//	real_w = fb->w;
		//	real_h = fb->h;
		//	rotated = false;
#endif
		
		glViewport(0, 0, preferences::actual_screen_width(), preferences::actual_screen_height());
//		glClearColor(0.0, 0.0, 0.0, 0.0);
//		glClear(GL_COLOR_BUFFER_BIT);
		glShadeModel(GL_FLAT);
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		
		if(preferences::screen_rotated()) {
			//		glOrtho(0, 640, 960, 0, -1.0, 1.0);
			glOrtho(0, screen_height(), screen_width(), 0, -1.0, 1.0);
		} else {
			glOrtho(0, screen_width(), screen_height(), 0, -1.0, 1.0);
		}
		
		//glOrtho(0, real_w, real_h, 0, -1.0, 1.0);
		if(preferences::screen_rotated()) {
			// Rotate 90 degrees ccw, then move real_h pixels down
			// This has to be in opposite order since A(); B(); means A(B(x))
			glTranslatef(screen_height(), 0.0f, 0.0f);
			glRotatef(90.0f, 0.0f, 0.0f, 1.0f);
			//glTranslatef(0.0f, 0.5f, 0.0f);
			//glScalef(0.5f, 0.5f, 1.0f);
		}
		
		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();
		
		glDisable(GL_DEPTH_TEST);
		glDisable(GL_LIGHTING);
		glDisable(GL_LIGHT0);
		
		glColor4f(1.0, 1.0, 1.0, 1.0);
	}
コード例 #4
0
ファイル: fill_rect.c プロジェクト: NathanRamage/CAB202
// Generate coordinates, draw box.
void demo()
{
	int x = rand() % screen_width() / 2;
	int y = rand() % screen_height() / 2;
	int w = rand() % ( screen_width() - x );
	int h = rand() % ( screen_height() - y );
	char * chars = "~!@#$%^&*-+";
	char ch = chars[rand() % strlen( chars )];

	fill_rect( x, y, w, h, ch );
	
	show_screen();
}
コード例 #5
0
ファイル: edacairo.c プロジェクト: gareth8118/geda-gaf
void
eda_cairo_center_arc (cairo_t *cr, int flags,
                      double center_width,
                      double line_width, double x, double y,
                      double radius, double start_angle, double sweep_angle)
{
  int s_center_width, s_line_width;
  double s_x, s_y, dummy = 0;
  int s_diameter;
  double even_center_width;
  double even_line_width;
  double even_diameter;
  double center_offset;
  double s_radius;
  int do_radius_hint = TRUE;

  if (!(flags & EDA_CAIRO_ENABLE_HINTS)) {
    do_arc (cr, x, y, radius, start_angle, sweep_angle);
    return;
  }

  WORLDtoSCREEN (cr, x, y, &s_x, &s_y);
  s_diameter = SCREENabs (cr, 2 * radius);
  even_diameter = ((s_diameter % 2) == 0);
  s_radius = (double) s_diameter / 2.;

  /* Switch off radius hinting for small radii. If we don't, then we get
   * a very abrupt transition once the arc reaches a single pixel size. */
  if (s_radius <= 1.) do_radius_hint = FALSE;

  /* Hint the center of the arc based on where a line
   * of thickness center_width (world) would drawn */
  s_center_width = screen_width (cr, center_width);
  even_center_width = (center_width == -1 || (s_center_width % 2) == 0);
  center_offset = even_center_width ? 0. : 0.5;

  /* Hint the radius to land its extermity on the pixel grid */
  s_line_width = screen_width (cr, line_width);
  even_line_width = (line_width == -1 || (s_line_width % 2) == 0);
  if (do_radius_hint)
    s_radius += ((even_center_width ==
                        even_line_width) == even_diameter) ? 0. : 0.5;

  s_x += center_offset;
  s_y += center_offset;
  cairo_device_to_user (cr, &s_x, &s_y);
  cairo_device_to_user_distance (cr, &s_radius, &dummy);

  do_arc (cr, s_x, s_y, s_radius, start_angle, sweep_angle);
}
コード例 #6
0
ファイル: zombieracer.c プロジェクト: 0xLeon/CAB202-Projects
void get_racetrack_params(
	int* x0, int* xr_outer, int* xr_inner,
	int* y0, int* yr_outer, int* yr_inner,
	double* p) {
	(*x0) = screen_width() / 2;
	(*xr_outer) = OUTER_PERCENT * (screen_width() / 2) / 100;
	(*xr_inner) = (*xr_outer) - NOMINAL_WIDTH;

	(*y0) = screen_height() / 2;
	(*yr_outer) = OUTER_PERCENT * (screen_height() / 2) / 100;
	(*yr_inner) = (*yr_outer) - NOMINAL_WIDTH;

	(*p) = DEFAULT_P;
}
コード例 #7
0
ファイル: gschem_cairo.c プロジェクト: jgriessen/geda-gaf
void gschem_cairo_arc (GSCHEM_TOPLEVEL *w_current,
                       int width, int x, int y,
                       int radius, int start_angle, int end_angle)
{
  int s_width;
  int x1, y1, x2, y2;
  double s_x, s_y, s_radius;
  double offset;

  WORLDtoSCREEN (w_current, x - radius, y + radius, &x1, &y1);
  WORLDtoSCREEN (w_current, x + radius, y - radius, &x2, &y2);
  s_width = screen_width (w_current, width);
  offset = ((s_width % 2) == 0) ? 0 : 0.5;

  s_x = (double)(x1 + x2) / 2.;
  s_y = (double)(y1 + y2) / 2.;
  s_radius = (double)(y2 - y1) / 2.;

  cairo_save (w_current->cr);
  cairo_translate (w_current->cr, s_x + offset, s_y + offset);

  /* Adjust for non-uniform X/Y scale factor. Note that the + 1
     allows for the case where x2 == x1 or y2 == y1 */
  cairo_scale (w_current->cr, (double)(x2 - x1 + 1) /
                              (double)(y2 - y1 + 1), 1.);

  do_arc (w_current->cr, 0., 0., (double) s_radius, start_angle, end_angle);

  cairo_restore (w_current->cr);
}
コード例 #8
0
ファイル: gschem_cairo.c プロジェクト: jgriessen/geda-gaf
void gschem_cairo_box (GSCHEM_TOPLEVEL *w_current, int line_width,
                       int x1, int y1, int x2, int y2)
{
  int s_line_width;
  int s_x1, s_y1, s_x2, s_y2;
  double offset;

  WORLDtoSCREEN (w_current, x1, y1, &s_x1, &s_y1);
  WORLDtoSCREEN (w_current, x2, y2, &s_x2, &s_y2);
  s_line_width = screen_width (w_current, line_width);
  offset = (line_width == -1 || (s_line_width % 2) == 0) ? 0 : 0.5;

  /* Allow filled boxes (inferred from line_width == -1)
   * to touch an extra pixel, so the filled span is inclusive */
  if (line_width == -1) {
    if (x1 > x2) x1 += 1; else x2 += 1;
    if (y1 > y2) y1 += 1; else y2 += 1;
  }

  cairo_move_to (w_current->cr, s_x2 + offset, s_y2 + offset);
  cairo_line_to (w_current->cr, s_x1 + offset, s_y2 + offset);
  cairo_line_to (w_current->cr, s_x1 + offset, s_y1 + offset);
  cairo_line_to (w_current->cr, s_x2 + offset, s_y1 + offset);
  cairo_close_path (w_current->cr);
}
コード例 #9
0
void save_screen( void ) {
    char * fileName = CAB202_SCREEN_NAME;

    FILE * f = fopen( fileName, "a" );

    if ( f == NULL ) return;

    int width = screen_width();
    int height = screen_height();

    fprintf( f, "Frame\n" );
    fprintf( f, "width=%d\n", width );
    fprintf( f, "height=%d\n", height );

    for ( int y = 0; y < height; y++ ) {
        for ( int x = 0; x < width; x++ ) {
            char c = get_screen_char( x, y );

            if ( c != ' ' ) {
                fprintf( f, "%d,%d,%d\n", x, y, (int)c );
            }
        }
    }

    fprintf( f, "EndFrame\n" );

    fclose( f );
}
コード例 #10
0
ファイル: megamaniac.c プロジェクト: trjstewart/qut-cab202
void MovementAliens(Game * game) {
	// Move Aliens according to Level
	if (game->game_level == 1) {
		MovementLevelOne(game);
	} else if (game->game_level == 2) {
		MovementLevelTwo(game);
	} else if (game->game_level == 3) {
		MovementLevelThree(game);
	} else if (game->game_level == 4) {
		MovementLevelFour(game);
	} else if (game->game_level == 5) {
		MovementLevelFive(game);
	}

	// Screen Wrapping
	for (int i = 0; i < 10; i++) {
		if (game->enemy_aliens[i]->x > screen_width() - 1) {
			game->enemy_aliens[i]->x = 0;
		}

		if (game->enemy_aliens[i]->y > screen_height() - 4) {
			game->enemy_aliens[i]->y = 0;
		}
	}
}
コード例 #11
0
ファイル: zombieracer.c プロジェクト: 0xLeon/CAB202-Projects
sprite_id generate_racetrack() {
	int width = screen_width();
	int height = screen_height();
	char* buffer;
	
	buffer = malloc(width * height * sizeof(char));
	
	if (buffer == NULL) {
		fprintf(stderr, "%s", "Couldn't initialize racetrack buffer.\nNot enough memory!");
		abort();
	}
	
	for (int y = 0; y < height; y++) {
		for (int x = 0; x < width; x++) {
			if (on_racetrack(x, y)) {
				buffer[y * width + x] = ' ';
			}
			else {
				buffer[y * width + x] = '&';
			}
		}
	}
	
	return create_sprite(0, 0, width, height, buffer);
}
コード例 #12
0
ファイル: bue2jsUs.C プロジェクト: micabressan/trabajo_final
void setup() {
        setup_screen();
        player = create_sprite(screen_width()/2, screen_height() - 5, 1, 1, "S");
        player->dy = 0;
        player->dx = 0;
 
        bullet = create_sprite(-1, -1, 1, 1, "*");
        bullet->dy = 0;
        bullet->dx = 0;
 
for (int i = 0; i < 3; i++) {
                alien[i] = create_sprite(4+4*i, 0, 1, 1, "@");
        }
for (int j = 0; j < 4; j++) {
                alien[j+3] = create_sprite(2+4*j, 3, 1, 1, "@");
        }
for (int k = 0; k < 3; k++) {
                alien[k+7] = create_sprite(4+4*k, 6, 1, 1, "@");
        }      
for (int r = 0; r < 10; r++) {
        alien[r]->dx = 0.1;
        alien[r]->dy = 0;
}
 
 
        tim = create_timer(25);
}
コード例 #13
0
ファイル: planet.c プロジェクト: vivounicorn/eaburns.space
void create_planet()
{
  Uint32 x, y;
  Uint32 i;
  char *image = NULL;

  /* Get random coordinates. */
  x = ( rand() % screen_width() );
  y = -( rand() % 1000) + 100;

  /* Get random image name. */
  i = ( rand() % PLANET_IMAGE_NUM ) + 1; 
  switch( i ) {
  case 1: image = get_data( MOON_1_IMAGE, DATA_IMAGES ); break;
  default: image = NULL;
  }

  /* Make the planet sprite. */
  planet = new_sprite( x, y, 1, image, 0 );
  set_speed( planet, PLANET_SPEED ); 
  if( planet == NULL ) {
    fprintf( stderr, "Error creating new sprite: %s.\n",
              SDL_GetError() );
    exit(-1);
  }
}
コード例 #14
0
ファイル: board.c プロジェクト: Zirias/cursedsnake
Board *
board_create(Screen *screen)
{
    Board *self;
    size_t size;
    int w, h;

    w = screen_width(screen);
    h = screen_height(screen);
    if (w < MIN_COLS || h < MIN_ROWS)
    {
	fputs("Console too small, need at least "
		STR(MIN_COLS) "x" STR(MIN_ROWS) "\n", stderr);
	return 0;
    }
    --h;

#ifdef DOSREAL
    size = sizeof(Board);
    for (int i = 0; i < w*h-1; ++i) size += sizeof(Slot);
#else
    size = sizeof(Board) + (size_t)(w*h-1) * sizeof(Slot);
#endif
    self = malloc(size);
    memset(self, 0, size);
    self->w = w;
    self->h = h;
    self->screen = screen;
    return self;
}
コード例 #15
0
ファイル: edacairo.c プロジェクト: gareth8118/geda-gaf
void
eda_cairo_arc (cairo_t *cr, int flags,
               double width, double x, double y,
               double radius, double start_angle, double sweep_angle)
{
  int s_width;
  double x1, y1, x2, y2;
  double s_x, s_y, s_radius;
  double offset, dummy = 0;

  if (!(flags & EDA_CAIRO_ENABLE_HINTS)) {
    do_arc (cr, x, y, radius, start_angle, sweep_angle);
    return;
  }

  WORLDtoSCREEN (cr, x - radius, y + radius, &x1, &y1);
  WORLDtoSCREEN (cr, x + radius, y - radius, &x2, &y2);
  s_width = screen_width (cr, width);
  offset = ((s_width % 2) == 0) ? 0 : 0.5;

  s_x = (double)(x1 + x2) / 2.;
  s_y = (double)(y1 + y2) / 2.;
  s_radius = (double)(y2 - y1) / 2.;

  cairo_device_to_user (cr, &s_x, &s_y);
  cairo_device_to_user_distance (cr, &offset, &dummy);
  cairo_device_to_user_distance (cr, &s_radius, &dummy);

  do_arc (cr, s_x + offset, s_y + offset,
          s_radius, start_angle, sweep_angle);
}
コード例 #16
0
ファイル: edacairo.c プロジェクト: gareth8118/geda-gaf
void
eda_cairo_box (cairo_t *cr, int flags, double line_width,
               double x1, double y1, double x2, double y2)
{
  int s_line_width;
  double s_x1, s_y1, s_x2, s_y2;
  double offset;

  if (!(flags & EDA_CAIRO_ENABLE_HINTS)) {
    cairo_rectangle (cr, x1, y1, (x2 - x1), (y2 - y1));
    return;
  }

  WORLDtoSCREEN (cr, x1, y1, &s_x1, &s_y1);
  WORLDtoSCREEN (cr, x2, y2, &s_x2, &s_y2);
  s_line_width = screen_width (cr, line_width);
  offset = (line_width == -1 || (s_line_width % 2) == 0) ? 0 : 0.5;

  /* Allow filled boxes (inferred from line_width == -1)
   * to touch an extra pixel, so the filled span is inclusive */
  if (line_width == -1) {
    if (s_x1 > s_x2) s_x1 += 1; else s_x2 += 1;
    if (s_y1 > s_y2) s_y1 += 1; else s_y2 += 1;
  }

  s_x1 += offset; s_y1 += offset;
  s_x2 += offset; s_y2 += offset;
  cairo_device_to_user (cr, &s_x1, &s_y1);
  cairo_device_to_user (cr, &s_x2, &s_y2);
  cairo_move_to (cr, s_x2, s_y2);
  cairo_line_to (cr, s_x1, s_y2);
  cairo_line_to (cr, s_x1, s_y1);
  cairo_line_to (cr, s_x2, s_y1);
  cairo_close_path (cr);
}
コード例 #17
0
ファイル: edacairo.c プロジェクト: gareth8118/geda-gaf
void
eda_cairo_path (cairo_t *cr, int flags, double line_width,
                int nsections, PATH_SECTION *sections)
{
  int i;
  int s_line_width;
  double dummy = 0;

  if (flags & EDA_CAIRO_ENABLE_HINTS) {
    s_line_width = screen_width (cr, line_width);
  } else {
    cairo_user_to_device (cr, &line_width, &dummy);
    s_line_width = line_width;
  }

  for (i = 0; i < nsections; i++) {
    PATH_SECTION *section = sections + i;
    double x1 = section->x1;
    double x2 = section->x2;
    double x3 = section->x3;
    double y1 = section->y1;
    double y2 = section->y2;
    double y3 = section->y3;

    switch (section->code) {
      case PATH_CURVETO:
        /* Two control point grips */
        eda_cairo_path_hint (cr, flags, &x1, &y1, s_line_width);
        eda_cairo_path_hint (cr, flags, &x2, &y2, s_line_width);
        /* Fall through */
      case PATH_MOVETO:
      case PATH_MOVETO_OPEN:
      case PATH_LINETO:
        /* Destination point grip */
        eda_cairo_path_hint (cr, flags, &x3, &y3, s_line_width);
      case PATH_END:
        break;
    }

    switch (section->code) {
      case PATH_MOVETO:
        cairo_close_path (cr);
        /* fall-through */
      case PATH_MOVETO_OPEN:
        cairo_move_to (cr, x3, y3);
        break;
      case PATH_CURVETO:
        cairo_curve_to (cr, x1, y1, x2, y2, x3, y3);
        break;
      case PATH_LINETO:
        cairo_line_to (cr, x3, y3);
        break;
      case PATH_END:
        cairo_close_path (cr);
        break;
    }
  }
}
コード例 #18
0
ファイル: gschem_cairo.c プロジェクト: jgriessen/geda-gaf
void gschem_cairo_line (GSCHEM_TOPLEVEL *w_current, int line_end,
                        int w_line_width,
                        int w_x1, int w_y1, int w_x2, int w_y2)
{
  int x1, y1, x2, y2, line_width;
  double offset;
  double xoffset = 0;
  double yoffset = 0;
  int horizontal = 0;
  int vertical = 0;

  WORLDtoSCREEN (w_current, w_x1, w_y1, &x1, &y1);
  WORLDtoSCREEN (w_current, w_x2, w_y2, &x2, &y2);
  line_width = screen_width (w_current, w_line_width);
  offset = ((line_width % 2) == 0) ? 0 : 0.5;

  if (y1 == y2) horizontal = 1;
  if (x1 == x2) vertical = 1;

  /* Hint so the length of the line runs along a pixel boundary */

  if (horizontal)
    yoffset = offset;
  else if (vertical)
    xoffset = offset;
  else
    xoffset = yoffset = offset;

  /* Now hint the ends of the lines */

  switch (line_end) {
    case END_NONE:
      /* Line terminates at the passed coordinate */

      /* Add an extra pixel to give an inclusive span */
      if (horizontal) {
        if (x1 > x2) x1 += 1; else x2 += 1;
      } else if (vertical) {
        if (y1 > y2) y1 += 1; else y2 += 1;
      }
      break;

    case END_SQUARE:
    case END_ROUND:
      /* Line terminates half a width away from the passed coordinate */
      if (horizontal) {
        xoffset = offset;
      } else if (vertical) {
        yoffset = offset;
      }
      break;
  }

  cairo_move_to (w_current->cr, x1 + xoffset, y1 + yoffset);
  cairo_line_to (w_current->cr, x2 + xoffset, y2 + yoffset);
}
コード例 #19
0
	Rectangle2D Context::GetPixelCoord(const Rectangle2D& i_virtual_screen_coord)
	{
		uint32_t width = screen_width();
		uint32_t height = screen_height();
		return Rectangle2D(
			i_virtual_screen_coord.left() * width,
			i_virtual_screen_coord.right() * width,
			i_virtual_screen_coord.top() * height,
			i_virtual_screen_coord.bottom() * height );
	}
コード例 #20
0
ファイル: megamaniac.c プロジェクト: trjstewart/qut-cab202
void MovementPlayer(Game * game, int userInput) {
	// Move Player based on User Input.
	if (userInput == 'a' && game->player_spaceship->x >= 1) {
		game->player_spaceship->x -= game->player_spaceship->dx;
	} else if (userInput == 'd' && game->player_spaceship->x <= screen_width() - 4) {
		game->player_spaceship->x += game->player_spaceship->dx;
	}

	// Ensure the players Y location is correct.
	game->player_spaceship->y = screen_height() - 4;
}
コード例 #21
0
	void prepare_raster()
	{
		glViewport(0, 0, preferences::actual_screen_width(), preferences::actual_screen_height());
		glShadeModel(GL_FLAT);
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		
		if(preferences::screen_rotated()) {
			int top = screen_width();
			int bot = 0;
			if(g_flip_draws) {
				std::swap(top, bot);
			}
			glOrtho(0, screen_height(), top, bot, -1.0, 1.0);
		} else {
			int top = screen_height();
			int bot = 0;
			if(g_flip_draws) {
				std::swap(top, bot);
			}
			glOrtho(0, screen_width(), top, bot, -1.0, 1.0);
		}
		
		if(preferences::screen_rotated()) {
			// Rotate 90 degrees ccw, then move real_h pixels down
			// This has to be in opposite order since A(); B(); means A(B(x))
			glTranslatef(screen_height(), 0.0f, 0.0f);
			glRotatef(90.0f, 0.0f, 0.0f, 1.0f);
		}
		
		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();
		
		glDisable(GL_DEPTH_TEST);
#if !defined(USE_SHADERS)
		glDisable(GL_LIGHTING);
		glDisable(GL_LIGHT0);
#endif
		
		glColor4f(1.0, 1.0, 1.0, 1.0);
	}
コード例 #22
0
ファイル: gschem_cairo.c プロジェクト: jgriessen/geda-gaf
void gschem_cairo_center_arc (GSCHEM_TOPLEVEL *w_current,
                              int center_width,
                              int line_width, int x, int y,
                              int radius, int start_angle, int end_angle)
{
  int s_center_width, s_line_width;
  int s_x, s_y, s_diameter;
  int even_center_width;
  int even_line_width;
  int even_diameter;
  double center_offset;
  double s_radius;
  int do_radius_hint = TRUE;

  WORLDtoSCREEN (w_current, x, y, &s_x, &s_y);
  s_diameter = SCREENabs (w_current, 2 * radius);
  even_diameter = ((s_diameter % 2) == 0);
  s_radius = (double) s_diameter / 2.;

  /* Switch off radius hinting for small radii. If we don't, then we get
   * a very abrupt transition once the arc reaches a single pixel size. */
  if (s_radius <= 1.) do_radius_hint = FALSE;

  /* Hint the center of the arc based on where a line
   * of thickness center_width (world) would drawn */
  s_center_width = screen_width (w_current, center_width);
  even_center_width = (center_width == -1 || (s_center_width % 2) == 0);
  center_offset = even_center_width ? 0. : 0.5;

  /* Hint the radius to land its extermity on the pixel grid */
  s_line_width = screen_width (w_current, line_width);
  even_line_width = (line_width == -1 || (s_line_width % 2) == 0);
  if (do_radius_hint)
    s_radius += ((even_center_width ==
                        even_line_width) == even_diameter) ? 0. : 0.5;

  do_arc (w_current->cr, (double) s_x + center_offset,
                         (double) s_y + center_offset,
                         (double) s_radius,
                         start_angle, end_angle);
}
コード例 #23
0
ファイル: bue2jsUs.C プロジェクト: micabressan/trabajo_final
void update_state() {
        //Check if we've hit the boundaries
        if (player->x + player->dx < 0 || player->x + player->dx >= screen_width()){
                player->dx = 0;
                player->dy = 0;
        }
       
        //Move player
        player->x += player->dx;
        player->y +=player->dy;
 
        //Reset move vector
        player->dx = 0;
        player->dy = 0;
       
       
 
        if (shot == true) {
                bullet->y += bullet->dy;
                bullet->x = spot;
 
        }
        else {
			bullet->dy = 0;
        }
 
        for (int i = 0; i < 10; i++) {
                if (alien[i]->x + alien[i]->dx > screen_width() - 1) {
                        alien[i]->x = -1;
                }
        }
 
        for (int r = 0; r < 10; r++) {
                alien[r]->x += alien[r]->dx ;
                alien[r]->y += alien[r]->dy;
        }
 
       
}      
コード例 #24
0
ファイル: megamaniac.c プロジェクト: trjstewart/qut-cab202
void MovementLevelTwo(Game * game) {
	for (int i = 0; i < 10; i++) {
		// Generate new Y location for Aliens.
		double y = 2 * sin((game->enemy_aliens[3]->x * 2 * M_PI) / (screen_width() / 6));

		// Offset the top and bottom row of aliens back to their correct formation.
		(i == 0 || i == 1 || i == 2) ? y -= 2 : (i == 7 || i == 8 || i == 9) ? y += 2 : y;

		// Move the Aliens
		game->enemy_aliens[i]->x += game->enemy_aliens[i]->dx;
		game->enemy_aliens[i]->y = y + 5;
	}
}
コード例 #25
0
ファイル: raster.cpp プロジェクト: x2f/wesciv
void push_clip(const SDL_Rect& r)
{
	const bool was_enabled_clip = glIsEnabled(GL_SCISSOR_TEST);
	bool should_enable_clip = true;

	GLdouble x, y ,z;
	coords_to_screen(0, graphics::screen_height(), 0, &x, &y, &z);

	SDL_Rect s = r;
	s.x += static_cast<Sint16>(x);
	s.y -= static_cast<Sint16>(y);

	if(s.x == 0 && s.y == 0 && s.w == screen_width() && s.h == screen_height()) {
		should_enable_clip = false;
	}


	boost::shared_array<GLint> box(new GLint[4]);

	if(was_enabled_clip) {
		glGetIntegerv(GL_SCISSOR_BOX, box.get());
	} else {
		box[0] = 0;
		box[1] = 0;
		box[2] = screen_width();
		box[3] = screen_height();
	}
	clip_rectangles.push_back(box);

	if(should_enable_clip) {
		if(!was_enabled_clip) {
			glEnable(GL_SCISSOR_TEST);
		}
		glScissor(s.x, screen_height() - (s.y + s.h), s.w, s.h);
	} else if(was_enabled_clip) {
		glDisable(GL_SCISSOR_TEST);
	}
}
コード例 #26
0
ファイル: ui.c プロジェクト: bcl/parted
int
interactive_mode (PedDevice** dev, PedDisk** disk, Command* cmd_list[])
{
        StrList*    list;
        StrList*    command_names = command_get_names (cmd_list);

        commands = cmd_list;    /* FIXME yucky, nasty, evil hack */

        fputs (prog_name, stdout);

        print_using_dev (*dev);

        list = str_list_create (_(banner_msg), NULL);
        str_list_print_wrap (list, screen_width (), 0, 0, stdout);
        str_list_destroy (list);

        while (1) {
                char*       word;
                Command*    cmd;

                while (!command_line_get_word_count ()) {
                        if (got_ctrl_c) {
                                putchar ('\n');
                                return 1;
                        }
                        command_line_prompt_words ("(parted)", NULL,
                                                   command_names, 1);
                }

                word = command_line_pop_word ();
                if (word) {
                        cmd = command_get (commands, word);
                        free (word);
                        if (cmd) {
                                if (!command_run (cmd, dev, disk)) {
                                        command_line_flush ();

                                        if (*disk) {
                                                ped_disk_destroy (*disk);
                                                *disk = 0;
                                        }
                                }
                        } else
                                print_commands_help ();
                }
        }

        return 1;
}
コード例 #27
0
ファイル: video_output_qt.cpp プロジェクト: GiR-Zippo/bino
void video_output_qt::center()
{
    if (!dispatch::parameters().fullscreen())
    {
        // Move the window, not the widget, so that this also works inside the GUI.
        int dest_screen_pos_x = (screen_width() - width()) / 2;
        int dest_screen_pos_y = (screen_height() - height()) / 2;
        int window_offset_x = _widget->mapTo(_widget->window(), QPoint(0, 0)).x();
        int window_offset_y = _widget->mapTo(_widget->window(), QPoint(0, 0)).y();
        _widget->window()->setGeometry(
                dest_screen_pos_x - window_offset_x,
                dest_screen_pos_y - window_offset_y,
                _widget->window()->width(), _widget->window()->height());
    }
}
コード例 #28
0
ファイル: megamaniac.c プロジェクト: trjstewart/qut-cab202
void MovementLevelFour(Game * game) {
	for (int i = 0; i < 10; i++) {
		double r = (rand() % 100) - 50;
		r -= (i - 5);

		if (game->enemy_aliens[i]->x > game->LevelFour_borderRight) {
			game->enemy_aliens[i]->dx = 0.2;
		}
		if (game->enemy_aliens[i]->x < game->LevelFour_borderLeft) {
			game->enemy_aliens[i]->dx = -0.2;
		}

		// Collision Check - This could get nasty...
		for (int i = 0; i < 10; i++) {
			for (int n = 0; n < 10; n++) {
				if (round(game->enemy_aliens[i]->y) == round(game->enemy_aliens[n]->y) && round(game->enemy_aliens[i]->x) == (round(game->enemy_aliens[n]->x) - 2)) {
					game->enemy_aliens[i]->dx = 0.1;
				}

				if (round(game->enemy_aliens[i]->y) == round(game->enemy_aliens[n]->y) && round(game->enemy_aliens[i]->x) == (round(game->enemy_aliens[n]->x) + 2)) {
					game->enemy_aliens[i]->dx = -0.1;
				}
			}
		}

		//
		game->enemy_aliens[i]->x -= (r / 100) + game->enemy_aliens[i]->dx;
		game->enemy_aliens[i]->dy = 0.1;
		game->enemy_aliens[i]->y += game->enemy_aliens[i]->dy;

		if (game->LevelFour_borderRight > (screen_width() - 5)) {
			game->levelFour_contract = true;
		}
		if (game->LevelFour_borderRight < (game->LevelFour_borderLeft + 17)) {
			game->levelFour_contract = false;
		}

		if (game->levelFour_contract == true) {
			game->LevelFour_borderRight -= 0.01;
			game->LevelFour_borderLeft += 0.01;
		} else {
			game->LevelFour_borderRight += 0.01;
			game->LevelFour_borderLeft -= 0.01;
		}
	}
}
コード例 #29
0
ファイル: megamaniac.c プロジェクト: trjstewart/qut-cab202
void RespawnPlayer(Game * game) {
	if (game->player_lives == 0) {
		game->game_over = true;
	} else {
		// Respawn the Player in a safe location.
		game->player_spaceship->x = screen_width() / 2;
		game->player_spaceship->y = screen_height() - 4;
		game->player_spaceship->is_visible = true;

		// Reset Bonuses.
		game->bonusMissiles = 0;
	}

	for (int i = 0; i < 4; i++) {
		game->enemy_bombs[i]->is_visible = false;
	}
}
コード例 #30
0
ファイル: ship.c プロジェクト: vivounicorn/eaburns.space
void new_ship( char *t )
{
  Sint32 frames;
  Sint32 delay;
  Sint32 speed;
  Sint32 x, y;

  x = screen_width() / 2;
  y = screen_height() - 50;

  frames = get_num_frames( t );
  delay = get_frame_delay( t );
  speed = get_speed( t );
  ship.hp = get_hp( t ) * PLAYER_HP_FACTOR; 
  ship.hp_max = ship.hp;
  ship.type = strdup( t );

  ship.left = new_sprite_array( x, y, frames, get_left( t ), delay );
  if( ship.left == NULL ) { 
    fprintf( stderr, "Error creating new sprite: %s.\n", SDL_GetError() );
    exit( 1 );
  }
  set_speed( ship.left, speed );
  no_off_screen( ship.left );

  ship.right = new_sprite_array( x, y, frames, get_right( t ), delay );
  if( ship.right == NULL ) { 
    fprintf( stderr, "Error creating new sprite: %s.\n", SDL_GetError() );
    exit( 1 );
  }
  set_speed( ship.right, speed );
  no_off_screen( ship.right );

  ship.center = new_sprite_array( x, y, frames, get_center( t ), delay );
  if( ship.center == NULL ) { 
    fprintf( stderr, "Error creating new sprite: %s.\n", SDL_GetError() );
    exit( 1 );
  }
  set_speed( ship.center, speed );
  no_off_screen( ship.center );

  ship.current = ship.center;
  ship_center();
}