android平台俄罗斯方块游戏完整代码
2012-12-02 14:31:58 来源:WEB开发网核心提示:} 我们当然还要编写音乐播放类,资源播放类了等等,android平台俄罗斯方块游戏完整代码(2),,,,我把所有的图片资源编写在一个类里面,,
}
我们当然还要编写音乐播放类,资源播放类了等等。。。。。。
我把所有的图片资源编写在一个类里面,叫做GameResources.java,具体代码如下:
package com.example.eluosifangkuai;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Bitmap.Config;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Bitmap.Config;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
public class GameResources {
Resources m_Resources; // 资源类
Canvas m_Canvas; // 画布
Bitmap m_Bitmaphc = null; // 缓冲位图
Bitmap m_Bitmap01 = null; // 图像位图
Bitmap [] m_Bitmaps = new Bitmap[8]; //精灵位图
Bitmap score; // 分数位图
Bitmap Play; // 开始位图
Bitmap Level;
public GameResources(Context context) // 初始化 装载位图
{
m_Resources = context.getResources();
for(int i=0;i<7;i++)
{
m_Bitmaps[i] = createImage(m_Resources.getDrawable(R.drawable.cube_960_011+i),18,18);
}
m_Bitmap01 = createImage(m_Resources.getDrawable(R.drawable.bgcatcher),320,480);
m_Bitmaps[7] = createImage(m_Resources.getDrawable(R.drawable.main11),320,402);
score = createImage(m_Resources.getDrawable(R.drawable.score),87,150);
Play = createImage(m_Resources.getDrawable(R.drawable.b7),320,480);
Level = createImage(m_Resources.getDrawable(R.drawable.levelup),139,88);
m_Bitmaphc = Bitmap.createBitmap(320,480, Config.ARGB_8888);
m_Canvas = new Canvas(m_Bitmaphc);
bitmapB();
}
public void bitmapB()
{
Paint m_Paint = new Paint();
m_Paint.setAntiAlias(true);
m_Paint.setAlpha(220);
m_Canvas.drawBitmap(m_Bitmap01, 0,0,null);
}
public static Bitmap createImage(Drawable tile, int w, int h) { // 双缓冲 加载位图资源
Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
tile.setBounds(0, 0, w, h);
tile.draw(canvas);
return bitmap;
}
}
Resources m_Resources; // 资源类
Canvas m_Canvas; // 画布
Bitmap m_Bitmaphc = null; // 缓冲位图
Bitmap m_Bitmap01 = null; // 图像位图
Bitmap [] m_Bitmaps = new Bitmap[8]; //精灵位图
Bitmap score; // 分数位图
Bitmap Play; // 开始位图
Bitmap Level;
public GameResources(Context context) // 初始化 装载位图
{
m_Resources = context.getResources();
for(int i=0;i<7;i++)
{
m_Bitmaps[i] = createImage(m_Resources.getDrawable(R.drawable.cube_960_011+i),18,18);
}
m_Bitmap01 = createImage(m_Resources.getDrawable(R.drawable.bgcatcher),320,480);
m_Bitmaps[7] = createImage(m_Resources.getDrawable(R.drawable.main11),320,402);
score = createImage(m_Resources.getDrawable(R.drawable.score),87,150);
Play = createImage(m_Resources.getDrawable(R.drawable.b7),320,480);
Level = createImage(m_Resources.getDrawable(R.drawable.levelup),139,88);
m_Bitmaphc = Bitmap.createBitmap(320,480, Config.ARGB_8888);
m_Canvas = new Canvas(m_Bitmaphc);
bitmapB();
}
public void bitmapB()
{
Paint m_Paint = new Paint();
m_Paint.setAntiAlias(true);
m_Paint.setAlpha(220);
m_Canvas.drawBitmap(m_Bitmap01, 0,0,null);
}
public static Bitmap createImage(Drawable tile, int w, int h) { // 双缓冲 加载位图资源
Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
tile.setBounds(0, 0, w, h);
tile.draw(canvas);
return bitmap;
}
}
更多精彩
赞助商链接