include hge include hgevector include hgesprite include hgeparticle in

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
#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;
}