Android Open Source - TheFirstMyth01 Spirit Main






From Project

Back to project page TheFirstMyth01.

License

The source code is released under:

MIT License

If you think the Android project TheFirstMyth01 listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.game.renwu;
//  ww w.  ja  v a 2  s  . c  o  m
import java.util.ArrayList;
import java.util.List;

import com.game.commen.Direction;
import com.game.data.RoleData;

import android.R;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Typeface;

public class SpiritMain {

  /*
   * ////////////////////////////////////////////////////////////////////////
   * ????????????????????????????????????????Spirit?RPG?????????????????????????????????
   * ???????????????????????????????????????????
   * ?????????????????????????????????????????????????
   * ???????????????????????????????????????????????????????????????
   */
  // ???????????
  private List<Rect> rectlist;
  // ?????
  private List<Rect> waplist;
  // ????????
  public static boolean showwap = false;
  private static RoleData roloinfo;

  public SpiritMain(RoleData roloinfo) {
    super();

    this.roloinfo = roloinfo;
    rectlist = new ArrayList<Rect>();
    waplist = new ArrayList<Rect>();
  }

  int lastflag = 0;
  int flag = 0;
  int flagpao = 3;
  public int[] playflag = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
  public List<String> strlist;

  // ????
  public static void SetWaepenImg(Bitmap wapimg) {
    roloinfo.setWeaponsImg(wapimg);
  }

  int talkline = 0;//????????
  int talktime = 20;//?????????????
  public static int talkflag = 0;//??????
  
  public void myDraw_Spirit(Canvas canvas, Paint paint, int x, int y,
      Direction fangxiang, boolean pao) {

    // ??????
    int oneimgwidth = roloinfo.getPlayerImg().getWidth()
        / roloinfo.getHorizontalcutnum();
    int oneimgHeight = roloinfo.getPlayerImg().getHeight()
        / roloinfo.getVerticalcutnum();

    rectlist = getRectList(roloinfo.getPlayerImg(),
        roloinfo.getHorizontalcutnum(), roloinfo.getVerticalcutnum());
    // ???????
    if (roloinfo.getWeaponsImg() != null) {
      waplist = getRectList(roloinfo.getWeaponsImg(),
          roloinfo.getHorizontalcutnum(),
          roloinfo.getVerticalcutnum());
    }
    // ???????
    SetFangXiang(fangxiang, pao);

    // ????????????
    Rect dst = new Rect();
    // ????????
    dst.left = (int) x - oneimgwidth / 2;
    dst.top = (int) y - oneimgHeight / 2 - oneimgHeight / 4;
    dst.right = (int) x + oneimgwidth / 2;
    dst.bottom = (int) y + oneimgHeight / 2 - oneimgHeight / 4;

    // ?????
    Rect rect_yinzi = new Rect();
    rect_yinzi.left = 0;
    rect_yinzi.top = 0;
    rect_yinzi.right = roloinfo.getYinziImg().getWidth();
    rect_yinzi.bottom = (int) (roloinfo.getYinziImg().getHeight() * 1);

    String str = "??????????????????????????????????";
    strlist = new ArrayList<String>();

    if (str.length() > 0) {
      if ((int) (str.length() % 8) != 0) {
        talkline = (int) (str.length() / 8) + 1;
      } else {
        talkline = (int) (str.length() / 8);
      }
      for (int i = 0; i < talkline; i++) {
        if (i == talkline - 1) {
          strlist.add(str.substring(i * 8, str.length()));
        } else {
          strlist.add(str.substring(i * 8, (i * 8) + 8));
        }

      }
    }

    // ????????????
    Rect rect_yinzi1 = new Rect();
    // ???????
    rect_yinzi1.left = (int) x - roloinfo.getYinziImg().getWidth() / 2;
    rect_yinzi1.top = (int) y - roloinfo.getYinziImg().getHeight();
    rect_yinzi1.right = (int) x + roloinfo.getYinziImg().getWidth() / 2;
    rect_yinzi1.bottom = (int) y
        + (int) (roloinfo.getYinziImg().getHeight() * 0.4);

    // ??????????,?????????????
    canvas.drawBitmap(roloinfo.getYinziImg(), rect_yinzi, rect_yinzi1,
        paint);
    canvas.drawBitmap(roloinfo.getPlayerImg(), rectlist.get(lastflag), dst,
        paint);
    if (showwap == true) {
      canvas.drawBitmap(roloinfo.getWeaponsImg(), waplist.get(lastflag),
          dst, paint);
    }

    // ?????????????????
    paint.setTextSize(20);
    String familyName = "??";
    Typeface font = Typeface.create(familyName, Typeface.NORMAL);
    paint.setColor(Color.WHITE);
    paint.setTypeface(font);
    // ??????
    Paint p2 = new Paint();
    p2.setTextSize(21);
    Typeface font2 = Typeface.create(familyName, Typeface.BOLD);
    p2.setColor(Color.BLACK);
    p2.setTypeface(font2);
    canvas.drawText(roloinfo.getPlayerName(), x - (oneimgwidth / 8) + 1, y
        - (oneimgHeight / 2) + 1, p2);
    canvas.drawText(roloinfo.getPlayerName(), x - (oneimgwidth / 8), y
        - (oneimgHeight / 2), paint);

    // ??????
    Rect rect_talkpaopao = new Rect();
    rect_talkpaopao.left = 0;
    rect_talkpaopao.top = 0;
    rect_talkpaopao.right = roloinfo.getTalkbdImg().getWidth();
    rect_talkpaopao.bottom = roloinfo.getTalkbdImg().getHeight();

    Rect rect_talkpaopao1 = new Rect();
    // ?????????
    rect_talkpaopao1.left = (int) x - roloinfo.getTalkbdImg().getWidth()
        / 2;
    rect_talkpaopao1.top = (int) y
        - (int) (roloinfo.getTalkbdImg().getHeight() * 6)
        - (int) (roloinfo.getTalkbdImg().getHeight() * talkline);
    rect_talkpaopao1.right = (int) x + roloinfo.getTalkbdImg().getWidth()
        / 2;
    rect_talkpaopao1.bottom = (int) y
        - (int) (roloinfo.getTalkbdImg().getHeight() * 5);

    Paint p_talk = new Paint();
    p_talk.setTextSize(16);
    Typeface font3 = Typeface.create(familyName, Typeface.NORMAL);
    p_talk.setColor(Color.WHITE);
    p_talk.setTypeface(font3);
    // ??????
    Paint p_talk2 = new Paint();
    p_talk2.setTextSize(16);
    Typeface font4 = Typeface.create(familyName, Typeface.BOLD);
    p_talk2.setColor(Color.BLACK);
    p_talk2.setTypeface(font4);

    canvas.drawBitmap(roloinfo.getTalkbdImg(), rect_talkpaopao,
        rect_talkpaopao1, paint);

    int j = 0;
    for (int i = talkline - 1; i >= 0; i--) {

      canvas.drawText(strlist.get(j), x - (oneimgwidth / 3) + 2,
          y - (int) (roloinfo.getTalkbdImg().getHeight() * (6 + i))
              + 2, p_talk2);
      canvas.drawText(strlist.get(j), x - (oneimgwidth / 3), y
          - (int) (roloinfo.getTalkbdImg().getHeight() * (6 + i)),
          p_talk);
      j++;
    }

    // paint.setColor(R.color.transparent);
//    dst = null;
//    p2.reset();
  }

  /**
   * ???????? horizontalcutnum ??????? verticalcutnum ???????
   */
  public List<Rect> getRectList(Bitmap bmp, int horizontalcutnum,
      int verticalcutnum) {
    // ????????????
    int oneimgwidth = bmp.getWidth() / horizontalcutnum;
    int oneimgHeight = bmp.getHeight() / verticalcutnum;

    for (int i = 0; i < verticalcutnum; i++) {
      for (int j = 0; j < horizontalcutnum; j++) {
        Rect bmpRect = new Rect();
        int left = oneimgwidth * j;
        int top = oneimgHeight * i;
        int right = oneimgwidth * (j + 1);
        int bottom = oneimgHeight * (i + 1);
        bmpRect.set(left, top, right, bottom);
        rectlist.add(bmpRect);
      }
    }
    return rectlist;
  }

  public void SetFangXiang(Direction fangxiang, boolean pao) {
    if (fangxiang == Direction.?) {
      if (pao != true) {

        lastflag = playflag[flag] + (63);
        flag++;
        if (flag >= 3) {
          flag = 0;
        }
      } else {

        lastflag = playflag[flagpao] + (63);
        flagpao++;
        if (flagpao >= 8) {
          flagpao = 3;
        }
      }
    } else if (fangxiang == Direction.???) {
      if (pao != true) {
        lastflag = playflag[flag] + (45);
        flag++;
        if (flag >= 3) {
          flag = 0;
        }
      } else {
        lastflag = playflag[flagpao] + (45);
        flagpao++;
        if (flagpao >= 8) {
          flagpao = 3;
        }
      }
    } else if (fangxiang == Direction.?) {
      if (pao != true) {
        lastflag = playflag[flag] + (54);
        flag++;
        if (flag >= 3) {
          flag = 0;
        }
      } else {
        lastflag = playflag[flagpao] + (54);
        flagpao++;
        if (flagpao >= 8) {
          flagpao = 3;
        }
      }
    } else if (fangxiang == Direction.?) {
      if (pao != true) {
        lastflag = playflag[flag] + (36);
        flag++;
        if (flag >= 3) {
          flag = 0;
        }
      } else {
        lastflag = playflag[flagpao] + (36);
        flagpao++;
        if (flagpao >= 8) {
          flagpao = 3;
        }
      }
    } else if (fangxiang == Direction.????) {
      if (pao != true) {
        lastflag = playflag[flag] + (27);
        flag++;
        if (flag >= 3) {
          flag = 0;
        }
      } else {
        lastflag = playflag[flagpao] + (27);
        flagpao++;
        if (flagpao >= 8) {
          flagpao = 3;
        }
      }
    } else if (fangxiang == Direction.????) {
      if (pao != true) {
        lastflag = playflag[flag] + (0);
        flag++;
        if (flag >= 3) {
          flag = 0;
        }
      } else {
        lastflag = playflag[flagpao] + (0);
        flagpao++;
        if (flagpao >= 8) {
          flagpao = 3;
        }
      }
    } else if (fangxiang == Direction.??) {
      if (pao != true) {
        lastflag = playflag[flag] + (9);
        flag++;
        if (flag >= 3) {
          flag = 0;
        }
      } else {
        lastflag = playflag[flagpao] + (9);
        flagpao++;
        if (flagpao >= 8) {
          flagpao = 3;
        }
      }
    } else if (fangxiang == Direction.??) {
      if (pao != true) {
        lastflag = playflag[flag] + (17);
        flag++;
        if (flag >= 3) {
          flag = 0;
        }
      } else {
        lastflag = playflag[flagpao] + (17);
        flagpao++;
        if (flagpao >= 8) {
          flagpao = 3;
        }
      }
    }
  }
}




Java Source Code List

com.example.gametest1.GameActivity.java
com.example.gametest1.GameMainActivity.java
com.example.gametest1.GameView.java
com.example.gametest1.MoveTest.java
com.game.base.BaseInfo.java
com.game.base.GameBackGround.java
com.game.base.GameMap.java
com.game.base.PubSet.java
com.game.commen.ActionToDo.java
com.game.commen.BitmapUtil.java
com.game.commen.Direction.java
com.game.commen.EffectName.java
com.game.commen.GetImgCommen.java
com.game.commen.MapName.java
com.game.commen.ToDo.java
com.game.data.BaseInfo.java
com.game.data.RoleData_Main.java
com.game.data.RoleData.java
com.game.effect.SpecialEffect1.java
com.game.effect.SpecialEffect.java
com.game.renwu.Objs.java
com.game.renwu.SpiritMain.java
com.game.renwu.Spirit_Main.java
com.game.renwu.Spirit_NPC.java
com.game.renwu.Spirit.java
com.game.renwu.Spiritgirl.java