Rengga Dev – Farm Memory Game is a HTML5 Puzzle game. Match all identical cards before time runs out! From concept to Creation, I am building Farm Memory Game in 80 hours.
This game can be played on a variety of devices, including desktops, laptops, tablets, and smartphones. It typically requires a stable internet connection and a modern web browser that supports HTML5 technology.
How To Create:
CSS Files and Structure
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 styles for the canvas and some hack to be fully compatible with all most popular mobile devices.
JavaScript
This game contains:
- jQuery
- Our custom scripts
- CreateJs plugin
- Howler Sound library
- jQuery is a Javascript library that greatly reduces the amount of code that you must write.
- 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 text preloader to show resources loading progress
- CMenu: simple menu with the play button
- CGfxButton: this class create a standard button
- CToggle: this class create a standard toggle button
- CTextButton: this class create a standard text button
- CGame: this class manages the game logic
- CInterface: this class controls game GUI that contains text and buttons
- CGameOver: the final game over panel
- CVictory: this panel is shown when user win the game
- CCard: this class manages the cards
- CMain: the main class called by the index file.
- CreateJs is a suite of modular libraries and tools which work together to enable rich interactive content on open web technologies via HTML5.
- Howler is a javascript Audio library.
Resuming, the complete game flow is the following:
- The index.html file calls the CMain.js file after ready event is called
- The main class calls CPreloader.js to init preloader text and start sprite loading
- When all sprites contained in “/sprites” folder are loaded, the main class removes the preloader and calls the CMenu.js file that shows the main menu
- If user click the play button in main menu, the CGame.js class is called and the game starts
- The User play the game
- When the level time is over, the game calls the Game Over panel
- If user click on the exit button in the up-left corner, the game returns to the menu screen
Game Functions
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 create characters grid.
- unload()
This function removes all images from canvas and event listeners on buttons. It’s called when user decide to exit from the game. - checkMatching()
This function check if two cards are identical. - checkVictory()
This function check if level is complete. - nextLevel()
This function is called when start a new level. - update
Main game loop.
Sample Code
var oMain = new CMain({ card_per_level : [4, //NUM CARD IN LEVEL 1 8, //NUM CARD IN LEVEL 2 16, //NUM CARD IN LEVEL 3 32 //NUM CARD IN LEVEL 4 ], time_level:[30, //NUM SECONDS PER LEVEL 1 60, //NUM SECONDS PER LEVEL 2 120, //NUM SECONDS PER LEVEL 3 240 //NUM SECONDS PER LEVEL 4 ], score_match_card: 10, //SCORE ASSIGNED WHEN USER MATCH TWO CARDS score_time_left_mult: 2, //MULTIPLIER ASSIGNED TO REMAINING LEVEL TIME time_match_mult: 3000, //TIME AVAILABLE BETWEEN DISCOVERED MATCHING TO GET SCORE MULTIPLIER show_cards: 0 , //IF YOU WANT TO SHOW CARDS FOR SOME SECONDS WHEN LEVEL START, SET THIS VALUE > 0 (NUM OF SECONDS) 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 });