Ejemplo n.º 1
0
        public void StartNewGame()
        {
            //we want to load in the game initialization settings
            TFSH.PokeEngineScriptHelper.Initialize(graphics, content, font, world);
            lua = new Lua();

            previousTime = 0;

            //MAKE TEST MAP
            world.getBounds();
            world.changeZone("test");
            //GameDraw.makeGroundBuffers(map);
            GameDraw.MakeAdjBuffers(world);
            GameDraw.UpdateNPCSpritesheets(world);
            //MAKE PLAYER
            player             = new PC.Player();
            player.name        = "EncyKal";
            player.spriteSheet = "overworld.png";
            player.tileCoords  = new Point(4, 4);
            loadPlayerTextureSheet();
            //TFSH.PokeEngineScriptHelper.setMap("test", 6, 6);
            for (int i = 0; i < player.IdentifiedPokemon.Length; i++)
            {
                if (i % 3 != 0)
                {
                    player.IdentifiedPokemon[i] = true;
                }
            }
            //world.currentArea.tile[6, 6].setOccupied(true);

            GameDraw.UpdateNPCSpritesheets(world);

            //PokedexScreen.SetUpPokedex(player);
        }
Ejemplo n.º 2
0
        //draws adjacent ground and the current map given a player
        public static void DrawAdjacentGround(World inWorld, PC.Player inPlayer)
        {
            float   moveRatio    = (float)inPlayer.movementIndex / (float)inPlayer.speed;
            Vector3 drawLocation = new Vector3();

            drawLocation.X = inWorld.currentArea.globalX + inPlayer.tileCoords.X + moveRatio * (inPlayer.nextTile.X - inPlayer.tileCoords.X);
            drawLocation.Y = inWorld.currentArea.globalY + inPlayer.tileCoords.Y + moveRatio * (inPlayer.nextTile.Y - inPlayer.tileCoords.Y);
            drawLocation.Z = (float)inPlayer.currentZ + moveRatio * ((float)inWorld.currentArea.tile[inPlayer.nextTile.X, inPlayer.nextTile.Y].Z - (float)inPlayer.currentZ);
            DrawAdjacentGround(inWorld, drawLocation);
        }
Ejemplo n.º 3
0
        //method 2 of drawground
        //draws adjacent ground and the current map

        /*
         * public static void drawAdjacentGround(World inWorld, PC.Player inPlayer)
         * {
         *  playerPosition = new Vector3(inPlayer.mapCoords.X * 32, 0, inPlayer.mapCoords.Y * 32);
         *  cameraPosition = playerPosition + cameraOffset;
         *  SamplerState temp = null;
         *
         *  int numberOfTiles = 0;
         *  foreach (Zone z in inWorld.adjacentAreas)
         *  {
         *      numberOfTiles += (z.mapHeight * z.mapWidth);
         *  }
         *
         *  //create our world view projection matrices
         *  Matrix world = Matrix.Identity;
         *  Matrix view = Matrix.CreateLookAt(cameraPosition, playerPosition, Vector3.Up);
         *  Matrix projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f),
         *      aspectRatio, 1.0f, 10000.0f);
         *
         *  //make an effect to use
         *  //apply the texture and other effects
         *  BasicEffect effect = new BasicEffect(graphics.GraphicsDevice); //make new graphics device
         *  effect.TextureEnabled = true;
         *  //effect.EnableDefaultLighting();
         *  effect.World = world;
         *  effect.View = view;
         *  effect.Projection = projection;
         *
         *  Vector3 normal = Vector3.Up;
         *  Vector2 TLTex = new Vector2(0f, 0f);
         *  Vector2 TRTex = new Vector2(1f, 0f);
         *  Vector2 BRTex = new Vector2(1f, 1f);
         *  Vector2 BLTex = new Vector2(0f, 1f);
         *
         *  VertexPositionNormalTexture[] vertices = new VertexPositionNormalTexture[4];
         *  vertices[0] = new VertexPositionNormalTexture(new Vector3(-0.5f, 0, -0.5f), normal, TLTex);
         *  vertices[1] = new VertexPositionNormalTexture(new Vector3(+0.5f, 0, -0.5f), normal, TRTex);
         *  vertices[2] = new VertexPositionNormalTexture(new Vector3(+0.5f, 0, +0.5f), normal, BRTex);
         *  vertices[3] = new VertexPositionNormalTexture(new Vector3(-0.5f, 0, +0.5f), normal, BLTex);
         *  short[] indices = new short[6];
         *  indices[0] = 0;
         *  indices[1] = 2;
         *  indices[2] = 3;
         *  indices[3] = 0;
         *  indices[4] = 1;
         *  indices[5] = 2;
         *
         *  foreach( KeyValuePair<String, Texture2D> kvp in groundTexture)
         *  {
         *
         *      foreach (Zone z in inWorld.adjacentAreas)
         *      {
         *          for (int x = 0; x < z.mapWidth; x++)
         *          {
         *              for (int y = 0; y < z.mapHeight; y++)
         *              {
         *                  if (z.tile[x, y].tileType == kvp.Key)
         *                  {
         *                      effect.World = Matrix.CreateTranslation(new Vector3(z.globalX * 1f + x * 1f, z.tile[x, y].Z * 0.5f, z.globalY * 1f + y * 1f));
         *                      effect.Texture = kvp.Value;
         *
         *                      foreach (EffectPass pass in effect.CurrentTechnique.Passes)
         *                      {
         *                          pass.Apply();
         *                          graphics.GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionNormalTexture>(PrimitiveType.TriangleList, vertices, 0, 4, indices, 0, 2);
         *                      }
         *                  }
         *              }//end y loop
         *          }//end x loop
         *      }//endzone loop
         *  }
         *
         * }*/

        /* old
         * public static void drawPlayer(PC.Player inPlayer)
         * {
         *  playerPosition = new Vector3(inPlayer.mapCoords.X * 32, 0, inPlayer.mapCoords.Y * 32);
         *  cameraPosition = playerPosition + cameraOffset;
         *  SamplerState temp = null;
         *  //get the model's transforms
         *  Matrix[] transforms = new Matrix[spriteModel.Bones.Count];
         *  spriteModel.CopyAbsoluteBoneTransformsTo(transforms);
         *
         *  RasterizerState state = new RasterizerState();
         *  state.CullMode = CullMode.None;
         *  graphics.GraphicsDevice.RasterizerState = state;
         *
         *  // Draw the model. A model can have multiple meshes, so loop.
         *  foreach (ModelMesh mesh in spriteModel.Meshes)
         *  {
         *      // This is where the mesh orientation is set, as well as our camera and projection.
         *      foreach (BasicEffect effect in mesh.Effects)
         *      {
         *          temp = graphics.GraphicsDevice.SamplerStates[0];
         *          graphics.GraphicsDevice.SamplerStates[0] = SamplerState.PointClamp;
         *
         *          effect.TextureEnabled = true;
         *          effect.Texture = inPlayer.textureSheet;
         *
         *          effect.EnableDefaultLighting();
         *          effect.World = transforms[mesh.ParentBone.Index] * Matrix.CreateScale(1.0f) * Matrix.CreateBillboard(playerPosition, cameraPosition, Vector3.Up, null) ;
         *          effect.View = Matrix.CreateLookAt(cameraPosition, playerPosition, Vector3.Up);
         *          effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f),
         *          aspectRatio, 1.0f, 10000.0f);
         *      }
         *          // Draw the mesh, using the effects set above.
         *      mesh.Draw();
         *      graphics.GraphicsDevice.SamplerStates[0] = temp;
         *
         *  }//end model drawing
         *  state = new RasterizerState();
         *  state.CullMode = CullMode.CullCounterClockwiseFace;
         *  graphics.GraphicsDevice.RasterizerState = state;
         * }*/

        /// <summary>
        /// Draws the player
        /// </summary>
        /// <param name="spritePosition">position of the sprite to draw on the spitesheet</param>
        /// <param name="spritesheetSize">total size of entire spritesheet</param>
        public static void DrawPlayer(PC.Player inPlayer, World inWorld, Rectangle spritePosition, Rectangle spritesheetSize)
        {
            graphics.GraphicsDevice.SamplerStates[0] = SamplerState.PointClamp;
            effect.CurrentTechnique = effect.Techniques[0];
            graphics.GraphicsDevice.DepthStencilState = DepthStencilState.Default; //set stencil state
            graphics.GraphicsDevice.BlendState        = BlendState.AlphaBlend;
            float   moveRatio    = (float)inPlayer.movementIndex / (float)inPlayer.speed;
            Vector3 drawLocation = new Vector3();

            drawLocation.X = inWorld.currentArea.globalX + (float)inPlayer.tileCoords.X + moveRatio * ((float)inPlayer.nextTile.X - (float)inPlayer.tileCoords.X);
            drawLocation.Y = (float)inPlayer.currentZ + moveRatio * ((float)inWorld.currentArea.tile[inPlayer.nextTile.X, inPlayer.nextTile.Y].Z - (float)inPlayer.currentZ);
            drawLocation.Y = drawLocation.Y / 8;
            drawLocation.Z = inWorld.currentArea.globalY + (float)inPlayer.tileCoords.Y + moveRatio * ((float)inPlayer.nextTile.Y - (float)inPlayer.tileCoords.Y);
            playerPosition = drawLocation;
            cameraPosition = playerPosition + cameraOffset;
            //billboard does weird things with culling

            Vector3 normal = Vector3.Backward;
            Vector2 TLTex  = new Vector2((float)(spritePosition.X) / (float)spritesheetSize.Width, (float)(spritePosition.Y) / (float)spritesheetSize.Height);
            Vector2 TRTex  = new Vector2(((float)(spritePosition.X) + (float)spritePosition.Width) / (float)spritesheetSize.Width,
                                         (float)(spritePosition.Y) / (float)spritesheetSize.Height);
            Vector2 BRTex = new Vector2(((float)(spritePosition.X) + (float)spritePosition.Width) / (float)spritesheetSize.Width,
                                        ((float)(spritePosition.Y) + (float)spritePosition.Height) / (float)spritesheetSize.Height);
            Vector2 BLTex = new Vector2((float)(spritePosition.X) / (float)spritesheetSize.Width,
                                        ((float)(spritePosition.Y) + (float)spritePosition.Height) / (float)spritesheetSize.Height);

            //doing them backwards because the billboarding flips them for some reason
            playerVertices[0] = new CustomVertex(new Vector3(+0.8125f, +1.625f, 0), Vector3.Forward, TLTex, TLTex);
            playerVertices[1] = new CustomVertex(new Vector3(-0.8125f, +1.625f, 0), Vector3.Forward, TRTex, TRTex);
            playerVertices[2] = new CustomVertex(new Vector3(-0.8125f, 0, 0), Vector3.Forward, BRTex, BRTex);
            playerVertices[3] = new CustomVertex(new Vector3(+0.8125f, 0, 0), Vector3.Forward, BLTex, BLTex);
            //playerVertices[0] = new CustomVertex(new Vector3(+0.5f, +1f, 0), Vector3.Forward, TLTex, TLTex);
            //playerVertices[1] = new CustomVertex(new Vector3(-0.5f, +1f, 0), Vector3.Forward, TRTex, TRTex);
            //playerVertices[2] = new CustomVertex(new Vector3(-0.5f, 0, 0), Vector3.Forward, BRTex, BRTex);
            //playerVertices[3] = new CustomVertex(new Vector3(+0.5f, 0, 0), Vector3.Forward, BLTex, BLTex);
            playerIndices[0] = 0;
            playerIndices[1] = 2;
            playerIndices[2] = 3;
            playerIndices[3] = 0;
            playerIndices[4] = 1;
            playerIndices[5] = 2;


            //set effect parameters
            effect.Parameters["World"].SetValue(Matrix.CreateBillboard(playerPosition + new Vector3(0, 0, 0.4375f), cameraPosition, Vector3.Up, null)); //the new vector is to make the player appear at the bottom of the tile
            effect.Parameters["View"].SetValue(view);
            effect.Parameters["Projection"].SetValue(projection);
            graphics.GraphicsDevice.Textures[0] = inPlayer.textureSheet;

            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                graphics.GraphicsDevice.DrawUserIndexedPrimitives <CustomVertex>(PrimitiveType.TriangleList, playerVertices, 0, 4, playerIndices, 0, 2);
            }
        }