Пример #1
0
        private static void DrawGridCells(IGameState state)
        {
            GL.LineWidth(5.0f);
            var deltaX = 2.0f / (float)state.GridWidth;
            var deltaY = 2.0f / (float)state.GridHeight;
            var cell = new Box2D(0, 0, deltaX, deltaY);
            for (int u = 0; u < state.GridWidth; ++u)
            {
                for (int v = 0; v < state.GridHeight; ++v)
                {
                    cell.X = deltaX * u - 1.0f;
                    cell.Y = 1.0f - deltaY * (v + 1);
                    switch (state[u, v])
                    {
                        case FieldType.DIAMONT:
                            DrawDiamont(cell);
                            break;
                        case FieldType.CROSS:
                            DrawCross(cell);
                            break;
                        default: break;
                    }

                }
            }
        }
Пример #2
0
 /// <summary>
 /// draws a GL quad, textured with an animation.
 /// </summary>
 /// <param name="rectangle">coordinates ofthe GL quad</param>
 /// <param name="totalSeconds">animation position in seconds</param>
 public void Draw(Box2D rectangle, float totalSeconds)
 {
     var id = (int)CalcAnimationFrame(totalSeconds);
     textures[id].BeginUse();
     rectangle.DrawTexturedRect(Box2D.BOX01);
     textures[id].EndUse();
 }
Пример #3
0
 public Enemy(Component<Box2D> frame, float absoluteTime, float speedY)
 {
     this.frame = frame.Value;
     this.speedY = speedY;
     lastUpdate = absoluteTime;
     startTime = absoluteTime;
 }
Пример #4
0
 public ConstantMovement(Box2D frame, float absoluteTime, float speedX, float speedY)
 {
     this.SpeedX = speedX;
     this.SpeedY = speedY;
     this.Frame = frame;
     lastUpdate = absoluteTime;
 }
Пример #5
0
        private void GameWindow_RenderFrame(object sender, FrameEventArgs e)
        {
            GL.Clear(ClearBufferMask.ColorBufferBit);

            //setup blending equation Color = Color_s · alpha + Color_d · (1 - alpha)
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            GL.BlendEquation(BlendEquationMode.FuncAdd);

            GL.Enable(EnableCap.Blend);
            var rect = new Box2D(-.75f, -.75f, .5f, .5f);
            DrawRect(rect, new Color4(.5f, .7f, .1f, 1));
            rect.X += .25f;
            rect.Y += .25f;
            DrawRect(rect, new Color4(.7f, .5f, .9f, .5f));
            rect.X += .25f;
            rect.Y += .25f;
            DrawRect(rect, new Color4(.7f, .5f, .9f, .5f));
            rect.X += .25f;
            rect.Y += .25f;
            DrawRect(rect, new Color4(.5f, .7f, 1, .5f));
            rect.X += .25f;
            rect.Y += .25f;
            DrawRect(rect, new Color4(.5f, .7f, 1, .5f));
            GL.Disable(EnableCap.Blend);
        }
Пример #6
0
 public void DrawScreen(Box2D clipFrame, uint points)
 {
     GL.Clear(ClearBufferMask.ColorBufferBit);
     GL.LoadIdentity();
     GL.Enable(EnableCap.Blend);
     GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
     if (null != clipFrame)
     {
         foreach (IDrawable drawable in drawables)
         {
             if (clipFrame.Intersects(drawable.Rect))
             {
                 drawable.Draw();
             }
         }
     }
     else
     {
         foreach (IDrawable drawable in drawables)
         {
             drawable.Draw();
         }
     }
     Print(-0.15f, 0.0f, 0.0f, 0.04f, points.ToString());
     GL.Disable(EnableCap.Blend);
 }
 /// <summary>
 /// draws a GL quad, textured with an animation.
 /// </summary>
 /// <param name="rectangle">coordinates ofthe GL quad</param>
 /// <param name="totalSeconds">animation position in seconds</param>
 public void Draw(Box2D rectangle, float totalSeconds)
 {
     spriteSheet.BeginUse();
     var id = CalcAnimationSpriteID(FromID, ToID, AnimationLength, totalSeconds);
     spriteSheet.Draw(id, rectangle);
     spriteSheet.EndUse();
 }
Пример #8
0
 private void DrawBox(Box2D rect, float depth)
 {
     GL.Begin(PrimitiveType.Quads);
     GL.Vertex3(rect.X, rect.Y, depth);
     GL.Vertex3(rect.MaxX, rect.Y, depth);
     GL.Vertex3(rect.MaxX, rect.MaxY, depth);
     GL.Vertex3(rect.X, rect.MaxY, depth);
     GL.End();
 }
