public bool CheckCollision(Actor actor) {
			if (this.cls != null && !this.cls.IsInstanceOfType(actor)) {
				return false;
			} else {
				float actorX = actor.GetX();
				float actorY = actor.GetY();
				if (actorX == this.x && actorY == this.y) {
					return false;
				} else {
					float ax = actor.GetX();
					float ay = actor.GetY();
					float dx;
					float dy;
					if (!this.diag) {
						dx = MathUtils.Abs(ax - this.x);
						dy = MathUtils.Abs(ay - this.y);
						return dx + dy <= this.distance;
					} else {
						dx = this.x - this.distance;
						dy = this.y - this.distance;
						float x2 = this.x + this.distance;
						float y2 = this.y + this.distance;
						return ax >= dx && ay >= dy && ax <= x2 && ay <= y2;
					}
				}
			}
		}
Esempio n. 2
0
 public bool CheckCollision(Actor actor)
 {
     if (this.cls != null && !this.cls.IsInstanceOfType(actor))
     {
         return(false);
     }
     else
     {
         float actorX = actor.GetX();
         float actorY = actor.GetY();
         if (actorX == this.x && actorY == this.y)
         {
             return(false);
         }
         else
         {
             float ax = actor.GetX();
             float ay = actor.GetY();
             float dx;
             float dy;
             if (!this.diag)
             {
                 dx = MathUtils.Abs(ax - this.x);
                 dy = MathUtils.Abs(ay - this.y);
                 return(dx + dy <= this.distance);
             }
             else
             {
                 dx = this.x - this.distance;
                 dy = this.y - this.distance;
                 float x2 = this.x + this.distance;
                 float y2 = this.y + this.distance;
                 return(ax >= dx && ay >= dy && ax <= x2 && ay <= y2);
             }
         }
     }
 }
Esempio n. 3
0
        public IList GetNeighbours(Actor actor, float distance,
                                   bool diag, Type cls)
        {
            float x      = actor.GetX();
            float y      = actor.GetY();
            float xPixel = x * this.cellSize;
            float yPixel = y * this.cellSize;
            float dPixel = distance * this.cellSize;

            float[] r = { xPixel - dPixel, yPixel - dPixel, dPixel * 2 + 1,
                          dPixel * 2 + 1 };
            lock (this.neighbourQuery)
            {
                this.neighbourQuery.Init(x, y, distance, diag, cls);
                IList res = this.GetIntersectingObjects(r, this.neighbourQuery);
                return(res);
            }
        }
Esempio n. 4
0
        public IList GetNeighbours(Actor actor, float distance,
                bool diag, Type cls)
        {
            float x = actor.GetX();
            float y = actor.GetY();
            float xPixel = x * this.cellSize;
            float yPixel = y * this.cellSize;
            float dPixel = distance * this.cellSize;
            float[] r = { xPixel - dPixel, yPixel - dPixel, dPixel * 2 + 1,
					dPixel * 2 + 1 };
            lock (this.neighbourQuery)
            {
                this.neighbourQuery.Init(x, y, distance, diag, cls);
                IList res = this.GetIntersectingObjects(r, this.neighbourQuery);
                return res;
            }
        }
Esempio n. 5
0
        public void PaintObjects(GLEx g, int minX, int minY, int maxX, int maxY)
        {
            lock (objects)
            {
                batch.Begin();
                IIterator it = objects.Iterator();
                for (; it.HasNext();)
                {
                    thing = (Actor)it.Next();
                    if (!thing.visible)
                    {
                        continue;
                    }
                    isListener = (thing.actorListener != null);

                    if (isVSync)
                    {
                        if (isListener)
                        {
                            thing.actorListener.Update(elapsedTime);
                        }
                        thing.Update(elapsedTime);
                    }

                    RectBox rect = thing.GetRectBox();
                    actorX      = minX + thing.GetX();
                    actorY      = minY + thing.GetY();
                    actorWidth  = rect.width;
                    actorHeight = rect.height;
                    if (actorX + actorWidth < minX || actorX > maxX ||
                        actorY + actorHeight < minY || actorY > maxY)
                    {
                        continue;
                    }
                    LTexture actorImage = thing.GetImage();
                    if (actorImage != null)
                    {
                        width          = (actorImage.GetWidth() * thing.scaleX);
                        height         = (actorImage.GetHeight() * thing.scaleY);
                        isBitmapFilter = (thing.filterColor != null);
                        thing.SetLastPaintSeqNum(paintSeq++);
                        angle      = thing.GetRotation();
                        colorAlpha = thing.alpha;

                        if (isBitmapFilter)
                        {
                            batch.Draw(actorImage, actorX, actorY, width,
                                       height, angle, thing.filterColor);
                        }
                        else
                        {
                            if (colorAlpha != 1f)
                            {
                                g.SetAlpha(colorAlpha);
                            }
                            batch.Draw(actorImage, actorX, actorY, width,
                                       height, angle);
                            if (colorAlpha != 1f)
                            {
                                g.SetAlpha(1f);
                            }
                        }
                    }
                    if (actorX == 0 && actorY == 0)
                    {
                        thing.Draw(g);
                        if (isListener)
                        {
                            thing.actorListener.Draw(g);
                        }
                    }
                    else
                    {
                        g.Translate(actorX, actorY);
                        thing.Draw(g);
                        if (isListener)
                        {
                            thing.actorListener.Draw(g);
                        }
                        g.Translate(-actorX, -actorY);
                    }
                }
                batch.End();
            }
        }
