Answer the question
In order to leave comments, you need to log in
Why are the squares drawn at the wrong size?
What I think is the problematic code
I have a program where squares move around the screen. But I have a problem, even though side = 30, the squares are very big. Where is my mistake?
public class Ball extends AFigure {
float x, y, vx, vy;
Paint p;
int side;
Ball(int w ,int h){
p = new Paint(Color.BLACK);
p.setStyle(Paint.Style.FILL);
side = 30;
x = (float) (Math.random()*w);
y = (float) (Math.random()*h);
vx = (float)(Math.random() * 8) + 8;
vy = (float)(Math.random() * 8) + 8;
}
@Override
public void draw(Canvas s) {
s.drawRect(x, y, side, side, p);
}
@Override
public void move(int w, int h) {
if (x > w || x < 0) vx *= -1;
if (y > h || y < 0) vy *= -1;
x += vx;
y += vy;
}
}
Answer the question
In order to leave comments, you need to log in
I figured out the problem. The answer is here https://medium.com/better-programming/learn-all-an...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question