Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (526)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (593)
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 475 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 : http://pastebin.java-gaming.org/e58cc3f9c3f

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.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
Rectangle[] missles = new Rectangle[3];

for (Rectangle missile:missiles){

if (missile == null){
continue;
}
else {
   draw(missile);
}

}


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  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

toopeicgaming1999 (73 views)
2014-11-26 15:22:04

toopeicgaming1999 (62 views)
2014-11-26 15:20:36

toopeicgaming1999 (15 views)
2014-11-26 15:20:08

SHC (29 views)
2014-11-25 12:00:59

SHC (27 views)
2014-11-25 11:53:45

Norakomi (32 views)
2014-11-25 11:26:43

Gibbo3771 (27 views)
2014-11-24 19:59:16

trollwarrior1 (40 views)
2014-11-22 12:13:56

xFryIx (78 views)
2014-11-13 12:34:49

digdugdiggy (57 views)
2014-11-12 21:11:50
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org 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‑gaming.org
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!