### “Jigsaw Deluxe” Documentation by “Code This Lab S.r.l.” v1.0

# “Jigsaw Deluxe”

Created: 31/05/2017
By: Code This Lab S.r.l.
Email: info@codethislab.com

Thank you for purchasing our game. If you have any questions that are beyond the scope of this help file, please feel free to email via user page contact form here. Thanks so much!

## Table of Contents

1. Description
2. Folder Content
3. Getting Started
4. HTML Structure
5. CSS Files and Structure
6. JavaScript
7. Game functions
8. Add Images
9. Change Graphic
10. Disable Sounds
11. Wordpress Plugin

### A) Description - top

Jigsaw is a HTML5 Puzzle game. The puzzle game par excellence. Select your favorite picture and complete the jigsaw in the shortest time possible!
Game Features:

1. 4 Game difficulties (16, 36, 64 and 100 pieces)
2. 6 Pictures that can be easily replaced with your own.

If you want more or less pictures you just have to modify their number in the game’s code (please read Add Images section)
The ZIP package contains the game with 1920x1080 resolution that scales to fit the whole screen device
Just warning that for very wide screens, the game may not be perfectly full screen.
The game is fully compatible with all most common mobile devices.
Sounds are enabled for mobile but we can't grant full audio compatibility on all mobile devices due to some well-known issue between some mobile-browser and HTML5. So if you want to avoid sound loading, please read Disable Sound section).
WARNING: Sounds can't be enabled for Windows Phone as this kind of device have unsolved issues with 'audio' and 'video' tag.

### B) Folder Content - top

1. ctl_arcade_wp_plugin:
This folder contains the zip package that can be used with our Wordpress plugin "CTL Arcade" (http://codecanyon.net/item/ctl-arcade-wordpress-plugin/13856421).
2. game
This folder contains the full game source code ready to be edited.
3. live_demo
This folder contains the obfuscated code. You should upload this folder on your server if you don't need to make any changes.
4. readme
This folder contains the package instructions.
5. thumbs
This folder contains all game icons.

### C) Getting Started - top

To install the game just upload on your server the game folder live_demo.

- Game Embedding: The proper way to embed the game is in a full-screen web page or in an iframe.
  In the first case the game will fit the screen size, in the second, that of the iframe.
  If the iframe size matches that of the screen, the game will fit accordingly.
  The alignment will be proportioned to the aspect ratio of the game.
  To install the game in a WordPress website, we suggest to use our plugin CTL Arcade .
- Save Score: if you need to call your php function for saving score, you can add it in the index.html file:

      						$(document).ready(function(){
      							var oMain = new CMain();

      							$(oMain).on("save_score", function(evt,iScore) {
                                   //alert("iScore: "+iScore );
                           });
      						});

- Localization: You can easily change game text for different languages, changing string in CLang.js

    					var TEXT_CHOOSE_IMAGE = "CHOOSE AN IMAGE";
    					var TEXT_CHOOSE_DIFFICULTY = "CHOOSE NUMBER OF PIECES";
    					var TEXT_PIECES = "PIECES";
    					var TEXT_SCORE = "SCORE";
    					var TEXT_COMPLETED = "JIGSAW COMPLETED!";
    					var TEXT_TIME = "TIME";
    					var TEXT_ARE_YOU_SURE = "ARE YOU SURE?";

    					var TEXT_DEVELOPED = "developed by";

    					var TEXT_SHARE_IMAGE = "200x200.jpg";
    					var TEXT_SHARE_TITLE = "Congratulations!";
    					var TEXT_SHARE_MSG1 = "You collected ";
    					var TEXT_SHARE_MSG2 = " points!

    Share your score with your friends!";
    					var TEXT_SHARE_SHARE1 = "My score is ";
    					var TEXT_SHARE_SHARE2 = " points! Can you do better";

- Game option: You can easily customize game setting when creating a new instance of the game in index.html file

    					var oMain = new CMain({
    										num_images:6,    //NUMBER OF IMAGES TO LOAD. YOU MUST ADD COHERENT NUMBER OF IMAGES IN /SPRITES FOLDER.
                                                audio_enable_on_startup:false, //ENABLE/DISABLE AUDIO WHEN GAME STARTS
                                                fullscreen:true, //SET THIS TO FALSE IF YOU DON'T WANT TO SHOW FULLSCREEN BUTTON
                                                check_orientation:true,     //SET TO FALSE IF YOU DON'T WANT TO SHOW ORIENTATION ALERT ON MOBILE DEVICES
                                    });

### D) HTML Structure - top

This game have the canvas tag in the body. The ready event into the body calls the main function of the game: CMain().
The head section declares all the javascript functions of the game. The whole project uses a typical object-oriented approach.
In the init function there are 6 mapped events that can be useful eventually for stats

### E) CSS Files and Structure - top

The game use two CSS files. The first one is a generic reset file. Many browser interpret the default behavior of html elements differently. By using a general reset CSS file, we can work round this. Keep in mind, that these values might be overridden somewhere else in the file.

The second file contains all of the specific stylings for the canvas and some hack to be fully compatible with all most popular mobile devices

### F) JavaScript - top

This game contains:

1. jQuery
2. Our custom scripts
3. CreateJs plugin
4. Howler Sound library

1. jQuery is a Javascript library that greatly reduces the amount of code that you must write.
2. The game have the following js files:
   - CMain: the main class called by the index file.
     This file controls the sprite_lib.js file that manages the sprite loading, the loop game and initialize the canvas with the CreateJs library
   - ctl_utils: this file manages the canvas resize and its centering
   - sprite_lib: this class loads all images declared in the main class
   - settings: general game settings
   - CLang: global string variables for language localization
   - CPreloader: simple preloader that shows resources loading progress
   - CMenu: simple menu with a play button
   - CGfxButton: this class create a standard button
   - CTextButton: this class create a standard text button
   - CToggle: this class create a toggle button
   - CGame: this class manages the game logic
   - CInterface: this class controls the game GUI that contains text and buttons
   - CAreYouSure: this class manage panel is shown when exit button is pressed
   - CButLevel: this class manages the level button
   - CChooseDifficultyPanel: this class manages the panel where user can choose number of pieces
   - CChooseImagePanel: this class manages the panel where user can choose the image
   - CEndPanel: this class shows the game over panel
   - CGameSettings: this class stores all the infos about pieces
   - CPiece: this class manages the jigsaw piece
   - CCreditsPanel: this class manages the Credits Panel
3. CreateJs is a suite of modular libraries and tools which work together to enable rich interactive content on open web technologies via HTML5.
4. Howler is a javascript Audio library.

Resuming, the complete game flow is the following:

1. The index.html file calls the CMain.js file after ready event is called
2. The main class calls CPreloader.js to init preloader text and start resources loading
3. When all resources contained in "/sprites" folder and "/sounds" folder are loaded, the main class removes the preloader and calls the CMenu.js file that shows the main menu
4. If user click on the play button in main menu, the CChooseImagePanel.js class is called and the user can choose an image
5. Once user choose an image, the CChooseDifficultyPanel.js class is called and the user can choose number of pieces
6. Once user choose difficulty, game starts
7. If user completes the jigsaw, the game over panel is shown
8. If user click on the exit button in the up-right corner, the game returns to the Menu panel

### G) Game functions - top

In this section will be explained all the most important functions used in CGame.js file.

- _init()
  This function attach on the canvas some game sprites like background (oBg), GUI and jigsaw pieces.
- unload()
  This function removes all images from canvas and event listeners on buttons. It's called when user decide to exit from the game.
- _attachImage()
  This function init image pieces.
- _checkCollision()
  This function checks if there are any matching when piece is released.
- _updateActiveJoints()
  This function refresh all the infos about piece joints.
- update()
  The main game loop useful game time.

### H) Add Images - top

By default there are 6 different available images in the game. If you want to increase the number of images, add them in /sprites folder and set correctly this param in index.html file:

    num_images:6

Please keep in mind that new images MUST be jpg with the resolution 840x840 or game will not work properly.

### I) Change Graphic - top

You can easily change all the game graphic, replacing all the file you need in the "/sprites" folder. Just respect file format (.png or .jpg) and size if you don't want to change any code line.

### J) Disable Sounds - top

If you want to disable all the sounds for mobile devices, you have to change the following value in settings.js file:

    var DISABLE_SOUND_MOBILE = true;

### K) Wordpress Plugin - top

CTL Arcade will allow you to add a real arcade on your worpress website, in this way your users will be more involved and will stay connected longer.
It's possible to add Ads banner at the beginning of each game and at the end of each level. This will give you a new tool to increase your revenues.
Your own users will promote your website sharing their scores on the main Social Networks, with no extra costs for you.
You'll get by default the score-sharing on Twitter. To add Facebook just follow the guideline below.
3 widgets can be added in your pages through a shortcode.

- Game iframe
- Rate the Game
- Leaderboard

Minimum Requirements:

- PHP 4.3
- WordPress 4.3.1
- HTML5
- Canvas
- Javascript / jQuery

This plugin is designed to work only with games built by Code This Lab.
You can find it here!

Once again, thank you so much for purchasing this game. Fell free to contact us if you have any questions or issue relating to this game. No guarantees, but we'll do our best to assist.

CODE THIS LAB S.R.L.

Go To Table of Contents