Results 1 to 8 of 8
- 06-27-2011, 10:20 PM #1
Member
- Join Date
- Jun 2011
- Posts
- 8
- Rep Power
- 0
Getting the right coordinates (Bubblegame)
Hello everyone,
Being busy with my game I came along another problem. But first I'll explain what the idea is of this class 'Hangbubble': The main idea is to create a game like Bubblegame. The hangbubble class is used for to call the bubble class to create a bubble and then place it on the gamefield.
The methods used therefore are to find if there's no other gameItem or Gametile at that coordinate/location.
If there's one of those things it will raise the coordinate bij 10 (is the size of all tiles and gameitems) en will do that untill there's a free place. Then it will ad the bubble as a new gameitem at that coordinate. At the start it will create 5 rows of 23bubbles (23 bubbles is horizontal max number of bubbles/line)
A timer will also call this class randomly to create 1 line (23 bubbles) that will fill the empty spots.
My problem is that my bubbles don't get the desired coordinates. It must start at (x,y) : 10,0 then for the next 20,0 and so on and then when a row is full it will start again but then at 10,10 ; 20,10 and so on.
They stick at 10,0 (I add the int n (=10) to it but nothing seems to happen)
Here's the class hangbubble code
After that i've got another problem with collissions of bubbles that are being shot and these hanging bubbles (same specs = delete gameitem, else the bubble that was shot will be added to the hangbubbles) But that i'll try to find out later (maybe using a arraylist to with coordinates and colortypes)Java Code:public class Hangbubble extends Bubble{ private int points; public static int kleur; private int x ; private int y ; private Bubblegame mijnspel; public Hangbubble(Bubblegame mijnspel) { this.mijnspel = mijnspel; System.out.println("Klasse hangbubble wordt aangeroepen " + mijnspel); points = 20; x=10; y=0; for (int i = 0; i< 23;i++ ) { System.out.println("Nieuwe hangbubble"); Bubble bb = new Bubble(); bb.kleurkiezen(mijnspel); setImage(bb.s); zoekRuimte(x,y); bb.setPosition(x,y); mijnspel.addGameItem(bb); } } public void zoekRuimte(int x, int y) { int n=10; System.out.println("Start ruimte zoeken en x,y is " + x + "," + y ); //System.out.println("alles: " + points + "," + mijnspel ); if (mijnspel == null) { System.out.println ("nullpointerexeption fout"); } while (mijnspel.findItemAt(x,y,getFrameWidth(),getFrameHeight()) != null ) { x=x+n; System.out.println("Iets gevonden, x wordt " + x); } if (mijnspel.findItemAt(x,y,getFrameWidth(),getFrameHeight()) == null ) //Kijkt of er bubble op de x-as zit { if (mijnspel.findTilesAt (x,y,getFrameWidth(),getFrameHeight()) == 0 ) // Als er geen bubble op locatie ... zit dan wordt daar een bubble geplaatst { System.out.println("Coordinaten om te plaatsen " + x + "," + y ); } else { x=10; y=y+n; zoekRuimte(x, y); } } else { System.out.println("foutmelding"); } } public int getPoints() { return points; } }
Last edited by NGE; 06-27-2011 at 10:59 PM.
- 06-27-2011, 10:48 PM #2
What was the first problem?i've got another problem
- 06-27-2011, 10:50 PM #3
Member
- Join Date
- Jun 2011
- Posts
- 8
- Rep Power
- 0
Correction: First problem is the first part with the code beneath it.
The final sentence i wrote is for later.Last edited by NGE; 06-27-2011 at 10:53 PM.
- 06-27-2011, 10:55 PM #4
Sorry, I don't see where you ask a question in the first part. All I see is documentation for how the program works.
- 06-27-2011, 11:01 PM #5
Member
- Join Date
- Jun 2011
- Posts
- 8
- Rep Power
- 0
Stupid me ... I wrote it all down and forget the most important thing

I added the question in blue
- 06-27-2011, 11:07 PM #6
Try debugging your code by printing out the coordinates for each bubble as you add it.
I see you have some already in your code. What is printed out when the code is executed?
Sorry, I don't understand what this means.It must start at (x,y) : 10,0 then for the next 20,0 and so on
Do the x,y values go from 10,0 to 11,0 to 12,0, ... 20,0?
- 06-27-2011, 11:14 PM #7
Member
- Join Date
- Jun 2011
- Posts
- 8
- Rep Power
- 0
My println says this
The idea is, that when a place is taken it will move with 10 (= size of a gameItem or a gameTile) next to it. When it moves 1 there still will be the same gameItem or tile (because of the size of it).Java Code:Nieuwe hangbubble De kleurcode is 5[COLOR="blue"]is println from other class[/COLOR] Nummer 5 is gekozen en de kleur wordt er aan gebonden[COLOR="blue"]is println from other class[/COLOR] /images/Bubblerood.png[COLOR="blue"]is println from other class[/COLOR] Start ruimte zoeken en x,y is 10,0 Coordinaten om te plaatsen 10,0
It will stick with 'Coordinaten om te plaatsen 10,0' each time it's like it doesn't see that the first time something was placed there.
- 06-27-2011, 11:19 PM #8
The only way I am able to solve these kinds of logic problems is by adding enough printlns to show where the logic problem is.
If x is supposed to change every time x happens and it is not changed where you need it, if you print out x's value every time it is changed, then the printouts will show where it is being reset or incorrectly set.
Similar Threads
-
Coordinates out of bounds
By trishtren in forum Java 2DReplies: 3Last Post: 05-19-2011, 08:10 PM -
Coordinates in PDFBox
By arunsegar in forum Advanced JavaReplies: 1Last Post: 05-16-2011, 09:41 AM -
Help Getting Image Coordinates
By Witik in forum New To JavaReplies: 2Last Post: 09-06-2010, 01:02 PM -
Coordinates
By Witik in forum New To JavaReplies: 3Last Post: 09-06-2010, 07:05 AM -
coordinates and radius
By tepong in forum New To JavaReplies: 1Last Post: 08-21-2010, 06:38 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks