Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - S_BISHOP

Pages: [1]
1
General / Precompiled Header Syntax, is this a valid pch ?
« on: January 21, 2019, 09:28:10 am »
I recently discovered the concept of using a precompiled header within a large project, to speed up compile time for those system headers that do not change.

I am now attempting to add to my own project, my question, is this the correct syntax ? or is there something more i have to add, for it to be marked and recognized as a pch.h ?

In code blocks clicking on the this header file and then clicking properties ive checked the file to be Compiled but purposely did not check the file to be linked, is it a pch now ? , is it meant to compile faster as i have it above,  i honestly have no idea.

thanks


#ifndef PCH_H_INCLUDED
#define PCH_H_INCLUDED

#include <iostream>
#include <fstream>
#include <sstream>
#include <strstream>
#include <chrono>
#include <random>
#include <ctime>
#include <memory>
#include <iterator>
#include <cstdlib>
#include <typeinfo>
#include <SFML/System.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>

#endif // PCH_H_INCLUDED

2
General / Re: Undefined reference ERROR Why?!?!?!!
« on: January 03, 2019, 09:44:44 am »
Hey mate, i have been through hell and back with this. its not clear and quite the pitfall.

when dowloading code bocks dowload the TDM install not the MING one, MING is apparently in-compatable with code blocks, because its windows specific, give it a go, i think it will work.

3

I have a Player type and he has a function to fire his Weapon type, that creates a Projectile type, pushing each new Projectile type pointer back into a vector of the same type with each shot fired.

all works beautifully. Apart from when its time to clear that memory, i pass the vector of pointers to this
function template, but its never safe and always results in a program crash ?

How do you keep tabs on a pointer that is passed around many many function of global program scope, and when do you know for sure it is completely untouched un-accessed so it can be safely deleted ?


this is my current methodology with in my simple game engine, is this typically how memory maement is done in game programming ?

thanks.




freeMemVecPerishTarget(t.firedProjectilesPtrs);


template<typename T>
inline void freeMemVecPerishTarget(vector<T*>& t){
   for (auto it = t.begin(); it != t.end();) {
      //
      (*it)->perishTotal = ((*it)->perishTotal < (*it)->perishTarget) ? (*it)->perishTotal += (*it)->perishUpdate : (*it)->alive = F;
      //
      if(!(*it)->alive) {
         delete *it;
         it = t.erase(it);
      } else
         ++it;
   }
}

 


4
@eXpl0it3r   Thanks, i have uncounted the tunnel effect multiple times, and yes i did release and learn that about the window overtime, but thanks for renewing that in my mind.

5
Thanks for the replys.

I just took a look at running in debug mode, and looks as if the players destructor is called to soon or multiple times and that should not be,  i once solved this issue by making the player a shared_ptr and not a unique_ptr, for the reasons that it is passed in and out of functions and needs to remain in scope.

6

 I admit this is a strange question (laughs)
 Im just curious, if this has happened to anyone else during there project development life cycle, its honestly
 happned 2 - 3 times in 2+ years of a dev cycle, and its difficult to re-find the cause of it each time.

If so, im glad to know i'm not the only one, What happens exactly? 
The Player entity goes invisible and off screen, no collision now applies,
so i guess there isnt even a plysical player enity to collide, or further develop with.

In the past Ive found it has something to do with RAM, my project reads in level entitys from txt file, and removing the expensive ones such as particlespawns can somtimes resolve it or number of ai floating around on screen ?




7
What does getActiveLevelPlatformableIndex(i) look like?

The crystal ball says you are modifying a copy instead of the actual object.


Hey mate thanks for the reply I did not realize you had posted a response or anyone for that matter.
This is what the member function prototype and the member function definition body look like:


Platformable& getActiveLevelPlatformableIndex(int index);

Platformable& LevelManager::getActiveLevelPlatformableIndex(int index){
    return activeLevelPlatformables[index];
}

After you having viewed this.
My question to you. Am i really modifying only a local copy and not the passed reference ?
Please get back to me mate.

8
Hello
I would like to know if anyone can see why and then thoughtfully explain to me why my sprites are not redrawing in new positions. I,ve spent a fair amount of time looking into this and examining my program functionality first before i had posted.
With what I have posted, In theory should this work fine?
If anyone can see a beginner mistake in either SFML or C++ please be kind and let me know.




I have a vector container of this type of object, each instance created contains a sf::Texture and sf::Sprite
all vector oriented member functions are return by reference.

std::vector<Platformable> activeLevelPlatformables;


std::vector<Platformable>& getActiveLevelPlatformables();

std::vector<Platformable>& LevelManager::getActiveLevelPlatformables(){
    return activeLevelPlatformables;
}


I then have these to member functions that get called continuously during the FPS of the main game loop of the main.cpp, what ever is the default FPS of the main game loop, no changes have been made there.

The first member function to re position all the sprites

The second member function to render all sprite position changes and draw re draw all the sprites to the screen. This member function receives the window object passed by reference.


 void positionActiveLevelSprites();

void LevelManager::positionActiveLevelSprites(){
    for (std::vector<Platformable>::size_type i = 0; i != getActiveLevelPlatformables().size(); i++) {
        getActiveLevelPlatformableIndex(i).setSpriteX(getActiveLevelPlatformableIndex(i).getSpriteX() + 20 );
    }
}


void drawActiveLevel(sf::RenderWindow &rw);

void LevelManager::drawActiveLevel(sf::RenderWindow &rw){
    for (std::vector<Platformable>::size_type i = 0; i != getActiveLevelPlatformables().size(); i++) {
        rw.draw(getActiveLevelPlatformableIndex(i).getSprite());
    }
}


please note: The key press A event handler is just a dummy value test, no specifics have been handled.



Then the main.cpp looks like this:




#include <SFML/Graphics.hpp>
#include <LevelManager.h>

#include <Vector>
#include <iostream>


int main()
{

    sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window"/*,sf::Style::Fullscreen*/);

    LevelManager lm;
    lm.loadActiveLevel();

        // Start the game loop
    while (window.isOpen())
    {
        // Process events
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed) {
                window.close();
            }

            if (event.type == sf::Event::KeyPressed) {

                if (event.key.code == sf::Keyboard::Escape) {
                    window.close();
                }

                if (event.key.code == sf::Keyboard::A) {
                    lm.positionActiveLevelSprites();
                    std::cout << "this is working" << std::endl;
                }
            }
        }

        lm.drawActiveLevel(window);
        window.display();
        window.clear();
    }

    return EXIT_SUCCESS;
}


 

9
Thanks Laurent. This was a good reply. I now understand.

10
Hello I come from Diploma student Java background.
I would like to know if this is typically how i would set up the get and set member functions in C++

virtual double getX();
virtual void setX(double &newX);

double* Spritable::getX(){return &x;}
void Spritable::setX(double &newX){x = newX;}


and then would I retrieve the values stored at those memory addresses pointed to, by de-referencing
somthing like this ?

p.getTexture().loadFromFile(activeLevelStructuresImages[0], sf::IntRect(*p.getX(), *p.getY(), *p.getWidth(), *p.getHeight()));


Or return references such as this ?

virtual double& getX();
virtual void setX(double &newX);

double& Spritable::getX(){return x;}
void Spritable::setX(double &newX){x = newX;}




if this is so, Yes I think I do understand the textbook logic behind these operations, such as pointers and References after reading "Jumping into C++" a first time. I just would like to be sure if this is how its done. The last thing I wont to do is learn bad habits or incorrect operations.

Thanks Please let me know.

11
Thanks mate, will not post big examples next time, I thought the error lied in everything you have explained, but yes wild pointers.
I appreciate your post , constructive and fair from programmer to programmer.
Have a good day :)

12
Hello I have spent the past month ready C++ Book Jumping Into C++, great book and great author.
This was after I had been pointed out on this forum that I have not learnt C++, and needed to.
Now I have, to I think an intermediate grasp of understanding,  I may read the whole thing from start to finish a second time, to concrete my understanding.

I would like to know If there is any incorrect Reference/Pointer logic in my class LevelManager.

By viewing this class, this is asuming the rest of my classes behave and are structured as how you would expect them to be in a somewhat generic game engine like structure.

I think I have done somethings in correct with datatypes and vectors, but not likley program flor structure, this is the way I intended it to run.

Problem:

Vector container  activeLevelPlatformables, will not store the Platformable objects, I,m not sure why ?
the vector prints out with a size of 0.


The good new is you don,t have to read most of it, up until you get to the doted line of the .cpp file , because its works as expected up until this point.

take not of this comment:
// Bug: Platformable memory addresses do not store in pointer vector



Please take a look thanks.




This is the structure:

                 Spritable
       _________|       |_________
       |                              |
      PlayableAIable            LevelStructurable
      |      |                    |                         |      
   Playable   AIable          Platformable     NonPlatformable


note: This class LevelManager is not part of this inheritance heir achy.


note: the comments need to be updated since I last typed them




/*
*/



#ifndef LEVELMANAGER_H
#define LEVELMANAGER_H

#include <Platformable.h>

#include <Vector>
#include <string>

class LevelManager
{
    public:

        LevelManager();
        ~LevelManager();

        void loadActiveLevel();
        std::vector<Platformable*> getActiveLevelPlatformables();

    private:

        const int LEVEL_NUM_TOTAL;

        const std::string FILE_PATH_ALL_LEVEL_STRUCTURES_XY_WIDTH_HEIGHT, FILE_PATH_ALL_LEVEL_STRUCTURES_IMAGES;

        // A marker point storing the last value read offset
        // to begin loading vector currentLevelStructuresXYPos, with each call of function loadAcativeLevel();
        int lastReadTokenCounterAllLevelStructuresXYPos, lastReadTokenCounterAllLevelStructuresWidthHeight, lastReadTokenCounterAllLevelStructuresImages;

        // This vector is reset and loaded with a new set of values, each time the function loadActiveLevels() is called
        // The values loaded in the vector are dependent on the value of the lastReadTokenCounter
        std::vector<int> activeLevelStructuresXYPos, activeLevelStructuresWidthHeight;
        std::vector<std::string> activeLevelStructuresImages;

        // A pointer is required to store enough memory bytes to allocate variable size objects and its member variables of this type
        std::vector<Platformable*> activeLevelPlatformables;
};

#endif // LEVELMANAGER_H


 




#include "LevelManager.h"
#include <Platformable.h>

#include <Vector>
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
#include <iterator>


LevelManager::LevelManager()
: LEVEL_NUM_TOTAL(100), FILE_PATH_ALL_LEVEL_STRUCTURES_XY_WIDTH_HEIGHT("res/allLevelsStructuresXYWidthHeight.txt"), FILE_PATH_ALL_LEVEL_STRUCTURES_IMAGES("res/allLevelsStructuresImages.txt")
{
    int proportionalInitVal = 0;
    lastReadTokenCounterAllLevelStructuresXYPos = proportionalInitVal;
    lastReadTokenCounterAllLevelStructuresWidthHeight = proportionalInitVal;
    lastReadTokenCounterAllLevelStructuresImages = proportionalInitVal;
}

LevelManager::~LevelManager()
{
}

std::vector<Platformable*> LevelManager::getActiveLevelPlatformables(){return activeLevelPlatformables;}

void LevelManager::loadActiveLevel(){

    // notes about this function
    // >=   =  (equal to) operator, of the conditions is only applicable to the intital run of this function
    // >=   >  (greater than sign), of the conditions is applicable after the intial function run


    // Clears all active level temperary resource vector collections
    activeLevelStructuresXYPos.clear();
    activeLevelStructuresImages.clear();



    int findLastTokenReadCounter = 0;
    std::string readLine;



    // Reads and stores the x y positions of the required structures of the active level

    std::ifstream FILE_ALL_LEVEL_STRUCTURES_XY_WIDTH_HEIGHT;
    std::string readValueX, readValueY, readValueWidth, readValueHeight;

    FILE_ALL_LEVEL_STRUCTURES_XY_WIDTH_HEIGHT.open(FILE_PATH_ALL_LEVEL_STRUCTURES_XY_WIDTH_HEIGHT);

    if (FILE_ALL_LEVEL_STRUCTURES_XY_WIDTH_HEIGHT.is_open()) {
        std::cout << "File " << FILE_PATH_ALL_LEVEL_STRUCTURES_XY_WIDTH_HEIGHT << " was opened Successfully" << std::endl << std::endl;
        std::cout << "platformableStructuresXYAllLevels.txt : Active level Structures x y values" << std::endl;

        while(getline(FILE_ALL_LEVEL_STRUCTURES_XY_WIDTH_HEIGHT, readLine)){

            findLastTokenReadCounter++;

            if(findLastTokenReadCounter >= lastReadTokenCounterAllLevelStructuresXYPos) {
                if (FILE_ALL_LEVEL_STRUCTURES_XY_WIDTH_HEIGHT >> readValueX) {
                    int readValueXToInt;
                    std::stringstream(readValueX) >> readValueXToInt;
                    activeLevelStructuresXYPos.push_back(readValueXToInt);
                    lastReadTokenCounterAllLevelStructuresXYPos++;

                    std::cout << readValueXToInt << " ";
                }

                if (FILE_ALL_LEVEL_STRUCTURES_XY_WIDTH_HEIGHT >> readValueY) {
                    int readValueYToInt;
                    std::stringstream(readValueY) >> readValueYToInt;
                    activeLevelStructuresXYPos.push_back(readValueYToInt);
                    lastReadTokenCounterAllLevelStructuresXYPos++;

                    std::cout << readValueYToInt << " ";
                }
            }

            if(findLastTokenReadCounter >= lastReadTokenCounterAllLevelStructuresWidthHeight) {

                findLastTokenReadCounter++;

                if (FILE_ALL_LEVEL_STRUCTURES_XY_WIDTH_HEIGHT >> readValueWidth) {
                    int readValueWidthToInt;
                    std::stringstream(readValueWidth) >> readValueWidthToInt;
                    activeLevelStructuresWidthHeight.push_back(readValueWidthToInt);
                    lastReadTokenCounterAllLevelStructuresWidthHeight++;

                    std::cout << readValueWidthToInt << " ";
                }

                 if (FILE_ALL_LEVEL_STRUCTURES_XY_WIDTH_HEIGHT >> readValueHeight) {
                    int readValueHeightToInt;
                    std::stringstream(readValueHeight) >> readValueHeightToInt;
                    activeLevelStructuresWidthHeight.push_back(readValueHeightToInt);
                    lastReadTokenCounterAllLevelStructuresWidthHeight++;

                    std::cout << readValueHeightToInt << " ";
                }
            }
                std::cout << std::endl;
        }
    }
    else {
        std::cout << " : File " << FILE_PATH_ALL_LEVEL_STRUCTURES_XY_WIDTH_HEIGHT << " was not opened Successfully" << std::endl;
    }

    FILE_ALL_LEVEL_STRUCTURES_XY_WIDTH_HEIGHT.close();



    findLastTokenReadCounter = 0;
    readLine = "";


    // Reads and stores the image resources of each structure of the active level

    std::ifstream FILE_ALL_LEVEL_STRUCTURES_IMAGES;
    std::string readValueImage;


    FILE_ALL_LEVEL_STRUCTURES_IMAGES.open(FILE_PATH_ALL_LEVEL_STRUCTURES_IMAGES);

    if (FILE_ALL_LEVEL_STRUCTURES_IMAGES.is_open()) {
        std::cout << std::endl << std::endl << "File " << FILE_PATH_ALL_LEVEL_STRUCTURES_IMAGES << " was opened Successfully" << std::endl << std::endl;
        std::cout << "res/allLevelsStructuresImages.txt : Active level structures image values" << std::endl;

        while(getline(FILE_ALL_LEVEL_STRUCTURES_IMAGES, readLine)){

            findLastTokenReadCounter++;

            if(findLastTokenReadCounter >= lastReadTokenCounterAllLevelStructuresImages){
                if (FILE_ALL_LEVEL_STRUCTURES_IMAGES >> readValueImage) {
                    activeLevelStructuresImages.push_back(readValueImage);
                    lastReadTokenCounterAllLevelStructuresImages++;

                    std::cout << readValueImage << " ";
                }

                std::cout << std::endl;
            }
        }
    }
    else {
        std::cout << " : File " << FILE_PATH_ALL_LEVEL_STRUCTURES_IMAGES << " was not opened Successfully" << std::endl;
    }

    FILE_ALL_LEVEL_STRUCTURES_IMAGES.close();




// ----------------------------------------start looking here-------------------------------------------------------------------------

  // Bug: Platformable memory addresses do not store in Platformable pointer vector:   activeLevelPlatformables





    // Reads and loads visible resources and draws the structures of the active level

    int sortCounter = 0;
    for (std::vector<Platformable*>::size_type i = 0 ; i != activeLevelStructuresXYPos.size(); i++) {
        Platformable p;

        if (sortCounter == 0) {
                double tempValX = activeLevelStructuresXYPos[i];
                p.setX(tempValX);
                sortCounter++;
                break;
        } else if (sortCounter == 1) {
                double tempValY = activeLevelStructuresXYPos[i];
                p.setY(tempValY);
                sortCounter++;
                break;
        }  else if (sortCounter == 2) {
                double tempValWidth = activeLevelStructuresWidthHeight[i];
                p.setWidth(tempValWidth);
                sortCounter++;
                break;
        }  else if (sortCounter == 3) {
                double tempValHeight = activeLevelStructuresWidthHeight[i];
                p.setHeight(tempValHeight);
                sortCounter++;
                break;
        } else if (sortCounter > 3) {
            sortCounter = 0;
        }

        p.getTexture().loadFromFile(activeLevelStructuresImages[i], sf::IntRect(p.getX(), p.getY(), p.getWidth(), p.getHeight()));
        activeLevelPlatformables.push_back(&p);
    }



    // testing

    std::cout << std::endl << std::endl;

    std::cout << "The vector activeLevelStructuresXYPos size = " << activeLevelStructuresXYPos.size() << std::endl;;
    for(int value : activeLevelStructuresXYPos) {
        std::cout << value << " ";
    }

    std::cout << std::endl << std::endl;

    std::cout << "The vector activeLevelStructuresWidthHeight size = " << activeLevelStructuresWidthHeight.size() << std::endl;
    for(int value : activeLevelStructuresWidthHeight) {
        std::cout << value << " ";
    }

    std::cout << std::endl << std::endl;

    std::cout << "The vector activeLevelStructuresImages size = " << activeLevelStructuresImages.size() << std::endl;
    for(std::string value : activeLevelStructuresImages) {
        std::cout << value << " ";
    }

    std::cout << std::endl << std::endl;

 

    std::cout << "The vector activeLevelPlatformables size = " << activeLevelPlatformables.size() << std::endl;

    std::cout << std::endl << std::endl;

    for (std::vector<Platformable*>::size_type i = 0; i != activeLevelPlatformables.size(); i++) {
        std::cout << activeLevelPlatformables[i]->getX() << activeLevelPlatformables[i]->getY() << " " << activeLevelPlatformables[i]->getWidth() << " " << activeLevelPlatformables[i]->getHeight();
    }

}


 

