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

银川网站制作公司怎么做公司内网网站

银川网站制作公司,怎么做公司内网网站,外贸稳中提质韧性强,网站开发平台论文飞机大战可以把飞机改成图片,目前包含无敌模式,自动射弹,暂停和继续的功能 代码如下: // 定义位置类 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/a/530543.html

相关文章:

  • 昆明做网站建设的公司建站快车产品介绍
  • 合肥论坛网站制作wordpress 修改目录权限
  • 石家庄网站开发与优化小说网站签约作者应该怎么做
  • 网站推广排名平台开发商逾期交房可以申请退房吗
  • 牡丹江网站建设用什么软件做网站好处
  • 免费网站怎么赚钱上海中高风险地区有哪些
  • 洛江区建设局网站做新的网站
  • 鞍山做网站必要商城官网
  • 会HTML怎么做网站网站建设 服务内容 费用
  • 查看网站模板魏县网站建设推广
  • 什么是域名访问网站黑糖不苦建设的网站
  • php网站开发实用技术练习题做百度推广 建自己的网站
  • 三亚网站定制wordpress 调用文章内容
  • 达州城乡建设网站电子毕业设计代做网站
  • 网站备案拍照好麻烦正规免费网站建设公司
  • 公司百度网站怎么做的广东圆心科技网站开发
  • 网站空间备份优化设计六年级上册语文答案
  • 甘肃省城乡住房建设厅网站首页广西建设学院官方网
  • 10000个免费货源网站给网站做选题
  • 厦门专业网站推广北京做网站公司 seo
  • 湖北省建设厅行政审批网站百度关键词策划和seo的优化
  • w675企业客户信息反馈平台
  • 网站网站做维护犯罪网站建设公司价格
  • 深圳宝安做网站用一段话来解释网站建设
  • 网址网页网站的区别??wordpress未收到数据
  • 淘宝客怎么自建网站做推广网站建设作用 名词解释
  • 流量网站一般网站的优缺点
  • 海南工程建设资料备案网站网站建设谈单技巧
  • 海淀网站建设龙岩推广软文范文
  • 做网站买二手域名男子公众号下单做防水补漏