Long time….

So I’ve not been posting on here for a few months now, I have been incredibly busy with just finishing my second year of university and going on to my placement year. I have been searching for jobs, playing games, Making games and thinking up some great game ideas. So I am currently on my placement working at the amazing Monumental Games. I’ve been here two months now and loved every minute. It’s a design role so I’ve been scripting in TCL, using many of their great in house tools for things like collision, item placement, world building etc. It’s a nice change from programming, I can easily communicate my game ideas and see them working in game which leaves you with a great feeling of satisfaction, when it works. So I started off working on the design team for Football Superstars a free MMO this was so much fun, I’ve learnt so much from it and also PHP and SQL for the databases. You also learn how an MMO works and a lot about servers.

So after two months I went through an interview to move over onto the design team of MotoGP 09/10 this was my dream job to work on a triple A title, I also love the fact it’s a Racing game one of my favourite genres. This experience is so much different to working on an MMO. For a start its working with different hardware, development 360s and PS3s, but the main difference is MMOs don’t really have fixed deadlines you can always role live updates out every few months whereas on tripple A titles you have to plan and work to deadlines.  I’ve also joined at a bit of an odd time the game is going into beta stage. I can’t say too much about the game but its very fun to play :P

So the updates here are getting less and less due to me being busy with work. However I am working on two secret projects which I will reveal in the next coming months, One is a very unique idea which I got a quick prototype running by modifying my DirectX engine however I have now decided to rebuild it using XNA. Why, well you get more flexibility with XNA you can use existing samples such as the networking sample to allow network play, I can also make my idea look graphically better and handle more objects on screen. I will reveal my idea soon. The other game idea is also an XNA project which I working on with a friend. I am currently only working on it at the weekends so progress is slow; we hope to enter it into next year’s dream build play.

Flash Ahhh

So over the summer 09 I decided to look into flash action script for game development, Having only used flash in the past to make a presentation I had very little knowledge of flash. I had some great ideas for games but had no idea what I was limited too and how long it would take to learn some of the more advanced game techniques for flash. I decided to start simple and make a puzzle game, I wanted to make a bejewelled clone but with the board being able to rotate and flip to give it a unique spin. I looked on various websites and got some books on action script, I was surprised at how quickly it was to pick up. I had gone through some basic tutorials and figured out a lot with trial and error, within a week I had the core basic mechanics done allowing you to swap with neighbouring cells on click. After 4 weeks the game was completed, I had two special powerups which you get from matching 3 of the rare gems. Shifting a row across or shifting a column up or down, 2 modes of play Arcade/Time trials.

After receiving an email from a lecturer about a flash game competition I decided to enter it and modify my game slightly to fit the theme. The competition was run by Arriva buses they were looking for a bus themed game. I replaced the gems in my game with buses and made the powerups bus themed so clearing 3 rows with a bus swiping across the screen. I got a phone call today to say I had won the competition, I couldn’t believe it, from what started as just a simple venture into flash to being the winner of the competition I’m over the moon :) . The game will be available on the company’s website soon. I will post a link to it here.

Interactive 3D Graphics (DirectX) Finished

It’s been a while since my last update but after many weeks I’ve finished my De Blob remake, while it is finished to the deadlines I am still carrying on working on it, I will work more on shaders and some advanced directX techniques. As its stands it’s more of a tech demo than a game, I have taken this approach from the start since it began as a terrain demo, then to a zombie demo and now to almost a game. I am very happy with the way it has turned out, it has been the hardest work I’ve taken on yet, as directX was all new to me and learning the techniques and how it all works took some time.

As from my last update a lot has changed, before it was a blob changing colour on collision with three zombies. Since then I have got boundingBox collisions/Textured Meshes/Buildings/Shaders for the Blob/Particles/Road/Skybox/Car/Helicopter/Multiple camera angles/State system these are just a few of the recent additions. I have also optimised the code and refactored a lot of the classes to make it easier to work with and be more efficient.

It was near the end of the project that i started to think more about structure and making it into a game, I looked at inheritance and was able to get the car, helicopter and zombies all inheriting from a base object class. In Hindsight this approach should have been taken at the start but as it was at the experimental stages i took my time learning and applying the techniques learned each week.

Mobile Devices Battleships Game Complete

Mobile Devices Development Diary 6

Friday 03 April – Sound, Options and finishing the game

After getting Bluetooth done yesterday I spent most of today refactoring and adding small features. I began by adding sound, on researching this it seemed to be only 3 lines of code to set up a sound manager and to play the wav file. I followed the book on how to play a local resource sound file and hit a problem. On setting up the manager it said Incompatible type I tried changing it to play a sound from the internet thinking it might just be the local directory or the file but I was still getting the same error. To create a sound manager you call Player player the problem I was getting was I already had a class file named Player (server) which is the type the sound manager needs. I renamed my Player class and it fixed this problem.

The next problem I had was to do with the sound playing every second when you hit an enemy ship. I fixed this by checking the location of the text when it is at the top of the screen play the sound. I made the sound method take a string in its parameters this was the name of the file to play. This meant I could use the same method for losing just passing in the losing sound name. This fixed it because the text moves down the screen, it’s only going to hit the location once.

On testing the game out I found a bug in the layers it should take away a grid when you win or lose and display the relevant text. On the first go it would work fine but when you restart the game it would not remove the grid at the end. I started by changing the way the grids add to the layers I thought as they were being appended it was getting the order wrong. I changed it to insert and gave the layers fixed numbers. This didn’t do anything the next thing I tried was changing the end state when you win or lose instead of removing the layer I made it set the visibility of the layer. Again this didn’t fix it. I then looked at the reset method again and switched around create player board and create the AI board this fixed it, the reason I didn’t spot it before was I was thinking about the way it gets created but when you think it is getting removed in reverse, then it should get placed down the opposite way.

After getting the sound working I needed a way to give the user the option of sound. I looked at Choice Group which allows a tick box for on or off.  I created an options form which had I appended the choice group to it and added an OK command. I had troubles getting it to listen for my OK command I thought I was setting up my OK command but was actually just using an existing one which was already getting handled in the commandAction method. I ended up taking it out and just checking the is selected variable which is part of the ChoiceGroup this worked great and gave me the choice of sound. I then went on to add the menu command to the main game form allowing the user to get back to the menu, I had a few problems with this as starting a game and going back into the menu then to a new game would cause the game to run faster than usual. I realised where I was going wrong as every time you start a game it goes to the Run method, and each time I was doing that it wasn’t ending the previous game causing it to run faster. I solved this by just calling game end when I went back to the main menu.

The next thing I got working was vibration this was just one line and is part of the display library; the next problem was how to get the display from the midlet in my HUD class. I ended up passing it from the midlet class to the main battleships class through the main constructor this allowed me to get it and use it in my HUD class, like the sound problem earlier I put it in the sound method and surrounded it with if vibration was selected in the menu. By putting it in the sound method it meant it would only be called once when the ship had been hit. Inside the sound method it needed to check if sound was selected in the midlet class so I surrounded this in an if statement this meant I could have either sound or vibration or both selected.

The final thing I put in my game was Record set I had already experimented with this before when I made a pong game and adapted it to save the players best score. I simply copied the record set classes over and changed the variables it was saving and loading. Initially I set a variable score loaded to = 0 in my Hud class then when you win a game it would load from the record set into the score loaded variable, Increment it by 1 and save it out. The increment didn’t work and I ended up making it +=1. Back in the main menu I made a stats form which would display games player, win and loses I made this load in from the record set which would display from the record.

And that’s it the game is finished all that was left to do was add some more comments to my code and do some more refactoring and cleaning up. I am happy with the way it’s gone I have achieved a lot in just a small amount of time I have hit all the phases and even got features I hadn’t planned in such as sound and stats. Overall Bluetooth has been the hardest thing to get in taking 2 days of hard work to get working it’s something I never thought I would have time to do but has made it even better. Deploying it to my mobile to see it working first hand was gave me a great sense of achievement it was nice to hear the sound coming from the mobile and seeing it store the stats.

Mobile Devices Development Diary 5

Thursday 02 April – Bluetooth