13
Hello I've spent a good number hours trying to successfully link the SFML API with Eclipse C++ IDE.
As of now I have very little experience working with 3rd partie API,s.

although no red error lines are present in the program, and I can make reference to the sf:: namespace to access the various headers and such.
However I get this following error during the complication of the program.

(I believe the MinGW compiler is up and running because I can compile and run a bare bones C++ program, so I don't think that's a problem.)

complication error:

   18:55:35 **** Incremental Build of configuration Debug for project GameEngine ****
   Info: Internal Builder is used for build
   g++ "-IC:\\SFML-2.1-windows-gcc-4.7-mingw-32bits\\SFML-2.1\\include" -O0 -g3 -Wall -c -fmessage-length=0 -o GameRun.o "..\\GameRun.cpp"
   In file included from C:\SFML-2.1-windows-gcc-4.7-mingw-32bits\SFML-2.1\include/SFML/Window.hpp:32:0,
                    from C:\SFML-2.1-windows-gcc-4.7-mingw-32bits\SFML-2.1\include/SFML/Graphics.hpp:32,
                    from ..\GameRun.cpp:11:
   C:\SFML-2.1-windows-gcc-4.7-mingw-32bits\SFML-2.1\include/SFML/System.hpp:35:39: fatal error: SFML/System/InputStream.hpp: No such file or directory
    #include <SFML/System/InputStream.hpp>
                                       ^
   compilation terminated.
   
   18:55:40 Build Finished (took 4s.979ms)




This is the location of my set work space:             C:\Users\xxxxx\Documents\EclipseC++Workspace




These are the steps I've taken:
 

 (1). Downloaded this:   
                             GCC 4.7 MinGW (DW2) - 32 bits, installed it at root of C: drive top level
                             (ran the SDK Manger like window to install the various packages or what it may be referred to as)
 
 (2). linked the include and lib files respectively, in the project properties as follows:
   
      C/C++ Build > Settings > GCC C++ Compiler > includes:      
                             C:\SFML-2.1-windows-gcc-4.7-mingw-32bits\SFML-2.1\include
      C/C++ Build > Settings > MinGW C++ Linker > libraries:
                             lsfml-graphics
                             lsfml-window
                             lsfml-system
      C/C++ Build > Settings > MinGW C++ Linker > libraries Search Path:
                                 C:\SFML-2.1-windows-gcc-4.7-mingw-32bits\SFML-2.1\lib

 (3). included these (where the sf namespace is required as reference):
                             #include <SFML/Graphics.hpp>
                             #include <SFML/Window.hpp>
                             #include <SFML/System.hpp>



  This what the file structures look like:
                             C:\SFML-2.1-windows-gcc-4.7-mingw-32bits\SFML-2.1\lib

                             libsfml-graphics
                             libsfml-graphics-d.a
                             libsfml-graphics-s.a
                             libsfml-graphics-s-d.a

                             .. and so on for Window and System.



If anyone can provide good constructive feedback or suggestions it will be much appreciated.
I just need to know how to do this once and then its just repetition after that.

                            

 

15
Hello

I understand enough knowledge of the Java programming language to create a very simple little game engine. because I have done so in the past, nothing to be too proud off.

The current state of my project, would run in java with a few changes, but will not run in C++ because C++ has additional concepts and features I don't yet, and have been trying very hard to understand.

 such as:

1. If and where I should be using pointer(s) in the project
2. How and where copy constructor(s) should and will be created and used in the project


As a pure learning experience I would like someone to look at all my posted code and put all the pointers and
and create and call all the copy constructors where they should be called, to make my project work. basically put all the C++ magic into the project that is missing and is required to make the project work.

The reason I ask is so I can see all the changes made of the original posted code, need to be made to to make the project run with c++  and look over it and study it.



In the main.cpp the project does not draw any sf::Sprites objects to the RenderWindow "app"
even though ive used a for each loop an iterated over each LevelStructure object and called method getImage(), and added each image to the "app"





#ifndef SPRITES_H
#define SPRITES_H


#include "GameStateManager.h"
#include <SFML/Graphics.hpp>
#include <string>
using namespace std;


class Sprites
{
    public:
        Sprites();
        ~Sprites();

        // identifiers

        string GROUPS[100];
        string POSITIONING_DIRECTIONS[100];
        string SUBTYPE_ID[100];
        sf::Texture imageTypesTextures[100];
        sf::Sprite imageTypes[100];
        sf::Texture activeAnimationFrameTextures;
        sf::Sprite activeAnimationFrame;

        // coorinates

        virtual double getX();
        virtual void setX(double);
        virtual double getY();
        virtual void setY(double);

        // velocity

        virtual double getXV();
        virtual void setXV(double);
        virtual double getYV();
        virtual void setYV(double);

        // width / height

        virtual int getWidth();
        virtual void setWidth(int);
        virtual int getHeight();
        virtual void setHeight(int);

        // attributes

