C::B , menu and better organization

Project adapted to Code::Blocks and Windows, new main menu and a better organization, putting all the source files in a directory and the entity source files in other one inside the source directory. New icon for the final executable.
This commit is contained in:
Pòsweg 2017-06-16 17:24:22 +02:00
parent c03f5db6dd
commit e94936ec99
24 changed files with 178 additions and 53 deletions

12
.gitignore vendored
View File

@ -59,5 +59,15 @@ reated by https://www.gitignore.io/api/vim,c++,linux
Session.vim
# temporary
.netrwhist
### CodeBlocks ###
# specific to CodeBlocks IDE
*.cbp
*.layout
*.depend
# generated directories
bin/
obj/
# auto-generated tag files
tags

BIN
main

Binary file not shown.

View File

@ -3,7 +3,7 @@
#ifndef __CAMERA_H_INCLUDED__
#define __CAMERA_H_INCLUDED__
#include"player.h"
#include"entity/player.h"
class Camera{
public:

View File

@ -23,7 +23,7 @@ void Core::close(){
int Core::coreInit(){
init();
bool quit = false;
/*bool quit = false;
SDL_Event e;
while(!quit){
@ -37,8 +37,11 @@ int Core::coreInit(){
SDL_RenderPresent(gRenderer);
}*/
if(menu(gRenderer) == 1){
map1();
}
map1();
close();
return 0;
@ -61,7 +64,7 @@ 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());

View File

@ -4,12 +4,13 @@
#define __CORE_H_INCLUDED__
#include<iostream>
#include<SDL2/SDL.h>
#include"entity.h"
#include"player.h"
#include"block.h"
#include"powerup.h"
#include<SDL.h>
#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:

View File

@ -1,9 +1,9 @@
//Delta time class header
//Delta time class header<
#ifndef __DT_H_INCLUDED__
#define __DT_H_INCLUDED__
#include<SDL2/SDL.h>
#include<SDL.h>
class DeltaTime{
public:

View File

@ -4,7 +4,7 @@
#define __BLOCK_H_INCLUDED__
#include"entity.h"
#include<SDL2/SDL.h>
#include<SDL.h>
#include<iostream>
#include"player.h"

View File

@ -3,7 +3,7 @@
#ifndef __ENTITY_H_INCLUDED__
#define __ENTITY_H_INCLUDED__
#include<SDL2/SDL.h>
#include<SDL.h>
#include<iostream>
class Entity{

View File

@ -41,6 +41,8 @@ Player::Player(SDL_Renderer** render){
ply.setRenderer(renderer);
loadMedia();
//first = true;
ground = false;
};
void Player::loadMedia(){

View File

@ -1,14 +1,14 @@
//Player class header
//Player class header<
#ifndef __PLAYER_H_INCLUDED__
#define __PLAYER_H_INCLUDED__
#include<SDL2/SDL.h>
#include<SDL.h>
#include<iostream>
#include<cmath>
#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;
};

View File

@ -3,7 +3,7 @@
#ifndef __POWERUP_H_INCLUDED__
#define __POWERUP_H_INCLUDED__
#include<SDL2/SDL.h>
#include<SDL.h>
#include<iostream>
#include"entity.h"
#include"player.h"

BIN
source/icon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 361 KiB

6
source/icon.rc Normal file
View File

@ -0,0 +1,6 @@
#ifndef RESOURCE_RC_INCLUDED
#define RESOURCE_RC_INCLUDED
1 ICON "icon.ico"
#endif // RESOURCE_RC_INCLUDED

86
source/menu.cpp Normal file
View File

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

10
source/menu.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef MENU_H
#define MENU_H
#include<SDL.h>
#include<iostream>
#include"texture.h"
int menu(SDL_Renderer* render);
#endif // MENU_H

View File

@ -1,6 +1,6 @@
#include"texture.h"
PosuTexture::PosuTexture(){
Texture::Texture(){
//Initialize variables
szW = 0;
szH = 0;
@ -9,16 +9,16 @@ 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();
@ -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;
};

View File

@ -3,18 +3,19 @@
#ifndef __TEXTURE_H_INCLUDED__
#define __TEXTURE_H_INCLUDED__
#include<SDL2/SDL.h>
#include<SDL2/SDL_image.h>
#include<SDL.h>
#include<SDL_image.h>
#include<iostream>
#include<string>
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();

BIN
textures/title.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB