diff --git a/.gitignore b/.gitignore index 5b45ac6..ddf7b24 100644 --- a/.gitignore +++ b/.gitignore @@ -59,5 +59,15 @@ reated by https://www.gitignore.io/api/vim,c++,linux Session.vim # temporary .netrwhist -# auto-generated tag files -tags + +### CodeBlocks ### +# specific to CodeBlocks IDE +*.cbp +*.layout +*.depend + +# generated directories +bin/ +obj/ + +# auto-generated tag files \ No newline at end of file diff --git a/main b/main deleted file mode 100755 index c3ea9f8..0000000 Binary files a/main and /dev/null differ diff --git a/camera.cpp b/source/camera.cpp similarity index 100% rename from camera.cpp rename to source/camera.cpp diff --git a/camera.h b/source/camera.h similarity index 91% rename from camera.h rename to source/camera.h index 70e2f49..a88dc73 100644 --- a/camera.h +++ b/source/camera.h @@ -3,7 +3,7 @@ #ifndef __CAMERA_H_INCLUDED__ #define __CAMERA_H_INCLUDED__ -#include"player.h" +#include"entity/player.h" class Camera{ public: diff --git a/core.cpp b/source/core.cpp similarity index 91% rename from core.cpp rename to source/core.cpp index 4df2d03..4da476c 100644 --- a/core.cpp +++ b/source/core.cpp @@ -7,7 +7,7 @@ void Core::init(){ gWindow = SDL_CreateWindow("Platform Test!",SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,SCREEN_WIDTH,SCREEN_HEIGHT,SDL_WINDOW_SHOWN); gRenderer = SDL_CreateRenderer(gWindow,-1,SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); SDL_SetRenderDrawColor(gRenderer,0xFF,0xFF,0xFF,0xFF); - + sz = SCREEN_WIDTH/16; } @@ -23,7 +23,7 @@ void Core::close(){ int Core::coreInit(){ init(); - bool quit = false; + /*bool quit = false; SDL_Event e; while(!quit){ @@ -37,15 +37,18 @@ int Core::coreInit(){ SDL_RenderPresent(gRenderer); + }*/ + + if(menu(gRenderer) == 1){ + map1(); } - map1(); close(); return 0; }; void Core::map1(){ - Player posweg(&gRenderer); + Player posweg(&gRenderer); bool quit = false; SDL_Event e; @@ -61,8 +64,8 @@ void Core::map1(){ Camera camera(36*sz,SCREEN_WIDTH); - posweg.print(100,100,camera.getPosX()); - + posweg.print(40,8*sz ,camera.getPosX()); + camera.update(posweg.getRectangle().x,posweg.getRectangle().y); Block wallA(8*sz,7*sz,sz*2,sz*2,&gRenderer,&posweg,camera.getPosX()); Block wallB(4*sz,9*sz,sz,sz*2,&gRenderer,&posweg,camera.getPosX()); @@ -74,5 +77,5 @@ void Core::map1(){ SDL_RenderPresent(gRenderer); } - + }; diff --git a/core.h b/source/core.h similarity index 73% rename from core.h rename to source/core.h index 19a462a..cb74b9d 100644 --- a/core.h +++ b/source/core.h @@ -4,12 +4,13 @@ #define __CORE_H_INCLUDED__ #include -#include -#include"entity.h" -#include"player.h" -#include"block.h" -#include"powerup.h" +#include +#include"entity/entity.h" +#include"entity/player.h" +#include"entity/block.h" +#include"entity/powerup.h" #include"camera.h" +#include"menu.h" class Core{ public: @@ -17,7 +18,7 @@ class Core{ private: void init(); void close(); - + void map1(); const int SCREEN_WIDTH = 640; @@ -26,7 +27,7 @@ class Core{ SDL_Window* gWindow = NULL; SDL_Renderer* gRenderer = NULL; - + //Player posweg(&gRenderer); }; diff --git a/dt.cpp b/source/dt.cpp similarity index 100% rename from dt.cpp rename to source/dt.cpp diff --git a/dt.h b/source/dt.h similarity index 76% rename from dt.h rename to source/dt.h index e208992..7ebefad 100644 --- a/dt.h +++ b/source/dt.h @@ -1,9 +1,9 @@ -//Delta time class header +//Delta time class header< #ifndef __DT_H_INCLUDED__ #define __DT_H_INCLUDED__ -#include +#include class DeltaTime{ public: diff --git a/block.cpp b/source/entity/block.cpp similarity index 100% rename from block.cpp rename to source/entity/block.cpp diff --git a/block.h b/source/entity/block.h similarity index 94% rename from block.h rename to source/entity/block.h index c244115..1afed18 100644 --- a/block.h +++ b/source/entity/block.h @@ -4,7 +4,7 @@ #define __BLOCK_H_INCLUDED__ #include"entity.h" -#include +#include #include #include"player.h" diff --git a/entity.cpp b/source/entity/entity.cpp similarity index 100% rename from entity.cpp rename to source/entity/entity.cpp diff --git a/entity.h b/source/entity/entity.h similarity index 92% rename from entity.h rename to source/entity/entity.h index 908c207..ea20aac 100644 --- a/entity.h +++ b/source/entity/entity.h @@ -3,7 +3,7 @@ #ifndef __ENTITY_H_INCLUDED__ #define __ENTITY_H_INCLUDED__ -#include +#include #include class Entity{ diff --git a/player.cpp b/source/entity/player.cpp similarity index 97% rename from player.cpp rename to source/entity/player.cpp index eb11190..f6c6e33 100644 --- a/player.cpp +++ b/source/entity/player.cpp @@ -2,7 +2,7 @@ #include"player.h" -void Player::print(int x,int y,int cameraX){ +void Player::print(int x,int y,int cameraX){ if(first == true){ first = false; posX = x; @@ -10,7 +10,7 @@ void Player::print(int x,int y,int cameraX){ } oldPosX = posX; - oldPosY = posY; + oldPosY = posY; rect.x = posX; rect.y = posY; @@ -41,6 +41,8 @@ Player::Player(SDL_Renderer** render){ ply.setRenderer(renderer); loadMedia(); //first = true; + + ground = false; }; void Player::loadMedia(){ @@ -69,10 +71,10 @@ int Player::intVelX(){ void Player::move(){ //float dt = dTime.getDt(); float dt = 0.016; - - //Set keyboard variable + + //Set keyboard variable const Uint8* currentKeyStates = SDL_GetKeyboardState(NULL); - + //Intializing variables int direction = 0; //1 = right, 0 = idle/both, -1 = left int dur = 4; //Divide transition time @@ -115,7 +117,7 @@ void Player::move(){ if(intVelX() > 0) velocityX = 0; } else if(velocityX <= 1 or velocityX >= -1) velocityX = 0; - + //Jump and gravity logic if(ground){ isRunning = false; @@ -129,14 +131,14 @@ void Player::move(){ else{ if(isRunning == false) run = 1; } - + if(run!=1) ifRunning = true; //Get the position and update the velY with gravity velocityY -= gravity * dt; float x = velocityX * dt * run; float y = velocityY * dt; - + //Convert and set new int position posX += static_cast(x); posY -= static_cast(y+0.5); @@ -154,7 +156,7 @@ int Player::check(SDL_Rect rectA, int type){ //Float-ize the position float movX = posX, movY = posY; - + //Move the player out of the rectangle if(type == 1){ while(((movX >= bX and movX < b2X) @@ -167,7 +169,7 @@ int Player::check(SDL_Rect rectA, int type){ movY -= (posY - oldPosY)/2; collision = 1; } - + //Correct possible position issues if(collision == 1){ //Vertical adjustement @@ -200,7 +202,7 @@ int Player::check(SDL_Rect rectA, int type){ //Set and int-ize the position*/ posX = static_cast(movX); posY = static_cast(movY); - + //Check collsion type and reset velocities //Vertical collisions if((posX >= bX and posX < b2X) diff --git a/player.h b/source/entity/player.h similarity index 87% rename from player.h rename to source/entity/player.h index 250d2fd..052a386 100644 --- a/player.h +++ b/source/entity/player.h @@ -1,14 +1,14 @@ -//Player class header +//Player class header< #ifndef __PLAYER_H_INCLUDED__ #define __PLAYER_H_INCLUDED__ -#include +#include #include #include -#include"dt.h" +#include"../dt.h" #include"entity.h" -#include"texture.h" +#include"../texture.h" class Entity; @@ -34,7 +34,7 @@ class Player: public Entity{ bool first; int power = 0; - PosuTexture ply; + Texture ply; SDL_Rect plyFrame[3]; SDL_Rect plyRun; }; diff --git a/powerup.cpp b/source/entity/powerup.cpp similarity index 100% rename from powerup.cpp rename to source/entity/powerup.cpp diff --git a/powerup.h b/source/entity/powerup.h similarity index 93% rename from powerup.h rename to source/entity/powerup.h index 41187c0..88a718d 100644 --- a/powerup.h +++ b/source/entity/powerup.h @@ -3,7 +3,7 @@ #ifndef __POWERUP_H_INCLUDED__ #define __POWERUP_H_INCLUDED__ -#include +#include #include #include"entity.h" #include"player.h" diff --git a/source/icon.ico b/source/icon.ico new file mode 100644 index 0000000..9c6e878 Binary files /dev/null and b/source/icon.ico differ diff --git a/source/icon.rc b/source/icon.rc new file mode 100644 index 0000000..7b4adf2 --- /dev/null +++ b/source/icon.rc @@ -0,0 +1,6 @@ +#ifndef RESOURCE_RC_INCLUDED +#define RESOURCE_RC_INCLUDED + +1 ICON "icon.ico" + +#endif // RESOURCE_RC_INCLUDED diff --git a/main.cpp b/source/main.cpp similarity index 100% rename from main.cpp rename to source/main.cpp diff --git a/source/menu.cpp b/source/menu.cpp new file mode 100644 index 0000000..42319c5 --- /dev/null +++ b/source/menu.cpp @@ -0,0 +1,86 @@ +#include "menu.h" + +int menu(SDL_Renderer* renderer){ + int SCREEN_WIDTH, SCREEN_HEIGHT; + SDL_GetRendererOutputSize(renderer,&SCREEN_WIDTH,&SCREEN_HEIGHT); + + bool quit = false; + SDL_Event e; + + Texture txLogo; + txLogo.setRenderer(&renderer); + txLogo.loadTexture("textures/title.png"); + + int logoVmargin = 40; + + SDL_Rect logo = {(SCREEN_WIDTH/2)-txLogo.getWidth()/2,logoVmargin,txLogo.getWidth(),txLogo.getHeight()}; + + int btnSpc = SCREEN_HEIGHT - (logo.y + logo.h); + int buttonNum = 3; + SDL_Rect button[buttonNum]; + int btnWidth = SCREEN_WIDTH/3; + int btnHeight = btnSpc/buttonNum/2; + int spc = (btnSpc-buttonNum*btnHeight)/(buttonNum+1); + + for(int i = 0; i < buttonNum; i++){ + button[i].x = SCREEN_WIDTH/2-btnWidth/2; + button[i].y = ((i+1)*spc+i*btnHeight)+SCREEN_HEIGHT-btnSpc; + button[i].w = btnWidth; + button[i].h = btnHeight; + std::cout << "Button " << i+1 + << " set as -> x: " << button[i].x + << " y: " << button[i].y + << " w: " << button[i].w + << " h: " << button[i].h + << std::endl; + } + + int select = 0; + bool wait = 0; + const Uint8* currentKeyStates = SDL_GetKeyboardState(NULL); + + std::cout << std::endl << "Entering main loop..." << std::endl; + + while(!quit){ + while(SDL_PollEvent(&e)!=0){ + if(e.type == SDL_QUIT){ + quit = true; + } + } + SDL_SetRenderDrawColor(renderer,100,200,200,0xFF); + SDL_RenderClear(renderer); + + int dir = 0; + if(currentKeyStates[SDL_SCANCODE_UP]) dir--; + if(currentKeyStates[SDL_SCANCODE_DOWN])dir++; + + if(dir != 0){ + if(!wait) select += dir; + wait = true; + } + else wait = false; + + if(select >= buttonNum) select = 0; + if(select < 0) select = buttonNum-1; + + txLogo.render(&logo); + + for(int i = 0; i < buttonNum; i++){ + if(static_cast(select) == i){ + SDL_SetRenderDrawColor(renderer,80,80,80,0xFF); + if(currentKeyStates[SDL_SCANCODE_SPACE]) SDL_SetRenderDrawColor(renderer,200,200,200,0xFF); + } + else SDL_SetRenderDrawColor(renderer,128,128,128,0xFF); + + SDL_RenderFillRect(renderer,&button[i]); + } + if(currentKeyStates[SDL_SCANCODE_SPACE]){ + if(select == 0) return 1; + else if(select == 2) break; + } + + SDL_RenderPresent(renderer); + } + + return 0; +} diff --git a/source/menu.h b/source/menu.h new file mode 100644 index 0000000..b6a235e --- /dev/null +++ b/source/menu.h @@ -0,0 +1,10 @@ +#ifndef MENU_H +#define MENU_H + +#include +#include +#include"texture.h" + +int menu(SDL_Renderer* render); + +#endif // MENU_H diff --git a/texture.cpp b/source/texture.cpp similarity index 73% rename from texture.cpp rename to source/texture.cpp index c4a8800..15f8747 100644 --- a/texture.cpp +++ b/source/texture.cpp @@ -1,6 +1,6 @@ #include"texture.h" -PosuTexture::PosuTexture(){ +Texture::Texture(){ //Initialize variables szW = 0; szH = 0; @@ -9,19 +9,19 @@ PosuTexture::PosuTexture(){ //Set renderer }; -void PosuTexture::setRenderer(SDL_Renderer** render){ +void Texture::setRenderer(SDL_Renderer** render){ renderer = render; }; -PosuTexture::~PosuTexture(){ +Texture::~Texture(){ //Deallocate //free(); }; -void PosuTexture::loadTexture(std::string path){ +void Texture::loadTexture(std::string path){ //Get rid of preexisting texture free(); - + //Load image at specified path SDL_Surface* loadedSurface = IMG_Load( path.c_str() ); @@ -47,7 +47,7 @@ void PosuTexture::loadTexture(std::string path){ } }; -void PosuTexture::free(){ +void Texture::free(){ //Free texture if it exists if(texture != NULL){ SDL_DestroyTexture(texture); @@ -57,8 +57,8 @@ void PosuTexture::free(){ } }; -void PosuTexture::render(SDL_Rect* quad,SDL_Rect* frame){ -//void PosuTexture::render(SDL_Rect* quad){ +void Texture::render(SDL_Rect* quad,SDL_Rect* frame){ +//void Texture::render(SDL_Rect* quad){ //Set clip rendering dimensions /*if(frame != NULL){ quad.w = frame->w; @@ -71,10 +71,16 @@ void PosuTexture::render(SDL_Rect* quad,SDL_Rect* frame){ //std::cout << "ye" << std::endl; }; -int PosuTexture::getWidth(){ +void Texture::render(SDL_Rect* quad){ + SDL_Rect frame = {0,0,quad->w,quad->h}; + + SDL_RenderCopy(*renderer,texture,&frame,quad); +}; + +int Texture::getWidth(){ return szW; }; -int PosuTexture::getHeight(){ +int Texture::getHeight(){ return szH; }; diff --git a/texture.h b/source/texture.h similarity index 80% rename from texture.h rename to source/texture.h index 6e5919f..0cd1ffd 100644 --- a/texture.h +++ b/source/texture.h @@ -3,18 +3,19 @@ #ifndef __TEXTURE_H_INCLUDED__ #define __TEXTURE_H_INCLUDED__ -#include -#include +#include +#include #include #include -class PosuTexture{ +class Texture{ public: - PosuTexture(); - ~PosuTexture(); + Texture(); + ~Texture(); void loadTexture(std::string path); void free(); void render(SDL_Rect* quad,SDL_Rect* frame); + void render(SDL_Rect* quad); //void render(SDL_Rect* quad); int getWidth(); int getHeight(); diff --git a/textures/title.png b/textures/title.png new file mode 100644 index 0000000..faad291 Binary files /dev/null and b/textures/title.png differ