C .
ODE
G
AMELET
# GLT One Paragraph of the game description goes here ## Getting Started ### Auth (Login) ```typescript // All action must wait until auth system is ready. CG.GLT.auth.onReady(user => { if(user.isLocalGuest()) { // not login yet } else { // logged in user } }); // auth event listener, triggered when auth user changed let authListener = CG.GLT.auth.onAuth(user => { if(user.isLocalGuest()) { // logged out } else { // logged in user } }); // auth event listener, triggered when validating a new auth action // a following onAuth event is expected. this.validatingListener = onAuthValidating(() => { // show loading animation }); ``` ### API The CG.GLT.api is responsible to communicate with glt.gamelet.online. CG.GLT.commands includes all comments to query/submit data from glt.gamelet.online. The commands has a function submit() that uses CG.GLT.api.submitCommand(), so most of the time, you don't need to call the api to submit. ```typescript CG.GLT.commands.scoreService.submitScore( 'challenge', // the name of the score to submit 10, // the score SubmitType.KEEP_HIGHEST, // submit only when the new score is greater than the one on server TimeRange.ALL // submit to all time-ranges (history and weekly) ) .submit(); // to receive the weekly high score list CG.GLT.commands.scoreService.listScores( 'challenge', // the name of the scores to get TimeRange.WEEKLY, // in which time range OrderType.HIGH_TO_LOW, // how to order the scores CG.GLT.api.lastUpdatedServerTimestamp, // tell the server which week to see 0, // start index 10, // how many to get (list: UserScoreList) => { // do something with the scorelist }, (error) => { // deal with error } ) ``` ## Authors **[Haskasu](/profile/113321052805704333314@google)**
# CgEventsLib The engine of CgEvents. CgEvents is a great way to build your own games with with a CG.built-in editor. ## Attention 請注意 This project is not released and still in actively development. Expect breaking changes before official release. 這個專案目前仍在測試階段,在正式推出之前,所有功能隨時都有可能大改,請謹慎試用。 ## Live Demo <a href="cg://source/test/physics.events" class="mat-raised-button mat-primary">Open Demo Events Sheet</a> ## Concept The engine takes a *.events file to run. The .events file is an encoded json which contains a config field and a events field. ```json { config: { stage: { width: "number", height: "number", resolutionPolicy: "showAll" | "exactFit" | "fixedWidth" | "fixedHeight" | "origin", alignHorizontal: "left" | "center" | "right", alignVertical: "top" | "middle" | "bottom" } }, events: [ { id: "string", triggers: [], checks: [], actions: [] }, ... ] } ``` Yon can edit the json with CG.built-in editor to control all your game events. ## How Events Work Each event contains a TRIGGER, some CHECKS, and some ACTION. The event flow works like this: 1. The TRIGGER of the event is triggered by the engine (keyboard pressed, event over, or maybe the hero collides with an enemy) 1. Once the trigger is triggered, the engine then goes check the CHECKS. 1. If all CHECKS pass, the engine executes all the ACTIONS in the event. ## Getting Started ```typescript let manager = new CgEventManager(); manager.importFromSource('CG.YourProject/yourGame.events') .then(() => manager.preload()) .then(() => manager.start()) ; ``` ## Versioning We use [SemVer](http://semver.org/) for versioning. ## Authors * **[Haskasu](/profile/Haskasu)**
# CG.Base Provide tool kits that helps you fast build an app on Code.Gamelet. Key features include: 1. initialize [pixi.js](#pixi.init) or [three.js](#three.init) environment 1. load and access resources that are imported via Code.Gamelet IDE 1. manage update functions that are called every frame 1. provide debug utilities ## Getting Started Follow the steps below to fast start an app with [PixiJS](#pixi.init) or [three.js](#three.init). We will implement a box2d environment to demo the usage of Base. <a name="pixi.init"></a> ## Start with Pixi.js<a name="pixi.init"></a> ```typescript class App { constructor() { // initialize pixi CG.Base.pixi.initialize(600, 400); CG.Base.pixi.physicsDebugDraw.setActive(true); // make a physics wall var wall = CG.Base.physics.createPhysicsObject('wall', {type: 'static'}); wall.addEdge(new CG.Base.geom.Point(10, 300), new CG.Base.geom.Point(500, 330)); // make a dynamic physics ball var ball = CG.Base.physics.createPhysicsObject('ball', {type: 'dynamic'}); ball.addCircle(0, 0, 10, {friction: 0.1, density: 0.1, restitution: 0.3}); ball.setPosition(100, 10); } } new App(); ``` @see [Demo](/edit/Base_Start_with_PIXI) <a name="three.init"></a> ## Start with three.js ```typescript class App { constructor() { CG.Base.three.initialize(600, 400); CG.Base.three.physicsDebugDraw.setActive(true); CG.Base.three.camera.position.z = -50; CG.Base.three.camera.up.set(0, -1, 0); CG.Base.three.camera.lookAt(new THREE.Vector3()); // make a physics wall var wall = CG.Base.physics.createPhysicsObject('wall', { type: 'static' }); wall.addEdge(new CG.Base.geom.Point(10, 300), new CG.Base.geom.Point(500, 330)); // make a dynamic physics ball var ball = CG.Base.physics.createPhysicsObject('ball', { type: 'dynamic' }); ball.addCircle(0, 0, 10, { friction: 0.1, density: 0.1, restitution: 0.3 }); ball.setPosition(100, 10); } } new App(); ``` @see [Demo](/edit/Base_Start_with_THREE) ## Load and play with Resources To load resources that are imported from IDE: ```typescript // tell resources what resources to load (using the alias names) CG.Base.resourceManager.addAppResource('Game1.button'); CG.Base.resourceManager.addAppResource('Game1.music'); // start loading CG.Base.resourceManager.load(() => { // all loaded callback // create button with the image "Game1.button" alias name var button = new CG.Base.pixis.interactive.Button(CG.Base.resourceManager.createPixiSprite('Game1.button', 20, 20)); // set the position of the button button.displayObject.position.set(100, 100); // add the button to pixi.root, so pixi can render the button CG.Base.pixi.root.addChild(button.displayObject); // add a click event listener button.on(CG.Base.pixis.interactive.Button.EVENT.CLICK, () => { // when the button is clicked, play sound with "Game1.music" alias name CG.Base.resourceManager.playSound('Game1.music') }); }); ``` @see [Demo](/edit/Base_Load_Resources) ## Manage update functions Take advantage of CG.Base.addUpdateFunction to make a function called every frame ```typescript class App { constructor() { CG.Base.pixi.initialize(600, 400); CG.Base.addUpdateFunction(this, this.update); } // this function will be called every frame(called 60 times per second normally) private update(deltaTime:number):void { // do something } } new App(); ``` @see [Demo](/edit/Base_Update_and_Delay_Func) You can call a function in the future by CG.Base.addDelayFunction ```typescript class App { constructor() { CG.Base.pixi.initialize(600, 400); // call this.delayAction in 1000 milliseconds(= one second) CG.Base.addDelayFunction(this, this.delayAction, 1000); } private delayAction():void { // do something } } new App(); ``` @see [Demo](/edit/Base_Update_and_Delay_Func) ## Interact with Keyboard Use PIXI.keyboard package to interact with keyboard events. ```typescript export class App { constructor() { // make the window focused, so we can receive keyboard events. window.focus(); // initialize pixi CG.Base.pixi.initialize(600, 400); // tell resourceManager to load the resource 'Game1.button' CG.Base.resourceManager.addAppResource('Game1.button'); // load resources, and wait callback when resources are all loaded CG.Base.resourceManager.load(() => { // add keyboard event listener, when a key is pressed PIXI.keyboardManager.on('pressed', key => { // if the pressed key is space, we call this.createSprite() if (key == PIXI.keyboard.Key.SPACE) { this.createSprite(); } }); }); } private createSprite(): void { // create a sprite with the image 'Game1.button' var sprite: PIXI.Sprite = CG.Base.resourceManager.createPixiSprite('Game1.button'); // set the position of the sprite sprite.position.set(CG.Base.utils.IntUtil.randomBetween(100, 500), CG.Base.utils.IntUtil.randomBetween(100, 300)); // add the sprite to pixi.root, so it can be rendered CG.Base.pixi.root.addChild(sprite); } } new App(); ``` @see [Demo](/edit/Base_PIXI_Keyboard) ## Debugging The best debug tool on browser is the [developer tools](https://developer.chrome.com/devtools) in Chrome (F12). To find your source code in developer tools, first open developer tools(F12), click "Sources" tab, and search the Network tree as below: > top => {projectCode} => gameFrame => code.gamelet.com => gassets => file/{projectCode}/src for example, if the projectCode is 'Game1', source code is located at > top => Game1 => gameFrame => code.gamelet.com => gassets => file/Game1/src ![Source Network Tree](https://code.gamelet.com/gassets/asset/Base/Base.networktree/networktree.png "Source Network Tree") ### Add Watch In addition to browser's debugging tools, CG.Base provides other useful tools. CG.Base.addWatch() adds objects or objects' properties to Watch panel in CG IDE. ```typescript export class App { constructor() { // initialize pixi CG.Base.pixi.initialize(600, 400); // tell resourceManager to load the resource 'Game1.button' CG.Base.resourceManager.addAppResource('Game1.button'); CG.Base.resourceManager.load(() => { // add the created sprite into Watch panel, the alias name in Watch panel is 'sprite' CG.Base.addWatch('sprite', this.createSprite()); }); // add this(App)'s 'time' property into Watch panel. The alias name for this property is 'now' CG.Base.addWatch('now', this, 'time'); } private createSprite(): PIXI.Sprite { // create a sprite with the image 'Game1.button' var sprite: PIXI.Sprite = CG.Base.resourceManager.createPixiSprite('Game1.button'); // set the position of the sprite sprite.position.set(CG.Base.utils.IntUtil.randomBetween(100, 500), CG.Base.utils.IntUtil.randomBetween(100, 300)); // add the sprite to pixi.root, so it can be rendered CG.Base.pixi.root.addChild(sprite); return sprite; } // a getter function, that works like a property of App object. get time(): number { return CG.Base.time(); } } new App(); ``` @see [Demo](/edit/Base_Add_Watch) ## Versioning We use [SemVer](http://semver.org/) for versioning. ## Links and Resources This library is running with the libraries below. * [Pixi.js](http://www.pixijs.com/) - 2D rendering engine * [API reference](http://pixijs.download/release/docs/index.html) * [Examples](http://pixijs.io/examples/) * [Three.js](https://threejs.org/) - 3D rendering engine * [API & Docs](https://threejs.org/docs/index.html#manual/introduction/Creating-a-scene) * [Examples](https://threejs.org/examples/) * [Pixi keyboard](https://github.com/Nazariglez/pixi-keyboard) - Keyboard utility * [Pixi sound](https://github.com/pixijs/pixi-sound) - Sound utility * [Pixi filters](https://github.com/pixijs/pixi-filters) - Filters Collections * [Pixi GafPlayer](https://github.com/mathieuanthoine/PixiGAFPlayer) - [GafMedia](https://gafmedia.com/) Player * [Liquidfun](http://google.github.io/liquidfun/) - Box2D based physics engine * [MD5](http://www.myersdaily.org/joseph/javascript/md5-text.html) - MD5 implementation by Joseph Myers ## Authors **Haska Su** - *Initial work*
# PixiGif Add [GIF](https://en.wikipedia.org/wiki/GIF) 89a (animated GIF) support for pixi.js. ## Getting Started Add GIF image alias to resourceManager as regular resources, and create a GifSprite by CG.PixiGif.createGifSprite(); ```typescript let resourceAlias = 'PixiGif.anim'; CG.Base.resourceManager.addAppResource(alias); CG.Base.resourceManager.load(() => { CG.Base.pixi.initialize(300, 300); // create a GifSprite, attach to pixi.root and play the animation let sprite = CG.PixiGif.createGifSprite(resourceAlias); CG.Base.pixi.root.addChild(sprite); sprite.play(); }); ``` You can setup custom sequences by any combination of frames. ```typescript let sprite = CG.PixiGif.createGifSprite(resourceAlias); sprite.addSequence('jump', [1,3,5]); // define a sequence named jump sprite.setSequence('jump', true); // set jump as the current sequence, and play ``` You can listen to events from GifSprite ```typescript let sprite = CG.PixiGif.createGifSprite(resourceAlias); sprite.on('frameChanged', (sp) => console.log('the frame is just changed')); sprite.on('complete', (sp) => console.log('the animation is complete and stopped')); sprite.on('play', (sp) => console.log('just starts playing the animation')); sprite.on('stop', (sp) => console.log('the animation is stopped')); sprite.on('end', (sp) => console.log('the animation plays to the end of the sequence')); ``` #### References - [GIF reader by Dean McNamee](https://github.com/deanm/omggif) - [GIF Format](http://www.onicos.com/staff/iz/formats/gif.html)
# TiledMapEngine 方塊地圖遊戲引擎 如果大家有玩過光暈戰記/Minecraft,那一定方塊地圖十分了解:<br/> #### <I>方塊地圖是指地圖由一格一格組成。</I><br/> 這個引擎可以讓大家輕鬆做出方塊地圖,並在地圖上設計遊戲。<br/> 不過使用這個引擎之前,你必須在<a href="">我們提供的地圖編輯器</a>設計你的地圖。<br/> 有關地圖編輯器的說明,可以在該專案查看。<br/><br/> ## 我不懂那些函式怎用,怎麼辨? 你可以點入本專案程式碼查看說明,一切程式碼都是開源的。<br/> 你也可以在本專案建立討論串,說明你的問題。<br/> ## How to use 本專案大多使用asynchronous function,<br/> 換而言之,在使用本專案之前,你可能需要學習一些語法,比如: ```typescript this.gameMap.renderMap() .then(() => { //write your code in here }); ``` 這個程式是要this.gameMap去加載地圖,由於加載地圖需要時間,<br/> 不使用asynchronous function的話,你的程式會卡著一段時間。<br/> 現在,在使用asynchronous function的設計後,你只要把加載地圖之後的程式寫在then中,就可以避免卡著的情況。<br/><br/> 在完成地圖設計之後,你會得一個JSON檔案,這個檔案儲存了一切有關那個的資料。<br/> 然後,你須在你的專案加入本模組,並把JSON檔案上載至你的專案(你也可以修改左方CG.TiledMapEngine中的tiled_map.json)。<br/> 接下來,請參考加載地圖示範: ```typescript CG.Base.pixi.initialize(500, 600); //格式化PIXI CG.Base.resourceManager.addAppResource('TiledMapEngine.mapResource') //加載你的地圖圖片 CG.Base.resourceManager.load(() => { //step 1: 加載JSON $.getJSON(CG.Base.getAppSourceUrl('CG.TiledMapEngine/tiled_map.json'), (data) => { //請把那個url改成你json檔案位置,如果你是直接修改tiled_map.json,這邊可以不用改 //step 2:建立地圖,並把地圖資料,即JSON傳入 this.gameMap = new CG.TiledMapEngine.Map(data , true); //建立一張新地圖,在建立時,會把json資料傳入, true代表有視野限制 //step 3:把地圖素材包加到地圖中 this.gameMap.importUsedMapTexture() //把地圖格子資料加到地圖 .then(() => { //step 4:生成地圖 this.gameMap.renderMap() //生成地圖 .then(() => { CG.Base.pixi.root.addChild(this.gameMap); //把地圖加到PIXI中 }); }); }) }); ``` 這樣,你就會得一個this.gameMap,而這就是你的地圖。<br/> 在CG中,實作無限地圖十分簡單,<br/> 在光暈,我們只有一個地圖,即是只有一個this.gameMap,<br/> 但在CG,你可以使用上面的方法,建立多個地圖。 ## API ### CG.TiledMapEngine.camera ### <div style="color:red">Method</div> set(map: Map, x: number, y: number): void<br/> 根據輸入的地圖和位置,移動視角。 | Parameter | Type | Description | Optional | |:---------:|:------:|:------------------:|:--------:| | map | Map | 要移動視角的地圖。 | No | | x | number | 位置的x軸座標。 | No | | y | number | 位置的y軸座標。 | No | ## Author **[gamtable](/profile/gamtable)**
# TwilightWarsLib A Top-down view shooting game framework. ## Getting Started These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. To start a .event ```typescript CG.TwilightWarsLib.initialize() .then(() => { CG.TwilightWarsLib.events.startEvents('test/test.events', 'arena'); }) ``` To manually setup the game: ```typescript CG.TwilightWarsLib.initialize() .then(() => let mapSource = 'test/test.twmap'; CG.Base.resourceManager.addAppSource(mapSource); CG.Base.resourceManager.load(() => { let mapResource = new CG.TWMap.resources.MapResource(); mapResource.importBase64(CG.Base.resourceManager.getText(mapSource)); mapResource.loadTextures(() => { CG.Base.pixi.initialize(600, 500); let game = new CG.TwilightWarsLib.games.Game(); CG.Base.pixi.root.addChild(game); game.initResources(mapResource); game.start(); console.log('tw game created'); let me = new CG.TwilightWarsLib.games.actors.Actor(game, 'me'); game.addActor(me, new MyActorController(me), 32, 100, 0, null); game.gameCamera.setFocus(me); game.interface.setMe(me); let ai = new CG.TwilightWarsLib.games.actors.Actor(game, 'ai'); ai.camp = CG.TwilightWarsLib.games.datas.Camp.CAMP2; ai.actorClip.headClip.clip.gotoAndStop(5); game.addActor(ai, new CG.TwilightWarsLib.games.actors.controllers.AIController(ai), 160, 300, 0, null); game.createStuff(null, 64 + 16, 128 + 16, CG.TwilightWarsLib.games.items.StuffInfo.getByCode('sword'), game.stuffManager.useNextStuffId(), true); }); }); }) ``` ## Versioning We use [SemVer](http://semver.org/) for versioning. ## Authors * **[Haskasu](/profile/Haskasu)** ## Acknowledgments * Hat tip to anyone who's code was used * Inspiration * etc
# Rapid 快速開發模組(by gamtable) 簡化一般常用的功能,讓用戶可以快速開發。 ## Why use Rapid? 為什麼要用Rapid呢? 有些人可能問:為什麼要用Rapid呢?</br> Rapid又有什麼好處呢?</br></br> Rapid把使用對象設在國中生,把功能的複雜的程度大量簡化,當您載入了Rapid,就可以很輕鬆地做出很多東西。</br> 一些很複雜的東西(比如是loadber、按鈕等等),在Base中都沒沒有提供,但Rapid不但提供了以上功能,我們還把功能整合、中文化。</br></br></br></br> <h3>學習程式?就是如此簡單。</h3> ## Start 開始使用 在使用模組之前,必須在右方的"加載模組"載入本模組。<br> 在編輯時,輸入 **CG.Rapid.**就可以使用,以下為例子: ```typescript export class App { constructor() { CG.Rapid.system.addResource('圖片1','圖片2','圖片3'); //加載資源 } } ``` **注意1:**本模組已事先載入Base的模組,用戶不必重新載入。<br> **注意2:**用戶可以在"討論"提出意見。開發本模組時是根據團隊團員不擅長之處開發,不一定可以涵蓋所有用戶。<br> **注意3:**後續版本會閞發類似光暈同人陣的環境,閞發者可以在OwnGame.ts找到所需函數(未開發完成,現階段使用並沒有效果)。 ## Tutorial 一般教學 檢查是不是用手機瀏覽 ```typescript export class App { constructor() { CG.Base.pixi.initialize(800,600); CG.Rapid.fillClr(0xFFFFFF); if (CG.Rapid.system.checkMobile() == true) { CG.Rapid.text('這是手機用戶',100,100) } else { CG.Rapid.text('這是電腦用戶',100,100) } } } export const APP: App = new App(); ``` 列出一段文字 ```typescript export class App { constructor() { CG.Base.pixi.initialize(800,600); CG.Rapid.fillClr(0xFFFFFF); CG.Rapid.text('列出一段文字',100,100); } } export const APP: App = new App(); ``` 放置圖片 ```typescript export class App { constructor() { CG.Rapid.system.addResource('圖片1'); //要先加載圖片 CG.Base.pixi.initialize(800,600); CG.Base.resourceManager.load(() => { let myImage = CG.Rapid.img('圖片1'); //放置圖片 CG.Base.pixi.root.removeChild(myImage); //移除圖片 }; } } ``` 放置按鈕 ```typescript export class App { constructor() { CG.Rapid.system.addResource('圖片1'); //要先加載圖片 CG.Base.resourceManager.load(() => { let newButton = CG.Rapid.GUI.button(10,10,'圖片1',() => { console.log('點下去就會say hi!'); }); //放置按鈕 CG.Base.pixi.root.removeChild(newButton); //移除按鈕 }; } } ``` ## Authors 作者 * **[gamtable](/dev/profile/gamtable)**
# TMXMap Use [Tiled Map Editor](https://www.mapeditor.org/) maps in Code.Gamelet with [pixi.js](http://www.pixijs.com/). ## What is Tiled Map Editor Tiled is a 2D level editor that helps you develop the content of your game. Its primary feature is to edit tile maps of various forms, but it also supports free image placement as well as powerful ways to annotate your level with extra information used by the game. Tiled focuses on general flexibility while trying to stay intuitive. ## Getting Started #### Usage 1. import tmx resources into one appResource ``` typescript CG.Base.resourceManager.addAppResource('TMXMap.testMap'); CG.Base.resourceManager.load(() => { CG.Base.pixi.initialize(600, 600); let tiledMap = new CG.TMXMap.MapRenderer('TMXMap.testMap'); CG.Base.pixi.root.addChild(tiledMap); }); ``` #### Usage 2. import tmx resources into a appResource, and load tmx file from source code ``` typescript CG.Base.resourceManager.addAppSource('test/beach.tmx'); CG.Base.resourceManager.load(() => { CG.Base.pixi.initialize(600, 600); let tiledMap = new CG.TMXMap.MapRenderer('test/beach.tmx') CG.Base.pixi.root.addChild(tiledMap); }); ``` To use tmx of appSource (usage 2), you need to modify the tmx: * tileset > source (tsx file) change "filename" to "resourceAlias:filename" * tileset > image > source (embeded tileset) change "filename" to "resourceAlias" or "resourceAlias:filename" ## Versioning We use [SemVer](http://semver.org/) for versioning. ## Authors * **[Haskasu](/profile/Haskasu)** ## Resources * [Official Tiled Documentation](http://doc.mapeditor.org/en/stable/) * [Tiled Youtube Tutorial](https://www.youtube.com/watch?v=ZwaomOYGuYo)
ⒸCode.Gamelet.com | Privacy Policy | Terms of Service