Пример #1
0
void Pickup::Update(float dt, XNA::AxisAlignedBox *player, World* w)
{
	Platform* p = w->getPlatform(this->getCPID());

	if(p != NULL)
	{
		XMFLOAT3 pos = p->getPos();
		pos.x += this->mPos.x;
		pos.y += this->mPos.y;
		pos.z += this->mPos.z;

		mEntity->SetPosition(pos);
		this->mSphere.Center = pos;
	}

	if(XNA::IntersectSphereAxisAlignedBox(&mSphere, player))
	{
		struct Data
		{
			int id; //dummy
		};
		Data* data = new Data;
		data->id = this->mID;

		Network::GetInstance()->Push(new Package(Package::Header(9, this->mID, sizeof(Data)), Package::Body((char*)(data))));
	}
}
Пример #2
0
void Editor::Update() {
    if ( myKeys[sf::Keyboard::Back].pressed ) {
        myStage->getArea(0)->Clear();
        myNextScreen = ScreenMenu;
    }
    sf::Vector2i mouseCell((int)myMouse.x/32,(int)myMouse.y/32);

    myGUI->Update( myMouse );


    /*
    *   Mouse is on GUI
    */
    if ( myGUI->onGUI() ) {

        /*
        *   TOOLBAR
        */
        if ( myGUI->getGUI( ) == myToolBar ) {
            if ( myMouseLeft && myGUI->onWidget() && myGUI->getWidget()->getType() == widget_button ) {
                Button * btn = static_cast<Button*>(myGUI->getWidget());

                if ( myBrush == btn->getValue() ) myBrush = brush_null;

                else switch(btn->getValue() ) {
                    case brush_platform:
                    case brush_enemy:
                    case brush_spawn: {
                        myBrush = btn->getValue();
                        break;
                    }

                    case action_save: {
                        myStage->Save();
                        myAlert->setText("Map saved...");
                        myAlert->Display();
                        break;
                    }

                    case action_load: {
                        myStage->Load();
                        myAlert->setText("Map loaded...");
                        myAlert->Display();
                        break;
                    }
                    }
            }
        }


    }
    /*
    *   Otherwise
    */
    else {
        if ( myBrush != brush_null ) myPlatformHelper.SetPosition( mouseCell.x*32, mouseCell.y*32);
        // =========================================================================================
        //  Brush: Platform
        // =========================================================================================
        if ( myBrush == brush_platform ) {
            if ( !myPlatform) {
                if ( myMouseLeft ) {
                    int erase = 0;
                    Area * a = myStage->getArea(0);

                    for( vector<Platform*>::iterator it = a->myPlatforms.begin(); it != a->myPlatforms.end(); ++it) {
                        Platform * p = *it;
                        if ( p->getPos().x > myMouse.x || p->getPos().x + p->getSize().x < myMouse.x ||
                                p->getPos().y > myMouse.y || p->getPos().y + p->getSize().y < myMouse.y ) continue;
                        delete p;
                        a->myPlatforms.erase(it);
                        erase = 1;
                        break;
                    }

                    if ( !erase ) {

                        Platform * p = new Platform();
                        myPlatform = p;
                        p->setPos( sf::Vector2f(mouseCell.x*32, mouseCell.y*32) );
                        myCell = mouseCell;
                        a->myPlatforms.push_back(p);
                    }
                }
            }
            else {
                if ( myMouseLeftDown ) {
                    int x_dif = mouseCell.x - myCell.x;
                    int y_dif = mouseCell.y - myCell.y;
                    if ( x_dif < 0 ) {
                        myPlatform->setX( myCell.x*32+x_dif*32 );
                        x_dif = -x_dif;
                    }
                    else myPlatform->setX( myCell.x*32);

                    if ( y_dif < 0 ) {
                        myPlatform->setY( myCell.y*32+y_dif*32 );
                        y_dif = -y_dif;
                    }
                    else myPlatform->setY( myCell.y*32);
                    ++x_dif;
                    ++y_dif;
                    myPlatform->setSize( sf::Vector2f(x_dif*32,y_dif*32));
                }
                else {
                    myPlatform->materialize();
                    myPlatform = 0;
                }
            }
        }
        // =========================================================================================
        //  Brush: Enemy
        // =========================================================================================
        if ( myBrush == brush_enemy ) {
            if ( myMouseLeft ) {
                int erase = 0;
                Area * area = myStage->getArea(0);

                for( vector<Enemy*>::iterator it = area->myEnemies.begin(); it != area->myEnemies.end(); ++it) {
                    sf::FloatRect bb = (*it)->getBB();
                    if ( myMouse.x < bb.Left || myMouse.x > bb.Width
                            || myMouse.y < bb.Top || myMouse.y > bb.Height ) continue;

                    delete (*it);
                    area->myEnemies.erase(it);
                    erase = 1;
                    break;
                }

                if ( !erase ) {
                    Enemy * e1 = new Enemy(*myEnemy);
                    e1->setPos( sf::Vector2f(mouseCell.x*32 + e1->getSize().x/2, mouseCell.y*32+32) );
                    area->myEnemies.push_back(e1);
                }
            }
        }


    }
}