Jump to content

  • Log In with Google      Sign In   
  • Create Account


FantasyVII

Member Since 13 Jul 2012
Offline Last Active Jun 03 2014 06:21 AM
-----

Topics I've Started

smoth fog of war

28 March 2014 - 03:51 AM

Hello everyone,

 

so for the past few days i have been implementing fog of war mechanics to my game. and i made it work, which is nice. But i did not feel satisfied with the way it looked.

 

So here is my question. how can I have a smother fog of war that looks like this?

 

81b3509eb5db0dcc2875a43f5e9f3989.jpg

 

this is how i implemented. I made a 512x512 map with a 32x32 tile size. i filled the map with a black tile and i set all the cells in my map to unexplored. when a unit moves through the map, I set that cell to explored and I stop rendering the black tile in that particle cell of the map.

 


Waypoint system problem XNA

17 March 2014 - 07:00 AM

Hello everyone,

 

So i have a waypoint system implemented in my game, but I have a problem with it.

 

here is the code

public class WayPoint
    {
        Vector2 Direction;
        public int WayPointIndex;
        double Length;

        public Vector2 GetMovment(List<Vector2> WayPointList, Vector2 CurrentPosition, float Speed)
        {
            // Calculate direction vector
            Direction.X = WayPointList[WayPointIndex].X - CurrentPosition.X;
            Direction.Y = WayPointList[WayPointIndex].Y - CurrentPosition.Y;

            // Normalize direction vector to unit length
            Length = Math.Sqrt(Direction.X * Direction.X + Direction.Y * Direction.Y);
            Direction.X /= (float)Length;
            Direction.Y /= (float)Length;

            // Apply movement vector to move
            CurrentPosition.X += (float)Direction.X * Speed;
            CurrentPosition.Y += (float)Direction.Y * Speed;

            if (Length <= Speed)
            {
                if(WayPointIndex <= WayPointList.Count - 2)
                    WayPointIndex++;
            }

            return CurrentPosition;
        }
    } 
class WayPointTestClass
    {
        GraphicsDeviceManager Graphics;

        StreamTexture streamTexture;
        WayPoint waypoint;

        Texture2D texture;
        Vector2 position = new Vector2(0, 0);
        float speed = 0.5f;

        List<Vector2> waypointList = new List<Vector2>();

        public WayPointTestClass()
        {
            streamTexture = new StreamTexture();
            waypoint = new WayPoint();

            waypointList.Add(new Vector2(64,   128));
            waypointList.Add(new Vector2(64,   1216));
            waypointList.Add(new Vector2(256,  1216));
            waypointList.Add(new Vector2(256,  128));
            waypointList.Add(new Vector2(448,  128));
            waypointList.Add(new Vector2(448,  1216));
            waypointList.Add(new Vector2(640,  1216));
            waypointList.Add(new Vector2(640,  128));
            waypointList.Add(new Vector2(832,  128));
            waypointList.Add(new Vector2(832,  1216));
            waypointList.Add(new Vector2(1024, 1216));
            waypointList.Add(new Vector2(1024, 128));
            waypointList.Add(new Vector2(1216, 128));
            waypointList.Add(new Vector2(1216, 1216));
            waypointList.Add(new Vector2(1344, 1216));
            waypointList.Add(new Vector2(1344, 1024));
            waypointList.Add(new Vector2(1644, 1024));
            waypointList.Add(new Vector2(1644, 1644));
            waypointList.Add(new Vector2(2112, 1644));
        }

        public void Initialize(GraphicsDeviceManager Graphics)
        {
            this.Graphics = Graphics;
        }

        public void LoadContent()
        {
            texture = streamTexture.LoadTextureFromStream(Graphics, @"C:\test.png");
        }

        public void Update()
        {
            position = waypoint.GetMovment(waypointList, position, speed);
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(texture, position, Color.White);
        }
    } 

So what the code does is basically, take the current position of an enemy unit and take how fast its moving and the list of waypoint the enemy unit should go to.

 

so lets say enemy unit is at (0, 0) and the next waypoint is (0, 100), the enemy unit will go to that point with a speed of lets say 0.4f. now the problem is. when i increase the speed of the enemy unit to 0.5 or 1 or 1.5 or 2. the enemy unit disappears and the CurrentPosition will be equal to "NaN" (when i debug my software) and the code will stop at waypoint number 4 for example. (there is 19 way points). However if i set the speed to any other vault that is not (0.5, 1, 1.5, 2, 2.5, 3, 3.5,etc.....) the enemy unti will go through all the way points and reach its final way point. any idea why is this happening?


Shader Model 2.0 runs faster than 3.0 !

12 April 2013 - 06:41 PM

Hello everyone,

 

So I been making a pixel shader lighting system in XNA with SM 3.0. I was getting around 70FPS with 4 lights. However when I changed the SM version in the fx file from 3.0 to 2.0, I got around 120FPS !!! Why?

 

obviously I can't use SM 2.0 because it's very limited with the amount of arithmetic that I can do. But why is it that SM 2.0 faster than 3.0? You would think 3.0 would run much much faster !!

 

Also in SM 3.0 I can have an array size of 15 elements. I can use all 15 lights and I get 70FPS. If i use 1 light I get 70FPS so it doesn't really matter. However when I set the array to 16 elements in the fx file my FPS drops to 10FPS !! even if I only use 1 light. why is that?!

 

struct Light
{
	float2 Position;
	float4 Color;
	float Radius;
	float Intensity;
};

Light lights[15];

 

 


2D Deferred lighting in XNA

11 April 2013 - 05:34 AM

Hello everyone,

 

So I have been trying to learn HLSL and I think I got the hang of it. I found this awesome tutorial that show how to implement deferred lighting. and I think I understand it. However there is just one thing that I would like to know. How can I change the light shape from point light to cone shape like light?

 

1111fs.png

 

 

Here is a video of my implementation of deferred lighting.

 

 

and here is the code

struct Light
{
	float2 position;
	float4 color;
	float power;
};

texture colortexture;

int numberOfLights;
Light lights[4];

float ambient;
float4 ambientColor;

float screenWidth;
float screenHeight;

sampler ColorMap = sampler_state
{
	Texture = <colortexture>;
};

float4 CalculateLight(Light light, float4 base, float3 pixelPosition)
{
	float2 direction = light.position - pixelPosition;
	float distance = 1 / length(light.position - pixelPosition) * light.power;
	float amount = max(dot(base, normalize(distance)), 0);
	
	return base * distance * light.color * ambient;
}

float4 Deferredlight(float2 texCoords : TEXCOORD0) : COLOR
{
	float4 base = tex2D(ColorMap, texCoords);

	float3 pixelPosition = float3(screenWidth * texCoords.x, screenHeight * texCoords.y, 0);
		
	float4 finalColor = (base * ambientColor * ambient);
	for(int i=0; numberOfLights; i++)
	{
		finalColor += CalculateLight(lights[i], base, pixelPosition);
	}
	
	return finalColor;
}

technique Deferred
{
	pass Pass1
	{
		PixelShader = compile ps_2_0 Deferredlight();
	}
}

I want to share my tower defense game with you

13 March 2013 - 07:20 AM

Hello everyone,

 

For the past six months I have been working on a multiplayer 2D tower defense in XNA and C#. And I just thought I would share my work with all of you.

 

If anyone is interested here is my website check it out.

www.vault16software.com

 

I try to post a dev video when I can.

 

 


PARTNERS