Bug fixes
This commit is contained in:
parent
880ce752d4
commit
94a8df620d
|
@ -1,10 +1,2 @@
|
||||||
*.swp
|
|
||||||
*.o
|
*.o
|
||||||
*.swo
|
*.sw*
|
||||||
*.swn
|
|
||||||
*.swk
|
|
||||||
*.swl
|
|
||||||
*.swm
|
|
||||||
*.swi
|
|
||||||
*.swh
|
|
||||||
*.swj
|
|
||||||
|
|
2
Makefile
2
Makefile
|
@ -33,7 +33,7 @@ camera.o: camera.cpp camera.h
|
||||||
$(CC) -c camera.cpp
|
$(CC) -c camera.cpp
|
||||||
|
|
||||||
texture.o: texture.cpp texture.h
|
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
|
powerup.o: powerup.cpp powerup.h
|
||||||
$(CC) -c powerup.cpp $(LINKER_FLAGS)
|
$(CC) -c powerup.cpp $(LINKER_FLAGS)
|
||||||
|
|
2
main.cpp
2
main.cpp
|
@ -80,7 +80,7 @@ int main(int argc, char* args[]){
|
||||||
ground.print(camera.getPosX());
|
ground.print(camera.getPosX());
|
||||||
ground2.print(camera.getPosX());
|
ground2.print(camera.getPosX());
|
||||||
powerup.print(camera.getPosX());
|
powerup.print(camera.getPosX());
|
||||||
|
|
||||||
//Entity *ePwrUp = &powerup;
|
//Entity *ePwrUp = &powerup;
|
||||||
/*posweg.check(wallA.getRectangle());
|
/*posweg.check(wallA.getRectangle());
|
||||||
posweg.check(wallB.getRectangle());
|
posweg.check(wallB.getRectangle());
|
||||||
|
|
44
player.cpp
44
player.cpp
|
@ -13,10 +13,10 @@ void Player::print(int cameraX){
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_SetRenderDrawColor(*renderer,0xFF,0,0,0xFF);
|
SDL_SetRenderDrawColor(*renderer,0xFF,0,0,0xFF);
|
||||||
ply.render(&cameraFix,currentFrame,renderer);
|
ply.render(&cameraFix,&plyFrame[0]);
|
||||||
if(ifRunning)ply.render(&cameraFix,&plyFrame[5],renderer);
|
//ply.render(currentFrame);
|
||||||
|
if(ifRunning)ply.render(&cameraFix,&plyFrame[1]);
|
||||||
|
|
||||||
currentFrame = &plyFrame[0];
|
|
||||||
|
|
||||||
oldPosX = posX;
|
oldPosX = posX;
|
||||||
oldPosY = posY;
|
oldPosY = posY;
|
||||||
|
@ -35,32 +35,26 @@ Player::Player(int x,int y, int w, int h, SDL_Renderer** render){
|
||||||
oldPosX = posX;
|
oldPosX = posX;
|
||||||
oldPosY = posY;
|
oldPosY = posY;
|
||||||
|
|
||||||
|
ply.setRenderer(renderer);
|
||||||
loadMedia();
|
loadMedia();
|
||||||
|
|
||||||
currentFrame = &plyFrame[0];
|
currentFrame = &plyFrame[0];
|
||||||
};
|
};
|
||||||
|
|
||||||
bool Player::loadMedia(){
|
void Player::loadMedia(){
|
||||||
bool success = true;
|
ply.loadTexture("textures/player.png");
|
||||||
|
|
||||||
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++;
|
|
||||||
} }
|
|
||||||
}
|
|
||||||
|
|
||||||
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(){
|
int Player::intVelX(){
|
||||||
return static_cast<int>(velocityX);
|
return static_cast<int>(velocityX);
|
||||||
|
@ -210,13 +204,11 @@ int Player::check(SDL_Rect rectA, int type){
|
||||||
ground = true;
|
ground = true;
|
||||||
collision = 2;
|
collision = 2;
|
||||||
velocityY = 0;
|
velocityY = 0;
|
||||||
currentFrame = &plyFrame[1];
|
|
||||||
}
|
}
|
||||||
//Bottom collision
|
//Bottom collision
|
||||||
else if(posY == b2Y){
|
else if(posY == b2Y){
|
||||||
collision = 3;
|
collision = 3;
|
||||||
topCollision = true;
|
topCollision = true;
|
||||||
currentFrame = &plyFrame[3];
|
|
||||||
if(velocityY > 0)
|
if(velocityY > 0)
|
||||||
velocityY -= static_cast<int>(velocityY);
|
velocityY -= static_cast<int>(velocityY);
|
||||||
}
|
}
|
||||||
|
@ -228,14 +220,12 @@ int Player::check(SDL_Rect rectA, int type){
|
||||||
//Left collision
|
//Left collision
|
||||||
if(posX + szW == bX){
|
if(posX + szW == bX){
|
||||||
collision = 4;
|
collision = 4;
|
||||||
currentFrame = &plyFrame[2];
|
|
||||||
if(velocityX > 0)
|
if(velocityX > 0)
|
||||||
velocityX -= static_cast<int>(velocityX);
|
velocityX -= static_cast<int>(velocityX);
|
||||||
}
|
}
|
||||||
//Right collision
|
//Right collision
|
||||||
else if(posX == b2X){
|
else if(posX == b2X){
|
||||||
collision = 5;
|
collision = 5;
|
||||||
currentFrame = &plyFrame[4];
|
|
||||||
if(velocityX < 0)
|
if(velocityX < 0)
|
||||||
velocityX -= static_cast<int>(velocityX);
|
velocityX -= static_cast<int>(velocityX);
|
||||||
}
|
}
|
||||||
|
|
6
player.h
6
player.h
|
@ -18,8 +18,7 @@ class Player: public Entity{
|
||||||
int check(SDL_Rect rectA,int type);
|
int check(SDL_Rect rectA,int type);
|
||||||
Player(int x, int y,int w, int h,SDL_Renderer** render);
|
Player(int x, int y,int w, int h,SDL_Renderer** render);
|
||||||
private:
|
private:
|
||||||
int* coll;
|
void loadMedia();
|
||||||
bool loadMedia();
|
|
||||||
void move();
|
void move();
|
||||||
int intVelX();
|
int intVelX();
|
||||||
SDL_Renderer** renderer;
|
SDL_Renderer** renderer;
|
||||||
|
@ -36,8 +35,7 @@ class Player: public Entity{
|
||||||
|
|
||||||
PosuTexture ply;
|
PosuTexture ply;
|
||||||
SDL_Rect* currentFrame;
|
SDL_Rect* currentFrame;
|
||||||
const static int plyNum = 6;
|
SDL_Rect plyFrame[2];
|
||||||
SDL_Rect plyFrame[plyNum];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
37
texture.cpp
37
texture.cpp
|
@ -2,28 +2,32 @@
|
||||||
|
|
||||||
PosuTexture::PosuTexture(){
|
PosuTexture::PosuTexture(){
|
||||||
//Initialize variables
|
//Initialize variables
|
||||||
texture = NULL;
|
|
||||||
szW = 0;
|
szW = 0;
|
||||||
szH = 0;
|
szH = 0;
|
||||||
|
|
||||||
IMG_Init(IMG_INIT_JPG);
|
IMG_Init(IMG_INIT_PNG);
|
||||||
//Set renderer
|
//Set renderer
|
||||||
}
|
};
|
||||||
|
|
||||||
|
void PosuTexture::setRenderer(SDL_Renderer** render){
|
||||||
|
renderer = render;
|
||||||
|
};
|
||||||
|
|
||||||
PosuTexture::~PosuTexture(){
|
PosuTexture::~PosuTexture(){
|
||||||
//Deallocate
|
//Deallocate
|
||||||
free();
|
//free();
|
||||||
}
|
};
|
||||||
|
|
||||||
bool PosuTexture::loadTexture(std::string path,SDL_Renderer** renderer){
|
void PosuTexture::loadTexture(std::string path){
|
||||||
//Get rid of preexisting texture
|
//Get rid of preexisting texture
|
||||||
free();
|
free();
|
||||||
|
|
||||||
//Load image at specified path
|
//Load image at specified path
|
||||||
SDL_Surface* loadedSurface = IMG_Load( path.c_str() );
|
SDL_Surface* loadedSurface = IMG_Load( path.c_str() );
|
||||||
|
|
||||||
if(loadedSurface == NULL)
|
if(loadedSurface == NULL){
|
||||||
std::cout << "Couldn't load " << path.c_str() << std::endl;
|
std::cout << "Couldn't load " << path.c_str() << std::endl;
|
||||||
|
}
|
||||||
else{
|
else{
|
||||||
//Create texture from surface pixels
|
//Create texture from surface pixels
|
||||||
texture = SDL_CreateTextureFromSurface
|
texture = SDL_CreateTextureFromSurface
|
||||||
|
@ -41,9 +45,7 @@ bool PosuTexture::loadTexture(std::string path,SDL_Renderer** renderer){
|
||||||
//Get rid of old loaded surface
|
//Get rid of old loaded surface
|
||||||
SDL_FreeSurface(loadedSurface);
|
SDL_FreeSurface(loadedSurface);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
return texture != NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PosuTexture::free(){
|
void PosuTexture::free(){
|
||||||
//Free texture if it exists
|
//Free texture if it exists
|
||||||
|
@ -53,9 +55,10 @@ void PosuTexture::free(){
|
||||||
szW = 0;
|
szW = 0;
|
||||||
szH = 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
|
//Set clip rendering dimensions
|
||||||
/*if(frame != NULL){
|
/*if(frame != NULL){
|
||||||
quad.w = frame->w;
|
quad.w = frame->w;
|
||||||
|
@ -64,12 +67,14 @@ void PosuTexture::render(SDL_Rect* quad,SDL_Rect* frame,SDL_Renderer** renderer)
|
||||||
|
|
||||||
//Render to screen
|
//Render to screen
|
||||||
SDL_RenderCopy(*renderer,texture,frame,quad);
|
SDL_RenderCopy(*renderer,texture,frame,quad);
|
||||||
}
|
//SDL_RenderFillRect(*renderer,quad);
|
||||||
|
//std::cout << "ye" << std::endl;
|
||||||
|
};
|
||||||
|
|
||||||
int PosuTexture::getWidth(){
|
int PosuTexture::getWidth(){
|
||||||
return szW;
|
return szW;
|
||||||
}
|
};
|
||||||
|
|
||||||
int PosuTexture::getHeight(){
|
int PosuTexture::getHeight(){
|
||||||
return szH;
|
return szH;
|
||||||
}
|
};
|
||||||
|
|
|
@ -12,14 +12,17 @@ class PosuTexture{
|
||||||
public:
|
public:
|
||||||
PosuTexture();
|
PosuTexture();
|
||||||
~PosuTexture();
|
~PosuTexture();
|
||||||
bool loadTexture(std::string path,SDL_Renderer** renderer);
|
void loadTexture(std::string path);
|
||||||
void free();
|
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 getWidth();
|
||||||
int getHeight();
|
int getHeight();
|
||||||
|
void setRenderer (SDL_Renderer** render);
|
||||||
private:
|
private:
|
||||||
SDL_Texture* texture;
|
SDL_Texture* texture = NULL;
|
||||||
int szW, szH;
|
int szW, szH;
|
||||||
|
SDL_Renderer** renderer;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue