/*
软件作者:https://xuhss.com/oxox/pro
*/
"ui";
importClass(android.content.pm.ActivityInfo);
importClass(android.view.WindowManager);
ui.layout(
<frame>
<canvas id="board" layout_weight="1"/>
<button id="but" alpha="0.5" w="100" h="100" text="前进" layout_gravity="left|center_vertical"/>
</frame>
);
ui.run(() => {
//横屏
activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); //设置成全屏模式
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); //强制为横屏
/*
//竖屏
activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);//设置成全屏模式
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);//竖屏
*/
});
var W = 128;
var paint = new Paint();
//paint.setColor(colors.WHITE);
//paint.setColor(colors.BLACK);
paint.setARGB(255, 64, 64, 64);
paint.setStrokeWidth(10);
paint.setTextSize(75);
//paint.setStyle(Paint.Style.STROKE);
//paint.setStrokeCap(Paint.Cap.ROUND);
//paint.setShader(new android.graphics.RadialGradient(0,200,50,200,colors.RED,colors.GREEN,android.graphics.Shader.TileMode.REPEAT));
var paint1 = new Paint();
//paint1.setColor(colors.BLACK);
paint1.setARGB(255, 127, 127, 127);
paint1.setStrokeWidth(5)
paint1.setStrokeCap(Paint.Cap.ROUND);
//paint1.setShader(new android.graphics.RadialGradient(0,200,50,200,colors.RED,colors.GREEN,android.graphics.Shader.TileMode.REPEAT));
paint1.setXfermode(new android.graphics.PorterDuffXfermode(android.graphics.PorterDuff.Mode.XOR));
var mbitmap = android.graphics.Bitmap.createBitmap(W, W, android.graphics.Bitmap.Config.ARGB_8888);
var mcanvas = new Canvas(mbitmap);
var rainbowColor = [-65536, -23296, -256, -16711936, -16744449, -16776961, -7667457];
var xyz = [{ //x
x: 0,
y: 0,
x1: 10,
y1: 0,
}, { //y
x: 0,
y: 0,
x1: 0,
y1: 10,
}, { //x
x: 0,
y: 0,
x1: -10,
y1: 0,
}, { //y
x: 0,
y: 0,
x1: 0,
y1: -10,
}];
var player = {
x: 0,
y: 0,
Y: 225, //平面360度。
YW: 120,
};
var Suum = 0;
var ASX = new XYToMatrix(null, 4);
//ui.board.setMaxFps(60);
ui.board.on("draw", function(canvas) {
let w = canvas.getWidth();
let h = canvas.getHeight();
//canvas.translate(w / 2, h / 2);
let matrix = canvas.getMatrix();
//绘制背景色
//canvas.drawColor(colors.argb(25, 0, 0, 0));
canvas.drawARGB(255, 127, 127, 127);
matrix.postConcat(ASX.matrix);
canvas.setMatrix(matrix);
//paint.setColor(rainbowColor[random(0,rainbowColor.length-1)]);
//canvas.drawBitmap(mbitmap, 0, 0, paint);
var Yw1 = player.YW / 2;
var minY = player.Y - Yw1;
var maxY = player.Y + Yw1;
//log(maxY, minY);
paint.setARGB(255, 0, 255, 0);
paint.setStrokeWidth(3);
//canvas.drawLine(0, h / 2, w, h / 2, paint);
canvas.drawPoint(player.x * 10 + (w - 200), player.y * 10 + 200, paint);
var xy = getsd(10 * 10, kdfx(player.Y));
canvas.drawLine(player.x * 10 + (w - 200), player.y * 10 + 200, player.x * 10 + (w - 200) + xy[0], player.y * 10 + 200 + xy[1], paint);
var xy = getsd(20 * 10, kdfx(player.Y + Yw1));
canvas.drawLine(player.x * 10 + (w - 200), player.y * 10 + 200, player.x * 10 + (w - 200) + xy[0], player.y * 10 + 200 + xy[1], paint);
var xy = getsd(20 * 10, kdfx(player.Y - Yw1));
canvas.drawLine(player.x * 10 + (w - 200), player.y * 10 + 200, player.x * 10 + (w - 200) + xy[0], player.y * 10 + 200 + xy[1], paint);
paint.setARGB(255, 0, 0, 0);
paint.setStrokeWidth(10);
for (var i = 0; i < xyz.length; i++) {
var obj = xyz[i];
var S = weiyi([obj.x1 - player.x, obj.y1 - player.y]);
if (S < 2) {
Suum++;
do {
obj.x1 = random(-15, 15);
obj.y1 = random(-15, 15);
} while (weiyi([obj.x1 - player.x, obj.y1 - player.y]) < 2);
obj.c = rainbowColor[random(0, rainbowColor.length)];
//continue;
};
if (obj.c) {
paint.setColor(obj.c);
};
canvas.drawPoint(obj.x1 * 10 + (w - 200), obj.y1 * 10 + 200, paint);
var Y = ydfx([obj.x1 - player.x, obj.y1 - player.y]);
// log(Y);
while (Y >= -Yw1) {
Y -= 360;
};
while (Y < 360 + Yw1) {
Y += 360;
//if (minY <= Y && Y <= maxY) {
// log("OK");
var bl = (maxY - Y) / (maxY - minY);
var bx = w - w * bl;
// log(bx);
canvas.drawCircle(bx, h / 2, 1000 / S, paint);
// };
};
};
if (isRun) {
Sds += 0.05;
var xy = getsd(Sds, kdfx(player.Y));
player.x += xy[0];
player.y += xy[1];
xyz = xyz.sort(function(A, B) {
var S = weiyi([A.x1 - player.x, A.y1 - player.y]);
var S1 = weiyi([B.x1 - player.x, B.y1 - player.y]);
return S1 - S;
});
} else if (Sds > 0) {
Sds -= 0.2;
if (Sds < 0) {
Sds = 0;
};
var xy = getsd(Sds, kdfx(player.Y));
player.x += xy[0];
player.y += xy[1];
xyz = xyz.sort(function(A, B) {
var S = weiyi([A.x1 - player.x, A.y1 - player.y]);
var S1 = weiyi([B.x1 - player.x, B.y1 - player.y]);
return S1 - S;
});
};
paint.setARGB(255, 0, 0, 0);
canvas.drawText("当前分数" + Suum, w / 2, h / 10, paint);
});
//ui.board.setOnTouchListener(ASX.touchListener);
var py = player.Y;
var mLastX, mLastY;
ui.board.setOnTouchListener(new android.view.View.OnTouchListener({
onTouch: function(view, event) {
var x = event.getX();
var y = event.getY();
switch (event.getAction()) {
case android.view.MotionEvent.ACTION_DOWN:
mLastX = x;
mLastY = y;
py = player.Y;
break;
case android.view.MotionEvent.ACTION_MOVE:
var Yr = py + (x - mLastX) / 5;
while (Yr < 0) {
Yr += 360;
};
while (Yr >= 360) {
Yr -= 360;
};
player.Y = Yr;
break;
case android.view.MotionEvent.ACTION_UP:
var Yr = py + (x - mLastX) / 5;
while (Yr < 0) {
Yr += 360;
};
while (Yr >= 360) {
Yr -= 360;
};
player.Y = Yr;
break;
}
return true;
}
}));
var isRun = false;
var Sds = 0;
ui.but.setOnTouchListener(new android.view.View.OnTouchListener({
onTouch: function(view, event) {
switch (event.getAction()) {
case android.view.MotionEvent.ACTION_DOWN:
isRun = true;
break;
case android.view.MotionEvent.ACTION_MOVE:
break;
case android.view.MotionEvent.ACTION_UP:
isRun = false;
break;
}
return true;
}
}));
function RToxy(R) {
var x = Math.cos(R);
var y = Math.sin(R);
return [x, y];
};
function weiyi(ary) {
var sum = 0;
for (var i = 0; i < ary.length; i++) {
sum += Math.pow(ary[i], 2);
};
return Math.sqrt(sum);
};
function kdfx(Y) {
var x = Math.cos(Y % 360 / 360 * 2 * Math.PI);
var y = Math.sin(Y % 360 / 360 * 2 * Math.PI);
return [x, y];
};
function getsd(s, ary) {
var sum = weiyi
没有合适的资源?快使用搜索试试~ 我知道了~
AutoJs源码-简单的三维2D吃球游戏
共1个文件
js:1个
需积分: 1 0 下载量 8 浏览量
2022-11-16
04:55:12
上传
评论
收藏 4KB 7Z 举报
温馨提示
AutoJs源码-简单的三维2D吃球游戏。本资源购买前提醒:本源码都是实际autojs项目模板,安装好autojs直接运行即可打开。1、支持低版本autojs。2、资源仅供学习与参考,请勿用于商业用途,否则产生的一切后果将由您自己承担!。3、安装过程详见具体资源,不会使用autojs谨慎下载
资源推荐
资源详情
资源评论
收起资源包目录
AutoJs源码-简单的三维2D吃球游戏.7z (1个子文件)
AutoJs源码-简单的三维2D吃球游戏.js 17KB
共 1 条
- 1
资源评论
[虚幻私塾】
- 粉丝: 335
- 资源: 1558
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功