diff --git a/script.js b/script.js index 21523e5..fb8c94a 100644 --- a/script.js +++ b/script.js @@ -136,31 +136,45 @@ class Vector2 { $(document).ready(function($) { var entities = []; - - var entityId = 0; + + var entityId = 0; class Entity { constructor() { - this.id = entityId++; + var entity = this; + this.id = entityId++; this.position = new Vector2(); this.speed = new Vector2(); - var elem = this.elem = $('
').addClass('point').appendTo('body'); - this.row = $('').appendTo('#table_entities'); - this.columns = { - id: $('').text(this.id).appendTo(this.row), - position: $('').appendTo(this.row), - speed: $('').appendTo(this.row), - color: $('').appendTo(this.row), - actions: $('').appendTo(this.row), - } - $('') - .attr('type', 'color') - .change(function(){ - console.log($(this).val()); - elem.css('background-color', $(this).val()); - }) - .appendTo(this.columns.color) - .change(); + this.elem = $('
').addClass('point').appendTo('body'); + this.row = $('').appendTo('#table_entities'); + this.columns = { + id: $('').text(this.id).appendTo(this.row), + position: $('').appendTo(this.row), + speed: $('').appendTo(this.row), + color: $('').appendTo(this.row), + actions: $('').appendTo(this.row), + } + $('') + .attr('type', 'color') + .change(function(){ + entity.elem.css('background-color', $(this).val()); + }) + .appendTo(this.columns.color) + .change(); + $('