#include "library.h" struct actor { double xpos, ypos; double speed, reach; int hue; string yay; }; actor create(double x, double y, double spd, double rch, int col, string s) { actor a; a.xpos = x; a.ypos = y; a.speed = spd; a.reach = rch; a.hue = col; a.yay = s; return a; } void update(actor & runner, actor target, double ti) { move_to(runner.xpos, runner.ypos); double a = direction_from_to_in_radians(runner.xpos, runner.ypos, target.xpos, target.ypos); double d = runner.speed * ti; runner.xpos += d * sin(a); runner.ypos -= d * cos(a); set_pen_color(runner.hue); draw_to(runner.xpos, runner.ypos); double farness = distance_to(target.xpos, target.ypos); if (farness < runner.reach) write_string(runner.yay); } void main() { const int fieldw = 500, fieldl = 800; const double timeint = 0.001; actor boy = create(100, fieldw, 8, 2, color::blue, "Boy gets apple and is safe"); actor bull = create(0, 0, 10, 4, color::red, "Graaah! Bull eats boy!"); actor tree = create(fieldl/4*3, fieldw/2, 0, 0, color::green, "Tree eats both"); make_window(fieldl+3, fieldw+3); fill_rectangle(0, 0, fieldl, fieldw, color::green); fill_rectangle(1, 1, fieldl-2, fieldw-2, color::white); set_pen_width(3); while (true) { update(boy, tree, timeint); update(bull, boy, timeint); update(tree, tree, timeint); } }