Пример #1
0
 public void CopySprite(int x, int y, int z, AnimChunk c, int rot, byte destruct)
 {
     for (int xx = 0; xx < c.X_SIZE; xx++)
     {
         for (int yy = 0; yy < c.Y_SIZE; yy++)
         {
             for (int zz = 0; zz < c.Z_SIZE; zz++)
             {
                 if (c.Voxels[xx, yy, zz].Active)
                 {
                     if (rot == 0)
                     {
                         SetVoxel(x + xx, y + ((c.Z_SIZE - 1) - zz), z + yy, true, destruct, VoxelType.Prefab, c.Voxels[xx, yy, zz].Color, new Color(c.Voxels[xx, yy, zz].Color.ToVector3() * 0.5f));
                     }
                     if (rot == 1)
                     {
                         SetVoxel(x + zz, y + ((c.Z_SIZE - 1) - xx), z + yy, true, destruct, VoxelType.Prefab, c.Voxels[xx, yy, zz].Color, new Color(c.Voxels[xx, yy, zz].Color.ToVector3() * 0.5f));
                     }
                     if (rot == 2)
                     {
                         SetVoxel(x + xx, y + ((c.Z_SIZE - 1) - zz), z + ((c.Z_SIZE - 1) - yy), true, destruct, VoxelType.Prefab, c.Voxels[xx, yy, zz].Color, new Color(c.Voxels[xx, yy, zz].Color.ToVector3() * 0.5f));
                     }
                     if (rot == 3)
                     {
                         SetVoxel(x + xx, y + ((c.Z_SIZE - 1) - zz), z + yy, true, destruct, VoxelType.Prefab, c.Voxels[xx, yy, zz].Color, new Color(c.Voxels[xx, yy, zz].Color.ToVector3() * 0.5f));
                     }
                 }
             }
         }
     }
 }
Пример #2
0
        public void Draw(GraphicsDevice gd, Camera gameCamera, BasicEffect drawEffect)
        {
            drawEffect.DiffuseColor = wallColor.ToVector3();

            for (int x = 0; x < 15; x++)
            {
                for (int y = 0; y < 9; y++)
                {
                    if (x == 0 || x == 14 || y == 0 || y == 8)
                    {
                        if (x != 7 && y != 4)
                        {
                            drawEffect.World = Matrix.CreateRotationX(MathHelper.PiOver2) *
                                               Matrix.CreateRotationZ(wallRots[x, y]) *
                                               Matrix.CreateTranslation(VoxelWorld.ToScreenSpace((x * 16) + 7, (y * 16) + 7, 21) + (Vector3.One * Voxel.HALF_SIZE)) *
                                               gameCamera.worldMatrix;
                            foreach (EffectPass pass in drawEffect.CurrentTechnique.Passes)
                            {
                                pass.Apply();

                                AnimChunk c = objectSheet.AnimChunks[7];
                                gd.DrawUserIndexedPrimitives <VertexPositionNormalColor>(PrimitiveType.TriangleList, c.VertexArray, 0, c.VertexArray.Length, c.IndexArray, 0, c.VertexArray.Length / 2);
                            }
                        }
                    }
                }
            }

            drawEffect.DiffuseColor = Color.White.ToVector3();
        }
Пример #3
0
        public void Draw(GraphicsDevice gd, Camera gameCamera)
        {
            foreach (EffectPass pass in drawEffect.CurrentTechnique.Passes)
            {
                pass.Apply();

                AnimChunk c = spriteSheet.AnimChunks[currentFrame];
                gd.DrawUserIndexedPrimitives <VertexPositionNormalColor>(PrimitiveType.TriangleList, c.VertexArray, 0, c.VertexArray.Length, c.IndexArray, 0, c.VertexArray.Length / 2);

                if (!attacking && !defending)
                {
                    c = spriteSheet.AnimChunks[currentFrame + 4];
                    gd.DrawUserIndexedPrimitives <VertexPositionNormalColor>(PrimitiveType.TriangleList, c.VertexArray, 0, c.VertexArray.Length, c.IndexArray, 0, c.VertexArray.Length / 2);
                }

                if (attacking)
                {
                    c = spriteSheet.AnimChunks[attackFrame + 8];
                    gd.DrawUserIndexedPrimitives <VertexPositionNormalColor>(PrimitiveType.TriangleList, c.VertexArray, 0, c.VertexArray.Length, c.IndexArray, 0, c.VertexArray.Length / 2);
                }

                if (defending)
                {
                    c = spriteSheet.AnimChunks[12];
                    gd.DrawUserIndexedPrimitives <VertexPositionNormalColor>(PrimitiveType.TriangleList, c.VertexArray, 0, c.VertexArray.Length, c.IndexArray, 0, c.VertexArray.Length / 2);
                }
            }
        }
