diff --git a/.gitignore b/.gitignore index a9e50e9..4826d30 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,2 @@ -*.swp *.o -*.swo -*.swn -*.swk -*.swl -*.swm -*.swi -*.swh -*.swj +*.sw* diff --git a/Makefile b/Makefile index 425d00a..95261c2 100644 --- a/Makefile +++ b/Makefile @@ -33,7 +33,7 @@ camera.o: camera.cpp camera.h $(CC) -c camera.cpp texture.o: texture.cpp texture.h - $(CC) -c -lSDL2_image texture.cpp + $(CC) -c -lSDL2_image texture.cpp $(LINKER_FLAGS) powerup.o: powerup.cpp powerup.h $(CC) -c powerup.cpp $(LINKER_FLAGS) diff --git a/main b/main index 94d6ed8..ab338ce 100755 Binary files a/main and b/main differ diff --git a/main.cpp b/main.cpp index d9a878e..fb824a5 100644 --- a/main.cpp +++ b/main.cpp @@ -80,7 +80,7 @@ int main(int argc, char* args[]){ ground.print(camera.getPosX()); ground2.print(camera.getPosX()); powerup.print(camera.getPosX()); - + //Entity *ePwrUp = &powerup; /*posweg.check(wallA.getRectangle()); posweg.check(wallB.getRectangle()); diff --git a/player.cpp b/player.cpp index bbf2635..08cfe17 100644 --- a/player.cpp +++ b/player.cpp @@ -13,10 +13,10 @@ void Player::print(int cameraX){ } SDL_SetRenderDrawColor(*renderer,0xFF,0,0,0xFF); - ply.render(&cameraFix,currentFrame,renderer); - if(ifRunning)ply.render(&cameraFix,&plyFrame[5],renderer); + ply.render(&cameraFix,&plyFrame[0]); + //ply.render(currentFrame); + if(ifRunning)ply.render(&cameraFix,&plyFrame[1]); - currentFrame = &plyFrame[0]; oldPosX = posX; oldPosY = posY; @@ -35,32 +35,26 @@ Player::Player(int x,int y, int w, int h, SDL_Renderer** render){ oldPosX = posX; oldPosY = posY; + ply.setRenderer(renderer); loadMedia(); currentFrame = &plyFrame[0]; }; -bool Player::loadMedia(){ - bool success = true; - - if(!ply.loadTexture("textures/player.png",renderer)){ - std::cout << "Failed to load ply texture" << std::endl; - success = false; - } - else{ - int frame = 0; - for(int row = 0;row < 2;row++){ - for(int column = 0;column < 3;column++){ - plyFrame[frame].w=szW; - plyFrame[frame].h=szH; - plyFrame[frame].x=szW*column; - plyFrame[frame].y=szH*row; - frame++; - } } - } +void Player::loadMedia(){ + ply.loadTexture("textures/player.png"); - return success; -} + plyFrame[0].w = szW; + plyFrame[0].h = szH; + plyFrame[0].x = 0; + plyFrame[0].y = 0; + + plyFrame[1].w = szW; + plyFrame[1].h = szH; + plyFrame[1].x = 2*szW; + plyFrame[1].y = szH; + +}; int Player::intVelX(){ return static_cast(velocityX); @@ -210,13 +204,11 @@ int Player::check(SDL_Rect rectA, int type){ ground = true; collision = 2; velocityY = 0; - currentFrame = &plyFrame[1]; } //Bottom collision else if(posY == b2Y){ collision = 3; topCollision = true; - currentFrame = &plyFrame[3]; if(velocityY > 0) velocityY -= static_cast(velocityY); } @@ -228,14 +220,12 @@ int Player::check(SDL_Rect rectA, int type){ //Left collision if(posX + szW == bX){ collision = 4; - currentFrame = &plyFrame[2]; if(velocityX > 0) velocityX -= static_cast(velocityX); } //Right collision else if(posX == b2X){ collision = 5; - currentFrame = &plyFrame[4]; if(velocityX < 0) velocityX -= static_cast(velocityX); } diff --git a/player.h b/player.h index ca51e12..0a21cde 100644 --- a/player.h +++ b/player.h @@ -18,8 +18,7 @@ class Player: public Entity{ int check(SDL_Rect rectA,int type); Player(int x, int y,int w, int h,SDL_Renderer** render); private: - int* coll; - bool loadMedia(); + void loadMedia(); void move(); int intVelX(); SDL_Renderer** renderer; @@ -36,8 +35,7 @@ class Player: public Entity{ PosuTexture ply; SDL_Rect* currentFrame; - const static int plyNum = 6; - SDL_Rect plyFrame[plyNum]; + SDL_Rect plyFrame[2]; }; #endif diff --git a/texture.cpp b/texture.cpp index adbb5c3..c4a8800 100755 --- a/texture.cpp +++ b/texture.cpp @@ -2,28 +2,32 @@ PosuTexture::PosuTexture(){ //Initialize variables - texture = NULL; szW = 0; szH = 0; - IMG_Init(IMG_INIT_JPG); + IMG_Init(IMG_INIT_PNG); //Set renderer -} +}; + +void PosuTexture::setRenderer(SDL_Renderer** render){ + renderer = render; +}; PosuTexture::~PosuTexture(){ //Deallocate - free(); -} + //free(); +}; -bool PosuTexture::loadTexture(std::string path,SDL_Renderer** renderer){ +void PosuTexture::loadTexture(std::string path){ //Get rid of preexisting texture free(); - + //Load image at specified path SDL_Surface* loadedSurface = IMG_Load( path.c_str() ); - if(loadedSurface == NULL) + if(loadedSurface == NULL){ std::cout << "Couldn't load " << path.c_str() << std::endl; + } else{ //Create texture from surface pixels texture = SDL_CreateTextureFromSurface @@ -41,9 +45,7 @@ bool PosuTexture::loadTexture(std::string path,SDL_Renderer** renderer){ //Get rid of old loaded surface SDL_FreeSurface(loadedSurface); } - - return texture != NULL; -} +}; void PosuTexture::free(){ //Free texture if it exists @@ -53,9 +55,10 @@ void PosuTexture::free(){ szW = 0; szH = 0; } -} +}; -void PosuTexture::render(SDL_Rect* quad,SDL_Rect* frame,SDL_Renderer** renderer){ +void PosuTexture::render(SDL_Rect* quad,SDL_Rect* frame){ +//void PosuTexture::render(SDL_Rect* quad){ //Set clip rendering dimensions /*if(frame != NULL){ quad.w = frame->w; @@ -64,12 +67,14 @@ void PosuTexture::render(SDL_Rect* quad,SDL_Rect* frame,SDL_Renderer** renderer) //Render to screen SDL_RenderCopy(*renderer,texture,frame,quad); -} + //SDL_RenderFillRect(*renderer,quad); + //std::cout << "ye" << std::endl; +}; int PosuTexture::getWidth(){ return szW; -} +}; int PosuTexture::getHeight(){ return szH; -} +}; diff --git a/texture.h b/texture.h index 5d89156..6e5919f 100644 --- a/texture.h +++ b/texture.h @@ -12,14 +12,17 @@ class PosuTexture{ public: PosuTexture(); ~PosuTexture(); - bool loadTexture(std::string path,SDL_Renderer** renderer); + void loadTexture(std::string path); void free(); - void render(SDL_Rect* quad,SDL_Rect* frame,SDL_Renderer** renderer); + void render(SDL_Rect* quad,SDL_Rect* frame); + //void render(SDL_Rect* quad); int getWidth(); int getHeight(); + void setRenderer (SDL_Renderer** render); private: - SDL_Texture* texture; + SDL_Texture* texture = NULL; int szW, szH; + SDL_Renderer** renderer; }; #endif