Example #1
0
File: TGApp.cpp Project: Nuos/DnDTG
void TGApp::polygonOverlay()
{
	//We need to build the polygons from points
	for_each(world->regions.begin(), world->regions.end(), [&] (pair<int,MapRegion*> pr)
	{		
		MapRegion* r = pr.second;
		if(!r->edge)
		{
			vector<mPoint> pizzoints = r->sortedPoints();
			mPoint c = r->getCentroid();
			ScreenShape *s = new ScreenShape(ScreenShape::SHAPE_CUSTOM);
			s->setPosition(c.x ,c.y);
			for_each(pizzoints.begin(), pizzoints.end(), [&] (mPoint v)
			{
				s->addShapePoint(v.x - c.x,v.y - c.y);
			});						
			if(r->ocean)
				s->setColor(r->elevation/2,r->elevation/2,r->elevation,1);
			//TODO: Parameterize essentialy this "lake threshold"
			else if(r->rainLevel > .2)
				s->setColor(r->elevation/1.5f,r->elevation/1.5f,r->elevation,1);
			else
				s->setColor(r->elevation,r->elevation,r->elevation,1);			
			s->strokeEnabled = true;
			s->setStrokeColor(1,1,0,1);
			s->setStrokeWidth(1);
			polOver.push_back(s);
			screen->addChild(s);
			r->myShape = s;
			//screen->addCollisionChild(s, PhysicsScreenEntity::ENTITY_MESH);		
		}
	});
}
Example #2
0
HelloPolycodeApp::HelloPolycodeApp(PolycodeView *view) {

#ifdef __APPLE__
	core = new CocoaCore(view, 640,480,false,false,0,0,90);	  
#else
	core = new SDLCore(view, 640,480,false,false,0,0,90);	  
#endif

	PhysicsScreen *screen = new PhysicsScreen(10, 50);

	ScreenShape *ceiling = new ScreenShape(ScreenShape::SHAPE_RECT, 640, 20);
	ceiling->setColor(0.0, 0.0, 0.0, 1.0);
	ceiling->setPosition(640/2, 10);
	screen->addPhysicsChild(ceiling, PhysicsScreenEntity::ENTITY_RECT, true);
	
	// Revolute Joint	
	ScreenShape *shape = new ScreenShape(ScreenShape::SHAPE_RECT, 10, 30);
	shape->setPosition(150, 20+15);
	screen->addPhysicsChild(shape, PhysicsScreenEntity::ENTITY_RECT, false);
	screen->createRevoluteJoint(shape, ceiling, 0, -15);
	screen->applyImpulse(shape, 10, 0);
	
	// Distance Joint	
	shape = new ScreenShape(ScreenShape::SHAPE_RECT, 10, 30);
	shape->setPosition(250, 20+25);
	screen->addPhysicsChild(shape, PhysicsScreenEntity::ENTITY_RECT, false);
	screen->createDistanceJoint(shape, ceiling, false);
	screen->applyImpulse(shape, 200, 0);
	
	ScreenLine *line = new ScreenLine(shape, ceiling);
	line->setColor(1.0, 0.0, 0.0, 1.0);
	screen->addChild(line);

	// Prismatic Joint	
	shape = new ScreenShape(ScreenShape::SHAPE_RECT, 10, 30);
	shape->setPosition(450, 20+25);
	screen->addPhysicsChild(shape, PhysicsScreenEntity::ENTITY_RECT, false);
	screen->createPrismaticJoint(ceiling, shape, Vector2(0,1), 0,0, false, 100, 0, true);

	ScreenEntity *lineAnchor = new ScreenEntity();
	lineAnchor->setPosition(450,10);
	line = new ScreenLine(shape, lineAnchor);
	line->setColor(0.0, 1.0, 0.0, 1.0);
	screen->addChild(line);
}
HelloPolycodeApp::HelloPolycodeApp(PolycodeView *view) {

	core = new POLYCODE_CORE(view, 640,480,false,false,0,0,90);

	PhysicsScreen *screen = new PhysicsScreen(10, 60);	
	
	ScreenShape *shape = new ScreenShape(ScreenShape::SHAPE_RECT, 600,30);
	shape->setColor(0.0,0.0,0.0,1.0);
	shape->setPosition(640/2, 400);
	screen->addPhysicsChild(shape, PhysicsScreenEntity::ENTITY_RECT, true);	
	
	for(int i=0; i < 200; i++) {
		shape = new ScreenShape(ScreenShape::SHAPE_RECT, 20,5);
		shape->setRotation(rand() % 360);
		shape->setPosition(rand() % 640, rand() % 300);
		screen->addPhysicsChild(shape, PhysicsScreenEntity::ENTITY_RECT, false);		
	}

}
HelloPolycodeApp::HelloPolycodeApp(PolycodeView *view) : EventHandler() {

	core = new POLYCODE_CORE(view, 640,480,false,false,0,0,90);
	
	CoreServices::getInstance()->getResourceManager()->addArchive("Resources/default.pak");
	CoreServices::getInstance()->getResourceManager()->addDirResource("default", false);	

	screen = new PhysicsScreen(10, 60);		
	ScreenShape *shape = new ScreenShape(ScreenShape::SHAPE_RECT, 600,30);
	shape->setColor(0.0,0.0,0.0,1.0);
	shape->setPosition(640/2, 400);
	screen->addPhysicsChild(shape, PhysicsScreenEntity::ENTITY_RECT, true);	
	
	for(int i=0; i < 50; i++) {
		shape = new ScreenShape(ScreenShape::SHAPE_RECT, 20,5);
		shape->setRotation(rand() % 360);
		shape->setPosition(rand() % 640, rand() % 300);
		screen->addPhysicsChild(shape, PhysicsScreenEntity::ENTITY_RECT, false);		
	}
	collisionSound = new Sound("Resources/hit.wav");
	screen->addEventListener(this, PhysicsScreenEvent::EVENT_NEW_SHAPE_COLLISION);
}