Example #1
0
        public static Geometry CreateBox(OpenTK.Box2 box)
        {
            Vector2[] vertices = new Vector2[4] {
                new Vector2(box.Left, box.Bottom),
                new Vector2(box.Left, box.Top),
                new Vector2(box.Right, box.Top),
                new Vector2(box.Right, box.Bottom)
            };

            Color4[] colors = new Color4[4]
            {
                new Color4(1.0f, 1.0f, 1.0f, 1.0f),
                new Color4(1.0f, 1.0f, 1.0f, 1.0f),
                new Color4(1.0f, 1.0f, 1.0f, 1.0f),
                new Color4(1.0f, 1.0f, 1.0f, 1.0f)
            };

            Vector2[] texCoords = new Vector2[4]
            {
                new Vector2(0, 1),
                new Vector2(0, 0),
                new Vector2(1, 0),
                new Vector2(1, 1)
            };

            int[]    indices = new int[] { 0, 1, 2, 0, 2, 3 };
            Geometry geom    = new Geometry(OpenTK.Graphics.OpenGL4.PrimitiveType.Triangles, vertices, colors, texCoords, indices);

            return(geom);
        }
Example #2
0
        public void AddFrame(Visual graphicsObject, float time, OpenTK.Box2 aabb)
        {
            Frame frame = new Frame();

            frame.graphicsObject = graphicsObject;;
            frame.time           = time;
            frame.aabb           = aabb;
            frames.Add(frame);
        }
Example #3
0
        /// <summary>
        ///     Finds all grids that intersect the rectangle in the world.
        /// </summary>
        /// <param name="worldArea">The are in world coordinates to search.</param>
        /// <returns></returns>
        public IEnumerable <IMapGrid> FindGridsIntersecting(OpenTK.Box2 worldArea)
        {
            var gridList = new List <MapGrid>();

            foreach (var kvGrid in _grids)
            {
                if (kvGrid.Value.AABBWorld.Intersects(worldArea))
                {
                    gridList.Add(kvGrid.Value);
                }
            }
            return(gridList);
        }
Example #4
0
        public SSTReader(System.IO.BinaryReader sst)
        {
            byte compressMode = sst.ReadByte();

            switch (compressMode)
            {
            case 0:
                cmode = SSTCompressMode.RGBA;
                break;

            case 10:
                cmode = SSTCompressMode.DXT1;
                break;

            case 11:
                cmode = SSTCompressMode.DXT3;
                break;

            case 12:
                cmode = SSTCompressMode.DXT5;
                break;

            default:
                throw new Exception("Bad sst texture.");
            }

            UInt16 rectSize = sst.ReadUInt16();

            width  = sst.ReadUInt16();
            height = sst.ReadUInt16();

            rects = new OpenTK.Box2[rectSize];

            for (UInt16 i = 0; i < rectSize; ++i)
            {
                UInt16 x = sst.ReadUInt16();
                UInt16 y = sst.ReadUInt16();
                UInt16 w = sst.ReadUInt16();
                UInt16 h = sst.ReadUInt16();

                rects[i].Left   = x / width;
                rects[i].Right  = (x + w) / width;
                rects[i].Top    = y / height;
                rects[i].Bottom = (y + h) / height;
            }

            var dataSize = sst.ReadInt32();

            data = sst.ReadBytes(dataSize);
        }
Example #5
0
 public Button(int tex, OpenTK.Box2 b)
 {
     texture = tex;
     box = b;
     press = false;
 }
Example #6
0
 public Button(Effect effect, OpenTK.Box2 b)
 {
     this.graphicsObject = new Visual(GeometryFactory.CreateBox(b), effect);
     box     = b;
     pressed = false;
 }
Example #7
0
        protected override void OnLoad(EventArgs e)
        {
            AnimationState beginPlayState, winnerState, loserState, newGameState;
            StartMenuState startMenuState;
            GameOverState  gameOverState;
            PlayingState   playingState;

            Animation readyGoAnimation;
            Animation newGameAnimation;
            Animation winAnimation;
            Animation loseAnimation;

            OpenTK.Box2 box = new OpenTK.Box2(
                new OpenTK.Vector2(-Constants.tableWidth * 0.5f, Constants.tableHeight * 0.5f),
                new OpenTK.Vector2(Constants.tableWidth * 0.5f, -Constants.tableHeight * 0.5f));
            Geometry boxGeometry = GeometryFactory.CreateBox(box);

            readyGoAnimation = new Animation();
            readyGoAnimation.AddFrame(new Visual(boxGeometry,
                                                 new TextureEffect("ready.png")), 0.3f, box);

            readyGoAnimation.AddFrame(new Visual(boxGeometry,
                                                 new TextureEffect("go.png")), 0.2f, box);

            newGameAnimation = new Animation();
            newGameAnimation.AddFrame(new Visual(boxGeometry,
                                                 new TextureEffect("newGame.png")), 0.1f, box);
            newGameAnimation.AddFrame(new Visual(boxGeometry,
                                                 new TextureEffect("countDown3.png")), 0.1f, box);
            newGameAnimation.AddFrame(new Visual(boxGeometry,
                                                 new TextureEffect("countDown2.png")), 0.1f, box);
            newGameAnimation.AddFrame(new Visual(boxGeometry,
                                                 new TextureEffect("countDown1.png")), 0.1f, box);

            winAnimation = new Animation();
            winAnimation.AddFrame(new Visual(boxGeometry,
                                             new TextureEffect("winner.png")), 2.0f, box);

            loseAnimation = new Animation();
            loseAnimation.AddFrame(new Visual(boxGeometry,
                                              new TextureEffect("loser.png")), 2.0f, box);

            beginPlayState = new AnimationState(stateManager, soundEngine, readyGoAnimation, "", StateId.Pop);
            winnerState    = new AnimationState(stateManager, soundEngine, winAnimation, "", StateId.GameOver);
            loserState     = new AnimationState(stateManager, soundEngine, loseAnimation, "", StateId.GameOver);
            newGameState   = new AnimationState(stateManager, soundEngine, newGameAnimation, ResourceManager.MediaPath + "countdown.wav",
                                                StateId.BeginPlay);
            startMenuState = new StartMenuState(stateManager, resourceManager);
            playingState   = new PlayingState(stateManager, soundEngine, renderer, resourceManager);
            gameOverState  = new GameOverState(stateManager, resourceManager);

            stateManager.Add(StateId.Menu, startMenuState);
            stateManager.Add(StateId.Playing, playingState);
            stateManager.Add(StateId.Winner, winnerState);
            stateManager.Add(StateId.Loser, loserState);
            stateManager.Add(StateId.BeginPlay, beginPlayState);
            stateManager.Add(StateId.GameOver, gameOverState);
            stateManager.Add(StateId.NewGame, newGameState);



            stateManager.Change(StateId.Menu);
        }
Example #8
0
        protected override void OnLoad(EventArgs e)
        {
            tableTexture = renderer.CreateTextureFromFile("table.png");

            OpenTK.Box2 box = new OpenTK.Box2(new OpenTK.Vector2(-Constants.tableWidth * 0.5f, Constants.tableHeight * 0.5f), new OpenTK.Vector2(Constants.tableWidth * 0.5f, -Constants.tableHeight * 0.5f));
            readyGoAnimation = new Animation();
            readyGoAnimation.AddFrame(renderer.CreateTextureFromFile("ready.png"), 0.3f, box );
            readyGoAnimation.AddFrame(renderer.CreateTextureFromFile("go.png"), 0.2f, box);

            newGameAnimation = new Animation();
            newGameAnimation.AddFrame(renderer.CreateTextureFromFile("newGame.png"), 0.3f, box);
            newGameAnimation.AddFrame(renderer.CreateTextureFromFile("countDown3.png"), 1.0f, box);
            newGameAnimation.AddFrame(renderer.CreateTextureFromFile("countDown2.png"), 1.0f, box);
            newGameAnimation.AddFrame(renderer.CreateTextureFromFile("countDown1.png"), 1.0f, box);

            winAnimation = new Animation();
            winAnimation.AddFrame(renderer.CreateTextureFromFile("winner.png"), 2.0f, box);

            loseAnimation = new Animation();
            loseAnimation.AddFrame(renderer.CreateTextureFromFile("loser.png"), 2.0f, box);

            SetGameState(GameState.Menu);
        }
 /// <summary>
 /// Converts a OpenTK Box2 to a SFML FloatRect.
 /// </summary>
 /// <param name="box">OpenTK Box2.</param>
 /// <returns>SFML FloatRect.</returns>
 public static FloatRect Convert(this OpenTK.Box2 box)
 {
     return(new FloatRect(box.Left, box.Top, box.Width, box.Height));
 }