Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Adam Eldemire

Pages: [1]
1
General / Checking for a non-transparent spot at (x,y)
« on: September 27, 2009, 09:56:37 pm »
That's essentially what I'm doing, using the Wiki collision code. However, it doesn't work at all: the 'player' goes straight through the wall.

2
General / Checking for a non-transparent spot at (x,y)
« on: September 27, 2009, 09:20:23 pm »
I don't get what you mean by "manage all the object's positions otherwise than by pixel checking". Do you mean I should check each pixel of one object and see if it collides with another object? That doesn't seem very efficient.

What I've been is creating a dummy object at the proper position (where the player is trying to move to) and of the right size, hiding it, and checking if it collides with a wall or other solid object. Here's my code:
Code: [Select]

bool Application::ObjAtPos(float x, float y, float xsize, float ysize, std::vector<Object*> * vec)
{
//[TODO]: Make this more efficent
//Right now, it creates an object
Object checker(x,y,this,"data/empty.tga");
checker.SetVisible(false);
checker.GetSprite().Resize(xsize,ysize);
std::vector<Object*> * vec0 = this->GetCollides(&checker);
if(vec0)
{
vec = vec0;
return true;
}
else
{
return false;
}
}

std::vector<Object*> * Application::GetCollides(Object * obj)
{
unsigned int i = 0;
std::vector<Object*> * ObjectCollides = new std::vector<Object*>;
for(i = 0; i <= objmap.size(); i++) //placeholder [TESTCODE]
{
try
{
if(objmap.empty() == true)//is the whole thing empty?
{
if(objmap.at(i))//is it empty?
{
if(collision.PixelPerfectTest(objmap.at(i)->GetSprite(),obj->GetSprite()))
{
ObjectCollides->push_back(objmap.at(i));
}
continue;
}
else //objmap's done
{
break;
}
}
else //empty, also due to stupidty
{
break;
}
}
catch(...)
{
GetLogger()->AddToFile("Some error was encountered.");
}
}

return ObjectCollides;
}


And then to use it:
Code: [Select]

void Object::Update()
{
float etime = app->GetRenderWindow()->GetFrameTime();
//std::cout << etime << "\n";
bool shouldmove = true;
//[TODO]: Find something to put here
//this->GetSprite().SetX(GetSprite().GetPosition().x + this->velocity.x);//Update the x to the correct one
//this->GetSprite().SetY(GetSprite().GetPosition().y + this->velocity.y);//Same
//this->app->GetLogger()->AddToFile(this->GetSprite().GetPosition().x);
//this->app->GetLogger()->AddToFile(this->GetSprite().GetPosition().y);

//new moving code
std::vector<Object*> * c_v = new std::vector<Object*>;
if(app->ObjAtPos(spr.GetPosition().x + (this->velocity.x * etime),spr.GetPosition().y,spr.GetSize().x,spr.GetSize().y,c_v))
{
//std::cout << " Started checking for densities (x).\n";
for(int i = 0;i < c_v->size();i++)
{
if(c_v->at(i)->GetDensity() > this->GetDensity())
{
//denser than this object
shouldmove = false;
std::cout << "Holy shit, higher density!\n";
break;
}
}
if(shouldmove == true)
{
this->Object::spr.SetX(this->Object::spr.GetPosition().x + (this->velocity.x * etime));
}
else
{
}
}
else
{
this->Object::spr.SetX(this->Object::spr.GetPosition().x + (this->velocity.x * etime));
}
//and for the y axis
if(app->ObjAtPos(spr.GetPosition().x,spr.GetPosition().y + (this->velocity.y * etime),spr.GetSize().x,spr.GetSize().y,c_v))
{
//std::cout << " Started checking for densities (y).\n";
for(int i = 0;i < c_v->size();i++)
{
std::cout << c_v->at(i)->GetDensity() << "\n" ;
if(c_v->at(i)->GetDensity() > this->GetDensity())
{
//denser than this object
shouldmove = false;
break;
}
}
if(shouldmove == true)
{
this->Object::spr.SetY(this->Object::spr.GetPosition().y + (this->velocity.y * etime));
}
else
{
}
}
else
{
this->Object::spr.SetY(this->Object::spr.GetPosition().y + (this->velocity.y * etime));
}


//this->Object::spr.SetX(this->Object::spr.GetPosition().x + (this->velocity.x * etime));
//this->Object::spr.SetY(this->Object::spr.GetPosition().y + (this->velocity.y * etime));
OnCollide(); //Does second part of updating
}


If you need anything else, ask.[/code]

3
General / Checking for a non-transparent spot at (x,y)
« on: September 27, 2009, 09:06:17 pm »
I'm wondering if there's a way to check for a sprite at a certain position. I'm trying to make a game, and I need to check if the space the player is trying to moving to is clear. Is there any way I could do this, preferably based on pixels (so that transparent parts wouldn't register).

4
Window / [Visual C++ 2008] Command Prompt not shutting down
« on: August 05, 2009, 11:38:30 pm »
It seems to happen whenever the render window is created outside of int main(). That seems to be all I can glean.

5
Window / [Visual C++ 2008] Command Prompt not shutting down
« on: August 05, 2009, 10:59:31 pm »
For my first SFML application ( a simple test app), as soon as I call
Code: [Select]
window->Close();
the console window closes immediatly. However, in my new project, I am forced to close the consloe window automatically. This causes some errors with my file logging system.

Is there a function that I have to add, or is my memory just foggy?

Pages: [1]