Thursday, 17 November 2011

Graphics revisited

It's been 6 months since I last tried programming. I quickly got the hang of the basics and made a few text-based games. But I only skimmed over graphics, which is where I need to be headed if I want to make an Xbox indie game.


It's been a while since I last used XNA so I don't know which template to use. XNA Game Studio 4.0 - Windows Game 4.0 seems like it might be right, so let's choose that.

Now I need to get some graphics in there. An image of anything will do. The last time I tried this, it required copy and pasting lots of code, just to get a picture of Gargamel to appear on the screen.

Let's try the tutorial I used before.



Ok, so I have my screen setup nicely. I just have to go through the tutorial and make something appear on the screen. Let's time how long it takes me - the time now is 7:33pm.

Well it's 7.58 now and I haven't yet been able to display a simple image. I came across 2 main problems. I had an error regarding the inability of my graphics card to display the game - something I have experienced before, and have a solution for. What I didn't expect was having to reopen the solution for my change to take effect. Then I found that Visual Studio doesn't like gif images for some reason, but not before spending 10 minutes figuring out why my gif image was producing an error message even though it wasn't even referenced in the code.

My current situation is I can actually run the game without any errors (F5 to run it, useful that) but my image isn't showing. Instead all i get is a relaxing blue gradient background.


Actually, this isn't relaxing at all. It gives me vertigo because I feel like I'm falling into the sky.

This isn't over, Visual Studio.

Sunday, 15 May 2011

Graphics

All right, enough of this shit. Let's do some graphics. Let's just get something, ANYTHING, visible in the game.

The tutorial (this one, I think - me, 6 months later) says this will be, and i quote, really easy and straightforward. Hm. We'll see, but I already doubt it.

Ok, so I put in the code the tutorial asked for (which wasn't really easy), but when I try to run the game I get an error message:


I think I've had a similar problem before... hang on, let me check.

Yes, I solved the problem before by setting the graphics to 'Reach' instead of the default (see my earlier post).
Now the game runs, and I have graphics!

Sunday, 1 May 2011

Class clarity

I have my classes working now, since I've figured out the code (see below). I'm still not sure about the meanings of 'public' and 'static'. At first I thought they were mutually exclusive, but I was wrong. You have can have a method which is both public and static, which implies they refer to something different.


Making a new object
ClassName object1 = new ClassName();


Running a method for a particular object
MethodName(object1);
or
ClassName.MethodName(object1);


A method that takes an object for input
static void MethodName(ClassName ClassName)
        {
        }


Refering to an object's variable
object1.variableName

e.g.
Console.WriteLine(object1.variableName);
or
object1.variableName = 6


A new class
class Monster
    {
        public int variableName;
    }


A new method within that class
public static void MethodName(ClassName ClassName)
    {
    }

Wednesday, 27 April 2011

Class confusion - part 3

My problem with classes is I don't know how to make them return variables. If they can't return variables, then surely methods within the Program class are better? At least with them you can return a variable (even it's only just 1).

Also I keep getting errors about declaring classes. Let's take a look at that first.

After some work I've made this guide for myself, for creating classes:

static - whether the variables can be changed outside this method?
public - as above?
void / string / int - The variable type to be returned (void seems to be optional for the the first method in the class?
Method name - e.g. Main
(inputted variables) - e.g. (string variableName, int number)

This vaguely seems to be right so far. At first I thought static and public were mutually exclusive, but I found a class that had both.





The next problem is being able to use public variables. Can I use them outside of the class they're declared in? I would have thought so.

it seems to be classname.variablename
e.g. monster.health

Aha! I've finally got it working. Will post more later.

Sunday, 24 April 2011

Class confusion - part 2

I've decided to do some experiments with classes to see if they behave how I think they do.

First I want to see I can call a method in a different class. I was able to do it, and here's the code, below:

The Program class

The monster class.


Then I made a second method in the monster class to see if I could call either of them when I wanted to, which I was able to. Also, typing the class name brings up a list of its methods (usefully).




This makes an error.
Then I tried creating variables inside of the new class. I tried to do it outside of a method initially, but this generates errors. Is it possible to have a main method for a new class? What would be the purpose of it?





Next I created 2 new 'monsters' in the Program class, monster1 and monster2. I made the Program class define their HP and names from monster class.

The Program class.
The monster class

The question is, now what do I do? Where can the variables 'monsterHP' and 'monsterName' be used? Can they be used outside of the monster class? If so, how do I refer to them? I'm guessing the 'static' part means the variables can't be changed outside of that method, so I need to take 'static' out. Taking it out produces this error:

Well what do I have to type in, to replace 'static'? It's asking for an object reference and I don't even know what an object is yet.

excerpt code from the tutorial
Annoyingly, in the tutorials I'm following the guy seems to get away without replacing the word static. Sometimes he doesn't write 'public' either (which I guess is actually optional).

Also he's able to create variables outside of a method, which generated an error for me.

Saturday, 23 April 2011

Class confusion

Yesterday I learned how to make a new class - right click on the namespace in the solution explorer, select 'new' and select 'class'. Ok, sounds simple. I'm just getting to grips with what they're for...

'Program' is the default class which is the first thing that's looked at when the game runs.

Classes have methods in them, which are 'mini-programs' - they either 'do something' or return a value of variable. I get the idea of methods - they can be called when you need them, and save you writing the same code mulitple times. Classes seem to be like methods... but what's the difference? And crucially, what's the point of having classes?

In the tutorials I'm following, class instances are defined like variables -

Hero myhero;
Battle battle;
(Hero and Battle are classes)

To create a new class instance, this code is used:
myhero = new Hero();
The only time I've seen 'new' before is with random numbers:
randomNumber = new Random();
To run a certain method within a class this code is used:
Hero.Initialise(myhero);
'Initialise' is a method withing the Hero class. Like methods can accept variable values, Initialise accepts instances of the Hero class. This is what the first line of Initialise looks like within the class Hero:
public static void Initialise(Hero hero)
In the tutorials, the current purpose of the Initialise method (the tutorial calls methods in classes other than Program 'arguments' for some reason) is to give values to loads of variables, like the hero's health, defense, etc.

This has all been a lot to try to take in and understand, hence my confusion and scepticism.

On a different topic, here's a cool 'bullet hell' game. Guaranteed to make you say fuck a lot.


DN8 at newgrounds.com
 And no, those aren't health orbs, they're BULLETS.

Thursday, 21 April 2011

Finally finished Swords n' Shields

Well, a playable version of it anyway.

The link to it is here.

What I need is people to playtest it, so please leave a comment here if you've got advice on how to improve the game!

Tuesday, 19 April 2011

Dividing by zero

Dividing by zero error message in C#
Dividing by zero in maths gives an 'undefined' answer or infinity as the answer.

When you divide by zero in C#, the program crashes.

I wondered if dividing zero by zero would make the same error, and yes, it does. I thought 0/0 = 0, since logically it's true. But no, I'm wrong.

Sunday, 17 April 2011

Evolution sims - Graphics

One obstacle to making an evolution sim is graphically representing the organisms and their environment. Evolve represents its creatures with yellow squares. The most basic creature is a single yellow square, while more complex ones are collections of squares.  Food is represented by blue and white squares.




This guy's sim uses circles to represent organisms and squares as food. Simple graphics aren't just laziness. How would you ensure a sim could animate a moveable arm? Draw longer legs? An evolution sim implies the creatures will change into unexpected forms. Spore was ground-breaking for its ability to animate creatures as players made them. Hobbyist programmers working alone won't have the resources to accomplish this, so it seems inevitable that graphics must be kept simple.

This evolution sim is cool because the creatures are a little more true to real-life. Each has a head (a black dot) and one or more tails. The tails are nicely animated so it really looks like the creatures are swimming in their 2D water environment.



In 2D video games I generally prefer a side view to a top-down view. There is a joyous freedom in Mario's constant skirting of the rules of the gravity. It feels more natural than a top down view, which I find more cerebral. Our instinctual brains are more suited to watching jumping, climbing, and falling. How often do you view life from a top-down view?
One place is watching insects on the ground. In particular, ants, since these are usually found in large numbers and aren't shy.
Another place is under a microscope. This isn't a view most people have first-hand experience of, but everyone has seen microbes under a microscope on the tv. Which is why 2 of the above games make me think the creatures are in a petri dish, when actually the creators didn't actually confirm that.

Is an evolution sim with a 2D side view possible?
I think so. I also think it'd be more interesting to watch than a top-down view. I'd be urging on the creatures to climb higher through the trees.

Saturday, 16 April 2011

Evolution simulators

For years I've had an on/off idea for a program which simulates evolution. Like all good ideas I have, someone got there before me. Lots of people, in this case. Let's have look at some of them.

Bug Hunt is a very simple game. You play as a crow, and click on bugs to eat them. The bugs spawn randomly to begin with, but as you play on they spawn more often in the dark areas where you can't see them.
The bugs are spawning in the dark areas because that's where they have the greatest chance of survival. The program must have a gene for each bug for where it spawns.
It's not too clear though that's this is what is actually happening. A player could think the bugs are just learning to hide.


Here's another game from That's Evolution, the same site that Bug Hunt was from.
This game is call ROBO and is bleeding tedious. Each generation, the Robo has 3 offspring, and you have to choose which one will father the next generation. The aim is to 'evolve' a Robo tall enough to reach fruit from a tree.
It's not real evolution though. It's more like you're playing God playing at evolution. There's no such thing as a predestined 'goal' in evolution.
Also, it takes ages to make a Robo tall enough to each the fruit! Not billions of years though, but still.



This game (again from That's Evolution - though I'm not being paid by them or anything) is simply called 'moths'. You click on moths, and presumably the surviving moths pass on their genes. After a while all you get are moths that camoflagued so well against the tree they're practically invisible. It's a shame that when each moth spawns they give their position away immediately with a animation.




Ah, Spore. I didn't even play it, but from what I read it's not a real evolution simulator. The player upgrades their species - adds claws, lengthens arms, etc - which makes it more creationism that anything else.




This game is simply called 'evolution'. It has the opposite effect, because it has me enquring to God why it's so boring.
It really is slow-paced. I just played it for 5 minutes without even realising it - I was surfing other webpages.
The idea is to grow bugs to fight (sounds like pokemon). You can also breed them, and presumably traits are inherited. Not evolution then, but a breeding sim.
If you want a really slow-paced game (sometimes I actually do) then this is for you.


Here's a genuine evolution sim, called 'Evolve'. (imaginiatively named, these games). You look down on a petri dish while creatures made of squares run around looking for randomly spawning food.
They can evolve in 2 ways:
  • their shape / size (i.e. physical attributes)
  • their behaviour
Sadly the sim didn't live up the creator's speculations that the creatures would hunt each other, even after he left it running for an entire year. His FAQ makes for a very interesting read, though. He explains how the behaviour system works - the organism keeps making choices from a series of options, depending on its immediate situation.

I'm not sure what this simulator is called - perhaps it doesn't have a name. It's very similar to the sim above. The animation is a lot better though - each creature has a tail it uses to swim through its 2D watery environment. I like the accessibility of playing it in an internet browser. The rate of evolution is quite slow though - this is a sim where you leave it playing and forget about it for a few hours.

Thursday, 14 April 2011

Swords n' shields update

STILL working on this game. I didn't expect nor want it to take this long.


A cool thing I learned today was, calling the main method to go straight back to the main menu. Before I'd learnt this, I had to make the program go back through all the other methods it happened to be in.

Though isn't calling the main method a bit like running a program within the same program? I guess it doesn't matter, so long as it works.

I got the editor mode working today!

Things I haven't included in this game are:
  • graphics
  • save game option
  • music & proper sound effects
  • arrays
  • non-static methods (still not sure what the advantages of these are)
In my next game(s) I'll learn how to do these.

Saturday, 9 April 2011

Still working on this game

I still have a while to go before Swords n' Shields is completed.
 Here's my todo list (in my own notes):

Level 3: wizard can cast more spells
Level 4: 2nd sandworm to appear after x turns (or at random while sandworm is emerging and submerging?)
Level 6: shapeshifters die if shift while underground.
level 7: give future you a personality
level 8: finish drunk goblin personality
level 9: bhaal (entire level to do)
level 11: you go back through hades
 

Other things
hints
intro & outro text
editor mode
sound effects for monsters attacking each other & themselves
battle report - shows if monster is submerged?
playtest the hell out of it


Optional things
picture for each level?
coloured text
sand worms can eat you
gravestone text centred
I'm able to do about 2-3 things a day, and it takes that many hours! I won't give up though (even though I wanted to a while ago).

I got some cool text ascii art from http://patorjk.com/software/taag/
...and some really cool nice ascii art from http://www.ascii-art.de/ascii/index1.shtml

Wednesday, 6 April 2011

Update on Battle Monsters

The first thing to say is, I've decided to call the game Swords 'n Shields instead. Since that's what your 2 main choices in the game are, to use your sword or your shield.

The game consists of battles that are rpg-like, but you don't gain experience or level up. So each battle is a puzzle instead. For example, in one battle you fight against 2 shadow versions of yourself, that copy your moves. Attacking them won't work since the 2 of them combined will kill you first. Defending won't work either since they'll just defend too. One solution is to keep attacking yourself - they'll attack themselves too, and in around 1 in 4 games they'll die before you do (since attack damage is randomised). There's at least 1 other solution so far, though I'll keep that one a secret.

I've given up hoping to finish it soon because coding always takes longer than I expect. Is it because I'm a novice programmer or is it because it's difficult to navigate through 1000 lines of code? Whatever the case, I'm determined to finish it, so it won't become another failed project.

Here's some more screenshots.

Thursday, 31 March 2011

Update

A few updates:
  • I made a calculator a few days ago (with a twist)
  • All the games I make will be uploaded to MediaFire (the file hosting site) where they'll be available to download via a link on the right-hand side of this blog. Hopefully MediaFire will makes it easy to download them.
  • Over the past 3 days I've been working hard on a text-based game currently called 'Battle Monsters' (don't worry, this isn't going to be its final name).
Basically the tutorials I'm following told me to make a very simple fighting game, where you can choose to either attack or defend. This gave me all sorts of ideas for improvements, but what intially started as a few good ideas has spiralled out of control. The game's code is now so vast I'm having trouble navigating it. Just as well I learned how to use methods, which are essentially 'mini-programs'. They're great because they let you call (use) a piece of code whenener you want it.

I have a burning enthusiam for this current game, but I know soon it'll burn out and I'll be left with a mountain of unfinished and confusing code. So I'm trying to rein the game's scope as much as possible. I hope that once I've finished the initial foundation of the game everything else will be easy, and cosmetic.

Once I've finished this game I'll eventually move on to super-cool graphics! (and not just text-based games).

Here's some screenshots of 'Battle Monsters':

Sunday, 27 March 2011

My second game

I've been working on a text-based game (the only game I can make right now). It took an hour and an half, so not too long.

My 2nd game, Pun Escape


I've started using DO / WHILE statements which means I can make the game repeat itself. I can see how powerful the DO / WHILE statements are now. In this new game, the user types something, the game gives a response, then it goes back to the beginning. It means the user can type the same thing twice and get the same response, or achieve tasks (or just do anything) in different orders.

So you can examine the room, examine yourself, pick up items, etc, in any order you want. I'm making it sound better than it actually is, but only because this is the tool I needed for the 1st game I made.

I've called it 'Pun Escape'. It's based on a stupid puzzle my mom told me when I was a boy. It begins as you find yourself in a room with no doors and windows, and you have only a table and a mirror with you to help you escape.

I made sure to include lots of variations on what people could type.
e.g. to 'go to the table', there's like 20 variations the game would also pick up, such as 'examine table', 'look at table', inspect the table'. Because it's spirit-crushing when someone gets annoyed at a game because of unusability. Including so many variations reminds me of Douglas Adams' text game, The Hitchhikers Guide to the Galaxy. It's the only text game I've played which doesn't annoy due to the program not recognising something you type. Here's a version of it.

The Hitchhiker's Guide to Galaxy (flash version, hence the fancy graphics).


And here's a link to Pun Escape

I'm not sure how good these file hosting sites are. The first 1 I used requires the downloader to enter their email address. And the download button doesn't work for me, for this new one.

My first game

I've made a game! Well, it's a game in the sense that it changes based on user input. And it's really short, but it's still 'a game'. I call the game 'The Cake is Inevitable'.

My creme de la creme, 'The Cake is Inevitable'.


Here's a link to it as a download: http://www.filehosting.org/file/details/214517/The_Cake_is_Inevitable.exe

I would have liked to have known how to make the program go back to a previous line of code, because in one section I wanted the program to repeat itself until a certain statement is true. At the moment all I know about looping is 'if / then' statements. I'm sure other loop statements hold the answer.

The Endless Blue

Here's the default game for a new Xbox Windows Game. Yes, it's just an empty blue screen. The tutorial I'm following says it's actually 'infinite space in 2D or 3D' which makes it sound more exciting.

default xbox windows 'game' (playtest mode)

Now I'm confused because a lot of jargon is being thrown at me, including:
  • methods (e.g. the main game method, constructor, initialise, loadcontent)
  • statements
  • classes (e.g. an input class)
  • variables
I think methods are a collection of statements. Like, mini-programs. They have names and purposes. I've never seen the word 'method' used in this context before though.

Maybe a 'statement' is a single line of code?

I'm fairly familiar with variables. They hold values or even text information.
E.g. the variable 'number of lives' could be 3, and can change throughout the game.

I don't know what a class is.

Saturday, 26 March 2011

Hello World!

Day 2



When I opened Visual Studio today, a new option was available: XNA Game Studio 4.0! I guess the program had to be restarted for this option to appear.
Creating a new XNA game studio project in Visual Studio

















Choosing 'Xbox 360 Game' creates a new project file. I was surprised to see the new file already comes with some code. It's not a lot of code though. I'm not sure what it does either.
Pre-existing code for XNA game studio projects.















Since there's so much pre-existing code, I don't think this is the best way to start learning C#. I might get confused about what I've done and what was already there when I started. I wonder what project type I should choose to get the least amount of pre-existing code?

I'm going to follow a tutorial where you make a pong game. It suggests you start with a Windows game (an option under XNA game studio). I guess if I made a xbox game I'd only be able to playtest it on an xbox? (And playtesting on the xbox requires a paid membership to the xbox creators' club)

A new problem. When I playtest the pre-existing code, I get an error message saying my graphics card isn't good enough (even though my laptop is less than 1 year old).

error message when trying to run a game using F5


Thankfully there's a solution, which I found here. It was to have the game use a 'Reach' profile instead of the default 'HiDef' profile. (Maybe my laptop can't run high definition graphics then?) This webpage has an easy walkthrough to set the game to Reach graphics.

The solution explorer
This may be a good time to look at the 'solution explorer'. A strange name for what seems to be a menu where you select different aspects of the game. The most important option appears to be Game1.cs and Program.cs, which is the code for the game.


Friday, 25 March 2011

Day 1

XNA game studio in my start menu.
Today I've taken my first steps to making an xbox indie game.

First I installed visual studio 2000 and Microsoft XNA Game Studio 4.0.

After this I'm not sure what to do...

Clicking on XNA game studio in the start menu brings up a list of programs and links, but none of them is actually a program to make games with.

I've been googling what to do next, and I've eventually found this bit of helpful text (here):

You have heard all the buzz, you might have even seen some cool games that people said were written with XNA, but you're still not sure what exactly XNA is and what you can do with it. "XNA" the term is a brand, it refers to all the Microsoft Technologies that have to do with developing games. This includes both DirectX and the XNA framework. Most of the buzz lately is due to the XNA framework and chances are that is why you are here.
The XNA framework is an API. What that means is that it is a framework developed by Microsoft to help you make games faster. It's not a drag and drop game maker and you will need to learn how to program before you can use it. It is easy to use, but you will have to be somewhat technical to develop games with it.
The XNA framework is not a game engine. It does not include physics, collision detection and other things often found in game engines. It is a game development framework, but how the game works is programmed entirely by you.
XNA Game Studio is the environment you develop in. XNA Game Studio is basically a plug-in that gets installed into one of the currently supported Visual Studio environments. Typically XNA framework games are written in C#, but there is some support for other .NET languages with some slight functionality lost.

From this I gather that:
  • XNA Game Studio is a.k.a. XNA framework
  • You write in C#
  • C# is a .NET language
  • You use the XNA framework in Visual Studio

I've opened Visual Studio and there isn't an obvious choice from here. I guess I'll choose file > new > project.

Starting a new project in Visual Studio


The options when you start a new project in Visual Studio
Now what do I choose? There's no obvious choice like 'XNA framework' or 'Xbox Indie Game'. I thought it could be 'Console Application' (since the Xbox is a console) but googling the term gives:
A console application is a computer program designed to be used via a text-only computer interface, such as a text terminal, the command line interface of ...

It seems I also need to learn how to program (using C# (how is this pronounced? 'see hash?)). I've ordered a £15 book from amazon, which was recommended for beginners on this thread.


It seems the next step is either to join the App Hub for around £60, or to learn some C#. I think I'll do the latter first - at least see if programming is for me, before I shell out that much money.