Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (791)
Games in Android Showcase (234)
games submitted by our members
Games in WIP (864)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  collision detection problem  (Read 1389 times)
0 Members and 1 Guest are viewing this topic.
Offline safater

Junior Newbie

« Posted 2013-01-23 14:50:24 »

I've been working on a dropdown shooter game i've been working on this for a long time now i have not been able to solve one problem that's stopping me from proggressing

my code :

I know its too long but i cant really ask one part of it as it wouldnt make sense
i have an array of tiles the map which makes up the map each tile location ad rectangle is represented in borders[] array
and i have the bullet rectangle which changes continuesly
what i want is if bullet collides with any of the tiles it should dissappear you can see from my messy code that i've tried numerous ways

and any advice on how to improve my code would be greatly appreciated

and if i get to fix this i would share my game and maybe show people how easy it is to make one
any help is greatly appreciated since this is bugging me for days now
thanks in advance
Offline doos

Senior Devvie

Medals: 2
Projects: 2

Here be random

« Reply #1 - Posted 2013-01-23 20:18:44 »

Making stuff disappear is easy. Just set the missile position to null in your array and skip nulls on the draw and hit steps. You've got an array of borders, have one for missiles.

I see what you're doing with all the rectangles for the map array, but you could try putting your missile rectangle into that space.. I mean, if you know that your missile is somewhere within in the grids (2,2),(2,3), (3,2), (3,3), then you only need to check the rectangles of 4 grids instead of all of them.
Offline safater

Junior Newbie

« Reply #2 - Posted 2013-01-23 21:15:18 »

ok so if i want to make it clear because i don't think i have completely understood you
you're telling me to make an array of missiles make it like the borders array so it only draws them where they should appear
lets say
0 0 1 (or nulls)                                                                                               1 1 1
0 1 0                                                                                                            0 1 0
1 0 0 .. if this is what you meant how do i check collision here if lets the borders are  0 0 0 then i would stop drawing at the 1 in the center? just to clarify
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline doos

Senior Devvie

Medals: 2
Projects: 2

Here be random

« Reply #3 - Posted 2013-01-24 01:00:17 »

Two different peices here:

if you set a missile in the array to null you can skip drawing it, and dont try doing hit detection with it either.

Rectangle[] missles = new Rectangle[3];

for (Rectangle missile:missiles){

if (missile == null){
else {


And heres the other bit:
Lets say you know your missile has two corners: (20,20) and (30,30). If thats so, its going to be in the first grid in your map array since your rectangles are size 50x50.. So why are you testing every single border object? You can narrow the search down. If you want to.

Pages: [1]
  ignore  |  Print  

hadezbladez (2895 views)
2018-11-16 13:46:03

hadezbladez (1046 views)
2018-11-16 13:41:33

hadezbladez (2846 views)
2018-11-16 13:35:35

hadezbladez (560 views)
2018-11-16 13:32:03

EgonOlsen (3839 views)
2018-06-10 19:43:48

EgonOlsen (4256 views)
2018-06-10 19:43:44

EgonOlsen (2552 views)
2018-06-10 19:43:20

DesertCoockie (3367 views)
2018-05-13 18:23:11

nelsongames (3481 views)
2018-04-24 18:15:36

nelsongames (4492 views)
2018-04-24 18:14:32
Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!