HiveBrain v1.2.0
Get Started
← Back to all entries
patterncppMinor

Gradius-like game

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
gradiusgamelike

Problem

I have some experience with OOP but I'm very new to game programming. For a school assignment, here's my first attempt at making a "real" game containing Entities, a game engine, game loop and the likes. I wanted to know if I used those concepts correctly, and would love to have some tips on things I could've done better.

GitHub

Here's the Entities header, from which everything is derived (players, enemies, asteroids...):

#ifndef A_ENTITIES_HPP
# define A_ENTITIES_HPP

#include 
#include 

class AEntities
{
private:
    AEntities(void);

protected:
    WINDOW const *      _win;
    int                 _x, _y;
    int                 _winwidth, _winheight;
    char                _char;
    AEntities *         _missile;

public:

    AEntities(WINDOW const * win, int x, int y, char caract);
    virtual ~AEntities(void);
    AEntities(AEntities const &src);

    AEntities &operator=(AEntities const & rhs);

    virtual void        movement() = 0;
    virtual void        update(void) = 0;

    void                draw(void);
    void                del(void);

    bool                impact(AEntities * entities) const;

    int                 getX(void) const;
    int                 getY(void) const;
    char                getChar(void) const;
    AEntities *         getMissile(void) const;

    static int          loopCount;
};

#endif


And here's the GameEngine which contains a array of pointers to Entities, for their management:

AEntities *                 _entities[ENTITIES_MAX];


Code:

```
#include "GameEngine.hpp"

GameEngine::GameEngine(void)
{
initscr();
nodelay(stdscr, TRUE);
keypad(stdscr, TRUE);
noecho();
curs_set(0);
getmaxyx(stdscr, _winheight, _winwidth);
_p1 = new Player(stdscr, 0, _winheight / 2);
_win = stdscr;
for (int i = 0; i draw();
for (int i = 0; i draw();
}
}

void GameEngine::addEntity(AEntities * entity)
{
for (int i = 0; i del();
_p1->update();

Solution

One remark regarding the way collisions are handled:

bool playerColision(void);
void entityColision(void);


Basically what you want to do when you have a generic game engine is the possibilty to reuse your code, instead of having a distinction between "Player" and "AEntities" inside your GameEngine, your GameEngine could only handle "AEntities" entities and having a callback to call in the AEntity class

void OnCollision(AEntity* other);


This way each class could handle the collision the way they want.

Code Snippets

bool playerColision(void);
void entityColision(void);
void OnCollision(AEntity* other);

Context

StackExchange Code Review Q#86712, answer score: 6

Revisions (0)

No revisions yet.