#include "hge.h"
#include "hgevector.h"
#include "hgesprite.h"
#include "hgeparticle.h"
#include "hgefont.h"
#include "hgeanim.h"
/***************************************************************************************/
HGE *hge = 0;
#define WormMax 500
#define SCREEN_WIDTH 1024
#define SCREEN_HEIGHT 768
#define WINDOWED true
int BodyStep = 30;
int AnimFPS = 10;
struct floatcoord
{
float x, y;
};
struct TWorm
{
floatcoord coord[WormMax+1];
float speed;
bool pause;
hgeVector v;
};
struct TGumBoy
{
float x,y,direction;
};
float x, y;
float dt;
int step;
hgeVector g;
HTEXTURE textures;
hgeSprite* spr_body;
hgeSprite* spr_head;
hgeAnimation* anim_head;
HTEXTURE tex_gumboy;
hgeSprite* spr_gumboy;
HTEXTURE tex_ground,tex_darkground;
hgeQuad quad_ground;
TWorm worm;
TGumBoy gumboy1;
hgeFont* fnt;
/***************************************************************************************/
bool RenderWorm()
{
int i;
hge->Gfx_RenderQuad(&quad_ground);
for (i=0;i<=WormMax; i+=BodyStep)
{
spr_body->RenderEx(worm.coord[i].x,worm.coord[i].y,0);
}
anim_head->RenderEx(worm.coord[WormMax].x,worm.coord[WormMax].y,worm.v.Angle()+M_PI_2);
spr_gumboy->RenderEx(gumboy1.x,gumboy1.y,gumboy1.direction);
}
bool InitWorm()
{
int i;
textures = hge->Texture_Load("Graphic1.png");
spr_body=new hgeSprite(textures, 1, 1, 32, 32);
spr_head = new hgeSprite(textures, 33, 0, 32, 39);
spr_body->SetHotSpot(16,16);
spr_head->SetHotSpot(16,20);
anim_head=new hgeAnimation(textures,3,AnimFPS,32,0,32,39);
anim_head->SetMode(HGEANIM_FWD or HGEANIM_LOOP or HGEANIM_PINGPONG);
anim_head->SetHotSpot(16,20);
//anim_head->Play();
tex_gumboy = hge->Texture_Load("gumboy.png");
spr_gumboy = new hgeSprite(tex_gumboy,0,0,32,32);
gumboy1.y = SCREEN_HEIGHT/2-16;
gumboy1.x=0;
spr_gumboy->SetHotSpot(16,16);
tex_ground = hge->Texture_Load("ground.png");
tex_darkground = hge->Texture_Load("darkground.png");
quad_ground.tex=tex_ground;
quad_ground.v[0].x=0; quad_ground.v[0].y=SCREEN_HEIGHT/2; quad_ground.v[0].tx=0; quad_ground.v[0].ty=0;
quad_ground.v[1].x=SCREEN_WIDTH; quad_ground.v[1].y=SCREEN_HEIGHT/2; quad_ground.v[1].tx=1; quad_ground.v[1].ty=0;
quad_ground.v[2].x=SCREEN_WIDTH; quad_ground.v[2].y=SCREEN_HEIGHT; quad_ground.v[2].tx=1; quad_ground.v[2].ty=1;
quad_ground.v[3].x=0; quad_ground.v[3].y=SCREEN_HEIGHT; quad_ground.v[3].tx=0; quad_ground.v[3].ty=1;
for(i=0; i<=3; i++)
{
quad_ground.v[i].col=0xFFFFFFFF;
quad_ground.v[i].z=0.5;
quad_ground.v[i].tx=quad_ground.v[i].x/320;
quad_ground.v[i].ty=quad_ground.v[i].y/320;
}
worm.speed=0.5f;
for (i=0; i<=WormMax; i++)
{
worm.coord[i].y=SCREEN_HEIGHT/3*2;
worm.coord[i].x=50;
}
worm.v = hgeVector(500,0);
g=hgeVector(0,0.98f);
fnt=new hgeFont("comic.fnt");
}
bool FrameWorm()
{
int i;
if (worm.coord[WormMax].y>SCREEN_HEIGHT/2)
{
if (hge->Input_GetKeyState(HGEK_LEFT)) { worm.v.Rotate(-4*dt);}
if (hge->Input_GetKeyState(HGEK_RIGHT)) {worm.v.Rotate(4*dt);}
if (hge->Input_GetKeyState(HGEK_UP)) { worm.speed=1;} else {worm.speed=0.5;}
worm.pause=hge->Input_GetKeyState(HGEK_DOWN);
if (hge->Input_GetKeyState(HGEK_UP)and (!anim_head->IsPlaying())) { anim_head->Play();}
if (not hge->Input_GetKeyState(HGEK_UP)) { anim_head->Stop();}
}
if (!worm.pause) {
for (i=0; i<WormMax; i++){
worm.coord[i].x=worm.coord[i+1].x;
worm.coord[i].y=worm.coord[i+1].y;
}
worm.coord[WormMax].x=worm.coord[WormMax].x + worm.v.x*worm.speed*dt;
worm.coord[WormMax].y=worm.coord[WormMax].y + worm.v.y*worm.speed*dt;
}
if (worm.coord[WormMax].y<SCREEN_HEIGHT/2){ worm.v+=g; }
if (worm.coord[WormMax].x<0) { worm.coord[WormMax].x=0;}
if (worm.coord[WormMax].y<0) { worm.coord[WormMax].y=0;}
if (worm.coord[WormMax].x>SCREEN_WIDTH) { worm.coord[WormMax].x=SCREEN_WIDTH;}
if (worm.coord[WormMax].y>SCREEN_HEIGHT) { worm.coord[WormMax].y=SCREEN_HEIGHT;}
anim_head->Update(dt);
gumboy1.x+=dt*50;
gumboy1.direction+=dt*50/16;
step = int(0.01/dt);
if (step=0){step++;}
}
bool FrameFunc()
{
dt=hge->Timer_GetDelta();
if (hge->Input_GetKeyState(HGEK_ESCAPE)) return true;
FrameWorm();
return false;
}
bool RenderFunc()
{
hge->Gfx_BeginScene();
hge->Gfx_Clear(0);
RenderWorm();
hge->Gfx_EndScene();
}
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
hge = hgeCreate(HGE_VERSION);
hge->System_SetState(HGE_FRAMEFUNC, FrameFunc);
hge->System_SetState(HGE_RENDERFUNC, RenderFunc);
hge->System_SetState(HGE_TITLE, "Death Worm");
hge->System_SetState(HGE_WINDOWED, WINDOWED);
hge->System_SetState(HGE_USESOUND, false);
hge->System_SetState(HGE_SCREENWIDTH, SCREEN_WIDTH);
hge->System_SetState(HGE_SCREENHEIGHT, SCREEN_HEIGHT);
hge->System_SetState(HGE_SCREENBPP, 32);
hge->System_SetState(HGE_LOGFILE, "deathworm.log");
if(hge->System_Initiate())
{
InitWorm();
hge->System_Start();
}
else
{
MessageBox(NULL, hge->System_GetErrorMessage(), "Error", MB_OK | MB_ICONERROR | MB_APPLMODAL);
}
hge->System_Shutdown();
hge->Release();
return 0;
}