Пример #4
0
        public void Draw(GraphicsDevice gd, Camera gameCamera, BasicEffect drawEffect)
        {
            drawEffect.World = Matrix.CreateRotationX(MathHelper.PiOver2) * Matrix.CreateRotationZ((Dir == 1 || Dir == 3) ? MathHelper.PiOver2 : 0f) * Matrix.CreateTranslation(Position) * gameCamera.worldMatrix;

            foreach (EffectPass pass in drawEffect.CurrentTechnique.Passes)
            {
                pass.Apply();

                AnimChunk c = spriteSheet.AnimChunks[currentFrame];
                gd.DrawUserIndexedPrimitives <VertexPositionNormalColor>(PrimitiveType.TriangleList, c.VertexArray, 0, c.VertexArray.Length, c.IndexArray, 0, c.VertexArray.Length / 2);
            }
        }
Пример #5
0
        public void CopySprite(int x, int y, int z, AnimChunk c, int rot, byte destruct)
        {
            for (int xx = 0; xx < c.X_SIZE; xx++)
            {
                for (int yy = 0; yy < c.Y_SIZE; yy++)
                {
                    for (int zz = 0; zz < c.Z_SIZE; zz++)
                    {
                        if (c.Voxels[xx, yy, zz].Active)
                        {
                            if(rot==0)
                                SetVoxel(x + xx, y+ ((c.Z_SIZE-1)-zz), z + yy, true, destruct, VoxelType.Prefab, c.Voxels[xx,yy,zz].Color, new Color(c.Voxels[xx,yy,zz].Color.ToVector3()*0.5f));
                            if(rot==1)
                                SetVoxel(x + zz, y + ((c.Z_SIZE - 1) - xx), z + yy, true, destruct, VoxelType.Prefab, c.Voxels[xx, yy, zz].Color, new Color(c.Voxels[xx, yy, zz].Color.ToVector3() * 0.5f));
                            if (rot == 2)
                                SetVoxel(x + xx, y + ((c.Z_SIZE - 1) - zz), z + ((c.Z_SIZE - 1) - yy), true, destruct, VoxelType.Prefab, c.Voxels[xx, yy, zz].Color, new Color(c.Voxels[xx, yy, zz].Color.ToVector3() * 0.5f));
                            if (rot == 3)
                                SetVoxel(x + xx, y + ((c.Z_SIZE - 1) - zz), z + yy, true, destruct, VoxelType.Prefab, c.Voxels[xx, yy, zz].Color, new Color(c.Voxels[xx, yy, zz].Color.ToVector3() * 0.5f));

                        }
                    }
                }
            }
        }
