Wednesday, June 26, 2019

A New Roguelike Project

Roguelikes really suit my programming style: they can be ASCII based, which makes creating the graphics very easy, and they are usually grid based, so positioning entities and checking for collisions is simple.  This means that I can spend more time actually creating a game rather than writing all that boilerplate collision and graphics code.

I wrote my first roguelike (Astro Commander) several years ago; it was based on what I thought FTL was like, having never actually played that game.  I've now decided to write another roguelike, after deciding that 3D graphics are too much hard work.  Also, I wanted to have another go at creating an even-better ECS system.  And of course, the theme of the game will be a classic Spectrum game: Alien (Mind Games).

In this game, you will control the crew of Nostromo.






Do you know, I always feel I should write about the games I create in order to "get them out there".  However, when I'm excited about a new project, I prefer to spend my time creating it (rather than writing about it and taking screenshots).  Once this excitement has passed and I've completed all the interesting challenges, I'm then too disinterested in the project to bother writing about it, since I'll probably start another project and won't look at this again.
 
If you want to look at the source code, it's here.  It contains a good ECS system, and units can walk around.  But now I've decide the writing a co-op game is my next project, maybe in Unity.

Friday, June 21, 2019

What is an Entity Component System?

Let's assume you've written a game.  Imagine you've split your game logic into several well-defined classes, e.g. a movement class, a collision class, a drawing class.  Let's call them "systems".  Each has a specific and obvious role.  Also imagine that your game has a bunch of "things" that make up the game, such as the player's avatar, power-ups, bullets etc...  Let's call them "entities".

Each entity is basically a collection of data, and depending on what data it has, it can be handled by one or more systems.  For example, if it has "bounding box" data, it can be handled by the Collision System.  If it has image data, it can be handled by the drawing system.

Your game then works by cycling through specific systems that are required to run each game loop, e.g. Player Input System, then the Movement System, then the Drawing System.  Each system then "processes" all the entities that apply to it, e.g. draw all the entities which have image data.  Systems may well call upon other systems as-and-when required.  For example, your Collision System may call upon the Score System if a player's bullet hits a perp.

And that's it! 

The advantage of this is that it's very easy to pinpoint which bit of code is doing something.  If there's a problem with the animation, it will probably be in the Animation System.  If there's a bug with collisions, it will probably be in Collision System.  If you need to implement explisions, create an Explosion System.

Designing a game now becomes a task of defining your systems based on what your game is.  Once you have clearly defined and scoped systems, the rest is easy.

Thursday, June 06, 2019

C# Gotcha - "static readonly" v "const"

On the face of it, there seems very little difference between these, apart from one takes longer to type out.  However, there is one difference that could easily catch you out: you can reference a "static readonly" from pretty much anywhere in your code, but until your code gets to the line where it is declared, it will have the default value (typically zero for numbers).

Time for an example:-

public static readonly int size = width * height;
public static readonly
int width = 100;
public static readonly
int height = 50;

public void Test() {
    Console.WriteLine($"The size is {size}");
}

Yes, this program will output "The size is 0".  Probably not what you wanted.

Thursday, March 28, 2019

Super Spectrum World

If you're like me and a big fan of the ZX Spectrum (especially the games) please take a look at Super Spectrum World, my homage to lots of classic Spectrum games.

I wrote this as a test of the features of LibGDX, and so far it's been great.  If you lament the end of Java applets and were looking for a way to create apps that could be embedded in a web page, look no further.

Currently the game has about ~20 screens, all with graphics taken from various games.  In JSW style, your objective is to collect as many glasses as possible, and keys are O, P and Space.

Have fun!

Wednesday, March 13, 2019

Why does anyone use MS SQL Server?

Everything about MS SQL server seems designed to make it as difficult as possible to do anything.

Want to restore a backup database?  You'd better be restoring to a database of exactly the same version or else you're not allowed.  Even if you're restoring from v10.000.000.1 to v10.000.000.2, that different version number will stop you.  This might make sense if you were restoring to an older version, but you will be blocked even restoring to a later version of the database, which could and should be able to understand an earlier version.

Want to import an SQL file?  You may think that SQL Server Studio would have that sorted (and indeed it does for small files) but if you want to import an SQL file of more than 250Mb, get ready to use the command line.  And if you have any errors in your SQL, don't expect SQLCMD to tell you the correct line number!  And you are bound to get an error; I don't think I've ever managed to directly import an sql file (that was directly exported from MSSQL) without having to manually edit something in it first.

And then there's "named pipes" and "instances" to adde extra layers of complication.  And different versions: LocalDb, SQLExpress, SQLServer, each with their own features and problems.  Some will work with IIS, some won't.  Apparently LocalDb is "a SQL Server Database Engine that developer them write and test Transact-SQL code without having to manage a full server instance of SQL Server."  Why not just run a full server instance, or have MS realise that it's just too cumbersome?  That developers (unlike end-users) have seen through the looking glass and know better than to use it, but are forced to in order to develop for it?

Tuesday, March 05, 2019

LibGDX Setup Problem

LibGDX is a complex technology, which utilizes lots of other complex technologies, so getting a project up-and-running the first time can have a few problems.  Here's a rundown of the problems I experienced, along with solutions. 

This article assumes you are using Eclipse and running the default "blank" project (which shows the LibGDX logo).


Eclipse Error: GWT jar missing:

Do an Eclipse "quick fix"

Eclipse Error: Web.xml missing:

Move the web.xml to \war\web-inf

Running the program, get the error "File not found: badlogic.jpg"

The application will fail the first time. Open the Run Configuration you just created and set the working directory to the android/assets/ directory.
Go to Run => Run Configurations.. => choose DesktopLauncher, Arguments Tab => Working Directory => Others then browse to yourproject-android/assets/ and click Apply
https://stackoverflow.com/questions/22822767/file-not-found-when-running-new-libgdx-project

Eclipse Error: EntryPoint not found

You need to download the Gradle plugin for Eclipse, from http://gwt-plugins.github.io/documentation/gwt-eclipse-plugin/Download.html


Running Gradle, get error "could not reserve space for object heap"

Check you're using 64bit java for Gradle.
If that doesn't work, add the environment variable "_JAVA_OPTIONS" (with the underscore) and set it to something higher, like "-Xms256m -Xmx2500m".


--
Hopefully, once you've got through all those problems, your project should work!

Thursday, January 10, 2019

My Open-Source Projects

I've created a seperate website to showcase all my open source projects.  Take a look at https://my-open-source-code.blogspot.com, and maybe use them to kickstart your own projects.