Example #1
0
 public void DeployOn(RenderTarget target, float alpha, AABB region_bounds = null)
 {
     /*
      * // offset fixes texture coord rounding
      * var offset = 0.25f * Zoom;
      * center.X += offset;
      * center.Y += offset;
      */
     //Target = center;
     //ActualPosition = center;
     this.ViewPosition = AppMath.Interpolate(ActualPosition, PreviousPosition, alpha);
     this.View.Center  = this.ViewPosition;
     target.SetView(this.View);
 }
Example #2
0
        protected bool hasCeiling(cWorld world, float delta, out float bottomY)
        {
            bottomY = 0.0f;

            float predictedPosY = position.Y + delta;

            Vector2f oldTopLeft  = new Vector2f(position.X, position.Y);
            Vector2f newTopLeft  = new Vector2f(position.X, predictedPosY);
            Vector2f newTopRight = new Vector2f(newTopLeft.X + Bounds.dims.X - 2.0f, newTopLeft.Y);

            int endY = world.ToMapPos(oldTopLeft).Y; //mMap.GetMapTileYAtPoint(newBottomLeft.y);
            int begY = Math.Min(world.ToMapPos(newTopLeft).Y, endY);


            int dist = Math.Max(Math.Abs(endY - begY), 1);

            int tileIndexX;

            for (int tileIndexY = begY; tileIndexY <= endY; ++tileIndexY)
            {
                var topLeft  = AppMath.Interpolate(newTopLeft, oldTopLeft, (float)Math.Abs(endY - tileIndexY) / dist);
                var topRight = new Vector2f(topLeft.X + Bounds.dims.X - 1, topLeft.Y);

                for (var checkedTile = topLeft; ; checkedTile.X += Constants.TILE_SIZE)
                {
                    checkedTile.X = Math.Min(checkedTile.X, topRight.X);

                    tileIndexX = world.ToMapPos(checkedTile).X;

                    if (world.CurrentLevel.GetTileAtXY(tileIndexX, tileIndexY).Type == TileType.WALL)
                    {
                        bottomY = (((float)tileIndexY) * Constants.TILE_SIZE + world.WorldBounds.topLeft.Y + Constants.TILE_SIZE);
                        return(true);
                    }

                    if (checkedTile.X >= topRight.X)
                    {
                        break;
                    }
                }
            }

            return(false);
        }
