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 - arkus

Pages: [1]
1
General / Re: Access problem / Entity Manager
« on: September 02, 2013, 04:24:58 pm »
Quote
Modify it so the iterator gets dereferenced twice before the call and it should work.

I hadn't been aware that an iterator is like a pointer. It works fine now, thank you for helping!  :)

2
General / Re: Access problem / Entity Manager
« on: September 02, 2013, 07:14:28 am »
Quote
You should use pointers in list not objects:

okay i tried that but now I get the errors C2039 and C2839 when I try to call the functions with the iterator:

mEntityIt->Render(mRenderWindow);
  :-\

The compiler says that he needs the type "pointer to class".

3
General / Re: Access problem / Entity Manager
« on: September 01, 2013, 08:49:52 pm »
okay here is the whole project:

https://www.dropbox.com/s/ivi4c1pv2fhqd6s/loloid-attack.zip

You need to know that i created three test-asteroids (ast1,ast2,ast3) at the game class and call their update function to evade the access problem.

Thank you in anticipation!

4
General / Re: Access problem / Entity Manager
« on: September 01, 2013, 08:27:31 pm »
Just GetSprite() creates an error, but this is not the actual problem. The problem is that the entity manager only calls the entity functions but not the asteroid funtions (render, update, handleevents).

I think the cause is that the manager just puts entities in its list and doesn't even know that the asteroid class inherits from it:

void EntityManager::AddEntity(Entity *entity)
{
        bool mHit = false;

        for(mEntityIt = mEntityList.begin(); mEntityIt != mEntityList.end(); mEntityIt++)
        {
                if(mEntityIt->GetID() == entity->GetID())
                {
                        std::cout << "Entity with ID: " << mEntityIt->GetID() << " already exists" << std::endl;
                        mHit = true;
                }
        }

        if(mHit == false)
        {
                mEntityList.push_back(*entity);
        }
}

This just calls the entity but not the asteroid render function:

void EntityManager::Render()
{
        for(mEntityIt = mEntityList.begin(); mEntityIt != mEntityList.end(); mEntityIt++)
        {      
                mEntityIt->Render(mRenderWindow);
        }
}

I thought this would also call the asteroid functions, since they inherit from the entity class.

5
General / Re: Access problem / Entity Manager
« on: September 01, 2013, 08:02:39 pm »
Both classes (entity, asteroid) have their own render, update and handleevent function (the entity functions are virtual). The window only renders the entities when I call the draw function of the window in the entity-render-function:

#include "Entity.hpp"

Entity::Entity(std::string id)
{
        mTexture = new sf::Texture;
        mSprite  = new sf::Sprite;
        SetID(id);
}

Entity::~Entity()
{
}

void Entity::Render(sf::RenderWindow *rw) //virtual
{
        rw->draw(*this->GetSprite()); //works fine
}

void Entity::Update(float frametime) //virtual
{
}

void Entity::HandleEvents(sf::Event *ev) //virtual
{
}
 

#include "Asteroid.hpp"

Asteroid::Asteroid(std::string id) : Entity(id)
{
        //asteroid construct stuff
}

void Asteroid::Render(sf::RenderWindow *rw)
{
    rw->draw(*this->GetSprite()); //doesn't work
}

void Asteroid::Update(float frametime)
{      
}

void Asteroid::HandleEvents(sf::Event *ev)
{
}

6
General / Access problem / Entity Manager
« on: September 01, 2013, 07:35:32 pm »
I created an entity-basic class and the entities are managed by an entity-manager. I also created an asteroid class, which inherits from the entity class. The manager adds the entities to a list and calls their functions:

class EntityManager
{
public:
        EntityManager(sf::RenderWindow *rw,sf::Event *ev);
        ~EntityManager();

        void Render();
        void Update(float frametime);
        void HandleEvents();

        void AddEntity(Entity* entity);
        void KillEntity(std::string id);
        Entity GetEntity(std::string id);

private:
        std::list<Entity> mEntityList;
        std::list<Entity>::iterator mEntityIt;

        sf::RenderWindow *mRenderWindow;
        sf::Event *mEvent;
};

E.g. the render function:

void EntityManager::Render()
{
        for(mEntityIt = mEntityList.begin(); mEntityIt != mEntityList.end(); mEntityIt++)
        {      
                mEntityIt->Render(mRenderWindow);
        }
}

I declared the functions of the basic class as virtual functions and overwrote them at the asteroid class. The problem is that the manager only accesses the functions of the basic entity class, but not the functions of the asteroid class.

class Entity
{
public:

        Entity(std::string id);
        ~Entity();

        virtual void Render (sf::RenderWindow *rw);
        virtual void Update (float frametime);
        virtual void HandleEvents (sf::Event *ev);

        sf::Sprite*  GetSprite()   {return mSprite;};
        sf::Texture* GetTexture()  {return mTexture;};
        std::string  GetID()       {return mID;};
        bool         GetAlive()    {return mIsAlive;};

        void SetID(std::string id) {mID = id;};

private:

