当前位置: 首页>>代码示例>>C++>>正文


C++ Laser::getVector方法代码示例

本文整理汇总了C++中Laser::getVector方法的典型用法代码示例。如果您正苦于以下问题:C++ Laser::getVector方法的具体用法?C++ Laser::getVector怎么用?C++ Laser::getVector使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Laser的用法示例。


在下文中一共展示了Laser::getVector方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: handle


//.........这里部分代码省略.........
						destroyBullet = true;
					}
				}
				else
				{
					if(sq(fixtoi(ch->x - p->x)) + sq(fixtoi(ch->y - p->y)) < sq(p->img[0][0] / 2))
					{
						destroyBullet = true;
						G_score += 100;
						G_power = min(G_power + 10, MAX_POWER);
					}
				}
			}
			if(destroyBullet)
				deactivate_homing(i);
			else
			{
				if(ch->handle())
					deactivate_homing(i);
				else if(!G_skipFrame)
					ch->draw();
			}
		}
		else break;
	}
	
	// Lasers
	for(int i = 0; i < MAX_LASER; i++)
	{
		Rect *r, r1, r2;
		Laser *cl = &data_laser[i];
		if(cl->isActive())
		{
			if(cl->origin->isActive())
			{
				r = cl->getVector();
				cl->getSides(&r1, &r2);
				
				if(!p->isDying())
				{
					// Uses cartesian hitbox for checking collision with player
					// First, see if the player is not too far
					if(sq(fixtoi(p->x) - r->x) + sq(fixtoi(p->y) - r->y) <= sq(cl->getAmplitude()))
					{
						// if we're not too far, carry on collision checking
						// calculate the laser's cartesian equation and apply it to each of its sides
						// ax + by + c = 0
						int a, b, c1, c2;
						a = r->h;
						b = -r->w;
						c1 = -(a * r1.x + b * r1.y);
						c2 = -(a * r2.x + b * r2.y);
						
						if(p->getPolarity() != cl->getPolarity())
						{
							int temp = a * fixtoi(p->x) + b * fixtoi(p->y);
							// Work the player's 1 px hitbox
							if(sign(temp + c1) != sign(temp + c2))
								// Hit !
								p->hurt();
						}
						else
						{
							int temp1 = a * (fixtoi(p->x) - p->img[0][0] / 2) + b * fixtoi(p->y);
							int temp2 = a * (fixtoi(p->x) + p->img[0][0] / 2) + b * fixtoi(p->y);
							
							if(sign(temp1 + c1) != sign(temp1 + c2) || sign(temp2 + c1) != sign(temp2 + c2))
							{
								// Hit, but doesn't hurt
								cl->setAmplitude((int)sqrt(sq(fixtoi(p->x) - r->x) + sq(fixtoi(p->y) - r->y)));
								// Using G_skipFrame as a delay
								if(!G_skipFrame)
								{
									G_power += G_power < MAX_POWER;
									G_score += 100;
								}
								// Lasers are powerful, so they push the player
								p->x += fixcos(cl->angle) / 2;
								p->y += fixsin(cl->angle) / 2;
								
								// Add particles ! Yeeee !
								int k = (rand() % 4) + 1;
								for(int j = 0; j < k; j++)
								{
									Fixed a = cl->angle + 128 + (rand() % 64) - 32;
									G_particles->add(p->x, p->y, fixcos(a) / 2, fixsin(a) / 2, cl->getPolarity());
								}
							}
						}
					}
				}
				
				cl->handle();
				if(!G_skipFrame) cl->draw();
			}
			else
				cl->deactivate();
		}
	}
}
开发者ID:QuanticPotato,项目名称:nKaruga,代码行数:101,代码来源:BulletArray.cpp


注:本文中的Laser::getVector方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。