Example #1
0
void Game::testCollision(Object& object)
{
    if(object.x() < 0) object.x(0);
    if(object.y() < 0) object.y(0);
    if(object.x()+1 > cols) object.x(cols-1);
    if(object.y()+1 > rows) object.y(rows-1);
}
Example #2
0
void GameObjectView::setViewPosition( Object& obj,
                                      const ProtoObject::View & v,
                                      float x,
                                      float y,
                                      float z,
                                      float interp ) {
  float dx = 0, dy = 0, dz = 0;
  double modelSize[3] = { obj.bounds().max[0] - obj.bounds().min[0],
                          obj.bounds().max[1] - obj.bounds().min[1],
                          obj.bounds().max[2] - obj.bounds().min[2] };

  const int * align = v.align;
  double alignSize  = v.alignSize;

  dx = modelSize[0]*obj.sizeX()*align[0]*alignSize;
  dy = modelSize[1]*obj.sizeY()*align[1]*alignSize;
  dz = modelSize[2]*obj.sizeZ()*align[2]*alignSize;

  float lx = obj.x() + (x+dx - obj.x())*interp;
  float ly = obj.y() + (y+dy - obj.y())*interp;
  float lz = obj.z() + (z+dz - obj.z())*interp;

  if( lx!=obj.x() || ly!=obj.y() || lz!=obj.z() )
    obj.setPosition( lx,ly,lz );
  }
Example #3
0
void Game::moveEnemyClose(Object& player, Object& enemy)
{
    if(player.x() > enemy.x()) enemy.moveRight();
    if(player.x()+1 < enemy.x()) enemy.moveLeft();
    if(player.y() > enemy.y()) enemy.moveDown();
    if(player.y()+1 < enemy.y()) enemy.moveUp();
}
Example #4
0
bool Game::tooClose(Object& player, Object& enemy)
{
    if ((player.x() > enemy.x() - 15) &&
        (player.x()+1 < enemy.x() + 15) &&
        (player.y() > enemy.y() - 15) &&
        (player.y()+1 < enemy.y() + 15))
    {
        moveEnemyClose(player, enemy);
        return true;
    }
    else return false;
}
Example #5
0
void testApp::walls() {
  for (list<Object*>::iterator oi = objects.begin(); oi != objects.end(); oi++) {
		Object* o = *oi;
    
		if (o->x() < boxArray[1].max.x && o->x() > boxArray[1].min.x && o->y() < boxArray[1].max.y && o->y() > boxArray[1].min.y) {
			o->binWorld = true;
		}
		else {
			o->binWorld = false;
		}
		if (oi == objects.end()) break;
  }
}
Example #6
0
void testApp::draw_objects() {
	for (list<Object*>::iterator oi = objects.begin(); oi != objects.end(); oi++) {
		Object* o = *oi;
		ofSetColor(255, 0, 0);
		ofFill();
		ofCircle(o->x(), o->y(), 25);
		
		o->info(arial);
	}
}
void Scene::display() {
    // Set lighting
    light.setLighting();
    // Set background color
    glClearColor(backgroundColor[0],
                 backgroundColor[1],
                 backgroundColor[2],
                 backgroundColor[3]);
 	glColor3f(1,1,1);
    if (drawAxesOn) drawAxes(-(worldX/2)-5, -(worldY/2)-5, -(worldZ/2)-5);

    // Draw real time scene
    /*
    Thing thing;
    unsigned long nObjects = model.get_num_objects();
    Vec3 * p = 0;
    Vec3 * r = 0;
    double * a = 0;

    for (unsigned long i=0; i<nObjects; i++) {
        model.get_next_object_state(&p,&r,&a);
        if (p != 0) {
            thing.Cube(p->x, p->y, p->z,
                       0.4,0.4,0.4,
                       *a,p->x,p->y,p->z);
        }
        else { std::cout << "its zero" << std::endl;}
    }
    */
    // Draw box bounding the world
    WireframeCube(0,0,0,
                  worldX,worldY, worldZ,
                  0,0,0,0);

    // Draw recorded scene
    double radius = 1.0;
    FrameState * frame = reader.get_next_frame();
    if (frame != 0) {
        unsigned long nObjects = frame->get_num_objects();
        for (unsigned long i=0; i<nObjects; i++) {
            Object * o = frame->get_object(i);
            if (o != 0) {
                // Set color based on id
                int origin = o->getID() >> 28;
 	            glColor3f(colors[origin].x, colors[origin].y, colors[origin].z);


                // Draw an object from the animation record file
                //Cube(o->x(), o->y(), o->z(),
                //           0.4,0.4,0.4,
                //           o->a_r(),o->x_r(),o->y_r(),o->z_r());
                Sphere(o->x(), o->y(), o->z(), radius);
            }
        }
Example #8
0
bool Game::contact(Object& player, Object& object)
{
    return ((player.x() >= object.x()-1 && player.x() <= object.x()+1) && 
            (player.y() >= object.y()-1 && player.y() <= object.y()+1));
}
Example #9
0
void Game::randLocation(Object& object)
{
    object.x(rand()%cols);
    object.y(rand()%rows);
}