2017年8月21日
Create.js开发算术大师游戏(终结篇)
近期比较忙,博客也很久没更新了,讲真其实我的博客水平没那么高,自己写的小东西也是本着怕自己忘记,也算是给自己提醒,诶 最近记忆里不是很好,
先看html:
<canvas id=”game-canvas” width=”1280″ height=”720″></canvas>
上js代码 依旧是入口文件,配置文件,预加载文件
window.init = () => {
letloadingValue=$(“#loading span”);
window.queue=newc.LoadQueue();
window.queue.installPlugin(createjs.Sound);
window.queue.addEventListener(“complete”, (ev)=>{
window.game=newGame();
$(“#loading”).hide();
});
window.queue.addEventListener(“progress”, (ev)=>{
loadingValue.text((ev.progress*100).toFixed() +”%”);
})
window.queue.loadManifest([
{ id: “pointsound”, src: “music/pointsound.mp3” },
{ id: “noMuc”, src: “music/noMuc.mp3” },
{ id: “s2”, src: “music/s2.mp3” },
{ id: “nzb”, src: “music/nzb.mp3” },
])
window.queue.loadManifest([
{ id: “1”, src: “image/assest/1.png”},
{ id: “2”, src: “image/assest/2.png”},
{ id: “3”, src: “image/assest/3.png”},
{ id: “4”, src: “image/assest/4.png”},
{ id: “5”, src: “image/assest/5.png”},
{ id: “6”, src: “image/assest/6.png”},
{ id: “restart”, src: “image/assest/restart.png”},
{ id: “scBtn”, src: “image/direPic/scBtn.png”},
{ id: “sgBtn”, src: “image/direPic/sgBtn.png”},
{ id: “pjBtn”, src: “image/direPic/middle.png”},
{ id: “getScore”, src: “image/assest/getScore.png”},
{ id: “gamebg”, src: “image/assest/gamebg.png”},
{ id: “timer”, src: “image/assest/timer.png”}
]);
}
貌似没啥变化,还是老一套,
ok看游戏逻辑代码处理,
class Game {
constructor(){
this.stage=newc.Stage(“game-canvas”);
c.Touch.enable(this.stage);
this.stage.enableMouseOver();
this.width=this.stage.canvas.width;
this.height=this.stage.canvas.height;
this.nTimeCount=300;
this.gameDataSheet();
this.render();
createjs.Sound.play(“s2”, createjs.Sound.INTERRUPT_NONE,0,0,-1,1,0);
}
获取canvas,触屏事件,鼠标监听事件,舞台宽,舞台高,倒计时,心跳计时,bgm,
render(){
this.stage.update();
window.requestAnimationFrame(()=>{
this.render();
})
}
gameDataSheet(){
window.ceil=window.localStorage.vision;
window.score=0;
this.firstScreen();
}
firstScreen() {
vargameView;
this.gameView=newcreatejs.Container();
this.stage.addChild(this.gameView);
this.gamebg();
this.bgMain(); //游戏背景
this.Layout(); //游戏布局按钮,游戏逻辑
this.fCountTime(); //倒计时模块
}
killScore(){
letgameView;
this.gameView=newcreatejs.Container();
this.stage.addChild(this.gameView);
this.bgMain(); //游戏背景
//得分面板
varscorePanel=newcreatejs.Bitmap(window.queue.getResult(“getScore”));
scorePanel.x=390;
scorePanel.y=50;
this.gameView.addChild(scorePanel);
// 得分
lettext_score=newcreatejs.Text(window.score,”38px Arial”, “#ffffff”);
text_score.x=710;
text_score.y=190;
text_score.textAlign=”center”;
this.gameView.addChild(text_score);
// 重新开始
varrestart=newcreatejs.Bitmap(window.queue.getResult(“restart”));
restart.x=560;
restart.y=0;
createjs.Tween.get(restart).to({ x:restart.x, y:restart.y+400 }, 700,createjs.Ease.backOut);
this.gameView.addChild(restart);
restart.addEventListener(“mousedown”,(ev)=>{
window.location.href=”index.html”;
})
}
// 倒计时
fCountTime() {
lettext_sum=newcreatejs.Text(this.nTimeCount, “20px Arial”, “#ffffff”);
text_sum.x=1227;
text_sum.y=9;
text_sum.textAlign=”center” ;
this.gameView.addChild(text_sum);
window.upSteTimeOut=setTimeout(()=>{
if(this.nTimeCount>0){
this.nTimeCount–;
text_sum.text=this.nTimeCount;
this.gameView.removeChild(text_sum);
this.fCountTime();
}else{
window.clearInterval(window.upSteTimeOut);
this.reset();
this.killScore();
}
},1000)
}
//游戏布局处理
Layout(){
vartimer,getHero,insect,redImgHero,sgBtns,scBtns,pjBtns;
varheroContainer=newcreatejs.Container();
window.currentIndex=babyEye.randomRange(1, 7);
getHero=window.queue.getResult(currentIndex);
insect=newcreatejs.Bitmap(getHero);
insect.scaleX=insect.scaleY=ceil;
insect.regX=148;
insect.regY=28;
heroContainer.addChild(insect);
heroContainer.x=this.width/2;
heroContainer.y=this.height/6;
this.gameView.addChild(heroContainer);
//3按钮
sgBtns=newcreatejs.Bitmap(window.queue.getResult(“sgBtn”));
sgBtns.x=850;
sgBtns.y=300;
this.gameView.addChild(sgBtns);
//1按钮
scBtns=newcreatejs.Bitmap(window.queue.getResult(“scBtn”));
scBtns.x=320;
scBtns.y=320;
this.gameView.addChild(scBtns);
//2按钮
pjBtns=newcreatejs.Bitmap(window.queue.getResult(“pjBtn”));
pjBtns.x=580;
pjBtns.y=260;
this.gameView.addChild(pjBtns);
//倒计时图
this.timer=newcreatejs.Bitmap(window.queue.getResult(“timer”));
this.timer.x=1139;
this.timer.y=4;
this.gameView.addChild(this.timer);
游戏核心主逻辑
if(window.currentIndex==5||window.currentIndex==6){
scBtns.addEventListener(“mousedown”,(ev)=>{
this.gameView.removeChild(heroContainer);
console.log(window.score);
this.builderSuccess();
})
}else{
scBtns.addEventListener(“mousedown”,(ev)=>{
heroContainer.scaleX=heroContainer.scaleY+0.1;
this.buildrFail();
})
}
//3判断
if(window.currentIndex==3||window.currentIndex==2){
sgBtns.addEventListener(“mousedown”,(ev)=>{
this.gameView.removeChild(heroContainer);
this.builderSuccess();
})
}else{
sgBtns.addEventListener(“mousedown”,(ev)=>{
heroContainer.scaleX=heroContainer.scaleY+0.1;
this.buildrFail();
})
}
//2判断
if(window.currentIndex==1||window.currentIndex==4){
pjBtns.addEventListener(“mousedown”,(ev)=>{
this.gameView.removeChild(heroContainer);
this.builderSuccess();
})
}else{
pjBtns.addEventListener(“mousedown”,(ev)=>{
heroContainer.scaleX=heroContainer.scaleY+0.1;
this.buildrFail();
})
}
}
builderSuccess(){
//视标缩放代码算法
if(ceil==0.10000000000000014){ // 0.20000000000000015
ceil=ceil-0.3;
ceil+=0.3;
}else{
ceil=ceil-0.1;
}
//分数成绩代码算法
if(window.score<100){
window.score=window.score+10;
window.speed=window.speed+0.02;
}else if(window.score == 100){
window.score=100;
}
this.success(); //你真棒
window.clearInterval(window.upSteTimeOut); //清除倒计时
this.reset(); //清除画布所有内容
this.firstScreen(); //画布刷新
}
得分逻辑
buildrFail(){
window.speed=window.speed-0.1;
this.fail();
if(window.score<=0){
window.score=0;
}else{
window.score=window.score-10;}
window.clearInterval(window.upSteTimeOut);
this.reset();
this.firstScreen();
}
//成功处理
success(){
createjs.Sound.play(“nzb”, createjs.Sound.INTERRUPT_NONE, 0, 0, 0, 1, 0);
$(“#sucImg”).show(500);
$(“#sucImg”).hide(500);
}
//失败处理
fail(){
createjs.Sound.play(“noMuc”, createjs.Sound.INTERRUPT_NONE, 0, 0, 0, 1, 0);
$(“#failImg”).show(500);
$(“#failImg”).hide(500);
}
//移除画布所有
reset(){
this.stage.removeAllChildren();
this.stage.removeAllEventListeners();
}
//播放背景
gamebg(){
letgamebg=window.queue.getResult(“gamebg”);
letgamebgs=newcreatejs.Bitmap(gamebg);
gamebgs.x=0;
gamebgs.y=20;
this.gameView.addChild(gamebgs);
}
References:
Nars casino bronzer
References:
https://may22.ru/user/pilotinch2/
References:
Legal safe
References:
http://47.94.173.135:3000/ilalin3323328
References:
Casino drive
References:
https://www.adpost4u.com/user/profile/4308831
References:
Bodybuilding losing weight
References:
https://www.servus-nachbar.at/Neuigkeiten/index.php/;focus=W4YPRD_com_cm4all_wdn_Flatpress_7491266&path=&frame=W4YPRD_com_cm4all_wdn_Flatpress_7491266?x=entry:entry250911-114805%3Bcomments:1
References:
Steroids chemistry
References:
http://47.109.30.152:3000/marie05n733168
References:
Free steroids pills
References:
https://git.gasshog.fr/caralandseer8/wedioz.com1997/wiki/Clenbuterol%3A-Erfahrungen%2C-Wirkung-%26-Alternativen-2026
References:
Weight loss steroids for sale
References:
http://47.109.30.152:3000/milesaguilar7/miles1984/wiki/5-Best-Anavar-Stacks%3A-An-Overview-of-Potential-Combinations
References:
Effects of performance enhancing drugs
References:
https://datemyfamily.tv/@shonaosburne38
References:
Closest thing to steroids that is legal
References:
https://jandlfabricating.com/employer/effects-of-low-testosterone/
References:
Best steroid to gain mass
References:
https://rsas.de/judeirwin72591
References:
New steroids
References:
http://47.113.145.232:3000/cliffordaguila
References:
Weight lifting supplements for sale
References:
https://lyfeclick.com/@rollandtrout74
You are so interesting! I do not suppose I’ve truly read through something like that before.
So great to find somebody with some genuine thoughts
on this subject. Seriously.. thank you for starting
this up. This site is something that’s needed
on the internet, someone with a bit of originality!
References:
https://myenglishguide.com/members/pointsmash9/activity/15719/
References:
Instant Casino Einzahlungsmethoden
References:
https://sonnik.nalench.com/user/carboniris41/
References:
Instant Casino Live Casino
References:
https://enregistre-le.top/item/596033
References:
Instant Casino Konto erstellen
References:
https://thefreeadforum.top/index.php?page=user&action=pub_profile&id=864707
References:
H top casino royal
References:
https://mensvault.men/story.php?title=guide-to-progressive-jackpots-tips-tricks-how-they-work
References:
Casino coushatta
References:
https://opensourcebridge.science/wiki/WinSpirit_asino_Reviews_Read_Customer_Service_Reviews_of_winspirit_com
References:
Short people facts
References:
https://pads.jeito.nl/s/oBr0Qm9-DH
References:
Steroids|2ahukewjy0cqyv7hnahvpes0khayodxuq4lyoahoecaeqfq
References:
http://uniprint.co.kr/bbs/board.php?bo_table=free&wr_id=272637
References:
Steroids t nation
References:
http://play.kkk24.kr/bbs/board.php?bo_table=online&wr_id=346448
supplement stacks bodybuilding
References:
https://yogicentral.science/wiki/7_best_sites_to_buy_testosterone_online_in_2025_New_York_Post
References:
Online Casino Echtgeld Gewinn
References:
https://perusilk54.werite.net/beste-echtgeld-online-casinos-alle-in-einer-casino-liste-2026
References:
Geant casino la foux
References:
https://pikidi.com/seller/profile/systembrush84
References:
Rocketplay neosurf real money
References:
https://app.readthedocs.org/profiles/relishback0/
References:
https://graph.org/ripper-casino-review-bonuses-04-20 rocket australia
References:
Aristocrat slots
References:
https://graph.org/Stay-Casino-Review-Features-Bonuses–Payouts-04-20
References:
Emerald queen casino tacoma
References:
https://online-casino-klarna.online-spielhallen.de/
References:
Newcastle casino
References:
https://kingbilly-casino.online-spielhallen.de/
References:
Freiburg im Breisgau
References:
https://casinos-polen.online-spielhallen.de/
References:
Ludwigshafen am Rhein
References:
https://deutsche-welle-casino.online-spielhallen.de/
References:
Bochum
References:
https://altes-casino-petersberg.online-spielhallen.de/
References:
Practice blackjack
References:
https://graph.org/Can-You-Park-At-The-Casino-Gold-Coast-04-27
References:
Casino games list
References:
https://graph.org/Australian-Slot-Machines-List-04-27
References:
Med
References:
https://gitea.shizuka.icu/cortezmannino4
References:
Erfarne spilleres valg af casino udbetaling
References:
http://www.gtcm.info/home.php?mod=space&uid=1366841
References:
Udbetalingsrate
References:
http://www.shkxrd.com:3000/elaneholtz6980
References:
Sikker gevinst udbetaling online casino
References:
https://dammsound.com/ernademaine17
References:
Venetian casino las vegas https://gangsain.co.kr/bbs/board.php?bo_table=free&wr_id=324249
References:
Walker mn casino http://git.qniao.cn/stewartoswald
References:
Blackjack surrender https://jobs.maanas.in/institution/new-microgaming-bonus-codes-for-may-2026/
References:
Online casino reviews 1 site for best online casinos https://gitea.jsjymgroup.com/omarmorrissey1/microgaming-casino-welcome-pack6919/wiki/Start-Your-Jackpot-Adventure-Today
References:
Spotlight 29 casino https://lius.familyds.org:3000/aureliomcbeath
References:
Casino paypal https://dev8.webserver5.com/employer/latest-microgaming-casino-bonuses-may-2026/