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

2012/6/25

Making actor score points/menu tourbleshooting.

1
2
3
4
5
ThinkingPainter ThinkingPainter

2012/6/26

#
i dont see a code button beneath my text field or i would've done it last time sorry, and if by class you mean actor i have a actor class for the shot
SPower SPower

2012/6/26

#
Use that instead of the Shot name I just thought it was :)
ThinkingPainter ThinkingPainter

2012/6/26

#
Shot shot = new shot();  
             // set the rotation  
             // add it to the world
        {
           Shot.setRotation(getRotation()); 
        }
SPower SPower

2012/6/26

#
Yes, that's the code button. But now, indent your code right for the forum and remove this:
{
  Shot.setRotation(getRotation());
}
ThinkingPainter ThinkingPainter

2012/6/26

#
Shot shot = new shot();  
// set the rotation  
// add it to the world
        
still same error after i removed it
SPower SPower

2012/6/26

#
Show me all the code.
SPower SPower

2012/6/26

#
Do you really have a Shot class, which is EXACTLY called Shot?
ThinkingPainter ThinkingPainter

2012/6/26

#
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * A bullet to be shot at asteroids.
 * 
 * The Shot moves to the top of the screen and then expires. If it hits an asteroid
 * on the way, it destroys the asteroid, and then expires immediately.
 */
public class Shot  extends Actor
{
private Blip myShip;

/**
* Constructor for a Shot. You must specify the ship the shot comes from.
*/
public Shot(Blip myShip)
{
this.myShip = myShip;
Shot shot = new shot();  
// set the rotation  
// add it to the world
        
}

/**
* Act - do whatever the Shot wants to do. This method is called whenever
 * the 'Act' or 'Run' button gets pressed in the environment.
 */
 public void act() 
  {
 int ypos = getY();
 if (ypos > 0) {
 ypos = ypos - 5;
 setLocation(getX(), ypos);
Actor rock = getOneIntersectingObject(RedBlip.class);
            if (rock != null) {
// We've hit an asteroid!
    hitAnAsteroid();
  getWorld().removeObject(rock);
   getWorld().removeObject(this);
     }
    }
    else {
  // I reached the top of the screen
  getWorld().removeObject(this);
 }
          
        
 }
    
/**
* This method gets called (from the act method, above) when the shot hits an
* asteroid. It needs to do only one thing: increase the score counter.
* (Everything else, such as removing the asteroid which was hit, is dealt
 * with in the act method).
*/
private void hitAnAsteroid()
{
        Space spaceWorld = (Space) getWorld();  // get a reference to the world
    Counter counter = spaceWorld.getCounter();  // get a reference to the counter
    counter.bumpCount(5);
}
}
 
  


 
  

yes i think i have a shot class i might be wrong
SPower SPower

2012/6/26

#
I think? Just look and you see!
ThinkingPainter ThinkingPainter

2012/6/26

#
This is the code for my actor Shot up above... if by class you mean actor yes i have one....
SPower SPower

2012/6/26

#
OOOO, I didn't see :). You mustn't create a Shot in the shot itself, that code was meant for another class: the class which fires the shots.
ThinkingPainter ThinkingPainter

2012/6/26

#
orly? ill give it a try
ThinkingPainter ThinkingPainter

2012/6/26

#
Whelp its in the class that fires the shot.. but different error
Shot shot = new Shot();    
// set the rotation    
// add it to the world 
"New shot" is giving me error: cannot find symbol - constructor Shot() should i change Shot to my others actor name "Blip" or is it something else?
SPower SPower

2012/6/26

#
No, you wrote your own constructor:
public Shot(Blip myShip)  
{  
this.myShip = myShip;  
Shot shot = new shot();    
// set the rotation    
// add it to the world
}
Instead of:
new Shot();
You now have to put a Ship object between the ()
ThinkingPainter ThinkingPainter

2012/6/26

#
so
Shot shot = new shot(Blip); myShip);      
// set the rotation      
// add it to the world  
it needs to look like this basically?
There are more replies on the next page.
1
2
3
4
5