-
Notifications
You must be signed in to change notification settings - Fork 0
/
food.js
33 lines (28 loc) · 787 Bytes
/
food.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
var food = function(){
return {
init : function () {
this.y = Math.random() * (world.bottom - world.top) + world.top
this.x = Math.random() * (world.right - world.left) + world.left
this.id = (''+Math.random()).replace('.', '');
this.radius = 10
$('#world').append('<div class="food" id="food-'+this.id+'"></div>');
this.el = $('#food-'+this.id);
this.el.css({
transform : 'translate3d('+this.x+'px, '+this.y+'px, 0)',
width : this.radius * 2,
height : this.radius * 2,
top : -this.radius,
left : -this.radius
})
},
beEaten : function () {
this.el.remove()
_.remove(foods, {id : this.id})
//if(foods.length < min_food_count){
var new_food = food()
new_food.init()
foods.push(new_food)
//}
}
}
}