Esempio n. 6
0
        public virtual void PaintObjects(GLEx g, int minX, int minY, int maxX, int maxY)
        {
            lock (objects)
            {
                IIterator it = objects.Iterator();
                for (; it.HasNext(); )
                {
                    thing = (Actor)it.Next();
                    if (!thing.visible)
                    {
                        continue;
                    }
                    isListener = (thing.actorListener != null);

                    if (isVSync)
                    {
                        if (isListener)
                        {
                            thing.actorListener.Update(elapsedTime);
                        }
                        thing.Update(elapsedTime);
                    }

                    RectBox rect = thing.GetRectBox();
                    actorX = minX + thing.GetX();
                    actorY = minY + thing.GetY();
                    actorWidth = rect.width;
                    actorHeight = rect.height;
                    if (actorX + actorWidth < minX || actorX > maxX
                            || actorY + actorHeight < minY || actorY > maxY)
                    {
                        continue;
                    }
                    LTexture actorImage = thing.GetImage();
                    if (actorImage != null)
                    {

                        width = (actorImage.GetWidth() * thing.scaleX);
                        height = (actorImage.GetHeight() * thing.scaleY);
                        isBitmapFilter = (thing.filterColor != null);
                        thing.SetLastPaintSeqNum(paintSeq++);
                        angle = thing.GetRotation();
                        colorAlpha = thing.alpha;

                        if (thing.isAnimation)
                        {

                            if (isBitmapFilter)
                            {
                                g.DrawTexture(actorImage, actorX, actorY, width,
                                        height, angle, thing.filterColor);
                            }
                            else
                            {
                                if (colorAlpha != 1f)
                                {
                                    g.SetAlpha(colorAlpha);
                                }
                                g.DrawTexture(actorImage, actorX, actorY, width,
                                        height, angle);
                                if (colorAlpha != 1f)
                                {
                                    g.SetAlpha(1f);
                                }
                            }

                        }
                        else
                        {

                            int texId = actorImage.GetTextureID();

                            LTextureBatch batch = (LTextureBatch)textures
                                    .GetValue(texId);

                            if (batch == null)
                            {
                                LTextureBatch pBatch = LTextureBatch
                                        .BindBatchCache(this, texId,
                                                actorImage);
                                batch = pBatch;
                                batch.GLBegin();

                                textures.Put(texId, batch);

                            }

                            batch.SetTexture(actorImage);

                            if (isBitmapFilter)
                            {
                                batch.Draw(actorX, actorY, width, height, angle,
                                        thing.filterColor);
                            }
                            else
                            {
                                if (colorAlpha != 1f)
                                {
                                    alphaColor.a = colorAlpha;
                                }
                                batch.Draw(actorX, actorY, width, height, angle,
                                        alphaColor);
                                if (colorAlpha != 1f)
                                {
                                    alphaColor.a = 1;
                                }
                            }

                        }
                    }
                    if (thing.isConsumerDrawing)
                    {
                        if (actorX == 0 && actorY == 0)
                        {
                            thing.Draw(g);
                            if (isListener)
                            {
                                thing.actorListener.Draw(g);
                            }
                        }
                        else
                        {
                            g.Translate(actorX, actorY);
                            thing.Draw(g);
                            if (isListener)
                            {
                                thing.actorListener.Draw(g);
                            }
                            g.Translate(-actorX, -actorY);
                        }
                    }
                }

                int size = textures.Size();
                if (size > 0)
                {
                    for (int i = 0; i < size; i++)
                    {
                        LTextureBatch batch = (LTextureBatch)textures.Get(i);
                        batch.GLEnd();
                    }
                    textures.Clear();
                }
            }
        }
