Exemplo n.º 1
0
// draw_menu - draws menu centered on surface
void draw_menu(struct Menu* menu, SDL_Surface* destination, int oldx, int oldy) {
    struct MenuElement* element;
    int i;
    int x = 0;
    int y = 0;
    int w = 200;
    int h = menu->length*25;
    SDL_Surface* menusurf = create_surface(w, h);
    SDL_Surface* menutextsurf;
    for (i = 0; i < menu->length; i++) {
        element = &menu->elements[i];
        if (element->active) { // draw active element red
            menutextsurf = draw_text(0, 0, NULL, element->text, 255, 0, 0);
            draw_surface(x, y,
                         menutextsurf,
                         menusurf, NULL);
            SDL_FreeSurface(menutextsurf);
        }
        else {
            menutextsurf = draw_text(0, 0, NULL, element->text, 255, 255, 255);
            draw_surface(x, y, //draw inactive element white
                         menutextsurf,
                         menusurf, NULL);
            SDL_FreeSurface(menutextsurf);
        }
        y += 25;
    }
    draw_surface_centered(menusurf, destination);
    SDL_FreeSurface(menusurf);
}
Exemplo n.º 2
0
int main(int argc, char** argv){
    int i;
    int j;
    int* score = (int*) malloc(sizeof(int));
    if (SDL_Init(SDL_INIT_EVERYTHING) == -1){
        printf("SDL_Init: %s\n", SDL_GetError());
        return 1;
    }
    // Unicode support for hiscore table
    SDL_EnableUNICODE(1);
    if(TTF_Init()==-1) {
        printf("TTF_Init: %s\n", TTF_GetError());
        return 1;
    }
    SDL_Surface* screen = SDL_SetVideoMode(608, 640, 32, SDL_SWSURFACE);
    SDL_WM_SetCaption("martet", "martet");
    SDL_Surface* board = create_surface(320, 640);
    SDL_Surface* border = load_image("../data/tetborder.png");
    draw_surface(321, 0, border, screen, NULL);
    draw_text(390, 35, screen, "Next tetromino:", 255, 255, 255);
    draw_text(330, 200, screen, "Score: ", 255, 255, 255);
    // create menu
    struct Menu* menu = menu_create();
    menu_addelement(menu, "Start Game");
    menu_addelement(menu, "Quit");
    menu->active_element = &menu->elements[0];
    menu->active_element->active = 1;
    bool running = true;
    while (running){
        if (menu_martet(screen, board, menu, score) == KEYEVENT_EXIT)
            break;
        // fill the board with blocks on game over
        for (i = 0; i < BOARD_HEIGHT; i++) {
            char* line = get_board_line(i);
            for (j = 0; j < BOARD_WIDTH; j++) {
                line[j] = rand() % 7 + '0';
            }
            draw_board(board);
            draw_surface(0, 0, board, screen, NULL);
            SDL_Flip(screen);
            SDL_Delay(50);
        }
        manage_hiscores(screen, board, score);
        board_delete();
    }
    menu_destroy(menu);
    SDL_FreeSurface(border);
    SDL_FreeSurface(board);
    free(score);
    SDL_Quit();
    return 0;
}
Exemplo n.º 3
0
void intro(void){
  int i, sound = 0;
  time_t begin, now;
  float speed[6];
  circle *planet[6], *moon1;
  camera *cam = new_camera(0.0, 0.0, 800.0, 800.0);
  surface *dark_weaver = new_image("dark_weaver.png");
  surface *credits = new_image("credits.png");
  for(i = 0; i < 6; i ++){
    speed[i] = ((rand() % 20) + 10) / 1000.0;
    planet[i] = new_circle(450.0 + i*50, 450.0 + i*50, (rand() % 20) + 10.0);
  }
  moon1 = new_circle(planet[2] -> x + 40.0, planet[2] -> y + 40.0, 10.0);
  limit_camera(cam, window_width / 2 - 400, window_height / 2 - 400,
	       800, 800);
  begin = time(NULL);
  initialize_star();
  for(;;){
    now = time(NULL);
    if(now - begin > 3){
      draw_surface(dark_weaver, window, 
		   (window_width - dark_weaver -> width) / 2, 
		   (window_height - dark_weaver -> height) / 2);
      draw_surface(credits, window, (window_width - credits -> width) / 2, 0);
      if(sound == 0){
	sound = 1;
	play_sound("weaver.ogg");
      }
      if(now - begin > 5)
	break;
    }
    for(i = 0; i < 6; i ++)
      erase_fullcircle(cam, planet[i]);
    erase_fullcircle(cam, moon1);
    for(i = 0; i < 6; i ++)
      rotate_circle(planet[i], 400.0, 400.0, speed[i]);
    rotate_circle(moon1, planet[2] -> x, planet[2] -> y, speed[2]*10.0);
    film_fullcircle(cam, planet[0], 0x220000);
    film_fullcircle(cam, planet[1], 0x002200);
    film_fullcircle(cam, planet[2], 0x000022);
    film_fullcircle(cam, planet[3], 0x002222);
    film_fullcircle(cam, planet[4], 0x220022);
    film_fullcircle(cam, planet[5], 0x222222);
    film_fullcircle(cam, moon1, 0x444400);
    update_star();
    weaver_rest(10000000);
  }
  destroy_surface(dark_weaver);
  destroy_surface(credits);
  destroy_star();
}
Exemplo n.º 4
0
static void Display(void)
{
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    draw_surface( state );
    glFlush();
    if (doubleBuffer) glutSwapBuffers();
}
Exemplo n.º 5
0
/**
 * @param surface_src zdroj
 * @param surface_dst cíl
 */
