Class not working with engine

This is a discussion on Class not working with engine within the C++ Programming forums, part of the General Programming Boards category; EDIT: Woops! I'm an idiot xP this is fixed now... And I forgot to declare a P1 variable, or how ...

  1. #1
    Hail to the king, baby. Akkernight's Avatar
    Join Date
    Oct 2008
    Location
    Faroe Islands
    Posts
    717

    Class not working with engine *FIXED*

    EDIT: Woops! I'm an idiot xP this is fixed now... And I forgot to declare a P1 variable, or how it's called >.<

    Well, I made this class and for some reason it ain't working o.o I blame the engine, 'cause I havn't got any of my includes working with it, but I've got no proof it's the engine xP
    NOTE: I'm about to move my globals into classes, so sorry for the mess xP
    Anyway, I've got this class
    Code:
    class P1
    {
    public:
    	P1();
    	~P1();
    
    	const float x;
    	float y;
    	float speed;
    
    };
    And it's giving me these errors, a load of them
    Code:
    error C2143: syntax error : missing ';' before '.'
    
    and
    
    warning C4832: token '.' is illegal after UDT 'P1'
    objects.h(5) : see declaration of 'P1'
    error C2275: 'P1' : illegal use of this type as an expression
    objects.h(5) : see declaration of 'P1'
    Well here's the code that worked when I used globals instead of classes
    Code:
    #include "objects.h"
    
    #include "hge.h"
    #include "hgeresource.h"
    #include "hgesprite.h"
    
    HGE *hge = 0;
    
    //resource managers
    hgeResourceManager* myRes;
    
    //sprites
    hgeSprite* ballSprite;
    hgeSprite* platformP1;
    hgeSprite* platformP2;
    
    
    //ball variables
    float ballX = 400, ballY = 300;
    float ballSpeed = 90;
    
    
    bool FrameFunc(){
    
    	float dt = hge->Timer_GetDelta();
    
    	if(hge->Input_GetKeyState(HGEK_ESCAPE)) return true;
    	//movement controls
    	//Player 1
    	if(hge->Input_GetKeyState(HGEK_W)) P1.y -= P1.speed*dt;
    	if(hge->Input_GetKeyState(HGEK_S)) P1.y += P1.speed*dt;
    	//player 2
    	if(hge->Input_GetKeyState(HGEK_UP)) P2.y -= P2.speed*dt;
    	if(hge->Input_GetKeyState(HGEK_DOWN)) P2.y += P2.speed*dt;
    
    	return false;
    }
    
    
    bool RenderFunc(){
    
    	hge->Gfx_BeginScene();
    	hge->Gfx_Clear(0);
    
    	ballSprite->RenderStretch(ballX, ballY, ballX + 16, ballY + 16);
    	//Render platformP1
    	platformP1->SetColor(0xFF0000FF);
    	platformP1->RenderStretch(P1.x, P1.y, P1.x + 10, P1.y + 64);
    	//Render platformP2
    	platformP2->SetColor(0xFFFF0000);
    	platformP2->RenderStretch(P2.x, P2.y, P2.x + 10, P2.y + 64);
    
    	hge->Gfx_EndScene();
    
    	return false;
    }
    
    int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int){
    
    	hge = hgeCreate(HGE_VERSION);
    
    	hge->System_SetState(HGE_LOGFILE, "LOGFILE.log");
    	hge->System_SetState(HGE_FRAMEFUNC, FrameFunc);
    	hge->System_SetState(HGE_RENDERFUNC, RenderFunc);
    	hge->System_SetState(HGE_TITLE, "HGE application");
    	hge->System_SetState(HGE_WINDOWED, true);
    	hge->System_SetState(HGE_SCREENWIDTH, 800);
    	hge->System_SetState(HGE_SCREENHEIGHT, 600);
    	hge->System_SetState(HGE_SCREENBPP, 32);
    
    	if(hge->System_Initiate()){
    
    		myRes = new hgeResourceManager("resource.res");
    		ballSprite = myRes->GetSprite("ballSprite");
    		platformP1 = myRes->GetSprite("platformSprite");
    		platformP2 = myRes->GetSprite("platformSprite");
    
    		hge->System_Start();
    
    		delete myRes;
    	}
    	else{
    		MessageBox(NULL, hge->System_GetErrorMessage(), "Error", MB_OK | MB_ICONERROR | MB_APPLMODAL);
    	}
    
    	hge->System_Shutdown();
    	hge->Release();
    
    	return 0;
    }
    Thanks in advance!
    Last edited by Akkernight; 01-26-2009 at 04:24 AM.
    Currently research OpenGL

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Creating a database
    By Shamino in forum Game Programming
    Replies: 19
    Last Post: 06-10-2007, 01:09 PM
  2. deriving classes
    By l2u in forum C++ Programming
    Replies: 12
    Last Post: 01-15-2007, 04:01 PM
  3. help working with class files for first time
    By jrb47 in forum C++ Programming
    Replies: 12
    Last Post: 11-30-2006, 08:20 AM
  4. Class not working!!! HELP
    By swgh in forum C++ Programming
    Replies: 1
    Last Post: 02-16-2006, 05:47 AM
  5. Need help to build network class
    By weeb0 in forum C++ Programming
    Replies: 0
    Last Post: 02-01-2006, 10:33 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21