今日做出做出一个春节接金币红包的活动,感觉挺不错的分享给大家
这个小游戏采用hilojs实现的,详情
第一步:安装插件
npm i hilojs或者yarn add hilojs
第二步:创建一个Asset.js文件
import Hilo from "hilojs"; export default Hilo.Class.create({ Mixes: Hilo.EventMixin, queue: null, // 下载类 gold: null, // 金币 wood: null, // 金币 water: null, // 蛋 fireElement: null, // 金币 soil: null, // 红包 person: null, // 车 score0: null, // score1: null, // score2: null, // load() { let imgs = [ { id: 'soil',//红包 src: require('../../../assets/image/red.png') }, { id: 'water',//蛋 src: require('../../../assets/image/dan.png') }, { id: 'gold',//金币 src: require('../../../assets/image/money3.png') }, { id: 'person',//车 src: require('../../../assets/image/che1.png') } ]; this.queue = new Hilo.LoadQueue(); this.queue.add(imgs); this.queue.on('complete', this.onComplete.bind(this)); this.queue.on('error', (e) => { console.log('加载出错', e) }) this.queue.start(); }, onComplete() { //加载完成 console.log('加载完成') this.gold = this.queue.get('gold').content;//金币 this.water = this.queue.get('water').content;//蛋 this.soil = this.queue.get('soil').content;//红包 this.person = this.queue.get('person').content; //删除下载队列的complete事件监听 this.queue.off('complete'); // complete暴露 this.fire('complete'); } })
第三步:创建一个game.js文件
import Hilo from "hilojs"; import Asset from './Asset'//定义金币红包车参数 import Gold from './gold'//随机生成金币红包臭蛋 import Hand from './hand'//汽车初始化级碰撞 let startTime = 0 export default class game { constructor(page) { this.page = page //设置的游戏时间 this.gameTime = 0 this.gameStatus = "ready" /* play 游戏开始 ready 游戏结束 **/ // 下载队列 this.asset = new Asset() // 画布对象 this.stage = null // 画布信息 this.width = (window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth) * 2 // this.height = innerHeight * 2 < 1334 "play" this.calcTime() } calcTime() { //游戏时间 this.timerAll = setTimeout(() => { let now = new Date().getTime() let difference = parseInt((now - startTime) / 1000) if (difference % 30 == 0) { this.Gold.score[0] = this.Gold.score[0] + 5 this.Gold.score[2] = this.Gold.score[2] + 5 this.Gold.enemySpeed = this.Gold.enemySpeed + 500 this.Gold.redSpeed = this.Gold.redSpeed + 200 this.Gold.danSpeed = this.Gold.danSpeed + 300 } this.calcTime() }, 1000); } clearCalcTime() { this.Gold.score[0] = 5 this.Gold.score[2] = 5 this.Gold.enemySpeed = 1000 this.Gold.redSpeed = 1000 this.Gold.danSpeed = 1000 clearTimeout(this.timerAll); } gameOver() {//游戏结束调用 this.Gold.stopCreateEnemy() this.gameStatus = "ready" this.initBeginBtn() //this.hand.removeChild(this.hand.score) this.stage.removeChild(this.hand) } initZongzi() {//初始化金币红包 this.Gold = new Gold({ id: 'gold', height: this.height, width: this.width, enemySpeed: this.enemySpeed, redSpeed: this.redSpeed, danSpeed: this.danSpeed, createSpeed: this.createSpeed, pointerEnabled: false, // 不关闭事件绑定 无法操作舞台 SmallGoldList: [this.asset.gold, this.asset.water, this.asset.soil], startTime }).addTo(this.stage, 2) //舞台更新 this.stage.onUpdate = this.onUpdate.bind(this); } initHand() {//初始化手 this.hand = new Hand({ id: 'hand', img: this.asset.person, height: this.asset.person.height, width: this.asset.person.width, x: this.width / 2 - this.asset.person.width / 4, y: this.height - this.asset.person.height / 2 - 40 }).addTo(this.stage, 1); Hilo.util.copy(this.hand, Hilo.drag); this.hand.startDrag([0, this.height - this.asset.person.height / 2 - 40, this.width - this.asset.person.width / 2 + 10, 0]); } onUpdate() {//舞台更新 if (this.gameStatus == 'ready') { return } // console.log('碰撞', this.crashList) let num = [] this.crashList.forEach(e => { if (e == 'dan') { num.push(e) } }) this.danNum = num.length if (num.length >= 3) {//游戏结束 console.log('游戏结束') this.clearCalcTime() this.isEnd = true; this.gameOver() return } this.Gold.children.forEach(item => { if (this.hand.checkCollision(item)) { if (item.drawable.image.src.indexOf("red") != -1) { this.crashList.push('red') } if (item.drawable.image.src.indexOf("money3") != -1) { this.crashList.push('money3') } if (item.drawable.image.src.indexOf("dan") != -1) { this.crashList.push('dan') } // 碰撞了 item.over(); this.score += item.score || 0; switch (item.score) { case -1: this.hand.addScore(this.asset.score0) break; case 1: this.hand.addScore(this.asset.score1) break; case 2: this.hand.addScore(this.asset.score2) break; default: break; } } }) } initBeginBtn() { } }
第四步:创建一个gold.js文件
import Hilo from "hilojs"; import SmallGold from './SmallGold' let Enemy = Hilo.Class.create({ Extends: Hilo.Container, timer: null, // 定时器 SmallGoldList: [], enemySpeed: 0, redSpeed: 0, danSpeed: 0, createSpeed: 0, score: [5, 0, 5], tween: null, startTime: null, constructor: function (properties) { Enemy.superclass.constructor.call(this, properties); this.startTime = properties.startTime this.tween = Hilo.Tween; this.creatEnemy(); this.beginCreateEnemy(); }, creatEnemy() { let now = new Date().getTime() let difference = parseInt((now - this.startTime) / 200) let index = null; let differenceNow = parseInt((now - this.startTime) / 1000) if (0 <= differenceNow && differenceNow <= 60) { if (difference == 0) { index = 0 this.createGold(index, this.enemySpeed) } else if (difference % 70 == 0) {//0-15秒,障碍蛋1个 index = 1 this.createGold(index, this.danSpeed) } else if (difference % 147 == 0 || difference % 154 == 0) {//15-30秒障碍蛋2个(150-155) index = 1 this.createGold(index, this.danSpeed) } else if (difference % 222 == 0 || difference % 226 == 0 || difference % 235 == 0) {//30-45秒障碍蛋3个(225-230) index = 1 this.createGold(index, this.danSpeed) } else if (difference % 296 == 0 || difference % 302 == 0 || difference % 307 == 0 || difference % 311 == 0) {//60秒,障碍蛋4个 index = 1 this.createGold(index, this.danSpeed) } else { let number = this.random(0, 100); if (number < 40) { //0为金币2位红包1为蛋 index = 0 this.createGold(index, this.enemySpeed) } else if (number <= 100) { index = 2 this.createGold(index, this.redSpeed) } } } else { let nowmiao = difference - 300 if (nowmiao % 70 == 0 || nowmiao % 75 == 0 || nowmiao % 78 == 0 || nowmiao % 85 == 0) {//0-15秒,障碍蛋4个 index = 1 this.createGold(index, this.danSpeed) } else { let number = this.random(0, 100); if (number < 40) { //0为金币2位红包1为蛋 index = 0 this.createGold(index, this.enemySpeed) } else if (number <= 100) { index = 2 this.createGold(index, this.redSpeed) } } } }, createGold(index, enemySpeed) { let hold = undefined if (this.SmallGoldList[index].width && this.SmallGoldList[index].height) { hold = new SmallGold({ image: this.SmallGoldList[index], rect: [0, 0, this.SmallGoldList[index].width, this.zongziList[index].height], width: this.SmallGoldList[index].width / 2, height: this.SmallGoldList[index].height / 2, // scaleX: 0.5, // scaleY: 0.5, }).addTo(this); } let widthScreen = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth let heightScreen = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight hold.x = 0.45 * widthScreen; hold.y = 0.4 * heightScreen; hold.score = this.score[index] this.tween.to(hold, { x: this.random(0, (this.width - this.SmallGoldList[0].width / 2)), y: this.height }, { duration: 1400 / enemySpeed * 1000, loop: false, onComplete: () => { hold.removeFromParent() } }); }, random(lower, upper) { return Math.floor(Math.random() * (upper - lower + 1)) + lower; }, beginCreateEnemy() {//开始生成 this.timer = setInterval(() => { this.creatEnemy(); }, this.createSpeed); }, stopCreateEnemy() {//停止生成并全部移除 clearInterval(this.timer) this.removeAllChildren() }, checkCollision(enemy) {//碰撞检测 for (var i = 0, len = this.children.length; i < len; i++) { if (enemy.hitTestObject(this.children[i], true)) { return true; } } return false; } }) export default Enemy
第五步:创建一个hand.js文件
import Hilo from "hilojs"; let hand = Hilo.Class.create({ Extends: Hilo.Container, // 图 img: null, //车 bowl: null, //分数 score: null, constructor(properties) { hand.superclass.constructor.call(this, properties) this.initHand() }, initHand() { //初始化背景 this.hand = new Hilo.Bitmap({ id: 'hand', image: this.img, rect: [0, 0, this.img.width, this.img.height], width: this.img.width / 2, height: this.img.height / 2, // scaleX: 0.5, // scaleY: 0.5, }).addTo(this); }, addScore(image) { //加分 if (this.img.width && image.width) { this.score = new Hilo.Bitmap({ id: 'score', image: image, rect: [0, 0, image"htmlcode">import Hilo from "hilojs"; let SmallGold= Hilo.Class.create({ Extends: Hilo.Bitmap, constructor: function (properties) { SmallGold.superclass.constructor.call(this, properties); this.onUpdate = this.onUpdate.bind(this); }, over(){ this.removeFromParent(); }, onUpdate() { if (this.parent.height < this.y) { this.removeFromParent(); return } } }) export default SmallGold我这是在vue中使用
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
暂无评论...
稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!
昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。
这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。
而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?
更新日志
2024年11月26日
2024年11月26日
- 凤飞飞《我们的主题曲》飞跃制作[正版原抓WAV+CUE]
- 刘嘉亮《亮情歌2》[WAV+CUE][1G]
- 红馆40·谭咏麟《歌者恋歌浓情30年演唱会》3CD[低速原抓WAV+CUE][1.8G]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[320K/MP3][193.25MB]
- 【轻音乐】曼托凡尼乐团《精选辑》2CD.1998[FLAC+CUE整轨]
- 邝美云《心中有爱》1989年香港DMIJP版1MTO东芝首版[WAV+CUE]
- 群星《情叹-发烧女声DSD》天籁女声发烧碟[WAV+CUE]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[FLAC/分轨][748.03MB]
- 理想混蛋《Origin Sessions》[320K/MP3][37.47MB]
- 公馆青少年《我其实一点都不酷》[320K/MP3][78.78MB]
- 群星《情叹-发烧男声DSD》最值得珍藏的完美男声[WAV+CUE]
- 群星《国韵飘香·贵妃醉酒HQCD黑胶王》2CD[WAV]
- 卫兰《DAUGHTER》【低速原抓WAV+CUE】
- 公馆青少年《我其实一点都不酷》[FLAC/分轨][398.22MB]
- ZWEI《迟暮的花 (Explicit)》[320K/MP3][57.16MB]