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

📄 graphics.cpp

📁 After decades of war one company, who had gained powerful supplying both sides with weaponary, steps
💻 CPP
字号:
/*Copyright (C) 2003 Parallel RealitiesThis program is free software; you can redistribute it and/ormodify it under the terms of the GNU General Public Licenseas published by the Free Software Foundation; either version 2of the License, or (at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.*/#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 movesthem 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 + -