Пример #6
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Black);

            if (generatedPercent < 100)
            {
                spriteBatch.Begin();
                for (int x = 0; x < 4; x++)
                {
                    for (int y = 0; y < 3; y++)
                    {
                        spriteBatch.Draw(texTitleBG, -titleScrollPos + (new Vector2(x * texTitleBG.Width, y * texTitleBG.Height)), null, Color.White);
                    }
                }
                spriteBatch.End();

                GraphicsDevice.DepthStencilState = DepthStencilState.Default;
                GraphicsDevice.SamplerStates[0]  = SamplerState.PointClamp;
                GraphicsDevice.BlendState        = BlendState.AlphaBlend;

                drawEffect.World      = Matrix.CreateRotationY(MathHelper.PiOver4) * Matrix.CreateRotationX(MathHelper.PiOver4);
                drawEffect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, GraphicsDevice.Viewport.AspectRatio, 0.1f, 200f);
                drawEffect.View       = Matrix.CreateLookAt(new Vector3(0, 0, -20f), Vector3.Zero, Vector3.Down);

                foreach (EffectPass pass in drawEffect.CurrentTechnique.Passes)
                {
                    pass.Apply();

                    AnimChunk c = gameHero.spriteSheet.AnimChunks[titleCurrentFrame];
                    GraphicsDevice.DrawUserIndexedPrimitives <VertexPositionNormalColor>(PrimitiveType.TriangleList, c.VertexArray, 0, c.VertexArray.Length, c.IndexArray, 0, c.VertexArray.Length / 2);
                    c = gameHero.spriteSheet.AnimChunks[titleCurrentFrame + 4];
                    GraphicsDevice.DrawUserIndexedPrimitives <VertexPositionNormalColor>(PrimitiveType.TriangleList, c.VertexArray, 0, c.VertexArray.Length, c.IndexArray, 0, c.VertexArray.Length / 2);
                }

                spriteBatch.Begin();
                spriteBatch.Draw(texTitle, new Vector2(0, 1), new Rectangle(0, 0, 1280, 20), Color.White);
                spriteBatch.Draw(texTitle, new Vector2(0, 1), new Rectangle(0, 20, (1280 / 100) * generatedPercent, 20), Color.White);
                spriteBatch.Draw(texTitle, new Vector2(300, (GraphicsDevice.Viewport.Height / 2)), new Rectangle(0, 40, 434, 380), Color.White, 0f, new Vector2(434, 380) / 2, 1f, SpriteEffects.None, 1);
                spriteBatch.Draw(texTitle, new Vector2(GraphicsDevice.Viewport.Width - 300, (GraphicsDevice.Viewport.Height / 2)), new Rectangle(433, 40, 393, 552), Color.White, 0f, new Vector2(393, 552) / 2, 1f, SpriteEffects.None, 1);

                //spriteBatch.DrawString(font, "generating: " + generatedPercent, new Vector2(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height) / 2, Color.DarkGray, 0f, font.MeasureString("generating: " + generatedPercent) / 2, 1f, SpriteEffects.None, 1);
                spriteBatch.End();

                base.Draw(gameTime);
                return;
            }

            GraphicsDevice.DepthStencilState = DepthStencilState.Default;
            GraphicsDevice.SamplerStates[0]  = SamplerState.PointClamp;
            GraphicsDevice.BlendState        = BlendState.AlphaBlend;

            foreach (EffectPass pass in drawEffect.CurrentTechnique.Passes)
            {
                pass.Apply();

                for (int y = 0; y < currentRoom.World.Y_CHUNKS; y++)
                {
                    for (int x = 0; x < currentRoom.World.X_CHUNKS; x++)
                    {
                        Chunk c = currentRoom.World.Chunks[x, y, 0];
                        if (!c.Visible)
                        {
                            continue;
                        }

                        if (c == null || c.VertexArray.Length == 0)
                        {
                            continue;
                        }
                        if (!gameCamera.boundingFrustum.Intersects(c.boundingSphere))
                        {
                            continue;
                        }
                        GraphicsDevice.DrawUserIndexedPrimitives <VertexPositionNormalColor>(PrimitiveType.TriangleList, c.VertexArray, 0, c.VertexArray.Length, c.IndexArray, 0, c.VertexArray.Length / 2);
                    }
                }
            }

            currentRoom.Draw(GraphicsDevice, gameCamera, drawEffect);

            foreach (Door d in Doors)
            {
                d.Draw(GraphicsDevice, gameCamera, drawEffect);
            }
            enemyController.Draw(gameCamera, currentRoom);
            projectileController.Draw(gameCamera, currentRoom);
            pickupController.Draw(gameCamera, currentRoom);
            bombController.Draw(gameCamera, currentRoom);

            gameHero.Draw(GraphicsDevice, gameCamera);

            particleController.Draw();

            spriteBatch.Begin();
            //for (int x = 0; x < 4; x++)
            //    for (int y = 0; y < 4; y++)
            //    {
            //        if (!Rooms[x, y].IsGap) spriteBatch.Draw(roomIcon, new Vector2(5+(x*25), 5+(y*25)), null, (gameHero.RoomX==x && gameHero.RoomY==y)?Color.Magenta:Color.Gray);
            //    }
            spriteBatch.DrawString(timerFontLarge, ((int)(doorCountdown / 1000)).ToString("00"), new Vector2(GraphicsDevice.Viewport.Width - 110, 5), Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 1);
            double ms = doorCountdown - ((int)(doorCountdown / 1000) * 1000);

            spriteBatch.DrawString(timerFontSmall, MathHelper.Clamp(((float)ms / 10f), 0f, 99f).ToString("00"), new Vector2(GraphicsDevice.Viewport.Width - 35, 45), Color.Gray);
            spriteBatch.Draw(texHud, new Vector2(0, GraphicsDevice.Viewport.Height - texHud.Height), Color.White);
            //323,9 500,50
            //1139,9 30,50 15
            spriteBatch.Draw(texHud, new Vector2(0, GraphicsDevice.Viewport.Height - texHud.Height) + new Vector2(323, 9), new Rectangle(323, 9, (int)((500f / gameHero.MaxHealth) * gameHero.Health), 50), Color.Red);
            for (int i = 0; i < gameHero.numBombs; i++)
            {
                spriteBatch.Draw(texHud, new Vector2(0, GraphicsDevice.Viewport.Height - texHud.Height) + new Vector2(1139, 9) + new Vector2(i * 45, 0), new Rectangle(1139, 9, 30, 50), Color.Red);
            }

            if (showCompleteAlpha > 0f)
            {
                if (allRoomsComplete && !gameHero.exitReached)
                {
                    spriteBatch.Draw(texStingers, new Vector2(GraphicsDevice.Viewport.Width / 2, 200), new Rectangle(0, 0, 413, 362), Color.White * showCompleteAlpha, 0f, new Vector2(413, 362) / 2, 1f, SpriteEffects.None, 1);
                }
                else if (allRoomsComplete && gameHero.exitReached)
                {
                    spriteBatch.Draw(texStingers, new Vector2(GraphicsDevice.Viewport.Width / 2, 200), new Rectangle(413, 0, 413, 362), Color.White * showCompleteAlpha, 0f, new Vector2(413, 362) / 2, 1f, SpriteEffects.None, 1);
                }
                else if (gameHero.Dead)
                {
                    spriteBatch.Draw(texStingers, new Vector2(GraphicsDevice.Viewport.Width / 2, 200), new Rectangle(413 * 2, 0, 413, 362), Color.White * showCompleteAlpha, 0f, new Vector2(413, 362) / 2, 1f, SpriteEffects.None, 1);
                }
            }

            spriteBatch.End();

            base.Draw(gameTime);
        }