Esempio n. 7
0
        public virtual void PaintObjects(GLEx g, int minX, int minY, int maxX, int maxY)
        {
            lock (objects)
            {
                IIterator it = objects.Iterator();
                for (; it.HasNext();)
                {
                    thing = (Actor)it.Next();
                    if (!thing.visible)
                    {
                        continue;
                    }
                    isListener = (thing.actorListener != null);

                    if (isVSync)
                    {
                        if (isListener)
                        {
                            thing.actorListener.Update(elapsedTime);
                        }
                        thing.Update(elapsedTime);
                    }

                    RectBox rect = thing.GetRectBox();
                    actorX      = minX + thing.GetX();
                    actorY      = minY + thing.GetY();
                    actorWidth  = rect.width;
                    actorHeight = rect.height;
                    if (actorX + actorWidth < minX || actorX > maxX ||
                        actorY + actorHeight < minY || actorY > maxY)
                    {
                        continue;
                    }
                    LTexture actorImage = thing.GetImage();
                    if (actorImage != null)
                    {
                        width          = (actorImage.GetWidth() * thing.scaleX);
                        height         = (actorImage.GetHeight() * thing.scaleY);
                        isBitmapFilter = (thing.filterColor != null);
                        thing.SetLastPaintSeqNum(paintSeq++);
                        angle      = thing.GetRotation();
                        colorAlpha = thing.alpha;

                        if (thing.isAnimation)
                        {
                            if (isBitmapFilter)
                            {
                                g.DrawTexture(actorImage, actorX, actorY, width,
                                              height, angle, thing.filterColor);
                            }
                            else
                            {
                                if (colorAlpha != 1f)
                                {
                                    g.SetAlpha(colorAlpha);
                                }
                                g.DrawTexture(actorImage, actorX, actorY, width,
                                              height, angle);
                                if (colorAlpha != 1f)
                                {
                                    g.SetAlpha(1f);
                                }
                            }
                        }
                        else
                        {
                            int texId = actorImage.GetTextureID();

                            LTextureBatch batch = (LTextureBatch)textures
                                                  .GetValue(texId);

                            if (batch == null)
                            {
                                LTextureBatch pBatch = LTextureBatch
                                                       .BindBatchCache(this, texId,
                                                                       actorImage);
                                batch = pBatch;
                                batch.GLBegin();

                                textures.Put(texId, batch);
                            }

                            batch.SetTexture(actorImage);

                            if (isBitmapFilter)
                            {
                                batch.Draw(actorX, actorY, width, height, angle,
                                           thing.filterColor);
                            }
                            else
                            {
                                if (colorAlpha != 1f)
                                {
                                    alphaColor.a = colorAlpha;
                                }
                                batch.Draw(actorX, actorY, width, height, angle,
                                           alphaColor);
                                if (colorAlpha != 1f)
                                {
                                    alphaColor.a = 1;
                                }
                            }
                        }
                    }
                    if (thing.isConsumerDrawing)
                    {
                        if (actorX == 0 && actorY == 0)
                        {
                            thing.Draw(g);
                            if (isListener)
                            {
                                thing.actorListener.Draw(g);
                            }
                        }
                        else
                        {
                            g.Translate(actorX, actorY);
                            thing.Draw(g);
                            if (isListener)
                            {
                                thing.actorListener.Draw(g);
                            }
                            g.Translate(-actorX, -actorY);
                        }
                    }
                }

                int size = textures.Size();
                if (size > 0)
                {
                    for (int i = 0; i < size; i++)
                    {
                        LTextureBatch batch = (LTextureBatch)textures.Get(i);
                        batch.GLEnd();
                    }
                    textures.Clear();
                }
            }
        }
Esempio n. 8
0
        public void PaintObjects(GLEx g, int minX, int minY, int maxX, int maxY)
        {
            lock (objects)
            {
                g.BeginBatch();
                IIterator it = objects.Iterator();
                for (; it.HasNext(); )
                {
                    thing = (Actor)it.Next();
                    if (!thing.visible)
                    {
                        continue;
                    }
                    isListener = (thing.actorListener != null);

                    if (isVSync)
                    {
                        if (isListener)
                        {
                            thing.actorListener.Update(elapsedTime);
                        }
                        thing.Update(elapsedTime);
                    }

                    RectBox rect = thing.GetRectBox();
                    actorX = minX + thing.GetX();
                    actorY = minY + thing.GetY();
                    actorWidth = rect.width;
                    actorHeight = rect.height;
                    if (actorX + actorWidth < minX || actorX > maxX
                            || actorY + actorHeight < minY || actorY > maxY)
                    {
                        continue;
                    }
                    LTexture actorImage = thing.GetImage();
                    if (actorImage != null)
                    {
                        width = (actorImage.GetWidth() * thing.scaleX);
                        height = (actorImage.GetHeight() * thing.scaleY);
                        isBitmapFilter = (thing.filterColor != null);
                        thing.SetLastPaintSeqNum(paintSeq++);
                        angle = thing.GetRotation();
                        colorAlpha = thing.alpha;

                        if (isBitmapFilter)
                        {
                            g.DrawBatch(actorImage, actorX, actorY, width,
                                    height, angle, thing.filterColor.Color);
                        }
                        else
                        {
                            if (colorAlpha != 1f)
                            {
                                g.SetAlpha(colorAlpha);
                            }
                            g.DrawBatch(actorImage, actorX, actorY, width,
                                    height, angle);
                            if (colorAlpha != 1f)
                            {
                                g.SetAlpha(1f);
                            }
                        }
                    }
                    if (actorX == 0 && actorY == 0)
                    {
                        thing.Draw(g);
                        if (isListener)
                        {
                            thing.actorListener.Draw(g);
                        }
                    }
                    else
                    {
                        g.Translate(actorX, actorY);
                        thing.Draw(g);
                        if (isListener)
                        {
                            thing.actorListener.Draw(g);
                        }
                        g.Translate(-actorX, -actorY);
                    }
                }
                g.EndBatch();
            }
        }