Sorry, but I need a pastebin in a hurry! :/
http://www.2shared.com/file/4729264/.../platform.html
http://www.2shared.com/file/4729268/9e6fccbc/Ball.html
main.cpp
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;
//My classes
player1 P1;
player2 P2;
Cball ball;
bool FrameFunc(){
float dt = hge->Timer_GetDelta();
if(ball.moving){
ball.x += ball.speed * dt;
}
if(hge->Input_GetKeyState(HGEK_ESCAPE)) return true;
if(hge->Input_GetKey() == HGEK_SPACE) ball.moving = 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;
P1.wallCollide();
P2.wallCollide();
return false;
}
bool RenderFunc(){
hge->Gfx_BeginScene();
hge->Gfx_Clear(0);
ballSprite->RenderStretch(ball.x, ball.y, ball.x + 16, ball.y + 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;
}
platformP1.cpp
Code:
#include "objects.h"
player1::player1(){
y = 236;
speed = 500;
}
player1::~player1(){
}
void player1::wallCollide(){
if(y>600 - 65) {y = 600 - 65;}
if(y<1) {y = 1;}
}
objects.h
Code:
#ifndef OBJECTS_H
#define OBJECTS_H
class player1
{
public:
player1();
~player1();
static const int x = 20;
float y;
float speed;
void wallCollide();
protected:
};
class player2
{
public:
player2();
~player2();
static const int x = 800 - 30;
float y;
float speed;
void wallCollide();
protected:
};
class Cball
{
public:
Cball();
~Cball();
float x, y;
float speed;
bool moving;
int sendDir();
};
#endif
platformP2.cpp
Code:
#include "objects.h"
player2::player2(){
y = 236;
speed = 500;
}
player2::~player2(){
}
void player2::wallCollide(){
if(y>600 - 65) {y = 600 - 65;}
if(y<1) {y = 1;}
}
ball.cpp
Code:
#include "objects.h"
Cball::Cball(){
x = 400;
y = 300;
speed = 250;
moving = false;
}
Cball::~Cball(){
}