![]() |
|
|
Tutorial 07 - Thousand of Hares 一千个兔子 This tutorial shows HGE rendering power and usage of various blending modes. 这个指南展示了HGE描绘的威力和各种各样混合模式的使用。 Creation of sprites 精灵的创建 We will skip all the technical stuff now and dive right into the action. First we should create and initialize a couple of sprites, used for "game objects" and background rendering. Note how the background sprite is created from a tiny 64x64 tile and tinted at the bottom: 现在我们将跳过所有的技术资料,完全潜入到行为动作里面去。首先我们将创建和初始化一对精灵,用作游戏对象和背景描绘。注意,怎样从一个小的64*64的方块来创建底部带有颜色的游戏背景精灵 HTEXTURE tex, bgtex; hgeSprite *spr, *bgspr; tex=hge->Texture_Load("zazaka.png"); spr=new hgeSprite(tex,0,0,64,64); spr->SetHotSpot(32,32); bgtex=hge->Texture_Load("bg2.png"); bgspr=new hgeSprite(bgtex,0,0,800,600); bgspr->SetBlendMode(BLEND_COLORADD | BLEND_ALPHABLEND); bgspr->SetColor(0xFF000000,0); bgspr->SetColor(0xFF000000,1); bgspr->SetColor(0xFF000040,2); bgspr->SetColor(0xFF000040,3); Initializing game objects array初始化游戏对象数组 Now we should create an array, holding properties of our "game objects" and fill it with random values: 现在我们将创建一个数组,处理我们的游戏对象的属性,使用随机数填充他。 #define MAX_OBJECTS 2000 struct sprObject { float x,y; float dx,dy; float scale,rot; float dscale,drot; DWORD color; }; sprObject* pObjects; int nObjects; pObjects=new sprObject[MAX_OBJECTS]; nObjects=1000; for(i=0; i<MAX_OBJECTS; i++) { pObjects[i].x=hge->Random_Float(0,SCREEN_WIDTH); pObjects[i].y=hge->Random_Float(0,SCREEN_HEIGHT); pObjects[i].dx=hge->Random_Float(-200,200); pObjects[i].dy=hge->Random_Float(-200,200); pObjects[i].scale=hge->Random_Float(0.5f,2.0f); pObjects[i].dscale=hge->Random_Float(-1.0f,1.0f); pObjects[i].rot=hge->Random_Float(0,M_PI*2); pObjects[i].drot=hge->Random_Float(-1.0f,1.0f); } Changing blending mode 改变混合模式 SetBlend function takes an integer from range 0..4 and adjusts blending mode of the game object sprite and colors within game objects array: SetBlend 函数或的一个从0到4范围内的整数,调整游戏对象精灵的混合模式和游戏对象数组的颜色: void SetBlend(int blend) { static int sprBlend[5]= { BLEND_COLORMUL | BLEND_ALPHABLEND | BLEND_NOZWRITE, BLEND_COLORADD | BLEND_ALPHABLEND | BLEND_NOZWRITE, BLEND_COLORMUL | BLEND_ALPHABLEND | BLEND_NOZWRITE, BLEND_COLORMUL | BLEND_ALPHAADD | BLEND_NOZWRITE, BLEND_COLORMUL | BLEND_ALPHABLEND | BLEND_NOZWRITE }; static DWORD sprColors[5][5]= { {0xFFFFFFFF, 0xFFFFE080, 0xFF80A0FF, 0xFFA0FF80, 0xFFFF80A0}, {0xFF000000, 0xFF303000, 0xFF000060, 0xFF006000, 0xFF600000}, {0x80FFFFFF, 0x80FFE080, 0x8080A0FF, 0x80A0FF80, 0x80FF80A0}, {0x80FFFFFF, 0x80FFE080, 0x8080A0FF, 0x80A0FF80, 0x80FF80A0}, {0x40202020, 0x40302010, 0x40102030, 0x40203010, 0x40102030} }; if(blend>4) blend=0; nBlend=blend; spr->SetBlendMode(sprBlend[blend]); for(int i=0;i<MAX_OBJECTS;i++) { pObjects[i].color=sprColors[blend][hge->Random_Int(0,4)]; } 上一页12 下一页
|