This site requires JavaScript, please enable it in your browser!
Greenfoot back
thegamer
thegamer wrote ...

2012/4/2

code help please!!!

1
2
thegamer thegamer

2012/4/4

#
can anyone help please
davmac davmac

2012/4/4

#
Your code?
danpost danpost

2012/4/4

#
Do you want them to alternate shots?? or random decision as to which shoots?? or just seperate keys for each to shoot??
thegamer thegamer

2012/4/5

#
What i plan to do is to make option page and have one level which is two player and have another which the dimentions randomly shoot
thegamer thegamer

2012/4/5

#
danpost wrote...
Do you want them to alternate shots?? or random decision as to which shoots?? or just seperate keys for each to shoot??
also want them to have separate keys to shoot
davmac davmac

2012/4/5

#
I gave you a suggestion (actually I gave you two suggestions) and you said it didn't work. I know that it should have worked, so there is most likely a problem with your code when you tried it. If you post that code, we can help you find the error in it.
thegamer thegamer

2012/4/5

#
here is both of the codes penival:
port greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class penival here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class penival extends Actor
{    
    /**
     * Act - do whatever the penival wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {       
      
      if (Greenfoot.isKeyDown("left")) 
      {
       move(-3);
      } 
      if (Greenfoot.isKeyDown("right"))
      { 
       move(3);
      }     
      String key = Greenfoot.getKey();  
      if ("space".equals(key)) 
      {  
       fire();
      }  
 

    }        
    /**
     * Fire the penival
     */
    private void fire()
    {
    
       Bullet bullet = new Bullet();
       getWorld().addObject(bullet, getX(), getY());
       bullet.setRotation(getRotation());
    }
}
dimentions:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Dimentions here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Dimentions extends Actor
{
    /**
     * Act - do whatever the Dimentions wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
    
         if (Greenfoot.isKeyDown("a"))
    {
       move(-3);
    } 
    if (Greenfoot.isKeyDown("d"))
    {
        move(3);
    }       
    String key = Greenfoot.getKey();  
    if ("z".equals(key))
    {  
       fire();   
    }      
    
    }
    
    /**
     * Fire the dimentions
     */
    private void fire()
    {
    
       Bullet2 bullet2 = new Bullet2();
       getWorld().addObject(bullet2, getX(), getY());
       bullet2.setRotation(getRotation());
    }
    }   
thegamer thegamer

2012/4/5

#
sorry for the penival i missed out the import part but thats not the problem
davmac davmac

2012/4/5

#
Ok; I can't really see how this is very different from your code before. My two suggestions were:
For instance, use a variable to keep track of whether the key was up or down last time you checked, and only fire if it was up last time and down this time. Alternatively, you can move the getKey() into a single location (such as the world) and then have it control the other objects depending on which key was pressed
Which of these did you want to try?
thegamer thegamer

2012/4/5

#
both could you please type the code what you think it should be
thegamer thegamer

2012/4/5

#
i don't know i am very confused
davmac davmac

2012/4/5

#
Well, no, I'm not going to write the code for you; it's important that you at least give it a go yourself. If you make a decent effort, and it doesn't work, I'll gladly help you to correct it. Perhaps you should go through the Greenfoot tutorials (see the "Documentation" link at the top of the page); seems like you're not very familiar with some of the more basic concepts, and the tutorials would help you a lot (watch the videos!)
thegamer thegamer

2012/4/5

#
i have but i have got the to shoot by it only allow on person to shoot at a time and i want both of them to shoot
thegamer thegamer

2012/4/12

#
confused people please help!!!!!!!!!!
danpost danpost

2012/4/12

#
You should probably check the key presses in the world and call a method in the appropriate class depending on the key.
You need to login to post a reply.
1
2