///'// 定义全局变量//nvar score = 0; // 分数//nvar level = 1; // 关卡//nvar character = ///'Player///'; // 人物//nvar weapon = ///'Gun///'; // 武器//n//n// 飞碟对象构造函数//nfunction Disk() {//n this.x = Math.random() * 800; // 飞碟的初始横坐标,范围在0-800之间//n this.y = 0; // 飞碟的初始纵坐标//n this.speed = Math.random() * 3 + level; // 飞碟的下落速度,随关卡逐渐增加//n}//n//n// 更新飞碟的位置//nDisk.prototype.update = function() {//n this.y += this.speed; // 飞碟下落//n if (this.y > 600) { // 当飞碟超出屏幕时,重置位置//n this.x = Math.random() * 800;//n this.y = 0;//n score--; // 分数减1//n }//n}//n//n// 绘制飞碟//nDisk.prototype.draw = function() {//n fill(255, 0, 0); // 设置飞碟颜色为红色//n ellipse(this.x, this.y, 50, 50); // 绘制飞碟//n}//n//n// 点击飞碟的事件处理函数//nDisk.prototype.onClick = function() {//n score++; // 分数加1//n level++; // 关卡加1//n this.x = Math.random() * 800; // 重置飞碟位置//n this.y = 0;//n this.speed = Math.random() * 3 + level; // 随关卡逐渐增加速度//n}//n//n// 创建飞碟对象//nvar disk = new Disk();//n//n// 游戏循环//nfunction draw() {//n background(0); // 清空画布//n disk.update(); // 更新飞碟位置//n disk.draw(); // 绘制飞碟//n fill(255); // 设置文本颜色为白色//n textSize(20); // 设置文本大小为20//n text(///'Score: ///' + score, 10, 30); // 绘制分数//n text(///'Level: ///' + level, 10, 60); // 绘制关卡//n text(///'Character: ///' + character, 10, 90); // 绘制人物//n text(///'Weapon: ///' + weapon, 10, 120); // 绘制武器//n}//n//n// 点击事件处理函数//nfunction mouseClicked() {//n var distance = dist(mouseX, mouseY, disk.x, disk.y); // 计算点击位置与飞碟中心的距离//n if (distance <= 25) { // 如果距离小于等于25,说明点击到了飞碟//n disk.onClick(); // 触发飞碟的点击事件处理函数//n }//n}//n//n// 启动游戏//nfunction setup() {//n createCanvas(800, 600); // 创建画布大小为800x600//n}//n//n// 运行游戏循环//nfunction draw() {//n draw();//n}//n/


原文地址: https://www.cveoy.top/t/topic/pM7V 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录