Пример #1
0
void
Controller::update_bullets()
{
  Bullet *bullet(0);
  Bot *bot(0);
  sf::Vector2f hitPoint;
  for (unsigned int i(0); i < m_model.get_bullets().size(); i++)
  {    
    // Get a direct pointer for convenience.
    bullet = (Bullet*) m_model.get_bullets()[i];
    
    if (m_model.collides(bullet, hitPoint)) // Collision with circles and world' boundaries.
    {
      m_view.add_explosion(hitPoint);
      m_model.erase_bullet(i);
    }
    else if (m_model.collides(bullet, &bot, hitPoint)) // Collision with bots.
    {
      m_view.add_explosion(hitPoint);
      m_model.inflict_damages(bot);
      if (!bot->is_alive())
      {
	bullet->get_bot_origin()->add_kill();
        m_view.add_bot_explosion(bot->get_position());
      }
      m_model.erase_bullet(i);
    }
    else
      bullet->move(); // Update position.
  }
}
PlayerColliderComponent::PlayerColliderComponent(const Core::Identifier &i, Game::IEntity &e)
    : ColliderComponent(i, e)
    , m_platform(false)
{
	/* high velocity jumps may cause indentation */
	bullet() = true;
}
Пример #3
0
void keyhit(int i)
{
	int j,k;
	setbkcolor(0);
	target(i);
	char ch;
	for(j=0;j<10000;j++)
	{
		while(!kbhit())
		{target(i);}
		ch=getch();
		if(ch=='q'||ch==27)
		 {
		closegraph();exit(0);}
		while(ch=='a'||ch==75)
		{target(i-=10);k=kbhit();while(k==0){target(i);k=kbhit();}ch=getch();sound(900);delay(2);nosound();}
		while(ch=='d'||ch==77)
		{target(i+=10);k=kbhit();while(k==0){target(i);k=kbhit();}ch=getch();sound(900);delay(2);nosound();}
		while(ch=='w'||ch==72)
		{if(shots<25)
		{bullet(i);
		 k=kbhit();
		 target(i);
		 while(k==0)
		 {target(i);k=kbhit();}shots++;ch=getch();}
		 else
		 score(i,::l,::shots);}
	}
}
Пример #4
0
void GUI::SlideBar::draw(sf::RenderTarget &target, sf::RenderStates states) const {

    states.transform *= getTransform();

    RoundedRectangleShape rect(sf::Vector2f(mLength,mHeight),mHeight/2, 30);
    rect.setFillColor(sf::Color(230,230,230));
    target.draw(rect, states);
    sf::CircleShape bullet(mHeight/4);
    bullet.setFillColor(sf::Color(210,210,210));
    bullet.setOrigin(bullet.getRadius(),bullet.getRadius());
    if (mShowMarks) {
        for (int i=mCurrentStep+1; i<mSteps-1; i++){
            bullet.setPosition(mHeight/2+i*(mLength-mHeight)/((float)mSteps-1), mHeight/2);
            target.draw(bullet,states);
        }
    }
    rect.setFillColor(sf::Color(31,188,153));
    rect.setSize(sf::Vector2f(mHeight/2+(mLength-mHeight)*mCurrentStep/((float)mSteps-1),mHeight));
    target.draw(rect,states);
    bullet.setFillColor(sf::Color(26,160,131));
    bullet.setRadius(mHeight*0.75);
    bullet.setOrigin(bullet.getRadius(),bullet.getRadius());
    bullet.setPosition(mHeight/2+(mLength-mHeight)*mCurrentStep/((float)mSteps-1),mHeight/2);
    target.draw(bullet,states);
}
Пример #5
0
bullet starship::shoot(float xf, float yf, float zf) {
    // Add bullet every half-a-second
    if (glutGet(GLUT_ELAPSED_TIME) - previousShooting < 500)
        return bullet(0, 0, xf, yf, zf, true);
    
    previousShooting = glutGet(GLUT_ELAPSED_TIME);
    
    if (xf == -1 && yf == -1 && zf == -1) {
        xf = x;
        yf = y;
        zf = z - 10;
    }
    
    playShootingSong();
    return bullet(x, y, xf, yf, zf);
}
void render(cairo_t *cr) {
  float y_bearing = 3/4.0;
  float x_bearing = 1/8.0;
  float width     = 1/2.0;
  float pen_width = 1/64.0;

  float height = y_bearing;
  float x_advance = width + 2 * x_bearing;

  h_guide(cr, -1/2.0 + height - y_bearing);
  h_guide(cr, -1/2.0 + y_bearing);
  v_guide(cr, -width/2.0);
  v_guide(cr,  width/2.0);

  bullet(cr, -width/2.0 - x_bearing, -1/2.0);
  bullet(cr, -width/2.0 - x_bearing + x_advance, -1/2.0);

  cairo_move_to(cr, -width/2.0 - x_bearing, -1/2.0);
}
Пример #7
0
void Thing::fire(float vx, float vy, float xoff, float yoff)
{
	Bullet bullet(this);
	bullet.x = this->x + (xoff == -1 ? this->width()/2 : xoff);
	bullet.y = this->y + (yoff == -1 ? this->height()/2 : yoff);
	bullet.vx = vx;
	bullet.vy = vy;
	//bullet.image = (imageOverride ? imageOverride : this->bulletImage);
	
	ownedBullets.push_back(bullet);
}
Пример #8
0
void Game::Init() {
    SDL_Init(SDL_INIT_VIDEO);
    displayWindow = SDL_CreateWindow("LaupsyGame", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, SDL_WINDOW_OPENGL);
    SDL_GLContext context = SDL_GL_CreateContext(displayWindow);
    SDL_GL_MakeCurrent(displayWindow, context);
    glViewport(0, 0, 800, 600);
    glMatrixMode(GL_MODELVIEW);
    
    
    Bullet bullet(0.05f,10.0f,0.0f,0.0f);
    bullets.push_back(bullet);
}
Пример #9
0
void Player::shootBullet() {
    const Uint8 *keys = SDL_GetKeyboardState(NULL);
    if (keys[SDL_SCANCODE_SPACE]) {
        Bullet bullet(x/2);
        bullets.push_back(bullet);
    }
//    Bullet newBullet;
//    newBullet.x = -1.2;
//    newBullet.y = 0.0;
//    newBullet.angle = (float)(45 - (rand() % 90));
//    newBullet.speed = 2.0;
//    bullets.push_back(newBullet);
}
Пример #10
0
Airplane::Airplane(int windowHeight, int windowWidth)
{
	this->windowHeight = windowHeight;
	this->windowWidth = windowWidth;
	this->xSpeed = 5;
	this->width = 50;
	this->height = 100;
	this->xPosition = 0;
	this->yPosition = 100;
	this->fuelAmount = this->windowHeight*2;

	Bullet bullet(windowHeight,windowWidth);
	this->bullet = bullet;
}
Пример #11
0
void Weapon::fire(const sf::Vector2<float> & p_position, const float & p_speed, const float & p_angle, const sf::Sprite & p_sprite){
	SceneNode::Ptr bullet(new Bullet(p_position, p_speed, p_angle, p_sprite));

	for (int i = 0; i < m_powers.size(); i++)
	{
		for (int j = 0; j < m_powers[i].m_powerFunctions.size(); j++)
		{
			m_powers[i].m_powerFunctions[j]((Bullet*)bullet.get(), m_world, &m_delay);
		}
	}

	m_world.addNode(std::move(bullet));

	m_time = 0;
}
	void BobShooter::fireGun()
	{
		unique_ptr<Entity> bullet(new Entity);
		bullet->setTransform(getEntity()->getTransform() * getEntity()->getComponents<Model>()[1]->getTransform());
		rotate(bullet->getTransform(), MathConstants::PI * -0.5f, Vector4(1.0f, 0.0f, 0.0f, 1.0f));

		ModelFactory::Recipe recipe;
		recipe.shape = ModelFactory::Recipe::Shape::PYRAMID;
		recipe.color = Vector4(1.0f, 0.0f, 0.0f, 1.0f);
		recipe.dimensions = Vector3(0.2f, 0.5f, 0.0f);
		shared_ptr<Mesh> mesh = ModelFactory::cookMesh(recipe);

		const MeshData& meshData = mesh->getData();
		unique_ptr<Shape> bounds = ModelFunctions::getSquareBoundsXZ(meshData.vertexData, meshData.vertexCount);
		mesh->releaseData();

		Body::Material material;
		material.mass = 0.2f;
		material.friction = 0.5f;
		material.restitution = 0.1f;

		Box bodyBounds(0.1f, 0.25f, 0.1f);

		unique_ptr<Body> body = PhysicsFactory::createBody(material, *mesh, bodyBounds, bullet->getTransform());

		Vector3 trajectory = getUp3(bullet->getTransform());
		trajectory.normalize();
		trajectory *= 50.0f;
		body->applyForce(trajectory, Vector3(0.0f, 0.0f, 0.0f));

		unique_ptr<Model> model(new Model);
		model->setBounds(move(bounds));
		model->setMesh(move(mesh));

		bullet->addComponent(move(model));
		bullet->addComponent(move(body));

		Simplicity::getScene()->addEntity(move(bullet));

		firing = false;
	}
Пример #13
0
void ClientGame::processMessage(MessagePtr msg)
{
    switch(msg->getType())
    {
    case MessageType::SRV_ASTEROID_SPAWN:
    {
        print("ClientGame: spawning asteroid\n");
        AsteroidSpawnMessage *spawn_msg = static_cast<AsteroidSpawnMessage*>(msg.get());
        AsteroidPtr ast(new Asteroid(this, spawn_msg->getData(), asteroid_data));
        entities.push_back(ast);
        asteroids.push_back(ast);
    }
    break;
    case MessageType::SRV_SHIP_SPAWN:
    {
        ShipSpawnMessage *spawn_msg = static_cast<ShipSpawnMessage*>(msg.get());
        const ShipSpawnData &d = spawn_msg->getData();

        ShipPtr ship(new Ship(this, d));
        entities.push_back(ship);
        ships.push_back(ship);

        print(format("ClientGame: spawning ship id=%1% name=%2%\n") % ship->getID() % ship->getName());
    }
    break;
    case MessageType::SRV_BULLET_SPAWN:
    {
        BulletSpawnMessage *spawn_msg = static_cast<BulletSpawnMessage*>(msg.get());
        const BulletSpawnData &d = spawn_msg->getData();

        BulletPtr bullet(new Bullet(this, d));
        entities.push_back(bullet);
        if(Audio::distToListener(d.state.position) < 200.0f)
            Audio::playSFX("sounds/laser0.wav", false, d.state.position, 0.5f, 10.0f);
        print(format("ClientGame: spawning bullet id=%1%\n") % bullet->getID());
    }
    break;
    case MessageType::SRV_SHIP_STATE:
    {
        ShipStateMessage *state_msg = static_cast<ShipStateMessage*>(msg.get());
        int id = state_msg->getEntityID();

        //print(format("ClientGame: received ship state data for ship id=%1%\n") % id);

        //TODO use a map?
        for(unsigned int i = 0; i < ships.size(); i++)
            if(ships[i]->getID() == id)
            {
                ships[i]->setStateData(state_msg->getData());
                break;
            }
    }
    break;
    case MessageType::SRV_SHIP_OWNER:
    {
        ShipOwnerMessage *owner_msg = static_cast<ShipOwnerMessage*>(msg.get());
        print("owner message\n");

        for(unsigned int i = 0; i < ships.size(); i++)
            if(ships[i]->getID() == owner_msg->getData().ship_id)
            {
                print("owner message\n");
                player_ship = ships[i];
                ship_cam->setShip(player_ship);
                break;
            }
    }
    case MessageType::SRV_ASTEROID_STATE:
    {
        AsteroidStateMessage *state_msg = static_cast<AsteroidStateMessage*>(msg.get());
        int id = state_msg->getEntityID();

        //print(format("ClientGame: received asteroid state data for asteroid id=%1%\n") % id);

        for(unsigned int i = 0; i < asteroids.size(); i++)
            if(asteroids[i]->getID() == id)
            {
                asteroids[i]->setStateData(state_msg->getData());
                break;
            }
    }
    break;
    case MessageType::SRV_ENTITY_DELETE:
    {
        print("ClientGame: deleting entity\n");
        EntityDeleteMessage *delete_msg = static_cast<EntityDeleteMessage*>(msg.get());
        int id = delete_msg->getData().entity_id;

        for(unsigned int i = 0; i < entities.size(); i++)
            if(entities[i]->getID() == id)
            {
                entities[i]->die();
                entities.erase(entities.begin()+i);
                break;
            }

        if(player_ship && id == player_ship->getID())
            player_ship.reset();

        //TODO do this properly
        for(unsigned int i = 0; i < ships.size(); i++)
            if(ships[i]->getID() == id)
            {
                cml::vector2f pos = ships[i]->getPosition();
                cml::vector3f col1(ships[i]->getBodyColor().data());
                cml::vector3f col2 = cml::vector3f(0.0f, 0.0f, 0.0f);
                ExplosionEmitterPtr e(new ExplosionEmitter(pos, col1, col2, 40, 50.0f, 1.6f));
                particle_system->addEmitter(e);
                if(Audio::distToListener(pos) < 200.0f)
                    Audio::playSFX("sounds/explosion0.wav", false, pos, 0.1f, 10.0f);

                ships.erase(ships.begin()+i);
                break;
            }

        for(unsigned int i = 0; i < asteroids.size(); i++)
            if(asteroids[i]->getID() == id)
            {
                AsteroidPtr a = asteroids[i];
                if(a->getBounds().intersects(game_bounds))
                {
                    cml::vector2f pos = a->getPosition();
                    cml::vector3f col1 = cml::vector3f(1.0f, 0.0f, 0.0f);
                    cml::vector3f col2 = cml::vector3f(0.1f, 0.0f, 0.0f);
                    ExplosionEmitterPtr e(new ExplosionEmitter(pos, col1, col2, 50, 30.0f, 1.6f));
                    particle_system->addEmitter(e);

                    col1.set(0.2f, 0.2f, 0.0f);
                    col2.set(0.0f, 0.0f, 0.0f);
                    ExplosionEmitterQuadsPtr e2(new ExplosionEmitterQuads(pos, col1, col2, 30, 20.0f, 1.6f));
                    particle_system->addEmitter(e2);

                    if(Audio::distToListener(pos) < 300.0f)
                        Audio::playSFX(asteroid_explosions[rand()%asteroid_explosions.size()], false, pos, 0.01f, 1.0f);
                }
                asteroids.erase(asteroids.begin()+i);
                break;
            }

        /*
        for(unsigned int i = 0; i < bullets.size(); i++)
            if(bullets[i]->getID() == id)
            {
                bullets.erase(bullets.begin()+i);
                break;
            }
        */
    }
    break;
    case MessageType::SRV_SCORE:
    {
        ScoreMessage *score_msg = static_cast<ScoreMessage*>(msg.get());
        scores = score_msg->getData();
    }
    break;
    default:
        break;
    }
}
Пример #14
0
void Hero::fire(std::list<Bullet> &bullets){

    Bullet bullet(x+4,y-94.5,-10);
    bullets.push_back(bullet);

}
Пример #15
0
int main( int argc, char* args[] )
{
    bool quit = false;
    bool debug = false;
    int level = 1;
    Player control(200,700);
    Ball bullet(200 + PADDLE_WIDTH/2, 500);
    int tilesDestroyed = 0;

    float startTicks = 0;
    float deltaTicks = 0;
    char ballVelX[5];
    char ballVelY[5];
    char playerLife[5];


    Tile *tiles[TOTAL_TILES];
    int destroyedTile[TOTAL_TILES];


    for( int t = 0; t < TOTAL_TILES; t++ )
    {
       destroyedTile[t] = false;
    }

    if(init() == false)
    {
        return 5;
    }

    if(load_files() == false)
    {
        return 6;
    }

   clip_tiles();

   if( set_tiles( tiles , level ) == false )
   {
       return 1;
   }   

    startTicks = SDL_GetTicks();

    while(quit == false)
    {
        tilesDestroyed = 0;
        while(SDL_PollEvent(&event))
        {
           if((event.type == SDL_KEYDOWN))
            {

                if(event.key.keysym.sym == SDLK_1 && debug == true)//Adjusting velocity via the 1 number key in debuging mode
                {
                    bullet.xVelocity += 100;
                    bullet.yVelocity += 100;
                }
                else if(event.key.keysym.sym == SDLK_2 && debug == true)//Adjusting velocity via the 2 number key in debuging mode
                {
                    bullet.xVelocity -= 100;
                    bullet.yVelocity -= 100;
                }
                else if(event.key.keysym.sym == SDLK_F1)//Enabling or disabling debuging mode ( information of velocities)
                {
                    if(debug == false)
                    {
                        debug = true;
                    }
                    else
                    {
                        debug = false;
                    }

                }
            }

            control.handle_input();//Handle the paddle's movement

            if(event.type == SDL_QUIT)
            {
                quit = true;
            }
        }

        deltaTicks = SDL_GetTicks() - startTicks;//Frame rate
        control.move(deltaTicks);
        bullet.move(control.player,tiles,deltaTicks,destroyedTile);//Moving the ball

        SDL_FillRect( screen, &screen->clip_rect, SDL_MapRGB( screen->format, 0x00, 0x00, 0x00 ) );//Black color every frame


        for( int t = 0; t < TOTAL_TILES; t++ )
        {
           if(destroyedTile[t] == 0)
           {
               tiles[ t ]->show();

           }
        }

        control.show();
        bullet.show();

        sprintf(ballVelX,"xVel %d",bullet.xVelocity);//Formating text to be displayed for the HUD
        sprintf(ballVelY,"yVel %d",bullet.yVelocity);
        sprintf(playerLife,"Life : %d",bullet.life);

        showBallvelocityX = TTF_RenderText_Solid(font,ballVelX,textColor);
        showBallvelocityY = TTF_RenderText_Solid(font,ballVelY,textColor);

        life = TTF_RenderText_Solid(font,playerLife,textColor);

        apply_surface(20, 10, life, screen );

        if(debug == true)
        {
            apply_surface(20, 50, showBallvelocityX, screen );
            apply_surface(20, 70, showBallvelocityY, screen );
            SDL_FreeSurface(showBallvelocityY);
            SDL_FreeSurface(showBallvelocityX);
        }

        startTicks = SDL_GetTicks();
        deltaTicks = 0;


        for( int t = 0; t < TOTAL_TILES; t++ )//Checking how many tiles are destroyed in the game
        {
           if(destroyedTile[t] == 1)
           {
               tilesDestroyed++;
           }
        }


        if(bullet.life == 0 || tilesDestroyed == TOTAL_TILES)//Close the game if life drops to zero or all the tiles are destroyed in the game
        {
            quit = true;
        }

        if( SDL_Flip( screen ) == -1 )
        {
            return 1;
        }
    }


    clean_up();
    return 0;

}
Пример #16
0
void render_line(slide *sl, displayline *out, DrawMode *dm,
		SDL_Surface *surface)
{
	style *st = sl->st;
	int single_line;
	
	int textshift, x, shift;
	int xmargin = st->leftmargin;
	int xbase = st->leftmargin + st->foldmargin;
	TTF_Font *font;

	if(dm != NULL)
	{
		// Store initial draw mode to make future individual line redraws easy:
		out->initial_dm = *dm;
		single_line = 0;
	}
	else
	{
		// Just drawing this line (not whole slide), so use saved draw mode:
		dm = new DrawMode;
		*dm = out->initial_dm;
		single_line = 1;
	}
	
	shift = 0;
	if(out->bullet == -1)
	{
		shift = dm->lastshift;
	}
	else if(out->bullet > 0)
	{
		shift = 10 + 30 * out->bullet;
		bullet(out->bullet, xbase + shift - 20,
				out->y + (st->text_ascent - st->text_descent) / 2,
				surface, st);
	}
	if(out->centred)
	{
		int text_area = sl->des_w - st->leftmargin - st->foldmargin -
				st->rightmargin;
		shift = (sl->des_w - out->width) / 2 - st->leftmargin - st->foldmargin;

		/* Force long lines into the text area, even if that means
			they end up off-centre within the slide itself due to
			different left/fold and right margins: */
		if(shift + out->width > text_area) // Too far right
			shift = text_area - out->width;
		if(shift < 0) // Too far left
			shift = 0;
	}
	
	if(out->exposed > 0)
		exposeicon(out->exposed, xmargin, out->y, out->height, surface, st);
	if(out->type == TYPE_FOLDED)
	{
		textshift = 0;
		if(dm->ttmode)
			textshift += (st->text_ascent - st->fixed_ascent) / 2;
		else if(dm->italicmode)
			textshift += (st->text_ascent - st->italic_ascent) / 2;
		else if(dm->boldmode)
			textshift += (st->text_ascent - st->bold_ascent) / 2;
		foldicon(1, out->exposed, xmargin, out->y, out->height,
				out->y + (st->text_ascent - st->text_descent) / 2 + textshift,
				surface, st, out->highlighted);
	}
	else if(out->type == TYPE_EXPANDED)
	{
		textshift = 0;
		if(dm->ttmode)
			textshift += (st->text_ascent - st->fixed_ascent) / 2;
		else if(dm->italicmode)
			textshift += (st->text_ascent - st->italic_ascent) / 2;
		else if(dm->boldmode)
			textshift += (st->text_ascent - st->bold_ascent) / 2;
		foldicon(0, out->exposed, xmargin, out->y, out->height,
				out->y + (st->text_ascent - st->text_descent) / 2 + textshift,
				surface, st, out->highlighted);
	}
	
	x = xbase + shift;
	if(out->bullet == 0 && out->prespace > 0)
	{
		x += out->prespace * (dm->ttmode ? st->fixed_space_width :
				st->text_space_width);
	}

	if(out->import != NULL)
	{
		SDL_Rect dst;

		dst.x = x;
		dst.y = out->y + st->latexspaceabove;
		SDL_BlitSurface(out->import, NULL, surface, &dst);
	}
	else if(out->rule)
	{
		int width;
		SDL_Rect dst;
		
		width = sl->des_w * st->rulewidth / 100;
		
		dst.x = (sl->des_w - width) / 2;
		dst.y = out->y + st->rulespaceabove;
		dst.w = width;
		dst.h = st->ruleheight;
		SDL_FillRect(surface, &dst, colour->fills->item(st->rulecolour));
	}
	else if(out->line == NULL)
		error("Impossible out->line in render.cpp");
	else if(out->heading && strlen(out->line) > 0)
	{
		x = render_text(out->line, st->heading_font,
				st->headingcolour, surface,
				x, out->y + st->headspaceabove, 0);
	}
	else if(strlen(out->line) > 0)
	{
		svector *codes;
		char code;
		svector *v = split_string(out->line, &codes);
		const char *s;
		int link_text_colour_index;

		if(out->highlighted)
			link_text_colour_index = st->highlightcolour;
		else
			link_text_colour_index = st->linkcolour;

		for(int j = 0; j < v->count(); j++)
		{
			s = v->item(j);
			code = codes->item(j)[0];
			if(strlen(s) > 0)
			{
				textshift = 0;
				if(dm->italicmode)
				{
					font = st->italic_font;
					textshift += st->text_ascent - st->italic_ascent;
				}
				else if(dm->boldmode)
				{
					font = st->bold_font;
					textshift += st->text_ascent - st->bold_ascent;
				}
				else if(dm->ttmode)
				{
					font = st->fixed_font;
					textshift += st->text_ascent - st->fixed_ascent;
				}
				else
				{
					font = st->text_font;
				}
				x = render_text(s, font,
						out->link == NULL ? dm->current_text_colour_index :
						link_text_colour_index, surface, x,
						out->y + textshift,
						out->link == NULL || !st->underlinelinks ? 0 :
						st->textsize);
			}
			if(code == '$')
				dm->ttmode = 1 - dm->ttmode;
			else if(code == '%')
			{
				if(codes->item(j)[1] == '\0')
				{
					dm->current_text_colour_index = st->textcolour; // Default
				}
				else
				{
					int colour_index;
					
					if(codes->item(j)[1] == '#')
					{
						colour_index = colour->search_add(codes->item(j) + 2);
						if(colour_index == -1)
							error("Incorrect hex colour %s", codes->item(j) + 1);
					}
					else
					{
						colour_index = colour->names->find(codes->item(j) + 1);
						if(colour_index == -1)
							error("Unknown colour <%s>", codes->item(j) + 1);
					}
					dm->current_text_colour_index = colour_index;
				}
			}
			else if(code == '*')
			{
				if(dm->ttmode == 0)
					dm->boldmode = 1 - dm->boldmode;
				else
					x = render_text("*", st->fixed_font,
						out->link == NULL ? dm->current_text_colour_index :
						link_text_colour_index, surface, x,
						out->y + st->text_ascent - st->fixed_ascent,
						out->link == NULL || !st->underlinelinks ? 0 :
						st->textsize);
			}
			else if(code == '/')
			{
				if(dm->ttmode == 0)
					dm->italicmode = 1 - dm->italicmode;
				else
					x = render_text("/", st->fixed_font,
						out->link == NULL ? dm->current_text_colour_index :
						link_text_colour_index, surface, x,
						out->y + st->text_ascent - st->fixed_ascent,
						out->link == NULL || !st->underlinelinks ? 0 :
						st->textsize);
			}
		}
		delete v;
		delete codes;
	}

	if(debug & DEBUG_BASELINES)
	{		
		pixelColor(surface, xbase, out->y, colour->red_pen);
		pixelColor(surface, xbase - 1, out->y - 1, colour->red_pen);
		pixelColor(surface, xbase + 1, out->y + 1, colour->red_pen);
		pixelColor(surface, xbase - 1, out->y + 1, colour->red_pen);
		pixelColor(surface, xbase + 1, out->y - 1, colour->red_pen);
	}

	if(single_line)
		delete dm;
	else
		dm->lastshift = shift;
}
Пример #17
0
void Weapon::update(
    const UpdateFrame & updateFrame,
    const EquipmentUpdateContext & context,
    const Pose3D &                 weaponPose,
    float                          maxAngle)
{
    auto seconds = updateFrame.gameSeconds();

    if (!m_fireRequestActive)
    {
        m_pose = weaponPose;
        m_cooldown = std::max(0.0f, m_cooldown - seconds);
        return;
    }

    auto timeAccumulator = 0.0f;

    auto baseMillis = updateFrame.beginMicros() / 1000;

    while (seconds > m_cooldown)
    {
        seconds -= m_cooldown;
        timeAccumulator += m_cooldown;

        auto intermediatePose = m_pose.interpolated(
            weaponPose, timeAccumulator / (seconds + timeAccumulator));

        const auto origin = intermediatePose.position();
        const auto trajectoryLocal =
            intermediatePose.directionWorldToLocal(m_fireRequestDirection);

        auto angle = glm::angle(trajectoryLocal, glm::vec3(0.0f, 0.0f, -1.0f));

        if (angle <= maxAngle && angle > 0.0f)
        {
            auto & world = m_hailstormManager.world();

            /**
             * Lazily init render batch
             */
            if (m_prototype->vfxMeshRenderBatchIndex() == INVALID_VFX_MESH_RENDER_BATCH_INDEX)
            {
                auto renderBatchKey = VfxBatchKey(m_prototype->vfxMeshId(), true, RenderPhase::Forward,
                                                  VfxParticleOrientationType::World);
                auto renderBatchIndex = m_hailstormManager.vfxManager().meshRenderer().getOrCreateBatchIndex(renderBatchKey);
                m_prototype->setVfxMeshRenderBatchIndex(renderBatchIndex);
            }

            const auto velocity = m_fireRequestDirection * m_prototype->speed() +
                                  context.body->linearVelocity();

            VfxParticle particle(
                origin,
                velocity,
                baseMillis + ((TimestampMillis)(timeAccumulator * 1000.0f)),
                static_cast<DurationMillis>(m_prototype->lifetime() * 1000));

            particle.meshRenderBatchIndex = m_prototype->vfxMeshRenderBatchIndex();
            particle.birthRGBA = glm::vec4(1.0f);
            particle.deathRGBA = glm::vec4(1.0f);

            particle.birthOrientation = GetArcQuaternion({0, 0, -1}, glm::normalize(velocity));

            particle.pointLight = VfxPointLightDesc{1000.0f};
            particle.birthScale = m_prototype->scale();
            particle.birthScale = m_prototype->scale();

            HailstormBullet bullet(particle, 50.0f, 3, context.entity.id());
            bullet.explosionEmitter = m_prototype->explosionEmitter();
            bullet.intensity = m_prototype->damage();

            m_hailstormManager.addBullet(bullet);

            Assert(m_prototype->frequency() != 0.0f);
            m_cooldown = 1.0f / m_prototype->frequency();
        }
        else
        {
            seconds -= 0.001f;
        }
    }

    m_pose = weaponPose;
    m_cooldown -= seconds;
}
Пример #18
0
void Game::playingHandleEvent(sf::Event &event) {

	if ((event.type == sf::Event::KeyPressed &&
				event.key.code == sf::Keyboard::Escape) ||
			event.type == sf::Event::LostFocus)
	{
			previous_game_state.push_back(Playing);
			next_game_state = PauseMenu;
			std::cout << "menu" << std::endl;
	}

	if (event.type == sf::Event::KeyPressed) {
		if (event.key.code == sf::Keyboard::Escape) {
			previous_game_state.push_back(Playing);
			next_game_state = PauseMenu;
			std::cout << "menu" << std::endl;
		} else if (event.key.code == sf::Keyboard::F8) {
			window.setMouseCursorVisible(true);
			next_game_state = MapEditor;
			std::cout << "mapeditor" << std::endl;
		} else if (event.key.code == (sf::Keyboard::Key)keys["reload"] &&
				player.extra_ammo > 0) {
			player.reloading = true;
			player.reload_timer = clock.getElapsedTime() + sf::milliseconds(1000);
			reload_sound.play();
		}
	} else if (event.type == sf::Event::MouseButtonPressed) {
        if (event.mouseButton.button == sf::Mouse::Left) {
			if (player.ammo > 0 && !player.reloading) {
				player.ammo -= 1;
				bool possible;
				sf::Vector2f pos = bulletSpawnPosition(possible);
				if (!possible) {
					return;
				}
				sf::Vector2f vel = vecUnit(player.moving * player.vel +
						(vecUnit(pos - player.position) * 0.002f)) * 0.002f;
				//sf::Vector2f vel = vecUnit(pos - player.position) * 0.002f;
				Bullet bullet(&clock, &window, vel);
				bullet.position = pos;
				bullet.prev_pos = pos;
				bullets.push_back(bullet);
				gunshot_sound.play();
				for (int i=-10; i<10; i++) {
					sf::Vector2f pvel = vecUnit(vecUnit(vel) + vecUnit(sf::Vector2f(vel.y, -vel.x))*float(i/50.0)) *
						(0.0012f + (rand() % 10) / 100000.f);
					Particle part(&clock, &window, 1, pvel, -0.000000005);
					part.position = bullet.position;
					particles.push_back(part);
				}
			}
        } else if (event.mouseButton.button == sf::Mouse::Right) {
			if (knives.size() == 0) {
				bool possible;
				sf::Vector2f pos = bulletSpawnPosition(possible);
				if (!possible) {
					return;
				}
				sf::Vector2f vel = vecUnit(player.moving * player.vel +
						(vecUnit(pos - player.position) * 0.002f)) * 0.002f;
				Knife knife(&textures[2], &clock, &window, vel);
				knife.position = pos;
				knives.push_back(knife);
				knife_sound.play();
			}
		}
	}
}