|
| 1 | +//Moving Enemies |
| 2 | + |
| 3 | +var data = [{'x':1150, 'y':750}, {'x':1150, 'y':750}, {'x':1150, 'y':750}, {'x':1150, 'y':750}, {'x':1150, 'y':750}, |
| 4 | +{'x':1150, 'y':750}, {'x':1150, 'y':750}, {'x':1150, 'y':750}, {'x':1150, 'y':750}, {'x':1150, 'y':750}, |
| 5 | +{'x':1150, 'y':750}, {'x':1150, 'y':750}, {'x':1150, 'y':750}]; |
| 6 | + |
| 7 | +var update = function(data){ |
| 8 | + d3.select('body').selectAll('image').data(data).enter().append('image') |
| 9 | + .transition() |
| 10 | + .duration(1500) |
| 11 | + .attr('x', function(d){return d.x*Math.random()}) |
| 12 | + .attr('y', function(d){return d.y*Math.random()}) |
| 13 | + .style("height", function(d){return 50 + "px"}) |
| 14 | + .style("width", function(d){return 50 + "px"}) |
| 15 | +}; |
| 16 | +// var update = function(data){ |
| 17 | +// d3.select('body').selectAll('.enemy') |
| 18 | +// .data(data) |
| 19 | +// .transition() |
| 20 | +// .duration(1500) |
| 21 | +// .attr("x", function(d){ |
| 22 | +// return d.x * Math.random() |
| 23 | +// }) |
| 24 | +// .attr("y", function(d){ |
| 25 | +// return d.y * Math.random() |
| 26 | +// }) |
| 27 | +// }; |
| 28 | + |
| 29 | +update(data); |
| 30 | + |
| 31 | +setInterval(function(){ |
| 32 | + update(data) |
| 33 | +}, 1500); |
| 34 | + |
| 35 | +//__________________________________________________________________________________________________________________ |
| 36 | +//Draggable Player |
| 37 | + |
| 38 | +var drag = d3.behavior.drag() |
| 39 | + // .on('dragstart', function() { circle.style('fill', 'red'); }) |
| 40 | + .on('drag', function() { lebron.attr('x', d3.event.x) |
| 41 | + .attr('y', d3.event.y); }) |
| 42 | + // .on('dragend', function() { circle.style('fill', 'black'); }); |
| 43 | + |
| 44 | +var lebron = d3.select('body').selectAll('.player') |
| 45 | + .data([{ 'x': 565, 'y': 365}]) |
| 46 | + .attr('x', function(d) { return d.x; }) |
| 47 | + .attr('y', function(d) { return d.y; }) |
| 48 | + .call(drag) |
| 49 | + |
| 50 | +//__________________________________________________________________________________________________________________ |
| 51 | +//Collisions |
| 52 | + |
| 53 | +var collision = function(){ |
| 54 | + var array = []; |
| 55 | + |
| 56 | + var enemyPos = d3.selectAll('.enemy').each(function(d){console.log(d.x)}); |
| 57 | + // var playerPos = d3.selectAll('.player').each(function(d){ |
| 58 | + // return d |
| 59 | + // }) |
| 60 | + // console.log(enemyPos); |
| 61 | +} |
| 62 | +setInterval(function(){ |
| 63 | + collision() |
| 64 | +}, 750) |
| 65 | + |
| 66 | + |
| 67 | +//__________________________________________________________________________________________________________________ |
| 68 | +//Current Score |
| 69 | +var count = 0 |
| 70 | + |
| 71 | +var current = function(){ |
| 72 | + d3.select('.current').selectAll('span') |
| 73 | + .text(count++) |
| 74 | +} |
| 75 | + |
| 76 | +setInterval(function(){ |
| 77 | + current() |
| 78 | +}, 750) |
| 79 | + |
0 commit comments