So I've got a game in the works, finally. Basically I'm diving headfirst into Java with what I know after a couple semesters and I plan to write as much as I can. I've been doing a lot of planning and not much writing of code (that's how I do things. I plan for a long time and then write it all in a flurry without realizing it), and I've been thinking about hit detection.
How the hell do you do hit detection on anything but a rectangle? I mean, rectangles are easy. Just
and then the same deal for y and height, and then you're done. Simple, easy.
But I don't want everything in my game to be a rectangle or really close to it. Some things (small circles, mainly) work pretty well having a rectangular hitbox, but it'd be nice if I could have a triangular hitbox. I just can't think of a way to make if(between slope and straight line) into actual code.
Am I missing something really obvious and dumb, or is it really that hard? And I don't even wanna think about doing a circlular hitbox.
Note: Programming in Java (because it's all I know, pretty much), which probably isn't the best for this. The only game programs we've done in class was Snake, and that's all 1x1 squares hitting each other, which is piss easy.
How the hell do you do hit detection on anything but a rectangle? I mean, rectangles are easy. Just
Code:
if(thing.x+thing.width > stuff.x && thing.x < stuff.x+stuff.width)
But I don't want everything in my game to be a rectangle or really close to it. Some things (small circles, mainly) work pretty well having a rectangular hitbox, but it'd be nice if I could have a triangular hitbox. I just can't think of a way to make if(between slope and straight line) into actual code.
Am I missing something really obvious and dumb, or is it really that hard? And I don't even wanna think about doing a circlular hitbox.
Note: Programming in Java (because it's all I know, pretty much), which probably isn't the best for this. The only game programs we've done in class was Snake, and that's all 1x1 squares hitting each other, which is piss easy.




Comment