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}};
}
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}};
}