Saturday 28 May 2016

Alone Update: Object Collision!

A small but very important addition has been made: The game now knows when you are getting absolutely wrecked by ghosts and wolves and you will lose health when touching an enemy.
Up next is the changing of scenes, maybe platforms, and then attacking. When that is finished, all that left will be to put in the graphics and hopefully sound!
A desperate koala tries to escape flowers and penguins.

Wednesday 25 May 2016

Alone: An English Project

Wow I haven't been using this blog much at all! I almost forgot about it. Logging on today, I realized that I have two nerding out drafts that I'll hopefully finish sometime before the end of the school year. Anyway, into the main points.

For an English project, I am tasked with creating a game based on a poem written by a classmate(apparently in less than 20 minutes, impressive huh?) This poem is called Alone and it looks something like this:

This game will be for a technology fair sometime soon, and I have all the reasons to make it really good. Some background information though I am only an amateur programmer with almost no experience in game making(For a French project I made a point and click game that feels like its stitched together, though it worked pretty well.)  After a bit of thinking, I have decided to make a platformer type game instead of perhaps a choose your adventure game that was first envisioned. The poem itself limits the game play quite a bit as I cannot find any part of the poem that can be made into a game. In the end what I had in mind was a game in which the player would walk across the screen and encounter several enemies along the way, perhaps some ghosts and wolves, fitting the mood. Trust me though, it looks REALLY good in my head. I used wpf on visual studio and experimented with Images and the Dispatcher timer, not too shabby actually.
Currently ~100 lines of code in the Mainwindow class
Now for the specifics.
Probably really messy declarations, just made all player related things static because there will only be one player. I am using a few of the Windows default images for place-holders, as you will soon see. The commented out portions of the code involving rect and prect represents the (more than likely failed) attempts at a lazy and non-math solution to object collision.
The timer tick event is triggered every 5 milliseconds (wow I thought I set it to 15 milliseconds) as seen in Mainwindow(). This essentially updates the locations of the Image objects every 5 milliseconds. In addition, this event will also check for user inputs, namely the A, D, and spacebar keys. I had the W and S keys to move the player vertically, and eventually commented them out once I implemented jumping. The jumping was actually quite tricky to do and took quite a while. Since no collision exists, I had to bound the player's Image within the canvas' borders. Since the movement isn't continuous and a high velocity would exceed the bottom edge, a lot of changes had to be made before the player was able to fall to a fake gravity while jumping.
Another part of the failed attempt
Quick! Sneak in a picture of the xaml file to look cool!
Hard to have a game without enemies, up next is the monster class(only ~80 lines, as I don't have to stuff everything in here).
Note the public variables, I was too lazy to make accessor and mutator methods.
Monsters follow a similar scheme, with their independent DispatcherTimers that tick every 15 milliseconds. While not entirely obvious from this picture alone, there are two types of monsters(for now, as I have yet to find anything else fitting for the poem): wolves and ghosts. Ghosts are pretty slow and will follow you in the 2D plane while wolves can only move at a fixed height, albeit with a faster speed. The idea is that the player will have a weapon (maybe a branch?) that allows him/her to fend off the monsters but still giving him/her the option of avoiding combat and just jumping over them.
Monsters in their most natural habitat
The result looks something like this:
The koala is a jumping player, the penguins a ghost, and the flowers a wolf.
As this is stationary, one probably can't tell that this thing works, but trust me it does.

The next step is collision. I had some experimentations with Rectangles and realized that they are not the same as Rects, so that was the failed attempt. As I browsed the internet for an elegant solution to collision, I saw a comment suggesting that wpf isn't a game maker. It is right. Wpf made games are probably going end up feeling like a lot of the problems are covered with a band-aid instead of solved. So, naturally, I turned my eyes to Unity. With about half an hour of playing around I was able to get gravity to be applied on one sprite while not on the other, perhaps I should be watching some tutorials.
Is all my wpf work going to waste?
So now it seems like wpf is a backup plan in case Unity fails. Moving forward I am waiting on some art from my friend. If you are an artist and would like to draw a few things, perhaps the background or the sprites (don't worry they'll be silhouettes, I can't ask too much of someone who is working out of the goodness of their hearts), please contact me by commenting down here somewhere. The background will just be a general dark blue and dark red sky with maybe a dark forest closer to the ground. Somewhat like the game Limbo. 

Anyway, this is a pretty long post and here is hoping that this project will end well. 

In Unity there is strength. 

(Start it at 1:14, embed not treating me well.)
Ironic isn't it? Alone is the name of the game.