⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 charactersprite.java

📁 J2ME的游戏原代码!希望能帮助有需要帮助的师兄弟们!
💻 JAVA
字号:
package com.centerscore.game;

import java.io.*;

class CharacterSprite {
    static final private byte MONSTER_MOTION_CYCLES = 2;

    private int m_x;
    private int m_y;

    private int m_dir;
    private int m_type;
    private int m_row;
    private int m_cube;
    private int m_colRow;
    private int m_colCube;
    private int m_colRowTimer;
    private int m_score;
    private int m_lives;

    private int m_img_position;
    private int m_img_cycle;

    // These are for moving qbert back where he was when he dies
    private int m_old_x;
    private int m_old_y;
    private int m_old_row;
    private int m_old_cube;

    // These are used for delay between actions for enemies
    private boolean m_bDelay;
    private int m_step;
    private int m_speed; // speed at which enemies move (delay on square).

    // higher delays make for easier games

    // Shows if the char is on the board
    private boolean m_bOnBoard;

    // This is only for the enemies - so they can know where in
    // the index they are.
    private int m_enemy_index;

    // Shows if the char is to be shown
    private boolean m_bShowChar;

    // For checking for future moves
    private int m_arrFutureMoves[] = new int[8];

    CharacterSprite(int x, int y, int dir,
            int type, int row, int cube, int score, int lives) {

        // initial values
        m_bDelay = true;
        m_bOnBoard = true;
        m_bShowChar = true;
        m_img_position = 0;

        m_step = 1;

        // settable values
        m_x = x;
        m_y = y;
        m_dir = dir;
        m_type = type;
        m_row = row;
        m_cube = cube;
        m_colRow = row;
        m_colCube = cube;
        m_colRowTimer = 0;
        m_score = score;
        m_lives = lives;
        m_img_cycle = 0;//num_imgs;

        storeOldValues();
    }


    int charX() {
        return m_x;
    }


    void setCharX(int x) {
        m_x = x;
    }


    int charY() {
        return m_y;
    }


    void setCharY(int y) {
        m_y = y;
    }


    int charDir() {
        return m_dir;
    }


    void charDir(int dir) {
        m_dir = dir;
    }


    int charType() {
        return m_type;
    }


    void charType(int type) {
        m_type = type;
    }


    int charRow() {
        return m_row;
    }


    void charRow(int row) {
        m_row = row;
    }


    int charCube() {
        return m_cube;
    }


    void charCube(int cube) {
        m_cube = cube;
    }


    int charColRow() {
        return m_colRow;
    }


    void charColRow(int row) {
        m_colRow = row;
    }


    int charColCube() {
        return m_colCube;
    }


    void charColCube(int cube) {
        m_colCube = cube;
    }


    void decrementRowTimer() {
        if (m_colRowTimer > 0) {
            m_colRowTimer--;
        }
    }


    void resetRowTimer(int num) {
        m_colRowTimer = num;
    }


    boolean rowTimerDone() {
        if (m_colRowTimer == 0) {
            m_colRowTimer = -1;
            return true;
        }
        return false;
    }


    boolean rowTimerExpired() {
        if (m_colRowTimer < 0) {
            return true;
        }
        return false;
    }


    int rowTimer() {
        return m_colRowTimer;
    }


    int charScore() {
        return m_score;
    }


    void charScore(int score) {
        m_score = score;
    }


    void charScoreAdd(int pts) {
        m_score += pts;
    }


    int charLives() {
        return m_lives;
    }


    void charLives(int lives) {
        m_lives = lives;
    }


    int[] charFutureMoves() {
        return m_arrFutureMoves;
    }


    void charResetMoves() {
        for (int i = 0; i < m_arrFutureMoves.length; i++) {
            m_arrFutureMoves[i] = 0;
        }
    }


    int charOldX() {
        return m_old_x;
    }


    int charOldY() {
        return m_old_y;
    }


