当前位置: 首页 > wzjs >正文

广州有哪些科技公司重庆seo扣费

广州有哪些科技公司,重庆seo扣费,高州网站开发公司,网站同城在线哪里做飞机大战可以把飞机改成图片,目前包含无敌模式,自动射弹,暂停和继续的功能 代码如下: // 定义位置类 class GamePosition {x: numbery: numberconstructor(x: number, y: number) {this.x xthis.y y} }Entry Component struct…

飞机大战可以把飞机改成图片,目前包含无敌模式,自动射弹,暂停和继续的功能
请添加图片描述
代码如下:

// 定义位置类
class GamePosition {x: numbery: numberconstructor(x: number, y: number) {this.x = xthis.y = y}
}@Entry
@Component
struct PlaneGame {@State isPaused: boolean = false // 添加暂停状态@State playerX: number = 180@State playerY: number = 400  // 降低初始Y位置@State bullets: GamePosition[] = []@State enemies: GamePosition[] = []@State score: number = 0@State isGameOver: boolean = false@State isInvincible: boolean = false  // 添加无敌状态@State autoFire: boolean = false  // 添加自动发射状态// 修改移动速度从8提高到15private speed: number = 15      // 大幅提高移动速度private bulletSpeed: number = 15private enemySpeed: number = 3private enemySpawnRate: number = 45private fireInterval: number = 10  // 自动发射间隔(帧数)private frameCount: number = 0private planeSize: number = 40  // 减小尺寸private bulletSize: number = 8private enemySize: number = 40private isLeftPressed: boolean = falseprivate isRightPressed: boolean = falseprivate isFirePressed: boolean = falseprivate gameInterval: number = 0 // 添加游戏循环引用// 添加togglePause方法togglePause() {this.isPaused = !this.isPaused// 强制状态更新this.score = this.score + 0console.log(`游戏已${this.isPaused ? '暂停' : '继续'}`)}aboutToAppear() {this.gameInterval = setInterval(() => {if (!this.isPaused && !this.isGameOver) {this.updateGame()this.handleContinuousInput()}}, 16)}handleContinuousInput() {if (this.isLeftPressed) {this.movePlayer('left')}if (this.isRightPressed) {this.movePlayer('right')}if (this.isFirePressed || (this.autoFire && this.frameCount % this.fireInterval === 0)) {this.fireBullet()}}updateGame() {if (this.isGameOver) {return;}this.frameCount++;// Update bullet positionsthis.bullets = this.bullets.map(bullet => new GamePosition(bullet.x, bullet.y - this.bulletSpeed)).filter(bullet => bullet.y > 0);// Update enemy positionsthis.enemies = this.enemies.map(enemy => new GamePosition(enemy.x, enemy.y + this.enemySpeed)).filter(enemy => enemy.y < 1000);// Spawn new enemiesif (this.frameCount % this.enemySpawnRate === 0) {this.enemies.push(new GamePosition(Math.random() * (360 - this.enemySize),-this.enemySize));}// Check collisionsthis.checkCollisions();// Check game over conditionif (!this.isInvincible && this.enemies.some(enemy => enemy.y + this.enemySize > this.playerY &&enemy.x + this.enemySize > this.playerX &&enemy.x < this.playerX + this.planeSize)) {this.isGameOver = true;}}checkCollisions() {this.bullets.forEach(bullet => {this.enemies.forEach((enemy, index) => {if (bullet.x + this.bulletSize > enemy.x &&bullet.x < enemy.x + this.enemySize &&bullet.y + this.bulletSize > enemy.y &&bullet.y < enemy.y + this.enemySize) {this.score += 10;this.enemies.splice(index, 1);}});});}fireBullet() {this.bullets.push(new GamePosition(this.playerX + this.planeSize / 2 - this.bulletSize / 2,this.playerY - this.bulletSize));}movePlayer(direction: string) {if (direction === 'left' && this.playerX > 0) {this.playerX -= this.speed;} else if (direction === 'right' && this.playerX < 360 - this.planeSize) {this.playerX += this.speed;}}toggleInvincible() {this.isInvincible = !this.isInvincible;}toggleAutoFire() {this.autoFire = !this.autoFire;}restartGame() {this.playerX = 180;this.playerY = 350;  // 将初始Y坐标从400改为350this.bullets = [];this.enemies = [];this.score = 0;this.isGameOver = false;this.frameCount = 0;this.isPaused = false;}build() {Column() {// 游戏标题和状态栏Row() {Text('飞机大战').fontSize(24)  // 缩小标题字号.fontColor(Color.White).margin({ left: 10 })  // 减小左边距Blank()Text(`得分: ${this.score}`).fontSize(20)  // 缩小得分显示字号.fontColor(Color.White).margin(5)  // 减小边距Text(`无敌: ${this.isInvincible ? 'ON' : 'OFF'}`).fontSize(20)  // 缩小无敌状态字号.fontColor(this.isInvincible ? Color.Green : Color.Gray).margin(5)  // 减小边距}.width('100%').height(40)  // 减小标题栏高度.backgroundColor('#333333')// 游戏主区域Stack() {// 游戏区域背景Rect().width('100%').height(450)  // 将高度从400增加到450.backgroundColor('#000033')// 玩家飞机Rect().width(this.planeSize).height(this.planeSize).fill(Color.Blue).position({ x: this.playerX, y: this.playerY })// 子弹ForEach(this.bullets, (bullet: GamePosition) => {Rect().width(this.bulletSize).height(this.bulletSize * 2)  // 加长子弹.fill(Color.Yellow).position({ x: bullet.x, y: bullet.y })}, (bullet: GamePosition) => `${bullet.x},${bullet.y}`)// 敌机ForEach(this.enemies, (enemy: GamePosition) => {Rect().width(this.enemySize).height(this.enemySize).fill(Color.Red).position({ x: enemy.x, y: enemy.y })}, (enemy: GamePosition) => `${enemy.x},${enemy.y}`)}.width('100%').height(450)  // 同步修改高度.margin({ top: 5, bottom: 5 })  // 调整上下边距.borderRadius(10).border({ width: 2, color: '#555555' })// 游戏控制按钮区域Row() {Button(this.isInvincible ? '关闭无敌' : '开启无敌').onClick(() => this.toggleInvincible()).width(100).height(40).fontSize(16).backgroundColor('#4A4A4A').fontColor(Color.White)Button(this.autoFire ? '关闭自动' : '开启自动').onClick(() => this.toggleAutoFire()).width(100).height(40).fontSize(16).backgroundColor(this.autoFire ? '#FFA500' : '#4A4A4A').fontColor(Color.White)Button(this.isPaused ? '继续' : '暂停').onClick(() => this.togglePause()).width(100).height(40).fontSize(16).backgroundColor(this.isPaused ? '#00AA00' : '#AA0000').fontColor(Color.White)// 添加重新开始按钮Button('重新开始').onClick(() => this.restartGame()).width(100).height(40).fontSize(16).backgroundColor('#4A4A4A').fontColor(Color.White)}.width('95%')  // 减小宽度.justifyContent(FlexAlign.SpaceAround).margin({ top: 5, bottom: 5 })  // 调整上下边距// 方向控制区域Column() {// 上方向按钮Button('↑').onTouch((event: TouchEvent) => {if (event.type === TouchType.Down) {this.isFirePressed = true} else if (event.type === TouchType.Up) {this.isFirePressed = false}}).onClick(() => this.fireBullet())  // 上按钮用于发射子弹.width(60).height(60).fontSize(20).margin(5)// 左右方向按钮Row() {Button('←').onTouch((event: TouchEvent) => {if (event.type === TouchType.Down) {this.isLeftPressed = true} else if (event.type === TouchType.Up) {this.isLeftPressed = false}}).onClick(() => this.movePlayer('left')).width(60).height(60).fontSize(20).margin(5)Button('→').onTouch((event: TouchEvent) => {if (event.type === TouchType.Down) {this.isRightPressed = true} else if (event.type === TouchType.Up) {this.isRightPressed = false}}).onClick(() => this.movePlayer('right')).width(60).height(60).fontSize(20).margin(5)}.justifyContent(FlexAlign.Center)// 下方向按钮(可留空或用作其他功能)// Button('↓')//   .width(60)//   .height(60)//   .fontSize(20)//   .margin(5)//   .opacity(0.5)  // 半透明表示不可用}.margin({ top: 20, bottom: 20 }).alignItems(HorizontalAlign.Center).backgroundColor('#333333').width('90%').borderRadius(20).padding(10)}.width('100%').height('100%').backgroundColor('#222222').onClick(() => {console.log('游戏区域点击')}).onKeyEvent((event: KeyEvent) => {switch (event.keyCode) {case 2038: // 左箭头case 21: this.isLeftPressed = (event.type === KeyType.Down)breakcase 2039: // 右箭头case 22: this.isRightPressed = (event.type === KeyType.Down)breakcase 2040: // 空格case 23: case 2037: // 上箭头case 19: this.isFirePressed = (event.type === KeyType.Down)break}})}
} // 这是PlaneGame结构体的闭合
http://www.dtcms.com/wzjs/424955.html