        sf::Texture *mTexture;
        sf::Sprite  *mSprite;  
        std::string mID;
        bool mIsAlive;

};

class Asteroid : public Entity
{
public:

        Asteroid(std::string id);

        void Render (sf::RenderWindow *rw);
        void Update (float frametime);
        void HandleEvents (sf::Event *ev);
       
        void UpdateMovement(float frametime);

private:

        float mSize;
        int mYPosition;
        int mRotation;
        int mSpeed;

};

Can I access the functions of the asteroid class by the entity-manager?
I hope I've explained my problem understandable, please ask if you need further information.

7
SFML projects / Re: My first space shooter
« on: August 31, 2013, 05:50:11 pm »
Hello!

I just wanted to tell you that I'm still working at the project. I've learned a lot about classes, states and stuff in the last weeks and already built a state-based menu with animated buttoms:  :)



Next I'll work at the game state with the engine and entity managing, but that will take time.

I'm still here!  ;)

8
SFML projects / Re: My first space shooter
« on: August 02, 2013, 01:43:16 pm »
Houston, we have a problem!

I wrote the entire code into main and already got over 1200 lines...  :o
It becomes more and more difficult to keep an overview and i really have to learn more about classes and all that stuff.
For this reason, i will stop the work on the actual projekt and will try to convert it into a clearer code...

9
Graphics / Re: sprite collision
« on: July 28, 2013, 07:02:43 pm »
Quote
IF you know for sure that the two objects are circles, you know that there is a collision is the distance of the two centers is less than, or equal, to the sum of the two radiuses. It will be much faster than doing complex pixel-perfect collision detection.

nice hint, i think this will work in most cases. thank you!

10
Graphics / sprite collision
« on: July 28, 2013, 05:31:54 pm »
Hi!

I'm looking for an easier way to manage the collosion of two sprites. at the moment, i use sprite.getposition().x/y of each sprite and compare the values with a certain tolerance:


Is there a function which compares the alpha channel of two sprites and spots a collision of them?
i need it especially for the collsion of round objects.

11
SFML projects / Re: My first space shooter
« on: July 28, 2013, 02:55:14 pm »
First of all thank you for all the feedback!  :D
Instead of starting a new level, the game just closes after the boss. i think i will create some new levels with different loloid-enemies before the boss attacks.

Quote
Unfortunatly I can't see the screenshots, so here are two other screenshots.

Thank you for uploading, i still have some trouble with uploading screenshots  :o
Pressing "insert image" with the dropbox hyperlink didn't work for me  :-\

Quote
How about making the asteroid speeds randomized as well (and maybe size, too). I'd say it'll be pretty easy to do since you already randomized their position, and a little variation would look great i think.

I've been thinking about that already, but i don't know how to make it. currently, i create the asteroids with a list and manage the movement and the rotation like this:

if((sf::Randomizer::Random(0,100) < asteroid_spawner) && (asteroid_bool) && (asteroid_list.size() < asteroid_max))
{
                sf::Sprite *asteroid;
                asteroid = new sf::Sprite;
                asteroid->SetImage(asteroid_img);
                asteroid->SetPosition(850+sf::Randomizer::Random(0,60),sf::Randomizer::Random(10,530));
                asteroid_it->Rotate(sf::Randomizer::Random(0,50));

                asteroid_list.push_back(*asteroid);
}

for(asteroid_it = asteroid_list.begin(); asteroid_it != asteroid_list.end(); asteroid_it++)
{
                        asteroid_it->Move(-100*Window.GetFrameTime(),0);
                        asteroid_it->Rotate(1);
                        asteroid_it->SetCenter(25,25);
{
 

Randomized speed and rotation would mean that i would have to create seperate lists for that, wouldn't it?  :o
Additionally, a randomized size would make the colliding between shot/asteroid and player/asteroid much more difficult because i adjusted it to the standard size (+- 25p):

if(schuss_it->GetPosition().y <= asteroid_it->GetPosition().y +25 &&
 schuss_it->GetPosition().y >= asteroid_it->GetPosition().y -25 &&
schuss_it->GetPosition().x >= asteroid_it->GetPosition().x -25)
//{delete asteroid}
 

agenda
- new sounds
- new levels (with new enemies)
- randomized asteroid size and rotation
- new ship upgrades (max armor, shot power, (suggestions?))
- a story (what are the loloids and what do they want?)

12
SFML projects / My first space shooter
« on: July 24, 2013, 11:06:55 pm »
Hey!  :)

I want to show you my first SFML projekt: "Loloid-Attack", a tiny space shooter.  8)
Three levels are finished yet, you gain kredits by killing enemies and you can buy upgrades at the end of the levels.

The whole content is self-made, the sprites are made with GIMP and the sounds with Reason Propellerhead (well the sounds are very annoying so far and only placeholders  :P).

Many functions such as a high score list and some items in the market are still not finished.
I appreciate any criticism, suggestions and bug reports.  ;D

Download: https://www.dropbox.com/s/tbgl26w66t3t5cf/loloid_attack.zip

Pages: [1]