    int charOldRow() {
        return m_old_row;
    }


    int charOldCube() {
        return m_old_cube;
    }


    boolean charShowChar() {
        return m_bShowChar;
    }


    void charShowChar(boolean show) {
        m_bShowChar = show;
    }


    boolean charDelay() {
        boolean temp = false;
        if (m_step > MONSTER_MOTION_CYCLES + m_speed) {
            m_step = 0;
            temp = m_bDelay;
            m_bDelay = false;
        } else {
            temp = m_bDelay;
            m_bDelay = true;
        }
        m_step++;
        return temp;
    }


    void setCharSpeed(int speed) {
        m_speed = speed;
    }


    void charIndex(int index) {
        m_enemy_index = index;
    }


    int charIndex() {
        return m_enemy_index;
    }


    void charOnBoard(boolean on) {
        m_bOnBoard = on;
    }


    boolean charOnBoard() {
        return m_bOnBoard;
    }


    int charPosition() {
        return m_img_position;
    }


    void charPosition(int pos) {
        m_img_position = pos;
    }


    int charImgCycle() {
        return m_img_cycle;
    }


    void setImageCycle(int cycle) {
        m_img_cycle = cycle;
    }


    void storeOldValues() {
        m_old_x = m_x;
        m_old_y = m_y;
        m_old_row = m_row;
        m_old_cube = m_cube;
    }

    void saveSelf(DataOutputStream pDos) throws Exception {
        pDos.writeInt(m_x);
        pDos.writeInt(m_y);

        pDos.writeByte((byte)m_dir);
        pDos.writeByte((byte)m_type);
        pDos.writeByte((byte)m_row);
        pDos.writeByte((byte)m_cube);
        pDos.writeByte((byte)m_colRow);
        pDos.writeByte((byte)m_colCube);
        pDos.writeByte((byte)m_colRowTimer);
        pDos.writeInt(m_score);
        pDos.writeByte((byte)m_lives);
        pDos.writeInt(m_img_position);
        pDos.writeInt(m_img_cycle);

        if (m_type == Globals.QBERT) {
            pDos.writeByte((byte)m_old_x);
            pDos.writeByte((byte)m_old_y);
            pDos.writeByte((byte)m_old_row);
            pDos.writeByte((byte)m_old_cube);
        }
        pDos.writeBoolean(m_bDelay);
        pDos.writeInt(m_step);
        pDos.writeByte((byte)m_speed);
        pDos.writeBoolean(m_bOnBoard);
        pDos.writeInt(m_enemy_index);
        pDos.writeBoolean(m_bShowChar);
        for (int i = 0; i < m_arrFutureMoves.length; i++) {
            pDos.writeByte((byte)m_arrFutureMoves[i]);
        }
    }


    void loadSelf(DataInputStream pDis) throws Exception {
        m_x = pDis.readInt();
        m_y = pDis.readInt();

        m_dir = pDis.readByte();
        m_type = pDis.readByte();
        m_row = pDis.readByte();
        m_cube = pDis.readByte();
        m_colRow = pDis.readByte();
        m_colCube = pDis.readByte();
        m_colRowTimer = pDis.readByte();
        m_score = pDis.readInt();
        m_lives = pDis.readByte();
        m_img_position = pDis.readInt();
        m_img_cycle = pDis.readInt();
        if (m_type == Globals.QBERT) {
            m_old_x = pDis.readByte();
            m_old_y = pDis.readByte();
            m_old_row = pDis.readByte();
            m_old_cube = pDis.readByte();
        }
        m_bDelay = pDis.readBoolean();
        m_step = pDis.readInt();
        m_speed = pDis.readByte();
        m_bOnBoard = pDis.readBoolean();
        m_enemy_index = pDis.readInt();
        m_bShowChar = pDis.readBoolean();

        for (int i = 0; i < m_arrFutureMoves.length; i++) {
            m_arrFutureMoves[i] = pDis.readByte();
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -