当前位置:主页 > 计算机电子书 > 编程资源 > android游戏源码资源下载

android顽皮小球游戏源码

2021-05-07 10:00:59 类别:android游戏源码

  • 更新:2021-05-07 10:00:59
  • 大小:3.02 MB
  • 热度:768
  • 审核:惠凯捷
  • 类别:技术文章
  • 格式:PDF

扫二维码手机浏览

资源介绍

给大家整理一篇android游戏源码类学习资源,由武奇略测试纠错,内容涉及到android、顽皮小球、android源码、android游戏源码的内容,已被753人关注,同类资源中评分为7.3分。

【实例截图】 package com.bg;import org.jbox2d.collision.AABB;import org.jbox2d.collision.CircleDef;import org.jbox2d.collision.PolygonDef;import org.jbox2d.common.Vec2;import org.jbox2d.dynamics.Body;import org.jbox2d.dynamics.BodyDef;import org.jbox2d.dynamics.ContactListener;import org.jbox2d.dynamics.World;import org.jbox2d.dynamics.contacts.ContactPoint;import org.jbox2d.dynamics.contacts.ContactResult;import android.content.Context;import android.graphics.Bitmap;import android.graphics.BitmapFactory;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Paint;import android.graphics.Paint.Style;import android.util.Log;import android.view.KeyEvent;import android.view.MotionEvent;import android.view.SurfaceHolder;import android.view.SurfaceView;import android.view.SurfaceHolder.Callback;public class MySurfaceView extends SurfaceView implements Callback, Runnable, ContactListener {private Thread th;private SurfaceHolder sfh;private Canvas canvas;private Paint paint;private boolean flag;// ----添加一个物理世界----private final float RATE = 30;// 屏幕到现实世界的比例 30px:1m;private World world;// 声明一个物理世界对象private AABB aabb;// 声明一个物理世界的范围对象private Vec2 gravity;// 声明一个重力向量对象private float timeStep = 1f / 60f;// 物理世界模拟的的频率private int iterations = 10;// 迭代值,迭代越大模拟越精确,但性能越低// 声明小球的Body,便于后续对小球进行操作private Body bodyBall;//声明胜利与失败的body,用于判定游戏的胜负private Body lostBody1, lostBody2, winBody;// 声明屏幕宽高private int screenW, screenH;// 声明游戏状态private final int GAMESTATE_MENU = 0;private final int GAMESTATE_HELP = 1;private final int GAMESTATE_GAMEING = 2;private int gameState = GAMESTATE_MENU;// 为了游戏暂停时,失败,胜利能继续可能到游戏中的状态,所以并没有将其写成一个状态private boolean gameIsPause, gameIsLost, gameIsWin;// Body图片资源private Bitmap bmpH, bmpS, bmpSh, bmpSs, bmpBall;// 菜单、按钮、游戏背景图片资源private Bitmap bmpMenu_help, bmpMenu_play, bmpMenu_exit, bmpMenu_resume, bmpMenu_replay, bmp_menubg, bmp_gamebg, bmpMenuBack, bmp_smallbg, bmpMenu_menu,bmp_helpbg, bmpBody_lost, bmpBody_win, bmpWinbg, bmpLostbg;// 创建按钮private HButton hbHelp, hbPlay, hbExit, hbResume, hbReplay, hbBack, hbMenu;public MySurfaceView(Context context) {super(context);this.setKeepScreenOn(true);sfh = this.getHolder();sfh.addCallback(this);paint = new Paint();paint.setAntiAlias(true);paint.setStyle(Style.STROKE);this.setFocusable(true);this.setFocusableInTouchMode(true);// --添加一个物理世界---aabb = new AABB();gravity = new Vec2(0, 10);aabb.lowerBound.set(-100, -100);aabb.upperBound.set(100, 100);world = new World(aabb, gravity, true);// ---实例化Body图片资源bmpH = BitmapFactory.decodeResource(getResources(), R.drawable.h);bmpS = BitmapFactory.decodeResource(getResources(), R.drawable.s);bmpSh = BitmapFactory.decodeResource(getResources(), R.drawable.sh);bmpSs = BitmapFactory.decodeResource(getResources(), R.drawable.ss);bmpBall = BitmapFactory.decodeResource(getResources(), R.drawable.ball);// 实例菜单、按钮、游戏背景图片资源bmpMenu_help = BitmapFactory.decodeResource(getResources(), R.drawable.menu_help);bmpMenu_play = BitmapFactory.decodeResource(getResources(), R.drawable.menu_play);bmpMenu_exit = BitmapFactory.decodeResource(getResources(), R.drawable.menu_exit);bmpMenu_resume = BitmapFactory.decodeResource(getResources(), R.drawable.menu_resume);bmpMenu_replay = BitmapFactory.decodeResource(getResources(), R.drawable.menu_replay);bmp_menubg = BitmapFactory.decodeResource(getResources(), R.drawable.menu_bg);bmp_gamebg = BitmapFactory.decodeResource(getResources(), R.drawable.game_bg);bmpMenuBack = BitmapFactory.decodeResource(getResources(), R.drawable.menu_back);bmp_smallbg = BitmapFactory.decodeResource(getResources(), R.drawable.smallbg);bmpMenu_menu = BitmapFactory.decodeResource(getResources(), R.drawable.menu_menu);bmp_helpbg = BitmapFactory.decodeResource(getResources(), R.drawable.helpbg);bmpBody_lost = BitmapFactory.decodeResource(getResources(), R.drawable.lostbody);bmpBody_win = BitmapFactory.decodeResource(getResources(), R.drawable.winbody);bmpWinbg = BitmapFactory.decodeResource(getResources(), R.drawable.gamewin);bmpLostbg = BitmapFactory.decodeResource(getResources(), R.drawable.gamelost);}//SurfaceView创建public void surfaceCreated(SurfaceHolder holder) {//防止Home按键导致游戏重置if (gameState == GAMESTATE_MENU) {screenW = this.getWidth();screenH = this.getHeight();// 实例化按钮hbPlay = new HButton(bmpMenu_play, screenW / 2 - bmpMenu_help.getWidth() / 2, 150);hbHelp = new HButton(bmpMenu_help, hbPlay.getX(), hbPlay.getY() 50);hbExit = new HButton(bmpMenu_exit, hbPlay.getX(), hbHelp.getY() 50);hbBack = new HButton(bmpMenuBack, 0, screen

以上就是本次关于本资源的介绍和部分内容,我们还整理了以往更新的其它相关资源内容,可以在下方直接下载,关于相关的资源我们在下方做了关联展示,需要的朋友们也可以参考下。

你可能感兴趣的文章:

1、深入解析Android 5.0系统 PDF电子书

2、Android程序设计 PDF电子书

3、AndroidStudio从入门到精通 编程资源

4、Android开发实战:从学习到产品 PDF电子书

5、Android应用案例开发大全 PDF电子书

6、Android程序设计经典教程 PDF电子书

7、java,android面试宝典 编程资源


下载地址

留言评论

欢迎发表评论:

联系我们

邮件联系:3522365@qq.com

QQ联系:3522365