Пример #7
0
        public static void LoadSprite(string fn, ref VoxelSprite sprite)
        {
            byte[] buffer;

            using (FileStream gstr = new FileStream(fn, FileMode.Open))
            {
                byte[] lb = new byte[4];
                gstr.Position = gstr.Length - 4;
                gstr.Read(lb, 0, 4);
                int msgLength = BitConverter.ToInt32(lb, 0);

                buffer = new byte[msgLength];

                gstr.Position = 0;

                using (GZipStream str = new GZipStream(gstr, CompressionMode.Decompress))
                {
                    str.Read(buffer, 0, msgLength);
                }
            }

            int pos = 0;

            int xs     = buffer[0];
            int ys     = buffer[1];
            int zs     = buffer[2];
            int frames = buffer[3];

            sprite = new VoxelSprite(xs, ys, zs);
            sprite.AnimChunks.Clear();
            sprite.ChunkRTs.Clear();

            pos = 4;

            for (int i = 0; i < 10; i++)
            {
                // don't need swatches in game!
                pos += 3;
            }


            for (int frame = 0; frame < frames; frame++)
            {
                sprite.AddFrame(false);

                AnimChunk c = sprite.AnimChunks[frame];

                while (pos < buffer.Length)
                {
                    if (Convert.ToChar(buffer[pos]) != 'c')
                    {
                        //str.Seek(-1, SeekOrigin.Current);
                        //str.Read(ba, 0, 10);
                        int   vx  = buffer[pos];
                        int   vy  = buffer[pos + 1];
                        int   vz  = buffer[pos + 2];
                        Color top = new Color(buffer[pos + 3], buffer[pos + 4], buffer[pos + 5]);

                        c.SetVoxel(vx, vy, vz, true, top);
                        pos += 6;
                    }
                    else
                    {
                        pos++;
                        break;
                    }
                }

                c.UpdateMesh();
            }

            GC.Collect();
        }