Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.12 KB | None | 0 0
  1. const createGame = require('voxel-engine'),
  2. highlight = require('voxel-highlight'),
  3. player = require('voxel-player'),
  4. voxel = require('voxel'),
  5. fly = require('voxel-fly'),
  6. walk = require('voxel-walk'),
  7. label = require('voxel-label'),
  8. AWS = require('aws-sdk');
  9.  
  10. // setup engine
  11. const game = createGame({
  12. generate: function(x, y, z) {
  13. // return (Math.sqrt(x*x + y*y + z*z) > 100 || y*y > 10) ? 0 : (Math.random() * 3) + 1;
  14. return y === 1 ? 1 : 0;
  15. // if (x*x + y*y + z*z > 20*20) return 0;
  16. // return Math.floor(Math.random() * 4) + 1;
  17. },
  18. chunkDistance: 2,
  19. textures: './textures',
  20. worldOrigin: [0, 0, 0],
  21. controls: { discreteFire: true }
  22. });
  23.  
  24. window.game = game; // for debugging
  25.  
  26. // attach engine to document container
  27. const container = document.getElementById('container') || document.body;
  28. game.appendTo(container);
  29.  
  30. // setup player avatar
  31. const avatar = player(game)('player.png');
  32. avatar.possess();
  33. avatar.yaw.position.set(2, 14, 4);
  34.  
  35. // enable flying support
  36. game.flyer = fly(game)(game.controls.target());
  37.  
  38. // block highlighting
  39. let blockPosPlace, blockPosErase;
  40. const hl = game.highlighter = highlight(game, { color: 0xff0000 });
  41.  
  42. hl.on('highlight', (voxelPos) => { blockPosErase = voxelPos });
  43. hl.on('remove', (voxelPos) => { blockPosErase = null });
  44. hl.on('highlight-adjacent', (voxelPos) => { blockPosPlace = voxelPos });
  45. hl.on('remove-adjacent', (voxelPos) => { blockPosPlace = null });
  46.  
  47. // enable 1st person / 3rd person toggle
  48. window.addEventListener('keydown', (ev) => {
  49. if(ev.keyCode === 'R'.charCodeAt(0)) avatar.toggle();
  50. });
  51.  
  52. // block creation/destruction
  53. let currentMaterial = 2;
  54.  
  55. game.on('fire', (target, state) => {
  56. let position = blockPosPlace
  57. if(position){
  58. game.createBlock(position, currentMaterial);
  59. console.log(position)
  60. }
  61. else{
  62. position = blockPosErase;
  63. if(position) game.setBlock(position, 0);
  64. }
  65. });
  66.  
  67. // walking animation
  68. game.on('tick', () => {
  69. const target = game.controls.target();
  70. walk.render(target.playerSkin)
  71. const vx = Math.abs(target.velocity.x),
  72. vz = Math.abs(target.velocity.z);
  73.  
  74. if(vx > 0.001 || vz > 0.001) walk.stopWalking();
  75. else walk.startWalking();
  76. });
  77.  
  78. // sample item mesh
  79. var mesh = new game.THREE.Mesh(
  80. new game.THREE.CubeGeometry(5, 3, 1), // width, height, depth
  81. game.materials.material
  82. )
  83. game.materials.paint(mesh, 'grass')
  84. mesh.position.set(0, 3, -5)
  85. var item = game.addItem({
  86. mesh: mesh,
  87. size: 1,
  88. velocity: { x: 0, y: 0, z: 0 }
  89. })
  90.  
  91.  
  92. // build data center
  93. for(let x=0; x<30; x++){
  94. for(let z=0; z<30; z++){
  95. for(let y=0; y<30; y++){
  96. // walls
  97. if(z == 0 || z === 29 || x == 0 || x === 29){
  98. game.createBlock([x, y, z], 2);
  99. }
  100. // level
  101. if(y % 5 === 0 && ((x < 10 || x > 12) || (z < 10 || z > 12))){
  102. game.createBlock([x,y,z], 3);
  103. }
  104. // roof
  105. if(y === 29){
  106. game.createBlock([x,y,z], 2);
  107. }
  108. }
  109. }
  110. }
  111.  
  112. // cut out door
  113. game.setBlock([0,2,3],0);
  114. game.setBlock([0,2,4],0);
  115. game.setBlock([0,3,3],0);
  116. game.setBlock([0,3,4],0);
  117.  
  118.  
  119.  
  120. // AWS data
  121. const awsParams = {
  122. region: 'us-east-1',
  123. accessKeyId: 'asdaf',
  124. secretAccessKey: 'asdfasd',
  125. sessionToken: 'asdfasdf'
  126. };
  127.  
  128. const eb = new AWS.ElasticBeanstalk(awsParams),
  129. ec2 = new AWS.EC2(awsParams);
  130.  
  131. setTimeout(() => {
  132. console.log('Querying EB...');
  133. eb.describeApplications({}, (err, data) => {
  134. let i = 1;
  135. data.Applications.forEach((app) => {
  136. console.log('Adding block for: %s', app.ApplicationName);
  137. game.createBlock([1, 2*(i++), -5], currentMaterial);
  138. });
  139. });
  140.  
  141. console.log('Querying EC2...');
  142. ec2.describeInstances({}, (err, data) => {
  143. let i = 1;
  144. console.log(data)
  145. data.Reservations.forEach((res) => {
  146. res.Instances.forEach((instance) => {
  147. console.log('Adding block for :%s', instance.InstanceId);
  148. game.createBlock([3, 2*(i++), -5], 3);
  149. });
  150. });
  151. });
  152. }, 2000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement