Exemple #1
0
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();
}
Exemple #2
0
	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);
	}
Exemple #3
0
// 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();
}
Exemple #4
0
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;
}
Exemple #5
0
void check_input() {
        int key = get_char();
        if (key == 'a'){
                player->dx = -1;
               
        }
        else if (key == 'd'){
                player->dx = 1;
               
        }
        else if (key == 's'){
                bullet->y = screen_height() - 5;
                bullet->dy = -1;
                spot = player->x;
                shoot = true;
        }      
        else {
                player->dx = 0;
                player->dy = 0;
 
        }
       
       
 
        while (get_char() != -1) {
 
        }
}
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 );
}
Exemple #7
0
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);
}
Exemple #8
0
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);
}
Exemple #9
0
static Uint8 move_enemy( ENEMY *e )
{
  /* If the enemy is on the screen, then set their active flag. */
  if( e->current->y + 
      e->current->surface[e->current->cur_frame]->h > 0 )
    e->flags |= E_FLAG_ACTIVE;  /* Set the active flag. */

  /* Check if the enemy has left the bottom of the screen. */
  if( e->current->y > (Sint32)screen_height() ) {
    remove_enemy( e );
    player_score -= get_points( e->type ); 
    return 0;
  }

  /* If the enemy is not active then they only scroll down.
   * once the enemy is active they follow their movement
   * pattern. */
  if( !IS_ACTIVE( e->flags ) )
    e->current->y += ENEMY_SCROLL_SPEED;

  else if( e->move_funct == NULL )
    move_enemy_down( e );

  else
    e->move_funct( e );

  return 1;
}
Exemple #10
0
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;
}
Exemple #11
0
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;
		}
	}
}
Exemple #12
0
bool update_ship( Game * game, int key_code ) {
	int shipX = round(game->ship->x);
	int shipY = round(game->ship->y);

	if (key_code == '1' && shipX > 0) {
		game->ship->x--;
	} else if (key_code == '2' && (shipY + game->ship->height) < (screen_height() - 2)) {
		game->ship->y++;
	} else if (key_code == '3' && (shipX + game->ship->width) < 30) {
		game->ship->x++;
	} else if (key_code == '5' && shipY > 0) {
		game->ship->y--;
	} else {
		return false;
	}

	int shipXnew = round(game->ship->x);
	int shipYnew = round(game->ship->y);

	if (shipX != shipXnew) {
		return true;
	} else if (shipY != shipYnew) {
		return true;
	}
	return false;
}
Exemple #13
0
void draw_planet()
{
  if( planet->y > (Sint32)screen_height() )
    create_planet();

  draw_sprite( planet );
  sprite_down( planet );
}
	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 );
	}
Exemple #15
0
int main() {
	setup_screen();

	draw_paddles();

	draw_string(0, screen_height( ) - 1, "Press any key to finish...");
	wait_char();
	cleanup_screen();
	
	return 0;
}
Exemple #16
0
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;
}
Exemple #17
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);
	}
Exemple #18
0
void CollisionBonuses(Game * game) {
	// Collision with Sheild Bonus Drop.
	if (game->bonus_sheild->is_visible && round(game->bonus_sheild->x) >= game->player_spaceship->x && round(game->bonus_sheild->x) <= (game->player_spaceship->x + game->player_spaceship->width - 1) && round(game->bonus_sheild->y) == game->player_spaceship->y) {
		game->player_sheild->is_visible = true;
		game->bonus_sheild->is_visible = false;
	}

	// Collision with Missile Bonus Drop.
	if (game->bonus_missiles->is_visible && round(game->bonus_missiles->x) >= game->player_spaceship->x && round(game->bonus_missiles->x) <= (game->player_spaceship->x + game->player_spaceship->width - 1) && round(game->bonus_missiles->y) == game->player_spaceship->y) {
		game->bonusMissiles += 10;
		game->bonus_missiles->is_visible = false;
	}

	// Collision with Bottom of Screen.
	if (game->bonus_sheild->is_visible && game->bonus_sheild->y > screen_height() - 4) {
		game->bonus_sheild->is_visible = false;
	}
	if (game->bonus_missiles->is_visible && game->bonus_missiles->y > screen_height() - 4) {
		game->bonus_missiles->is_visible = false;
	}
}
inline void location_tracker::update() {
    GLdouble model[16], proj[16];
    GLint view[4];

    glGetDoublev(GL_MODELVIEW_MATRIX, model);
    glGetDoublev(GL_PROJECTION_MATRIX, proj);
    glGetIntegerv(GL_VIEWPORT, view);
    
    /* top left */
    box_[0] = static_cast<GLfloat>(screen_width());
    box_[1] = static_cast<GLfloat>(screen_height());
    /* bottom right */
    box_[2] = 0.0;
    box_[3] = 0.0;
    
    for(std::vector<boost::shared_array<GLfloat> >::iterator it = vertices_.begin();
        it != vertices_.end(); ++it) {
        GLdouble v[3];
        gluProject((*it)[0], (*it)[1], (*it)[2],
                   model, proj, view, v, v+1, v+2);

        if(v[0] < box_[0]) {
            box_[0] = v[0];
        }
        if(v[1] < box_[1]) {
            box_[1] = v[1];
        }
        if(v[0] > box_[2]) {
            box_[2] = v[0];
        }
        if(v[1] > box_[3]) {
            box_[3] = v[1];
        }
    }
    
    /* screen is "upside down" */
    GLfloat tmp = box_[1];
    box_[1] = screen_height() - box_[3];
    box_[3] = screen_height() - tmp;
}
Exemple #20
0
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);
	}
}
Exemple #21
0
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());
    }
}
Exemple #22
0
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();
}
Exemple #23
0
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;
	}
}
Exemple #24
0
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();
}
Exemple #25
0
void draw_ellipse_p( double x0, double y0, double xr, double yr, double p, char ch )
{
	if ( xr > 0 && yr > 0 && p > 0 )
	{
		for ( int i = 0; i < screen_width(); i++ )
		{
			for ( int j = 0; j < screen_height(); j++ )
			{
				double x = ( i - x0 ) / xr;
				double y = ( j - y0 ) / yr;
				double inEllipse = p_norm( x, y, p );
			
				if ( inEllipse <= 1 )
				{
					draw_char( i, j, ch );
				}
			}
		}
	}
}
Exemple #26
0
void GameStats(Game * game) {
	// Draw my Name and Student Number.
	draw_line(0, screen_height() - 3, screen_width() - 1, screen_height() - 3, '_');
	draw_string(1, screen_height() - 2, "Tylor Stewart (N9013555)");

	// Draw the current Score of the Player.
	draw_string(screen_width() - 23, screen_height() - 2, "Score = ");
	draw_int(screen_width() - 15, screen_height() - 2, game->player_score);

	// Draw the current Lives of the Player.
	draw_string(screen_width() - 10, screen_height() - 2, "Lives = ");
	draw_int(screen_width() - 2, screen_height() - 2, game->player_lives);

	// Draw the current Level of the Game the Player is on.
	int levelX = screen_width() / 2;
	int levelY = screen_height() - 1;
	if (game->game_level == 1) {
		char levelName[] = "Level 1: Basic";
		levelX -= strlen(levelName) / 2;
		draw_string(levelX, levelY, levelName);
	} else if (game->game_level == 2) {
		char levelName[] = "Level 2: Harmonic";
		levelX -= strlen(levelName) / 2;
		draw_string(levelX, levelY, levelName);
	} else if (game->game_level == 3) {
		char levelName[] = "Level 3: Falling";
		levelX -= strlen(levelName) / 2;
		draw_string(levelX, levelY, levelName);
	} else if (game->game_level == 4) {
		char levelName[] = "Level 4: Drunken";
		levelX -= strlen(levelName) / 2;
		draw_string(levelX, levelY, levelName);
	} else if (game->game_level == 5) {
		char levelName[] = "Level 5: Aggressive";
		levelX -= strlen(levelName) / 2;
		draw_string(levelX, levelY, levelName);
	}
}
Exemple #27
0
void demo() {
	const int N = 5;
	const double X_MAX = screen_width();
	const double Y_MAX = screen_height();

	double p[] = {0.5, 1, 1.5, 2, 3};
	
	for (int i = 0; i < N; i++) {
		clear_screen();
		double x0 = X_MAX / 2;
		double y0 = Y_MAX / 2;
		double xr = X_MAX / 3;
		double yr = Y_MAX / 3;
		
		draw_ellipse_p(x0, y0, xr, yr, p[i], '*');
		draw_string(0, 0, "p = ");
		draw_double(4, 0, p[i]);
		show_screen();
		timer_pause(5000);
	}
}
Exemple #28
0
int init_game(struct Game* game)
{
    // clear out the log file
    FILE *logfile = fopen("log.txt", "w");
    fprintf(logfile, "%c", '\0');
    fclose(logfile);

    // malloc the player
    malloc_player(game);

    // malloc the world
    malloc_world(game);

    //malloc the camera
    malloc_camera(game->world);
    camera_set_size(game->world->camera, screen_width(stdscr), screen_height(stdscr));

    // load the game
    load_game(game);

    // set running to true
    game->running = true;
}
Exemple #29
0
void pop_clip() {
	const bool was_enabled_clip = glIsEnabled(GL_SCISSOR_TEST);
	bool should_enable_clip = false;
	boost::shared_array<GLint> box;

	if(!clip_rectangles.empty()) {
		box = *clip_rectangles.rbegin();
		clip_rectangles.pop_back();

		if(box[0] != 0 || box[1] != 0 || box[2] != screen_width() || box[3] != screen_height()) {
			should_enable_clip = true;
		}
	}

	if(should_enable_clip) {
		if(!was_enabled_clip) {
			glEnable(GL_SCISSOR_TEST);
		}
		glScissor(box[0], box[1], box[2], box[3]);
	} else if(was_enabled_clip) {
		glDisable(GL_SCISSOR_TEST);
	}
}
Exemple #30
0
void CollisionBombs(Game * game) {
	for (int i = 0; i < 4; i++) {
		// Bombs collision with Spaceship.
		if (game->enemy_bombs[i]->is_visible && round(game->enemy_bombs[i]->x) >= game->player_spaceship->x && round(game->enemy_bombs[i]->x) <= (game->player_spaceship->x + game->player_spaceship->width - 1) && round(game->enemy_bombs[i]->y) == game->player_spaceship->y) {
			game->enemy_bombs[i]->is_visible = false;
			game->enemy_alive -= 1;
			game->player_lives -= 1;
			RespawnPlayer(game);
		}

		// Bombs collision with Bottom of Screen.
		if (game->enemy_bombs[i]->is_visible && game->enemy_bombs[i]->y > screen_height() - 4) {
			game->enemy_bombs[i]->is_visible = false;
			game->enemy_alive -= 1;
		}

		// Bombs collision with Player Sheild.
		if (game->enemy_bombs[i]->is_visible && game->player_sheild->is_visible && round(game->enemy_bombs[i]->x) >= game->player_sheild->x && round(game->enemy_bombs[i]->x) <= (game->player_sheild->x + game->player_sheild->width - 1) && round(game->enemy_bombs[i]->y) == game->player_sheild->y) {
			game->player_sheild->is_visible = false;
			game->enemy_bombs[i]->is_visible = false;
			game->enemy_alive -= 1;
		}
	}
}