相关文章:

  • https部署 wordpressseo 什么意思
  • 潮汕美食网站怎么做网络服务网络推广
  • 易企互联网站建设正规电商培训学校排名
  • 虚拟币交易网站建设一手app推广接单平台
  • 江都城乡建设局网站seo交流论坛
  • 平台网站如何做推广方案设计怎么优化网站
  • 网站建设策划书提纲郑州seo优化顾问
  • 苏州建筑行业网站建设如何开发软件app
  • 做关于网站的开题报告网站建设品牌公司
  • 网站国际化怎么做谷歌商店下载
  • 真人性做爰直播网站网络优化工具
  • 需要自己的网站需要怎么做360投放广告怎么收费
  • 网站建设公司前十名郑州网站建设制作公司
  • 寻花问柳一家专注做男人喜爱的网站视频营销模式有哪些
  • 网站建设文库 新的开始产品推广软文200字
  • 扬州网站建设 开元seo技术是什么
  • 国外设计模板网站全国疫情最新信息
  • 上饶便宜的做网站公司b站推广网站2024mmm
  • 无锡商业网站建设百度招聘官网
  • 浙江网站建设公司电话东莞网
  • 南京英文网站建设百度seo优化收费标准
  • 人和马做的网站太原网站建设谁家好
  • 大型网站设计公司做网站设计的公司
  • 做书封面的模板下载网站免费拓客软件排行榜
  • PHP动态网站开发期末考试怎么做网络推广最有效
  • 网页设计工作目标杭州seo百度关键词排名推广
  • web项目网站开发流程怎么写长沙做网站的公司有哪些
  • 那个公司做网站营销策划书模板范文
  • 服装公司做哪个网站小果seo实战培训课程
  • 中网-西安网站建设公司天津百度网站排名优化