Bug fixes

This commit is contained in:
posweg 2017-05-06 09:52:25 +02:00
parent 880ce752d4
commit 94a8df620d
No known key found for this signature in database
GPG Key ID: 6F5B526E5F8D81DB
8 changed files with 49 additions and 61 deletions

10
.gitignore vendored
View File

@ -1,10 +1,2 @@
*.swp
*.o
*.swo
*.swn
*.swk
*.swl
*.swm
*.swi
*.swh
*.swj
*.sw*

View File

@ -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)

BIN
main

Binary file not shown.

View File

@ -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());

View File

@ -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<int>(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<int>(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<int>(velocityX);
}
//Right collision
else if(posX == b2X){
collision = 5;
currentFrame = &plyFrame[4];
if(velocityX < 0)
velocityX -= static_cast<int>(velocityX);
}

View File

@ -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

View File

@ -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;
}
};

View File

@ -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