<commit_before>package org.jill.game.entities.obj;

import java.awt.image.BufferedImage;
import org.jill.game.entities.obj.abs.AbstractParameterObjectEntity;
import org.jill.game.entities.obj.util.UtilityObjectEntity;
import org.jill.openjill.core.api.entities.BackgroundEntity;
import org.jill.openjill.core.api.message.object.ObjectListMessage;
import org.jill.openjill.core.api.message.statusbar.inventory.
        InventoryPointMessage;
import org.jill.openjill.core.api.entities.ObjectEntity;
import org.jill.openjill.core.api.entities.ObjectParam;
import org.jill.openjill.core.api.keyboard.KeyboardLayout;
import org.jill.openjill.core.api.message.EnumMessageType;
import org.jill.openjill.core.api.message.statusbar.inventory.InventoryLifeMessage;

/**
 * Apple object.
 *
 * @author <NAME>
 */
public final class BladeManager extends AbstractParameterObjectEntity {
    /**
     * To remove this object from object lis.
     */
    private ObjectListMessage killme;

    /**
     * Picture array.
     */
    private BufferedImage[] images;
    
    /**
     * SubState value to remove blade.
     */
    private int subStateToRemoveMe;
    
    /**
     * Background map.
     */
    private BackgroundEntity[][] backgroundObject;

    /**
     * Default constructor.
     *
     * @param objectParam object parameter
     */
    @Override
    public void init(final ObjectParam objectParam) {
        super.init(objectParam);

        int tileIndex = getConfInteger("tile");
        int tileSetIndex = getConfInteger("tileSet");

        int numberTileSet = getConfInteger("numberTileSet");
        
        this.subStateToRemoveMe = getConfInteger("subStateToRemoveMe");

        // Load picture for each object. Don't use cache cause some picture
        // change between jill episod.
        this.images
            = new BufferedImage[numberTileSet];

        for (int index = 0; index < numberTileSet; index++) {
            this.images[index]
                = this.pictureCache.getImage(tileSetIndex, tileIndex
                    + index);
        }

        this.backgroundObject = objectParam.getBackgroundObject();
        
        // Remove me from list of object (= kill me)
        this.killme = new ObjectListMessage(this, false);
    }

    /*
    @Override
    public void msgTouch(final ObjectEntity obj,
            final KeyboardLayout keyboardLayout) {
        if (obj.isPlayer()) {
            this.messageDispatcher.sendMessage(EnumMessageType.OBJECT, killme);

            if (this.getState() == 0) {
                this.messageDispatcher.sendMessage(
                        EnumMessageType.INVENTORY_POINT,
                    new InventoryPointMessage(getConfInteger("point"), true,
                    this, obj));

                this.messageDispatcher.sendMessage(
                        EnumMessageType.INVENTORY_LIFE,
                        new InventoryLifeMessage(getConfInteger("life")));

                if (messageDisplayAppleMessage) {
                    sendMessage();
                    messageDisplayAppleMessage = false;
                }
            } else {
                Integer msgId = (getState() + getConfInteger("boxMsgOffset"))
                                & getConfInteger("boxMsgMask") ;
                this.messageDispatcher.sendMessage(
                        EnumMessageType.MESSAGE_BOX, msgId);
            }
        }
    }*/

    @Override
    public BufferedImage msgDraw() {
        return this.images[this.counter];
    }

    /**
     * Call to update.
     */
    @Override
    public void msgUpdate(final KeyboardLayout keyboardLayout) {
        setCounter(getCounter() + 1);
        setSubState(getSubState() + 1);

        if (getCounter() >= this.images.length) {
            setCounter(0);
        }
     
        // Remove blade
        if (getSubState() >= this.subStateToRemoveMe) {
            this.messageDispatcher.sendMessage(EnumMessageType.OBJECT, killme);
        }
        
        moveUpDown();
        
        moveLeftRight();
        
        System.out.println("----------");
        System.out.println("x = " + getX());
        System.out.println("y = " + getY());
        System.out.println("xSpeed = " + getxSpeed());
        System.out.println("ySpeed = " + getySpeed());
        System.out.println("subState = " + getSubState());
        System.out.println("counter = " + getCounter());
    }

    /**
     * Move blade up or down.
     */
    private void moveUpDown() {
        final int oldY = getY();
        
        setySpeed(getySpeed() + 1);
        
        // Move blade
        if (getySpeed() > Y_SPEED_MIDDLE) {
            // Move down
            if (!UtilityObjectEntity.moveObjectDown(this, getySpeed(),
                    backgroundObject) && oldY == getY()) {
                setySpeed(getySpeed() * -1);
            }
        } else {
            // Move up
            if (!UtilityObjectEntity.moveObjectUp(this, getySpeed(),
                    backgroundObject) && oldY == getY()) {
                setySpeed(getySpeed() * -1);
            }
        }
    }

    /**
     * Move blade left or right.
     */
    private void moveLeftRight() {
        if ((getxSpeed() > X_SPEED_MIDDLE
                && !UtilityObjectEntity.moveObjectRight(this, getxSpeed(),
                    backgroundObject))
                || (getxSpeed() < X_SPEED_MIDDLE
                && !UtilityObjectEntity.moveObjectLeft(this, getxSpeed(),
                        backgroundObject))) {<commit_msg>Rework Blade object (object 50).<commit_after>package org.jill.game.entities.obj;

import java.awt.image.BufferedImage;
import org.jill.game.entities.obj.abs.AbstractParameterObjectEntity;
import org.jill.game.entities.obj.util.UtilityObjectEntity;
import org.jill.openjill.core.api.entities.BackgroundEntity;
import org.jill.openjill.core.api.message.object.ObjectListMessage;
import org.jill.openjill.core.api.entities.ObjectEntity;
import org.jill.openjill.core.api.entities.ObjectParam;
import org.jill.openjill.core.api.keyboard.KeyboardLayout;
import org.jill.openjill.core.api.message.EnumMessageType;

/**
 * Apple object.
 *
 * @author <NAME>
 */
public final class BladeManager extends AbstractParameterObjectEntity {
    /**
     * To remove this object from object lis.
     */
    private ObjectListMessage killme;

    /**
     * Picture array.
     */
    private BufferedImage[] images;
    
    /**
     * SubState value to remove blade.
     */
    private int subStateToRemoveMe;
    
    /**
     * Background map.
     */
    private BackgroundEntity[][] backgroundObject;

    /**
     * Default constructor.
     *
     * @param objectParam object parameter
     */
    @Override
    public void init(final ObjectParam objectParam) {
        super.init(objectParam);

        int tileIndex = getConfInteger("tile");
        int tileSetIndex = getConfInteger("tileSet");

        int numberTileSet = getConfInteger("numberTileSet");
        
        this.subStateToRemoveMe = getConfInteger("subStateToRemoveMe");

        // Load picture for each object. Don't use cache cause some picture
        // change between jill episod.
        this.images
            = new BufferedImage[numberTileSet];

        for (int index = 0; index < numberTileSet; index++) {
            this.images[index]
                = this.pictureCache.getImage(tileSetIndex, tileIndex
                    + index);
        }

        this.backgroundObject = objectParam.getBackgroundObject();
        
        // Remove me from list of object (= kill me)
        this.killme = new ObjectListMessage(this, false);
        
        setRemoveOutOfVisibleScreen(true);
    }

    
    @Override
    public void msgTouch(final ObjectEntity obj,
            final KeyboardLayout keyboardLayout) {
        if (obj.isPlayer()) {
            this.messageDispatcher.sendMessage(EnumMessageType.OBJECT, killme);
        } else if (obj.isKillableObject()) {
            obj.msgKill(this, 0, 0);
        }
    }

    @Override
    public BufferedImage msgDraw() {
        return this.images[this.counter];
    }

    /**
     * Call to update.
     */
    @Override
    public void msgUpdate(final KeyboardLayout keyboardLayout) {
        setCounter(getCounter() - 1);
        setSubState(getSubState() + 1);

        if (getCounter() == -1) {
            setCounter(this.images.length - 1);
        }
     
        // Remove blade
        if (getSubState() >= this.subStateToRemoveMe) {
            this.messageDispatcher.sendMessage(EnumMessageType.OBJECT, killme);
        }
        
        moveLeftRight();
                
        moveUpDown();
    }

    /**
     * Move blade up or down.
     */
    private void moveUpDown() {
        // If blade can't move fully, way not change.
        // Way change only when blade don't move.
        final int oldY = getY();
        
        setySpeed(getySpeed() + 1);
        
        // Move blade
        if (getySpeed() > Y_SPEED_MIDDLE) {
            // Move down
            if (!UtilityObjectEntity.moveObjectDown(this, getySpeed(),
                    backgroundObject) && oldY == getY()) {
                setySpeed(getySpeed() * -1);
            }
        } else {
            // Move up
            if (!UtilityObjectEntity.moveObjectUp(this, getySpeed(),
                    backgroundObject) && oldY == getY()) {
                setySpeed(getySpeed() * -1);
            }
        }
    }

    /**
     * Move blade left or right.
     */
    private void moveLeftRight() {
        // If blade can't move fully, way not change.
        // Way change only when blade don't move.
        final int oldX = getX();
        
        if (((getxSpeed() > X_SPEED_MIDDLE
                && !UtilityObjectEntity.moveObjectRight(this, getxSpeed(),
                    backgroundObject))
                || (getxSpeed() < X_SPEED_MIDDLE
                && !UtilityObjectEntity.moveObjectLeft(this, getxSpeed(),
                        backgroundObject))) && oldX == getX()) {
{'fraction_non_alphanumeric': 0.10969285999202234, 'fraction_numerical': 0.001994415636218588, 'mean_word_length': 1.9488385768891503, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2409127', 'n_tokens_mistral': 2821, 'n_tokens_neox': 2739, 'n_words': 552}