Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


AhmedCoeia

Member Since 21 May 2012
Offline Last Active Yesterday, 06:30 PM

Topics I've Started

Review of class rendering code using marmalade c++

24 February 2015 - 04:42 PM

Hi All,

I'm trying to clone space invader of atari and I have problem with bounding rect calculations.. the rect is not correctly bounded.. maybe I have problem with the transformations 

void Barrier::Render()
{
	 
	if (mBarrierImage)
	{
		CIwFMat2D Transform;
		// Build transform
		Transform.SetIdentity();
		Transform.SetRot(0);
		Transform.ScaleRot(1);
		Transform.SetTrans(Position);
		Iw2DSetTransformMatrix(Transform);

		Iw2DSetColour(0xffffffff);
	 
	CIwFVec2 pos = Transform.t;
	BoundingRect.x = Position.x;
	BoundingRect.y = Position.y;
	BoundingRect.w = (float)mBarrierImage->GetWidth();
	BoundingRect.h = (float)mBarrierImage->GetHeight();
	Iw2DSetColour(0xff0000ff); // Set red
	Iw2DDrawRect(CIwFVec2(pos.x, pos.y), CIwFVec2(mBarrierImage->GetWidth(), mBarrierImage->GetHeight())); // Draw red outline

}


blast a solid black circle

23 February 2015 - 01:56 PM

Hi All,

I'm trying to clone space invader, collision with the green barriers.

Right now I have access to the pixels of the green barrier

I would like to draw a solid black circle around the collision point of the bullet, right now I'm using the following code, but it spread random pixels, not solid black circle and it's center the hitting point

 

int radius = 44;
for (int y = -radius; y <= radius; y++)
{
for (int x = -radius; x <= radius; x++)
{
if (x*x + y*y <= radius*radius)
{
int j = y + bullet.x;
int i = x + bullet.y;
uint8 pixelOffset = j*4 + i*pitch;
ptr += pixelOffset;
*ptr = 0xff000000;
}
}
}

Building Mesh topology the math behind it

23 February 2015 - 04:53 AM

I'm trying to know the math of building a topology like that from a set of vertices P1,P2,P3, and get the desired indices for those triangles. Currently I'm just making a plane but I don't take account of vertices P1, P2 or make the first triangle and the last one.

public static void CreatePlane(int width, int height, Transform transform, int segmentsWidth, int segmentsHeight)
{
int ix,
iy,
widthHalf = width / 2,
heightHalf = height / 2,
gridX = segmentsWidth,
gridY = segmentsHeight,
gridX1 = gridX + 1,
gridY1 = gridY + 1,
segmentWidth = width / gridX,
segmentHeight = height / gridY;

Vector3 normal = new Vector3(0, 0, 1);
List<Vector3> vertices = new List<Vector3>();
List<Vector3> vertexNormals = new List<Vector3>();
List<int> faces = new List<int>();
List<Vector2> faceVertexUvs = new List<Vector2>();

int cnt = 0;
for (iy = 0; iy < gridY1; iy++)
{
for (ix = 0; ix < gridX1; ix++)
{
float x = ix * segmentWidth - widthHalf;
float y = iy * segmentHeight - heightHalf;
vertices.Add(new Vector3(x, -y, 0));
}
}

for (iy = 0; iy < gridY; iy++)
{
for (ix = 0; ix < gridX; ix++)
{
int a = ix + gridX1 * iy;
int b = ix + gridX1 * (iy + 1);
int c = (ix + 1) + gridX1 * (iy + 1);
int d = (ix + 1) + gridX1 * iy;
faces.Add(a);
faces.Add(b);
faces.Add(c);
faces.Add(d);
faceVertexUvs.Add(new Vector2(ix / gridX, iy / gridY));
faceVertexUvs.Add(new Vector2(ix / gridX, (iy + 1) / gridY));
faceVertexUvs.Add(new Vector2((ix + 1) / gridX, (iy + 1) / gridY));
faceVertexUvs.Add(new Vector2((ix + 1) / gridX, iy / gridY));
}
}
// create mesh
GameObject plane = new GameObject("TreePlane");
plane.transform.position = transform.position;
plane.transform.rotation = transform.transform.rotation;

MeshFilter mf = (MeshFilter)plane.AddComponent(typeof(MeshFilter));
Mesh m = mf.mesh;
m.vertices = vertices.ToArray();
m.SetIndices(faces.ToArray(), MeshTopology.Quads, 0);
m.uv = faceVertexUvs.ToArray();
MeshRenderer renderer = plane.AddComponent(typeof(MeshRenderer)) as MeshRenderer;
Material material = (Material)Resources.Load("Red", typeof(Material));

if (renderer != null)
{
renderer.sharedMaterial = material;
}
m.RecalculateBounds();
m.RecalculateNormals();
}

pwE1e.png


blasting filled circle in space invader

18 February 2015 - 05:25 PM

Hi, I'm trying to implement spaceinvader atari collision where the barriers are hit, there are blasting black pixels around the barrier when they are hit.

 

Right now I subtract the rectangle of the bullet from the rectangle of the barrier, then I try to draw a solid filled circle of black, but the result is a random pixels that are set into the bitmap. I don't know why...

bool CheckCollisionNewBarriers(Ship *ship, vector<Barrier*> *barriers, CIwTexture *tex, uint8*pixels, uint32 pitch, Resources *gameResources)
{
	bool isCollision = false;
	for (vector<Barrier*>::iterator itBarrier = barriers->begin(); itBarrier != barriers->end();)
	{
		for (list<Bullet*>::iterator it = ship->Bullets->begin(); it != ship->Bullets->end();)
		{
			if (IntersectsWith((*it)->BoundingRect, (*itBarrier)->BoundingRect))
			{

				//cRect bounding = Intersection((*it)->BoundingRect, (*itBarrier)->BoundingRect);
				 
				int normX = (*it)->BoundingRect.x - (*itBarrier)->BoundingRect.x;
				int normY = (*it)->BoundingRect.y - (*itBarrier)->BoundingRect.y;

				uint32* ptr = (uint32*)pixels;
				int radius = 4;
				for (int y = -radius; y <= radius; y++)
				{
					for (int x = -radius; x <= radius; x++)
					{
						if (x*x + y*y <= radius*radius)
						{
							int j = normY + y;
							int i = normX + x;
							uint8 pixelOffset = j + i*pitch;
							ptr += pixelOffset;
							*ptr = 0xff000000;
						}
					}
				}

is anybody psycho here?

18 February 2015 - 04:12 PM

Hi All,

I'm diagnosed with bipolar disorder.. is anybody here doing gamedev professionally and taking antipsychotics, antidepressants? 


PARTNERS