Repository navigation
Expand file tree
/
Copy pathtest1.html
More file actions
57 lines (50 loc) · 1.88 KB
/
Copy pathtest1.html
File metadata and controls
57 lines (50 loc) · 1.88 KB
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
<html>
<head></head>
<body>
<div id="game"></div>
<script type="text/javascript" src="https://rawgithub.com/craftyjs/Crafty/release/dist/crafty-min.js"></script>
<script>
var speed = 8;
var xLocation = 0;
var yLocation = 250;
var width = 10;
var height = 10;
//game map region
Crafty.init(500,350, document.getElementById('game'));
//first floor
Crafty.e('Floor, 2D, Canvas, Color')
.attr({x: xLocation, y: yLocation, w: width, h: height})
.color('green');
for (var i = 0; i <100; i++){
if ( Math.random()>.5){
var horizontalShift = (500 - xLocation) * Math.random();// + xLocation;
xLocation = horizontalShift;
console.log("xLocation = " + xLocation);
if (Math.random()>.5){
var verticalShift = (350 - yLocation) * Math.random();// + yLocation;
yLocation = verticalShift;
console.log("yLocation = " + yLocation);
}
else{
var verticalShift = (350 - yLocation) * Math.random();// - yLocation;
yLocation = verticalShift;
console.log("yLocation = " + yLocation);
}
}
else{
var horizontalShift = (500 - xLocation) * Math.random();// - xLocation;;
xLocation = horizontalShift;
console.log("xLocation = " + xLocation);
}
Crafty.e('Floor, 2D, Canvas, Color')
.attr({x: xLocation, y: yLocation, w: width, h: height})
.color('green');
}
Crafty.e('2D, Canvas, Color, Fourway, Gravity')
.attr({x: 0, y: 0, w: 10, h: 10})
.color('#F00')
.fourway(speed)
.gravity('Floor');
</script>
</body>
</html>