4.0.2 • Published 2 months ago

gameslib v4.0.2

Weekly downloads
-
License
ISC
Repository
github
Last release
2 months ago

CSSoch Games Build Status Version

Games library for the CSSoch Curriculum

This library provides all the necessary functionality to integrate games and projects with the CSSoch framework.

Installation

The package is now publicly available (this may change to private in the future). You can link to the library using the Unpkg CDN or install it using npm.

npm

npm install gameslib

unpkg

<script src="https://unpkg.com/gameslib/dist/main.js"></script>

Usage

Basic Setup

The following code imports the game library and creates a new game object of type 'rocket'.

import Game from 'gameslib';
let gameObj = new Game.default('rocket');

The argument 'rocket' states the type of the game. Other game types include - 'maze' and 'draw' (though these are currently unavailable). More game types will be added in the future.

Options

When creating the game object, certain options need to be configured which can be done through the 'setup' method:

gameObj.setup(options, assessment);

The first option is the structure of the game. This can either be 'codingEnvironment' or 'playgroundEnvironment'. The coding environment is for games that require both a game window and a blockly window for writing code. The playground environment is simpler and only contains blocks which the students link together. Options are divided into two categories: 'blockly' and 'game'. The following table is a list of options required for the coding environment.

Blockly

OptionTypeDescription
toolboxRefStringID for toolbox div in html (this is where the toolbox will go)
blocklyAreaRefStringID for blockly area div in html (this div will hold the blockly window)
blocklyRefStringID for blockly div in html (this is where the blockly worspace will go)
renderer (Optional)StringOne of three: "Thrasos", "Zelos", "Geras". This option will be provided in the CMS UI
categoriesInToolboxBooleanWhether there are categories in toolbox or not. This option will be provided in the CMS UI

Game

OptionTypeDescription
canvasStringID for canvas div in html (this is where the game window will go)
ProjectBooleanWhether the game is a project or not. This option will be provided in the CMS UI

The playground environment requires only the 'blocklyAreaRef' and 'blocklyRef' fields under the 'blockly' category. The 'game' category is not needed.

Note: When loading the playground environment, an additional boolean parameter needs to be passed in for assessment to the setup method. This is to allow for concurrent running of game instances, and is not required for the coding environment.

Assets

The game assets need to be provided in the form of a dictionary with the key being the name of the file (without the path and the extension), and the value being the entire file path. Eg: {'RocketImage': '../assets/rocket/RocketImage.png'}.

gameObj.loadAssets(assetsDict);

There is an other category of images for blockly. These blockly assets are passed as a dictionary in the same way as the game assets.

gameObj.loadBlocklyImgs(blocklyAssetsDict);

Levels

The game object requires json config files in order to load levels. These json files shall be uploaded by the game developer throught the CMS UI. The json needs to be passed onto the game object.

gameObj.loadLevel(json);

Note: The latest versions of all the assets and json file levels used in the games can be found under the corresponding 'assets' and 'json' folders.

Running the Code

To run the code, the following method can be called:

gameObj.runCode();

Other Functionality

// Restart the game
gameObj.restart();

// Set function to be called when the user fails
gameObj.setFailure(callback);
// Set function to be called when the user succeeds
gameObj.setSuccess(callback);

// Return a string form of the user's code
gameObj.fetchCode();
// Load the code into the workspace
gameObj.loadCode(code);

// Load the solution into the workspace
gameObj.loadSolution();

Note: The failure callback must accept a string argument. This is the fail code. The fail code must be mapped with the code provided in the CMS to find the appropriate message to display to the student. If no message is available for the fail code, or there is any other problem with the code, the 'DEFAULT' code's message can be displayed.

Tech

This library has 4 dependencies:

  • Blockly - Used for the block based programming interface used in the games
  • P5 - For the game engine and
  • FastAverageColor - Used in the playground environment for getting the average colour of images
  • jQuery

Roadmap

  • More features to be added to the library to make it more flexible, including functionality to lock the workspace, pause the game, etc.
  • More game types will continuously be added to the library and examples for these shall be made available under the GamesTest folder.
  • Refer to the CSSoch Games Project for details on work being done.

Note: The GamesTest folder contains a set of demos on how to use a few different types of games.

4.0.2

2 months ago

4.0.1

2 months ago

4.0.0

2 months ago

3.3.1

4 months ago

3.3.0

4 months ago

3.2.2

7 months ago

3.2.6

6 months ago

3.2.5

6 months ago

3.2.4

6 months ago

3.2.3

7 months ago

3.2.9

6 months ago

3.2.8

6 months ago

3.2.7

6 months ago

3.2.10

5 months ago

3.2.1

8 months ago

3.2.0

8 months ago

3.1.2

8 months ago

3.1.1

9 months ago

3.1.0

9 months ago

3.0.5

10 months ago

3.0.4

11 months ago

3.0.3

11 months ago

3.0.2

12 months ago

3.0.1

1 year ago

3.0.0

1 year ago

2.9.2

1 year ago

2.9.1

1 year ago

2.9.4

1 year ago

2.9.3

1 year ago

2.9.0

1 year ago

2.8.3

1 year ago

2.8.4

1 year ago

2.8.1

1 year ago

2.8.0

1 year ago

2.8.2

1 year ago

2.7.13

1 year ago

2.7.4

2 years ago

2.7.6

2 years ago

2.7.5

2 years ago

2.7.8

1 year ago

2.7.7

1 year ago

2.7.9

1 year ago

2.7.11

1 year ago

2.7.10

1 year ago

2.7.12

1 year ago

2.7.0

2 years ago

2.7.2

2 years ago

2.7.1

2 years ago

2.6.5

2 years ago

2.7.3

2 years ago

2.6.1

2 years ago

2.6.0

2 years ago

2.6.3

2 years ago

2.6.2

2 years ago

2.6.4

2 years ago

2.5.1

3 years ago

2.5.0

3 years ago

2.4.0

3 years ago

2.3.4

3 years ago

2.3.3

3 years ago

2.3.2

3 years ago

2.3.0

3 years ago

2.2.1

3 years ago

2.2.0

3 years ago

2.3.1

3 years ago

2.2.2

3 years ago

2.1.1

3 years ago

2.1.0

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.6.0

3 years ago

1.5.0

3 years ago

1.4.0

3 years ago

1.3.0

3 years ago

1.2.0

3 years ago

1.1.0

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago