Last active
October 7, 2016 05:35
-
-
Save MarcoWorms/5bcd3c884a8d50df27155e1eba3f5f79 to your computer and use it in GitHub Desktop.
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
// | |
// Motivations: | |
// | |
// * bring accessible functional programming to game development | |
// * handy and easy default options for quick game prototyping | |
// * flexibility for advanced game developers | |
const W = { | |
getAngle: (pointA, pointB) => null, | |
emit: (channel, message, data) => null | |
} | |
const layout_default_config = { | |
size: [1280, 720], | |
layers: ['layer1', 'layer2'] | |
} | |
const my_display_component = { | |
type: 'display', | |
layer: 'layer 1', | |
angle: 0, | |
opacity: 100, | |
position: [50, 50], | |
size: [100, 100], | |
visible: true | |
} | |
const my_text_component = { | |
type: 'text', | |
value: 'Kiwi', | |
init: (thisComponent, components) => { | |
thisComponent.value('Hello World!!!!!!!!') | |
} | |
} | |
const my_image_component = { | |
type: 'image', | |
source: './image.png' | |
} | |
const my_custom_component = { | |
init: (components) => { | |
components.byType('display').position([60, 60]) | |
}, | |
every_frame: (components) => { | |
components.byType('display').position(['+', 10, 10]) | |
}, | |
destroyed: (components) => { | |
} | |
} | |
const my_collision_component = { | |
type: 'collision', | |
source: './collision_map.json', | |
targets: ['bar'], | |
collidedWith: (targetObject) => { | |
targetObject.destroy() | |
} | |
} | |
const bar = [ | |
my_display_component, | |
my_image_component, | |
my_custom_component, | |
my_collision_component, | |
{ | |
type: 'interval', | |
seconds: 3, | |
tiggered: (components) => { | |
W.emit('fooInteractions', 'changeText', 'some data') | |
} | |
} | |
] | |
const foo = [ | |
{ | |
type: 'display', | |
size: [50, 50] | |
}, | |
{ | |
type: 'image', | |
source: './image.png' | |
}, | |
{ | |
type: 'text', | |
value: 'Kiwi', | |
}, | |
{ | |
type: 'subscription', | |
channel: 'fooInteractions', | |
listen: 'changeText', | |
triggered: (components, data) => { | |
components.byType('text').value(data) | |
} | |
} | |
] | |
const layout1 = { | |
config: layout_default_config | |
objects: { | |
foo, | |
bar | |
} | |
} | |
const layouts = { | |
layout1 | |
} | |
const config = { | |
info: { | |
name: 'lorem', | |
version: '0', | |
description: 'lorem', | |
author: 'lorem' | |
}, | |
canvas_size: [1280, 720] | |
} | |
const game = { | |
config, | |
layouts | |
} | |
start(game) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment