package com.javarush.task.task24.task2413; /** * ÐазовÑй клаÑÑ Ð´Ð»Ñ Ð²ÑÐµÑ Ð¾Ð±ÑекÑов игÑÑ. */ public abstract class BaseObject { //кооÑдинаÑÑ protected double x; protected double y; //ÑадиÑÑ Ð¾Ð±ÑекÑа protected double radius; protected BaseObject(double x, double y, double radius) { this.x = x; this.y = y; this.radius = radius; } public double getX() { return x; } public void setX(double x) { this.x = x; } public double getY() { return y; } public void setY(double y) { this.y = y; } public double getRadius() { return radius; } public void setRadius(double radius) { this.radius = radius; } /** * ÐеÑод ÑиÑÑÐµÑ Ñвой обÑÐµÐºÑ Ð½Ð° "канваÑе". */ abstract void draw(Canvas canvas); /** * Ðвигаем ÑÐµÐ±Ñ Ð½Ð° один Ñ Ð¾Ð´. */ abstract void move(); /** * ÐÑовеÑÑем - не вÑÑ Ð¾Ð´Ð¸Ñ Ð»Ð¸ (x,y) за гÑаниÑÑ. */ void checkBorders(double minx, double maxx, double miny, double maxy) { if (x < minx) x = minx; if (x > maxx) x = maxx; if (y < miny) y = miny; if (y > maxy) y = maxy; } /** * ÐÑовеÑÑем - пеÑеÑекаÑÑÑÑ Ð»Ð¸ пеÑеданнÑй(o) и наÑ(this) обÑекÑÑ. */ boolean isIntersec(BaseObject o) { double dx = x - o.x; double dy = y - o.y; double destination = Math.sqrt(dx * dx + dy * dy); double destination2 = Math.max(radius, o.radius); return destination <= destination2; } }