1
0
Fork 0
blockofighter/src/run.cpp

210 lines
4.3 KiB
C++
Raw Normal View History

2014-02-16 14:32:28 +00:00
#include "main.h"
#include <SDL.h>
#include "run.h"
#include "fight.h"
#include "menu.h"
#include "camera.h"
2014-02-16 14:32:28 +00:00
#include "end.h"
#include "graphics.h"
#include "3dutils.h"
#include "audio.h"
#include "font.h"
#include "legoblocks.h"
#include "glapi.h"
int gamemode;
bool changed;
bool gameinitialized = false;
void initFontTexture(void);
2015-06-03 12:29:34 +00:00
void initScenes(void) {
knobgllist = glGenLists(1);
setDetail(detail);
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
// Simple loading-screen
enable2D();
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
SDL_GL_SwapBuffers();
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
initFontTexture();
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
print(0.08, 0.4, "Loading...", 0.2);
SDL_GL_SwapBuffers();
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
disable2D();
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
SKYBOX = -1;
initTextures();
initFight();
initMenu();
initEnd();
changeGameMode(MENUMODE);
// changeGameMode(ENDMODE);
gameinitialized = true;
2014-02-16 14:32:28 +00:00
}
2015-06-03 12:29:34 +00:00
void changeGameMode(int newmode) {
gamemode = newmode;
changed = true;
2014-02-16 14:32:28 +00:00
}
2015-06-03 12:29:34 +00:00
void calculateFrame(int framecount) {
switch (gamemode) {
case MENUMODE:
calculateMenu(framecount);
break;
case FIGHTMODE:
calculateFight(framecount);
break;
case ENDMODE:
calculateEnd(framecount);
break;
}
updateAudio();
changed = false;
2014-02-16 14:32:28 +00:00
}
2015-06-03 12:29:34 +00:00
void drawFrame(int framecount) {
if (changed)
calculateFrame(framecount);
2014-02-16 14:32:28 +00:00
/*glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);*/
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
glMatrixMode(GL_MODELVIEW);
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
switch (gamemode) {
case MENUMODE:
drawMenu(framecount);
break;
case FIGHTMODE:
drawFight(framecount);
break;
case ENDMODE:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
2015-06-03 12:29:34 +00:00
drawEnd(framecount);
break;
}
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
SDL_GL_SwapBuffers();
2014-02-16 14:32:28 +00:00
}
/*int SKY_FRONT_ID;
int SKY_BACK_ID;
int SKY_LEFT_ID;
int SKY_RIGHT_ID;
int SKY_TOP_ID;
int SKY_BOTTOM_ID;*/
bool texturesloaded = false;
Texture *flaretexture;
Texture *skyfronttexture;
Texture *skybacktexture;
Texture *skylefttexture;
Texture *skyrighttexture;
Texture *skytoptexture;
Texture *skybottomtexture;
Texture *damageHead;
Texture *damageTorso;
Texture *damageHand;
Texture *damageLeg;
Texture *tuxtexture;
Texture *faceTexture;
2015-06-03 12:29:34 +00:00
void initFontTexture(void) {
if (!texturesloaded) {
float trans[3] = {1, 0, 0};
fonttexture = new Texture();
fonttexture->loadImage(DATAPATH "font.png", trans);
} else {
fonttexture->reload();
}
2014-02-16 14:32:28 +00:00
}
2015-06-03 12:29:34 +00:00
void initTextures(void) {
/*SKY_FRONT_ID = DRUID.loadTexture(SKYFRONT);
SKY_BACK_ID = DRUID.loadTexture(SKYBACK);
SKY_LEFT_ID = DRUID.loadTexture(SKYLEFT);
SKY_RIGHT_ID = DRUID.loadTexture(SKYRIGHT);
SKY_TOP_ID = DRUID.loadTexture(SKYTOP);
SKY_BOTTOM_ID = DRUID.loadTexture(SKYBOTTOM);*/
if (!texturesloaded) {
skyfronttexture = new Texture();
skyfronttexture->loadImage(SKYFRONT);
skybacktexture = new Texture();
skybacktexture->loadImage(SKYBACK);
skylefttexture = new Texture();
skylefttexture->loadImage(SKYLEFT);
skyrighttexture = new Texture();
skyrighttexture->loadImage(SKYRIGHT);
skytoptexture = new Texture();
skytoptexture->loadImage(SKYTOP);
skybottomtexture = new Texture();
skybottomtexture->loadImage(SKYBOTTOM);
float something[3] = {1, 0, 0.5};
damageHead = new Texture();
damageHead->loadImage(DAMAGEHEAD, something);
damageTorso = new Texture();
damageTorso->loadImage(DAMAGETORSO, something);
damageHand = new Texture();
damageHand->loadImage(DAMAGEHAND, something);
damageLeg = new Texture();
damageLeg->loadImage(DAMAGELEG, something);
faceTexture = new Texture();
something[2] = 1;
faceTexture->loadImage(FACE, something);
float zeros[3] = {0, 0, 0};
flaretexture = new Texture();
flaretexture->loadImage(DATAPATH "flare.png", zeros);
float pink[3] = {1, 0, 1};
tuxtexture = new Texture();
tuxtexture->loadImage(DATAPATH "tux.png", pink);
} else {
skyfronttexture->reload();
skybacktexture->reload();
skylefttexture->reload();
skyrighttexture->reload();
skytoptexture->reload();
skybottomtexture->reload();
damageHead->reload();
damageTorso->reload();
damageHand->reload();
damageLeg->reload();
flaretexture->reload();
tuxtexture->reload();
}
texturesloaded = true;
2014-02-16 14:32:28 +00:00
}
2015-06-03 12:29:34 +00:00
void setDetail(int detail) {
switch (detail) {
case 0:
knobdetail = 0;
break;
case 1:
knobdetail = 5;
break;
case 2:
knobdetail = 8;
break;
case 3:
knobdetail = 16;
break;
}
initKnob();
2014-02-16 14:32:28 +00:00
}