...
this.culc_frame = function() {
// Mutex
if (mutex)
return;
else
mutex = true;
// clear Area is now separated from draw
var padding = 10;
this.canvas.fillStyle = 'black';
this.canvas.fillRect(0, 0, this.canvas_width - 1, this.canvas_height - 1);
this.canvas.strokeStyle = 'white';
this.canvas.lineWidth = 1;
this.canvas.strokeRect(padding, padding, this.arena_width, this.arena_height);
...
control = this.shells[i].action(robot_info[i], robot_info.filter(exclude_myself), shot_info, {arena_width: this.arena_width, arena_height: this.arena_height, robot_radius: this.robot_radius, shot_speed: 12}, engine.canvas );
...
// Draws current frame on canvas from string
// Using string params useful for battle replays
this.draw = function(situation) {
// Clear Background
var padding = 10;
this.canvas.fillStyle = 'black';
this.canvas.fillRect(0, 0, this.canvas_width - 1, this.canvas_height - 1);
this.canvas.strokeStyle = 'white';
this.canvas.lineWidth = 1;
this.canvas.strokeRect(padding, padding, this.arena_width, this.arena_height);
// Draw robots
current_index = 0;
...
this.action = function(my_state, enemies, shots, params, this_canvas )
// ,
for (var i = 0; i < shots.length; i++)
{
var shot_dest = get_shot_destination(shots[i]);
this_canvas.globalAlpha = 0.3;
this_canvas.beginPath();
this_canvas.arc(10 + shot_dest.x, 10 + shot_dest.y, 20, 0, Math.PI * 2, true);
this_canvas.closePath();
this_canvas.fillStyle = 'red';
this_canvas.fill();
this_canvas.globalAlpha = 1;
}
Source: https://habr.com/ru/post/75698/
All Articles