        virtual int getLives();
        virtual void setLives(int);
        virtual int getMinLives();
        virtual void setMinLives(int);
        virtual int getMaxLives();
        virtual void setMaxLives(int);
        virtual int getHealth();
        virtual void setHealth(int);
        virtual int getMinHealth();
        virtual void setMinHealth(int);
        virtual int getMaxHealth();
        virtual void setMaxHealth(int);

        // states

        virtual bool getIsAlive();
        virtual void setIsAlive(bool);
        virtual bool getIsDead();
        virtual void setIsDead(bool);
        virtual bool getHasCollidedTop();
        virtual void setHasCollidedTop(bool);
        virtual bool getHasCollidedBottom();
        virtual void setHasCollidedBottom(bool);
        virtual bool getHasCollidedLeft();
        virtual void setHasCollidedLeft(bool);
        virtual bool getHasCollidedRight();
        virtual void setHasCollidedRight(bool);
        virtual bool getIsFalling();
        virtual void setIsFalling(bool);
        virtual bool getIsJumping();
        virtual void setIsJumping(bool);
        virtual bool getIsDoubleJumping();
        virtual void setIsDoubleJumping(bool);
        virtual bool getCanClimb();
        virtual void setCanClimb(bool);
        virtual bool getIsClimbing();
        virtual void setIsClimbing(bool);
        virtual bool getIsStoryDialoguing();
        virtual void setIsStoryDialoguing(bool);
        virtual bool getIsRandomDialoguing();
        virtual void setIsRandomDialoguing(bool);

        // resources

        char storyDialogue[1000];
        char randomDialogue[1000];
    protected:


         // identifiers

         int indexStoryCurrentCharAsCurrentLetter;
         int indexRandomCurrentCharAsCurrentLetter;

         // coorinates

        double x;
        double y;

        // velocity

        double xV;
        double yV;

        // width / height

        double width;
        double height;

        // collision

      //  sf::RectangleShape collisionBounds(sf::Vector2f(x, y));

        // attributes

        int lives;
        int minLives;
        int maxLives;
        int health;
        int minHealth;
        int maxHealth;

        // states

        bool isAlive;
        bool isDead;
        bool hasCollidedTop;
        bool hasCollidedBottom;
        bool hasCollidedLeft;
        bool hasCollidedRight;
        bool isFalling;
        bool isJumping;
        bool isDoubleJumping;
        bool canClimb;
        bool isClimbing;
        bool isStoryDialoguing;
        bool isRandomDialoguing;
};


#endif // SPRITES_H


 





#include "Sprites.h"


Sprites::Sprites()
{
    //ctor
}

Sprites::~Sprites()
{
    //dtor
}


// coorinates

double Sprites::getX(){return x;}
void Sprites::setX(double newX){x = newX;}
double Sprites::getY(){return y;}
void Sprites::setY(double newY){y = newY;}

// velocity

double Sprites::getXV(){return xV;}
void Sprites::setXV(double newXV){xV = newXV;}
double Sprites::getYV(){return yV;}
void Sprites::setYV(double newYV){yV = newYV;}

// width / height

int Sprites::getWidth(){return width;}
void Sprites::setWidth(int newWidth){width = newWidth;}
int Sprites::getHeight(){return height;}
void Sprites::setHeight(int newHeight){height = newHeight;}

// attributes

int Sprites::getLives(){return lives;}
void Sprites::setLives(int newLives){lives = newLives;}
int Sprites::getMinLives(){return minLives;}
void Sprites::setMinLives(int newMinLives){minLives = newMinLives;}
int Sprites::getMaxLives(){return maxLives;}
void Sprites::setMaxLives(int newMaxLives){maxLives = newMaxLives;}
int Sprites::getHealth(){return health;}
void Sprites::setHealth(int newHealth){health = newHealth;}
int Sprites::getMinHealth(){return minHealth;}
void Sprites::setMinHealth(int newMinHealth){minHealth = newMinHealth;}
int Sprites::getMaxHealth(){return maxHealth;}
void Sprites::setMaxHealth(int newMaxHealth){maxHealth = newMaxHealth;}

// states

bool Sprites::getIsAlive(){return isAlive;}
void Sprites::setIsAlive(bool newIsAlive){isAlive = newIsAlive;}
bool Sprites::getIsDead(){return isDead;}
void Sprites::setIsDead(bool newIsDead){isDead = newIsDead;}
bool Sprites::getHasCollidedTop(){return hasCollidedTop;}
void Sprites::setHasCollidedTop(bool newHasCollidedTop){hasCollidedTop = newHasCollidedTop;}
bool Sprites::getHasCollidedBottom(){return hasCollidedBottom;}
void Sprites::setHasCollidedBottom(bool newHasCollidedBottom){hasCollidedBottom = newHasCollidedBottom;}
bool Sprites::getHasCollidedLeft(){return hasCollidedLeft;}
void Sprites::setHasCollidedLeft(bool newHasCollidedLeft){hasCollidedLeft = newHasCollidedLeft;}
bool Sprites::getHasCollidedRight(){return hasCollidedRight;}
void Sprites::setHasCollidedRight(bool newHasCollidedRight){hasCollidedRight = newHasCollidedRight;}
bool Sprites::getIsFalling(){return isFalling;}
void Sprites::setIsFalling(bool newIsFalling){isFalling = newIsFalling;}
bool Sprites::getIsJumping(){return isJumping;}
void Sprites::setIsJumping(bool newIsJumping){isJumping = newIsJumping;}
bool Sprites::getIsDoubleJumping(){return isDoubleJumping;}
void Sprites::setIsDoubleJumping(bool newIsDoubleJumping){isDoubleJumping = newIsDoubleJumping;}
bool Sprites::getCanClimb(){return canClimb;}
void Sprites::setCanClimb(bool newCanClimb){canClimb = newCanClimb;}
bool Sprites::getIsClimbing(){return isClimbing;}
void Sprites::setIsClimbing(bool newIsClimbing){isClimbing = newIsClimbing;}
bool Sprites::getIsStoryDialoguing(){return isStoryDialoguing;}
void Sprites::setIsStoryDialoguing(bool newIsStoryDialoguing){isStoryDialoguing = newIsStoryDialoguing;}
bool Sprites::getIsRandomDialoguing(){return isRandomDialoguing;}
void Sprites::setIsRandomDialoguing(bool newIsRandomDialoguing){isRandomDialoguing = newIsRandomDialoguing;}

// resources


 




#ifndef LEVELSTRUCTURE_H
#define LEVELSTRUCTURE_H

#include <Sprites.h>
#include <SFML/Graphics.hpp>
using namespace std;


class LevelStructure : public Sprites
{
    public:
        LevelStructure(double newX, double newY, int newWidth, int newHeight, char activeSpriteSheetChar);
        ~LevelStructure();
       // LevelStructure(const LevelStructure &s);

        sf::Sprite image;
        void load();

        sf::Sprite getImage();
    protected:
    private:
        sf::Texture LARGE_SPRITE_SHEET;
        sf::Texture MEDIUM_SPRITE_SHEET;
        sf::Texture SMALL_SPRITE_SHEET;
        char activeSpriteSheetChar;
};


#endif // LEVELSTRUCTURE_H



 




#include "LevelStructure.h"
#include <ioStream>
using namespace std;


LevelStructure::LevelStructure(double newX, double newY, int newWidth, int newHeight, char spriteSheetChar)
{
    x = newX;
    y = newY;
    width = newWidth;
    height = newHeight;

    if (spriteSheetChar == 'L'){
        if (LARGE_SPRITE_SHEET.loadFromFile("LARGE_SPRITE_SHEET.png", sf::IntRect(x, y, width, height))){
            image.setTexture(LARGE_SPRITE_SHEET);
        } else{
            cout << "Texture \"LARGE_SPRITE_SHEET\" could not be loaded from file path \"LARGE_SPRITE_SHEET.png\"" << endl;
        }
    }  else if (spriteSheetChar == 'M'){
           if (MEDIUM_SPRITE_SHEET.loadFromFile("MEDIUM_SPRITE_SHEET.png", sf::IntRect(x, y, width, height))){
                image.setTexture(MEDIUM_SPRITE_SHEET);
           } else{
                cout << "Texture \"MEDIUM_SPRITE_SHEET\" could not be loaded from file path \"MEDIUM_SPRITE_SHEET.png\"" << endl;
           }
    }  else if (spriteSheetChar == 'S'){
           if (SMALL_SPRITE_SHEET.loadFromFile("SMALL_SPRITE_SHEET.png", sf::IntRect(x, y, width, height))){
               image.setTexture(SMALL_SPRITE_SHEET);
           } else{
               cout << "Texture \"SMALL_SPRITE_SHEET\" could not be loaded from file path \"SMALL_SPRITE_SHEET.png\"" << endl;
           }
    }
}

LevelStructure::~LevelStructure()
{
    //dtor
}

sf::Sprite LevelStructure::getImage(){return image;}


 





#ifndef LEVELMANAGER_H
#define LEVELMANAGER_H


#include <LevelStructure.h>


class LevelManager
{
    public:
        LevelManager();
        ~LevelManager();

        void loadActiveLevel();

        bool getLevelIsLoaded();
        void setLevelIsLoaded(bool);
        std::vector<LevelStructure> getLevelStructures();
    private:
        bool levelIsLoaded = false;
        std::vector<LevelStructure> levelStructures; // NUM_OF_LEVELS x   y   w  h
        int NUM_OF_LEVEL_STRUCTURES_PER_LEVEL[100] = {10,50,50,50,50,50,50,50,50,50,50};
        int activeNumOfLevelStructuresPerLevelIndex = NUM_OF_LEVEL_STRUCTURES_PER_LEVEL[0];
        int activeLevelStructureIndex = 0;
        double NUM_LEVELS_LEVEL_STRUCTURES_X_Y_WIDTH_HEIGHT[100][4] = {{10, 10, 40, 40}, {50, 50, 20, 40}};
        int activeSpriteSheetSizeIndex = 0;
        char ACTIVE_LEVEL_STRUCTURE_SPRITE_SHEET_SIZE[50] = {'L', 'L', 'L', 'L', 'L', 'L'};
};