void draw_center_surface(SDL_Surface* surface_src, SDL_Surface* surface_dst){
	if(surface_src && surface_dst){
		draw_surface(
			(surface_dst->w - surface_src->w)/2,
			(surface_dst->h - surface_src->h)/2,
			surface_src, surface_dst);
	}
}
Exemplo n.º 6
0
void draw_gametype(unsigned type, int x, int y){
  surface *select = new_image("select.png");
  surface *cpu = new_image("cpu.png");
  surface *human = new_image("human.png");

  draw_surface(select, window, x, y);
  if(type % 2)
    draw_surface(human, window, x + select -> width / 2 - cpu -> width, y);
  else
    draw_surface(cpu, window, x + select -> width / 2 - cpu -> width, y);
  if((type / 2) % 2)
    draw_surface(human, window, x + select -> width / 2, y);
  else
    draw_surface(cpu, window, x + select -> width / 2, y);
  destroy_surface(human);
  destroy_surface(cpu);
  destroy_surface(select);
}
Exemplo n.º 7
0
void move_surfaces() {
    for (i = 0; i < 7; i++) {
        if (surface_start_x[i] < 96)
            draw_surface(surface_start_x[i], surface_length_x[i], surface_y[i], COLOR_BLACK24);
        if (surface_start_x[i] == 0) {
            surface_start_x[i] = surface_start_x[i] + 1;
            surface_length_x[i] = surface_length_x[i] - 1;
        }
        surface_start_x[i] = surface_start_x[i] - 1;
        if (surface_start_x[i] < 96)
            draw_surface(surface_start_x[i], surface_length_x[i], surface_y[i], surface_color[i]);
        if (surface_length_x[i] <= 0) {
            surface_length_x[i] = (rand()%10)+(3*(7-i));
            surface_start_x[i] = (rand()%30)+96;
            int rand_color = rand()%7;
            surface_color[i] = colors[rand_color];
        }
    }
}
Exemplo n.º 8
0
static void draw1()
{
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    glPushMatrix();
    glRotatef( yrot, 0.0f, 1.0f, 0.0f );
    glRotatef( xrot, 1.0f, 0.0f, 0.0f );

    draw_surface();

    glPopMatrix();

    glFlush();
}
Exemplo n.º 9
0
void copyleft(void){
  int width, height;
  surface *c = new_image("copyleft.png");
  width = c -> width;
  height = c -> height;
  fill_screen(BLACK);
  draw_surface(c, window, (window_width - width)/2, 
	       (window_height - height)/2);
  weaver_rest(1);
  sleep(1);
  destroy_surface(c);
  return;
}
Exemplo n.º 10
0
int main(int argc, char **argv){
  unsigned type = PLR_X_CPU;
  int key_pressed = 0;
  awake_the_weaver(); // Initializing Weaver API
  hide_cursor();
  copyleft();
  intro();
  surface *title = new_image("title.png");
  for(;;){
    int esc_pressed = 0;
    int x = (window_width - title -> width) / 2; 
    int y = (window_height - title -> height) / 2;
    fill_screen(BLACK); 
    draw_surface(title, window, x, y);
    draw_gametype(type % 4, x + 120, y + 60);
    key_pressed = 0;
    for(;;){
      get_input();
      if(keyboard[ESC]){
	esc_pressed = 1;
	break;
      }
      if(keyboard[ENTER]){
	fill_screen(BLACK);
	flush();
	game(type % 4);
	break;
      }
      else if(keyboard[LEFT]){
	if(!key_pressed){
	  type --;
	  draw_gametype(type % 4, x + 120, y + 60);
	}
      }
      else if(keyboard[RIGHT]){
	if(!key_pressed){
	  type ++;
	  draw_gametype(type % 4, x + 120, y + 60);
	}
      }
      key_pressed = keyboard[ANY];
      weaver_rest(10000000);
    }
    if(esc_pressed)
      break;
  }
  destroy_surface(title);
  may_the_weaver_sleep();
  return 0;
}
Exemplo n.º 11
0
void display()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear Screen And Depth Buffer
	glLoadIdentity();									// Reset The Current Modelview Matrix

	glMatrixMode(GL_MODELVIEW);

	setUpCurve(4);

	Matrix4 cam = objCamera.c;
	cam.transpose();
	glLoadMatrixd(cam.getPointer());

	glColor3f(1, 1, 1);
	//Draw_Skybox(0, 0, 0, 100, 100, 100);

	Matrix4 ct;
	ct.makeTranslate(-1, 0, 0);
	cam = objCamera.c;
	cam = ct * cam;
	cam.transpose();
	glLoadMatrixd(cam.getPointer());
	glColor3f(1, 0, 0);
	//glutSolidCube(1);

	if (p == 1)
		drawPath();
	angle += .01;

	//draw();

	//Draw_Bezier(4.75, 4.75);
	draw_surface(4.75,4.75);

	glFlush();
	glutSwapBuffers();
}
Exemplo n.º 12
0
static void draw_surface( unsigned int with_state )
{
   GLint i, j;
   
   if (with_state & DISPLAYLIST) {
      if ((with_state & (RENDER_STYLE_MASK|PRIMITIVE_MASK|MATERIAL_MASK)) != 
	  dlist_state) {
	 /* 
	  */
	 fprintf(stderr, "rebuilding displaylist\n");

	 if (dlist_state)
	    glDeleteLists( surf1, 1 );

	 dlist_state = with_state & (RENDER_STYLE_MASK|PRIMITIVE_MASK|
				     MATERIAL_MASK);
	 surf1 = glGenLists(1);
	 glNewList(surf1, GL_COMPILE);
	 draw_surface( dlist_state );
	 glEndList();
      }

      glCallList( surf1 );
      return;
   }

   switch (with_state & (RENDER_STYLE_MASK|PRIMITIVE_MASK)) {
#ifdef GL_EXT_vertex_array

   case (DRAW_ELTS|TRIANGLES):
      if (with_state & MATERIALS) {
	 for (j = i = 0 ; i < num_tri_verts ; i += 600, j++) {
	    GLuint nr = MIN(num_tri_verts-i, 600);
	    glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, col[j]);
	    glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, col[j]);
	    glDrawElements( GL_TRIANGLES, nr, GL_UNSIGNED_INT, tri_indices+i );
	 }
      } else {
	 glDrawElements( GL_TRIANGLES, num_tri_verts, GL_UNSIGNED_INT,
			 tri_indices );
      }
      break;

   case (DRAW_ARRAYS|TRIANGLES):
      glDrawArraysEXT( GL_TRIANGLES, 0, (numverts-2)*3 );
      break;

   case (ARRAY_ELT|TRIANGLES):
      if (with_state & MATERIALS) {
	 for (j = i = 0 ; i < num_tri_verts ; i += 600, j++) {
	    GLuint nr = MIN(num_tri_verts-i, 600);
	    GLuint k;
	    glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, col[j]);
	    glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, col[j]);
	    glBegin( GL_TRIANGLES );
	    for (k = 0 ; k < nr ; k++)
	       glArrayElement( tri_indices[i+k] );
	    glEnd();
	 }
      } else {
	 glBegin( GL_TRIANGLES );
	 for (i = 0 ; i < num_tri_verts ; i++)
	    glArrayElement( tri_indices[i] );

	 glEnd();
      }
      break;


      /* Uses the original arrays (including duplicate elements):
       */
   case (DRAW_ARRAYS|STRIPS):
      glDrawArraysEXT( GL_TRIANGLE_STRIP, 0, numverts );
      break;
   case (DRAW_ELTS|STRIPS):
      glDrawElements( GL_TRIANGLE_STRIP, numverts,
		      GL_UNSIGNED_INT, strip_indices );
      break;

      /* Uses the original arrays (including duplicate elements):
       */
   case (ARRAY_ELT|STRIPS):
      glBegin( GL_TRIANGLE_STRIP );
      for (i = 0 ; i < numverts ; i++)
	 glArrayElement( i );
      glEnd();
      break;

   case (DRAW_ARRAYS|POINTS):
      glDrawArraysEXT( GL_POINTS, 0, numuniq );
      break;
   case (DRAW_ELTS|POINTS):
      /* can use numuniq with strip_indices as strip_indices[i] == i.
       */
      glDrawElements( GL_POINTS, numuniq, 
		      GL_UNSIGNED_INT, strip_indices );
      break;
   case (ARRAY_ELT|POINTS):
      /* just emit each unique element once:
       */
      glBegin( GL_POINTS );
      for (i = 0 ; i < numuniq ; i++)
	 glArrayElement( i );
      glEnd();
      break;
