-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added demo game for script node course
Signed-off-by: Scott Westover <[email protected]>
- Loading branch information
1 parent
744cd30
commit f38ac5e
Showing
29 changed files
with
1,109 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
hugo-site/static/games/phaser-editor-script-nodes/assets/asset-pack.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{ | ||
"section1": { | ||
"files": [ | ||
{ | ||
"url": "assets/sunnyland/environment/back.png", | ||
"type": "image", | ||
"key": "back" | ||
}, | ||
{ | ||
"url": "assets/kenny-button/button_rectangle_depth_gradient.png", | ||
"type": "image", | ||
"key": "button_rectangle_depth_gradient" | ||
}, | ||
{ | ||
"url": "assets/kenny-button/button_rectangle_gradient.png", | ||
"type": "image", | ||
"key": "button_rectangle_gradient" | ||
}, | ||
{ | ||
"url": "assets/sunnyland/sprites/instructions.png", | ||
"type": "image", | ||
"key": "instructions" | ||
}, | ||
{ | ||
"url": "assets/sunnyland/environment/middle.png", | ||
"type": "image", | ||
"key": "middle" | ||
}, | ||
{ | ||
"url": "assets/sunnyland/sprites/press-enter-text.png", | ||
"type": "image", | ||
"key": "press-enter-text" | ||
}, | ||
{ | ||
"url": "assets/sunnyland/sprites/title-screen.png", | ||
"type": "image", | ||
"key": "title-screen" | ||
} | ||
] | ||
}, | ||
"meta": { | ||
"app": "Phaser Editor 2D - Asset Pack Editor", | ||
"contentType": "phasereditor2d.pack.core.AssetContentType", | ||
"url": "https://phasereditor2d.com", | ||
"version": 2, | ||
"showAllFilesInBlocks": false | ||
} | ||
} |
Binary file added
BIN
+1.05 KB
...ser-editor-script-nodes/assets/kenny-button/button_rectangle_depth_gradient.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+969 Bytes
...es/phaser-editor-script-nodes/assets/kenny-button/button_rectangle_gradient.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+8.04 KB
...e/static/games/phaser-editor-script-nodes/assets/sunnyland/environment/back.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+6.74 KB
...static/games/phaser-editor-script-nodes/assets/sunnyland/environment/middle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.16 KB
...atic/games/phaser-editor-script-nodes/assets/sunnyland/sprites/instructions.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.19 KB
.../games/phaser-editor-script-nodes/assets/sunnyland/sprites/press-enter-text.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.51 KB
...atic/games/phaser-editor-script-nodes/assets/sunnyland/sprites/title-screen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions
28
hugo-site/static/games/phaser-editor-script-nodes/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
|
||
<title>My Game</title> | ||
|
||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/phaser.min.js"></script> | ||
<script src="src/main.js" type="module"></script> | ||
|
||
<style> | ||
body { | ||
background: #2f2f2f; | ||
margin: 0; | ||
padding: 0; | ||
} | ||
</style> | ||
|
||
</head> | ||
|
||
<body> | ||
</body> | ||
|
||
</html> | ||
|
||
|
46 changes: 46 additions & 0 deletions
46
.../static/games/phaser-editor-script-nodes/phaserjs_editor_scripts_base/ActionTargetComp.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// You can write more code here | ||
/* END-USER-IMPORTS */ | ||
export default class ActionTargetComp { | ||
constructor(gameObject) { | ||
this.gameObject = gameObject; | ||
gameObject["__ActionTargetComp"] = this; | ||
/* START-USER-CTR-CODE */ | ||
// Write your code here. | ||
/* END-USER-CTR-CODE */ | ||
} | ||
static getComponent(gameObject) { | ||
return gameObject["__ActionTargetComp"]; | ||
} | ||
gameObject; | ||
target = "GAME_OBJECT"; | ||
targetName = ""; | ||
/* START-USER-CODE */ | ||
static getTargetGameObject(scriptNode, args) { | ||
const comp = ActionTargetComp.getComponent(scriptNode); | ||
if (comp) { | ||
switch (comp.target) { | ||
case "GAME_OBJECT": | ||
return scriptNode.gameObject; | ||
case "ARG_1": | ||
return args[0]; | ||
case "ARG_2": | ||
return args[1]; | ||
case "ARG_3": | ||
return args[2]; | ||
case "ARG_4": | ||
return args[3]; | ||
case "ARG_5": | ||
return args[4]; | ||
case "ARG_6": | ||
return args[5]; | ||
case "ARG_7": | ||
return args[6]; | ||
case "ARG_8": | ||
return args[7]; | ||
} | ||
} | ||
return scriptNode.gameObject; | ||
} | ||
} | ||
/* END OF COMPILED CODE */ | ||
// You can write more code here |
95 changes: 95 additions & 0 deletions
95
hugo-site/static/games/phaser-editor-script-nodes/phaserjs_editor_scripts_base/ScriptNode.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import ActionTargetComp from "./ActionTargetComp.js"; | ||
export default class ScriptNode { | ||
_scene; | ||
_gameObject; | ||
_parent; | ||
_children; | ||
constructor(parent) { | ||
this._parent = parent; | ||
if (parent instanceof ScriptNode) { | ||
this._scene = parent.scene; | ||
this._gameObject = parent.gameObject; | ||
parent.add(this); | ||
} | ||
else if (parent instanceof Phaser.GameObjects.GameObject) { | ||
this._scene = parent.scene; | ||
this._gameObject = parent; | ||
} | ||
else { | ||
this._scene = parent; | ||
} | ||
const listenAwake = this.awake !== ScriptNode.prototype.awake; | ||
const listenStart = this.start !== ScriptNode.prototype.start; | ||
const listenUpdate = this.update !== ScriptNode.prototype.update; | ||
const listenDestroy = this.destroy !== ScriptNode.prototype.destroy; | ||
if (listenAwake) { | ||
this.scene.events.once("scene-awake", this.awake, this); | ||
} | ||
if (listenStart) { | ||
this.scene.events.once(Phaser.Scenes.Events.UPDATE, this.start, this); | ||
} | ||
if (listenUpdate) { | ||
this.scene.events.on(Phaser.Scenes.Events.UPDATE, this.update, this); | ||
} | ||
if (listenAwake || listenStart || listenUpdate || listenDestroy) { | ||
const destroyCallback = () => { | ||
this.scene.events.off("scene-awake", this.awake, this); | ||
this.scene.events.off(Phaser.Scenes.Events.UPDATE, this.start, this); | ||
this.scene.events.off(Phaser.Scenes.Events.UPDATE, this.update, this); | ||
if (listenDestroy) { | ||
this.destroy(); | ||
} | ||
}; | ||
if (this.gameObject) { | ||
this.gameObject.on(Phaser.GameObjects.Events.DESTROY, destroyCallback); | ||
} | ||
else { | ||
this.scene.events.on(Phaser.Scenes.Events.SHUTDOWN, destroyCallback); | ||
} | ||
} | ||
} | ||
getActionTargetObject(args) { | ||
const target = ActionTargetComp.getTargetGameObject(this, args); | ||
return target; | ||
} | ||
get scene() { | ||
return this._scene; | ||
} | ||
get gameObject() { | ||
return this._gameObject; | ||
} | ||
get parent() { | ||
return this._parent; | ||
} | ||
get children() { | ||
if (!this._children) { | ||
this._children = []; | ||
} | ||
return this._children; | ||
} | ||
add(child) { | ||
this.children.push(child); | ||
} | ||
executeChildren(...args) { | ||
if (this._children) { | ||
for (const child of this._children) { | ||
child.execute(...args); | ||
} | ||
} | ||
} | ||
execute(...args) { | ||
// override this on executable nodes | ||
} | ||
awake() { | ||
// override this | ||
} | ||
start() { | ||
// override this | ||
} | ||
update() { | ||
// override this | ||
} | ||
destroy() { | ||
// override this | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...ite/static/games/phaser-editor-script-nodes/phaserjs_editor_scripts_base/UserComponent.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
export default class UserComponent { | ||
/** | ||
* @param gameObject The entity. | ||
*/ | ||
constructor(gameObject) { | ||
this.scene = gameObject.scene; | ||
const listenAwake = this.awake !== UserComponent.prototype.awake; | ||
const listenStart = this.start !== UserComponent.prototype.start; | ||
const listenUpdate = this.update !== UserComponent.prototype.update; | ||
const listenDestroy = this.destroy !== UserComponent.prototype.destroy; | ||
if (listenAwake) { | ||
this.scene.events.once("scene-awake", this.awake, this); | ||
} | ||
if (listenStart) { | ||
this.scene.events.once(Phaser.Scenes.Events.UPDATE, this.start, this); | ||
} | ||
if (listenUpdate) { | ||
this.scene.events.on(Phaser.Scenes.Events.UPDATE, this.update, this); | ||
} | ||
if (listenStart || listenUpdate || listenDestroy) { | ||
gameObject.on(Phaser.GameObjects.Events.DESTROY, () => { | ||
this.scene.events.off(Phaser.Scenes.Events.UPDATE, this.start, this); | ||
this.scene.events.off(Phaser.Scenes.Events.UPDATE, this.update, this); | ||
if (listenDestroy) { | ||
this.destroy(); | ||
} | ||
}); | ||
} | ||
} | ||
scene; | ||
awake() { | ||
// override this | ||
} | ||
start() { | ||
// override this | ||
} | ||
update() { | ||
// override this | ||
} | ||
destroy() { | ||
// override this | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
hugo-site/static/games/phaser-editor-script-nodes/phaserjs_editor_scripts_base/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export { default as ScriptNode } from "./ScriptNode.js"; | ||
export { default as UserComponent } from "./UserComponent.js"; | ||
export { default as ActionTargetComp } from "./ActionTargetComp.js"; |
22 changes: 22 additions & 0 deletions
22
hugo-site/static/games/phaser-editor-script-nodes/src/main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import ButtonExample from "./scenes/ButtonExample.js"; | ||
import Title from "./scenes/Title.js"; | ||
import Preload from "./scenes/Preload.js"; | ||
|
||
window.addEventListener('load', function () { | ||
|
||
var game = new Phaser.Game({ | ||
width: 288, | ||
height: 192, | ||
type: Phaser.AUTO, | ||
backgroundColor: "#242424", | ||
scale: { | ||
mode: Phaser.Scale.FIT, | ||
autoCenter: Phaser.Scale.CENTER_BOTH | ||
}, | ||
pixelArt: true | ||
}); | ||
|
||
game.scene.add("ButtonExample", ButtonExample); | ||
game.scene.add("Title", Title); | ||
game.scene.add("Preload", Preload, true); | ||
}); |
93 changes: 93 additions & 0 deletions
93
hugo-site/static/games/phaser-editor-script-nodes/src/scenes/ButtonExample.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
|
||
// You can write more code here | ||
|
||
/* START OF COMPILED CODE */ | ||
|
||
import OnPointerDownActionScript from "../scriptnodes/gameobjects/OnPointerDownActionScript.js"; | ||
import LogMessageActionScript from "../scriptnodes/utils/LogMessageActionScript.js"; | ||
import OnPointerEventActionScript from "../scriptnodes/gameobjects/OnPointerEventActionScript.js"; | ||
import UpdateTextureActionScript from "../scriptnodes/gameobjects/UpdateTextureActionScript.js"; | ||
/* START-USER-IMPORTS */ | ||
/* END-USER-IMPORTS */ | ||
|
||
export default class ButtonExample extends Phaser.Scene { | ||
|
||
constructor() { | ||
super("ButtonExample"); | ||
|
||
/* START-USER-CTR-CODE */ | ||
// Write your code here. | ||
/* END-USER-CTR-CODE */ | ||
} | ||
|
||
/** @returns {void} */ | ||
editorCreate() { | ||
|
||
// blueButton | ||
const blueButton = this.add.image(144, 96, "button_rectangle_depth_gradient"); | ||
blueButton.scaleX = 0.3; | ||
blueButton.scaleY = 0.3; | ||
|
||
// onPointerDownActionScript | ||
const onPointerDownActionScript = new OnPointerDownActionScript(blueButton); | ||
|
||
// logMessageActionScript | ||
const logMessageActionScript = new LogMessageActionScript(onPointerDownActionScript); | ||
|
||
// onPointerEventActionScript | ||
const onPointerEventActionScript = new OnPointerEventActionScript(blueButton); | ||
|
||
// logMessageActionScript_1 | ||
const logMessageActionScript_1 = new LogMessageActionScript(onPointerEventActionScript); | ||
|
||
// updateTextureActionScript_1 | ||
const updateTextureActionScript_1 = new UpdateTextureActionScript(onPointerEventActionScript); | ||
|
||
// onPointerEventActionScript_1 | ||
const onPointerEventActionScript_1 = new OnPointerEventActionScript(blueButton); | ||
|
||
// logMessageActionScript_2 | ||
const logMessageActionScript_2 = new LogMessageActionScript(onPointerEventActionScript_1); | ||
|
||
// updateTextureActionScript | ||
const updateTextureActionScript = new UpdateTextureActionScript(onPointerEventActionScript_1); | ||
|
||
// onPointerDownActionScript (prefab fields) | ||
onPointerDownActionScript.once = true; | ||
|
||
// logMessageActionScript (prefab fields) | ||
logMessageActionScript.message = "the button was clicked"; | ||
|
||
// logMessageActionScript_1 (prefab fields) | ||
logMessageActionScript_1.message = "pointerover"; | ||
|
||
// updateTextureActionScript_1 (prefab fields) | ||
updateTextureActionScript_1.textureConfig = {"key":"button_rectangle_gradient"}; | ||
|
||
// onPointerEventActionScript_1 (prefab fields) | ||
onPointerEventActionScript_1.inputEvent = "pointerout"; | ||
|
||
// logMessageActionScript_2 (prefab fields) | ||
logMessageActionScript_2.message = "pointerout"; | ||
|
||
// updateTextureActionScript (prefab fields) | ||
updateTextureActionScript.textureConfig = {"key":"button_rectangle_depth_gradient"}; | ||
|
||
this.events.emit("scene-awake"); | ||
} | ||
|
||
/* START-USER-CODE */ | ||
|
||
// Write your code here | ||
|
||
create() { | ||
|
||
this.editorCreate(); | ||
} | ||
|
||
/* END-USER-CODE */ | ||
} | ||
|
||
/* END OF COMPILED CODE */ | ||
|
||
// You can write more code here |
Oops, something went wrong.