#endif // LEVELMANAGER_H


 







#include "LevelManager.h"
#include "LevelStructure.h"


LevelManager::LevelManager()
{
    //ctor
}

LevelManager::~LevelManager()
{
    //dtor
}

void LevelManager::loadActiveLevel() {
    if(!levelIsLoaded){
        for (int i = 0; i < activeNumOfLevelStructuresPerLevelIndex; i++) {
            LevelStructure ls = LevelStructure(
                                               NUM_LEVELS_LEVEL_STRUCTURES_X_Y_WIDTH_HEIGHT[activeLevelStructureIndex][0],
                                               NUM_LEVELS_LEVEL_STRUCTURES_X_Y_WIDTH_HEIGHT[activeLevelStructureIndex][1],
                                               (int)NUM_LEVELS_LEVEL_STRUCTURES_X_Y_WIDTH_HEIGHT[activeLevelStructureIndex][2],
                                               (int)NUM_LEVELS_LEVEL_STRUCTURES_X_Y_WIDTH_HEIGHT[activeLevelStructureIndex][3],
                                               ACTIVE_LEVEL_STRUCTURE_SPRITE_SHEET_SIZE[activeSpriteSheetSizeIndex]
                                              );
            levelStructures.push_back(ls);
            activeLevelStructureIndex++;
            activeSpriteSheetSizeIndex++;
        }
        levelIsLoaded = true;
    }
}


bool LevelManager::getLevelIsLoaded(){return levelIsLoaded;}
void LevelManager::setLevelIsLoaded(bool newLevelIsLoaded){levelIsLoaded = newLevelIsLoaded;}

std::vector<LevelStructure> LevelManager::getLevelStructures(){return levelStructures;}


 





#ifndef GAMESTATEMANAGER_H
#define GAMESTATEMANAGER_H
#include <string>
using namespace std;


class GameStateManager
{
    public:
        GameStateManager();
        ~GameStateManager();

        void incrementActiveGameState();
        void decrementActiveGameState();
        void selectGameState(int);

        void setActiveGameState(string);
        string getActiveGameState();
    protected:
    private:
        string GAME_STATES[4] = {"DEV_SCREEN", "TITLE_SCREEN", "OPTIONS_SCREEN", "LEVEL1"};
        string activeGameState = GAME_STATES[0];
};


#endif // GAMESTATEMANAGER_H



 




#include "GameStateManager.h"
#include <string>
using namespace std;


GameStateManager::GameStateManager()
{
    //ctor
}

GameStateManager::~GameStateManager()
{
    //dtor
}


void GameStateManager::incrementActiveGameState(){
    int counter = 0;
    for (string gs : GAME_STATES){
        if(activeGameState == gs){
            activeGameState = GAME_STATES[counter + 1];
            break;
        }
        counter++;
    }
}

void GameStateManager::decrementActiveGameState(){
    int counter = 0;
    for (string gs : GAME_STATES){
        if(activeGameState == gs){
            activeGameState = GAME_STATES[counter - 1];
            break;
        }
        counter++;
    }
}

void GameStateManager::selectGameState(int newActiveGameState){activeGameState = GAME_STATES[newActiveGameState];}


string GameStateManager::getActiveGameState(){ return activeGameState;}
void GameStateManager::setActiveGameState(string newActiveGameState){activeGameState = newActiveGameState;}



 





#include <SFML/Graphics.hpp>
#include <LevelManager.h>
#include <LevelStructure.h>
#include <iostream>


int main()
{
    // Create the main window
    sf::RenderWindow app(sf::VideoMode(1000, 600), "c++ SFML Game Engine");

    LevelManager lm;


        // Start the game loop
    while (app.isOpen())
    {

        // Process events
        sf::Event event;
        while (app.pollEvent(event))
        {
            // Close window : exit
            if (event.type == sf::Event::Closed)
                app.close();
        }


        app.clear();

        // rendering

        if(!lm.getLevelIsLoaded()) {
            lm.loadActiveLevel();
            for (LevelStructure ls : lm.getLevelStructures()) {
                app.draw(ls.getImage());

       // <------  Does not display Sprite objects, after they have been added to RenderWindow "app"

                // test
                cout << ls.getX() << " " << ls.getY() << " " << ls.getWidth() << " " << ls.getHeight() << endl;
            }
        }


        app.display();

    }

    return EXIT_SUCCESS;
}


 

Pages: [1]
anything