Yeah I replaced it all and it works but I get that break so do you just want my rigidbox class or should I just give you my all my source files?
I will give you the GameObject class which is what it derives from and the rigid box class for now:
GameObject.h
#ifndef GAMEOBJECT_H
#define GAMEOBJECT_H
#include "Box2D.h"
#include "Render.h"
#include "DarkGDK.h"
#include "Input.h"
class GameObject
{
public:
GameObject(int Xpos,int Ypos,float SpriteScale,int SpriteID,int TextureID,b2World* world);
virtual void Update();
virtual b2Body* GetBody();
virtual b2Vec2 GetPosition();
virtual void Delete(b2World* world);
protected:
#define b2PixelRatio 30.0f
int m_posX;
int m_posY;
int m_SpriteID;
int m_TextureID;
float m_scale;
float32 m_angle;
b2Vec2 m_position;
b2Body* p_body;
b2BodyDef p_bodyDef;
b2PolygonDef p_shapeDef;
b2CircleDef p_circleDef;
};
#endif
GameObject.cpp
#include "GameObject.h"
GameObject::GameObject (int Xpos,int Ypos,float SpriteScale,int SpriteID,int TextureID,b2World* world)
{
m_posX = Xpos;
m_posY = Ypos;
m_SpriteID = SpriteID;
m_TextureID = TextureID;
m_scale = SpriteScale;
dbSprite(m_SpriteID,0,0,m_TextureID);
dbOffsetSprite(m_SpriteID,dbSpriteWidth(m_SpriteID)/2,dbSpriteHeight(m_SpriteID)/2);
dbScaleSprite(m_SpriteID,m_scale);
p_bodyDef.position.Set(m_posX /b2PixelRatio, m_posY /b2PixelRatio);
p_body = world->CreateBody(&p_bodyDef);
p_shapeDef.SetAsBox((dbSpriteWidth(m_SpriteID)/b2PixelRatio)/2.0f, (dbSpriteHeight(m_SpriteID)/b2PixelRatio)/2.0f);
p_body->CreateShape(&p_shapeDef);
}
void GameObject::Update()
{
m_angle = p_body->GetAngle();
m_position = p_body->GetPosition();
m_position.x *= b2PixelRatio;
m_position.y *= b2PixelRatio;
m_angle *= (180.0 / 3.141592653589793238);
dbSprite(m_SpriteID,m_position.x,m_position.y,m_TextureID);
//dbPasteSprite(m_SpriteID,m_position.x,m_position.y);
dbRotateSprite(m_SpriteID, m_angle);
dbText(5,5,dbStr(m_position.x));
dbText(5,20,dbStr(m_position.y));
}
b2Body* GameObject::GetBody()
{
return p_body;
}
b2Vec2 GameObject::GetPosition()
{
return p_body->GetPosition();
}
void GameObject::Delete(b2World* world)
{
world->DestroyBody(p_body);
dbDeleteSprite(m_SpriteID);
}
RigidBox.h
#ifndef RIGIDBOX_H
#define RIGIDBOX_H
#include "Box.h"
class RigidBox: public Box
{
public:
RigidBox(int Xpos,int Ypos,float SpriteScale,int BoxID,int SpriteID,b2World* world);
//virtual void Initialize(b2World*);
protected:
};
#endif
RigidBox.cpp
#include "RigidBox.h"
RigidBox::RigidBox (int Xpos,int Ypos,float SpriteScale,int BoxID,int SpriteID,b2World* world):
Box(Xpos,Ypos,SpriteScale,BoxID,SpriteID,world)
{
p_shapeDef.density = 1.0f;
p_shapeDef.friction = 0.3f;
p_body->CreateShape(&p_shapeDef);
p_body->SetMassFromShapes();
}
RigidBox derives from box which derives fro game object but box and rigidbox are almost the exact same thing just two lines of code difference so gameobject is probably going to help more
Also this is where the break takes me if it helps. It is a file from box2d.
b2Body* b2World::CreateBody(const b2BodyDef* def)
{
b2Assert(m_lock == false);
if (m_lock == true)
{
return NULL;
}
void* mem = m_blockAllocator.Allocate(sizeof(b2Body));
b2Body* b = new (mem) b2Body(def, this);
// Add to world doubly linked list.
b->m_prev = NULL;
b->m_next = m_bodyList;
if (m_bodyList)
{
m_bodyList->m_prev = b;
}
m_bodyList = b;
++m_bodyCount;
return b;
}