Tag: match three

Deciding what level features to be used in the Match Three game

Deciding what level features to be used in the Match Three game

Match Three gameI’m at the point of deciding what features will be included in the game and then determining what % of features are used on each level. how to make the game harder etc. As with asteroids I’ll use Excel.

These are features to enhance the game and maybe increase difficulty.

  • Wanted animals. Most levels have a target of a number of pieces of one type. The level is completed when all of that piece have been removed. These ‘wanted’ animals are shown onscreen with a count of how many remain.
  • Locked pieces. On some levels, pieces are randomly locked. The lock is removed only when the piece is in a matched line or in the area affected (from bonus pieces). Locked pieces do not move even if there is a space beneath them. For really hard levels, two locks can be used on a piece. Each lock has to be removed.
  • Skulls. Some levels have a number of skull pieces to be removed. This can only be done by removing pieces below so the skull drops and eventually reaches the bottom row where it is automatically removed.
  • Timed levels. Some levels will have a count down timer; so many animal pieces have to be removed before the timer runs out.
  • Bonus Pieces. These appear when a 4-match, a 5-match or a 6-match occurs and show special pieces- a 4-piece, 5-piece etc. Two 4-pieces dragged together clear a 5 x5 area of all pieces (remove locks on locked pieces). Two 5-pieces dragged together wipe out all pieces in both the row and column. A 4 and a 5-piece together wipe out all animal pieces of the animal piece (picked randomly) next to the 5-piece. Two 6-pieces together wipe out all pieces on the board (locked pieces aren’t wiped, just unlocked). A 6-piece dragged on a 4-piece or 5-piece wipes out all pieces in 3 rows wide and 3 columns deeps.
  • Board Rotation. The board can be rotated clockwise or anti-clockwise. This allows spaces created under locked pieces to be possibly filled. It also helps get rid of skulls that are now on the bottom row. But some levels start with a number of board rotations. Once used up, the only way to earn them is to do something like drag two four-match pieces together.

So now I have to decide how these fit together on the different levels, what weighting each has and calculate a difficulty score that should increase as you progress through levels. Oh the joys of game design!

Progress on the Match Three game

Progress on the Match Three game

Match Three game Having a week off work has let me work on this game a bit more. I’ve put in about eight hours and it is now correctly dropping.

I’d never programmed one of these before so my first version used a board of pieces plus a secondary array for holding “transitions”. A transition was a struct that held information about two pieces being swapped and the current coordinates of each piece.  It seemed to be quite messy code and was quite buggy with pieces on top of other pieces.

So I then switched to a system where each board cell had a pointer to a struct for a piece (held in an array).  If the piece wasn’t moving the program calculated its pixel coordinates from the board coordinates and drew it there. If it was moving, it would no longer have board coordinates and would use the pixel coordinates to draw it.

That was better but then I thought why not just have the board just be a 2D array of structs with one struct for each piece.

This is the struct for each piece.

 

struct Cell {
	int piece;
	int moving;
	int scEndX, scEndY;
	float scCurrentX, scCurrentY;
	float velY, velX;
	int bdEndX;
	int bdEndY;
	int angle;
	int lock;  //1 = locked. Display padlock
	int size; // used when killing to diminish size
};

SDL2 does rotation very nicely; you don’t need to pre-render shapes just call SDL_RenderCopyEx instead of SDL_RenderCopy and specify the angle and one or two other parameters. When a piece is removed, it animates for about a half-second, rotating and shrinking in place. That’s the purpose of the angle and size fields.

If the lock value is 1 then the piece stays in place and won’t drop. You have to remove the lock by forming a line that includes the locked piece. When the line is removed, all locked pieces in the line remain but without the lock.

So far the game is currently about 800 lines of code. There’s no game level structure, high-score table, sounds, bonus pieces or even a basic piece matching algorithm. I’ve been testing by just randomly removing three vertical or horizontal pieces and then having unlocked pieces above fall down.

This 3rd version does not suffer from the Mexican-wave problem that the first and second version had. Sometimes when a column of pieces moved down, instead of all pieces moving together they moved one-by-one. New pieces get added in when the top row piece finishes dropping away.

So now on with the book and the next part of the game.

Working on the Match Three game

Working on the Match Three game

Match three gameThe second game is Match Three and I’d made some good progress. You can view some .mp4s from earlier this month here. The first one (MatchThree) shows rotations, something I’d never realised SDL is very good at doing. Graphics are from the excellent Dutch website (it’s in English) Kenney.nl.

The second mp4 (transitions) shows some animations. And the MatchThreeDropping shows pieces both being removed (first rotating and shrinking) and pieces dropping. However it also shows a flaw.  Sometimes all the pieces move together, other times (and this is the flaw) it shows them dropping one by one- Mexican wave-like, rather than all moving together.

My original algorithm, which I am now scrapping, had a transitions table. When the space or spaces below a piece became blank, a transition was created which had start and end positions. The piece was removed from the board (a simple 2d array) and reinstated in the board when it had finished moving to the end pixel position.

I think I have a much better method now, I still use a board but each element has a pointer to a piece in a big array of piece structs. I track both the coordinates in the board (0-9,0-9) and in pixels as each piece is 64 x 64. When a space is created in the board, all the pointers are shuffled and each piece is told to move from it’s old pixel position to its new one.

The move algorithm operates purely on the all pieces in the piece array not the board. The flawed algorithm worked on both the board and transition array and was quite messy. Sometimes you have to start with a clean slate than try and fix code that is working correctly.

My next Book – Match three

My next Book – Match three

I’ve been thinking about doing a 3rd book – something like ‘More C Games, design and programming’ which would have three games, each with a design and then implemented with explanations and bits of source code and all on Github.  The first game is possibly going to be a Match Three game.

Match tree gameMatch Three games have been around for the best part of a decade and have a basic mechanic of swapping two adjacent pieces to make a line up of three, four or five pieces which get removed.

What makes it more challenging and interesting is the almost limitless number of mechanisms you can build on. For instance when you clear four or five you get special items that when swapped with another special item do something interesting. Or could be you have to get a set of special items and so on.

Or you might have special levels where you have to clear all of one particular shape within a time or Boss levels where the baddy is continually adding hard to remove pieces that clog up the game, or you might have a rotate button that flips the board 90 degrees so you can get rid of hard to remove pieces by having them drop into special buckets beneath the board.

Now I just have to come up with two more games. Suggestions welcomed!