Bitmap

package com.qdsoftware.snake.map;




import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;


public class Map {
private int x;
private int y;

private int width;
private int height;

public int getX() {
return x;
}


public void setX(int x) {
this.x = x;
}


public int getY() {
return y;
}


public void setY(int y) {
this.y = y;
}
private Bitmap bg;
private Bitmap ww;
public Map(Bitmap bg,Bitmap ww,int width,int height){
this.bg = bg;
this.width = width;
this.height = height;
this.x = 0;
this.y = 0;
this.ww = ww;
}

private Paint p = new Paint();
public void onDraw(Canvas canvas){
for(int i = 0;i < 16;i++){
for(int j = 0;j < 16;j++){
int data = nMapData0[i][j];
int mapData = data&0xff;
if(mapData == 0){
continue;
}
//获取单元格的数组,并判断是那个图片
short[] bitmapData = nDrawPos[mapData - 1];
//新建Rect矩形,用来显示单元格
Rect src = new Rect();//src 这个是表示绘画图片在原图上的大小位置
Rect dst = new Rect();//dst 是表示 绘画这个图片在需要绘制的屏幕上的位置
if(bitmapData[0] == 0){
src.left = bitmapData[1];//bitmapData[] = {0,224,248,24,24};
src.top = bitmapData[2];
src.right = src.left + bitmapData[3];
src.bottom = src.top + bitmapData[4];
//确定绘制在屏幕上的位置
dst.left = bitmapData[3] * j;
dst.top = bitmapData[4] * i;
dst.right = dst.left + bitmapData[3];
dst.bottom = dst.top + bitmapData[4];
//绘制
canvas.drawBitmap(bg, src, dst, p);
}else if(bitmapData[0] == 1){
src.left = bitmapData[1];//bitmapData[] = {1,223,161,24,24};
src.top = bitmapData[2];
src.right = src.left + bitmapData[3];
src.bottom = src.top + bitmapData[4];
//确定绘制在屏幕上的位置
dst.left = 24 * j;
dst.top = 24 * i;
dst.right = dst.left + bitmapData[3];
dst.bottom = dst.top + bitmapData[4];
//绘制
canvas.drawBitmap(ww, src, dst, p);
}
}
}

}

public void onLogic(){
if(y==height){
y=0;
return;
}
y+=10;
}

//子图片索引表:{图片,左,上,宽,高,[旋转及镜象]}
short nDrawPos[][]={
{0,97,104,24,24},   //索引:[0]
{1,214,164,24,24},  //索引:[1]
{0,0,0,24,24},      //索引:[2]
{0,498,108,24,24}   //索引:[3]
};
//地图数据16x16
int nMapData0[][]={
{0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001},
{0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001},
{0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0002,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001},
{0x0001,0x0001,0x0001,0x0101,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001},
{0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0002,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001},
{0x0001,0x0001,0x0002,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001},
{0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0101,0x0001,0x0001,0x0001,0x0001,0x0002,0x0001,0x0001,0x0001},
{0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001},
{0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001},
{0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0101,0x0001,0x0001,0x0001,0x0001,0x0001},
{0x0001,0x0001,0x0001,0x0002,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0002,0x0001,0x0001,0x0001},
{0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0101,0x0001,0x0001,0x0001},
{0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0002,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001},
{0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0002,0x0001,0x0001,0x0101,0x0001},
{0x0001,0x0001,0x0002,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001},
{0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001}};







}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值