Exemplo n.º 1
0
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    
    auto listener = EventListenerTouchOneByOne::create();
    listener->onTouchBegan = CC_CALLBACK_2(HelloWorld::onTouchBegan, this);
    listener->onTouchMoved = CC_CALLBACK_2(HelloWorld::onTouchMoved, this);
    listener->onTouchEnded = CC_CALLBACK_2(HelloWorld::onTouchEnded, this);
    listener->onTouchCancelled = CC_CALLBACK_2(HelloWorld::onTouchEnded, this);
    getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener, this);
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    auto background = Sprite::create("bg.png");
    background->setPosition(Vec2(visibleSize.width/2,visibleSize.height/2));
    this->addChild(background);
    
    loadTowerPositions();
    addWaypoints();
    
    loadWaves();
    return true;
}
Exemplo n.º 2
0
QList<PathItem *> PathView::loadData(const Data &data)
{
	QList<PathItem *> paths;
	int zoom = _zoom;


	for (int i = 0; i < data.tracks().count(); i++)
		paths.append(addTrack(*(data.tracks().at(i))));
	for (int i = 0; i < data.routes().count(); i++)
		paths.append(addRoute(*(data.routes().at(i))));
	addWaypoints(data.waypoints());

	if (_tracks.empty() && _routes.empty() && _waypoints.empty())
		return paths;

	if ((_tracks.size() + _routes.size() > 1 && _zoom < zoom)
	  || (_waypoints.size() && _zoom < zoom))
		rescale(_zoom);
	else
		updatePOIVisibility();

	QRectF sr = contentsSceneRect();
	_scene->setSceneRect(sr);
	centerOn(sr.center());

	_mapScale->setZoom(_zoom, -(sr.center().ry() * mapScale(_zoom)));
	if (_mapScale->scene() != _scene)
		_scene->addItem(_mapScale);

	return paths;
}
Exemplo n.º 3
0
/**  The constructor sets the view to the size of the window
*  and centers the view on the center of the window.
*/
GameStatePlay::GameStatePlay(Game* game) {
	this->game = game;

	initializeButtonMap();
	firstStart = true;
	returnToMenu = false;
	endOfWaves = false;
	fieldTowerSelector = nullptr;

	this->current_waypoints = addWaypoints(getWaypointsFromMapPath());
	this->show_waypoints = false;

	//Set up critter wave levels
	this->setCritterWaveLevels(getStartingWaypoint());

	//Set current wave to the first level
	this->current_wave = wave_levels[0];

	//Set last activated critter to the first critter in the wave and activate it
	this->delay_count = 0;
	this->last_activated_critter = current_wave->findCritter(0);

	this->mew = new WhiteCat(11, getStartingWaypoint());
	this->blacky = new BlackCat(12, getStartingWaypoint());


	sf::Vector2f position = sf::Vector2f(this->game->game_window.getSize());
	//JEREMY LOOK HERE FOR VIEWS
	// Link to more info: http://sfml-dev.org/tutorials/2.0/graphics-view.php
	// You can do split screen and just keep the view camera unmoving
	this->_gameView.setSize(position);
	this->_guiView.setSize(position);

	sf::Vector2f center_position = 0.5f * position;
	this->_gameView.setCenter(center_position);
	this->_guiView.setCenter(center_position);
	font.loadFromFile("resources/helveticaneue-webfont.ttf");

	mapBackdrop.load("resources/images/MapBackdrop.png");
	mapBackdrop.setPosition(0*32,0*32);

	interfaceBackdrop.load("resources/images/InterfaceBackdrop.png");
	interfaceBackdrop.setPosition(0*32,12*32);

	// Activate mew!
	//mew->isActive = true;
}