Jump to content

  • Log In with Google      Sign In   
  • Create Account


__UFNHGGI_H__

Member Since 02 Dec 2012
Offline Last Active Private
-----

#5097199 Component based system

Posted by __UFNHGGI_H__ on 27 September 2013 - 05:02 AM

https://github.com/UFNHGGI/CBGE

 

try it wink.png

 

sample :

///////////////////FreeMove.h
#pragma once
#include <Engine.h>

class CFreeMove : CComponent
{
	SVec2 moveSpeed;

	COMPONENT_REG_BEGIN(CFreeMove, true)
	COMPONENT_REG_VAR(moveSpeed, true)	//automatic registration :O
	COMPONENT_REG_END()

	void onCreate()
	{
		moveSpeed = SVec2(RandRange(1, 5));
	}
	void onUpdate()
	{
		if(CInput::KeyDown('D'))
			owner()->position.x += moveSpeed.x;
		else if(CInput::KeyDown('A'))
			owner()->position.x -= moveSpeed.x;

		if(CInput::KeyDown('W'))
			owner()->position.y -= moveSpeed.y;
		else if(CInput::KeyDown('S'))
			owner()->position.y += moveSpeed.y;
	}
};

///////////////FreeMove.cpp
#include "FreeMove.h"
COMPONENT_IMPL(CFreeMove);



#5006520 How do you check collision against 1000x1000 objects?

Posted by __UFNHGGI_H__ on 03 December 2012 - 01:24 AM

hehe
1000 * 1000 == BOOOM Posted Image

The first solution ::

class Object
{
bool receiveCollision;
};
//player.receiveCollision = true;
//block.receiveCollision = false;
//items.receiveCollision = false;
for(int i = 0; i < objects.size(); ++i)
{
Object* obj =  objects[i];
if(obj->receiveCollision)
{
  for(int j = 0; j < objects.size(); ++i)
  {
   collisionCheck(obj, objects[j])
  }
}
}

The second solution ::

enum Tags { TagPlayer, TagEnemy, TagBlock, TagWeapons};
class Object
{
Tags tag;
std::vector<Tags> collisionTags;
};
for(int i = 0; i < objects.size(); ++i)
{
Object* obj =  objects[i];
for(int j = 0; j < obj->collisionTags.size(); ++i)
{
  for(int k = 0; k < objects.size(); ++k)
  {
   if(obj->collisionTags[j] == objects[k].tag )
   {
    collisionCheck(obj, objects[k]);
   }
  }
}
}

Posted Image


PARTNERS