--- /dev/null
+#include <common.h>
+
+/*SDL_Surface* loadTexture(char* filename){
+ SDL_Surface *optimizedSurface = NULL;
+ SDL_Surface *texture = IMG_Load(filename);
+ if(texture == NULL){
+ std::cout << "Unable to load an image properly from " << filename << "; Error: " << IMG_GetError() << std::endl;
+ }else{
+ optimizedSurface = SDL_ConvertSurface(texture, renderSurface->format, NULL);
+ if(optimizedSurface == NULL){
+ std::cout << "Unable to optimize image properly from " << filename << "; Error: " << IMG_GetError() << std::endl;
+ }
+ SDL_FreeSurface(texture);
+ }
+ return optimizedSurface;
+}*/
+
+GLuint loadTexture(const char *fileName){
+ SDL_Surface *image = IMG_Load(fileName);
+
+ //SDL_DisplayFormatAlpha(image);
+
+ unsigned object(0);
+
+ glGenTextures(1, &object);
+
+ glBindTexture(GL_TEXTURE_2D, object);
+
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image->w, image->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, image->pixels);
+
+ //Free surface
+ SDL_FreeSurface(image);
+
+ return object;
+}
\ No newline at end of file
}
void Entity::draw(void){ //draws the entities
+ glMatrixMode(GL_TEXTURE);
+ glLoadIdentity();
+ glEnable(GL_TEXTURE_2D);
+ glBindTexture(GL_TEXTURE_2D,texture);
+ glBegin(GL_QUADS);
if(type==NPCT){
- if(gender == MALE)
- glColor3ub(0,0,100);
- else if(gender == FEMALE)
+ if(gender == MALE){
+ glColor3ub(255,255,255);
+ 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);
+ }
+ else if(gender == FEMALE){
glColor3ub(255,105,180);
- }else if(type==STRUCTURET){
- glColor3ub(100,0,100);
+ 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);
+ }
+ }
+ if(type==PLAYERT){
+ if(right==true){
+ 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);
+ }if(left==true){
+ glRotatef(180.0f, 0.0f, 0.0f, 1.0f);
+ glScalef(-1.0f,1.0f,1.0f);
+ 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);
+ }
+
+ }else{
+ 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);
}
- glRectf(loc.x,loc.y,loc.x+width,loc.y+height);
+ glEnd();
+ glDisable(GL_TEXTURE_2D);
+ glMatrixMode(GL_MODELVIEW);
if(near){
ui::setFontSize(14);
ui::putText(loc.x,loc.y-ui::fontSize-HLINE/2,"%s",name);
alive = true;
ground = false;
near = true;
+ texture = loadTexture("assets/player.png");
}
void Player::interact(){ //the function that will cause the player to search for things to interact with
alive = true;
canMove = true;
near = false;
+ texture = loadTexture("assets/NPC.png");
}
void NPC::addAIFunc(int (*func)(NPC *)){
if(type == STRUCTURET){
loc.y=100;
width = 20 * HLINE;
- height = 16 * HLINE;
+ height = 20 * HLINE;
int tempN = (getRand() % 5 + 2); //amount of villagers that will spawn
for(int i=0;i<tempN;i++){
if(SDL_KEY==SDLK_a){ // Move left
left=true;
player->vel.x=-.15;
+ player->left = true;
+ player->right = false;
currentWorld=currentWorld->goWorldLeft(player);
}
if(SDL_KEY==SDLK_d){ // Move right
right=true;
player->vel.x=.15;
+ player->right = true;
+ player->left = false;
currentWorld=currentWorld->goWorldRight(player);
}
if(SDL_KEY==SDLK_s && player->ground==2){
KEYUP
*/
case SDL_KEYUP:
- if(SDL_KEY==SDLK_a)left=false; // Stop the player if movement keys are released
- if(SDL_KEY==SDLK_d)right=false;
+ if(SDL_KEY==SDLK_a){left=false;}// Stop the player if movement keys are released
+ if(SDL_KEY==SDLK_d){right=false;}
if(!left&&!right)player->vel.x=0;
if(SDL_KEY==SDLK_LSHIFT)player->speed = 1;