Quantcast
Channel: GameDev.net
Viewing all articles
Browse latest Browse all 17560

Isometric Tile Waves

$
0
0

Hi guys!!  

I wanted to make an ocean with Isometric Tiles.

 

I found this JavaScript example here http://codepen.io/arnaudrocca/pen/reNpaP and I tried to port it to XNA/Monogame

 

My wave doesn't look good and I don't know what is wrong.

 

This is my whole code

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.IO;

namespace IsometricWaveDemo
{
    /// <summary>
    /// This is the main type for your game.
    /// </summary>
    public class Game1 : Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;

        Texture2D tileTex;
        float min = 1.25f;
        int mapSize = 12;
	    int width = 50;
	    int height = 25;
	    int speed = 5;
	    int strength = 2;
	    char direction = 'x';

        float timer = 0;
        float deltaTime = 0;
        float lastTime = 0;

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
            graphics.PreferredBackBufferHeight = 900;
            graphics.PreferredBackBufferWidth = 1600;
        }

        protected override void Initialize()
        {
            base.Initialize();
        }

        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);
            FileStream fs = new FileStream("Content\\water4.png", FileMode.Open);
            tileTex = Texture2D.FromStream(GraphicsDevice,fs);
            fs.Close();
        }

        protected override void Update(GameTime gameTime)
        { 

            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Black);

            spriteBatch.Begin();

            deltaTime = (float)gameTime.TotalGameTime.TotalMilliseconds - lastTime;
            lastTime = (float)gameTime.TotalGameTime.TotalMilliseconds;
            timer += speed * deltaTime / 1000;
            for (int x = 0; x < mapSize; x++)
            {
                for(int y= 0; y < mapSize; y++)
                {

                    float z = 0;
                    if (direction == 'x')
                    {
                        z = (float)(min + Math.Sin(timer + Math.Sin((y - x) * strength / 10)));
                    }
                    else
                    {
                        z = (float)(min + Math.Cos(timer + Math.Cos((x + y) * strength / 10)));
                    }
                    spriteBatch.Draw(tileTex, new Rectangle(400 + (x - y) * width / 2, 200 + (int)((x + y - z) * height  / 2), width, height), Color.White);
                }
            }

            spriteBatch.End();
            base.Draw(gameTime);
        }
    }
}

I attached the tile which I used. Can someone help me?

 

 

Attached Thumbnails

  • water4.png

Viewing all articles
Browse latest Browse all 17560

Trending Articles