I spent most of today trying to figure out why it was missing the first move. I ended up re writing the Bluetooth about 6 times trying many different ways of sending and receiving the data. I wrote lots of diagrams on paper to help try and solve the problem. I wrote the sending and receiving pseudo code and helped spot my first problem which was to do with the double for loop sending, I found that it would send if the player had placed all ships. On receiving it would receive the grid in the double for loop but then outside the double for loop it would then get if the player has placed their ships. This meant it would be receiving the data in the wrong order.  I left the problem of it not detecting the enemy ship on the first go out and focused on getting it to update on the AI grid when the other player has fired. This involved sending my current playing grid with my attacked grids to the other players’ phone and to store it in there AI grid. I ran into a problem it would update my AI grid with my actions so it was acting like a mirror to my moves. I never did figure out why it was doing this after looking at how it sends the AI grid to the player and for the player to store it in the AI why couldn’t you just do the same for the player’s grid and store it in the other players AI grid? As this all sounds very complex it’s easy to get even more confused and make it even more complicated, which is what happened I ended up having 6 different versions all with different problems in the Bluetooth.

One version would just send my position and update it on the enemy’s grid so every time I moved it counted as firing or setting the cell. Getting more frustrated about how long Bluetooth was taking I decided to take a step back and start again with the basics. I knew that it could send and receive each player’s grid, storing it as the enemy on each mobile so I kept this in. I also knew that it didn’t need to be sent every second it could be placed in the player’s fire method. Instead of sending the players grid to the other player to store in there AI grid I decided to just sent my x and y position.

From the AI class receiving the x and y it could then store this as the opponents shot to do this I passed the x and y to AI go method this would then make a check on its own grid and see if the passed in x and y equals its own ship if so then lose part of the ship. This worked perfectly and was exactly what I was trying to achieve all day when trying to pass the whole grid in but couldn’t get it to work.

The next problem to solve was why it wouldn’t get the enemy’s ship on the first go. I tried many times debugging and looking through the grids I even got it displaying on screen so I could check. I sent a counter out and got the other mobile to receive it to check they were in sync. On doing this I found the counters to go out of sync when one player placed there ships down and started before the other. I thought this may be the problem and that data was getting sent and received in the wrong order causing them to go out of sync on the first move. I made it send if the player had finished placing their ships. The other player could then check this and check if they had finished placing their ships if so then send data back or receive data. This made no difference.

I then went back to paper and pen approach and mapped out what was happening I drew step by step what was happening and then I found out why it was out sync. It was because phone 1 would send its AI grid and at the same time try and receive phone 2s AI grid and store it in its own AI grid. The problem is what if you sent out data but the other phone hasn’t sent any data out you are then receiving nothing so your AI grid is going to contain no ships whereas the other player will receive your data and make it look like the other phone is in sync and working. On the next go it would work fine as the both grids would have been sent and received.

So now I knew the problem I was half way there to solving it I ran through my methods of sending and receiving and tried rearranging part of my method like I tried earlier.  So in the player(server) class when the player takes their turn it needs to send their AI grid(initial ships placed) and then check the other player/mobile AI grid for a hit or miss. This made it work all the time simply sending data before receiving it is what fixed it. This problem has taken 2 days and about 12 hours to solve and has been the hardest problem so far. The results are worth it I now have a perfectly working Bluetooth battleships game, and a clearer understanding of Bluetooth and the server/client all in one approach. I may try and optimise the Bluetooth later so instead of sending 48 ints I could change the data type to a byte making it 8 bits per byte compared to the 32 bits per int allowing less data to be sent. As it stands I have met the final phase’s milestones which were to get Bluetooth mode and finish graphics for the game.

Mobile Devices Development Diary 4

Wednesday 1st April – Scores, Refactoring and Bluetooth

The basic game was nearly done now it just needed scores. I researched text to screen and found it very easy to implement. I had it displaying “You sank the enemy’s Battleship” when the life of the AIs battleship equalled 0. I had a few issues with the text being too big for the screen. I used the width of the device and divided it by 2 to find the middle of the screen to draw to. Initially it would go from the left of the text but I saw there were different parameters for where to draw the text from such as Baseline meaning draw from the centre of the string. The next problem was the text didn’t wrap or move onto a new line. I tried putting \n for new line but got nowhere. I looked on the internet and found there is no new line method for j2me. I made two draw strings and just moved the y down slightly so it looked like a new line. I then got the text to come from the top of the screen down to the bottom each frame moving down. It looked really nice and made it feel more alive and animated instead of boring static text flashing up. I had a single player battleship game all working.

By now my code had become a mess the biggest thing was I wasn’t taking advantage of classes mainly because being so new to java and j2me I didn’t want try using them. I began to sort out what needed to be classed, the two main areas where the AI and the Player. I put these in a separate class but found I couldn’t access the variables in the main class. I checked the variables and they were private so I changed them to public the next problem was I had been using mostly global variables in my main class this meant I couldn’t pass them into the new classes as there was too many. Instead I passed in the main class as an object to the new classes default constructor. This allowed me full access to the main class if the variables and methods were public. From within the AI class I needed access to the player class to do this I could go through the main class and go into the Player class. A lot of modifications where needed to the other classes as they relied on main and the variables there. After the classes worked I decided to neaten up my code this involved lots of refactoring to make variables have nicer easy to read names.

The next thing I looked at was getting a main menu working. I looked at a sample main menu from a book but I had problems integrating it with mine as it something to do with extending canvas and not extending midlet. I then looked at a travel list sample which shows how to use lists. I took this and modified it work with my game. The only down side is I can’t get the canvas functionality as it must extend midlet. I could write a midlet that launches the menu to the launch my game midlet but it works fine the way is at the moment.

So far I’ve got my menu with my single player battleships game working now I needed to make a Bluetooth mode. For this I began looking at a counter example in which the phone acts as both the client and server, I read a chapter from a book on Bluetooth and planned out what would be needed for a Bluetooth mode. I initially wanted to have a one mobile be a client and the other be a server as I have used this method before but with visual basic. I wanted one phone to be sending out the information while the other listens. I decided to base my game off the counter example as it was all there ready to be used the core functionality was set up I just needed to make a new client and server class for my game. I thought about duplicating my classes and keeping them separate from single player mode, so if I made a mistake single player would still work but then realised that if I can get it sending and receiving data, I can just pass that on to the AI class and trick it into thinking its running AI. It also saves having to make the same changes to single and multiplayer when adding new features later.

This is my 2nd and 3rd milestone reached which was to get scores and menus working.

From the midlet class selecting Bluetooth would change a Boolean to true in my main app. The player class would now become the server so it would send out data and the AI class would receive the data. To start with I just sent out the current grids x and y position just to test that Bluetooth was working. I then displayed them on screen to see it working. I planned out just to send the AI grid and for the client to receive this. This was because when you are firing on the player grid it is checking the AIs grid to see if you have hit so by receiving the other players AI grid you are actually playing against them. This involved two for loops with i and j to index into the 2d AI grid array. This worked great with no slow down or lag even though it was sending 48 ints I expected there to be some delay in updating the grid. The only problem with this method was it wasn’t turn based you also couldn’t see the player attacking your ships or their moves. I put the send and receive in the players go and the AI go method and this made the mobile freeze until the both players have chosen this worked well as was turn based. The only downside is the first place you put your initial ship doesn’t count as putting your ship why I have no idea.

Mobile Devices Development Diary 3

Tuesday 31st March – Ship Placement, New Grid, Scores

I spent most of today working out how to get the ship placement more like battleships. I needed a template for the Aircraft carrier like highlighting 3 cells. I initially made it so you select your cell and it places/sets the cell to the left of your choice and to the right so it sets 3 cells in a row. This worked fine if you were near the middle and it would fit into the grid. I wrote some more checks to see if you were three cells away from the left side or the right side of the grid if so then place ship down. I ran into the problem what if you move to the first or last cell 1 or 2. I thought about preventing screen wrapping but ended up with changing it so it adds two cells to the right of the current one this meant just move the current one to the first cell and not move the other two. I did the same for the AI placement. After placing three down it then had to check if it was two away so it could place two down. The AI I wrote for placing the ships down wouldn’t work right as if the cell was empty it should place but it never checked one to the left or the right I changed this to check the other cells.

I then put in rotation in the ship placement. I made it so pressing 0 would rotate the ship either horizontally or vertically. Adding this would throw off my boundary checks as it only checked in the X axis. The code was similar just checking fewer cells as its 8×6. The big problem came from the corners if you started horizontal in the top corner and you rotate to make it vertical it would go off the grid. It is a similar problem with checking wrapping. I made it check if y is 0 then you are at the top of the grid so rotate down. I got myself confused with all the checks and spent a while getting it to work as sometimes if you were horizontal and switched to vertical it would move them diagonal. I found I had made a mistake in one the checks.

As I was still working off one grid Minesweeper style I decided it needs to look like battleships and so I implemented an AI grid this was a copy of the player grid but just held my initial ship placement in. A lot of changes would need to be made to incorporate the new grid mainly AI and player grid checks. I made it after you have placed your initial ships on the AI grid it would then move the AI grid up and bring down the player grid which is off-screen; it would come down every frame until it reached the bottom of the screen. This looked really good as it was animating and gave it a more professional ready to play feel. Once it came down to the bottom of the screen the target had to be changed to move down to the player grid. This involved making a spacing variable which changed when the new board had stopped moving. This made the target snap to the new player grid. I had a few problems with it snapping, the problem being I was setting the targets x and y to equal the start of the grid so the top left corner however I was setting the gridXposition or gridYposition back to 0. Changes were made to check the player’s grid for enemy ships. The enemy ship initial placement was now changed to the new player’s grid. And the AI would now check its AI grid where it had my initial ships.

To get the game up and working I needed scores. I wrote it so if your ship has been hit it removes 1 from your life. A check to see if your life is at 0 if so you lose, same applies to the AI. While this way works fine it didn’t have the battleships feel. I needed life for each ship this would require the ships to have the own unique number to identify them. The problems being all the ships use the same number as they index into the same ship graphic. To make them each have life’s they would need their own graphic so it can give the grid cell a different index. I added 3 more graphics to the image sheet. 1 for the carrier, 1 for the battleship and 1 for the cruiser. This had a knock on effect for everything as grid was looking for the right index value. I looked up using enums in j2me but found there was no support for them. I wrote my own static ints and used them as enums. It took a while to go through the code and place names instead of numbers but it was a good pay off as I could easily alter the image index. I was also able to write life for the ships. The only thing that was missing was the text to screen.

Mobile Devices Development Diary 2

Monday 30th March – Game Logic +AI

Today I started by looking at Layer Manager which allows you to place backgrounds and sprites or any images close or further away from the screen. Behind or in front of each other. This gives the illusion of distance and depth. I created a target that will be used to move across the grids and fire or place ships down. I then went on to implementing user input. The main problem I had with input was with the target getting it to snap to the grid. To fix it, it just needed offsetting and then to be multiplied by the current grid number to move it across. I then set up boundary checks to see if the target had reached the last grid in X or Y, if so then put back to first grid giving a screen wrapping effect.

After that I then implemented firing which would change the cells number to a different image index. The next thing was game logic I made a simple count to check if you had fired three times if so then change it not to place a ship down. It then has to check the current square if there is a ship there then set to the fire index of the image else set to empty. This is the basic check to see if there is a ship and how to handle it.

This is my second milestone reached which was to get a grid with user input working.

I was still missing AI so I wrote some basic AI methods. The first would set up the random three grid squares. This would select a random x number and a random y number making sure to stay in the bounds of the grid. I also made sure to check if the grid contained its own enemy ship image index or the players ship index this was handled in a while loop to which would end if the new random square was empty. This method was called once after the player has placed their three ships. After the player has placed three ships and has now just fired it would go to AI state which was a method to make the AI fire it did the same checks as the initial AI ship place method did.
The next part was to handle if you hit the enemy’s ship. This was a simple method that would get called in the fire method, it checked the current square if enemy the set to destroyed image index else set to empty. I did the same check for the AI but checking my ship index and it worked great apart from the game was becoming more and more like minesweeper.
This was my second phase 1st milestone reached which was to get AI working and simple game logic.

Mobile Devices Development Diary 1

Sunday 29th March – The start

Today I started my Battleships project, I started off by planning out what to do. I wrote down a few ideas for implementation of battleships. I decided to go with the approach of making one grid to start off with, this will make it easier for me to develop around. I looked at game canvas and how to draw sprites to the screen. After doing researching into graphics I have decided to go with Tiled Layers. These enable me to do animation and keep all my images in one image. After having a play about with a Tiled Layers example I began making a grid. I had to take into account the size of the grid and how big the squares are to make the game last longer. I decided on making an 8×6 grid size which takes up about half the screen on the mobile device. The great thing about tiled layers is it acts as a 2D array allowing you to get the contents with a simple getCell(x, y) or setCell(x,y,value). Using two for loops nested I can set the cell to = the tile index in the image. Filling the grid with the first index in the image set my grid up. This was my first Phase milestone 1 reached.