Cleaning up a bit things
This commit is contained in:
parent
55a0f0e064
commit
4f9d042877
|
@ -0,0 +1,2 @@
|
|||
*.swp
|
||||
*.o
|
2
Makefile
2
Makefile
|
@ -8,7 +8,7 @@ COMPILER_FLAGS = -w
|
|||
|
||||
LINKER_FLAGS = -lSDL2 -std=gnu++11
|
||||
|
||||
OBJ_NAME = main.exe
|
||||
OBJ_NAME = bin/main
|
||||
|
||||
|
||||
all: $(OBJS)
|
||||
|
|
|
@ -6,8 +6,6 @@ void Block::print(int x, int y, int w, int h,SDL_Renderer* renderer){
|
|||
szW = w;
|
||||
szH = h;
|
||||
|
||||
//std::cout<<x<<" "<<y<<" "<<w<<" "<<h<<" / ";
|
||||
|
||||
rect = {posX, posY, szW, szH};
|
||||
|
||||
SDL_SetRenderDrawColor(renderer,0,0xFF,0,0xFF);
|
||||
|
|
31
main.cpp
31
main.cpp
|
@ -18,7 +18,6 @@ void init();
|
|||
bool loadMedia();
|
||||
void close();
|
||||
void gameLoop();
|
||||
int check(SDL_Rect rectA, SDL_Rect rectB);
|
||||
|
||||
Player posweg;
|
||||
Block ground;
|
||||
|
@ -90,33 +89,3 @@ int main(int argc, char* args[]){
|
|||
close();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int check(SDL_Rect rectA, SDL_Rect rectB){
|
||||
|
||||
int collision = 0;
|
||||
|
||||
int aX = rectA.x;
|
||||
int aY = rectA.y;
|
||||
int a2X = rectA.x + rectA.w;
|
||||
int a2Y = rectA.y + rectA.h;
|
||||
|
||||
int bX = rectB.x;
|
||||
int bY = rectB.y;
|
||||
int b2X = rectB.x + rectB.w;
|
||||
int b2Y = rectB.y + rectB.h;
|
||||
|
||||
if(aX > bX and aX < b2X){
|
||||
if(aY > bY and aY < b2Y) collision += 1;
|
||||
if(a2Y > bY and a2Y < b2Y) collision += 2;
|
||||
}
|
||||
|
||||
if(a2X > bX and a2X < b2X){
|
||||
if(aY > bY and aY < b2Y) collision += 4;
|
||||
if(a2Y > bY and a2Y < b2Y) collision += 8;
|
||||
}
|
||||
|
||||
//std::cout<<aX<<" "<<a2X<<" "<<aY<<" "<<a2Y<<" / ";
|
||||
//std::cout<<bX<<" "<<b2X<<" "<<bY<<" "<<b2Y;
|
||||
|
||||
return collision;
|
||||
};
|
||||
|
|
11
player.cpp
11
player.cpp
|
@ -30,9 +30,9 @@ int Player::intVelX(){
|
|||
};
|
||||
|
||||
void Player::move(){
|
||||
//float dt = dTime.getDt();
|
||||
float dt = 0.016;
|
||||
|
||||
float dt = dTime.getDt();
|
||||
|
||||
//Set keyboard variable
|
||||
const Uint8* currentKeyStates = SDL_GetKeyboardState(NULL);
|
||||
|
||||
//Intializing variables
|
||||
|
@ -45,11 +45,13 @@ void Player::move(){
|
|||
int gravity = 800; //Gravity force
|
||||
int jump = 500; //Jump force
|
||||
|
||||
//Check keyboard current state
|
||||
if(currentKeyStates[SDL_SCANCODE_LEFT]) direction += -1;
|
||||
if(currentKeyStates[SDL_SCANCODE_RIGHT]) direction += 1;
|
||||
if(!currentKeyStates[SDL_SCANCODE_LSHIFT] and !isRunning) run = 1;
|
||||
if(run!=1) dur /= 1;
|
||||
|
||||
//Set velocity
|
||||
if(direction == 1 and intVelX() < speed){
|
||||
velocityX += speed * dt * dur;
|
||||
if(intVelX() > speed) velocityX = speed;
|
||||
|
@ -69,7 +71,7 @@ void Player::move(){
|
|||
}
|
||||
else if(velocityX <= 1 or velocityX >= -1) velocityX = 0;
|
||||
|
||||
//Jump and gravity key logic
|
||||
//Jump and gravity logic
|
||||
if(ground){
|
||||
isRunning = false;
|
||||
if(currentKeyStates[SDL_SCANCODE_SPACE] and !topCollision){
|
||||
|
@ -83,6 +85,7 @@ void Player::move(){
|
|||
if(isRunning == false) run = 1;
|
||||
}
|
||||
|
||||
//Get the position and update the velY with gravity
|
||||
velocityY -= gravity * dt;
|
||||
float x = velocityX * dt * run;
|
||||
float y = velocityY * dt;
|
||||
|
|
4
player.h
4
player.h
|
@ -13,7 +13,6 @@ class Entity;
|
|||
|
||||
class Player: public Entity{
|
||||
public:
|
||||
//Player(/*int* collision*/);
|
||||
void print();
|
||||
int check(SDL_Rect rectB);
|
||||
void init(int x, int y,int w, int h,SDL_Renderer** render);
|
||||
|
@ -27,13 +26,10 @@ class Player: public Entity{
|
|||
bool ground;
|
||||
bool topCollision;
|
||||
//int posX, posY;
|
||||
//int cVelocity, oldVelX, oldVelY, newVelX, newVelY;
|
||||
float velocityX = 0;
|
||||
float velocityY = 0;
|
||||
bool isRunning = false;
|
||||
int oldPosX, oldPosY;
|
||||
//int szW = 40;
|
||||
//int szH = 40;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue