Exemplo n.º 1
0
bool UpgradeState::update(sf::Time) {
	updateWeapon1();
	updateWeapon2();
	updateHull();
	updateShip();
	return true;
}
Exemplo n.º 2
0
void KoulesSimulator::step(const ob::State *start, const oc::Control* control,
    const double t, ob::State *result)
{
    unsigned int ii;

    memcpy(&qcur_[0], start->as<KoulesStateSpace::StateType>()->values, numDimensions_ * sizeof(double));
    time_ = 0.;
    endTime_ = t;
    std::fill(dead_.begin(), dead_.end(), false);
    updateShip(control, t);
    for (unsigned int i = 0; i <= numKoules_; ++i)
    {
        ii = ind(i);
        dead_[i] = qcur_[ii] == -2. * kouleRadius;
        if (!dead_[i])
        {
            if (i)
                rungeKutta4(&qcur_[ii], t, &qnext_[ii]);
            qcur_[ii + 2] = (qnext_[ii    ] - qcur_[ii    ]) / t;
            qcur_[ii + 3] = (qnext_[ii + 1] - qcur_[ii + 1]) / t;
        }
    }
    initCollisionEvents();
    while (!collisionEvents_.empty())
    {
        CollisionEvent event = collisionEvents_.top();
        double ct = std::get<0>(event);
        unsigned int i = std::get<1>(event), j = std::get<2>(event);

        collisionEvents_.pop();
        advance(ct);
        if (j <= numKoules_)
            elasticCollision(i, j);
        else
        {
            markAsDead(i);
            if (i == 0)
            {
                memcpy(result->as<KoulesStateSpace::StateType>()->values, &qcur_[0], numDimensions_ * sizeof(double));
                return;
            }
        }

        for (unsigned int k = 0; k <= numKoules_ + 2; ++k)
        {
            if (k < i)
                computeCollisionEvent(k, i);
            else if (k > i && k != j)
                computeCollisionEvent(i, k);
            if (k < j && k != i)
                computeCollisionEvent(k, j);
            else if (k > j)
                computeCollisionEvent(j, k);
        }
    }
    advance(t);
    memcpy(result->as<KoulesStateSpace::StateType>()->values, &qcur_[0], numDimensions_ * sizeof(double));
}
Exemplo n.º 3
0
void NounShip::simulate( dword nTick )
{
	PROFILE_FUNCTION();

	// update the ship
	if ( !isSleeping() && m_bShipEnabled )
	{
		updateShip( nTick );			// update ship systems
		updateDynamics( nTick );		// update movement, roll, etc..
		updateCombat( nTick );			// update out of combat timer
	}

	NounBody::simulate( nTick );
}
Exemplo n.º 4
0
void renderScene() {
  PREV_TIME = CURRENT_TIME;
  CURRENT_TIME = glutGet(GLUT_ELAPSED_TIME);
  dt = (CURRENT_TIME - PREV_TIME) / 1000.0;

  glDisable(GL_DEPTH_TEST);
  glClear(GL_COLOR_BUFFER_BIT);
  glClearColor(0.1, 0.1, 0.1, 1.0);

  updateShip();
  updateRoid();

  glutSwapBuffers();
  glutPostRedisplay();
}
Exemplo n.º 5
0
BOOL cmd_refuel(IMP)
{
    register Ship_t *rsh;
    ULONG shNum;

    /* get the number of the ship */
    if (reqShip(IS, &shNum, "Ship to refuel"))
    {
        rsh = &IS->is_request.rq_u.ru_ship;
        server(IS, rt_readShip, shNum);
        if (rsh->sh_owner != IS->is_player.p_number)
        {
            user(IS, "You don't own that ship\n");
        }
        else if (rsh->sh_type == st_m)
        {
            user(IS, "Use the 'miner' command to load fuel onto a miner\n");
            /* return FALSE here, since this could be a common mistake */
            return FALSE;
        }
        else
        {
            server(IS, rt_lockShip, shNum);
            updateShip(IS);
            if (rsh->sh_items[it_fuelTanks] == 0)
            {
                server(IS, rt_unlockShip, shNum);
                user(IS, "There are no fuel tanks on that ship\n");
            }
            else
            {
                rsh->sh_items[it_fuelTanks]--;
                rsh->sh_fuelLeft += IS->is_world.w_weight[it_fuelTanks];
                server(IS, rt_unlockShip, shNum);
                user(IS, "Fuel transfered to active fuel array\n");
            }
        }
        return TRUE;
    }
    return FALSE;
}
Exemplo n.º 6
0
int main()
{
	REG_DISPCTL = MODE3 | BG2_ENABLE;
	reset();
	while(1) {
		waitForVblank();
		switch (state) {
			case START:
				drawImage3(0, 0, 240, 160, StartScreen); //The start screen
				state = READY;
				break;
			case READY:
				if (KEY_DOWN_NOW(BUTTON_B)) {
					drawBg();
					state = PLAY;
				}
				break;
			case PLAY:
				if(KEY_DOWN_NOW(BUTTON_A)) {
					reset();
				}
				eraseImage3(150, 0, 240, 10);
				sprintf(buffer, "%d bugs left", bugsNum);
				drawString(150, 0, buffer, red);
				sprintf(buffer, "%d lives left", lives);
				drawString(150, 100, buffer, red);
				sprintf(buffer, "level %d", level);
				drawString(150, 190, buffer, red);
				updateShip(&ship);
				updateBugs(bugs, &ship, &state);
				if (bugsNum == 0 && lives > 0) {
					state = WON;
				}
				break;
			case WON:
				if (level == 1) {
					drawString(100, 10, "Almost there! Press enter to continue!", red);
					if(KEY_DOWN_NOW(BUTTON_A)) {
						reset();
					}
					if (KEY_DOWN_NOW(BUTTON_START)) {
						level++;
						drawBg();
						setShip(&ship);
						setBugs(bugs);
						state = PLAY;
					}
				} else {
					drawImage3(0, 0, 240, 160, Win); 
					if (KEY_DOWN_NOW(BUTTON_START) || KEY_DOWN_NOW(BUTTON_A)) {
						reset();
					}
				}
				break;
			case DIE:
				drawBg();
				sprintf(buffer, "%d lives left", lives);
				drawString(50, 75, buffer, red);
				if(KEY_DOWN_NOW(BUTTON_A)) {
					reset();
				}
				if (KEY_DOWN_NOW(BUTTON_START)) {
					drawBg();
					state = PLAY;
					ship.x = START_X;
					ship.y = START_Y;
					for (int i = 0; i < bugsNum; i++) {
						bugs[i].y = bugs[i].startY;
						bugs[i].charge = 0;
					}
				}
				break;
			case LOSE:
				drawImage3(0, 0, 240, 160, Ending);
				if(KEY_DOWN_NOW(BUTTON_A)) {
					reset();
				}
				if (KEY_DOWN_NOW(BUTTON_START)) {
					reset();
				}
				break;
		}
	}
	return 0;
}
Exemplo n.º 7
0
void MainWindow::gameUpdate()
{
    //update jugador
    updateShip(this->player);

    //update bullets
    for(int i = 0; i < playerBullets->size(); i++)
    {
        bool remove = UpdatePlayerBeam(playerBullets->at(i));

        if(remove)
        {
            delete playerBullets->at(i)->myLabel;
            playerBullets->removeAt(i);
            i--;

        }
    }
    for(int i= 0; i < enemies->size(); i++)
    {
        enemyUpdate(enemies->at(i));
    }

    QRect Rectplayer = player->myLabel->geometry();
    //Checkeo Colisiones
    for(int i = 0; i < playerBullets->size(); i++)
    {
        PlayerBeam* bullet = playerBullets->at(i);
        QRect Rectbullet = bullet->myLabel->geometry();

        if(Rectbullet.intersects(Rectplayer))
        {
            player->lives--;
            delete bullet->myLabel;
            playerBullets->removeAt(i);
            i--;
        }

        for(int j = 0; j < enemies->size(); j++)
        {
             enemy_T* actEnemy = enemies->at(j);
             QRect RectActEnemy = actEnemy->image->geometry();
             if(Rectbullet.intersects(RectActEnemy))
             {
                 hit(actEnemy);
                 delete bullet->myLabel;
                 playerBullets->removeAt(i);
                 i--;
                 break;
             }
        }

    }
    //Colisiones con el jugador


    for(int i = 0; i < enemies->size(); i++)
    {

        QRect RectActEnemy = enemies->at(i)->image->geometry();
        if(Rectplayer.intersects(RectActEnemy))
        {
            playerHitted = true;
            player->lives--;
            qDebug() << player->lives;
            hit(enemies->at(i));
        }
    }



    //check gmae over
    if(player->lives <= 0)
    {
         emit gameEnd();
    }

    //Checkeo Muerte de Enemigos
    for(int i = 0; i < enemies->size(); i++)
    {
        if(enemies->at(i)->dead)
        {
            delete enemies->at(i)->image;
            player->score += checkEnemyValue(enemies->at(i)->type);
            enemies->removeAt(i);
            i--;
            this->enemyKilled = true;
        }
    }

    if(enemies->size() == 0)
    {
        this->level++;
        generateNextLevel();
    }

    refreshScore();
    refreshLives();

}
Exemplo n.º 8
0
void minerRefuel(IMP)
{
    register Ship_t *rsh, *rp;
    ULONG shipNumber, mineNum;
    Ship_t saveShip;
    ULONG shEnergy, newEnergy;
    BOOL reduced;

    /* get the number of the miner */
    if (reqShip(IS, &mineNum, "Miner to refuel"))
    {
        rsh = &IS->is_request.rq_u.ru_ship;
        rp = &IS->is_request.rq_u.ru_shipPair[0];
        (void) skipBlanks(IS);
        reduced = FALSE;
        server(IS, rt_readShip, mineNum);
        if (rsh->sh_owner != IS->is_player.p_number)
        {
            err(IS, "you don't own that miner");
            return;
        }
        /* make sure the ship is a miner */
        if (rsh->sh_type != st_m)
        {
            err(IS, "that ship is not a miner");
            return;
        }
        /* make sure the ship is not on a planet */
        if (rsh->sh_planet != NO_ITEM)
        {
            err(IS, "miner is on the surface of a planet");
            return;
        }
        if (rsh->sh_dragger == NO_ITEM)
        {
            err(IS, "miner is not on a ship - alert system owner!");
            return;
        }
        shipNumber = rsh->sh_dragger;
        saveShip = *rsh;
        server(IS, rt_lockShip, shipNumber);
        updateShip(IS);
        server(IS, rt_unlockShip, shipNumber);
        if (rsh->sh_energy == 0)
        {
            err(IS, "the ship the miner is on has no energy");
            return;
        }
        shEnergy = umin(rsh->sh_energy, (USHORT) MAX_WORK - saveShip.sh_energy);
        if (shEnergy == 0)
        {
            err(IS, "the miner can not contain any more energy");
            return;
        }
        if (reqPosRange(IS, &newEnergy, shEnergy, "Transfer how many units"
            " of energy to the miner"))
        {
            server2(IS, rt_lockShipPair, mineNum, shipNumber);
            shEnergy = rp[1].sh_energy;
            if (shEnergy < newEnergy)
            {
                newEnergy = shEnergy;
                reduced = TRUE;
            }
            rp[0].sh_energy += newEnergy;
            rp[1].sh_energy -= newEnergy;
            server2(IS, rt_unlockShipPair, mineNum, shipNumber);
            if (reduced)
            {
                userN3(IS, "Actions have reduced the energy transfered to ",
                    newEnergy, " units\n");
            }
            else
            {
                userN3(IS, "Transfered ", newEnergy, " units\n");
            }
        }
        /* put out the dirty ship numbers */
        feShDirty(IS, mineNum);
        feShDirty(IS, shipNumber);
    }
}
Exemplo n.º 9
0
void minerEmpty(IMP)
{
    register Ship_t *rsh, *rp;
    ULONG shipNumber, mineNum;
    USHORT ore, bars;

    /* get the number of the miner */
    if (reqShip(IS, &mineNum, "Miner to empty"))
    {
        rsh = &IS->is_request.rq_u.ru_ship;
        rp = &IS->is_request.rq_u.ru_shipPair[0];
        (void) skipBlanks(IS);
        server(IS, rt_readShip, mineNum);
        if (rsh->sh_owner != IS->is_player.p_number)
        {
            err(IS, "you don't own that miner");
        }
        else if (rsh->sh_type != st_m)
        {
            err(IS, "that ship is not a miner");
        }
        /* make sure the ship is on a planet */
        else if (rsh->sh_planet != NO_ITEM)
        {
            err(IS, "miner is on the surface of a planet");
            return;
        }
        else
        {
            /* make sure the miner is in a ship */
            if (rsh->sh_dragger == NO_ITEM)
            {
                err(IS, "miner is not inside a ship - tell system owner!");
                return;
            }

            /* get the number of the ship the miner is on */
            shipNumber = rsh->sh_dragger;
            /* update the carrying ship */
            server(IS, rt_lockShip, shipNumber);
            updateShip(IS);
            server(IS, rt_unlockShip, shipNumber);

            /* now do the actual transfer */
            server2(IS, rt_lockShipPair, mineNum, shipNumber);
            /* get the maximum amount of ore that may be transfered */
            ore = umin(rp[0].sh_items[it_ore], (USHORT) MAX_WORK -
                rp[1].sh_items[it_ore]);
            /* remove that amount from the miner */
            rp[0].sh_items[it_ore] -= ore;
            /* get the maximum amount of bars that may be transfered */
            bars = umin(rp[0].sh_items[it_bars], (USHORT) MAX_WORK -
                rp[1].sh_items[it_bars]);
            /* remove that amount from the miner */
            rp[0].sh_items[it_bars] -= bars;
            /* now handle the weight */
            rp[0].sh_cargo -= (ore * IS->is_world.w_weight[it_ore]);
            rp[0].sh_cargo -= (bars * IS->is_world.w_weight[it_bars]);

            /* now put the items onto the carrying ship */
            rp[1].sh_items[it_ore] += ore;
            rp[1].sh_items[it_bars] += bars;
            server2(IS, rt_unlockShipPair, mineNum, shipNumber);

            /* see if we transfered anything */
            if ((ore == 0) && (bars == 0))
            {
                user(IS, "Unable to transfer anything from that miner\n");
            }
            else
            {
                userN3(IS, "Transfered ", ore, " units of ore ");
                userN3(IS, "and ", bars, " gold bars ");
                userN3(IS, "to ship ", shipNumber, "\n");
            }
            /* put out the dirty ship numbers */
            feShDirty(IS, mineNum);
            feShDirty(IS, shipNumber);
        }
    }
}
Exemplo n.º 10
0
UpgradeState::UpgradeState(StateStack& stack, Context context) :State(stack, context), mGUIContainer() {
	sf::Vector2f windowSize(context.window->getSize());

	w1 = getContext().player->getWeapon1();
	w2 = getContext().player->getWeapon2();
	h = getContext().player->getHull();
	sh = getContext().player->getShip();


	sf::Texture& texture = context.textures->get(Textures::TitleScreen);
	mBackgroundSprite.setTexture(texture);

	sf::Texture& ShipTexture = context.textures->get(Textures::Player);
	Ship.setTexture(ShipTexture);
	sf::IntRect shipRect(0, 0, 53, 52);
	Ship.setTextureRect(shipRect);
	Ship.setPosition(0.5f * windowSize.x, 0.3f * windowSize.y);
	Ship.setScale(Ship.getScale().x + 5.f, Ship.getScale().y + 5.f);

	sf::Texture& Modifications = context.textures->get(Textures::Modification);
	Weapon1.setTexture(Modifications);
	sf::IntRect weapon1Rect(0, 0, 72, 64);
	Weapon1.setTextureRect(weapon1Rect);
	Weapon1.setPosition(0.3f * windowSize.x, 0.19f * windowSize.y);

	Weapon2.setTexture(Modifications);
	sf::IntRect weapon2Rect(0, 63, 72, 63);
	Weapon2.setTextureRect(weapon2Rect);
	Weapon2.setPosition(0.3f * windowSize.x, 0.39f * windowSize.y);

	Hull.setTexture(Modifications);
	sf::IntRect hullRect(0, 129, 72, 66);
	Hull.setTextureRect(hullRect);
	Hull.setPosition(0.3f * windowSize.x, 0.59f * windowSize.y);

	Weapon1Text = std::make_shared<GUI::Label>("", *context.fonts);
	Weapon1Text->setPosition(0.05f * windowSize.x, 0.3f * windowSize.y);
	Weapon1Text->setText("Normal Laser, with pickups increasing spread.");


	Weapon2Text = std::make_shared<GUI::Label>("", *context.fonts);
	Weapon2Text->setPosition(0.05f * windowSize.x, 0.5f * windowSize.y);
	Weapon2Text->setText("Seeker Missile.");


	HullText = std::make_shared<GUI::Label>("", *context.fonts);
	HullText->setPosition(0.05f * windowSize.x, 0.7f * windowSize.y);
	HullText->setText("Normal Hull.");


	auto WeaponButton = std::make_shared<GUI::Button>(context);
	WeaponButton->setPosition(0.1f * windowSize.x, 0.2f * windowSize.y);
	WeaponButton->setText("Weapon 1");
	WeaponButton->setCallback([this]() {
		w1++;
		updateWeapon1();
	});


	auto WeaponButton2 = std::make_shared<GUI::Button>(context);
	WeaponButton2->setPosition(0.1f * windowSize.x, 0.4f * windowSize.y);
	WeaponButton2->setText("Weapon 2");
	WeaponButton2->setCallback([this]() {
		w2++;
		updateWeapon2();
	});


	auto HullButton = std::make_shared<GUI::Button>(context);
	HullButton->setPosition(0.1f * windowSize.x, 0.6f * windowSize.y);
	HullButton->setText("Hull");
	HullButton->setCallback([this]() {
		h++;
		updateHull();
	});

	auto leftButton = std::make_shared<GUI::Button>(context);
	leftButton->setPosition(0.4f * windowSize.x, 0.8f * windowSize.y);
	leftButton->setText("<");
	leftButton->setCallback([this]() {
		sh--;
		updateShip();
	});


	auto RightButton = std::make_shared<GUI::Button>(context);
	RightButton->setPosition(0.7f * windowSize.x, 0.8f * windowSize.y);
	RightButton->setText(">");
	RightButton->setCallback([this]() {
		sh++;
		updateShip();
	});


	auto BackButton = std::make_shared<GUI::Button>(context);
	BackButton->setPosition(0.1f * windowSize.x, 0.8f * windowSize.y);
	BackButton->setText("Back");
	BackButton->setCallback([this]() {
		requestStackPop();
	});

	mGUIContainer.pack(WeaponButton);
	mGUIContainer.pack(WeaponButton2);
	mGUIContainer.pack(HullButton);
	mGUIContainer.pack(BackButton);
	mGUIContainer.pack(leftButton);
	mGUIContainer.pack(RightButton);
	mGUIContainer.pack(Weapon1Text);
	mGUIContainer.pack(Weapon2Text);
	mGUIContainer.pack(HullText);
}