Пример #9
0
 public static void DrawTexturedRect(this Box2D rect, Box2D texCoords)
 {
     GL.Begin(PrimitiveType.Quads);
     GL.TexCoord2(texCoords.X, texCoords.Y); GL.Vertex2(rect.X, rect.Y);
     GL.TexCoord2(texCoords.MaxX, texCoords.Y); GL.Vertex2(rect.MaxX, rect.Y);
     GL.TexCoord2(texCoords.MaxX, texCoords.MaxY); GL.Vertex2(rect.MaxX, rect.MaxY);
     GL.TexCoord2(texCoords.X, texCoords.MaxY); GL.Vertex2(rect.X, rect.MaxY);
     GL.End();
 }
Пример #10
0
 private void DrawBox(Box2D rect)
 {
     GL.Begin(PrimitiveType.Quads);
     GL.Vertex2(rect.X, rect.Y);
     GL.Vertex2(rect.MaxX, rect.Y);
     GL.Vertex2(rect.MaxX, rect.MaxY);
     GL.Vertex2(rect.X, rect.MaxY);
     GL.End();
 }
Пример #11
0
 private static void DrawDiamont(Box2D o)
 {
     GL.Begin(PrimitiveType.Quads);
     GL.Vertex2(o.CenterX, o.Y);
     GL.Vertex2(o.MaxX, o.CenterY);
     GL.Vertex2(o.CenterX, o.MaxY);
     GL.Vertex2(o.X, o.CenterY);
     GL.End();
 }
Пример #12
0
        private static void DrawCross(Box2D o)
        {
            GL.Begin(PrimitiveType.Lines);
            GL.Vertex2(o.X, o.Y);
            GL.Vertex2(o.MaxX, o.MaxY);

            GL.Vertex2(o.MaxX, o.Y);
            GL.Vertex2(o.X, o.MaxY);
            GL.End();
        }
Пример #13
0
 public ComponentPlayer(Box2D frame, Box2D clipFrame)
 {
     if (null == frame)
     {
         throw new Exception("Valid frame needed");
     }
     this.frame = frame;
     this.clipFrame = clipFrame;
     this.Shoot = false;
 }
Пример #14
0
 private void DrawRect(Box2D rectangle, Color4 color)
 {
     GL.Color4(color);
     GL.Begin(PrimitiveType.Quads);
     GL.Vertex2(rectangle.X, rectangle.Y);
     GL.Vertex2(rectangle.MaxX, rectangle.Y);
     GL.Vertex2(rectangle.MaxX, rectangle.MaxY);
     GL.Vertex2(rectangle.X, rectangle.MaxY);
     GL.End();
 }
Пример #15
0
 private void Draw(Box2D Rectanlge)
 {
     GL.Color3(Color.White);
     GL.Begin(PrimitiveType.Quads);
         GL.TexCoord2(0.0f, 0.0f); GL.Vertex2(Rectanlge.X, Rectanlge.Y);
         GL.TexCoord2(1.0f, 0.0f); GL.Vertex2(Rectanlge.MaxX, Rectanlge.Y);
         GL.TexCoord2(1.0f, 1.0f); GL.Vertex2(Rectanlge.MaxX, Rectanlge.MaxY);
         GL.TexCoord2(0.0f, 1.0f); GL.Vertex2(Rectanlge.X, Rectanlge.MaxY);
     GL.End();
 }
Пример #16
0
 static void drawPaddle(Box2D frame)
 {
     GL.Begin(PrimitiveType.Quads);
     GL.Color3(Color.Green);
     GL.Vertex2(frame.X, frame.Y);
     GL.Vertex2(frame.MaxX, frame.Y);
     GL.Vertex2(frame.MaxX, frame.MaxY);
     GL.Vertex2(frame.X, frame.MaxY);
     GL.End();
 }
Пример #17
0
 public IDrawable CreateDrawable(string type, Box2D frame, IAnimation animation)
 {
     Texture tex;
     if (this.registeredTypes.TryGetValue(type, out tex))
     {
         IDrawable drawable = new AnimatedSprite(tex, frame, animation);
         drawables.Add(drawable);
         return drawable;
     }
     throw new Exception("Unregisterd type " + type.ToString());
 }
Пример #18
0
 private static void DrawTexturedRect(Box2D rect, Texture tex, Box2D texCoords)
 {
     tex.BeginUse();
     GL.Begin(PrimitiveType.Quads);
     GL.TexCoord2(texCoords.X, texCoords.Y); GL.Vertex2(rect.X, rect.Y);
     GL.TexCoord2(texCoords.MaxX, texCoords.Y); GL.Vertex2(rect.MaxX, rect.Y);
     GL.TexCoord2(texCoords.MaxX, texCoords.MaxY); GL.Vertex2(rect.MaxX, rect.MaxY);
     GL.TexCoord2(texCoords.X, texCoords.MaxY); GL.Vertex2(rect.X, rect.MaxY);
     GL.End();
     tex.EndUse();
 }
Пример #19
0
 private void DrawTexturedRect(Box2D Rectangle, Texture tex)
 {
     GL.Color3(Color.White);
     tex.BeginUse();
     GL.Begin(PrimitiveType.Quads);
     GL.TexCoord2(0.0f, 0.0f); GL.Vertex2(Rectangle.X, Rectangle.Y);
     GL.TexCoord2(1.0f, 0.0f); GL.Vertex2(Rectangle.MaxX, Rectangle.Y);
     GL.TexCoord2(1.0f, 1.0f); GL.Vertex2(Rectangle.MaxX, Rectangle.MaxY);
     GL.TexCoord2(0.0f, 1.0f); GL.Vertex2(Rectangle.X, Rectangle.MaxY);
     GL.End();
     tex.EndUse();
 }
Пример #20
0
 private static void DrawEnemy(Box2D o)
 {
     GL.Begin(PrimitiveType.Triangles);
     GL.Color3(Color.White);
     GL.Vertex2(o.CenterX, o.CenterY);
     GL.Vertex2(o.MaxX, o.CenterY);
     GL.Vertex2(o.MaxX, o.MaxY);
     GL.Color3(Color.Violet);
     GL.Vertex2(o.CenterX, o.CenterY);
     GL.Vertex2(o.X, o.CenterY);
     GL.Vertex2(o.X, o.Y);
     GL.End();
 }
Пример #21
0
 public static bool PushYRangeInside(this Box2D rectangleA, Box2D rectangleB)
 {
     if (rectangleA.SizeY > rectangleB.SizeY) return false;
     if (rectangleA.Y < rectangleB.Y)
     {
         rectangleA.Y = rectangleB.Y;
     }
     if (rectangleA.MaxY > rectangleB.MaxY)
     {
         rectangleA.MaxY = rectangleB.MaxY;
     }
     return true;
 }
Пример #22
0
 public static bool PushXRangeInside(this Box2D rectangleA, Box2D rectangleB)
 {
     if (rectangleA.SizeX > rectangleB.SizeX) return false;
     if (rectangleA.X < rectangleB.X)
     {
         rectangleA.X = rectangleB.X;
     }
     if (rectangleA.MaxX > rectangleB.MaxX)
     {
         rectangleA.MaxX = rectangleB.MaxX;
     }
     return true;
 }
Пример #23
0
 private static void DrawTexturedRect(Box2D Rect, Texture tex)
 {
     //the texture has to be enabled before use
     tex.BeginUse();
     GL.Begin(PrimitiveType.Quads);
         //when using textures we have to set a texture coordinate for each vertex
         //by using the TexCoord command BEFORE the Vertex command
         GL.TexCoord2(0.0f, 0.0f); GL.Vertex2(Rect.X, Rect.Y);
         GL.TexCoord2(1.0f, 0.0f); GL.Vertex2(Rect.MaxX, Rect.Y);
         GL.TexCoord2(1.0f, 1.0f); GL.Vertex2(Rect.MaxX, Rect.MaxY);
         GL.TexCoord2(0.0f, 1.0f); GL.Vertex2(Rect.X, Rect.MaxY);
     GL.End();
     //the texture is disabled, so no other draw calls use this texture
     tex.EndUse();
 }
Пример #24
0
 public static bool PushYRangeInside(this Box2D rectangleA, Box2D rectangleB)
 {
     if (rectangleA.SizeY > rectangleB.SizeY)
     {
         return(false);
     }
     if (rectangleA.Y < rectangleB.Y)
     {
         rectangleA.Y = rectangleB.Y;
     }
     if (rectangleA.MaxY > rectangleB.MaxY)
     {
         rectangleA.MaxY = rectangleB.MaxY;
     }
     return(true);
 }
Пример #25
0
 public static bool PushXRangeInside(this Box2D rectangleA, Box2D rectangleB)
 {
     if (rectangleA.SizeX > rectangleB.SizeX)
     {
         return(false);
     }
     if (rectangleA.X < rectangleB.X)
     {
         rectangleA.X = rectangleB.X;
     }
     if (rectangleA.MaxX > rectangleB.MaxX)
     {
         rectangleA.MaxX = rectangleB.MaxX;
     }
     return(true);
 }
Пример #26
0
        /// <summary>
        /// Calculates the AABR in the overlap
        /// Returns null if no intersection
        /// </summary>
        /// <param name="rectangleB"></param>
        /// <returns>AABR in the overlap</returns>
        public static Box2D Overlap(this Box2D rectangleA, Box2D rectangleB)
        {
            Box2D overlap = null;

            if (rectangleA.Intersects(rectangleB))
            {
                overlap = new Box2D(0.0f, 0.0f, 0.0f, 0.0f);

                overlap.X = (rectangleA.X < rectangleB.X) ? rectangleB.X : rectangleA.X;
                overlap.Y = (rectangleA.Y < rectangleB.Y) ? rectangleB.Y : rectangleA.Y;

                overlap.SizeX = (rectangleA.MaxX < rectangleB.MaxX) ? rectangleA.MaxX - overlap.X : rectangleB.MaxX - overlap.X;
                overlap.SizeY = (rectangleA.MaxY < rectangleB.MaxY) ? rectangleA.MaxY - overlap.Y : rectangleB.MaxY - overlap.Y;
            }

            return(overlap);
        }
Пример #27
0
 /// <summary>
 /// Create a new font that can be printed in OpenGL
 /// </summary>
 /// <param name="texture">texture containing a equally spaced grid of characters</param>
 /// <param name="charactersPerLine">number of characters per grid row</param>
 /// <param name="firstAsciiCode">ascii code of upper left most character in the grid</param>
 /// <param name="characterBoundingBoxWidth">bounding box width of each character cell, allows to zoom in/out of each character</param>
 /// <param name="characterBoundingBoxHeight">bounding box height of each character cell, allows to zoom in/out of each character</param>
 /// <param name="characterSpacing">how much to move to the right after drawing a single character</param>
 public TextureFont(Texture texture, uint charactersPerLine = 16, byte firstAsciiCode = 0
     , float characterBoundingBoxWidth = 1.0f, float characterBoundingBoxHeight = 1.0f, float characterSpacing = 1.0f)
 {
     this.texFont = new SpriteSheet(texture, charactersPerLine, characterBoundingBoxWidth, characterBoundingBoxHeight);
     // Creating 256 Display Lists
     this.baseList = (uint)GL.GenLists(256);
     //foreach of the 256 possible characters create a a quad
     //with texture coordinates and store it in a display list
     var rect = new Box2D(0, 0, 1, 1);
     for (uint asciiCode = 0; asciiCode < 256; ++asciiCode)
     {
         GL.NewList((this.baseList + asciiCode), ListMode.Compile);
         texFont.Draw(asciiCode - firstAsciiCode, rect);
         GL.Translate(characterSpacing, 0, 0);	// Move To The next character
         GL.EndList();
     }
 }
Пример #28
0
        /// <summary>
        /// Calculates the AABR in the overlap
        /// Returns null if no intersection
        /// </summary>
        /// <param name="rectangleB"></param>
        /// <returns>AABR in the overlap</returns>
        public static Box2D Overlap(this Box2D rectangleA, Box2D rectangleB)
        {
            Box2D overlap = null;

            if (rectangleA.Intersects(rectangleB))
            {
                overlap = new Box2D(0.0f, 0.0f, 0.0f, 0.0f);

                overlap.X = (rectangleA.X < rectangleB.X) ? rectangleB.X : rectangleA.X;
                overlap.Y = (rectangleA.Y < rectangleB.Y) ? rectangleB.Y : rectangleA.Y;

                overlap.SizeX = (rectangleA.MaxX < rectangleB.MaxX) ? rectangleA.MaxX - overlap.X : rectangleB.MaxX - overlap.X;
                overlap.SizeY = (rectangleA.MaxY < rectangleB.MaxY) ? rectangleA.MaxY - overlap.Y : rectangleB.MaxY - overlap.Y;
            }

            return overlap;
        }
Пример #29
0
        /// <summary>
        /// If an intersection with the frame occurs do the minimal translation to undo the overlap
        /// </summary>
        /// <param name="rectangleB">The AABR to check for intersect</param>
        public static void UndoOverlap(this Box2D rectangleA, Box2D rectangleB)
        {
            if (rectangleA.Intersects(rectangleB))
            {
                Vector2[] directions = new Vector2[]
                {
                    new Vector2(rectangleB.MaxX - rectangleA.X, 0),
                    new Vector2(rectangleB.X - rectangleA.MaxX, 0),
                    new Vector2(0, rectangleB.MaxY - rectangleA.Y),
                    new Vector2(0, rectangleB.Y - rectangleA.MaxY)
                };

                Vector2 minimum = directions.Aggregate((curMin, x) => (curMin == null || (x.Length) < curMin.Length) ? x : curMin);

                rectangleA.X += minimum.X;
                rectangleA.Y += minimum.Y;
            }
        }
Пример #30
0
        /// <summary>
        /// If an intersection with the frame occurs do the minimal translation to undo the overlap
        /// </summary>
        /// <param name="rectangleB">The AABR to check for intersect</param>
        public static void UndoOverlap(this Box2D rectangleA, Box2D rectangleB)
        {
            if (rectangleA.Intersects(rectangleB))
            {
                Vector2[] directions = new Vector2[]
                {
                    new Vector2(rectangleB.MaxX - rectangleA.X, 0),
                    new Vector2(rectangleB.X - rectangleA.MaxX, 0),
                    new Vector2(0, rectangleB.MaxY - rectangleA.Y),
                    new Vector2(0, rectangleB.Y - rectangleA.MaxY)
                };

                Vector2 minimum = directions.Aggregate((curMin, x) => (curMin == null || (x.Length) < curMin.Length) ? x : curMin);

                rectangleA.X += minimum.X;
                rectangleA.Y += minimum.Y;
            }
        }
Пример #31
0
 private void CreateEnemy(float absoluteTime)
 {
     var container = registry.CreateComponentContainer();
     var frame = new Box2D(0.5f, 1.0f, 0.06f, 0.1f);
     var compFrame = new Component<Box2D>(frame);
     registry.RegisterComponentTo(container, compFrame);
     var enemy = new Enemy(compFrame, absoluteTime, - 0.3f);
     registry.RegisterComponentTo(container, enemy);
     var periodicEnemyBullet = new ComponentPeriodicUpdate(absoluteTime, 1.5f);
     periodicEnemyBullet.OnPeriodElapsed += (s, time) =>
     {
         CreateEnemyBullet(time, frame.X, frame.Y);
         CreateEnemyBullet(time, frame.MaxX, frame.Y);
     };
     registry.RegisterComponentTo(container, periodicEnemyBullet);
     registry.RegisterComponentTo(container, new ComponentClipper(visibleFrame, frame, () => Remove(container)));
     registry.RegisterComponentTo(container, new Collidable(frame));
     registry.RegisterComponentTo(container, new Component<IDrawable>(renderer.CreateDrawable("enemy", frame)));
 }
Пример #32
0
        public void DrawScreen(IEnumerable<Box2D> enemies, IEnumerable<Box2D> bullets, Box2D player)
        {
            GL.Clear(ClearBufferMask.ColorBufferBit);
            GL.LoadIdentity();
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

            texEnemy.BeginUse();
            foreach (Box2D enemy in enemies)
            {
                Draw(enemy);
            }
            texEnemy.EndUse();
            texBullet.BeginUse();
            foreach (Box2D bullet in bullets)
            {
                Draw(bullet);
            }
            texBullet.EndUse();
            texPlayer.BeginUse();
            Draw(player);
            texPlayer.EndUse();
            GL.Disable(EnableCap.Blend);
        }
Пример #33
0
 private static void DrawTexturedRect(Box2D rect, Texture tex, Box2D texCoords)
 {
     tex.BeginUse();
     rect.DrawTexturedRect(texCoords);
     tex.EndUse();
 }
Пример #34
0
 public void Draw(uint spriteID, Box2D rectangle)
 {
     Box2D texCoords = CalcSpriteTexCoords(spriteID);
     rectangle.DrawTexturedRect(texCoords);
 }
Пример #35
0
 public static void TransformCenter(this Box2D rectangle, Matrix3 M)
 {
     /*var newPos = M.Transform(rectangle.CenterX, rectangle.CenterY);
      * rectangle.CenterX = newPos.X;
      * rectangle.CenterY = newPos.Y;*/
 }