程序小白----AndroidStudio之飞机大战

程序小白—-AndroidStudio之飞机大战

今天我们开始一些Android的学习

一:菜单类

新建一个菜单类用于定义一些变量和方法:

package com.example.xiao.fly;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.view.SurfaceHolder;
//以上为必要的包
/**
 * Created by Xiao on 2017/5/24.
 */

public class GameMeun {

    private Bitmap bmpMeunBG;  //菜单背景图片
    private  Bitmap bmpLogo;    //LOGO
    private  Bitmap bmpButton;  //按钮
    private Bitmap bmpText;     //文本
    private Rect rect;   //创建一个矩形 用以方置LOGO

public GameMeun(Bitmap bmpMeunBG,Bitmap bmpLogo,Bitmap bmpButton,Bitmap bmpText){

        this.bmpMeunBG=bmpMeunBG;
        this.bmpLogo=bmpLogo;
        this.bmpButton=bmpButton;
        this.bmpText=bmpText;
        rect = new Rect(0,GameSurface.hight/3,GameSurface.width,GameSurface.hight/3+GameSurface.hight/5);}
        //这是关于矩形的大小位置设计
/*以下是关于该方法的API文档解释
*   * @param left   The X coordinate of the left side of the rectangle
     * @param top    The Y coordinate of the top of the rectangle
     * @param right  The X coordinate of the right side of the rectangle
     * @param bottom The Y coordinate of the bottom of the rectangle
     */
    public Rect(int left, int top, int right, int bottom) {
        this.left = left;
        this.top = top;
        this.right = right;
        this.bottom = bottom;
    }
*/


    /**
     * 画背景图片
     * @param canvas
     * @param paint
     */
    public  void  draw(Canvas canvas , Paint paint){
        //画背景图片
        canvas.drawBitmap(bmpMeunBG,0,0,paint);
        //画logo
        canvas.drawBitmap(bmpLogo,null,rect,paint);
        //画按钮
        int x = GameSurface.hight/3*2;
        int y = GameSurface.width/2-bmpButton.getWidth()/2;
        canvas.drawBitmap(bmpButton,y,x,paint);  //前宽厚高
        //画文本
        int z = GameSurface.width/2-bmpText.getWidth()/2;
        canvas.drawBitmap(bmpText,z,x,paint);
    };
}

二:面板类:

package com.example.xiao.fly;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

/**
 * Created by Xiao on 2017/5/24.
 */

public class GameSurface extends SurfaceView implements SurfaceHolder.Callback{
//定义一些必要的变量
    private Canvas canvas;//画布
    private Paint paint;//画笔
    private SurfaceHolder surfaceHolder;

    public  static  int width;
    public  static  int hight;
    //Meun相关的

   //来自主菜单的一些变量
    private  GameMeun gameMenu;
    private Bitmap bmpMeunBG;
    private  Bitmap bmpLogo;
    private  Bitmap bmpButton;
    private Bitmap bmpText;

    public GameSurface(Context context) {
        super(context);
        surfaceHolder = this.getHolder();                                                                //初始化surfaceHolder
surfaceHolder.addCallback(this);//添加回调函数
paint = new Paint();   //初始化画笔
paint.setAntiAlias(true); //取消锯齿

  }
@Override

public void surfaceCreated(SurfaceHolder holder) {
width=this.getWidth();  //获取面板的宽度
hight=this.getHeight();  //获取面板的高度

intiBitmap();//初始化的方法

new Thread(new Runnable() {  
         @Override
         public void run() { 
             Mydraw();       ///进入线程通过Mydraw开始写入到视图中
         }
     }).start();
    }



    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {

    }

    @Override
    public void surfaceDestroyed(SurfaceHolder holder) {

    }

    /**
     * 绘图方法
     */
    private void Mydraw() {
      canvas = surfaceHolder.lockCanvas();  //创建视图到画板上
        gameMenu.draw(canvas,paint); //把所有的元素都布局到画板上
        if (canvas!=null){
    surfaceHolder.unlockCanvasAndPost(canvas);
        }
    }

    /**
     * 初始化图片
     */

    private void intiBitmap() {
        //把图片转化为Bitmap格式
        bmpMeunBG = BitmapFactory.decodeResource(
                this.getResources(),R.drawable.mainmenu
        );
        bmpLogo = BitmapFactory.decodeResource(
                this.getResources(),R.drawable.logo
        );
       bmpButton = BitmapFactory.decodeResource(
                this.getResources(),R.drawable.menustart
        );
       bmpText = BitmapFactory.decodeResource(
                this.getResources(),R.drawable.starttext
        );
        //初始化对象
 gameMenu = new GameMeun(bmpMeunBG,bmpLogo,bmpButton,bmpText);

    }
}
### 回答1: Android Studio 飞机大战是一款基于 Android Studio 开发的飞行射击游戏。玩家需要控制飞机躲避敌机的攻击并射击敌机,最终击败 Boss。这款游戏具有简单易懂的操作和精美的画面,适合各个年龄段的玩家。 ### 回答2: Android Studio飞机大战是一款基于Android平台开发的游戏应用程序。这款游戏使用了Android Studio开发工具,并利用Java语言编写。玩家扮演一名飞行员,在游戏中操控一架战斗机,与敌机展开战斗。 在游戏中,玩家可以使用屏幕上的触摸操作来控制战斗机的移动,同时按下屏幕进行射击。其操作简单直观,适合各个年龄段的玩家。游戏场景设置在空中,玩家需要躲避敌机的攻击,并尽可能多地消灭敌机。玩家可以通过击落敌机来积分,同时还可以获得道具和奖励,提升自己的战斗力。 这款游戏不仅具有良好的游戏性,还有精美的图形和音效。通过Android Studio平台的强大功能,游戏开发者可以设计出精美的游戏场景、真实的音效以及流畅的游戏操作,为玩家带来更好的游戏体验。 在开发过程中,开发者需要使用Android Studio提供的各种工具和资源进行开发。如Android Studio提供了所见即所得的可视化界面设计,开发者可以方便地布局游戏界面,设置按钮、背景等元素。同时,Android Studio还提供了强大的调试功能,开发者可以随时检查游戏代码的执行情况,及时修复bug。 总之,Android Studio飞机大战是一款基于Android平台的游戏应用程序,通过精美的图形和音效,简单直观的操作方式,给玩家带来了极具乐趣的游戏体验。如对游戏开发有兴趣的人员,可以使用Android Studio进行开发,体验游戏开发的魅力。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值