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

2023/5/25

#
danpost danpost

2023/5/25

#
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 !!!
Magzlum Magzlum

2023/6/1

#
in what code should i put it (enemy or ice)
/**
 * 
 */
public class ice extends Actor
{

    /**
     * Act - do whatever the ice wants to do. This method is called whenever the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act()
    {
        move(5);
        dog d = (dog) getOneIntersectingObject(dog.class);
        enemy v = (enemy) getOneIntersectingObject(enemy.class);
         if (v != null)
       {
          if ( ! isTouching(enemy.class)) move(0); 
       }   
          if (d != null)
       {
           move(0);
       }   
    }
}
this is my ice code if you need it
danpost danpost

2023/6/1

#
Magzlum wrote...
in what code should i put it (enemy or ice) << Code Omitted >> this is my ice code if you need it
The line I provided would go in the enemy class. In general, you can check for collision in either of the interacting object's classes, but only in one of them. Usually, it is easier to code what you want in one of the classes, where it is harder to code it in the other. Since the interaction between ice and enemy affects the enemy object, it would probably be easiest to code that interaction in the class of the enemy. As far as the ice class code you provided, there are some issues to be aware of. First, using zero as an argument in the move method call is pointless. Moving by no amount does not change anything. That being said, lines 13 through 22 do exactly nothing. It does not stop line 12 from moving the ice five cells to the right, if that is what was intended. The next thing is that lines 15 and 17 basically ask the same thing -- is there an enemy object that intersects the ice object. All I see in the ice class is:
import greenfoot.*;

public class ice extends Actor
{
    public void act()
    {
        move(5);
    }
}
Now, what happens if the ice object does not encounter any enemies and finds itself at the right edge of the world? It should probably be removed from the world at that point, so the act method should probably be:
public void act()
{
    move(5);
    if (isAtEdge()) getWorld().removeObject(this);
}
You still have not provided information on what the ice should do when interacting with an enemy or shown your enemy class codes here.
Magzlum Magzlum

2023/6/8

#
https://www.greenfoot.org/scenarios/31564 this is my game in case you didnt understand what it looked like, and what i have so pls give me some things i can put in my game and a better ice code
danpost danpost

2023/6/8

#
Magzlum wrote...
https://www.greenfoot.org/scenarios/31564 this is my game in case you didnt understand what it looked like, and what i have so pls give me some things i can put in my game and a better ice code
Cannot better codes unseen. It would help if you uploaded your scenario again (update it), but with the Publish source code check box checked.
You need to login to post a reply.