My mother went from improving to a very rapid decline and passed away July 29th at 1:05AM. She meant the world to me and will be greatly missed. While I posted a game on BlazingGames.com this week as the game ready to post, I will be taking a few week break from posting new material. I am many weeks ahead on this blog for material so may still post the weekly articles here but I can not guarantee this. Here is the continuation of my How Many Games can I Develop in 24 hours challenge.
Creating the Sliding Puzzle game is fairly straightforward as the only real game mechanic that needs to be implemented is the slider. The slider is simply the bottom right-most tile set to be highlighted with the highlight color being near-opaque. The reason for making it near-opaque instead of fully-opaque is that I felt the game would be better if you knew what part of the image the slider represented but it had to be dark enough that it was obviously the slider. Creating the slider, then, required very little code.
this.slider = new BGLayers.Point(tw-1, th-1);
this.view.setTileHighlight(tw-1, th-1, true);
this.view.setColors("rgb(100,0,100)", "green", "red", .5, .9);
With the slider on the board, the only other major game-play mechanic became moving the slider around. I decided that the best way to implement the movement of the slider would be to simply take a point that represents where the slider is to be moved to and then move the slider horizontally until it is at the proper x location and then vertically until it is at the proper y location.
PuzzleGallery.SlidingPuzzleGame.prototype.moveSlider = function(p)
{
this.view.setTileHighlight(this.slider.x, this.slider.y, false);
while (this.slider.x < p.x) {
this.puzzle.swapPuzzlePieces(this.slider.x, this.slider.y, this.slider.x+1, this.slider.y);
++this.slider.x;
};
while (this.slider.x > p.x) {
this.puzzle.swapPuzzlePieces(this.slider.x, this.slider.y, this.slider.x-1, this.slider.y);
--this.slider.x;
};
while (this.slider.y < p.y) {
this.puzzle.swapPuzzlePieces(this.slider.x, this.slider.y, this.slider.x, this.slider.y+1);
++this.slider.y;
};
while (this.slider.y > p.y) {
this.puzzle.swapPuzzlePieces(this.slider.x, this.slider.y, this.slider.x, this.slider.y-1);
--this.slider.y;
};
this.view.setTileHighlight(this.slider.x, this.slider.y, true);
this.view.update();
}
This made implementing the mouse very easy as you simply call the moveSlider function with the point passed by the onTileClick call that BasePuzzleView makes when a tile is clicked. While having both horizontal and vertical movement at once was nice, after playing the game I worried that it might be too confusing to the player so altered the onTileClick function to only allow the slider to move when the move was only horizontal or vertical.
The other thing I was worried about is that the scrambling of the puzzle was not based on the game-play mechanic. While I am positive that this shouldn’t matter and that any scrambled puzzle should be solvable, I decided not to take any chances and wrote my own Sliding Puzzle Game scrambling function. This simply moves the slider around by randomly selecting points on the puzzle and calling the moveSlider function using that point.
PuzzleGallery.SlidingPuzzleGame.prototype.scramble = function()
{
var p = new BGLayers.Point();
var w = this.puzzle.puzzleWidth;
var h = this.puzzle.puzzleHeight;
var n = w * h * 10;
for (var cntr = 0; cntr < n; ++cntr) {
p.x = Math.floor(Math.random() * w);
p.y = Math.floor(Math.random() * h);
this.moveSlider(p);
}
}
And with that done, we have finished a second game. For the third game, however, I am not going to go with the rotation puzzle but have a different sort of twist in mind.
Friday, July 29, 2011
Thursday, July 21, 2011
DDTe3 Hour 7 - Making a Slider
As mentioned last post, to make it easier to remember to post, I am going to post the blog at the same time I update Blazing Games. This week I am continuing my series of articles on the creation of Dozen Days of Tiles episode 3 which is an as many games as I can develop in under 24 hours of development time challenge. So far the picture puzzle game has been created so development on a sliding puzzle has just started.
After finishing the first game, most of the work is now present that additional games should be able to be created quickly. The second game that I have in mind is a sliding puzzle. To get the functionality needed to create the game, a slider has to be moved around the game board. This can be handled by swapping pieces so no additional features need to be added to the base puzzle model. However, there needs to be a visible slider on the screen so some extensions will need to be added to the base model view class.
While thinking about how to actually add the tile, my first thought was to simply make the highlight as the tile. As clicking on a tile will cause the slider to move, no highlight is needed for this game so all the work is already done. The only downside to this approach is that it would require a more-solid highlight but since I want to add the ability to change the border and highlight colors anyway, the slider would be essentially free. Another route that I could have taken would be to simply add an ability to grab a tiles display position so I could simply add a sprite over-top of the board.
To allow the tile border and highlight colors to be changed, a setColors function was added to the TileBorder class. The class uses both colors and alpha values as I had decided when creating the HighlightBlock class to keep the alpha value separate from the color. My thoughts at the time were that it allows for alpha effects to be implemented much easier and has the side benifit that normal color labels (such as red or blue) can then be used rather than requiring the use of the rgba() function to specify colors.
Finally, in the BaseModelView class, a set colors class was added which simply calls the setColor class for every border in the view.
PuzzleGallery.BasePuzzleView.prototype.setColors = function(col, ccol, ecol, ba, ha)
{
var w = this.puzzle.puzzleWidth;
var h = this.puzzle.puzzleHeight;
var n = w * h;
for (var indx = 0; indx < n; ++indx) {
this.tileBorders[indx].setColors(col, ccol, ecol, ba, ha);
}
this.addDirty(null);
}
We now have everything needed to create a slider so the next step is to create a sliding puzzle game.
After finishing the first game, most of the work is now present that additional games should be able to be created quickly. The second game that I have in mind is a sliding puzzle. To get the functionality needed to create the game, a slider has to be moved around the game board. This can be handled by swapping pieces so no additional features need to be added to the base puzzle model. However, there needs to be a visible slider on the screen so some extensions will need to be added to the base model view class.
While thinking about how to actually add the tile, my first thought was to simply make the highlight as the tile. As clicking on a tile will cause the slider to move, no highlight is needed for this game so all the work is already done. The only downside to this approach is that it would require a more-solid highlight but since I want to add the ability to change the border and highlight colors anyway, the slider would be essentially free. Another route that I could have taken would be to simply add an ability to grab a tiles display position so I could simply add a sprite over-top of the board.
To allow the tile border and highlight colors to be changed, a setColors function was added to the TileBorder class. The class uses both colors and alpha values as I had decided when creating the HighlightBlock class to keep the alpha value separate from the color. My thoughts at the time were that it allows for alpha effects to be implemented much easier and has the side benifit that normal color labels (such as red or blue) can then be used rather than requiring the use of the rgba() function to specify colors.
Finally, in the BaseModelView class, a set colors class was added which simply calls the setColor class for every border in the view.
PuzzleGallery.BasePuzzleView.prototype.setColors = function(col, ccol, ecol, ba, ha)
{
var w = this.puzzle.puzzleWidth;
var h = this.puzzle.puzzleHeight;
var n = w * h;
for (var indx = 0; indx < n; ++indx) {
this.tileBorders[indx].setColors(col, ccol, ecol, ba, ha);
}
this.addDirty(null);
}
We now have everything needed to create a slider so the next step is to create a sliding puzzle game.
Sunday, July 17, 2011
DDTe3 Hours 5 to 6 The Picture Puzzle Game
My mother is still in the hospital, which is at least part of the reason I missed posting this last week. I am thinking about updating this blog the same time that I update the Blazing Games site, but kind of want to keep them separate to emphasis the fact that they are separate things. The few people who actually read this probably already realize this and combining the posting dates may make things easier so don't be surprised if the blog starts being updated late Thursday nights (PST). This is continuing the development of Dozen Days of Tiles episode 3 which is a how many games can I develop in 24 hours challenge instead of the usual developing a game in under 24 hours challenge.
With the puzzle displaying, we are most of the way to a playable picture puzzle game. The only issue remaining that must be solved is input. The mouse input is handled by the BasePuzzleView class by calling a listener function. As this listener function can be set by any of the games, it is not game dependent. Instead, the function that gets called is what holds the game-play logic.
The information that the game needs to know is what tile was selected. There are a number of ways this information can be passed, but the most universally useful way is simply to indicate the row and column that was selected as any other information can be derived from that knowledge. Determining this is a bit more problematic as BGLayers passes real mouse positions not logical ones. This conversion from real to logical coordinates is something that BGLayers probably should have functions to handle but it does not. Still, this is very easy to calculate as it is essentially just a scaling calculation.
var rp = this.findRealPosition();
var lx = (x - rp.x) * (this._logicalSize.width / rp.width);
var ly = (y - rp.y) * (this._logicalSize.height / rp.height);
var p = new BGLayers.Point(Math.floor((lx - this.tileLeft) / this.tileWidth),
Math.floor((ly - this.tileTop) / this.tileHeight));
The game logic to handle the click simply stores the first tile clicked on as the selector and the second click swaps the two tiles. At this point we have a playable game but three problems immediately come to mind. First, there is no visible way of knowing what tile was selected. Second, it isn't always obvious where the tiles are. Third, there is no indication about which tiles are correct or not. The second and third problems can be solved by adding a border that has an optional hint capability. But instead of just having a border, why not add a highlight feature to the border as well and get a hat-trick. For those of you not familiar with Hockey, a hat-trick is when a player scores three goals in a single game.
The TileBorder class simply consists of the four borders and the highlight. The class holds 3 colors one highlight color, one correct color and one incorrect color. The correctness is handled by a setCorrect(b) function that sets the border colors to the correct color if passed true and to the error color if passed false. The highlight is set to the highlight color and is initially invisible but can be turned on (or off again) by calling the setHighlight function.
In my first attempt of implementing this, the borders were just layer classes but I discovered that the rgba colors were not working. This was obviously because the layers by default are solid. Unfortunately, setting them to transparent has the side effect of not drawing the background color making them invisible. This makes sense as the layers are placeholders that draw a background color if necessary and if the layer isn't solid then no background is needed. A new class, the HightlightBlock, was quickly created to draw a solid block. Instead of using rgba colors for transparency, I instead opted for a separate alpha channel. While not utilized yet, it opens the possibility of alternating the transparency without having to worry about the color.
The tile borders are then added to the BasePuzzleView class after the tiles are created so that the borders will always be above the tiles. The update method then adds a single line to it's update loop:
this.tileBorders[indx].setCorrect(tile == indx);
This line sets the correctness color of the border. With that we have a fully playable game. One game down and at least another 3 to go.
With the puzzle displaying, we are most of the way to a playable picture puzzle game. The only issue remaining that must be solved is input. The mouse input is handled by the BasePuzzleView class by calling a listener function. As this listener function can be set by any of the games, it is not game dependent. Instead, the function that gets called is what holds the game-play logic.
The information that the game needs to know is what tile was selected. There are a number of ways this information can be passed, but the most universally useful way is simply to indicate the row and column that was selected as any other information can be derived from that knowledge. Determining this is a bit more problematic as BGLayers passes real mouse positions not logical ones. This conversion from real to logical coordinates is something that BGLayers probably should have functions to handle but it does not. Still, this is very easy to calculate as it is essentially just a scaling calculation.
var rp = this.findRealPosition();
var lx = (x - rp.x) * (this._logicalSize.width / rp.width);
var ly = (y - rp.y) * (this._logicalSize.height / rp.height);
var p = new BGLayers.Point(Math.floor((lx - this.tileLeft) / this.tileWidth),
Math.floor((ly - this.tileTop) / this.tileHeight));
The game logic to handle the click simply stores the first tile clicked on as the selector and the second click swaps the two tiles. At this point we have a playable game but three problems immediately come to mind. First, there is no visible way of knowing what tile was selected. Second, it isn't always obvious where the tiles are. Third, there is no indication about which tiles are correct or not. The second and third problems can be solved by adding a border that has an optional hint capability. But instead of just having a border, why not add a highlight feature to the border as well and get a hat-trick. For those of you not familiar with Hockey, a hat-trick is when a player scores three goals in a single game.
The TileBorder class simply consists of the four borders and the highlight. The class holds 3 colors one highlight color, one correct color and one incorrect color. The correctness is handled by a setCorrect(b) function that sets the border colors to the correct color if passed true and to the error color if passed false. The highlight is set to the highlight color and is initially invisible but can be turned on (or off again) by calling the setHighlight function.
In my first attempt of implementing this, the borders were just layer classes but I discovered that the rgba colors were not working. This was obviously because the layers by default are solid. Unfortunately, setting them to transparent has the side effect of not drawing the background color making them invisible. This makes sense as the layers are placeholders that draw a background color if necessary and if the layer isn't solid then no background is needed. A new class, the HightlightBlock, was quickly created to draw a solid block. Instead of using rgba colors for transparency, I instead opted for a separate alpha channel. While not utilized yet, it opens the possibility of alternating the transparency without having to worry about the color.
The tile borders are then added to the BasePuzzleView class after the tiles are created so that the borders will always be above the tiles. The update method then adds a single line to it's update loop:
this.tileBorders[indx].setCorrect(tile == indx);
This line sets the correctness color of the border. With that we have a fully playable game. One game down and at least another 3 to go.
Monday, July 4, 2011
DDTe3 Hours 2 to 4 Drawing the Puzzle
As my Mother is still in the hospital, I am quite thankful that I have been writing my development articles as the games were written so I am months ahead of schedule when it comes to material that is ready to post. If only I could remember to post things on time :). This series was interrupted by a couple of weeks to celebrate the release of Duke Nukem Forever and to take a brief look at my ImageAtlas library but now we continue by developing the core classes that will allow me to create a lot of games really quickly.
The BasePuzzleView class has the job of displaying the puzzle. This puzzle is drawn from an image that is passed into this class. To make the game as flexible as possible, I want to be able to use only part of an image. This makes it easier to work with images that only have a partially usable portion. More important, at least in my situation, it makes it possible to maintain the proper aspect ratio for an image that is a different size than the canvas the game is going to be played in. While it is certainly possible to make the canvas a proportional size to the image being used, I like to keep my canvas a constant size. As my BGLayers library already has a rectangle class, it is simple enough to pass in a clipping region. Finally, we need the model class being displayed. With this information we have the constructor for our class.
When I started to write this class, two ways of implementing it came immediately to my mind. One way would be to have the class do all the bitmap manipulation itself when drawing. The other would be to have the class made up of a bunch of child ImageLayers that hold all the pieces of the puzzle. The first method removes a lot of overhead from having a lot of layers on the display list at a cost of a very difficult rendering process. While more efficient, speed probably is not going to be an issue whatsoever with any of the games that make up this project, so the easier to implement child path is the one I decided to go with.
The first step I then went on to implement was determining if borders were necessary. My old-school thinking was that tiles should be integers which means that it is possible for there to be borders. I was not thinking that the view is a layer that uses logical coordinates and is going to be scaled and that partial pixels are already handled by BGLayers. This is a weird lack of thinking as I am taking advantage of how BGLayers uses logical coordinates by setting the size of the layer to the size of the clipping region. Still, this is a fairly simple problem to solve. The tile size is determined by dividing width and height of the clipped image by the number of columns and rows of the puzzle. This is rounded down so the borders width is simply the width of the image clip minus the width of the tiles multiplied by the number of columns in the puzzle. Likewise the height of the borders is simply the height of the image clip minus the hight of the tiles multiplied by the number of rows in the puzzle.
The size of the individual borders is half the size of the border. If the border is an odd size, one border needs to be a pixel bigger than the other border for whatever orientation the border represents (top/bottom or left/right). The easiest way of doing this is to make the first border the total size of the borders divided by two rounded down and the other border being equal to the size of both the borders minus the size of the first border. This way of dealing with splitting odd integers is a handy trick to remember if you have to deal with integers a lot. Using integers was something that use to be important to graphics programming (when floating point numbers were thought to be evil due to how slow non-hardware accelerated floating point was) but is not so much the case anymore.
Once the borders have been created, it is very easy to lay out the tiles as the following code segment clearly shows.
indx = 0;
for (cntrR = 0; cntrR < puzzle.puzzleHeight; ++cntrR) {
for (cntrC = 0; cntrC < puzzle.puzzleWidth; ++cntrC) {
this.tiles[indx] = new BGLayers.ImageLayer("tile"+indx, img);
rect = new BGLayers.Rectangle(left + this.tileWidth * cntrC,
top + this.tileHeight * cntrR,
this.tileWidth, this.tileHeight);
this.tiles[indx].setClip(rect);
this.addChild(this.tiles[indx], rect);
++indx;
}
}
The only problem is that the tiles are laid out in the proper order, not in the order reflected in the current state of the puzzle data. This problem had me stumped for a second or two, but then I realized that all I needed to do was move the tiles to the position they are supposed to be in. As this is something that happens every time the puzzle data changes, an update function was created to deal with this task.
PuzzleGallery.BasePuzzleView.prototype.update = function()
{
var cntrR, cntrC, indx, tile;
var w = this.puzzle.puzzleWidth;
var h = this.puzzle.puzzleHeight;
indx = 0;
for (cntrR = 0; cntrR < h; ++cntrR) {
for (cntrC = 0; cntrC < w; ++cntrC) {
tile = this.puzzle.getPuzzlePiece(cntrC, cntrR);
this.tiles[tile].moveTo( this.tileLeft + cntrC * this.tileWidth,
this.tileTop + cntrR * this.tileHeight);
this.tileBorders[indx].setCorrect(tile == indx);
++indx;
}
}
this.addDirty(null);
}
The best part is that to make the tiles animate to their new position, I can simply create an animateTo function within the BGLayers library and have all the work done for me. I don't know if I will have time to do this within the 24 hours alloted to this project, but it is certainly something that I want to add to the BGLayers library eventually.
Now that we have the puzzle being displayable, we need to get on with creating a game. That, as you have already guessed, will be covered next week.
The BasePuzzleView class has the job of displaying the puzzle. This puzzle is drawn from an image that is passed into this class. To make the game as flexible as possible, I want to be able to use only part of an image. This makes it easier to work with images that only have a partially usable portion. More important, at least in my situation, it makes it possible to maintain the proper aspect ratio for an image that is a different size than the canvas the game is going to be played in. While it is certainly possible to make the canvas a proportional size to the image being used, I like to keep my canvas a constant size. As my BGLayers library already has a rectangle class, it is simple enough to pass in a clipping region. Finally, we need the model class being displayed. With this information we have the constructor for our class.
When I started to write this class, two ways of implementing it came immediately to my mind. One way would be to have the class do all the bitmap manipulation itself when drawing. The other would be to have the class made up of a bunch of child ImageLayers that hold all the pieces of the puzzle. The first method removes a lot of overhead from having a lot of layers on the display list at a cost of a very difficult rendering process. While more efficient, speed probably is not going to be an issue whatsoever with any of the games that make up this project, so the easier to implement child path is the one I decided to go with.
The first step I then went on to implement was determining if borders were necessary. My old-school thinking was that tiles should be integers which means that it is possible for there to be borders. I was not thinking that the view is a layer that uses logical coordinates and is going to be scaled and that partial pixels are already handled by BGLayers. This is a weird lack of thinking as I am taking advantage of how BGLayers uses logical coordinates by setting the size of the layer to the size of the clipping region. Still, this is a fairly simple problem to solve. The tile size is determined by dividing width and height of the clipped image by the number of columns and rows of the puzzle. This is rounded down so the borders width is simply the width of the image clip minus the width of the tiles multiplied by the number of columns in the puzzle. Likewise the height of the borders is simply the height of the image clip minus the hight of the tiles multiplied by the number of rows in the puzzle.
The size of the individual borders is half the size of the border. If the border is an odd size, one border needs to be a pixel bigger than the other border for whatever orientation the border represents (top/bottom or left/right). The easiest way of doing this is to make the first border the total size of the borders divided by two rounded down and the other border being equal to the size of both the borders minus the size of the first border. This way of dealing with splitting odd integers is a handy trick to remember if you have to deal with integers a lot. Using integers was something that use to be important to graphics programming (when floating point numbers were thought to be evil due to how slow non-hardware accelerated floating point was) but is not so much the case anymore.
Once the borders have been created, it is very easy to lay out the tiles as the following code segment clearly shows.
indx = 0;
for (cntrR = 0; cntrR < puzzle.puzzleHeight; ++cntrR) {
for (cntrC = 0; cntrC < puzzle.puzzleWidth; ++cntrC) {
this.tiles[indx] = new BGLayers.ImageLayer("tile"+indx, img);
rect = new BGLayers.Rectangle(left + this.tileWidth * cntrC,
top + this.tileHeight * cntrR,
this.tileWidth, this.tileHeight);
this.tiles[indx].setClip(rect);
this.addChild(this.tiles[indx], rect);
++indx;
}
}
The only problem is that the tiles are laid out in the proper order, not in the order reflected in the current state of the puzzle data. This problem had me stumped for a second or two, but then I realized that all I needed to do was move the tiles to the position they are supposed to be in. As this is something that happens every time the puzzle data changes, an update function was created to deal with this task.
PuzzleGallery.BasePuzzleView.prototype.update = function()
{
var cntrR, cntrC, indx, tile;
var w = this.puzzle.puzzleWidth;
var h = this.puzzle.puzzleHeight;
indx = 0;
for (cntrR = 0; cntrR < h; ++cntrR) {
for (cntrC = 0; cntrC < w; ++cntrC) {
tile = this.puzzle.getPuzzlePiece(cntrC, cntrR);
this.tiles[tile].moveTo( this.tileLeft + cntrC * this.tileWidth,
this.tileTop + cntrR * this.tileHeight);
this.tileBorders[indx].setCorrect(tile == indx);
++indx;
}
}
this.addDirty(null);
}
The best part is that to make the tiles animate to their new position, I can simply create an animateTo function within the BGLayers library and have all the work done for me. I don't know if I will have time to do this within the 24 hours alloted to this project, but it is certainly something that I want to add to the BGLayers library eventually.
Now that we have the puzzle being displayable, we need to get on with creating a game. That, as you have already guessed, will be covered next week.
Tuesday, June 28, 2011
Flash Image Atlas Animation System. Why?
This was suppose to be posted on Sunday, but with my mother going into the hospital, I kind of forgot about posting it. Sorry for the delay.
As part of my larger project, I have decided to develop my own animation system. As this larger project is currently being done in Flash, which is essentially an animation system with a powerful programming language tacked on to it, this may seem redundant. If I knew for sure that the project was going to be exclusively done in Flash, it would be. The truth is that I may end up having to port the game to other devices. While Flash is sort of runnable on portable devices, the performance currently isn't quite there. If, when my game is in a near finished state, the game runs fine on the target devices then there is no issue. However, this is not necessarily going to be the case so I have been looking into what would be involved in porting a game by creating a native version for certain devices.
OpenGL ES is pretty much the standard for all the devices I am thinking about targeting. While studying OpenGL one common optimization that comes highly recommended is to combine the textures that one is using into something called an image atlas. As it turns out, an image atlas is a more advanced version of image strips (aka sprite strips) and image grids (aka image sheets or sprite sheets). Image strips/sheets are what I was using for my Java games so I am well versed in the technique.
A lot of the artwork for my larger-scale game is bitmap graphics so creating a library that allows for an image atlas to drive an animation would be convenient and make porting easier. Spending a development week or two to get this functionality is really not much of a loss while the benefits are potentially great. I define a development week to be 40 hours which is a typical work week in Canada. As my work on the large scale game is part time, it may take two or three weeks in real world time for a development week. I plan on porting it to HTML 5 and possibly other platforms. Not too long ago I created a simple image atlas class for my HTML 5 JavaScript graphics library so an HTML 5 port so the HTML 5 version should be fairly quick to develop. This will give me a common set of components that will make it much easier to switch between platforms. While I personally believe that Flash will be around for a while, having an easy path to other platforms doesn't hurt.
In fact, with Microsoft not supporting Web GL in IE 9, any web-based will have to use a plug-in such as the upcoming Flash 11 to support 3D graphics in a cross-platform way. While Microsoft is claiming security issues (WebGL is fundementally far more secure than Microsoft's Active X which is still in IE), I hear that in Windows 8 there will be browser support for accessing Direct X 11. Since Direct X is essentially a less-secure version of Open GL (what WebGL is based on) I am wondering what Microsoft's true motivations for not supporting WebGL are. Still, I see the future of 3D on the web being Flash. Ideally it will be a WebGL with fallback to Flash future but more likely it will be just Flash with paid iOS apps for Apple users. Thanks Microsoft.
As part of my larger project, I have decided to develop my own animation system. As this larger project is currently being done in Flash, which is essentially an animation system with a powerful programming language tacked on to it, this may seem redundant. If I knew for sure that the project was going to be exclusively done in Flash, it would be. The truth is that I may end up having to port the game to other devices. While Flash is sort of runnable on portable devices, the performance currently isn't quite there. If, when my game is in a near finished state, the game runs fine on the target devices then there is no issue. However, this is not necessarily going to be the case so I have been looking into what would be involved in porting a game by creating a native version for certain devices.
OpenGL ES is pretty much the standard for all the devices I am thinking about targeting. While studying OpenGL one common optimization that comes highly recommended is to combine the textures that one is using into something called an image atlas. As it turns out, an image atlas is a more advanced version of image strips (aka sprite strips) and image grids (aka image sheets or sprite sheets). Image strips/sheets are what I was using for my Java games so I am well versed in the technique.
A lot of the artwork for my larger-scale game is bitmap graphics so creating a library that allows for an image atlas to drive an animation would be convenient and make porting easier. Spending a development week or two to get this functionality is really not much of a loss while the benefits are potentially great. I define a development week to be 40 hours which is a typical work week in Canada. As my work on the large scale game is part time, it may take two or three weeks in real world time for a development week. I plan on porting it to HTML 5 and possibly other platforms. Not too long ago I created a simple image atlas class for my HTML 5 JavaScript graphics library so an HTML 5 port so the HTML 5 version should be fairly quick to develop. This will give me a common set of components that will make it much easier to switch between platforms. While I personally believe that Flash will be around for a while, having an easy path to other platforms doesn't hurt.
In fact, with Microsoft not supporting Web GL in IE 9, any web-based will have to use a plug-in such as the upcoming Flash 11 to support 3D graphics in a cross-platform way. While Microsoft is claiming security issues (WebGL is fundementally far more secure than Microsoft's Active X which is still in IE), I hear that in Windows 8 there will be browser support for accessing Direct X 11. Since Direct X is essentially a less-secure version of Open GL (what WebGL is based on) I am wondering what Microsoft's true motivations for not supporting WebGL are. Still, I see the future of 3D on the web being Flash. Ideally it will be a WebGL with fallback to Flash future but more likely it will be just Flash with paid iOS apps for Apple users. Thanks Microsoft.
Sunday, June 19, 2011
Thoughts on Forever
I am going to delay my series of articles on the creation of episode 3 of Dozen Days of Tiles for a couple of weeks so I can touch on a couple of other topics. The big news in computer gaming (and to a lesser extent video gaming) circles is the release of Duke Nukem Forever (DNF). The reviews have been more negative than positive. Some of the negative reviews are negative because of the games play mechanics and other game play issues. These are fine and I consider them valid criticism. Other reviewers are those people that incorrectly think the game should be better because it took so long to develop. These people annoy me because the development time for DNF has nothing to do with its quality. There are a large number of reasons for this, but lets just look at the top three reasons.
First of all, the number of years a project is in development is not related to the development years of a project. A development year is one person working full time on a project for a year. If I spend 4 years working on a game and a team of 4 perfectly coordinated developers worked 1 year on the same type of game, the amount of time spent developing the two games is the same. My game should not be better because it took 4 times as long to develop because it didn't. Therefore, looking at the development time of a game strictly based on the number of years it has been in development is just stupid.
Second, the game changed game engines and major subsystems multiple times during development. This is not something that can be considered lightly as porting code from one platform to another is going to take a good chunk of time. In some cases, you may even need to spend a good chunk of time to recreate functionality if the features of the new engine are different. This is why very few games change their underlying engine mid-stream.
Finally, a huge part of the repeated delays of the game was a result of playing catchup. Many programmers, myself included, have worked on projects that have a moving goalpost. What happens is that you have your initial specifications and you work hard to reach these. Months before reaching the goal there is a review of the project and the big-wig decides that things have changed so new specifications are created requiring major changes to the existing code so the project is delayed and just before the project is finished, the big-wig shows up again and ... repeat until either the big-wig or the project (or both) are dead. DNF was clearly caught in the trap of trying to stay ahead of the game market. Every time it started getting near completion, enough time had passed that the game was no longer meeting the cutting edge requirements of management so the game would be delayed to allow time to catch up with the rest of the industry.
This is similar to what has happened with my Coffee Quest 5 project, the difference being that CQ5 has not been in development for all this time. My problem with CQ5 was more of a wanting a browser based game that would be able to use technology that simply was not available in browsers. The few times I did start on the project, it was quickly put on ice again as the technology simply wasn't there. While there were some Java 3D libraries, they simply did not work well within the browser as I discovered when a huge number of people had issues running CQGL. I had considered porting Coffee Quest to Flash and use PaperVision, but found that it had issues and Flash Player 10 was going to have some limited 3D support. So I waited for Flash Player 10 only to discover that the 3D effects had major sorting issues. Now there is the upcoming Mole-Hill version of Flash in beta as well as Web GL so the possibility of finally developing CQ5 is in my mind again.
Had I not had unrealistic expectations for the speed of browser development, I probably would have just enhanced my existing ray-caster or possibly even developed a simple software 3D library and released CQ5 many years ago. Sadly, I had Hardware 3D in the back of my mind and CQ5 ended up on the back-burner as I waited for Adobe or browser venders to finally put proper 3D into browsers. Something that really should have happened a decade ago but still hasn't happened.
While DNF may suck, I wonder how much of it has to do with overly high expectations and how much has to do with poor game play. I won't know the answer to that question until I see a copy of DNF in the bargain bin, as going by the reviewers I trust the game is not worth full price (and probably not worth bargain bin prices either but I am curious).
First of all, the number of years a project is in development is not related to the development years of a project. A development year is one person working full time on a project for a year. If I spend 4 years working on a game and a team of 4 perfectly coordinated developers worked 1 year on the same type of game, the amount of time spent developing the two games is the same. My game should not be better because it took 4 times as long to develop because it didn't. Therefore, looking at the development time of a game strictly based on the number of years it has been in development is just stupid.
Second, the game changed game engines and major subsystems multiple times during development. This is not something that can be considered lightly as porting code from one platform to another is going to take a good chunk of time. In some cases, you may even need to spend a good chunk of time to recreate functionality if the features of the new engine are different. This is why very few games change their underlying engine mid-stream.
Finally, a huge part of the repeated delays of the game was a result of playing catchup. Many programmers, myself included, have worked on projects that have a moving goalpost. What happens is that you have your initial specifications and you work hard to reach these. Months before reaching the goal there is a review of the project and the big-wig decides that things have changed so new specifications are created requiring major changes to the existing code so the project is delayed and just before the project is finished, the big-wig shows up again and ... repeat until either the big-wig or the project (or both) are dead. DNF was clearly caught in the trap of trying to stay ahead of the game market. Every time it started getting near completion, enough time had passed that the game was no longer meeting the cutting edge requirements of management so the game would be delayed to allow time to catch up with the rest of the industry.
This is similar to what has happened with my Coffee Quest 5 project, the difference being that CQ5 has not been in development for all this time. My problem with CQ5 was more of a wanting a browser based game that would be able to use technology that simply was not available in browsers. The few times I did start on the project, it was quickly put on ice again as the technology simply wasn't there. While there were some Java 3D libraries, they simply did not work well within the browser as I discovered when a huge number of people had issues running CQGL. I had considered porting Coffee Quest to Flash and use PaperVision, but found that it had issues and Flash Player 10 was going to have some limited 3D support. So I waited for Flash Player 10 only to discover that the 3D effects had major sorting issues. Now there is the upcoming Mole-Hill version of Flash in beta as well as Web GL so the possibility of finally developing CQ5 is in my mind again.
Had I not had unrealistic expectations for the speed of browser development, I probably would have just enhanced my existing ray-caster or possibly even developed a simple software 3D library and released CQ5 many years ago. Sadly, I had Hardware 3D in the back of my mind and CQ5 ended up on the back-burner as I waited for Adobe or browser venders to finally put proper 3D into browsers. Something that really should have happened a decade ago but still hasn't happened.
While DNF may suck, I wonder how much of it has to do with overly high expectations and how much has to do with poor game play. I won't know the answer to that question until I see a copy of DNF in the bargain bin, as going by the reviewers I trust the game is not worth full price (and probably not worth bargain bin prices either but I am curious).
Sunday, June 12, 2011
DDTe3 Hour 1 Planning and the Puzzle Model
For the third episode of Dozen Days of Tiles, my series where I develop games with a particular theme in under 24 hours of development time, I decided to twist the concept of developing a game in a day and instead trying to develop as many games as I can within the 24 hours. I know that while the work is done in 24 hours, because the work is spread out over multiple days, it is not the same as if I did the work in a single day. Having done the Dozen Days of Dice series as game in a day stints, I know that after twelve hours of coding the mind starts working against you. That said, finding a solid day to work on something is increasingly more difficult and can be easily interrupted even if such a rare block of time can be found. I also want to document my experience in the form of these blog posts. I do not count the time I spend writing these posts towards the 24 hours but I am trying to write the posts shortly after I put in a programming stint so the thought process at the time is preserved.
Part of the reason for the desire to create multiple games for this episode is directly related to the return of a weekly format for Blazing Games. While the weekly format is more iterative than it has been in the past, allowing for games to evolve into more complex games over time, I still prefer having a buffer of material so that if a larger third-party project interrupts my site work, the schedule will not need to be adjusted.
Creating multiple games in a 24 hour period leaves the question what set of games are tile related, and have similar enough game mechanics that the work on one can be utilized in allowing the related games to be created. At the same time, I am looking at some of the older games on the Blazing Games site and am trying to figure out what should be done with them. The Flash games can be enhanced as Flash is going to be around for a while yet. The Java games, sadly, are in a more precarious position so consideration should be made towards porting them to HTML5. Looking at some of the Java games that I have done, I noticed my picture puzzle series of games. These are simple enough games that I don't need to port the games at all but can instead re-write them from scratch without loosing that much time. In fact, with all the knowledge that I have gained over the years, I should be able to get the core picture puzzle game functional very quickly.
With the game in mind, it is time to start on the project. While having a client-model-view architecture is probably a bit of overkill for this series, it doesn't hurt so I will start by creating the model. This class is being called BasePuzzleModel in the project.
The model creates a two-dimensional array to hold the grid. In JavaScript, 2D arrays are created by making an array of arrays. The model could have also simply created a single array the size of the width times the height of the grid and mathematically determined the position of the tile. I chose to go with the the two-dimensional approach because that way the internal structure of the grid more closely matches the problem being solved. Still, as the tiles are then assigned linear values to represent their proper position, in hindsight going with a single dimensional array would have been easier and just as logical. As I write this, I am only 6 hours into the project and could change things but as the internal structure of the model is theoretically hidden from the classes that use it there would be no point changing it.
As briefly explained in the paragraph above, each tile is assigned an index value that is linear based on the row and column. The index is equal to the row * the width of the puzzle plus the column. By having the linear sequence of tile values, it is possible to easily determine if the puzzle is correct by simply seeing if the tiles are in order. Some simple convenience functions were created for manipulating the puzzle and within an hour we have the model up and running. The functions added were getPuzzlePiece(x,y), setPuzzlePiece(x,y, n), swapPuzzlePieces(x1,y1,x2,y2), scrambleBoard() and checkWin(). These are all fairly straightforward so I won’t delve into the details of these.
The next phase is to turn the model into something visible. The obvious class for this job would be something called the BasePuzzleView, which we will look at next week.
Part of the reason for the desire to create multiple games for this episode is directly related to the return of a weekly format for Blazing Games. While the weekly format is more iterative than it has been in the past, allowing for games to evolve into more complex games over time, I still prefer having a buffer of material so that if a larger third-party project interrupts my site work, the schedule will not need to be adjusted.
Creating multiple games in a 24 hour period leaves the question what set of games are tile related, and have similar enough game mechanics that the work on one can be utilized in allowing the related games to be created. At the same time, I am looking at some of the older games on the Blazing Games site and am trying to figure out what should be done with them. The Flash games can be enhanced as Flash is going to be around for a while yet. The Java games, sadly, are in a more precarious position so consideration should be made towards porting them to HTML5. Looking at some of the Java games that I have done, I noticed my picture puzzle series of games. These are simple enough games that I don't need to port the games at all but can instead re-write them from scratch without loosing that much time. In fact, with all the knowledge that I have gained over the years, I should be able to get the core picture puzzle game functional very quickly.
With the game in mind, it is time to start on the project. While having a client-model-view architecture is probably a bit of overkill for this series, it doesn't hurt so I will start by creating the model. This class is being called BasePuzzleModel in the project.
The model creates a two-dimensional array to hold the grid. In JavaScript, 2D arrays are created by making an array of arrays. The model could have also simply created a single array the size of the width times the height of the grid and mathematically determined the position of the tile. I chose to go with the the two-dimensional approach because that way the internal structure of the grid more closely matches the problem being solved. Still, as the tiles are then assigned linear values to represent their proper position, in hindsight going with a single dimensional array would have been easier and just as logical. As I write this, I am only 6 hours into the project and could change things but as the internal structure of the model is theoretically hidden from the classes that use it there would be no point changing it.
As briefly explained in the paragraph above, each tile is assigned an index value that is linear based on the row and column. The index is equal to the row * the width of the puzzle plus the column. By having the linear sequence of tile values, it is possible to easily determine if the puzzle is correct by simply seeing if the tiles are in order. Some simple convenience functions were created for manipulating the puzzle and within an hour we have the model up and running. The functions added were getPuzzlePiece(x,y), setPuzzlePiece(x,y, n), swapPuzzlePieces(x1,y1,x2,y2), scrambleBoard() and checkWin(). These are all fairly straightforward so I won’t delve into the details of these.
The next phase is to turn the model into something visible. The obvious class for this job would be something called the BasePuzzleView, which we will look at next week.
Subscribe to:
Posts (Atom)
