📄 penguinscreen.java
字号:
if (Drop.mapArrow == 0) delay(1000);
//每4针换下一个图片
if ( (Drop.CurY % 4 == 0) &&
(Drop.mapArrow < mapDrop.length - 2))
Drop.mapArrow++;
Drop.CurY = -Drop.CurX + 50;
}
}
else {//下落阶段
if (updateTime >= 150 - Drop.CurX / 2) {
if ( Drop.CurX < 70){
Drop.CurX++;
}
else{
Drop.CurX+=2;
}
bDrawDrop = true;
Drop.CurY = Drop.CurX * Drop.CurX * 2 / 125 -
40;
updateTime = 0;
//落地,再换下一个图片
if (Drop.CurY >= 100) {
Drop.mapArrow++;
}
}
}
}
else {//落地以后
//没有挥棒
UpdateGameState(End);
}
break;
//下面两个状态都是企鹅飞行的,没有break,区别是
//Init_fly是背景不动,企鹅向前飞
//Fly是企鹅只上下动背景向后移动
case Init_fly:
//这里只处理企鹅向前飞的计算
if (updateTime >= Flying.RefreshTime) {
Flying.CurX -= speedX / 10;
if (Flying.CurX <= 60) UpdateGameState(Fly);
}
case Fly:
//这里处理上下运动的计算
if (updateTime >= Flying.RefreshTime) {
//System.gc();
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 > 0 && Explode.mapArrow < mapExplode.length-1){
Explode.mapArrow++;
Explode.bDraw = true;
}
else{
Explode.bDraw = false;
Explode.CurX = 0;
Explode.CurY = 0;
Explode.mapArrow = 0;
}
//Add end;
if (Flying.CurY >= 100) {
//根据下落速度不同,Flying.CurY的值也不同,如果不强行赋值,企鹅的落点不在一条水平线上;
Flying.CurY = 100;
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 {
//画爆炸效果的位置得到
Explode.CurX = Flying.CurX;
Explode.CurY = Flying.CurY;
Explode.mapArrow++;
Explode.bDraw = true;
//速度衰减
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, 27, 34, -20,
Flying.CurY - 25);
curFrame = 0;
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);
}
}
updateTime = 0;
bDrawFly = true;
}
updateTime += aTimeTick;
break;
case Show_Succ:
//显示得到的分数,更新当前 AnimateScore的坐标
strikeTime += aTimeTick;
if (updateTime >= AnimateScore.RefreshTime) {
updateTime = 0;
if (curFrame < 2) {
AnimateScore.CurX = AnimateScore.CurX + 10;
}
if (curFrame == 3) {
if (state == RUN) {
UpdateGameState(Init_End);
}
else {
bDrawScore = false;
UpdateGameState(End);
}
}//向前移动
if (AnimateScore.CurX >= Flying.CurX - 20) {
if (curFrame < 3) {
if (curFrame < 2) {
curFrame = 1;
}
curFrame++;
}
}
if (curFrame < 2) {
if (curFrame == 0) {
curFrame = 1;
}
else {
curFrame = 0;
}
}
bDrawScore = true;
}
break;
//回收变量
case Init_End:
break;
case End:
curFrame = 0;
Score = 0;
ActualScore = 0;
Explode = null;
break;
}
updateTime += aTimeTick;
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;
case NET:
//查看网络排名,1-5名最多
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 >= 90000 || bNetStop) {
try {
http.join();
}
catch (Exception e) {
}
bNetStart = false;
paintLoadPos = 0;
bNetStop = false;
UpdateState(NETERROR);
netTimeOut = 0;
break;
}
delay(50);
//判断网络线程是否成功得到服务器数据
if (http.getStatus() == http.DONE) {
httpData = http.getResult();
try {
http.join();
}
catch (Exception e) {
System.out.println("Join Error");
}
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 >= 90000 || bNetStop) {
try {
//这儿应该强制执行线程退出函数。
http.join();
}
catch (Exception e) {
System.out.println("Join Error");
}
bNetStart = false;
paintLoadPos = 0;
bNetStop = false;
UpdateState(NETERROR);
netTimeOut = 0;
break;
}
delay(50);
if (http.getStatus() == http.DONE) {
httpData = http.getResult();
try {
http.join();
}
catch (Exception e) {
System.out.println("Join Error");
}
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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -