So, I'm working on teaching myself Canvas (HTML5) and having most of the simple game engine. This is a 2d representation of the cosmic scene (planets, stars, celestial bodies, etc.). My "Sprite" class has a frame listener by default, such as:
"baseClass" contains a function that allows you to inherit and applies "a" to "this.a". So, "var aTest = new Sprite ({foo:" bar "}); will do" aTest.foo = "bar" ". This is how I open my objects to each other.
Sprite = baseClass.extend({
init: function(a){
baseClass.init(this, a);
this.fields = new Array();
this.addFL(function(tick){
for(i = 0; i < gobjs.length; i++){
if(typeof(gobjs[i].a) != undefined && !gobjs[i].a.ignoreGravity && gobjs[i].id != this.id){
if(this.distanceTo(gobjs[i]) < this.a.size*10 && gobjs[i].fields.indexOf(this.id) == -1){
gobjs[i].fields.push(this.id);
}
}
}
for(i = 0; i < this.fields.length; i++){
distance = this.distanceTo(gobjs[this.fields[i]]);
angletosun = this.angleTo(gobjs[this.fields[i]])*(180/Math.PI);
this.a.angle = angletosun+(75+(distance*-1)/5);
if(this.distanceTo(gobjs[this.fields[i]]) > gobjs[this.fields[i]].a.size*10){
this.fields.splice(i);
}
}
});
}
});
Thanks in advance. The real trick is that there is one line, and by the way, I know that this makes no sense. Degrees + distance = failure.
this.a.angle = angletosun+(75+(distance*-1)/5);
, Javascript, - . .