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

2019/6/17

Greenfoot movement

dionzeka99 dionzeka99

2019/6/17

#
Hello I am creating the famouse Space Invaders game for an exam and I wanted to create the horizontally and vertically movement like in the real game and so I wanted to ask if somebody could help me doing it please ?
danpost danpost

2019/6/17

#
dionzeka99 wrote...
Hello I am creating the famouse Space Invaders game for an exam and I wanted to create the horizontally and vertically movement like in the real game and so I wanted to ask if somebody could help me doing it please ?
Maybe check out my Space Invaders Movement Demo scenario. Actually the movement is almost like the original game. Only difference is the movement of the rows is backward. That is, the bottom row should move first -- not the top (which should be an easy fix).
dionzeka99 dionzeka99

2019/6/18

#
danpost wrote...
dionzeka99 wrote...
Hello I am creating the famouse Space Invaders game for an exam and I wanted to create the horizontally and vertically movement like in the real game and so I wanted to ask if somebody could help me doing it please ?
Maybe check out my Space Invaders Movement Demo scenario. Actually the movement is almost like the original game. Only difference is the movement of the rows is backward. That is, the bottom row should move first -- not the top (which should be an easy fix).
Hello danpost, I looked at your demo and I checked your row class but when I tried the same on my game it says that the code is incorrect :/
danpost danpost

2019/6/18

#
dionzeka99 wrote...
Hello danpost, I looked at your demo and I checked your row class but when I tried the same on my game it says that the code is incorrect :/
Cannot fix codes that cannot be seen.
dionzeka99 dionzeka99

2019/6/18

#
danpost wrote...
dionzeka99 wrote...
Hello danpost, I looked at your demo and I checked your row class but when I tried the same on my game it says that the code is incorrect :/
Cannot fix codes that cannot be seen.
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Row here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Row extends Actor
{
    /**
     * Act - do whatever the Row wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public Row() 
    {
        // Add your action code here.
    }    
    
    public boolean moveRow(int dir)
    {
     boolean changeDir = false;
     for (Object obj : getIntersectingObjects(Alien.class))
     {
        
      Alien alien = (Alien) obj;
      changeDir = alien.moveAlien(dir) || changeDir;
     
     }
     return changeDir;
    
    }
    
    public void dropRow()
    {
     
   for (Object obj : getIntersectingObjects(Alien.class))
        {
            Actor alien = (Alien) obj;
            alien.setLocation(alien.getX(),alien.getY()+10);
        }
        setLocation(getX(), getY()+10);
    }
the method alien.moveAlien doesn't work
danpost danpost

2019/6/18

#
danpost wrote...
Cannot fix codes that cannot be seen.
Need to see Alien class as well.
dionzeka99 wrote...
the method alien.moveAlien doesn't work
And, what do you mean by "doesn't work"? Any error messages (if so, what are they)?
dionzeka99 dionzeka99

2019/6/19

#
danpost wrote...
danpost wrote...
Cannot fix codes that cannot be seen.
Need to see Alien class as well.
dionzeka99 wrote...
the method alien.moveAlien doesn't work
And, what do you mean by "doesn't work"? Any error messages (if so, what are they)?
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Alien here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Alien extends Actor
{
  private int timer = 2+Greenfoot.getRandomNumber(500);
  public Alien()
  {
      setRotation(0);
  }
    
  /**
     * Act - do whatever the Alien wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
       Actor bullet = getOneIntersectingObject(Bullet.class); //variable qui retourne la classe bullet
       if(bullet!= null) {
          World world = getWorld();
          MyWorld myWorld = (MyWorld)world;
          Counter counter = myWorld.getCounter();
          counter.addScore();
          getWorld().removeObject(this);
        }
       if (--timer==0){
         shoot();
         timer = 2+Greenfoot.getRandomNumber(500);
        }
        
 
       
    }    
    
  public void shoot()
   {
     getWorld().addObject(new AlienBullet(), getX(), getY());   
   }
}
Here's my Alien code and what I meant by doesn't work it is that the "changeDir = alien.moveAlien(dir) || changeDir;" is an error in the code
danpost danpost

2019/6/19

#
I do not see a moveAlien method in your Alien class.
dionzeka99 dionzeka99

2019/6/19

#
danpost wrote...
I do not see a moveAlien method in your Alien class.
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Row here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Row extends Actor
{
    /**
     * Act - do whatever the Row wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public Row() 
    {
        // Add your action code here.
    }    
    
    public boolean moveRow(int dir)
    {
     boolean changeDir = false;
     for (Object obj : getIntersectingObjects(Alien.class))
     {
        
      Alien alien = (Alien) obj;
      changeDir = alien.moveAlien(dir) || changeDir;
     
     }
     return changeDir;
    
    }
    
    public void dropRow()
    {
     
   for (Object obj : getIntersectingObjects(Alien.class))
        {
            Actor alien = (Alien) obj;
            alien.setLocation(alien.getX(),alien.getY()+10);
        }
        setLocation(getX(), getY()+10);
    }
}
Here you can see the moveAlien it says that it is wrong and that I must declare this method
danpost danpost

2019/6/19

#
dionzeka99 wrote...
<< Code Omitted >> Here you can see the moveAlien it says that it is wrong and that I must declare this method
You are showing the Row class where the method is being called from. The problem is that you do not yet have that method in your Alien class to call.
You need to login to post a reply.