mShrek
mLogan
mJohn Cena
--mDex Dogtective
++mDexDogtective
fShani
fIsidra
fAja
float y;
} vec2;
++typedef struct {
++ float x;
++ float y;
++ float z;
++} vec3;
++
/**
* This structure contains two sets of coordinates for ray drawing.
*/
*/
extern unsigned int loops;
++extern GLuint shaderProgram;
++
/**
* Prints a formatted debug message to the console, along with the callee's file and line
* number.
GENDER gender;
Texturec *tex;
++ Texturec *ntex;
unsigned int randDialog;
* Defines how many game ticks it takes for a day to elapse.
*/
--#define DAY_CYCLE 3000
++#define DAY_CYCLE 12000
/**
* The background type enum.
RAIN /**< Rain (not implemented :) )*/
} WEATHER;
++
++typedef struct{
++ vec2 loc;
++ Color color;
++}Light;
/**
* The line structure.
* This structure is used to store the world's ground, stored in vertical
std::vector<Entity *> entity;
std::vector<Object *> object;
std::vector<Particles *> particles;
++ std::vector<Light > light;
- void addStructure(_TYPE t,BUILD_SUB sub,float x,float y,World *outside,World *inside);
- void addVillage(int bCount, int npcMin, int npcMax,_TYPE t,float x,float y,World *outside,World *inside);
+ void addStructure(_TYPE t,BUILD_SUB sub,float x,float y,World *inside);
+ void addVillage(int bCount, int npcMin, int npcMax,_TYPE t,float x,float y,World *outside);
void addMob(int t,float x,float y);
void addMob(int t,float x,float y,void (*hey)(Mob *));
void addNPC(float x,float y);
void addObject(ITEM_ID, bool, const char *, float, float);
void addParticle(float, float, float, float, float, float, Color color, int);
++ void addLight(vec2, Color);
void update(Player *p,unsigned int delta);
/*******************************************************************************
* MAIN ************************************************************************
*******************************************************************************/
-
-#include <X11/Xlib.h>
--
int main(/*int argc, char *argv[]*/){
//*argv = (char *)argc;
gameRunning=false;
-
- XInitThreads();
-
++
/*!
* (Attempt to) Initialize SDL libraries so that we can use SDL facilities and eventually
* make openGL calls. Exit if there was an error.
if((err=glewInit()) != GLEW_OK){
std::cout << "GLEW was not able to initialize! Error: " << glewGetErrorString(err) << std::endl;
return -1;
-- }
++ }
/*
* Initialize the FreeType libraries and select what font to use using functions from the ui
player->near=true; // Draw the player's name
++ //glUniform2f(glGetUniformLocation(shaderProgram, "lightLocation"), 640,100);
currentWorld->draw(player);
++ //glUniform3f(glGetUniformLocation(shaderProgram, "lightColor"), 0,1.0f,0);
++
/*
* Apply shaders if desired.
}
glUseProgramObjectARB(0);
}
- player->inv->draw();
+
- glUseProgramObjectARB(shaderProgram);
- glUniform2f(glGetUniformLocation(shaderProgram, "lightLocation"), 250,250);
- glUniform3f(glGetUniformLocation(shaderProgram, "lightColor"), 1,0,0);
- glColor4f(0.0f,0.0f,0.0f,1.0f);
- glRectf(-SCREEN_WIDTH/2,0,SCREEN_WIDTH/2,SCREEN_HEIGHT);
- glUseProgramObjectARB(0);
-
- player->inv->draw();
++ player->inv->draw();
++
/*
* Here we draw a black overlay if it's been requested.
*/
near = false;
tex = new Texturec(3,"assets/house1.png", "assets/house2.png", "assets/fountain1.png");
++ ntex = new Texturec(1, "assets/house1N.png");
inWorld = NULL;
name = NULL;
void Entity::draw(void){ //draws the entities
glPushMatrix();
glColor3ub(255,255,255);
++ //glUniform1i(glGetUniformLocation(shaderProgram, "sampler"), 0);
if(type==NPCT){
if(NPCp(this)->aiFunc.size()){
glColor3ub(255,255,0);
//currentWorld->addParticle(loc.x,loc.y-HLINE,HLINE,HLINE,0,0,{0.0f,.17f,0.0f},1000);
if(up){
if(++texState==2)up=false;
++ glActiveTexture(GL_TEXTURE0);
tex->bindNext();
}else{
if(!--texState)up=true;
++ glActiveTexture(GL_TEXTURE0);
tex->bindPrev();
}
}
if(!ground){
++ glActiveTexture(GL_TEXTURE0 + 0);
tex->bind(0);
}else if(vel.x){
++ glActiveTexture(GL_TEXTURE0 + 0);
tex->bind(texState);
}else{
++ glActiveTexture(GL_TEXTURE0 + 0);
tex->bind(1);
}
break;
case MOBT:
switch(subtype){
case MS_RABBIT:
++ glActiveTexture(GL_TEXTURE0 + 0);
tex->bind(!ground);
break;
case MS_TRIGGER:
case MS_BIRD:
case MS_DOOR:
default:
++ glActiveTexture(GL_TEXTURE0 + 0);
tex->bind(0);
break;
}
for(auto &strt : currentWorld->build){
if(this == strt){
if(strt->bsubtype == HOUSE){
++ glActiveTexture(GL_TEXTURE1);
++ ntex->bind(0);
++ //When rendering an objectwith this program.
++ glActiveTexture(GL_TEXTURE0 + 0);
tex->bind(0);
++ //glBindSampler(0, linearFiltering);
++
++
}else if(strt->bsubtype == HOUSE2){
++ glActiveTexture(GL_TEXTURE0 + 0);
tex->bind(1);
}else if(strt->bsubtype == FOUNTAIN){
++ glActiveTexture(GL_TEXTURE0 + 0);
tex->bind(2);
}
}
}
break;
default:
++ glActiveTexture(GL_TEXTURE0 + 0);
tex->bind(0);
break;
}
glColor3ub(255,255,255);
++ glUseProgram(shaderProgram);
++ glUniform1i(glGetUniformLocation(shaderProgram, "sampler"), 0);
glBegin(GL_QUADS);
glTexCoord2i(0,1);glVertex2i(loc.x, loc.y);
glTexCoord2i(1,1);glVertex2i(loc.x + width, loc.y);
glTexCoord2i(1,0);glVertex2i(loc.x + width, loc.y + height);
glTexCoord2i(0,0);glVertex2i(loc.x, loc.y + height);
glEnd();
++ glUseProgram(0);
NOPE:
glDisable(GL_TEXTURE_2D);
glMatrixMode(GL_MODELVIEW);
worldSpawnHill3->setBGM("assets/music/ozone.wav");
worldSpawnHill3->addMob(MS_TRIGGER,-500,0,worldSpawnHill3_itemGet);
worldSpawnHill3->addMob(MS_TRIGGER,0,0,worldSpawnHill3_itemSee);
-- worldSpawnHill3->addObject(TEST_ITEM,false,"",-200,300);
- worldSpawnHill3->addMob(MS_TRIGGER,400,0,worldSpawnHill3_leave);
++ worldSpawnHill3->addObject(FLASHLIGHT,false,"",-200,300);
+ worldSpawnHill3->addMob(MS_TRIGGER,650,0,worldSpawnHill3_leave);
worldSpawnHill3->addHole(800,1000);
worldSpawnHill1->toRight = worldSpawnHill2;
//playerSpawnHill->addMob(MS_TRIGGER,-1300,0,CUTSCENEEE);*/
- currentWorld = worldSpawnHill1;
- worldSpawnHill2->addStructure(STRUCTURET,HOUSE,(rand()%120*HLINE),100,worldSpawnHill1,worldSpawnHill2);
+ worldSpawnHill2_Building1 = new IndoorWorld();
+ worldSpawnHill2_Building1->generate(300);
+ worldSpawnHill2_Building1->setBackground(BG_WOODHOUSE);
+ worldSpawnHill2_Building1->setBGM("assets/music/theme_jazz.wav");
+
+ worldSpawnHill2->addStructure(STRUCTURET,HOUSE,(rand()%120*HLINE),100,worldSpawnHill2_Building1);
++ worldSpawnHill2->addLight({300,100},{1.0f,1.0f,1.0f});
- worldSpawnHill2->addStructure(STRUCTURET,HOUSE,(rand()%120*HLINE),100,worldSpawnHill1,worldSpawnHill2);
++ //worldSpawnHill2->addStructure(STRUCTURET,HOUSE,(rand()%120*HLINE),100,worldSpawnHill1,worldSpawnHill2);
player = new Player();
player->spawn(200,100);
-
+
+ currentWorld = worldSpawnHill1;
currentWorld->bgmPlay(NULL);
-
atexit(destroyEverything);
}
default:
hangle = 0.0f;
}
--
++ glUseProgram(shaderProgram);
++ glUniform1i(glGetUniformLocation(shaderProgram, "sampler"), 0);
glTranslatef(itemLoc.x,itemLoc.y,0);
glRotatef(hangle, 0.0f, 0.0f, 1.0f);
glTranslatef(-itemLoc.x,-itemLoc.y,0);
glDisable(GL_TEXTURE_2D);
glTranslatef(player->loc.x*2,0,0);
glPopMatrix();
++ glUseProgram(0);
}
int Inventory::useItem(void){
NULL}
};
++Texturec *grassT;
++
const float bgDraw[3][3]={
{100,240,.6 },
{150,250,.4 },
star = new vec2[100];
memset(star,0,100 * sizeof(vec2));
++ grassT = new Texturec(1,"assets/grass.png");
}
void World::deleteEntities(void){
width = (-x_start) << 1;
glEnable(GL_TEXTURE_2D);
--
++
bgTex->bind(0);
safeSetColorA(255,255,255,255 - worldShade * 4);
--
glBegin(GL_QUADS);
glTexCoord2i(0,0);glVertex2i( cx_start,SCREEN_HEIGHT);
glTexCoord2i(1,0);glVertex2i(-cx_start,SCREEN_HEIGHT);
glTexCoord2i(1,1);glVertex2i(-cx_start,0);
glTexCoord2i(0,1);glVertex2i( cx_start,0);
glEnd();
--
++
bgTex->bindNext();
-- safeSetColorA(255,255,255,worldShade * 4);
--
++ safeSetColorA(255,255,255,worldShade * 4);
glBegin(GL_QUADS);
glTexCoord2i(0,0);glVertex2i( cx_start,SCREEN_HEIGHT);
glTexCoord2i(1,0);glVertex2i(-cx_start,SCREEN_HEIGHT);
glTexCoord2i(1,1);glVertex2i(-cx_start,0);
glTexCoord2i(0,1);glVertex2i( cx_start,0);
glEnd();
--
glDisable(GL_TEXTURE_2D);
/*
}
}
++
glEnable(GL_TEXTURE_2D);
/*
* Draw the mountains.
*/
--
bgTex->bindNext();
safeSetColorA(150-bgshade,150-bgshade,150-bgshade,220);
bool hey=false;
glEnable(GL_TEXTURE_2D);
++ glActiveTexture(GL_TEXTURE0);
bgTex->bindNext();
++
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); //for the s direction
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); //for the t direction
++ glUseProgram(shaderProgram);
++ glUniform1i(glGetUniformLocation(shaderProgram, "sampler"), 0);
++ glUniform1f(glGetUniformLocation(shaderProgram, "amb"), float(shade+50.0f)/100.0f);
++ if(light.size() == 0){
++ glUniform2f(glGetUniformLocation(shaderProgram, "lightLocation"), 0,-1000);
++ glUniform3f(glGetUniformLocation(shaderProgram, "lightColor"), 0.0f,0.0f,0.0f);
++ }else{
++ for(auto &l : light){
++ glUniform2f(glGetUniformLocation(shaderProgram, "lightLocation"), l.loc.x-offset.x,l.loc.y);
++ glUniform3f(glGetUniformLocation(shaderProgram, "lightColor"), l.color.red,l.color.green,l.color.blue);
++ }
++ }
++
glBegin(GL_QUADS);
-- for(i=is;i<(unsigned)ie-GEN_INC;i++){
-- cline[i].y+=(yoff-DRAW_Y_OFFSET); // Add the y offset
-- if(!cline[i].y){
-- cline[i].y=base;
-- hey=true;
-- glColor4ub(0,0,0,255);
-- }else
-- safeSetColorA(150+shade*2,150+shade*2,150+shade*2,255);
-- glTexCoord2i(0,0);glVertex2i(cx_start+i*HLINE ,cline[i].y-GRASS_HEIGHT);
-- glTexCoord2i(1,0);glVertex2i(cx_start+i*HLINE+HLINE,cline[i].y-GRASS_HEIGHT);
-- glTexCoord2i(1,(int)(cline[i].y/64)+cline[i].color);glVertex2i(cx_start+i*HLINE+HLINE,0);
-- glTexCoord2i(0,(int)(cline[i].y/64)+cline[i].color);glVertex2i(cx_start+i*HLINE ,0);
-- cline[i].y-=(yoff-DRAW_Y_OFFSET); // Restore the line's y value
-- if(hey){
-- hey=false;
-- cline[i].y=0;
-- }
++ for(i=is;i<(unsigned)ie-GEN_INC;i++){
++ cline[i].y+=(yoff-DRAW_Y_OFFSET); // Add the y offset
++ if(!cline[i].y){
++ cline[i].y=base;
++ hey=true;
++ glColor4ub(0,0,0,255);
++ }else safeSetColorA(150+shade*2,150+shade*2,150+shade*2,255);
++ glTexCoord2i(0,0);glVertex2i(cx_start+i*HLINE ,cline[i].y-GRASS_HEIGHT);
++ glTexCoord2i(1,0);glVertex2i(cx_start+i*HLINE+HLINE,cline[i].y-GRASS_HEIGHT);
++ glTexCoord2i(1,(int)(cline[i].y/64)+cline[i].color);glVertex2i(cx_start+i*HLINE+HLINE,0);
++ glTexCoord2i(0,(int)(cline[i].y/64)+cline[i].color);glVertex2i(cx_start+i*HLINE ,0);
++ cline[i].y-=(yoff-DRAW_Y_OFFSET); // Restore the line's y value
++ if(hey){
++ hey=false;
++ cline[i].y=0;
}
++ }
glEnd();
++ glUseProgram(0);
glDisable(GL_TEXTURE_2D);
--
/*
* Draw grass on every line.
*/
float cgh[2];
-- glBegin(GL_QUADS);
-- for(i=is;i<(unsigned)ie-GEN_INC;i++){
--
-- /*
-- * Load the current line's grass values
-- */
--
-- if(cline[i].y)memcpy(cgh,cline[i].gh,2*sizeof(float));
-- else memset(cgh,0 ,2*sizeof(float));
--
--
--
-- /*
-- * Flatten the grass if the player is standing on it.
-- */
--
-- if(!cline[i].gs){
-- cgh[0]/=4;
-- cgh[1]/=4;
-- }
--
-- /*
-- * Actually draw the grass.
-- */
--
-- cline[i].y+=(yoff-DRAW_Y_OFFSET);
--
-- safeSetColor(shade,100+shade*1.5,shade);
--
-- glVertex2i(cx_start+i*HLINE ,cline[i].y+cgh[0]);
-- glVertex2i(cx_start+i*HLINE+HLINE/2,cline[i].y+cgh[0]);
-- glVertex2i(cx_start+i*HLINE+HLINE/2,cline[i].y-GRASS_HEIGHT);
-- glVertex2i(cx_start+i*HLINE ,cline[i].y-GRASS_HEIGHT);
--
-- glVertex2i(cx_start+i*HLINE+HLINE/2,cline[i].y+cgh[1]);
-- glVertex2i(cx_start+i*HLINE+HLINE ,cline[i].y+cgh[1]);
-- glVertex2i(cx_start+i*HLINE+HLINE ,cline[i].y-GRASS_HEIGHT);
-- glVertex2i(cx_start+i*HLINE+HLINE/2,cline[i].y-GRASS_HEIGHT);
--
-- cline[i].y-=(yoff-DRAW_Y_OFFSET);
++
++ glEnable(GL_TEXTURE_2D);
++ glActiveTexture(GL_TEXTURE0);
++ grassT->bind(0);
++ glUseProgram(shaderProgram);
++ glUniform1i(glGetUniformLocation(shaderProgram, "sampler"), 0);
++ //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); //for the s direction
++ //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); //for the t direction
++ //glBegin(GL_QUADS);
++
++ for(i=is;i<(unsigned)ie-GEN_INC;i++){
++
++ /*
++ * Load the current line's grass values
++ */
++
++ if(cline[i].y)memcpy(cgh,cline[i].gh,2*sizeof(float));
++ else memset(cgh,0 ,2*sizeof(float));
++
++
++
++ /*
++ * Flatten the grass if the player is standing on it.
++ */
++
++ if(!cline[i].gs){
++ cgh[0]/=4;
++ cgh[1]/=4;
}
-- glEnd();
--
++
++ /*
++ * Actually draw the grass.
++ */
++
++ cline[i].y+=(yoff-DRAW_Y_OFFSET);
++ safeSetColorA(255,255,255,255);
++ glBegin(GL_QUADS);
++ glTexCoord2i(0,0);glVertex2i(cx_start+i*HLINE ,cline[i].y+cgh[0]);
++ glTexCoord2i(1,0);glVertex2i(cx_start+i*HLINE+HLINE/2,cline[i].y+cgh[0]);
++ glTexCoord2i(1,1);glVertex2i(cx_start+i*HLINE+HLINE/2,cline[i].y-GRASS_HEIGHT);
++ glTexCoord2i(0,1);glVertex2i(cx_start+i*HLINE ,cline[i].y-GRASS_HEIGHT);
++ glEnd();
++
++ glBegin(GL_QUADS);
++ glTexCoord2i(0,0);glVertex2i(cx_start+i*HLINE+HLINE/2,cline[i].y+cgh[1]);
++ glTexCoord2i(1,0);glVertex2i(cx_start+i*HLINE+HLINE ,cline[i].y+cgh[1]);
++ glTexCoord2i(1,1);glVertex2i(cx_start+i*HLINE+HLINE ,cline[i].y-GRASS_HEIGHT);
++ glTexCoord2i(0,1);glVertex2i(cx_start+i*HLINE+HLINE/2,cline[i].y-GRASS_HEIGHT);
++ glEnd();
++
++ cline[i].y-=(yoff-DRAW_Y_OFFSET);
++ }
++ //glEnd();
++ //glUseProgram(0);
++ glDisable(GL_TEXTURE_2D);
++
++ //glUseProgram(0);
++
/*
* Draw non-structure entities.
*/
particles.back()->canMove = true;
}
++void World::addLight(vec2 loc, Color color){
++ light.push_back(Light());
++ light.back().loc = loc;
++ light.back().color = color;
++}
++
/*void World::removeObject(Object i){
object.delete[](i);
}*/
*/
glEnable(GL_TEXTURE_2D);
++ glUseProgram(shaderProgram);
++ glUniform1i(glGetUniformLocation(shaderProgram, "sampler"), 0);
++ glUniform1f(glGetUniformLocation(shaderProgram, "amb"), 0.0f);
++ if(light.size() == 0){
++ glUniform2f(glGetUniformLocation(shaderProgram, "lightLocation"), 0,-1000);
++ glUniform3f(glGetUniformLocation(shaderProgram, "lightColor"), 0.0f,0.0f,0.0f);
++ }else{
++ for(auto &l : light){
++ glUniform2f(glGetUniformLocation(shaderProgram, "lightLocation"), l.loc.x-offset.x,l.loc.y);
++ glUniform3f(glGetUniformLocation(shaderProgram, "lightColor"), l.color.red,l.color.green,l.color.blue);
++ }
++ }
bgTex->bind(0);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); //for the s direction
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); //for the t direction
glColor4ub(255,255,255,255);
glBegin(GL_QUADS);
- for(j = x_start - SCREEN_WIDTH / 2;j < -x_start + SCREEN_WIDTH / 2; j += 512){
- glTexCoord2i(1,1);glVertex2i(j ,0);
- glTexCoord2i(0,1);glVertex2i(j+512,0);
- glTexCoord2i(0,0);glVertex2i(j+512,512);
- glTexCoord2i(1,0);glVertex2i(j ,512);
- }
+ //for(j = x_start - SCREEN_WIDTH / 2;j < -x_start + SCREEN_WIDTH / 2; j += 512){
+ glTexCoord2i(0,1); glVertex2i( x_start - SCREEN_WIDTH / 2,0);
+ glTexCoord2i((-x_start*2+SCREEN_WIDTH)/512,1);glVertex2i(-x_start + SCREEN_WIDTH / 2,0);
+ glTexCoord2i((-x_start*2+SCREEN_WIDTH)/512,0);glVertex2i(-x_start + SCREEN_WIDTH / 2,SCREEN_HEIGHT);
+ glTexCoord2i(0,0); glVertex2i( x_start - SCREEN_WIDTH / 2,SCREEN_HEIGHT);
+ //}
glEnd();
++ glUseProgram(0);
glDisable(GL_TEXTURE_2D);
/*
/*
* Draw the ground.
*/
--
++ glUseProgram(shaderProgram);
++ glUniform1i(glGetUniformLocation(shaderProgram, "sampler"), 0);
glBegin(GL_QUADS);
for(;i < ie - GEN_INC;i++){
safeSetColor(150,100,50);
glVertex2i(x ,line[i].y - 50);
}
glEnd();
++ glUseProgram(0);
/*
* Draw all entities.
-#version 120\r
-void main(){\r
- gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);\r
-}\r
++uniform sampler2D sampler;\r
++\r
+uniform vec2 lightLocation;\r
+uniform vec3 lightColor;\r
- uniform float screenHeight;\r
++uniform float amb;\r
++// uniform float lightStrength;\r
++//uniform float screenHeight;\r
++void main() {\r
++ float lightAdd = 1.0f;\r
+\r
- float radius = 4.9;\r
- float minLight = .01;\r
- float a = .01;\r
- float b = 1.0 / (radius*radius * minLight);\r
++ float dist = length(lightLocation - gl_FragCoord.xy);\r
++ float attenuation=1.0/(1.0+0.01*dist+0.00000000001*dist*dist);\r
+\r
- void main() {\r
- float distance = length(lightLocation - gl_FragCoord.xy);\r
- //float attenuation = 1.0 / (1.0 + a*distance + b*distance*distance);\r
- float attenuation = clamp(1.0 - distance*distance/(radius*radius), 0.0, 1.0); attenuation *= attenuation;\r
- vec4 color = vec4(attenuation, attenuation, attenuation, attenuation) * vec4(lightColor, 1);\r
++ //vec4 color = vec4(1.0f,1.0f,1.0f,1.0f);\r
++ vec4 color = vec4(attenuation, attenuation, attenuation, 1.0f) * vec4(lightColor, 1.0f);\r
++ //color = color + vec4((vec3(lightColor.r + amb, lightColor.g + amb, lightColor.b + amb)*0.25f),1.0f);\r
++\r
++ vec2 coords = gl_TexCoord[0].st;\r
++ vec4 tex = texture2D(sampler, coords);\r
+\r
- gl_FragColor = color;\r
++ color += vec4(amb,amb,amb,1.0f+amb);\r
++ gl_FragColor = tex * vec4(color)*tex.a;\r
+}