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

2023/5/11

ice attack

Magzlum Magzlum

2023/5/11

#
I am trying to make a attack with the name "ice" the plan is to make the movement speed of "enemy" nad "dog"my enemies 0 but i dont know how to do it can someone tell me how to do this
danpost danpost

2023/5/11

#
Magzlum wrote...
I am trying to make a attack with the name "ice" the plan is to make the movement speed of "enemy" nad "dog"my enemies 0 but i dont know how to do it can someone tell me how to do this
More information needed. Is this a temporary attack or will the enemies be "froze" there forever? Is there an actor that represents the "ice" and, if so, will it get removed at the end of the attack or when the attack begins or does it remain forever? Your codes for "enemies" should be provided, as well (cannot fix unseen codes).
Deepfist Deepfist

2023/5/11

#
Alright, I have a working method where the enemies get stopped in their tracks. This code should work if you change the names of my actors to your actors. The actor stops it's own movement with this code when it gets hit with the attack, after a set time period they will walk again. If you don't want this then remove the integers and instead only leave frozen1 as active. This is the code for the enemies,
import greenfoot.*; 
public class Enemies extends Actor
{
    public int W; //gives the movement speed, put this as "move(W);"
    public int Freezing = 0; //Countdown for freezing
    public boolean frozen1 = false; //Is the enemy frozen then it's true, if the enemy is not frozen then it's false
    public void act() {
       Frozen();
       if(frozen1 == true) {
             W = 0;
            }
       else {
            W = ...;  //put your own value here
            }
       move(W);
        }
    public void Frozen() {
        if(frozen1 == true) {
            Freezing++;
        }
        if(Freezing >= 100) {
            frozen1 = false;
            Freezing = 0;
        }
    }
}
This is the code of the Freezing attack, it's an actor in this case
import greenfoot.*;  
public class Freezing extends PlayerBullet
{
    public void act()
    {
            Freeze();
    }
    public void Freeze() {
        Enemies enem = (Enemies)getOneIntersectingObject(Enemies.class);
        if(enem != null && enem.frozen1 == false) {
            enem.frozen1 = true;
      }
   }
}
Deepfist Deepfist

2023/5/11

#
You need 2 classes for this, the first class is your enemies class and the second class is a freezing attack.
Magzlum Magzlum

2023/5/25

#
the attack freezes the enemy for a few seconds it should be the attack that freezes the enemy and not another entity
/**
 * Write a description of class villian here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class enemy extends Actor
{
    /**
     * Act - do whatever the enemy wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        move(-3);
       }
}
this is the code for my enemy
verrektecongool verrektecongool

2023/5/25

#
hi
danpost danpost

2023/5/25

#
Magzlum wrote...
the attack freezes the enemy for a few seconds it should be the attack that freezes the enemy and not another entity << Code Omitted >> this is the code for my enemy
A simple solution is to change line 15 to:
if ( ! isTouching(ice.class)) move(-3);
However, this will freeze the enemy until the ice is removed from the world or moves away from the enemy, neither of which is known to happen, as you have not provided any details.
verrektecongool verrektecongool

4 days ago

#
danpost danpost

4 days ago

#
danpost wrote...
However, this will freeze the enemy until the ice is removed from the world or moves away from the enemy, neither of which is known to happen, as you have not provided any details.
Or, until the ice melts. @verrektecongool, such an angry bird !!!
You need to login to post a reply.