Problem With Game Object Class and Game World Class

Discussion in 'Game Design' started by King0K, Sep 7, 2018.

  1. King0K

    King0K New Member

    Joined:
    Sep 7, 2018
    Messages:
    1
    Likes Received:
    0
    Hello

    I'm a beginner in game programming and I'm programming in visual studio 2017 with OpenGL and SDL2 libraries
    Every time I try to build my project i have this problem and i don't what is the problem:

    Code:
    1>------ Build started: Project: TheGame, Configuration: Debug Win32 ------
    1>Cube.cpp
    1>c:\users\king0k13\documents\games\thegame\thegame\game.h(18): error C2143: syntax error: missing ';' before '*'
    1>c:\users\king0k13\documents\games\thegame\thegame\game.h(18): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    1>Main.cpp
    1>Generating Code...
    1>Done building project "TheGame.vcxproj" -- FAILED.
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
    
    These are my Project files:

    - Game.h

    Code:
    #pragma once
    
    #ifndef _GAME_H_
    #define _GAME_H_
    
    #include <iostream>
    #include <SDL.h>
    #include <SDL_opengl.h>
    #include <SOIL.h>
    #include <gl/gl.h>
    #include <string>
    
    #include "Cube.h"
    
    #define ScreenWidth 600
    #define ScreenHeight 600
    
    Cube* cube1;
    
    class Game
    {
    public:
        // Constructors
        Game();
        ~Game();
    
        // Functions
        void Initialize();
        void SetOpenGLAttributes();
    
        void InputHandler();
        void Update();
        void Render();
        void Clean();
    
        // Globals
        bool RunningStatus;
    
    private:
        SDL_Window* GameScreen;
        SDL_GLContext GameContext;
        SDL_Event GameEvents;
    };
    
    #endif
    ---------------------------------------------------------------------------------------------------------------

    - Game.cpp

    Code:
    #include "Game.h"
    
    Game::Game()
    {
    }
    Game::~Game()
    {
    }
    
    /****************************************************************************/
    
    void Game::Initialize()
    {
        // Initilizng SDL
        if (SDL_Init(SDL_INIT_VIDEO) == 0)
        {
            std::cout << "SDL Initialized succesfully!" << std::endl;
        }
        else
        {
            std::cout << "Failed Initializing SDL : " << SDL_GetError() << std::endl;
            RunningStatus = false;
        }
    
        // Setting-Up The Game Screen
        GameScreen = SDL_CreateWindow("The Game",
            SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
            ScreenWidth, ScreenHeight, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
        if (GameScreen == NULL) // Handling Errors
        {
            std::cout << "SDL Failed Creating Window : " << SDL_GetError() << std::endl;
            RunningStatus = false;
        }
        else
        {
            std::cout << "Creating Window Succesful!" << std::endl;
            std::cout << "Window Data : \n" << "\tTitle : The Game\n\tX , Y Position : (CENTERED , CENTERED)\n\tWidth and Height : (" << ScreenWidth << " , "  << ScreenHeight << ")\n\tFlags : OpenGL | Shown\n" << std::endl;
        }
    
        // Creating Game Context for OpenGL use
        GameContext = SDL_GL_CreateContext(GameScreen);
        SetOpenGLAttributes(); // Setting OpenGLAttributes
        SDL_GL_SetSwapInterval(1);
    
        RunningStatus = true; // Turning on The Game Loop
    
        cube1->LoadTexture();
        cube1->ActiveTexture();
    }
    
    /****************************************************************************/
    
    void Game::SetOpenGLAttributes()
    {
        SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
        SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
        SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
        SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
    }
    
    /****************************************************************************/
    
    void Game::InputHandler()
    {
        while (SDL_PollEvent(&GameEvents))
        {
            switch (GameEvents.type)
            {
            case SDL_QUIT:
                RunningStatus = false;
                break;
    
            case SDL_KEYDOWN:
                switch (GameEvents.key.keysym.sym)
                {
                case SDLK_w:
                    break;
    
                case SDLK_a:
                    break;
    
                case SDLK_s:
                    break;
    
                case SDLK_d:
                    break;
    
                default:
                    break;
                }
                break;
            default:
                break;
            }
        }
    }
    
    /****************************************************************************/
    
    void Game::Update()
    {
        cube1->SetPosition(0, 0);
    }
    
    /****************************************************************************/
    
    void Game::Render()
    {
    
        SDL_GL_SwapWindow(GameScreen);
    }
    
    /****************************************************************************/
    
    void Game::Clean()
    {
        cube1->UnloadTexture();
    
        SDL_GL_DeleteContext(GameContext);
        SDL_DestroyWindow(GameScreen);
        SDL_Quit();
    }
    -----------------------------------------------------------------------------------------------------------------

    - Cube.h

    Code:
    #pragma once
    
    #ifndef _CUBE_H_
    #define _CUBE_H_
    
    #include "Game.h"
    
    class Cube
    {
    public:
        // Constractors
        Cube();
        ~Cube();
    
        // Functions
        void SetPosition(int x, int y);
        int GetPosition();
        void LoadTexture();
        void ActiveTexture();
        void UnloadTexture();
    
        // Globals
        //bool Hide;
    
    private:
        // Cube Position
        int X_pos;
        int Y_pos;
        //int Z_pos;
    
        // Cube Graphic
        unsigned char* CubeTexture;
        GLuint TextureID;
        int Channels;
        int Format;
        int T_Width;
        int T_Height;
    };
    
    #endif
    ----------------------------------------------------------------------------------------------------------------

    - Cube.cpp

    Code:
    #include "Cube.h"
    
    Cube::Cube()
    {
    }
    Cube::~Cube()
    {
    }
    
    /****************************************************************************/
    
    void Cube::SetPosition(int x, int y)
    {
        X_pos = x;
        Y_pos = y;
    }
    
    /****************************************************************************/
    
    int Cube::GetPosition()
    {
        return X_pos, Y_pos;
    }
    
    /****************************************************************************/
    
    void Cube::LoadTexture()
    {
        Channels = 0;
        CubeTexture = SOIL_load_image("assets/Block.png",
            &T_Width, &T_Height, &Channels, SOIL_LOAD_AUTO);
        if (CubeTexture == NULL)
        {
            std::cout << "SOIL Failed to Load Texture" << std::endl;
        }
    
        Format = GL_RGB;
        if (Channels == 4)
        {
            Format = GL_RGBA;
        }
    
        glGenTextures(1, &TextureID);
        
        glBindTexture(GL_TEXTURE_2D, TextureID);
        glTexImage2D(GL_TEXTURE_2D, 0, Format, T_Width, T_Height, 0,
            Format, GL_UNSIGNED_BYTE, CubeTexture);
        
        SOIL_free_image_data(CubeTexture);
    
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    }
    
    void Cube::ActiveTexture()
    {
        glBindTexture(GL_TEXTURE_2D, TextureID);
    }
    
    void Cube::UnloadTexture()
    {
        glDeleteTextures(1, &TextureID);
    }
    
    -----------------------------------------------------------------------------------------------------------------

    - Main.cpp

    Code:
    #include "Game.h"
    
    int main(int argc, char* argv[])
    {
        Game TheGame;
    
        TheGame.Initialize();
    
        while (TheGame.RunningStatus)
        {
            TheGame.InputHandler();
            TheGame.Update();
            TheGame.Render();
        }
    
        TheGame.Clean();
    
        return 0;
    }
    I would be really happy if someone helps me to fix the error.

    P.S. : If someone have any good advice to help me coding my project better please tell me!
     

Share This Page

  • About Indie Gamer

    When the original Dexterity Forums closed in 2004, Indie Gamer was born and a diverse community has grown out of a passion for creating great games. Here you will find over 10 years of in-depth discussion on game design, the business of game development, and marketing/sales. Indie Gamer also provides a friendly place to meet up with other Developers, Artists, Composers and Writers.
  • Buy us a beer!

    Indie Gamer is delicately held together by a single poor bastard who thankfully gets help from various community volunteers. If you frequent this site or have found value in something you've learned here, help keep the site running by donating a few dollars (for beer of course)!

    Sure, I'll Buy You a Beer