Separate move timer from draw timer
This commit is contained in:
		
							parent
							
								
									e79fbf72c8
								
							
						
					
					
						commit
						8e657a870a
					
				| @ -63,6 +63,8 @@ Number.prototype.div = function(divisor) { | ||||
| function init_walk() { | ||||
|   // Draw a grid of boxes on the canvas
 | ||||
|   setInterval(draw, 20); | ||||
|   // TODO: it would be cool to have this changable, but I may just ... not
 | ||||
|   setInterval(move_walker, controls.step_time); | ||||
| 
 | ||||
|   /* | ||||
| 
 | ||||
| @ -89,14 +91,8 @@ function init_walk() { | ||||
|   */ | ||||
| } | ||||
| 
 | ||||
| function move_walker(walker, possible_directions) { | ||||
|   // Update new random direction & update velocity of walker
 | ||||
|   var new_angle = Math.random() * 360 | ||||
|   walker.x_position = (walker.x_position + walker.x_velocity).mod(canvas.width); | ||||
|   walker.y_position = (walker.y_position + walker.y_velocity).mod(canvas.height); | ||||
|   walker.angle = degrees_to_radians(get_nearest_angle(new_angle, possible_directions)) | ||||
|   walker.x_velocity = walker.speed * Math.cos(walker.angle) | ||||
|   walker.y_velocity = walker.speed * Math.sin(walker.angle) | ||||
| function move_walker() { | ||||
|   add_random_direction(walker_pos); | ||||
| } | ||||
| 
 | ||||
| function add_random_direction(pos) { | ||||
| @ -148,7 +144,6 @@ function draw() { | ||||
| 
 | ||||
|   // draw a colored square at the walker location
 | ||||
|   draw_grid_square(walker_pos.row, walker_pos.col, "red"); | ||||
|   add_random_direction(walker_pos); | ||||
| 
 | ||||
|   // TODO CODE
 | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user