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
SPower SPower

2012/6/26

#
No, like this:
Ship ship = new Ship();
Shot shot = new Shot(ship);
ThinkingPainter ThinkingPainter

2012/6/26

#
Ive put this exactly the way you told me to and its still giving me errors
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class RedBlip here.
 * 
 * @author (Caleb Painter) 
 * @version (6/22/2012 VERSION 1.0)
 */
public class Blip extends Actor
{
   private int shotTimer = 0;

 /**
     * Act - do whatever the Blip wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
      if (shotTimer > 0) {
            shotTimer = shotTimer - 1;
        }
        else if (Greenfoot.isKeyDown("space")) {
            getWorld().addObject(new Shot(this), getX(), getY());
            shotTimer = 100; // delay next shot
        }
        if (Greenfoot.isKeyDown("w"))
      {
          move(4); 
        }
      if (Greenfoot.isKeyDown("a"))
      {
          turn (-3);
      }
      if (Greenfoot.isKeyDown("d"))
      {
          turn(3);
      }
      if (Greenfoot.isKeyDown("s"))
      {
          move(-4);
      }
          
    {    
       Ship ship = new Ship();  
       Shot shot = new Shot(ship);   
       // set the rotation      
      // add it to the world     
        
    }  
      eat();    
   
    }   
  
    
        public Blip()  
 {  
    GreenfootImage image = getImage();  
    image.scale(image.getWidth() - 10, image.getHeight() - 10);  
    setImage(image);  
 }  
  public void eat()
  {
      Actor goldenball;
      goldenball= getOneObjectAtOffset(0, 0, GoldenBall.class);
      if (goldenball != null)
      {
          World world;
          world = getWorld();
          world.removeObject(goldenball);
          
        }
        }
   
    
    }
error: cannot find symbol - class ship
SPower SPower

2012/6/26

#
I'm sorry, Ship should be Blip.
ThinkingPainter ThinkingPainter

2012/6/26

#
Change first line correct 2nd line not so much
Shot shot = new Shot(ship);
error: cannot find symbol - variable ship. I changed it to Blip, Shot also and gives me same error code.
SPower SPower

2012/6/26

#
This code should work:
Blip blip = new Blip();
Shot shot = new Shot(blip);
ThinkingPainter ThinkingPainter

2012/6/26

#
Were good there!!! just its still shooting the Shot in a straight line :P
SPower SPower

2012/6/26

#
I actually wonder why you don't understand this, I see this in your code:
getWorld().addObject(new Shot(this), getX(), getY());
That's almost what you want! You only have to change it to this:
Shot shot = new Shot(this);
shot.setRotation(getRotation());
getWorld().addObject(shot, getX(), getY());
SPower SPower

2012/6/26

#
ThinkingPainter wrote...
Were good there!!! just its still shooting the Shot in a straight line :P
Duhh, you didn't implement setting the rotation...
ThinkingPainter ThinkingPainter

2012/6/26

#
i dont understand it because ive just started coding a couple days ago, sorry i have no idea what anything means yet unlike someone whose been studying this for years, i appreciate you help here, most of the stuff that you see in my code is me copying and pasting
SPower SPower

2012/6/26

#
I think you better start on a simpler scenario, if you're still a beginner...
ThinkingPainter ThinkingPainter

2012/6/26

#
{    
       Blip blip = new Blip();  
       Shot shot = new Shot(blip);
       shot.setRotation(getRotation());  
       getWorld().addObject(shot, getX(), getY());
       // set the rotation      
      // add it to the world     
        
    }  
this just made me fire repeatedly and its still firing in a straight line
ThinkingPainter ThinkingPainter

2012/6/26

#
I think that i can do anything i set my mind too... simplier doesnt mean its going to help me ill edventually get up this again and will have to learn it
SPower SPower

2012/6/26

#
ThinkingPainter wrote...
{    
       Blip blip = new Blip();  
       Shot shot = new Shot(blip);
       shot.setRotation(getRotation());  
       getWorld().addObject(shot, getX(), getY());
       // set the rotation      
      // add it to the world     
        
    }  
this just made me fire repeatedly and its still firing in a straight line
Then, it's probably because the rotation of the blip is 0.
ThinkingPainter wrote...
I think that i can do anything i set my mind too... simplier doesnt mean its going to help me ill edventually get up this again and will have to learn it
It is a lot easier when you learn it with an easier scenario.
ThinkingPainter ThinkingPainter

2012/6/26

#
Where would you reccommend i start?
SPower SPower

2012/6/26

#
How about the Greenfoot book?
There are more replies on the next page.
1
2
3
4
5