⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 graphics.cpp

📁 打飞机的过关游戏(linux)
💻 CPP
字号:
#include "graphics.h"

SDL_Surface *loadImage(char *filename)
{
	 SDL_Surface *image, *newImage;

	 #if USEPACK
	 unpack(filename, PAK_IMG);
	 image = IMG_Load_RW(engine.sdlrw, 1);
	 #else
	 image = IMG_Load(filename);
	 #endif

	 if (image == NULL) {
		  printf("Couldn't load %s: %s\n", filename, SDL_GetError());
		  showErrorAndExit(0, filename);
	 }

	 newImage = SDL_DisplayFormat(image);
	 if ( newImage ) {
	 	SDL_FreeSurface(image);
	 } else {
		 // This happens when we are loading the window icon image
		 newImage = image;
	 }

	 return graphics.setTransparent(newImage);
}

/*
Simply draws the stars in their positions on screen and moves
them around. They are wrapped around using the wrapFloat()
function, as defined above, and putpixel as defined in graphics.cpp
*/
void doStarfield()
{
	/* Lock the screen for direct access to the pixels */
	if (SDL_MUSTLOCK(graphics.screen))
	{
		if (SDL_LockSurface(graphics.screen) < 0 )
		{
			showErrorAndExit(2, "");
		 }
	}

	int color = 0;

	SDL_Rect r;

	for (int i = 0 ; i < 200 ; i++)
	{
		if (star[i].speed == 3)
			color = graphics.white;
		else if (star[i].speed == 2)
			color = graphics.lightGrey;
		else if (star[i].speed == 1)
			color = graphics.darkGrey;

		Math::wrapFloat(&(star[i].x += (engine.ssx * star[i].speed)), 0, 799);
		Math::wrapFloat(&(star[i].y += (engine.ssy * star[i].speed)), 0, 599);

		graphics.putpixel(graphics.screen, (int)star[i].x, (int)star[i].y, color);
		r.x = (int)star[i].x;
		r.y = (int)star[i].y;
		r.w = 1;
		r.h = 1;

		graphics.addBuffer(r.x, r.y, r.w, r.h);
	}

	if (SDL_MUSTLOCK(graphics.screen))
	{
		SDL_UnlockSurface(graphics.screen);
	}
}

int isOnScreen(int x, int y, int w, int h)
{
	if ((x + w > 0) && (x < 800) && (y + h > 0) && (y < 600))
		return 1;
		
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -