接金币html5,JavaScript实现H5接金币功能(实例代码)

今日做出做出一个春节接金币红包的活动,感觉挺不错的分享给大家

这个小游戏采用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 ? innerHeight * 2 : 1334

this.height = (window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight) * 2

this.scale = 0.5

// 定时器对象

this.ticker = null

//金币红包臭蛋

this.Gold = null

//金币红包臭蛋下落速度

this.enemySpeed = 1000//金币下落速度

this.redSpeed = 1000//红包下落速度

this.danSpeed = 1000//红包下落速度

//金币红包臭蛋生成速度

this.createSpeed = 200

//接金币红包臭蛋的车

this.hand = null

//开始按钮

this.beginBtn = null

//分数

this.score = 0

//定义一个碰撞的数组

this.crashList = []

this.isEnd = false

//砸中臭蛋数量

this.danNum = 0

//定时器

this.timerAll = null

}

init()

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值