Collision and movement in Java2D

Hey guys new to the frequent lurker, first time poster here. Just wondering if it’s feasible to make a whole movement class on it’s own to control other object’s movement. The way it’s set up now in my project, each class has a move() method and it’s starting to get a little complicated and I’m duplicating code, and wanted to remove any duplication that I can. Also, the collision detection for my little game is getting funky too. I’ve had to do some weird things to make sure that objects don’t get stuck in eachother. Anyways, just wondering what you’re suggestions are. Here’s my github:


Thanks for anyhelp in advance!

Is it possible? Sure. I would suggest just trying it out and seeing what happens.

You might also consider having all of your classes extend another class, say MovableObject, that contains all of the standard movement and collision code.

That’s a good idea, I think I’ll try the MovableObject class. I’d have to make that abstract right?

You could. And it might make sense that way. But you don’t have to do anything.

You could also make these interfaces with default methods.

What has collision got to do with Java2D? Or with any other graphics library?

Ahh right sorry, I was just having trouble with the collision detection. Nothing to do explicitly with Java2D, but more to do with my understanding of how I should be doing it.

Logic (collision, movement, physics, etc.) has nothing to do with what’s used to render something.

Still, graphic libraries like awt and java2d can be helpful for collision detection. For example, one might use a shape for its contains or intersects function, or a point for it distance function.

That’s what I said? lol

Oh, sorry, didn’t notice.