So, continuing from my last post. Let’s see. It’s been some crazy year. I took part to Ludum Dare #31 Jam, with another developer. We decided to take part at almost last minute. With only 24 hours left. So we worked the Saturday, and then the day after that after our normal job, aaaall night long. We started again Monday 20.00 o’clock and finished around Tuesday 03.00. Time zones worked in favor for us! But, ach, these last minutes. We were racing against time to complete the game. I was at the edge of saying “alright. we can’t do it. Let’s not waste any more sleep hours”. But the persistent side of mine prevailed. At the final hour we completed the game and started packaging it for upload. Read the rest of this entry
Darn it, I’ve really have some time to write something to this blog. My apologies. Real life has caught me up again. Let me sum up the past few days.
First of all work. Well, I leveled up (a bit). We started working on a 3D game with Unity3D this time. No more flash. Don’t get me wrong, I like flash. I really think it’s what newest programmers getting in the world of games should start working with. Flash gives you the advantage to get straight into designed graphics without the hassle needed from other engines to load the texture into the memory, create a quad (or a mesh), create a UV for that mesh (or quad), and finally place it somewhere on scene. Well, in flash you just load the texture and voilla! It’s visible. There also a bunch of nifty engines out there, like Starling (totally kickass!) and flashpunk(kickass totally!), and a new developer is going to learn a lot. There also easy monetization options. You can pick a publisher for free and upload your game to Kongregate, or sell it to FGL, or build it for desktop, you can put ads, or IAPs. Just imagine it and puff, here you have it.
So, I didn’t have anything better to do, so I got again down and tried to make something of my own. I always liked to check my ability to code prototypes. I try to participate in game jams to test my skills, and I tend to watch a lot of tutorials for any type of game out there. Minesweeper was one of the games that people suggested that good coders should be able to make in less that one day, and I’ve never made a minesweeper before. Also, lately I got inspired by a student of mine, whom I teach ActionScript so I got motivated to create a minesweeper game to teach classes (among other things). The result was quite well and took me less than 1 hour, although I tried to optimize it later and make it as easy to learn and as efficient as I can within the limits of knowledge of my student.
I’ve uploaded the code to GitHub and you can find it here. The game was inspired by Windows Minesweeper. It’s plain ActionScript. 3 classes, and 1 more event class. Cloc reports 367 lines of code which is pretty small number, considering the auto completion I got from FlashDevelop and all. To sum this up here is the hierarchy:
- In the Main class I just initialize the app. I create the Minefield class and a restart textfield which serves as my button and upon click it calls a Minefield function to reset its grid.
- In Tile class I set a rectangular tile which serves as a tile in classic minefield. I create the color with a simple shape, and I just store information of the position of the tile (without any good reason. Just housekeeping). then I have a tile id which indicates if the tile is empty or contains a mine. A status variable which store the state of the mine if its shown or hidden (that’s an integer though it could become a boolean). Then I have one more integer which stores the amount of mines that exist in neighboring tiles. That one is print in a Textfield above the shape, when the tile is shown. Functions are the usual, and pretty much self described. Show, hide, reset/update, and a checkTile function which shows it for the player. That one dispatches an event in case it’s empty without any mines arround, and creates a flood effect to show up all other tiles until there are mines around. More on that on the Minefield class.
- A TileEvent class which serves to dispatch events from Tiles. Most of it is not used but I liked to show up the abilities it could have. Mainly it stores the event type, and the information of the tile (position, and if it contains a mine or not[Tile id]).
- Finally the Minefield class. First of all I set the minefield’s dimensions and mines. Interesting values are 8×8 with 10 mines, 16×16 with 40 mines, and 30×16 with 100 mines. Then I create the grid, which is a 2D array. I prefer to use Vectors for array but that one could be done the same with the Array class. Grid is created upon player click in order to avoid placing a mine where player made his 1st click. When we have the information of player click and which tile it hit, we then randomly place the mines avoiding the same tile for 2 mines and the tile which player clicked. With mine placement I increase by one the surrounding tiles info about neighboring mines to update their respective text. Minefield is ready. Then I respond to player clicks by doing a check at the respective clicked tiles. If tile was totally empty with no surrounding mines I dispatch an event to unfold surrounding tiles until a mine is around. This is called a flood-fill algorithm with a really simple implementation. In function showUntilMineAround, I check each surrounding tile if it has any mines around or not. If it doesn’t this means that we can unfold more neighboring tiles, so I set the current tile as open and then continue my search calling the same function recursively. Although calling the same function recursively could lead to an infinite loop causing the app to hang I avoid this case by setting in advance the tile to open and then if the tile is already open I return to the parent caller (that might seem a little confusing at first so if you didn’t understand it I urge you to search about recursively calling a function). When I spot a tile that has a mine around I also stop the search at this tile by returning to the parent caller.
That’s just about it. This is a simple sample and tutorial on how to create a minesweeper. I hope you liked this guide, the same as I’ve enjoyed creating it, and as my student appreciated it.
Well, long time no see. I’ve been busy. Work, personal life etc. Well, who am I kidding… just work. But lately I’ve found some free time and it’s time to get back to blogging again. Lately I’ve been at work with multiplayer games, and for that purpose I’ve used mostly SmartFoxServer. There are other alternatives, like Photon which is programmable in C#, but I prefer SmartFox because it is installable in a linux box, which I mostly use (and is cheaper in Amazon S3). I’ve noticed that SmartFox didn’t have lots of basic tutorials that explain the process as simple as it can be to test it, so I will be creating one. Also I’m doing this just to have a reference. So without further ado, let’s start.
In case you haven’t heard Adobe has released a new compiler for Flash and ActionScript. The new compiler does exactly what the legacy does, and mostly without any changes, but faster and better. Or at least that’s what it is supposed to do, but it’s still in Beta. So far you could only try it with Flash Builder 4.7 but thankfully there is a workaround for flashdevelop.
This post is based from this one by Alama, so in case you know French go on and prefer his guide.