弹球小游戏java代码_android 发射弹球小游戏 附完整源码下载

这篇博客介绍了如何在Android平台上制作一个弹球小游戏,包括核心代码实现,涉及弹球运动方向判断、碰撞检测等功能。附带完整源码供下载。
摘要由CSDN通过智能技术生成

【实例简介】android 弹球游戏制作

【实例截图】

8d804ed140da6bee39dfe2128668d9f6.png

b32c2726ef9ea36d7c5de17be3bb4847.png 【核心代码】

package wyf.ytl; //声明包语句

public class BallGoThread extends Thread {

GameView father;

boolean flag = true;

public BallGoThread(GameView father) {

this.father = father;

}

public void run() {

while (flag) {

switch (father.direction) {

case 0:

// 右上

// 当在向右上角移动的时候x坐标加,y坐标减

father.ballx = father.ballx father.ballSpan;

father.bally = father.bally - father.ballSpan;

//当碰到右边的墙壁的时候,向左下飘

if (father.ballx >= father.screenWidth - father.ballSize) {

father.direction = 3;

} else if (father.bally <= 0) {

// 碰到上壁,产生反射向右下飘

father.direction = 1;

}

break;

case 3:

// 向左上角飘,x坐标逐渐减,y坐标逐渐减

father.ballx = father.ballx - father.ballSpan;

father.bally = father.bally - father.ballSpan;

if (father.ballx <= 0) {// 碰到左壁

father.direction = 0;

} else if (father.bally <= 0) {// 碰到上壁

father.direction = 2;

}

break;

case 1:

// 向右下角飘

father.ballx = father.ballx father.ballSpan;

father.bally = father.bally father.ballSpan;

if (father.bally >= father.screenHeight - father.bannerHeight

- father.bottomSpance - father.ballSize) {// 碰到下壁

checkCollision(1);

} else if (father.ballx >= father.screenWidth - father.ballSize) {// 碰到右壁

father.direction = 2;

}

break;

case 2:

// 向左下角飘

father.ballx = father.ballx - father.ballSpan;

father.bally = father.bally father.ballSpan;

if (father.bally >= father.screenHeight - father.bannerHeight

- father.bottomSpance - father.ballSize) {// 碰到下壁

checkCollision(2);

} else if (father.ballx <= 0) {// 碰到左壁

father.direction = 1;

}

break;

}

try {

Thread.sleep(80);

} catch (Exception e) {

e.printStackTrace();

}

}

}

public void checkCollision(int direction) {

if (father.ballx >= father.bannerX - father.ballSize

&& father.ballx <= father.bannerX father.bannerWidth) {// 碰到板

switch (direction) {

case 1:

father.direction = 0;

break;

case 2:

father.direction = 3;

break;

}

} else {// 没有碰到板

// 游戏失败

father.tt.flag = false;

father.bgt.flag = false;

father.status = 2;

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值