Best collision detection for falling enemies ?

Hi guys :). I’ve hit a little bit or a wall and was wondering if anyone could help me. I’m creating my first game that spawns random enemies and as they fall down, the player has to dodge them. The enemies are stored in an array and I’ve used rectangles etc for collision detection but I’m not sure how to do this for my current issue.

if 2 rectangles are colliding you need to check if the sides are overlapping.

check if object1’s right side is > object2’s left side and object 1’s left side is < object 2’s right side. you can use your 2 hands to visualize this and what conditions are happening as your hands first touch, then pass over each other, or you could use 2 pieces of paper, this will help you understand whats happening, and what logic youre trying to code. do the same with the top and bottom sides.

The issue I have is this though D:

My class init’s an array of inactive enemies and then in the render, for any enemies that are active, it renders the enemies at a random location. I then used a variable called currentEnemies that increments every 850mili seconds and creates an active enemy, a max of 8. My issue is, how do I give every single enemy a rectangle from the Slick.geom class, relative to it’s position when created?. My instint tells me I need an array of rectangles but I keep getting a null pointer exception

Sorry if it’s a easy question, arrays are not my strong point but I’m getting better at them :slight_smile:

i would make a class called Enemy. store any data relevant to the enemies position, size, rectangle, graphics image, etc in this class. then you can make an array of type Enemy, and store each enemy (and all of its data) in the array.

I got it working :stuck_out_tongue: well a little. I have a problem somewhere but I’m sure I’ll find it in a minute. I’m only doing this project to get use to game programming so it’s a great learning experience :slight_smile: