📄 penguinscreen.java
字号:
if (Drop.mapArrow == 0) delay(700); //这里停顿一下,有蓄力的效果
//每4针换下一个图片
if ( (Drop.CurY % 4 == 0) &&
(Drop.mapArrow < mapDrop.length - 2))
Drop.mapArrow++;
}
}
else {//下落阶段
if (Drop.countTime >Drop.RefreshTime+20) {
Drop.CurX++;
Drop.bDraw = true;
//轨迹公式
Drop.CurY = 159 * (Drop.CurX - 87) *
(Drop.CurX - 87) / (33 * 33) + 26;
Drop.countTime = 0;
//落地,再换下一个图片
if (Drop.CurY >= 178) {
Drop.mapArrow++;
}
}
}
}
else {//落地以后
if (Strike==null){//没有挥棒
UpdateGameState(End);
}else{//如果有挥棒动作,要等待挥棒动画结束
Drop.bDraw=true;
if(bDrawStrike){
UpdateGameState(End);
}
if(Strike.mapArrow == mapStrike.length - 1){
bDrawStrike=true;
}
}
}
break;
//下面两个状态都是企鹅飞行的,没有break,区别是
//Init_fly是背景不动,企鹅向前飞
//Fly是企鹅只上下动背景向后移动
case Init_fly:
//这里只处理企鹅向前飞的计算
if (Flying.countTime >= Flying.RefreshTime) {
Flying.CurX -= speedX / 10;
if (Flying.CurX <= 60) UpdateGameState(Fly);
}
case Fly:
//这里处理上下运动的计算
if (Flying.countTime >= Flying.RefreshTime) {
int y_tmp = speedY / 10;
if (y_tmp == 0) {
if (speedY > 0) y_tmp = 1;
if (speedY < 0) y_tmp = -1;
}
Flying.CurY -= y_tmp;
speedY -= 1;
//取得图片的数组下标
int tmp = getMapArrow();
if (tmp >= 0) {
Flying.mapArrow = tmp;
}
//Add by Zxhred for Explode
//爆炸是当企鹅落在垫子上需要画几个爆炸效果
if (Explode.mapArrow >= mapExplode.length - 1) {
Explode.bDraw = false;
Explode.CurX = 0;
Explode.CurY = 0;
Explode.mapArrow = 0;
}
if (Explode.mapArrow >= 0 &&
Explode.mapArrow < mapExplode.length - 1) {
Explode.mapArrow++;
}
if (Flying.CurY >= 180) {
//根据下落速度不同,Flying.CurY的值也不同,如果不强行赋值,企鹅的落点不在一条水平线上;
Flying.CurY = 180;
boolean Elastic = false;
//判断是否落在垫子上
for (int i = 0; i < ElasticPos.length; i++) {
if (Flying.CurX >= phyX - ElasticPos[i] - 5 &&
Flying.CurX <=
phyX - ElasticPos[i] + 19) {
RePlaymidi(phut);
Elastic = true;
break;
}
}
//速度衰减
if (!Elastic) {
speedY = speedY * 3 / 5;
speedX = speedX * 3 / 5;
}
else {
if(speedY<-3){
//画爆炸效果的位置得到
//Add by Zxhred for Explode
Explode.CurX = Flying.CurX;
Explode.CurY = Flying.CurY;
Explode.bDraw = true;
//Add end
}
speedY = speedY * 10 / 9;
speedX = speedX * 5 / 3;
}
//speedY小于一定数值就不再弹起
if ( (speedY < 0) && (speedY > -10)) {
speedY = 0;
}
//停止,根据显示的图片来判断
if (Flying.mapArrow >= 12) {
ActualScore = Score +
(ROADFLAG1 - Flying.CurX) / 3;
AnimateScore = new Animate(250, 39, 50, -39,
Flying.CurY - 35);
UpdateGameState(Show_Succ);
}
//倒地后转头
if (speedX <= 0 && Flying.mapArrow < 12) {
if (Flying.mapArrow == 0) {
Flying.mapArrow = 10;
}
else {
Flying.mapArrow++;
}
}
//为了能更换最后一个停止的图片,更新状态要在判断状态之前
if (!Elastic) {
if (Flying.mapArrow == 8) Flying.mapArrow =
13;
if (Flying.mapArrow == 9) Flying.mapArrow =
14;
if (Flying.mapArrow >= 12) {
speedX = 0;
speedY = 0;
}
}
//反弹
if (speedY < 0) {
speedY = -speedY;
RePlaymidi(pDrop);
}
}
Flying.countTime = 0;
Flying.bDraw = true;
}
Flying.countTime += aTimeTick;
Flying.bDraw = true;
break;
//显示得到的分数,更新当前 AnimateScore的坐标
case Show_Succ:
AnimateScore.countTime += aTimeTick;
if (AnimateScore.countTime >= AnimateScore.RefreshTime) {
AnimateScore.countTime = 0;
//向前移动
if (AnimateScore.mapArrow < 2) {
AnimateScore.CurX = AnimateScore.CurX + 10;
}
//举牌完毕
if (AnimateScore.mapArrow == 3) {
if (state == RUN) {
UpdateGameState(Init_End);
}
else {
AnimateScore.bDraw = false;
UpdateGameState(End);
}
}
//换举牌的图片
if (AnimateScore.CurX >= Flying.CurX - 39) {
if (AnimateScore.mapArrow < 3) {
AnimateScore.mapArrow++;
}
}
//向前走的动画更换图片
if (AnimateScore.mapArrow < 2) {
if (AnimateScore.mapArrow == 0) {
AnimateScore.mapArrow = 1;
}
else {
AnimateScore.mapArrow = 0;
}
}
AnimateScore.bDraw = true;
}
break;
//回收变量
case Init_End:
Flying=null;
Drop=null;
Strike=null;
AnimateScore=null;
Explode=null;
Score = 0;
bDrawStrike=false;
System.gc();
break;
case End:
Flying=null;
Drop=null;
Strike=null;
AnimateScore=null;
Explode=null;
Score = 0;
ActualScore = 0;
bDrawStrike=false;
System.gc();
break;
}
break;
case INPUT:
//时间递减
updateTime += aTimeTick;
if (updateTime > 1000) {
RemainSecond--;
updateTime = 0;
}
//用户输入时间到,更新状态
if (RemainSecond < 0) {
UpdateState(LOCAL);
newsreel[order] = ActualScore;
order = -1;
updateTime = 0;
RemainSecond = 20;
}
break;
//查看网络排名,1-5名最多
case NET:
updateTime += aTimeTick;
netTimeOut += aTimeTick;
if (updateTime > 200) {
//下载数据时主屏幕上的移动的进度条位置更新
paintLoadPos += 10;
if (paintLoadPos > 114) {
paintLoadPos = 0;
}
updateTime = 0;
}
if (!bNetStart) {
//启动网络线程
http = new NetData("http://211.136.86.43/pm/", 1, "test", 2,
5, 1, 0);
http.start();
bNetStart = true;
}
//网络超时则显示Error界面
if (netTimeOut >= 30000 || bNetStop) {
bNetStart = false;
paintLoadPos = 0;
bNetStop = false;
UpdateState(NETERROR);
netTimeOut = 0;
break;
}
delay(50);
//判断网络线程是否成功得到服务器数据
if (http.getStatus() == http.DONE) {
httpData = http.getResult();
int Ret = 0;
//parse data to global array netOrder netName netScore
if (httpData.length() > 0
&& httpData != "ERROR"
&& http.getResponseCode() == HttpConnection.HTTP_OK) {
//解析网络数据格式并显示
if ( (Ret = ParseNetData(httpData)) < 0) {
UpdateState(NETERROR);
}
else {
UpdateState(NETDISP);
}
}
else {
UpdateState(NETERROR);
}
bNetStart = false;
paintLoadPos = 0;
netTimeOut = 0;
}
break;
//上传本地高分
case SCOREUPLOAD:
updateTime += aTimeTick;
netTimeOut += aTimeTick;
if (updateTime > 200) {
paintLoadPos += 10;
if (paintLoadPos > 114) {
paintLoadPos = 0;
}
updateTime = 0;
}
//计算高分和输入姓名,并上传
if (!bNetStart) {
byte uploadData[] = new byte[namelen[order]];
for (int i = 0; i < namelen[order]; i++) {
uploadData[i] = name[order][i];
uploadData[i] += 'A';
}
String strTmp = new String(uploadData);
strTmp = strTmp.substring(0, namelen[order]);
http = new NetData("http://211.136.86.43/pm/", 1, strTmp, 2,
5, 0, ActualScore);
http.start();
bNetStart = true;
}
//网络超时
if (netTimeOut >= 30000 || bNetStop) {
bNetStart = false;
paintLoadPos = 0;
bNetStop = false;
UpdateState(NETERROR);
netTimeOut = 0;
break;
}
delay(50);
if (http.getStatus() == http.DONE) {
httpData = http.getResult();
int Ret = 0;
//parse data to global array netOrder netName netScore
if (httpData.length() > 0
&& httpData != "ERROR"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -