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.