Last active
October 5, 2016 00:36
-
-
Save MarcoWorms/fca9a3cfc0d36a84f4775ae43563108c 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
// example of what this code would produce => http://worms.io/pocDeclarative | |
const makePlayer = () => { | |
return { | |
initial: { | |
size: [50, 50], | |
position: [10, 10], | |
physics: true | |
}, | |
on: { | |
mouse: { | |
clicked: (W, self, pointClicked) => { | |
self.fire('Bullet', pointClicked) | |
} | |
}, | |
keyboard: { | |
keyPressed: (W, self, key, keyMapped) => { | |
const angle = keyMapped | |
self.physics.velocity.addVectors([] | |
W.makeVector(angle, 100) | |
]) | |
} | |
}, | |
keyReleased: (W, self, key, keyMapped) => { | |
const reverseAngle = W.makeAngle(keyMapped + 180) | |
self.physics.velocity.addVectors([ | |
W.makeVector(reverseAngle, 100) | |
]) | |
} | |
} | |
}, | |
custom: { | |
fire: (W, self, bulletObject, pointClicked) => { | |
W.create(bulletObject, { | |
position: self.position, | |
direction: W.getAngle(self.position, pointClicked) | |
}) | |
} | |
} | |
} | |
} | |
} | |
makeBullet = () => { | |
return { | |
initial: { | |
size: [5, 5], | |
physics: true | |
}, | |
on: { | |
created: (W, self, helpers) => { | |
self.setPosition(helpers.direction) | |
self.physics.velocity.addVectors( | |
W.makeVector(helpers.direction, 100) | |
) | |
}, | |
leaveLayout: (W, self) => { | |
self.destroy() | |
} | |
} | |
} | |
} | |
const game = { | |
config: { | |
canvas: '.game' | |
}, | |
layout1: { | |
config: (W, layout) => { | |
layout.size = [1280, 720] | |
W.mapKeys: { | |
w: 90, | |
a: 180, | |
s: 270, | |
d: 0, | |
}, | |
} | |
objects: { | |
Player: makePlayer(), | |
Bullet: makeBullet() | |
} | |
} | |
} | |
run(game) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment