示例#1
0
    public void checkConstraints()
    {
        int[] collision = rayCast.rayCast((int)lastX, (int)lastY, (int)x, (int)y);
        if (collision.Length > 0)
        {
            Direction direction = velX > 0 ? Direction.FromLeft : Direction.FromRight;
//			pD.DestroyBullet();
            physics.Remove(this);
            explode.explode(collision [2], collision [3], 100, direction);              //60);

            //Debug.Log("last x " + lastX);
            //Debug.Log("last y " + lastY);
            //Debug.Log("x " + x);
            //Debug.Log("y " + y);
            //Debug.Log("vx " + velX);
            //Debug.Log("vy " + velY);
            //Debug.Log("explode x " + collision[2]);
            //Debug.Log("explode y " + collision[3]);
        }
        lastX = x;
        lastY = y;
    }
    void CalculateWorld()
    {
        UnityEngine.Profiling.Profiler.BeginSample("Game.CalculateWorld");

        /* Check for Dynamic Pixels and draw them */
        if (SpawnedPixels.Count > 0)                         // if there are active dPixels
        {
            for (int i = 0; i < SpawnedPixels.Count; i++)    // iterate through all active dPixels
            {
                int x = (int)SpawnedPixels[i].getX();        // then we get our current pos
                int y = (int)SpawnedPixels[i].getY();
                if (this.World.IsInside(new Vector2I(x, y))) // only set the pixel if its within boundaries
                {
                    if (this.World == null)
                    {
                        previousDynamicPixels.Add(new Vector2(x, y));
                        // and set our pixels currently // TODO: scale to destruction resolution!
                        this.addPixel(SpawnedPixels[i].col, x, y);
                    }
                }
                else
                {
//					Debug.LogWarning("Warning: pixel outside boundaries in calculate world!");
                    physics.Remove(SpawnedPixels[i]);              // TEMPORARY TESTING OF REMOVAL OF ROGUE PIXELS
                    SpawnedPixels.RemoveAt(i);                     // TEMPORARY TESTING OF REMOVAL OF ROGUE PIXELS
                }
            }
        }

        ///* Check for Player and draw them */
        //ourPlayerAnimation.X = player.getX();
        //ourPlayerAnimation.Y = player.getY();

        // old player drawing below
//		if (player != null)
//		{
//			// draw our player EXPERIMENTAL
//			for(int iteration = 0; iteration < player.playerHeight; iteration++)
//			{
//				for(int i = 0; i < player.playerWidth ;i++)
//				{
//					previousPlayerPixels.Add(new Vector2((int) player.x + (i - (player.playerWidth / 2)), (int) player.y + (iteration - (player.playerHeight / 2))));
//					//world.SetPixel((int) player.x + (i - 8), (int) player.y + (iteration - 8), Color.red);
//
//					if(isPixelSolid((int) player.x + (i - (player.playerWidth / 2)), (int) player.y + (iteration - (player.playerHeight / 2))))  //world.GetPixel((int) player.x + (i - (player.playerWidth / 2)), (int) player.y + (iteration - (player.playerHeight / 2))).a != 0) // if the pixel is solid in world, were supposed to be colliding
//					{
//						//Debug.LogError("Collision Overlap - Player/world at X: " + (player.x + (i - (player.playerWidth / 2))) + " Y: " + (player.y + (iteration - (player.playerHeight / 2))));
//					}
//					else // we only draw our pixels if were not overlapping the ground
//					{
//						if(iteration > player.playerHeight / 2)
//						{
//							dPixelsWorld.SetPixel((int) player.x + (i - (player.playerWidth / 2)), (int) player.y + (iteration - (player.playerHeight / 2)), Color.green);
//						}
//						else if(iteration < player.playerHeight / 2 && iteration < player.playerHeight / 4)
//						{
//							dPixelsWorld.SetPixel((int) player.x + (i - (player.playerWidth / 2)), (int) player.y + (iteration - (player.playerHeight / 2)), Color.white);
//						}
//						else
//						{
//							dPixelsWorld.SetPixel((int) player.x + (i - (player.playerWidth / 2)), (int) player.y + (iteration - (player.playerHeight / 2)), Color.gray);
//						}
//						dynamicPixelUpdate = true;
//					}
//				}
//			}
//
////			Debug.Log("setting pixel: " + player.x + " " + player.y);
//			//worldUpdate = true;
//		}

        UnityEngine.Profiling.Profiler.EndSample();
    }