Beispiel #1
0
Sprite
Resource::load_thumb_sprite(const std::string& name)
{
  Pathname thumb_path("thumbnails/" + name + ".png", Pathname::DATA_PATH);
  if (thumb_path.exist())
  {
    log_info("Loading thumb from: %1%", thumb_path.str());
    return Sprite(thumb_path);
  }
  else
  {
    Surface surface = load_surface(name);
    if (!surface)
    {
      return Sprite();
    }
    else
    {
      Size thumb_size;
      if (surface.get_width() <= 48)
        thumb_size.width = surface.get_width();
      else
        thumb_size.width = 48;

      if (surface.get_height() <= 48)
        thumb_size.height = surface.get_height();
      else
        thumb_size.height = 48;

      Sprite sprite(surface.scale(thumb_size.width, thumb_size.height));
      sprite.set_hotspot(origin_top_left, (48 - sprite.get_width())/2, (48 - sprite.get_height())/2);
      return sprite;
    }
  }
}
Beispiel #2
0
bool view::ChatView::initializeCloseButton() {
	closeButton = load_surface("../Images/closeButton.png");
	if (closeButton==NULL) {
		return false;
	}
	closeButtonRect.x = static_cast<Sint16>(textbox.getOffsetX()+textbox.getWidth()+6);
	closeButtonRect.y = static_cast<Sint16>(textbox.getOffsetY()+textbox.getHeight()-closeButton->h-5);
	closeButtonRect.w = static_cast<Uint16>(closeButton->w);
	closeButtonRect.h = static_cast<Uint16>(closeButton->h);
	return true;
}
Beispiel #3
0
static void set_window_icon(const char *filename)
{
#if !defined(__APPLE__)
    SDL_Surface *icon;

    if ((icon = load_surface(filename)))
    {
        SDL_SetWindowIcon(window, icon);
        free(icon->pixels);
        SDL_FreeSurface(icon);
    }
#endif
    return;
}
Beispiel #4
0
GLuint graphics_t::alloc_texture(fs_file_t& file) {
	pimpl_t::textures_t::const_iterator i = pimpl->textures.find(file.path());
	if(i != pimpl->textures.end())
		return i->second;
	SDL_Surface* surface = load_surface(file);
	GLuint texture = 0;
	try {
		texture = graphics()->alloc_texture();
		load_texture_2D(texture,surface);
		std::cout << "(loaded texture "<<file<<" "<<surface->w<<'x'<<surface->h<<")" << std::endl;
		SDL_FreeSurface(surface); surface = NULL;
		pimpl->textures[file.path()] = texture;
		return texture;
	} catch(...) {
		std::cerr << "Error loading: "<<file<<std::endl;
		SDL_FreeSurface(surface);
		glDeleteTextures(1,&texture);
		throw;
	}
	return texture;
}
Beispiel #5
0
int
main(int argc, char *argv[])
{
	SDL_Surface *screen, *sprite, *door;
	SDL_Rect rcSprite, rcWall, rcFloor, rcStatus;
	TTF_Font *fntText;
	SDL_Surface *sText;
	SDL_Rect rcText = { 5, 290, 0, 0 };
	SDL_Color clrText = { 192, 192, 192, 0 };
	char debug[100];
	unsigned int colorkey;


	/* Initialize the SDL library: */
	if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0) {
		printf("%s: SDL_Init(): %s\n", argv[0], SDL_GetError());
		exit(EXIT_FAILURE);
	}
	/* Clean up SDL on exit: */
	if (atexit(SDL_Quit) != 0) {
		printf("%s: Cannot register exit function SDL_Quit().\n", argv[0]);
		exit(EXIT_FAILURE);
	}

	/* Initialize SDL TTF engine: */
	if (TTF_Init() != 0) {
		printf("%s: TTF_Init(): %s\n", argv[0], TTF_GetError());
		exit(EXIT_FAILURE);
	}
	/* Clean up TTF on exit: */
	if (atexit(TTF_Quit) != 0) {
		printf("%s: Cannot register exit function TTF_Quit().\n", argv[0]);
		exit(EXIT_FAILURE);
	}

	/* Set up video: */
	screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0);
	if (screen == NULL) {
		printf("%s: SDL_SetVideoMode: %s\n", argv[0], SDL_GetError());
		exit(EXIT_FAILURE);
	}

	/* Set the title bar: */
	SDL_WM_SetCaption("Open Paradise Cafe", NULL);

	/* set keyboard repeat */
	SDL_EnableKeyRepeat(70, 70);

	/* load sprite damatta */
	sprite = load_surface("sprites.bmp");

	/* load door */
	door = load_surface("porta.bmp");

	/* setup sprite colorkey and turn on RLE */
	colorkey = SDL_MapRGB(screen->format, 255, 0, 255);
	SDL_SetColorKey(sprite, SDL_SRCCOLORKEY | SDL_RLEACCEL, colorkey);
	SDL_SetColorKey(door, SDL_SRCCOLORKEY | SDL_RLEACCEL, colorkey);

	/* posicao inicial do damatta */
	rcSprite.x = 150;
	rcSprite.y = 150;

	/* define o tamanho e o *frame* do boneco */
	rcSrc.x = 0;
	rcSrc.y = 0;
	rcSrc.w = SPRITE_WIDTH;
	rcSrc.h = SPRITE_HEIGHT;
	/*printf("sprite w=%d %d h=%d %d\n", sprite->w, SPRITE_WIDTH, sprite->h, SPRITE_HEIGHT);*/

	/* define o tamanho das portas */
	rcSrcDoor.x = 0;
	rcSrcDoor.y = 0;
	rcSrcDoor.w = 56; /* so a primeira frame */
	rcSrcDoor.h = door->h;
	/*printf("door w=%d h=%d\n", door->w, door->h);*/

	/* posicao inicial da porta */
	rcDoor.x = 350;
	rcDoor.y = 126;

	/* Wall: */
	rcWall.x = 0;
	rcWall.y = 0;
	rcWall.w = SCREEN_WIDTH;
	rcWall.h = SCREEN_HEIGHT;

	/* Floor:  */
	rcFloor.x = 0;
	rcFloor.y = 262;
	rcFloor.w = SCREEN_WIDTH;
	rcFloor.h = 24;

	/* Status: */
	rcStatus.x = 0;
	rcStatus.y = 262 + 24;
	rcStatus.w = SCREEN_WIDTH;
	rcStatus.h = SCREEN_HEIGHT - 262 - 24;

	/* load a font and give it a point-size */
	fntText = TTF_OpenFont("arial.ttf", 12);
	if (fntText == NULL) {
		printf("TTF_OpenFont: %s\n", TTF_GetError());
		exit(EXIT_FAILURE);
	}

	gameover = 0; /* usada pra sair */

	jewish_param.lol = SDLK_RIGHT;
	jewish_timer = SDL_AddTimer(100, jewish_timer_callback, &jewish_param);

	while (!gameover) {
		SDL_Event event;
		SDL_WaitEvent(NULL); /* para nao consumir 100% do cpu */

		/* /!\ ACHTUNG: DOOR /!\ */
		if (rcSprite.x + SPRITE_WIDTH == rcDoor.x && door_closed) {
			door_closed = 0;
			door_param.frame = 1;
			door_param.timer = SDL_AddTimer(250, door_timer_callback, &door_param);

			SDL_RemoveTimer(jewish_timer);
			jewish_timer = NULL;
			
			event.type = SDL_USEREVENT;
			event.user.code = USEREVENT_DOOR;
			event.user.data1 = 0;
			event.user.data2 = 0;
			SDL_PushEvent(&event);
		}

		/* Ao sair da porta a porta tem que se fechar */
		if (rcSprite.x == rcDoor.x + 50) {
			printf("dead by dawn");
		}

		/* look for an event */
		if (SDL_PollEvent(&event))
			HandleEvent(event);

		/* Draw the wall (red): */
		SDL_FillRect(screen, &rcWall, SDL_MapRGB(screen->format, 0xc8, 0x41, 0x34));

		/* Draw the floor (purple f*g): */
		SDL_FillRect(screen, &rcFloor, SDL_MapRGB(screen->format, 0xc6, 0x0, 0xc6));

		/* Draw the status line (blue): */
		SDL_FillRect(screen, &rcStatus, SDL_MapRGB(screen->format, 0x0, 0x0, 0xc6));

		/* Draw the door: */
		SDL_BlitSurface(door, &rcSrcDoor, screen, &rcDoor);

		/* Draw the sprite: */
		SDL_BlitSurface(sprite, &rcSrc, screen, &rcSprite);

		/* render text to an SDL_Surface */
		sprintf(debug, "src(x=%d y=%d) door(x=%d y=%d w=%d h=%d) srcdoor(x=%d y=%d w=%d h=%d)",
			rcSrc.x, rcSrc.y, rcDoor.x, rcDoor.y, rcDoor.w, rcDoor.h, rcSrcDoor.x, rcSrcDoor.y, rcSrcDoor.w, rcSrcDoor.h);
		sText = TTF_RenderText_Solid(fntText, debug, clrText);
		SDL_BlitSurface(sText, NULL, screen, &rcText);

		/* Update the screen: */
		SDL_UpdateRect(screen, 0, 0, 0, 0);
	}

	/* Clean up: */
	SDL_FreeSurface(sprite);
	SDL_FreeSurface(door);

	return 0;
}
Beispiel #6
0
int main ( int argc, char** argv )
{
	std::cout << "Starting\n";
    initalize();

    //TODO add resource load error handling
    add_surface("spaceb", load_surface("gray_space.png",1)   );
    add_surface("spacem", load_surface("gray_space.png",1)   );
    add_surface("spacef", load_surface("gray_space.png",1)   );

    for(int i=-2; i < 20+2; i++)
        meta::objects.push_back(new psrect_static(200*i, 200, 200, 200));
//meta::objects.push_back(new psrect_static(320, 20, 320, 20));

//meta::objects.push_back(new psrect_static(0, -400,1, 1000));
//meta::objects.push_back(new psrect_static(1000, -400, 1, 1000));

    meta::objects.push_back(new rocket(2000,-100, 50,70));

    //load_map("test.json");

    float32 timeStep = 1.0f / 30.0f;
    int32 velocityIterations = 6;
    int32 positionIterations = 2;

    FPSmanager manager;
    SDL_initFramerate(&manager);
    SDL_setFramerate(&manager, 30);

    // program main loop
    bool done = false;
    while (!done)
    {
        SDL_framerateDelay(&manager);

        // message processing loop
        SDL_Event event;
        while (SDL_PollEvent(&event))
        {
            // check for messages
            switch (event.type)
            {
                // exit if the window is closed
            case SDL_QUIT:
                done = true;
                break;

                // check for keypresses
            case SDL_KEYDOWN:
                // exit if ESCAPE is pressed
                if (event.key.keysym.sym == SDLK_ESCAPE)
                    done = true;
                break;


            } // end switch
        } // end of message processing

        // DRAWING STARTS HERE
        // clear screen
        //SDL_FillRect(meta::screen, 0, SDL_MapRGB(meta::screen->format, 0, 0, 0 ));
        SDL_FillRect(meta::screen, 0, SDL_MapRGB(meta::screen->format, meta::background_red , meta::background_green, meta::background_blue ));

        draw_background();

        // Instruct the world to perform a single step of simulation.
        // It is generally best to keep the time step and iterations fixed.
        meta::world.Step(timeStep, velocityIterations, positionIterations);

        update_objects();
        meta::world.DrawDebugData();

        // DRAWING ENDS HERE

        // finally, update the screen :)
        SDL_Flip(meta::screen);
    } // end main loop

    // all is well ;)
    printf("Exited cleanly\n");
    return 0;
}
Beispiel #7
0
Surface
Resource::load_surface(const std::string& res_name)
{
  return load_surface(ResDescriptor(res_name));
}