Wednesday, December 28, 2011

A Fresh Start

Hello everyone! My sincerest apologies for being away for so long. I must admit that I had become burnt out at  making games and wasn't spending enough time actually playing games. But now I am back and ready to get started on what I'm sure every aspiring game developer has thought of making at some point in their programming career, a classic RPG. My favorite types of rpgs are the 2D ones from the days of the Super Nintendo and the old 486 computers that some of you may not even remember. I am therefore going to shift gears with my blog to work on a classic 2D rpg in the style of FF2. I'm going to be taking you along for the ride and showing you and explaining to you what I'll be doing at each iteration of the game, much like I did with Prospectus. I'll be making this game using C#, Xna Game Studio, and Microsoft Visual Studio. I feel that Xna is a great way to take out many of the annoyances that come with trying to design the perfect game loop, or construct the best structure of a game, or ensure that the game updates and draws everything it is supposed to. This will allow me to focus more on the meat and potatoes of the game and leave the rest up to Xna.

I appreciate everyone who follows along with this blog and I again apologize for being away for so long. Here's to a successful venture into the world of rpgs!

Tuesday, August 16, 2011

How to Setup JDeveloper with Slick2D

I know we have all struggled with something like this at one point in our coding and usually the first thing I will do is head to Google to find out if anyone else has had the same problem and figured out how to fix it. This post is an explanation on how to setup a game project in JDeveloper 11G to work with the Slick2D library for your games. I have spent many hours working on this in order to make sure how it works and so that I'll be able to explain it better. Please feel free to comment or email me with questions if this is confusing and you need further help setting up your game.

In this post I will assume that you are starting off from the beginning and don't even have the JDK downloaded. 

Firstly, head over to the downloads section on the JDeveloper website and download the version of the Java Development Kit (JDK) that you wish to use. Note that JDeveloper and Slick2D work better with 32 bit versions of the JDK. I downloaded the 32 bit version of JDK 1.6.0_26 even though I have a 64 bit computer (below)



Secondly, after the JDK has downloaded, click on the .exe file (the one you downloaded) and allow it to install the JDK onto your computer. The default settings are what you want for this install, so feel free to click Next until it installs.

After the JDK finishes installing (Default location is C:\Program Files (x86)\Java), return to the JDeveloper site and download JDeveloper. The "Generic Release Java Edition" is all that is necessary unless you plan on developing enterprise websites with elaborate databases on the side (below). Note that Oracle will require you to create a FREE account in order to download JDeveloper.

After you have downloaded the .zip file from Oracle, extract it to a place on your computer (C:\oracle, for example). It is recommended you place all of the files in a location that does not contain any spaces in the path (for example "C:\oracle", not "C:\my oracle"). The next thing I recommend doing is opening the folder where you just extracted all of the contents from the .zip file to and right click on the "jdeveloper.exe" file to create either a desktop shortcut or a taskbar shortcut, as this will be a much faster way to open JDeveloper than navigating to the directory and clicking the .exe every time. 

Next, open up JDeveloper by either clicking on the jdeveloper.exe file or by clicking on the shortcut you just created. Note that JDeveloper will open a window asking you to enter the path to the JDK folder you downloaded earlier. If you installed the JDK to the default location you need to enter (or browse to) C:\Program Files (x86)\Java\jdk1.6.0_26\bin\java.exe and click OK. After this, JDeveloper may pop open a window that asks you if you want to migrate settings from a previous version of JDeveloper to this one, in which case you should click NO (because there is no other version of JDeveloper on your computer). After this, JDeveloper should open up to the start page not present any other message windows (aside from the "Tip of the day" window).

Now, let's create our first application and project. Click File > New > General > Application and enter the name of the application (SlickTest will work just fine) and click Next, then fill in the project name (project1 will do) and then click Finish. 


Next, right click on your project in the Application Navigator and click New

This will open the same window that opened when you created your application. This time, however, we are going to choose Java Class

Click OK and you will be prompted to fill in some basic info for the class (Name, package, etc.)

I recommend matching it to what I have shown above. Click OK and your new class will open in the main window of JDeveloper.

Now let's take a break from JDeveloper and head over to the Slick2D website to download the library. On the right hand side of the main page, click on the link that says "Download Full Distribution" to get a zip file that will have everything we need in order to run our Slick games. Next, I recommend navigating to your project's folder and creating a \bin, and a \lib folder for our Slick2D library items. Optionally, you can create a \content folder for all of your game's assets (images, music, fonts, etc.).

These folders will be referenced from inside JDeveloper (our project's properties, specifically) later on. Next, extract the files from the Slick2D download to a temporary place (Desktop works just fine). Once that is done, create a folder inside of the lib folder in your project and call it Slick2D (\lib\Slick2D). Place everything except for the .dll files from the download into this new folder. Now take the .dll files (four of them, to be precise) and place them inside the bin folder in your project. This is a fairly standard way of packaging your game with the library files it will need in order to be distributed to other people (and work properly).

Now, go into JDeveloper and right click your project's name and select Project Properties. This is where we will setup the Slick library in our project. Click on the Libraries and Classpath node and on the right sight of the window click on Add Library. We will then select New because JDeveloper has no idea about our Slick Library (we haven't created it yet). Now fill out the information as I have it below

It is important that you include all of the .jar files except for slick.jar from the \lib folder. Now click OK and you will return to the libraries screen where you will select Slick2D and click OK. Now you should be back at the Project Properties window and your new Slick2D library will be included in your project. Now click Add Jar/Directory and navigate back to the \lib folder and add slick.jar.

Now you are nearly done with setting up the Project Properties. From the Project Properties window, click on the + sign next to Project Source Paths and click on the Resources node. Click Add and add the \content folder you created earlier. This will allow you to begin your resources' filenames from the content folder (instead of the project folder).

Next click on the Run/Debug/Profile node and click Edit. Under the Java Options text box, add this:

-Djava.library.path=bin

This will tell JDeveloper to look in the bin folder of your project for the .dll files we put there earlier.

Now click OK until you have closed the Project Properties. Now to test your setup and create a basic Hello World game you will need to modify the Game.java file. To keep it simple, modify your Game.java class so that it looks just like this:
import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;

public class Game extends BasicGame {

    Image background;

    public Game(String title) {
        super(title);
    }

    public void init(GameContainer container) throws SlickException {
        background = new Image("helloWorld.png");
    }

    public void update(GameContainer container, int delta) 
        throws SlickException {
    }

    public void render(GameContainer container, Graphics g) 
        throws SlickException {
        background.draw();
    }

    public static void main(String[] args) throws SlickException {
        AppGameContainer app = new AppGameContainer(new Game("Game Test"));
        app.setDisplayMode(640, 480, false);
        app.setTargetFrameRate(60);
        app.start();
    }
}

One last thing to do is create a Hello World image like this one:

and place it in the \content folder in your project.

Now click the Run button (Big Green Arrow) and with any luck, your game will start up in no time! I really hope you have learned something from this post and are able to use Slick2D in JDeveloper. Please feel free to comment or email me with any questions you may have.

Wednesday, August 10, 2011

Basic Menu System Using Slick2D

Hello everyone, just wanted to write a quick post to let you all know that I'm still working hard on Prospectus and I haven't given up on it yet. I've been having a bit of trouble finishing the port of the current version of the game over to Java, so I decided to set it aside for a few days and focus on something else that will keep me encouraged about Prospectus.

With this in mind, I've quickly put together a very simple main menu system which makes excellent use of the Slick2D java library. It is so well put together that I was able to get a basic menu system up and running in a matter of 5 minutes!

The general idea is that your game extends a class called StateBasedGame, thus allowing you to be able to make use of different states easily and effectively. Once you have created this basic game structure, the idea is that you create different classes that extend BasicGameState to represent your different states (MainMenu, Gameplay, PauseScreen, etc.).

The awesome thing about extending BasicGameState is that you are forced to implement three abstract methods. These methods are very similar to methods found in almost every XNA game created today (init, render, update). This allows us access to a familiar game loop that we, as XNA programmers, are comfortable with. This also allows us to use a global input manager that is maintained by our generic gameContainer (created by the StateBasedGame class). From here we can display our menu image, and check for user input, telling us either to enter the game, exit the game, or do whatever we tell it to do.

This is just a quick and easy example of how Slick2D is helping us develop and grow Prospectus into a great game. Here is a short video of the menu test in action.



Thanks for reading and check back for more updates!

Friday, August 5, 2011

Java 2D TileMap Code Optimization

Hey guys, just thought I would give you guys a quick tip on 2D tile map optimization that's been helping me in this transition from Xna to Java. Normally what I do in this kind of a game is have a 2D array of tiles (Tile class) which make up the contents of the map. I then set each tile to be the appropriate kind of tile (i.e. dirt, grass, rock, etc).

With this new Java version of Prospectus though, I thought I could do a little better than that, so I set off to find a different way to get the same result. I came up with the idea of using a 2D array of characters instead of tiles. I then use that character map to decide what tile I need to draw in my draw method, as I need it. I then use a few different methods that allow me to retrieve the correct type of tile to draw/do calculations with for a specific x and y coordinate on the map, solely based on what character is that the x and y coordinate.

This, I believe, saves me time and speeds up the execution of my code. Instead of having to keep each tile on the entire map in memory, now I only care about the tiles that are on the screen (plus a couple rows and columns for cleanliness). This also helps with start-up time because I'm setting character literals instead of user-defined class instances.

I hope this has given some of you ideas on how to improve your own games in Java or C#/Xna (this method will work for either language). As I near completion of the port to Java, I'm getting more and more excited about where Prospectus can and will go in the future. Thanks for reading and be sure to check back soon for more updates.

-Cheers

Thursday, July 28, 2011

Extreme Makeover: Prospectus Edition

Hey guys I am very excited to bring you more news about Prospectus. I'm sorry it's been so long since my last post, but I have been busy making some changes that I hope will benefit more people down the road. Over the past few weeks I have been struggling with developing Prospectus only for .Net capable machines. I feel like I would be able to reach more people with Prospectus if I was not tied down to .Net machines. I have therefore decided to migrate the existing version of Prospectus (as well as continue on from here) to the Java language using Netbeans and the Slick2D Library.

It is my intention that more people will be able to play this game because I'm making it more platform-independent than before. I hope this does not upset too many people who were using this as an Xna-specific learning tool. I will do my best to make any code-related posts as generic as possible in order to continue to be useful and informative for the Xna community.

As always I want to thank everyone who reads this blog as it is a huge motivational tool for me to keep working on Prospectus. I will be bringing you new posts as soon as I finish porting the existing version of the game to Java, but in the meantime I hope you take the time to try out Prospectus for yourself and don't lose faith in me...I'm going to keep building this game into something great.

Until next time!

Monday, July 18, 2011

Thoughts on the Future of Prospectus

Hey guys it's been a few days now since I released the first Alpha of Prospectus and I must say 'Thank You'. I've seen a great response from you, the community, toward my game and I'm very excited about the future of this game. I've been working hard on adding in new features to the game to make it feel more like a game than just a blank sandbox world and I will be posting on here my updates as I make them.

I am also working very hard to come up with an effective way to make the newer versions of Prospectus automatically download and update your installed version, without requiring you to manually install them each time. I really appreciate everyone who has visited the Prospectus website and I would love to hear any feedback you may have at prospectus.game@gmail.com.

Until next time...

Friday, July 15, 2011

Prospectus Alpha 1.0 Is Here

Hello everyone, I am pleased to announce that I have chosen to name my game Prospectus, as it was the most popular in the poll. I appreciate everyone who voted in the poll and am excited about uploading Prospectus for you to download and play!

I have been hard at work creating a basic website for Prospectus for you to get your free copy of the Alpha 1.0 version. It's been a long time coming that I would distribute a game online and I am very excited to get feedback from the community about Prospectus. I have set up an email address as well that I would like you to direct any comments, feedback, bugs, issues, etc. of any kind to so that I can better organize my Prospectus-related traffic.

Again, I really appreciate everyone who reads this blog and look forward to hearing what you think about Prospectus. Please understand that right now, there is only basic mining and inventory in the game and it is very similar to early versions of Terraria and Minecraft, but rest assured I will be adding unique gameplay features very soon.

There will be detailed instructions on how to install Prospectus on the web site, along with a Read Me text file to assist with installation, basic gameplay, and controls.

You can find Prospectus here and feel free to contact me with any comments and feedback here. Thanks again everyone and have fun!

Sunday, July 10, 2011

Boring Work Before First Build

Hey guys, I know it's been a couple of days since my last post and I wanted to say that I'm still here and still working on the game, though I'm now in the boring part of cleaning up the code that I have before I make this first version ready for download.

I would like to apologize because I do not like to go this long between posts. I'm making minor tweaks to the code that will hopefully make it less buggy when it's ready for download. I'm getting very excited to see what everyone thinks about it up to this point. I would like to say to everyone who intends on downloading it to keep in mind that at this point it is basically a straight clone of Terraria. My plan is to make this game more of a Zelda-style game than a Terraria/Minecraft-style game before I'm done with it.

What do I mean by Zelda-style? I mean more intricate dungeons with bosses in the dungeons, different levels (as opposed to biomes), more NPC interaction with special items awarded (similar to Zelda games), and many more features to come! I hope that everyone appreciates this game and I would ask that anyone who decides to download it and has any type of comment (positive or negative) about it to let me know in a comment or in an email (I'll have an email address set up just for this game by Friday).

Thank you to everyone who follows this blog and game!

Tuesday, July 5, 2011

Alpha 1.0 Preview

Hey guys I'm just giving you a quick update about the latest addition to the game...updated, custom sprites for the player! I am very excited about this latest addition, mostly because I am not really an artist, just ask my wife :)

I'm getting even more excited about launch day, which I am glad to announce will be this next Friday, July 15. I will be uploading the first build of the game, mostly bug-free probably after I get back from the midnight showing of Harry Potter.

I will leave you now with a preview of my player:

And don't forget to vote for what the name of the game should be.

Monday, July 4, 2011

Player Animation Is Here

Hey guys it's been a few days since my last post, but I've been busy adding in one of the last things before my very first release of my game, player animation! I've been busy getting the game ready for it's first release and am pleased to announce that I now have a player in the game instead of just a rectangle.

I will say here that the sprite that I currently have in the game is just a dummy sprite I made for an rpg I was making and will definitely not be the final version of what the player will look like. I'm also including a poll on the blog for some names for the game to see what the popular choice will be for a name.

As for what I did to include player animation, I used a modified version of Nick Gravelyn's AnimatedSprite class and FrameAnimation class in his Tile Engine series for my game. I will likely have to modify those classes even further as the game progresses, but for now it works and that's good enough for me.

The features that you have to look forward to in the first build are,

  1. Basic mining and placing of blocks
  2. Basic inventory that shows the blocks the player has mined (scrollable)
  3. Random map and terrain generation with basic caves
  4. Player sprite with walking animations
  5. Dirt and Rock blocks



I would like to say 'Thank You' to everyone who reads this blog and I hope that you find my game entertaining. I am very excited about where this game can go in the future and look forward to hearing what you guys think of it as well.

Thanks again,
Jeff

Friday, July 1, 2011

Revamping the Terrain and Caves

Hey guys I've been busy reworking the terrain and cave generation code to give smoother and less rigid results. I've also cleaned up the HUD to show less things and not clutter up the screen as much. Enjoy!

Monday, June 27, 2011

Game Demos on YouTube

Hey guys I figured it was about time I upgraded my presentation quality with this game and starting recording some actual "gameplay" for you to see. So without further ado, here is the first in-game video for my Adventure Resource game:



I apologize for the low framerate, I'm still getting use to this new video capture program. I assure you the game runs plenty fast.

Friday, June 24, 2011

Updated Mining Technique

Hey guys it's been awhile since my last post but rest assured I've been working on my game and I do have a cool update to share with you. I now have a much better mining technique implemented where I'm actually using an item with statistics that affect the mining efficiency.

As of now, my first item in the game is a basic wooden pick that can mine blocks at a slow speed with poor mining strength. This makes it take longer to mine certain blocks compared to other blocks. I'm very excited about this new addition because it brings me one step closer to having a working inventory system in my game.

Please check back and thanks for reading about my adventures in making this game.

As always I won't leave you without an in-game screen shot.

Saturday, June 18, 2011

How to add a Basic Inventory

Hey guys it's been a great week here, I have a couple of new things added to my game and I thought I would share them with you. I admit that I have been spending a lot of time this week playing Terraria but I was still able to get some good progress made on my game. The two things I have added this update are

  1. A basic way to add different blocks into the game (still has a long way to go before I'll call it good)
  2. Very basic player inventory showing the block last mined (which I'm going to explain with code in this post)
Now I'm sure a lot of you have read, or been told, or know just from personal experience that when implementing something new into a game, or any software really, it's usually a great idea to create the most basic form of whatever it is you are trying to create. This way there is something to build on and improve on, as opposed to it remaining just an idea inside of your head.

The player inventory is a perfect example of this (in my mind). Instead of trying to create an elaborate inventory system from the start (since I have never made one before), I decided to simplify it and make my inventory (for now) consist of one block (the last block that the player 'mined'). This way I don't have to worry (yet) about managing a list of different items (which I don't even have in the game yet). The way that I do this is simply to add a:
 public Block Inventory;  
In my Player class. This allows me to add other lines whenever I click the left mouse button or right mouse button that (for example) look like this:
 Inventory = TileLayer.blocksDictionary[TileLayer.GetBlock(mouseCell.X, mouseCell.Y).Name + "SingleTop"];  
For the case of left mouse click (which adds the block the player clicked on to the inventory). When the player clicks the right mouse button, I simply have pass the block in the player's inventory to the method that I use to place a block:
 TileLayer.PlaceBlock(mouseCell.X,  
                  mouseCell.Y,  
                  Inventory);  
This very simplistic version of a player inventory is my starting place to expand upon later and add more functionality to it.

And that's the basics of adding in a player inventory. The only trick left to do is display it on the screen (which I do in the Game1.cs file). Basically, I added an itemBackground Texture2D variable with a rounded transparent rectangle as the item background texture. After that I simply told the spriteBatch to draw the item Background and the player's inventory's texture at the top right corner of the screen, thereby displaying a pretty cool new feature in the game. Here's some of the drawing code for a reference:
 spriteBatch.Draw(  
         itemBkgd,  
         hudLocation + new Vector2(titleSafeArea.Width - 42, 10.0f),  
         new Color(48, 48, 48, 100));  
 if (tileLayer.Player.Inventory != null) {  
    spriteBatch.Draw(  
           tileLayer.Player.Inventory.Texture,  
           hudLocation + new Vector2(titleSafeArea.Width - 42 + 16, 26.0f),  
           tileLayer.Player.Inventory.SourceRectangle,  
           Color.White,  
           0.0f,  
           new Vector2(8, 8),  
           1.0f,  
           SpriteEffects.None,  
           0.0f);  
 }  
I hope this has helped you understand that you don't have to have the biggest and best anything when you are first developing it. For most things, it's better to start off with the very basics and add to it as you go along. This helps keep you motivated as well as encouraged to put more things into your game.

And just in case you thought I wasn't going to show the "finished" product:


Check back soon for more updates to my game. On a side note, if you have an idea for a name for this game, leave me a comment because I think it's about time I started calling it something other than 'my game'. Thanks everyone!

Wednesday, June 15, 2011

Terrain Generation Explained

Hey guys I have been putting off writing this kind of a post for awhile (mostly because I didn't feel that my code was 'good enough' to show off), but I've had a request and so I will try and explain my method for terrain generation using a mixture of different techniques.

Let me start by saying that my way is definitely not the only way, or even the best way to create terrain; it just happens to work for me (for now). At first, what I tried to use was the Midpoint Displacement Algorithm for creating a rough sketch of ground-level blocks. This method was ok for the time, but I needed something else that gave me a more 'natural' look. This led me to the Perlin Noise algorithm, which turned out to be fairly easy for me to understand from reading a few good explanations of it. Before I put the code into my game, I also looked at techniques for cave generation, which was even easier for me to understand than the Perlin Noise.

For this reason, I decided to integrate the cave generation first as it was the easier of the two. My method for cave generation involves the classic 4-5 rule which states that a block is a wall if the 3x3 region centered on it contains at least 5 walls. Repeating this process n times gives decent looking caves in the map. The entire process is modified slightly in the last two iterations to further refine the shape of the caves and make them appear more 'natural'. Here is some code for example:

 private void CreateCaves(int i) { // i == Number of iterations  
      if (i == 1) {          
         for (int y = Height / 10; y < Height; y++) {            
           for (int x = 0; x < Width; x++) {  
             // Percentage needs to be 60% to make 40% filled  
             // NOTES 06/10: Perlin Noise method functional and not bad,  
             // "Poking holes" cave creation method pretty good.  
             // NOTES 06/14: Making the percentage 55% / 45% is pretty good  
             // with the addition of possibly skipping over the block if the   
             // depth is too little  
             if (rand.Next(100) <= 55) {  
               // PUTTING HOLES IN COMPLETELY FILLED MAP  
               // AS OPPOSED TO PUTTING BLOCKS IN EMPTY MAP  
               blocks[x, y] = LoadBlock('.', x, y);  
             }  
             else if (y < Height / 7)  
               continue;  
           }  
         }  
       }  
       else {  
         int neighboringWalls = 0;  
         string blockName = "";  
         for (int y = Height / 10; y < Height - 1; y++) {  
           for (int x = 1; x < Width - 1; x++) {  
             if (blocks[x - 1, y - 1].Texture != null) {  
               blockName = blocks[x - 1, y - 1].Name;  
               neighboringWalls++;  
             }  
             /////// Some block tests removed to shorten code \\\\\\\\\  
             if (blocks[x - 1, y].Texture != null) {  
               blockName = blocks[x - 1, y].Name;  
               neighboringWalls++;  
             }  
             if (i >= 4) {  
               if (neighboringWalls >= 6)  
                 blocks[x, y] = blocksDictionary[blockName + "SingleTop"];  
             }  
             else {  
               if (neighboringWalls >= 5)  
                 blocks[x, y] = blocksDictionary[blockName + "SingleTop"];  
               else if (neighboringWalls <= 2)  
                 blocks[x, y] = LoadBlock('.', x, y);  
             }  
             neighboringWalls = 0;  
           }  
         }  
       }  
     }  

The main difference between my code and the algorithm in the link I provided is that instead of filling in an empty map, I'm poking holes in a completely filled in map. This in my opinion gives different and better results for me.

After I added the cave generation to the game, I felt confident enough to tackle the Perlin Noise algorithm. Using the method provided in the link I gave above, I produced this code to create my surface terrain:

 private int[] CreatePerlinNoise() {  
       float[] values = new float[Width];  
       int[] realValues = new int[Width];  
       for (int i = 0; i < values.Length; i++) {  
         values[i] = PerlinNoise(i);  
         values[i] *= 10;  
         realValues[i] = (int)Math.Ceiling(values[i]);  
       }  
       return realValues;  
     }  
 private float Noise(int i, int x) {  
     if (i == 0) {  
       x = (x << 13) ^ x;  
       return (float)(1.0 - ((x * (x * x * 557 + 1049) + 2411) & 0x7fffffff) / 1073741824.0);  
     }  
     else if (i == 1) {  
       x = (x << 13) ^ x;  
       return (float)(1.0 - ((x * (x * x * 1303 + 2473) + 3229) & 0x7fffffff) / 1073741824.0);  
     }  
     else if (i == 2) {  
       x = (x << 13) ^ x;  
       return (float)(1.0 - ((x * (x * x * 4441 + 6277) + 7549) & 0x7fffffff) / 1073741824.0);  
     }  
     else {  
       x = (x << 13) ^ x;  
       return (float)(1.0 - ((x * (x * x * 4663 + 6007) + 6961) & 0x7fffffff) / 1073741824.0);  
     }  
 }  
 private float SmoothedNoise(int i, float x) {  
     return Noise(i, (int)x) / 2 + Noise(i, (int)x - 1) / 4 + Noise(i, (int)x + 1) / 4;  
 }  
 private float InterpolatedNoise(int i, float x) {  
     int y = (int)x;  
     float fractionalX = x - y;  
     float v1 = SmoothedNoise(i, y);  
     float v2 = SmoothedNoise(i, y + 1);  
     return MathHelper.Lerp(v1, v2, fractionalX);  
 }  
 private float PerlinNoise(float x) {  
     float total = 0;  
     float p = 0.5f; // persistance  
     int n = 4; // four octaves  
     for (int i = 0; i <= n; i++) {  
       float frequency = 2 ^ i;  
       float amplitude = (float)Math.Pow(p, i);  
       total += InterpolatedNoise(i, x * frequency) * amplitude;  
     }  
     return total;  
 }  

A high-level explanation of what happens in a Perlin Noise algorithm (as I understand it) is that the final product is an array of y values (for height) that is the size of all the x values in the map. To get these values, we basically generate random numbers for every x value in the array and linearly interpolate between them to 'smooth out' the shape of the terrain. The link I provided above was, for me, the best explanation I could find about how to make a Perlin Noise algorithm.

I am by no means the expert on Perlin Noise but if you have any questions please feel free to leave a comment below. This is a very basic overview of my technique for creating terrain and it is by no means the only way or the best way. Also, I intend to modify this technique before my game is complete, so feel free to use my code in your own projects, although it may not work with your specific game.

As always, thanks for reading and I will give a game update as soon as I have one.

Sunday, June 12, 2011

New Block Type

Hello everyone, I have a game update to share with you. As of tonight, I have a rudimentary way of random inserting a new block type into the game world. Right now, I'm only using dirt and coal (new) blocks. I'm pretty excited about this newest addition to the game, as it will allow me to begin work on other things such as the player's inventory.

My method for putting coal blocks in the game is pretty simple at this point. First, I loop through all the blocks in the map, looking for the first non-null blocks (meaning that this block is theoretically the ground level for this particular column). I then loop through the current column and have a set of 'if-then-else' conditions that check if the column block in question is at a certain depth. Based on the depth there is a chance that the block will be a coal type, otherwise it is a dirt type.

I'm sure there are many other more sophisticated ways to randomly put different block types into the map, but for now this method will do just fine for me. I appreciate everyone who is following this game's progress and I will continue to provide updates as I make changes and improvements to the game.

Saturday, June 11, 2011

Caves caves caves!

Hello everyone I am very tired but I thought I should write an update of my game. I have been working feverishly on cave generation using a form of Cellular Automata and so far I have had decent results. I am still tweaking the algorithm to give more natural "cave-like" structures that connect to each other better, but for now I am pleased with my cave making skills.

I am also still working on using Perlin Noise to generate the shape of the terrain at the surface level, though this cave generation turned out to be easier (which is why I worked on it first). I am really excited with how this game is coming together and I believe a name needs to be created for this game (hopefully name chosen soon!).

I really appreciate everyone who reads this development blog and I try to provide updates as frequently as I can. Thanks for reading and check back soon for more news!

Thursday, June 9, 2011

Dynamic Block Texturing Is Up

Great success! After too many days of struggling with the code to get the blocks updating their textures based on what blocks are neighboring around them, I finally have a working build that looks really good. The main trouble I was originally having was that I was trying to test for too many cases, which overcomplicated the entire thing.

What I first tried to do was test a block's eight neighbors to determine which texture should be used for that block. This was over-complicating the process; not only did I have to have the six textures for the simple left, right, top, bottom scenarios, but I also had to have textures for all of the possible corner cases. This left me very frustrated and in need of something else to do.

The solution to my problem was very easy in fact. What I did was shrink the block size from 32 x 32 to 16 x 16 and dropped the corner cases / corner textures. Please note that when I say corner textures I'm referring to a piece that has a corner cutout of it. I also created new textures for the blocks with edges that seemingly run together. This makes the cases in which there is an L-shape still look good in the corner spot because the top and right textures almost run together.

Other things that I did include changing the resolution to classic 800 x 600, changing the player sprite from a square to a thinner, taller rectangle (to more closely resemble the final sprite's size), and am running an UpdateBlock() method every time the player removes and adds a block (which updates the surrounding blocks' textures based on which action the player made).

The game is coming along nicely in my opinion. Next things on the list include better terrain generation, more types of blocks, player inventory, and many more things that I don't want to list for fear of getting overwhelmed by it all.

For now, please enjoy a screenshot of my small (but big to me) victory.

Monday, June 6, 2011

Update on Terrain Generation

Hey guys, it's been a busy last few days. This weekend was fairly productive and even a little frustrating at times. However, after much digging on the internet and reading up on terrain generation techniques, I have decided (at least for now) to use a modified version of the Midpoint Displacement algorithm for my terrain generation.

So far, this seems to be working moderately well. The overall shape of the terrain (top layer, of course) is fairly randomized but not too chaotic. The issue I have yet to work out is my technique for putting the correct block (i.e. with the correct texture) with the correct sides, cutouts, corners, etc.

I have spent a fair amount of time tweaking my brute force if then else statements to handle the different cases, but am having difficulty when I get more than just a few cases to try. Anyway, here is a screen shot of my latest build in all it's glory.
Though I am having trouble at the moment, I am enlisting the help of the wonderful people on the Xna forums so I should except to have a better strategy for my blocks in the near future.

In the meantime, I will be working on either the player's inventory (which at this point would only include blocks he has 'mined') or fixing the map saving/loading which has no doubt suffered because of my new terrain generation procedures.

Check back often for updates!

Sunday, June 5, 2011

Terrain Generation using Midpoint Displacement

Well it's been a productive couple of days since my last post. I've been busy working on implementing a better random terrain generator for my game using some tiles that I made myself using Paint.net. I must say that I have never been a strong algorithmic programmer, but I have been reading up on the subject and from what I have found, an easier way to implement random terrain is to use the Midpoint Displacement Algorithm.

This algorithm repeatedly uses two points in space and places a midpoint between them. Then, one point on either side of the midpoint is created at a random height (or displacement) from the midpoint. This algorithm recursively calls itself and continues to create a rough terrain shape. The more times this is done, the smoother the effect.

I'm definitely not the expert on this subject, so if you would like to read more about it check out this post. In the meantime, here is a sample the results of my terrain generation code. Note that there is still much work to be done to clean it up and improve it. This is definitely the first time I've done this.

That's all for now...

Thursday, June 2, 2011

Mouse input is now a reality

I'm happy to say that last night's dev session resulted in the game now having a decent mouse input handler in which the player can remove blocks and place blocks in the map. For now, the player can only place 'ground' blocks because I don't have any inventory system in place (yet) for the player.

I have also started making simple artwork for the different types of blocks found in the game. This is a very exciting game for me to make because I feel like I'm making great progress on it and these little successful additions really make the development process more fun and rewarding. This also gives me motivation to continue my efforts in making this game.

Also, I'm going to need a title for the game (maybe not right now, but soon). I don't want to keep calling it 'the game' or 'my Minecraft clone'. So if you have a suggestion for a name that would go along the lines of a 2D Resource gathering Rpg, please leave it in the comments :)

I'm really looking forward to the weekend because I'm going to work on changing over from the simple red and green tiles to some actual artwork. This is more of a challenge than it might seem because I will need to change my current map generation system. Basically, I will need to take it from a purely random generation to a more structured generation system that looks at the blocks next to the one it is currently generating in order to decide which block to place.

Check back and see how I do.

Wednesday, June 1, 2011

A New 2D Resource Game

Over the past few days I have begun creating a new XNA game that I am quite excited about. This game is a resource gathering game with rpg elements. I have found a new love for Minecraft and have discovered how much fun 2D resource games like Terraria can be. Truth be told, the fact that Terraria is written in C# using XNA Game Studio gave me new inspiration and motivation to create my own game.

The problem I usually face when creating a game is finding the motivation to finish it. It's true, I've only finished one game really (a space shmup) and have dozens of unfinished games lying around. I am determined to make sure this new game will be different though and I'm using this blog to help me accomplish that.

The basic premise of the game is to survive by gathering resources and building things (i.e. crafting weapons, constructing buildings, etc.) while monsters try and attack you. Later on there will be a day/night cycle and monsters will only come out at night, but that's for later. As for now I will focus on building the game in small increments. This will allow me to focus on the pieces of the puzzle as opposed to looking at the whole (and incomplete) picture itself, thereby keeping me more focused on the features in the game. One element of the game that will make it different from other games like Minecraft and Terraria is that the player will have skills that they must level-up in order to (for example) craft better tools, cook better food, make better potions, gather rarer resources, etc.

So far the things I have in the game are:
  • Random world generation
  • Platformer-style physics (modeled after the Platformer Starter Kit on the XNA site)
  • 2D camera that follows the player and does not allow him to leave the map (modeled after Nick Gravelyn's camera in his Tile Engine Tutorial)
  • Map saving and loading with the player's position saved as well (modeled after Nick Gravelyn's saving/loading in his Tile Engine Tutorial)
Other things that I will implement may include:
  • Items, gatherable and creatable
  • Enemies with basic AI
  • Block gathering / placing
  • Basic inventory
  • Menus
  • Crafting
  • And more...
Like I said before, I am only focusing on one or two features at a time to keep my spirits up and my mind focused...

Please check back for updates about the game and feel free to offer any comments about my game. Oh, and here is a screeny for your viewing pleasure.

Update 1.0 "Where have I been?"

Well after a long time I finally have something to write about. I apologize for being away for so long but I have been very busy with real life, family, and work. The truth is, I'm not especially skilled at blogging (although I nearly have a Bachelor's in English with a writing concentration) and, consequently, I find it very easy to neglect this blog.

I would like to say 'Thank You' to the people who have read the meager posts I have created up to this point. I would also like to say that I am working on a new XNA game that will give me much more to write about (hopefully) and should be a fun experience.

I plan on treating this blog as a quazi-journal of sorts for the development of this game. For me, this has a couple of benefits. First, it will help me keep track of the game's progress as I create it. Second, it will help me order my thoughts and ideas about the game in a somewhat structured manner. My hope is that this development journal will also be at least mildly interesting for the people who read it. At this point I intend to only add in things that I want to, things that I think would make the game more fun...but I will divulge more in the next post.

Thanks for everyone who reads this.
Jeff