Results 1 to 8 of 8
  1. #1
    NGE
    NGE is offline Member
    Join Date
    Jun 2011
    Posts
    8
    Rep Power
    0

    Question 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
    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;
    		}
    
    	
    
    
    
    
    }
    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)
    Last edited by NGE; 06-27-2011 at 10:59 PM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    i've got another problem
    What was the first problem?

  3. #3
    NGE
    NGE is offline Member
    Join Date
    Jun 2011
    Posts
    8
    Rep Power
    0

    Default

    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.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    Sorry, I don't see where you ask a question in the first part. All I see is documentation for how the program works.

  5. #5
    NGE
    NGE is offline Member
    Join Date
    Jun 2011
    Posts
    8
    Rep Power
    0

    Default

    Stupid me ... I wrote it all down and forget the most important thing
    I added the question in blue

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    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?

    It must start at (x,y) : 10,0 then for the next 20,0 and so on
    Sorry, I don't understand what this means.
    Do the x,y values go from 10,0 to 11,0 to 12,0, ... 20,0?

  7. #7
    NGE
    NGE is offline Member
    Join Date
    Jun 2011
    Posts
    8
    Rep Power
    0

    Default

    My println says this
    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
    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).

    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.

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    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

  1. Coordinates out of bounds
    By trishtren in forum Java 2D
    Replies: 3
    Last Post: 05-19-2011, 08:10 PM
  2. Coordinates in PDFBox
    By arunsegar in forum Advanced Java
    Replies: 1
    Last Post: 05-16-2011, 09:41 AM
  3. Help Getting Image Coordinates
    By Witik in forum New To Java
    Replies: 2
    Last Post: 09-06-2010, 01:02 PM
  4. Coordinates
    By Witik in forum New To Java
    Replies: 3
    Last Post: 09-06-2010, 07:05 AM
  5. coordinates and radius
    By tepong in forum New To Java
    Replies: 1
    Last Post: 08-21-2010, 06:38 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •