Get the full commented source code of

HTML5 Suika Watermelon Game

Talking about Flash and Game development.

One of the most interesting things about internet publishing is that you can receive feedback almost in real time.

For this reason, it’s very important to read every comment and above all negative comments.

When I released Tileball, I received some negative comments about the title screen. That’s right: I focused on the game and I did not care about a title screen, or a proper “congratulations” screen if a player manages to beat all levels.

When I was a kid, the “end screen” was very important. I remember myself playing some “not so good” games just to see how will they thank me for playing in their congratulations screen.

Too bad I forgot old times and released a game with such a lame intro and end screen.

I think it happened because I coded a lot of actionscript and did not want to nest more code to manage different game status such as info screen, welcome screen, and so on.

So I decided to make a Flash movie with the very basic structure every game should have.

This structure is made of:

* A “title” movieclip
* An “info” movieclip
* The game itself
* A “game over” movieclip
* A “congratulations” movieclip

Let’s see how do they work:

Title movieclip: it’s the first thing the player sees when the movie has loaded. It should have some appeal, just to tell players “hey, I’m a good game, give me a try”

Info movieclip: here you will put all instructions to play the game, or more information about the game.

The game itself: the most important thing, don’t forget it…

Game over movieclip: The screen the player will see once he dies and runs out of all lives, or runs out of time, or simply does not beat all levels. Here you can show highscores.

Congratulations movieclip: This is the screen the player will see should he ever complete the game. Congratulations, blah blah blah, show the highscores and play again

It’s very important that you include at least these sections, or your game will have an “home made” feeling. Now, we all know your game is home made, but we don’t want our game to seem “home made when sit in the bathroom”.

Come on, and let’s see how did I arrange actionscript and movieclips to have a game with the above features.

First, the actionscript:

current_status = "title";
play_game(current_status);
function play_game(game_status) {
	switch (game_status) {
	case "title" :
		_root.attachMovie("title_screen", "title_screen", 1);
		title_screen.instructions_button.onRelease = function() {
			play_game("instructions");
		};
		title_screen.play_button.onRelease = function() {
			play_game("play");
		};
		break;
	case "instructions" :
		_root.attachMovie("game_info", "game_info", 1);
		game_info.back_button.onRelease = function() {
			play_game("title");
		};
		game_info.play_button.onRelease = function() {
			play_game("play");
		};
		break;
	case "play" :
		_root.attachMovie("game_itself", "game_itself", 1);
		game_itself.game_over_button.onRelease = function() {
			play_game("game_over");
		};
		game_itself.win_button.onRelease = function() {
			play_game("game_won");
		};
		break;
	case "game_over" :
		_root.attachMovie("game_over", "game_over", 1);
		game_over.back_button.onRelease = function() {
			play_game("title");
		};
		game_over.play_button.onRelease = function() {
			play_game("play");
		};
		break;
	case "game_won" :
		_root.attachMovie("end_game", "end_game", 1);
		end_game.back_button.onRelease = function() {
			play_game("title");
		};
		end_game.play_button.onRelease = function() {
			play_game("play");
		};
		break;
	}
}

Line 1: Defining a variable containing the current status of the game. It’s set to title because when you start playing, the game must show the title screen

Line 2: Calling the main function, play_game, passing the current game status

Line 3: Beginning of the main function

Line 4: Performing a switch to the game_status variable: for each game status, I’ll execute proper actionscript

Line 5: Beginning of the actions to perform if the game status is set to title

Line 6: Attaching the movie with the title screen

Lines 7-9: Triggering a button that will lead to the instructions screen. Notice that when I release the button, I call the same play_game function with the game_status variable set to instructions

Lines 10-12: Same thing with the play button… this time the game_status takes the play value

Line 14: Beginning of the actions to perform if the game status is set to instructions

Line 15: Attaching the movie with the instructions

Lines 16-18: Triggering a back button that will take us to the title screen again

Lines 19-21: Triggering the play button as seen in lines 10-12

As you can see on further lines, the script remains almost the same for all game screens. Obviously the game itself is very lame (you win pressing a button and lose pressing the other button) and the whole presentation sucks, but this is the skeleton of the game and you should add your own gamescript (or more game screens) easily.

Look at the “game”…

… a very simple one but it has all the navigation options required.

Now you have no excuses to refuse making a good title screen.

Download the source

And talking about title screens…

Tileball 2

Never miss an update! Subscribe, and I will bother you by email only when a new game or full source code comes out.