Example #3
0
        protected bool hasGround(cWorld world, float delta, out float groundY)
        {
            /*var oldCenter = lastPosition;
             * var center = position;*/

            groundY = 0.0f;

            float predictedPosY = position.Y + delta;

            /*
             * Vector2f up = new Vector2f(0, -1);
             * Vector2f bottom = new Vector2f(0, 1);
             * Vector2f left = new Vector2f(-1, 0);
             * Vector2f right = new Vector2f(1, 0);*/

            Vector2f oldBottomLeft  = new Vector2f(position.X, position.Y + Bounds.dims.Y);
            Vector2f newBottomLeft  = new Vector2f(position.X, predictedPosY + Bounds.dims.Y);
            Vector2f newBottomRight = new Vector2f(newBottomLeft.X + Bounds.dims.X, newBottomLeft.Y);

            int endY = world.ToMapPos(newBottomLeft).Y; //mMap.GetMapTileYAtPoint(newBottomLeft.y);
            int begY = Math.Max(world.ToMapPos(oldBottomLeft).Y - 1, endY);

            int dist = Math.Max(Math.Abs(endY - begY), 1);

            int tileIndexX;

            for (int tileIndexY = begY; tileIndexY <= endY; ++tileIndexY)
            {
                var bottomLeft  = AppMath.Interpolate(newBottomLeft, oldBottomLeft, (float)Math.Abs(endY - tileIndexY) / dist);
                var bottomRight = new Vector2f(bottomLeft.X + Bounds.dims.X - 1.0f, bottomLeft.Y); // -1, -2.0f

                for (var checkedTile = bottomLeft; ; checkedTile.X += Constants.TILE_SIZE)
                {
                    checkedTile.X = Math.Min(checkedTile.X, bottomRight.X);

                    tileIndexX = world.ToMapPos(checkedTile).X;

                    //world.GetCurrentLevel.GetTileAtXY(tileIndexX, tileIndexY).PlayerCollidable = true;

                    groundY = (int)((float)tileIndexY * Constants.TILE_SIZE + world.WorldBounds.topLeft.Y);

                    TileType tile = world.CurrentLevel.GetTileAtXY(tileIndexX, tileIndexY).Type;
                    if (tile == TileType.WALL)
                    {
                        isOnOnewWayPlatform = false;
                        return(true);
                    }
                    else if (tile == TileType.ONEWAY_PLATFORM && position.Y <= groundY - Bounds.dims.Y)
                    {
                        isOnOnewWayPlatform = true;
                        return(true);
                    }

                    if (checkedTile.X >= bottomRight.X)
                    {
                        /*if(isOnOnewWayPlatform)
                         *  return true;*/
                        break;
                    }
                }
            }

            return(false);
        }
        public override void BuildVertexBuffer(float alpha)
        {
            uint multiplier = 4;
            uint vNum       = ((uint)pool.CountActive * multiplier) + 1;

            //vertices.Clear();
            vertices.Resize(vNum);

            float division = 2.0f;

            Vector2u uSize  = this.renderStates.Texture.Size;
            float    tsizeX = uSize.X;
            float    tsizeY = uSize.Y;

            Vector2f newDims = new Vector2f();

            for (uint i = 0; i < pool.CountActive; ++i)
            {
                Particle p = pool.get((int)i);

                newDims.X = p.Dims.X / division;
                newDims.Y = p.Dims.Y / division;

                p.ViewPos = AppMath.Interpolate(p.Pos, p.LastPos, alpha);

                uint vertexIndex = i * multiplier;

                Vector2f v0Pos = new Vector2f(p.ViewPos.X - newDims.X,
                                              p.ViewPos.Y - newDims.Y);

                Vector2f v1Pos = new Vector2f(p.ViewPos.X + newDims.X,
                                              p.ViewPos.Y - newDims.Y);

                Vector2f v2Pos = new Vector2f(p.ViewPos.X + newDims.X,
                                              p.ViewPos.Y + newDims.Y);

                Vector2f v3Pos = new Vector2f(p.ViewPos.X - newDims.X,
                                              p.ViewPos.Y + newDims.Y);


                // Top-left
                Vertex v0 = new Vertex(
                    v0Pos,
                    p.Color,
                    new Vector2f(0.0f, 0.0f)
                    );

                // Top-right
                Vertex v1 = new Vertex(
                    v1Pos,
                    p.Color,
                    new Vector2f(tsizeX, 0.0f)
                    );

                // Bottom-right
                Vertex v2 = new Vertex(
                    v2Pos,
                    p.Color,
                    new Vector2f(tsizeX, tsizeY)
                    );

                //Bottom-left
                Vertex v3 = new Vertex(
                    v3Pos,
                    p.Color,
                    new Vector2f(0.0f, tsizeY)
                    );

                vertices[vertexIndex + 0] = v0;
                vertices[vertexIndex + 1] = v1;
                vertices[vertexIndex + 2] = v2;
                vertices[vertexIndex + 3] = v3;
            }
        }
 public void CalculateViewPos(float alpha)
 {
     viewPosition = AppMath.Interpolate(position, lastPosition, alpha);
 }
        public override void BuildVertexBuffer(float alpha)
        {
            uint multiplier = 4;
            uint vNum       = ((uint)pool.CountActive * multiplier) + 1;

            //vertices.Clear();
            vertices.Resize(vNum);

            float division = 2.0f;

            Vector2u uSize  = this.renderStates.Texture.Size;
            float    tSizeX = uSize.X;
            float    tSizeY = uSize.Y;

            Vector2f halfDims = new Vector2f();

            for (int i = 0; i < pool.CountActive; ++i)
            {
                Particle p = pool.get(i);

                halfDims.X = p.Dims.X / division;
                halfDims.Y = p.Dims.Y / division;

                p.ViewPos = AppMath.Interpolate(p.Pos, p.LastPos, alpha);

                uint vertexIndex = (uint)i * multiplier;

                Vector2f v0Pos = new Vector2f(p.ViewPos.X - halfDims.X,
                                              p.ViewPos.Y - halfDims.Y);

                Vector2f v1Pos = new Vector2f(p.ViewPos.X + halfDims.X,
                                              p.ViewPos.Y - halfDims.Y);

                Vector2f v2Pos = new Vector2f(p.ViewPos.X + halfDims.X,
                                              p.ViewPos.Y + halfDims.Y);

                Vector2f v3Pos = new Vector2f(p.ViewPos.X - halfDims.X,
                                              p.ViewPos.Y + halfDims.Y);


                // if want rotation included:
                Transform rot = Transform.Identity;
                rot.Rotate((float)AppMath.RadianToDegress(p.Rotation), p.ViewPos);

                v0Pos = rot.TransformPoint(v0Pos);
                v1Pos = rot.TransformPoint(v1Pos);
                v2Pos = rot.TransformPoint(v2Pos);
                v3Pos = rot.TransformPoint(v3Pos);

                // END of rotation code

                // Top-left
                Vertex v0 = new Vertex(
                    v0Pos,
                    p.Color,
                    new Vector2f(0.0f, 0.0f)
                    );

                // Top-right
                Vertex v1 = new Vertex(
                    v1Pos,
                    p.Color,
                    new Vector2f(tSizeX, 0.0f)
                    );

                // Bottom-right
                Vertex v2 = new Vertex(
                    v2Pos,
                    p.Color,
                    new Vector2f(tSizeX, tSizeY)
                    );

                //Bottom-left
                Vertex v3 = new Vertex(
                    v3Pos,
                    p.Color,
                    new Vector2f(0.0f, tSizeY)
                    );

                vertices[vertexIndex + 0] = v0;
                vertices[vertexIndex + 1] = v1;
                vertices[vertexIndex + 2] = v2;
                vertices[vertexIndex + 3] = v3;
            }
        }