#endif

   case (GLVERTEX|TRIANGLES):
      if (with_state & MATERIALS) {
	 for (j = i = 0 ; i < num_tri_verts ; i += 600, j++) {
	    GLuint nr = MIN(num_tri_verts-i, 600);
	    GLuint k;
	    glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, col[j]);
	    glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, col[j]);
	    glBegin( GL_TRIANGLES );
	    for (k = 0 ; k < nr ; k++) {
	       glNormal3fv( &compressed_data[tri_indices[i+k]][3] );
	       glVertex3fv( &compressed_data[tri_indices[i+k]][0] );
	    }
	    glEnd();
	 }
      } else {
	 glBegin( GL_TRIANGLES );
	 for (i = 0 ; i < num_tri_verts ; i++) {
	    glNormal3fv( &compressed_data[tri_indices[i]][3] );
	    glVertex3fv( &compressed_data[tri_indices[i]][0] );
	 }
	 glEnd();
      }
      break;

   case (GLVERTEX|POINTS):
      /* Renders all points, but not in strip order...  Shouldn't be a
       * problem, but people may be confused as to why points are so
       * much faster in this demo...  And why cva doesn't help them...
       */
      glBegin( GL_POINTS );
      for ( i = 0 ; i < numuniq ; i++ ) {
         glNormal3fv( &compressed_data[i][3] );
         glVertex3fv( &compressed_data[i][0] );
      }
      glEnd();
      break;

   case (GLVERTEX|STRIPS):
      glBegin( GL_TRIANGLE_STRIP );
      for (i=0;i<numverts;i++) {
         glNormal3fv( &data[i][3] );
         glVertex3fv( &data[i][0] );
      }
      glEnd();
      break;

   default:
      fprintf(stderr, "unimplemented mode %x...\n", 
	      (with_state & (RENDER_STYLE_MASK|PRIMITIVE_MASK)));
      break;
   }
}
Exemplo n.º 13
0
Arquivo: label.c Projeto: Neckara/Gosh
void afficher_label(SDL_Surface* on, struct label* label)
{
	if (label->visible) {
		draw_surface(on, label->surface, label->x, label->y, label->align);
	}
}
Exemplo n.º 14
0
void
OpenGLFramebuffer::draw_surface(const FramebufferSurface& src, const Vector2i& pos)
{
  draw_surface(src, Rect(Vector2i(0, 0), src.get_size()),  pos);
}
Exemplo n.º 15
0
// run_martet: The game loop. Returns final score.
int run_martet(SDL_Surface* screen, SDL_Surface* board) {
    Tetromino* active_tetromino;
    Tetromino* next_tetromino;
    // Create ingame menu
    struct Menu* ingame_menu = menu_create();
    menu_addelement(ingame_menu, "Continue");
    menu_addelement(ingame_menu, "Quit Current Game");
    ingame_menu->active_element = &ingame_menu->elements[0];
    ingame_menu->active_element->active = 1;
    int score = 0;
    srand((unsigned) time(NULL));
    board_create();
    next_tetromino   = tetcreaterand();
    update_status_bar(next_tetromino, screen, score);
    active_tetromino = tetcreaterand();
    active_tetromino->position[0] = 4;
    struct Timer* timer = create_timer();
    timer_change_alarm_interval(timer, GAME_SPEED);
    timer_start(timer);
    bool running = true;
    while (running){
        int event = process_key_events(active_tetromino, tetaction);
        if (event == KEYEVENT_EXIT)
            exit(0);
        else if (event == KEYEVENT_MENU) {
            if (ingame_menu_martet(screen, board, ingame_menu) == 1)
                running = false;
        }
        else if (event == KEYEVENT_PAUSE)
            pause_martet(screen, board);
        if (timer_update(timer)) {
            // If collision and tetromino not deleted
            if ( tetmove('d', active_tetromino) == 0
                && active_tetromino->color != TETROMINO_DELETE) {
                place_tetromino(active_tetromino);
                active_tetromino->color = TETROMINO_DELETE;
            }
            else if ( active_tetromino->color == TETROMINO_DELETE ) {
                free(active_tetromino);
                active_tetromino = next_tetromino;
                next_tetromino   = tetcreaterand();
                if (check_rows(&score)) { // If score has increased.
                    timer_change_alarm_interval(timer,
                                                GAME_SPEED /
                                                sqrt( (double) score/5) + 1);
                }
            }
            if ( next_tetromino == NULL ) // If game over
                break;
            update_status_bar(next_tetromino, screen, score);
        }
        clear_surface(board, NULL);
        draw_board(board);
        draw_tetromino(board, active_tetromino);
        draw_ghost_tetromino(board, active_tetromino);
        draw_surface(0, 0, board, screen, NULL);
        SDL_Flip(screen);
    }
    if (active_tetromino) {
        free(active_tetromino);
    }
    free(next_tetromino);
    free(timer);
    menu_destroy(ingame_menu);
    return score;
}
Exemplo n.º 16
0
/**
 * @param window surface okna pro vykreslení
 * @param x cílová souřadnice pro vykreslení
 * @param y cílová souřadnice pro vykreslení
 */
void Animation::draw(SDL_Surface* window, Uint16 x, Uint16 y) const {
	if(draw_shadow_){
		draw_surface(x, y, shadow_frames_[next_frame_].GetSurface(), window);
	}
	draw_surface(x, y, frames_[next_frame_].GetSurface(), window);
}
Exemplo n.º 17
0
void
DrawingContext::draw_surface(SurfacePtr surface, const Vector& position,
                             int layer)
{
  draw_surface(surface, position, 0.0f, Color(1.0f, 1.0f, 1.0f), Blend(), layer);
}
Exemplo n.º 18
0
void
Canvas::draw_surface(const SurfacePtr& surface, const Vector& position, int layer)
{
  draw_surface(surface, position, 0.0f, Color(1.0f, 1.0f, 1.0f), Blend(), layer);
}