A 'for' Problem

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
zapakitul
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 15
Joined: Sat Jun 20, 2009 8:05 pm
Current Project: Swift
Favorite Gaming Platforms: PC, SNES, DS
Programming Language of Choice: C
Contact:

A 'for' Problem

Post by zapakitul »

I loaded an object [square-like model] and copied it 9 times into the memory using GDK. What I'm trying to do is position that object, something like this:
Image
But I can't do it right.
Here's what I tried so far:
Attempt1:

Code: Select all

	for(WorldObjects = 1; WorldObjects <= 9; WorldObjects++)
	{
		for(SizeX = 1; SizeX <= 3; SizeX++)
		{
			for(SizeZ = 1; SizeZ <= 3; SizeZ++)
			{
		 dbPositionObject(WorldObjects,dbObjectPositionX(WorldObjects)+SizeX,dbObjectPositionY(WorldObjects),			dbObjectPositionZ(WorldObjects)+SizeZ);
			}
		}
	}
Attempts2:

Code: Select all

float offset=0.35;
int i;
int j;
..........................................................................
for(WorldObjects = 1; WorldObjects <= 9; WorldObjects++)
	{	
		for(i=0;i<3;i++)
		{
			for(j=0;j<3;j++){
			dbPositionObject(WorldObjects,0+offset*i,0,0+offset*j);
			}
		}
	}
Any ideas what am I doing wrong?
User avatar
avansc
Respected Programmer
Respected Programmer
Posts: 1708
Joined: Sun Nov 02, 2008 6:29 pm

Re: A 'for' Problem

Post by avansc »

mmm... i didnt read over your code. but i'll give you a generic listing..

i'll assume that surface[9] holds the images/surfaces.
i'll assume that they are 50 units wide.
i'll assume that the print function is screen->displaySurface(arg image, arg x, arg y);

Code: Select all

for(int y = 0;y < 3;y++)
{
    for(int x = 0;x < 3;x++)
    {
        screen->displaySurface(surface[y*3+x], x*50, y*50);
    } 
}
i think that will work but i kinds just went off of memory.
Some person, "I have a black belt in karate"
Dad, "Yea well I have a fan belt in street fighting"
Post Reply