Android Open Source - TheFirstMyth01 Objs






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;
//from  w  ww .jav a2  s  .c o m
import java.util.ArrayList;
import java.util.List;

import com.example.gametest1.GameView;
import com.game.base.GameMap;
import com.game.commen.MapName;
import com.game.commen.ToDo;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.view.MotionEvent;
import android.widget.Toast;

public class Objs {

  private Bitmap ObjsImg;
  List<Rect> rectlist;

  public Objs(Bitmap ObjsImg) {
    super();
    this.ObjsImg = ObjsImg;
    rectlist = new ArrayList<Rect>();
  }

  public int playflag = 0;

  int oneimgwidth=0;
  int oneimgHeight=0;
  Rect dst;
  
  public boolean show_shuohua =  false;
  ToDo todo = ToDo.?????;
  /**
   * ???????????????????X,Y?????????????? ???????????????????????????????????????XY???????XY
   * **/
  public void myDraw_obj(Canvas canvas, Paint paint, float x, float y,
      int horizontalcutnum, int verticalcutnum, int cutnum, float zoom,int spirit_x,
      int spirit_y,ToDo todo,MapName mapname,int SF_X,int SF_Y,int MF_X,int MF_Y) {

    this.todo=todo;
    rectlist = getRectList(ObjsImg, horizontalcutnum, verticalcutnum);// 8???????
    oneimgwidth = ObjsImg.getWidth() / horizontalcutnum;
    oneimgHeight = ObjsImg.getHeight() / verticalcutnum;
    dst = new Rect();// ???????????
    dst.left = (int) x - (oneimgwidth / 2);
    dst.top = (int) y - (oneimgHeight / 2);
    dst.right = (int) x + (int) ((oneimgwidth / 2) * zoom);
    dst.bottom = (int) y + (int) ((oneimgHeight / 2) * zoom);

    if (playflag >= cutnum) {
      playflag = 0;
    }

    canvas.drawBitmap(ObjsImg, rectlist.get(playflag), dst, paint);
    
    
    playflag++;
    
    
    if(show_shuohua==true)
    {
    
      String familyName = "??";
      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.drawText("??????!", x - (oneimgwidth / 3) + 2, y
          - (int) (oneimgHeight * 0.85) + 2, p_talk2);
      canvas.drawText("??????!", x - (oneimgwidth / 3), y
          - (int) (oneimgHeight * 0.85), p_talk);
    }
    
    //????,?????????????//
    //??????????????????????//
    if (spirit_x > dst.left && spirit_x < dst.right
        && spirit_y > (dst.top+(oneimgHeight *0.5)) && spirit_y < dst.bottom) {
      //??????
      if(todo==ToDo.??????)
      {
        GameMap.F_x=MF_X;
        GameMap.F_y=MF_Y;
        GameView.zhujiao_x = SF_X;
        GameView.zhujiao_y = SF_Y;
        GameView.zhujiao_x_new = SF_X;
        GameView.zhujiao_y_new = SF_Y;
        GameView.mapflag = mapname;
      }
    }
    
  }

  //??????
  public void onTouch(MotionEvent e) {
    int x = (int) e.getX();
    int y = (int) e.getY();

    if (e.getAction() == MotionEvent.ACTION_DOWN
        || e.getAction() == MotionEvent.ACTION_MOVE) {
      if (x > dst.left && x < dst.right
          && y > dst.top && y < dst.bottom) {
        //??????
        if(todo==ToDo.?????)
        {
          show_shuohua=true;
        }
      }
    }
  }

  /*
   * ????????
   * 
   * lastleft lasttop ????????? horizontalcutnum ??????? verticalcutnum ???????
   */
  public List<Rect> getRectList(Bitmap bmp, int horizontalcutnum,
      int verticalcutnum) {
    List<Rect> rectlist = new ArrayList<Rect>();
    // ????????????
    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;
  }

}




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