Results 1 to 3 of 3
  1. #1
    Fortu is offline Member
    Join Date
    Dec 2010
    Posts
    57
    Rep Power
    0

    Default Java Game troubles continue

    I'm getting confused about how to move a rifle that an enemy would drop on screen so that it obeys the same motions as other objects on screen when you begin to move far enough that the background shifts. If anyone could please help it would be appreciated.


    Java Code:
      public void move(ArrayList alien)  // THIS METHOD IS WHERE THE BUG IS
      {
        second = alien;
        x=x+movex;
        if (v == 2)
        {
          v = 0;
          y=y-movey;
          if (movey > -25)
          {
            movey = movey-1;
          }
        }
        if(x<100)
        {
          x=100;
          grass1.shiftX();
          grass2.shiftX();
          grass3.shiftX();
    
          for(int p=0; p<second.size(); p++)
          {
            Brit enemy2 = (Brit) second.get(p);
            enemy2.move2();
    	fourth = enemy2.getSmoothbore(); // Here's the bug. I want to get all rifles
    	//From the enemy class, but the issue is that enemy2 or rifles contained by
    	// enemy2 are not sent to Inner to be painted, so moving them in this way
    	// Does nothing, but I can't think of code to fix this.
    
    	for(int y=0; y<fourth.size(); y++)
    	{
    	  Smoothbore smooth1 = (Smoothbore) fourth.get(y);
    	  smooth1.shiftX();
    	}
          }
        }
        if(x>375)
        {
          x=375;
          grass1.changeX();
          grass2.changeX();
          grass3.changeX();
    
          for(int o=0; o<second.size(); o++)
          {
            Brit enemy2 = (Brit) second.get(o);
            enemy2.move();
    	fourth = enemy2.getSmoothbore();  //Same issue here as above
    	for(int u=0; u<fourth.size(); u++)
    	{
    	  Smoothbore smooth1 = (Smoothbore) fourth.get(u);
    	  smooth1.changeX();
    	}
          }
        }
        if(y<1)
        {
          y=1;
        }
        if(y>371)
        {
          y=371;
        }
        if(y>390)
        {
          y=390;
        }
        v = v + 1;
      }

  2. #2
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    6

    Default

    I think you're going to find yourself needing to resign the structure of part of the application. If multiple objects need to share some bit of arbitrary information (like position at runtime), then perhaps you need to associate both objects with some kind of monitor that allows object to object communication. Best of luck!

  3. #3
    Fortu is offline Member
    Join Date
    Dec 2010
    Posts
    57
    Rep Power
    0

    Default

    Well, I did resign part of the structure of the game. I used logic for just half a second and found that it was silly of me to link my Gun class to my enemy class when I could just keep them separate.

Similar Threads

  1. Replies: 6
    Last Post: 02-13-2012, 09:57 PM
  2. Java Game troubles
    By Fortu in forum New To Java
    Replies: 1
    Last Post: 01-16-2011, 08:53 PM
  3. Continue or not?
    By kliane in forum New To Java
    Replies: 3
    Last Post: 01-19-2010, 02:42 PM
  4. Troubles,convert C/C++ Code to Java
    By cristianll in forum New To Java
    Replies: 1
    Last Post: 11-15-2009, 02:30 AM
  5. How to use Continue
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-17-2008, 07:46 PM

Tags for this Thread

Posting Permissions

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