|
|
|
|
|
|
نويسنده |
پيغام |
HGGI در حال رشد
تاريخ عضويت: شنبه 20 خرداد 1391 تعداد ارسالها: 32 محل سكونت: هرجا خدا بخواهد.
4 شنبه 24 خرداد 1391 - 12:25 |
|
|
حواسم نبود . 2010 نصب کنید .
فلسفش اینه که هی بری تو ستاره ها همین . هی مرحله تولید میشه !!!
اینم کد بازی ::
كد: |
#include <iostream>
#include <math.h>
#include <hge.h>
#include <hgesprite.h>
#include <hgefont.h>
#include <hgeparticle.h>
#define PI 3.141592653589
#define TWO_PI 6.283185307179
#define SCREEN_WIDTH 800
#define SCREEN_HEIGHT 600
#define SCREEN_BPP 32
#define FPS 60
#define WINMODE true
#define SCENE_WIDTH 4000
#define SCENE_HEIGHT 3000
#define BLOCK_NUM 1024
#define BLOCK_WIDTH 34
#define BLOCK_HEIGHT 34
#define ENEMY1_NUM 80
#define ENEMY1_MAXMOVE 2
#define ENEMY1_RADIUS 32
#define PLAYER_RADIUS 28
#define PLAYER_SPEED 8
#define ITEM_RADIUS 80
inline float DistanceGet(float x1,float y1,float x2,float y2);
inline bool IsFree(float xx,float yy);
inline void Player_Init();
inline void Player_Update();
inline void Player_Draw();
inline void Block_Create();
inline void Block_Init();
inline void Item_Init();
inline void Item_Create();
inline void Enemy1_Init();
inline void Enemy1_Create();
inline void Enemy1_Update();
inline void Enemy1_Draw();
bool Game_Init();
bool Game_Update();
bool Game_Draw();
void Game_End();
void Game_Reset();
HGE *game;
hgeFont *fntDefault;
DWORD backColor;
HTEXTURE texPart;
HTARGET tarPre;
hgeSprite *sprTar;
//View -------------
float _ViewX,_ViewY;
//Block ------------
hgeSprite *_BlockSpr;
hgeParticleSystem *_BlockPar;
float _BlocksX[BLOCK_NUM], _BlocksY[BLOCK_NUM];
//Enemy1 ----------
hgeSprite *_Enemy1Spr;
hgeParticleSystem *_Enemy1Par;
float _Enemy1X[ENEMY1_NUM],_Enemy1Y[ENEMY1_NUM],_Enemy1Dir[ENEMY1_NUM],_Enemy1Elapsed[ENEMY1_NUM],_Enemy1Spe[ENEMY1_NUM];
//Player ------------
hgeSprite *_PlayerSpr;
hgeParticleSystem *_PlayerPar;
hgeColorRGB *_PlayerPreCol;
float _PlayerX,_PlayerY,Player_Health;
int _PlayerEnergy;
//Item --------------
hgeSprite *_ItemSpr;
hgeParticleSystem *_ItemPar;
float _ItemX, _ItemY;
int _Score = 0;
const DWORD _Colors[10] = {0xFFFF0000,0xFF00FF00,0xFF0000FF,0xFFFFFF77,0xFF7777FF,0xFF44FFFF,0xFF00FF00,0xFF224488,0xFFFFAA88,0xFFFF11FF};
bool Game_Init()
{
game = hgeCreate(HGE_VERSION);
game->System_SetState(HGE_FRAMEFUNC, Game_Update);
game->System_SetState(HGE_RENDERFUNC, Game_Draw);
game->System_SetState(HGE_TITLE, "Particle Battle");
game->System_SetState(HGE_FPS, FPS);
game->System_SetState(HGE_WINDOWED, WINMODE);
game->System_SetState(HGE_SCREENWIDTH, SCREEN_WIDTH);
game->System_SetState(HGE_SCREENHEIGHT, SCREEN_HEIGHT);
game->System_SetState(HGE_SCREENBPP, SCREEN_BPP);
game->System_SetState(HGE_SHOWSPLASH, false);
game->System_SetState(HGE_HIDEMOUSE, false);
if(game->System_Initiate())
{
backColor = 0xFF000000;
// Load texture and font ------------------------------
texPart = game->Texture_Load("Data\\particles.png");
fntDefault = new hgeFont("Data\\font1.fnt");
if(!texPart || !fntDefault)
{
MessageBox(NULL, "Can't load files", "Error", MB_OK | MB_ICONERROR);
return false;
}
tarPre = game->Target_Create(SCREEN_WIDTH,SCREEN_HEIGHT,true);
sprTar = new hgeSprite(game->Target_GetTexture(tarPre), 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
sprTar->SetBlendMode(BLEND_COLORMUL | BLEND_ALPHAADD | BLEND_ZWRITE);
sprTar->SetColor(_Colors[game->Random_Int(0,10)], 0);
sprTar->SetColor(_Colors[game->Random_Int(0,10)], 1);
sprTar->SetColor(_Colors[game->Random_Int(0,10)], 2);
sprTar->SetColor(_Colors[game->Random_Int(0,10)], 3);
Player_Init();
Block_Init();
Item_Init();
Enemy1_Init();
game->System_Start();
}
return true;
}
bool Game_Update()
{
float dt = game->Timer_GetDelta();
Enemy1_Update();
_ItemPar->Transpose(_ItemX - _ViewX, _ItemY - _ViewY);
_ItemPar->Update(dt);
Player_Update();
return false;
}
bool Game_Draw()
{
game->Gfx_BeginScene(tarPre);
game->Gfx_Clear(backColor);
//Draw Blocks
for(int i = 0; i < BLOCK_NUM; i++)
{
if(_BlocksX[i] == 0 && _BlocksY[i] == 0)
continue;
_BlockPar->Transpose(_BlocksX[i] - _ViewX, _BlocksY[i] - _ViewY);
_BlockPar->Update(game->Timer_GetDelta());
_BlockPar->Render();
}
Enemy1_Draw();
game->Gfx_EndScene();
game->Gfx_BeginScene();
game->Gfx_Clear(backColor);
sprTar->SetTexture(game->Target_GetTexture(tarPre));
sprTar->Render(0,0);
_ItemPar->Render();
_PlayerPar->Transpose(_PlayerX - _ViewX ,_PlayerY - _ViewY);
_PlayerPar->Render();
fntDefault->printf(8,6,HGETEXT_LEFT,"FPS : %d\nSCORE : %d\nEnergy : %d", game->Timer_GetFPS(), _Score, _PlayerEnergy);
game->Gfx_EndScene();
return false;
}
void Game_End()
{
//delete fntDefault;
//game->Target_Free(tarPre);
//game->Texture_Free(texPart);
game->System_Shutdown();
game->Release();
}
void Game_Reset()
{
Sleep(0xFF);
Block_Create();
Item_Create();
Enemy1_Create();
_PlayerX = SCREEN_WIDTH/2;
_PlayerY = SCREEN_HEIGHT/2;
_ViewX = 0;
_ViewY = 0;
sprTar->SetColor(_Colors[game->Random_Int(0,10)], 0);
sprTar->SetColor(_Colors[game->Random_Int(0,10)], 1);
sprTar->SetColor(_Colors[game->Random_Int(0,10)], 2);
sprTar->SetColor(_Colors[game->Random_Int(0,10)], 3);
}
inline float DistanceGet(float x1,float y1,float x2,float y2)
{
float xx = x2 - x1;
float yy = y2 - y1;
return sqrtf(xx*xx + yy*yy);
}
inline bool IsFree(float xx,float yy)
{
for(int i = 0; i < BLOCK_NUM; i++)
{
if(_BlocksX[i] == 0 && _BlocksY[i] == 0)
{
continue;
}
else if(xx < _BlocksX[i] || yy < _BlocksY[i] || xx > _BlocksX[i]+BLOCK_WIDTH || yy > _BlocksY[i]+BLOCK_HEIGHT)
{
continue;
}
else return false;
}
return true;
}
inline void Player_Init()
{
_PlayerEnergy = 100;
_PlayerX = SCREEN_WIDTH/2;
_PlayerY = SCREEN_HEIGHT/2;
_PlayerSpr = new hgeSprite(texPart, 0, 0, 32, 32);
_PlayerSpr->SetHotSpot(PLAYER_RADIUS/2, PLAYER_RADIUS/2);
_PlayerSpr->SetBlendMode(BLEND_COLORMUL | BLEND_ALPHAADD | BLEND_ZWRITE);
_PlayerPar = new hgeParticleSystem("Data\\Player.psi",_PlayerSpr);
_PlayerPar->info.bRelative = true;
_PlayerPar->Fire();
}
inline void Player_Update()
{
if(game->Input_KeyDown(HGEK_ESCAPE))
Game_End();
//Mouse Down
if(game->Input_GetKeyState(HGEK_LBUTTON) && _PlayerEnergy > 1)
{
_PlayerPar->info.fDirection += 0.5;
for(int i = 0; i < ENEMY1_NUM; i++)
{
if(DistanceGet(_PlayerX ,_PlayerY ,_Enemy1X[i], _Enemy1Y[i] ) < PLAYER_RADIUS*2 + ENEMY1_RADIUS)
{
_Score += 10;
_PlayerEnergy += 10;
_Enemy1X[i] = game->Random_Int(256,SCENE_WIDTH-256);
_Enemy1Y[i] = game->Random_Int(256,SCENE_HEIGHT-256);
_Enemy1Dir[i] = game->Random_Float(0,TWO_PI);
_Enemy1Spe[i] = game->Random_Float(1,6);
_Enemy1Elapsed[i] = 0;
}
}
}
else
{
for(int i = 0; i < ENEMY1_NUM; i++)
{
if(DistanceGet(_PlayerX ,_PlayerY ,_Enemy1X[i], _Enemy1Y[i] ) < PLAYER_RADIUS + ENEMY1_RADIUS)
{
_Score -= 10;
Game_Reset();
}
}
float mx=0,my=0,dir=0;
game->Input_GetMousePos(&mx,&my);
dir = atan2f(my + _ViewY -_PlayerY, mx + _ViewX - _PlayerX) + PI;
if(dir > TWO_PI)
dir -= TWO_PI;
_PlayerPar->info.fDirection = dir;
if(game->Input_GetKeyState(HGEK_RBUTTON))
{
if(DistanceGet(mx + _ViewX ,my + _ViewY ,_PlayerX,_PlayerY) > 16)
{
float nx=0,ny=0;
nx = _PlayerX + cosf(dir) * -PLAYER_SPEED;
ny = _PlayerY + sinf(dir) * -PLAYER_SPEED;
if(IsFree(nx,ny))
{
_PlayerX = nx;
_PlayerY = ny;
_ViewX = _PlayerX - SCREEN_WIDTH/2;
_ViewY = _PlayerY - SCREEN_HEIGHT/2;
}
else
{
nx = _PlayerX + cosf(dir) * PLAYER_SPEED;
ny = _PlayerY + sinf(dir) * PLAYER_SPEED;
_PlayerX = nx;
_PlayerY = ny;
_ViewX = _PlayerX - SCREEN_WIDTH/2;
_ViewY = _PlayerY - SCREEN_HEIGHT/2;
}
if(DistanceGet(_PlayerX , _PlayerY , _ItemX , _ItemY) < PLAYER_RADIUS + ITEM_RADIUS)
{
_Score += 100;
_PlayerEnergy += 100;
Game_Reset();
}
}
}
}
if(game->Input_KeyDown(HGEK_LBUTTON)&& _PlayerEnergy > 1)
{
_PlayerPreCol = new hgeColorRGB(_PlayerPar->info.colColorStart);
_PlayerPar->info.colColorStart = hgeColorRGB(0.9f,0,0,1);
}
else if(game->Input_KeyUp(HGEK_LBUTTON)&& _PlayerEnergy > 1)
{
_PlayerEnergy -= 10;
_PlayerPar->info.colColorStart = *_PlayerPreCol;
}
if(game->Input_KeyDown(HGEK_R))
{
_Score = 0;
_PlayerEnergy = 100;
Game_Reset();
}
_PlayerPar->Update(game->Timer_GetDelta());
}
inline void Enemy1_Init()
{
_Enemy1Spr = new hgeSprite(texPart,4*32,32,32,32);
_Enemy1Spr->SetHotSpot(16,16);
_Enemy1Par= new hgeParticleSystem("Data\\Enemy1.psi",_Enemy1Spr);
_Enemy1Par->Fire();
Enemy1_Create();
}
inline void Enemy1_Create()
{
for(int i = 0; i < ENEMY1_NUM; i++)
{
_Enemy1X[i] = game->Random_Int(256,SCENE_WIDTH-256);
_Enemy1Y[i] = game->Random_Int(256,SCENE_HEIGHT-256);
_Enemy1Dir[i] = game->Random_Float(0,TWO_PI);
_Enemy1Spe[i] = game->Random_Float(1,6);
_Enemy1Elapsed[i] = 0;
}
}
inline void Enemy1_Update()
{
for(int i = 0; i < ENEMY1_NUM; i++)
{
float nx = 0,ny = 0;
nx = cosf(_Enemy1Dir[i]) * _Enemy1Spe[i];
ny = sinf(_Enemy1Dir[i]) * _Enemy1Spe[i];
_Enemy1Elapsed[i] += game->Timer_GetDelta();
if(_Enemy1Elapsed[i] > ENEMY1_MAXMOVE)
{
_Enemy1Dir[i] += PI;
if(_Enemy1Dir[i] > TWO_PI)
_Enemy1Dir[i] -= TWO_PI;
_Enemy1Elapsed[i] = 0;
}
_Enemy1X[i] += nx;
_Enemy1Y[i] += ny;
}
}
inline void Enemy1_Draw()
{
for(int i = 0; i < ENEMY1_NUM; i++)
{
_Enemy1Par->info.fDirection = _Enemy1Dir[i];
_Enemy1Par->Transpose(_Enemy1X[i] - _ViewX, _Enemy1Y[i] - _ViewY);
_Enemy1Par->Update(game->Timer_GetDelta());
_Enemy1Par->Render();
}
}
inline void Block_Create()
{
int i = 0;
for (int jj = 0; jj < SCENE_WIDTH/BLOCK_WIDTH; jj++)
{
_BlocksX[i] = jj*BLOCK_WIDTH;
_BlocksY[i] = 0;
i++;
_BlocksX[i] = jj*BLOCK_WIDTH;
_BlocksY[i] = SCENE_HEIGHT;
i++;
}
for (int kk= 0; kk < SCENE_HEIGHT/BLOCK_HEIGHT; kk++)
{
_BlocksX[i] = BLOCK_WIDTH;
_BlocksY[i] = kk*BLOCK_HEIGHT;
i++;
_BlocksX[i] = SCENE_WIDTH;
_BlocksY[i] = kk*BLOCK_HEIGHT;;
i++;
}
while(i < BLOCK_NUM)
{
start:
int nr = game->Random_Int(8,16);
if(i+nr >= BLOCK_NUM)
nr = BLOCK_NUM - i;
float xx = static_cast<int>(game->Random_Int(0,SCENE_WIDTH)/BLOCK_WIDTH)*BLOCK_WIDTH;
float yy = static_cast<int>(game->Random_Int(0,SCENE_HEIGHT)/BLOCK_HEIGHT)*BLOCK_HEIGHT;
int xr = 0, yr = 0;
if(game->Random_Int(8,16)% 2 == 0)
xr = game->Random_Int(-1,1);
if(game->Random_Int(8,16)% 2 == 0)
yr = game->Random_Int(-1,1);
xx += xr*BLOCK_WIDTH*nr;
yy += yr*BLOCK_HEIGHT*nr;
int c = 0;
while(c < nr)
{
if(IsFree(xx,yy))
{
_BlocksX[i] = xx;
_BlocksY[i] = yy;
xx += xr*BLOCK_WIDTH;
yy += yr*BLOCK_HEIGHT;
c++;
i++;
}
else
{
goto start;
}
}
}
}
inline void Block_Init()
{
_BlockSpr = new hgeSprite(texPart,5*32,0,32,32);
_BlockSpr->SetBlendMode(BLEND_COLORMUL | BLEND_ALPHAADD | BLEND_ZWRITE);
_BlockSpr->SetHotSpot((BLOCK_WIDTH/4), (BLOCK_HEIGHT/4));
_BlockPar = new hgeParticleSystem("Data\\Block.psi",_BlockSpr);
_BlockPar->Fire();
Block_Create();
}
inline void Item_Init()
{
_ItemSpr = new hgeSprite(texPart,32,32,32,32);
_ItemSpr->SetBlendMode(BLEND_COLORMUL | BLEND_ALPHAADD | BLEND_ZWRITE);
_ItemPar = new hgeParticleSystem("Data\\Item.psi",_ItemSpr);
Item_Create();
}
inline void Item_Create()
{
float xx = 0;
float yy = 0;
while(true)
{
xx = static_cast<int>(game->Random_Int(1024,SCENE_WIDTH-800)/BLOCK_WIDTH)*BLOCK_WIDTH;
yy = static_cast<int>(game->Random_Int(1024,SCENE_HEIGHT-800)/BLOCK_HEIGHT)*BLOCK_HEIGHT;
if(IsFree(xx,yy))
{
_ItemX = xx;
_ItemY = yy;
_ItemPar->Fire();
break;
}
}
}
int WinMain (HINSTANCE hInstance, HINSTANCE hPreInstance,LPSTR lpCMD, int nShowCMD)
{
if(!Game_Init())
{
Game_End();
return 0;
}
Game_End();
return 0;
}
|
|
_________________ 0xFF00FFAACC33EEFF11FF3FFF |
|
بازگشت به بالا |
|
|
|
|
|
|
|
|
صفحه 2 از 2 |
تمام ساعات و تاريخها بر حسب 3.5+ ساعت گرينويچ مي باشد برو به صفحه قبلي 1, 2
|
|
شما نمي توانيد در اين انجمن نامه ارسال كنيد. شما نمي توانيد به موضوعات اين انجمن پاسخ دهيد شما نمي توانيد نامه هاي ارسالي خود را در اين انجمن ويرايش كنيد شما نمي توانيد نامه هاي ارسالي خود را در اين انجمن حذف كنيد شما نمي توانيد در نظر سنجي هاي اين انجمن شركت كنيد
|
|
|