+++ /dev/null
-LIBS = -lGL -lGLEW -lSDL2main -lSDL2 -lfreetype -lSDL2_image -lSDL2_mixer
-
-FLAGS = -m32 -std=c++11 -Iinclude -Iinclude/freetype2
-
-all:
- @g++ $(FLAGS) -o main main.cpp $(LIBS)
\ No newline at end of file
+++ /dev/null
-#include <GL/glew.h>
-
-#include <SDL2/SDL.h>
-#include <SDL2/SDL_opengl.h>
-#include <SDL2/SDL_image.h>
-#include <SDL2/SDL_mixer.h>
-#include <iostream>
-
-#define SCREEN_WIDTH 1280
-#define SCREEN_HEIGHT 720
-
-SDL_Window* window;
-SDL_GLContext mainGLContext = NULL;
-
-int main(void){
- if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0){
- std::cout << "SDL was not able to initialize! Error: " << SDL_GetError() << std::endl;
- return -1;
- }
- // Run SDL_Quit when main returns
- atexit(SDL_Quit);
-
- window = SDL_CreateWindow("Ass",
- SDL_WINDOWPOS_UNDEFINED, // Spawn the window at random (undefined) x and y coordinates
- SDL_WINDOWPOS_UNDEFINED, //
- SCREEN_WIDTH,
- SCREEN_HEIGHT,
- SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL
-#ifdef FULLSCREEN
- | SDL_WINDOW_FULLSCREEN
-#endif // FULLSCREEN
- );
-
- if(window==NULL){
- std::cout << "The window failed to generate! SDL_Error: " << SDL_GetError() << std::endl;
- return -1;
- }
-
- if((mainGLContext = SDL_GL_CreateContext(window)) == NULL){
- std::cout << "The OpenGL context failed to initialize! SDL_Error: " << SDL_GetError() << std::endl;
- return -1;
- }
-
-
- GLenum err;
- glewExperimental = GL_TRUE;
- if((err=glewInit()) != GLEW_OK){
- std::cout << "GLEW was not able to initialize! Error: " << glewGetErrorString(err) << std::endl;
- return -1;
- }
-
- SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
-
- glViewport(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
-
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
-
- bool gameRunning = true;
- while(gameRunning){
-
- }
- SDL_GL_DeleteContext(mainGLContext);
- SDL_DestroyWindow(window);
- return 0;
-}
\ No newline at end of file
void initColorIndex();
vec2 getIndex(Color c);
+ dim2 imageDim(const char *fileName);
}
/**
*/
Texturec(uint amt,const char **paths);
+ Texturec(std::vector<std::string>vec);
/**
* Frees memory taken by the image array.
int strCreateFunc(const char *equ);
+template<typename N, size_t s>
+size_t arrAmt(N (&)[s]){return s;}
+
extern void *NULLPTR;
#endif // COMMON_H
enum GENDER{
MALE,
FEMALE,
- NONE
+ TRANSBULLSHIT
};
enum MOB_SUB {
class Structures : public Entity{
public:
BUILD_SUB bsubtype;
+ World *inWorld;
char *inside;
+ char *textureLoc;
Structures();
~Structures();
*/
Texturec *bgTex;
-
+
/**
* Defines the set of background images that should be used for this world.
*/
*/
char *bgm;
+ std::vector<std::string>bgFiles;
+ std::vector<std::string>bgFilesIndoors;
public:
* A vector of all light elements in this world.
*/
- std::vector<Light > light;
+ std::vector<Light > light;
+
+ /**
+ * Vector of all building textures for the current world style
+ */
+
+ std::vector<std::string > sTexLoc;
+
/**
* NULLifies pointers and allocates necessary memory. This should be
* the structure.
*/
- void addStructure(BUILD_SUB subtype,float x,float y,const char *inside);
+ void addStructure(BUILD_SUB subtype,float x,float y, char* tex, const char *inside);
//void addVillage(int buildingCount, int npcMin, int npcMax,const char *inside);
/**
*/
void setBGM(const char *path);
+
+ /**
+ * Sets the worlds style folder
+ */
+
+ void setStyle(const char* pre);
/**
* Plays/stops this world's BGM. If `prev` is not NULL, that world's BGM
struct texture_t {
char *name;
GLuint tex;
+ dim2 dim;
} __attribute__ ((packed));
struct index_t{
GL_UNSIGNED_BYTE,
image->pixels
);
-
- SDL_FreeSurface(image); // Free the surface
LoadedTexture[LoadedTextureCounter] = new struct texture_t; //(struct texture_t *)malloc(sizeof(struct texture_t));
LoadedTexture[LoadedTextureCounter]->name = new char[strlen(fileName)+1]; //(char *)malloc(safe_strlen(fileName));
LoadedTexture[LoadedTextureCounter]->tex = object;
strcpy(LoadedTexture[LoadedTextureCounter]->name,fileName);
+ LoadedTexture[LoadedTextureCounter]->dim.x = image->w;
+ LoadedTexture[LoadedTextureCounter]->dim.y = image->h;
LoadedTextureCounter++;
+ SDL_FreeSurface(image); // Free the surface
+
return object;
}
+
+ dim2 imageDim(const char *fileName){
+ for(unsigned int i=0;i<LoadedTextureCounter;i++){
+ if(!strcmp(LoadedTexture[i]->name,fileName)){
+ return LoadedTexture[i]->dim;
+ }
+ }
+ return {0,0};
+ }
void freeTextures(void){
for(unsigned int i=0;i<LoadedTextureCounter;i++){
va_end(fNames);
}
+Texturec::Texturec(std::vector<std::string>v){
+ texState = 0;
+ image = new GLuint[v.size()];
+ for(unsigned int i = 0; i < v.size(); i++){
+ image[i] = Texture::loadTexture(v[i].c_str());
+ }
+}
+
Texturec::Texturec(uint amt,const char **paths){
texState = 0;
image = new GLuint[amt];
extern const char *itemName;
-std::string sTexLoc[] = { "assets/townhall.png",
- "assets/house1.png",
- "assets/house2.png",
- "assets/house1.png",
- "assets/house1.png",
- "assets/fountain1.png",
- "assets/lampPost1.png",
- "assets/brazzier.png"};
-
GLuint waterTex;
void initEntity(){
subtype = 0;
health = maxHealth = 100;
speed = 1;
- tex = new Texturec(9, "assets/playerk.png",
- "assets/playerk1.png",
- "assets/playerk2.png",
- "assets/playerk3.png",
- "assets/playerk4.png",
- "assets/playerk5.png",
- "assets/playerk6.png",
- "assets/playerk7.png",
- "assets/playerk8.png");
+ tex = new Texturec(9, "assets/player/playerk.png",
+ "assets/player/playerk1.png",
+ "assets/player/playerk2.png",
+ "assets/player/playerk3.png",
+ "assets/player/playerk4.png",
+ "assets/player/playerk5.png",
+ "assets/player/playerk6.png",
+ "assets/player/playerk7.png",
+ "assets/player/playerk8.png");
inv = new Inventory(PLAYER_INV_SIZE);
}
Player::~Player(){
tex = new Texturec(1,"assets/NPC.png");
inv = new Inventory(NPC_INV_SIZE);
- randDialog = 6;//rand() % 12 - 1;
+ randDialog = rand() % 12 - 1;
dialogIndex = 0;
}
NPC::~NPC(){
alive = true;
bsubtype = sub;
+ dim2 dim;
/*
* tempN is the amount of entities that will be spawned in the village. Currently the village
//unsigned int tempN = (getRand() % 5 + 2);
switch(sub){
- case TOWN_HALL:
- tex = new Texturec(1, sTexLoc[sub].c_str());
- width = 50 * HLINE;
- height = 40 * HLINE;
-
- break;
- case HOUSE:
- tex = new Texturec(1, sTexLoc[sub].c_str());
- width = 50 * HLINE;
- height = 40 * HLINE;
- break;
- case FOUNTAIN:
- tex = new Texturec(1, sTexLoc[sub].c_str());
- width = 50 * HLINE;
- height = 40 * HLINE;
- break;
- case LAMP_POST:
- tex = new Texturec(1, sTexLoc[sub].c_str());
- width = 10 * HLINE;
- height = 40 * HLINE;
- break;
- case FIRE_PIT:
- tex = new Texturec(1, sTexLoc[sub].c_str());
- width = 12 * HLINE;
- height = 12 * HLINE;
- break;
default:
+ tex = new Texturec(1, textureLoc ? textureLoc : inWorld->sTexLoc[sub].c_str());
+ dim = Texture::imageDim(textureLoc ? textureLoc : inWorld->sTexLoc[sub].c_str());
+ width = dim.x;
+ height = dim.y;
break;
}
return 0;
#ifdef DEBUG
DEBUG_printf("Initialized FreeType2.\n",NULL);
#endif // DEBUG
- dialogClick = Mix_LoadWAV("assets/click.wav");
+ dialogClick = Mix_LoadWAV("assets/sounds/click.wav");
battleStart = Mix_LoadWAV("assets/sounds/frig.wav");
sanic = Mix_LoadWAV("assets/sounds/sanic.wav");
- Mix_Volume(1,50);
+ //Mix_Volume(1,50);
}
void destroyFonts(void){
* Draws a character at the specified coordinates, aborting if the character is unknown.
*/
- vec2 putChar(float x,float y,char c){
+ vec2 putChar(float xx,float yy,char c){
vec2 c1,c2;
-
+
+ int x = xx, y = yy;
+
/*
* Get the width and height of the rendered character.
*/
*/
void drawMenu(Menu *menu){
-
- setFontSize(20);
+ setFontSize(18);
SDL_Event e;
mouse.x=premouse.x+offset.x-(SCREEN_WIDTH/2);
//currentWorld->addVillage(player->loc.x, player->loc.y, 5, 10, 100, NULL);
break;
case SDLK_b:
- currentWorld->addStructure(FIRE_PIT, player->loc.x, player->loc.y, NULL);
+ currentWorld->addStructure(FIRE_PIT, player->loc.x, player->loc.y, NULL, NULL);
currentWorld->addLight({player->loc.x + SCREEN_WIDTH/2, player->loc.y},{1.0f,1.0f,1.0f});
break;
case SDLK_F12:
WEATHER weather = SUNNY;
-const char *bgPaths[2][7]={
- {"assets/bg.png", // Daytime background
- "assets/bgn.png", // Nighttime background
- "assets/bgFarMountain.png", // Furthest layer
- "assets/forestTileBack.png", // Closer layer
- "assets/forestTileMid.png", // Near layer
- "assets/forestTileFront.png", // Closest layer
- "assets/dirt.png"}, // Dirt
- {"assets/bgWoodTile.png",
- NULL,
- NULL,
- NULL,
- NULL,
- NULL}
+// const char *bgPaths[2][7]={
+// {"assets/bg.png", // Daytime background
+// "assets/bgn.png", // Nighttime background
+// "assets/bgFarMountain.png", // Furthest layer
+// "assets/forestTileBack.png", // Closer layer
+// "assets/forestTileMid.png", // Near layer
+// "assets/forestTileFront.png", // Closest layer
+// "assets/dirt.png"}, // Dirt
+// {"assets/bgWoodTile.png",
+// NULL,
+// NULL,
+// NULL,
+// NULL,
+// NULL}
+// };
+
+const std::string bgPaths[2][8]={
+ {"bg.png", // Daytime background
+ "bgn.png", // Nighttime background
+ "bgFarMountain.png", // Furthest layer
+ "forestTileBack.png", // Closer layer
+ "forestTileMid.png", // Near layer
+ "forestTileFront.png", // Closest layer
+ "dirt.png", // Dirt
+ "grass.png"}, // Grass
+ {"bgWoodTile.png",
+ "bgWoodTile.png",
+ "bgWoodTile.png",
+ "bgWoodTile.png",
+ "bgWoodTile.png",
+ "bgWoodTile.png",
+ "bgWoodTile.png",
+ "bgWoodTile.png"}
};
-Texturec *grassT;
+const std::string buildPaths[] = { "townhall.png",
+ "house1.png",
+ "house2.png",
+ "house1.png",
+ "house1.png",
+ "fountain1.png",
+ "lampPost1.png",
+ "brazzier.png"};
const float bgDraw[3][3]={
{100,240,.6 },
bgType = bgt;
switch(bgt){
case BG_FOREST:
- bgTex = new Texturec(7,bgPaths[0]);
+ bgTex = new Texturec(bgFiles);
break;
case BG_WOODHOUSE:
- bgTex = new Texturec(1,bgPaths[1]);
+ bgTex = new Texturec(bgFilesIndoors);
break;
}
}
+void World::setStyle(const char* pre){
+ std::string prefix = pre ? pre : "assets/style/classic/";
+ for(uint i = 0; i < arrAmt(buildPaths);i++){
+ sTexLoc.push_back(prefix);
+ sTexLoc.back() += buildPaths[i];
+ std::cout << sTexLoc.back() << std::endl;
+ }
+ prefix += "bg/";
+ for(uint i = 0; i < arrAmt(bgPaths[0]);i++){
+ bgFiles.push_back(prefix);
+ bgFiles.back() += bgPaths[0][i];
+ std::cout << bgFiles.back() << std::endl;
+ }
+ for(uint i = 0; i < arrAmt(bgPaths[1]);i++){
+ bgFilesIndoors.push_back(prefix);
+ bgFilesIndoors.back() += bgPaths[1][i];
+ std::cout << bgFilesIndoors.back() << std::endl;
+ }
+}
+
World::World(void){
bgm = NULL;
star = new vec2[100];
memset(star,0,100 * sizeof(vec2));
- grassT = new Texturec(1,"assets/grass.png");
}
void World::deleteEntities(void){
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(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);
+ 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;
glEnable(GL_TEXTURE_2D);
glActiveTexture(GL_TEXTURE0);
- grassT->bind(0);
+ bgTex->bindNext();
glUseProgram(shaderProgram);
glUniform1i(glGetUniformLocation(shaderProgram, "sampler"), 0);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); //for the s direction
goto LOOOOP;
}*/
}
-void World::addStructure(BUILD_SUB sub, float x,float y,const char *inside){
+void World::addStructure(BUILD_SUB sub, float x,float y, char *tex, const char *inside){
build.push_back(new Structures());
+ build.back()->inWorld = this;
+ build.back()->textureLoc = tex;
build.back()->spawn(sub,x,y);
-
+
if(inside)
strcpy((build.back()->inside = new char[1 + strlen(inside)]),inside);
else
World *World::goWorldLeft(Player *p){
World *tmp;
-
- if(toLeft && p->loc.x < x_start + HLINE * 15){
+ if(toLeft && p->loc.x < x_start + (int)HLINE * 15){
tmp = loadWorldFromXML(toLeft);
p->loc.x = -tmp->x_start - HLINE * 10;
tmp->setToRight(ptr);
else abort();
}else if(!strcmp(name,"style")){
+ tmp->setStyle(wxml->Attribute("folder"));
tmp->setBackground((WORLD_BG_TYPE)wxml->UnsignedAttribute("background"));
tmp->setBGM(wxml->Attribute("bgm"));
}else if(!strcmp(name,"generation")){
}else if(!strcmp(name,"structure")){
ptr = wxml->Attribute("inside");
- if(wxml->QueryFloatAttribute("x",&spawnx) != XML_NO_ERROR)
- tmp->addStructure((BUILD_SUB)wxml->UnsignedAttribute("type"),getRand() % tmp->getTheWidth() / 2.0f,100,ptr);
- else
- tmp->addStructure((BUILD_SUB)wxml->UnsignedAttribute("type"),spawnx,wxml->FloatAttribute("y"),ptr);
+ tmp->addStructure((BUILD_SUB)wxml->UnsignedAttribute("type"),
+ wxml->QueryFloatAttribute("x",&spawnx) != XML_NO_ERROR ?
+ getRand() % tmp->getTheWidth() / 2.0f :
+ spawnx,
+ 100,
+ (char*)wxml->Attribute("texture"),
+ ptr);
}else if(!strcmp(name,"trigger")){
tmp->addMob(MS_TRIGGER,wxml->FloatAttribute("x"),0,commonTriggerFunc);
tmp->mob.back()->heyid = wxml->Attribute("id");
<?xml version="1.0"?>
<World>
- <style background="0" bgm="assets/music/embark.wav" />
+ <style background="0" bgm="assets/music/embark.wav" folder="assets/style/classic/" />
<generation type="Random" width="1600" />
-
- <link right="playerSpawnHill2.xml" />
+ <link left="playerSpawnHill2.xml" />
<mob type="1" aggressive="false" />
<npc name="Ralph" hasDialog="true" />
<npc name="Johnny" hasDialog="true" />
- <structure type="5" inside="playerSpawnHill1_Building1.xml" />
+ <structure type="5" inside="playerSpawnHill1_Building1.xml"/>
+ <village>
+
+ </village>
</World>
</text>
<text id="2" call="Johnny" callid="1">
- what you have done it to trick Microsoft
+ what you have done it to trick Microsoft?
</text>
</Dialog>
<?xml version="1.0"?>
<World>
- <style background="0" bgm="assets/music/embark.wav" />
- <generation type="Random" width="500" />
+ <style background="0" bgm="assets/music/embark.wav" folder="assets/style/rustic/"/>
+ <generation type="Random" width="1000" />
+ <structure type="5" inside="playerSpawnHill1_Building1.xml"/>
- <link left="playerSpawnHill1.xml" />
+ <link right="playerSpawnHill1.xml" />
</World>