网站怎么改版自适应,湛江网站建设策划方案,做58一样的网站,电子商务网站建设多少钱3D台球
【3D台球】这款游戏的操作简洁明了#xff0c;玩家只需要简单的练习两分钟便能够掌握。玩家需要用鼠标控制击球的方向和力度#xff0c;将白球打进洞中。每次进球后#xff0c;玩家需要选择下一个要击打的球#xff0c;直到所有的球都打进洞中。但要注意避免黑球进…3D台球
【3D台球】这款游戏的操作简洁明了玩家只需要简单的练习两分钟便能够掌握。玩家需要用鼠标控制击球的方向和力度将白球打进洞中。每次进球后玩家需要选择下一个要击打的球直到所有的球都打进洞中。但要注意避免黑球进洞。 运行效果 HTML源码
!DOCTYPE HTML
html
headmeta http-equivContent-Type contenttext/html; charsetUTF-8meta nameviewport contentuser-scalableno /meta nameapple-mobile-web-app-capable contentyes /meta nameapple-touch-fullscreen contentyes /meta nameapple-mobile-web-app-status-bar-style contentblack /titleball/titlestyle typetext/cssbody{margin:0;padding:0;font-size:12px;background:url(res/wood.jpg)}/style
/head
bodydiv id container/divdiv id fps style position:absolute/divscript src src/quark.base-1.0.0.alpha.min.js/scriptscript src Taiqiu.js/script
/body
/htmlTaiqiu.js源码
function Vector(a,b){this.xa||0;this.yb||0}Vector.prototype.resetfunction(a,b){this.xa;this.yb};Vector.prototype.getClonefunction(){return new Vector(this.x,this.y)};Vector.prototype.cutfunction(a){this.setLength(Math.min(a,this.getLength()))};Vector.prototype.cutNewfunction(a){var aMath.min(a,this.getLength()),bthis.getClone();b.setLength(a);return b};Vector.prototype.equalsfunction(a){return this.xa.xthis.ya.y};Vector.prototype.plusfunction(a){this.xa.x;this.ya.y};
Vector.prototype.plusNewfunction(a){return new Vector(this.xa.x,this.ya.y)};Vector.prototype.minusfunction(a){this.x-a.x;this.y-a.y};Vector.prototype.minusNewfunction(a){return new Vector(this.x-a.x,this.y-a.y)};Vector.prototype.negatefunction(){this.x-this.x;this.y-this.y};Vector.prototype.negateNewfunction(){return new Vector(-this.x,-this.y)};Vector.prototype.scalefunction(a){this.x*a;this.y*a};Vector.prototype.scaleNewfunction(a){return new Vector(this.x*a,this.y*a)};
Vector.prototype.getLengthfunction(){return Math.sqrt(this.x*this.xthis.y*this.y)};Vector.prototype.setLengthfunction(a){var bthis.getLength();b?this.scale(a/b):this.xa};Vector.prototype.getAnglefunction(){return Math.atan2(this.y,this.x)};Vector.prototype.setAnglefunction(a){var bthis.getLength();this.xb*Math.cos(a);this.yb*Math.sin(a)};
Vector.prototype.rotatefunction(){var a,b;barguments;b.length1?(aMath.cos(b[0]),bMath.sin(b[0])):(ab[0],bb[1]);var dthis.x*bthis.y*a;this.xthis.x*a-this.y*b;this.yd};Vector.prototype.rotateNewfunction(a){var bnew Vector(this.x,this.y);b.rotate(a);return b};Vector.prototype.dotfunction(a){return this.x*a.xthis.y*a.y};Vector.prototype.getNormalfunction(){return new Vector(-this.y,this.x)};Vector.prototype.isPerpTofunction(a){return this.dot(a)0};
Vector.prototype.angleBetweenfunction(a){athis.dot(a)/(this.getLength()*a.getLength());return Math.acos(a)};(function(){function a(){for(var a in q)f[a]new Quark.Bitmap({image:q[a],x:c.offset.x,y:c.offset.y,eventEnabled:!1})}function b(){a();d();e();c.ui.init();g();c.initEvent();c.initCue();c.initLine();c.initShotTxt();c.initScore();c.initWin();c.initLose();c.loopc.shoot;l.updatefunction(){c.frames;c.loop()}}function d(){var aQuark.getDOM(container),enew Quark.DOMContext({canvas:a});canvasQuark.createDOM(canvas,{width:h,height:i,style:{position:absolute}});canvasContextnew Quark.CanvasContext({canvas:canvas});
a.appendChild(canvas);lc.stagenew Quark.Stage({container:a,width:h,height:i,context:e});onew Quark.Timer(1E3/k);o.addListener(l);o.addListener(Q.Tween);o.start();l.addChild(f.table);c.initPlayers()}function g(){c.Ball.createBalls();var ac.pointnew Quark.Bitmap({image:c.Ball.images[0],rect:[0,0,c.r*2,c.r*2],regX:c.r,regY:c.r});l.addChild(c.point);a.alpha0.3;l.step();for(var a0,ec.Ball.balls.length;ae;a){var nc.Ball.balls[a];n.bitmap.drawable.domDrawable.style.borderRadiusjpx;n.light.drawable.domDrawable.style.borderRadius
jpx}c.point.drawable.domDrawable.style.borderRadiusc.rpx;l.addChild(f.ballRoad);l.addChild(f.cue);f.ballRoad.yp.y-60;f.ballRoad.xp.x180;c.xxf.ballRoad.xf.ballRoad.width-j-6}function e(){c.frames0;fpsContainerQuark.getDOM(fps);setInterval(function(){fpsContainer.innerHTMLFPS:c.frames;c.frames0},1E3)}var cQ.use(BallGame),jc.r14,h960,i600,k60,sc.paramsQuark.getUrlParams(),nc.mouseRs.r||Q.supportTouch?90:0,lc.stage,fc.bitmaps{},qc.images{},pc.offset{x:55,y:70};
c.canShot!0;var o;window.onloadfunction(a){var cnew Quark.ImageLoader;c.addEventListener(complete,function(a){a.target.removeAllEventListeners();for(var c in a.images)q[c]a.images[c].image;b()});c.load(a)}([{id:table,src:res/table.jpg},{id:cue,src:res/cue.png},{id:light,src:res/light.png},{id:ballRoad,src:res/ballRoad.png},{id:player-txt,src:res/player-txt.png},{id:ball1,src:res/ball1.png},{id:ball9,src:res/ball9.png},{id:shot-txt,src:res/shot-txt.png},{id:num,
src:res/number.png},{id:win,src:res/win.png},{id:lose,src:res/lose.png},{id:loading,src:res/loading.gif},{id:num1,src:res/num.png}]);c.shootfunction(){var ac.line.rotation*Math.PI/180;c.point.xc.mouse.x-n*Math.cos(a);c.point.yc.mouse.y-n*Math.sin(a);if(c.isDown(c.powerc.powerV,c.power27||c.power1))c.powerV*-1};window.shootfunction(a,c){BallGame.whiteBall.v.reset(a,c);BallGame.loopBallGame.Ball.update};window.printfunction(){for(var a0;aBallGame.Ball.balls.length;a){var c
BallGame.Ball.balls[a];console.log(c.x-p.x,c.y-p.y,c.num)}}})();(function(){function a(a,e){this.p1a;this.p2e}var bBallGame.lines[],d[[27.1,50.7,27.1,385.5],[50.4,408.9,399.1,408.9],[446,408.9,795,408.9],[818.5,385.6,818.5,50.9],[795.1,27.5,445.9,27.5],[399.1,27.5,50.5,27.5]];BallGame.holePoint[[26,25],[421,17],[817,23],[820,407],[422,416],[26,408]];(function(){var g,e,c;g0;for(ed.length;ge;g)cd[g],cnew a(new Vector(c[0]BallGame.offset.x,c[1]BallGame.offset.y),new Vector(c[2] BallGame.offset.x,c[3] BallGame.offset.y)),b[g]c})()})();(function(){var aQ.use(BallGame);a.initCuefunction(){var ba.cuea.bitmaps.cue,da.mouse;b.regY15;b.regX0;b.updatefunction(){this.xa.whiteBall.x;this.ya.whiteBall.y;var bMath.atan2(d.y-this.y,d.x-this.x);this.rotationb/Math.PI*180180;this.x-(a.power*310)*Math.cos(b);this.y-(a.power*310)*Math.sin(b)}};a.initLinefunction(){var ba.linenew Quark.Bitmap({image:a.Ball.images[0],regX:0,width:1,height:3,rect:[16,16,1,3]});b.alpha0.5;b.updatefunction(){var ba.mouse;this.xa.whiteBall.x;
this.ya.whiteBall.y;var gb.x-this.x,bb.y-this.y;this.rotationMath.atan2(b,g)/Math.PI*180;this.scaleXMath.sqrt(g*gb*b)-a.mouseR};a.stage.addChild(a.line)}})();(function(){function a(a,e){var bQ.createDOM(canvas,{width:4*c,height:4*c}),fb.getContext(2d);f.moveTo(c,c);f.fillStylea;f.fillRect(0,0,4*c,4*c);if(e){f.fillStyle#eee;if(e8)f.fillRect(0,0,4*c,c/3),f.fillRect(0,2*c-c/3,4*c,c/3*2),f.fillRect(0,4*c-c/3,4*c,c/3),f.arc(c2*c,c2*c,c/3*2,0,Math.PI*2),f.fill(),f.fillStylea,f.textAligncenter,f.textBaselinemiddle,f.fontcpx/1 Consolas, tahoma, Srial, helvetica, sans-serif,f.fillText(e,3*c,3*c);f.fillStyle#eee;f.beginPath();f.arc(c,
c,c/3*2,0,Math.PI*2);f.arc(3*c,3*c,c/3*2,0,Math.PI*2);f.fill();f.fillStylea;f.textAligncenter;f.textBaselinemiddle;f.fontcpx/1 Consolas, tahoma, Srial, helvetica, sans-serif;f.fillText(e,c,c);f.fillText(e,3*c,3*c)}return b.toDataURL()}function b(){for(var a!0,c0,ei.length;ce;c)i[c].v.getLength()0.01(a!1);return a}function d(){var a!1,ch.type,bh.type.length,f!1;if(b0)e.setBad();else{for(var d0;db;d)if(c[d]8){e.player.num!7?e.setLose():e.setWin();return}else c[d]
0(f!0);for(d0;db;d)!e.player.typec[d]!0?(e.initPlayerType(c[d]),f||(e.player.addScore(10),a!0),e.player.num):e.player.typec[d]?(f||(e.player.addScore(10),a!0),e.player.num):e.player.next.typec[d]e.player.next.num;console.log(e.player1.num e.player2.num);f?(e.changePlayer(),e.whiteBall.isDownQ.supportTouch?!1:!0,e.whiteBall.visible!0,e.whiteBall.updatee.Ball.prototype.checkBounds):a?e.setGood():e.setBad()}}function g(a,e){if(!a.isDie!e.isDie){var ba.v.getLength(),
fe.v.getLength();if(!(b0.1f0.1)(fa.loc.minusNew(e.loc),f.getLength()2*c)){var df.getAngle(),bMath.sin(d),dMath.cos(d);f.rotate(d,-b);a.loc.rotate(d,-b);a.v.rotate(d,-b);e.loc.rotate(d,-b);e.v.rotate(d,-b);f2*c-Math.abs(a.loc.x-e.loc.x);a.v.x0?(e.loc.x-e.v.x0?f:-f,e.loc.y-e.v.y*f/Math.abs(e.v.x)):e.v.x0?(a.loc.x-a.v.x0?f:-f,a.loc.y-a.v.y*f/Math.abs(a.v.x)):a.loc.xe.loc.x?(a.loc.x-f*0.5,e.loc.xf*0.5):(a.loc.xf*0.5,e.loc.x-f*0.5);a.loc.rotate(d,b);a.v.rotate(d,b);e.loc.rotate(d,
b);e.v.rotate(d,b);fa.loc.minusNew(e.loc);df.getAngle();bMath.sin(d);dMath.cos(d);f.rotate(d,-b);a.loc.rotate(d,-b);a.v.rotate(d,-b);e.loc.rotate(d,-b);e.v.rotate(d,-b);fa.v.x;a.v.xe.v.x;e.v.xf;a.loc.rotate(d,b);a.v.rotate(d,b);e.loc.rotate(d,b);e.v.rotate(d,b)}}}var eQ.use(BallGame),ce.r,je.lines,he.Ballfunction(a){this.num0;this.vnew Vector;this.rythis.rx0;this.constructor.superClass.constructor.call(this,a);this.heightthis.width32;this.locnew Vector(this.x,this.y);this.bitmap
new Quark.Bitmap({image:k[this.num],width:2*c,height:2*c,regX:c,regY:c,x:16,y:16,rect:[0,0,2*c,2*c],eventEnabled:!1});this.lightnew Quark.Bitmap({image:e.images.light,regX:16,regY:16,x:16,y:16,eventEnabled:!1});this.init()},ih.balls[],kh.images[];h.scale0.99;Quark.inherit(h,Quark.DisplayObjectContainer);h.prototype.initfunction(){this.addChild(this.bitmap);this.addChild(this.light);this.typethis.num0?0:this.num8?1:this.num8?8:-1};h.createBallsfunction(){for(var b[#ffffff,#E1AE07,
#064771,#D7141A,#1E1D63,#E9520B,#0A5326,#900910,#000],d0;d9;d)k[d]new Image,k[d].srca(b[d],d);for(d0;d8;d)k[d9]new Image,k[d9].srca(b[d1],d9);bMath.sqrt(3)0.1;dc;b[0,-330,0,0,-d,b*d,d,b*d,-2*d,2*b*d,0,2*b*d,2*d,2*b*d,-3*d,3*b*d,-d,3*b*d,d,3*b*d,3*d,3*b*d,-4*d,4*b*d,-2*d,4*b*d,0,4*b*d,2*d,4*b*d,4*d,4*b*d];for(d0;d16;d){var gnew h({num:d,regX:16,regY:16,x:600b[2*d1]e.offset.x,y:219b[2*d]e.offset.y});h.balls[d]g;e.stage.addChild(g)}e.whiteBalle.Ball.balls[0];
e.whiteBall.alpha1;e.stage.addChild(e.whiteBall)};h.prototype.movefunction(){this.v.getLength()0.1?(this.v.x0,this.v.y0):(this.loc.plus(this.v),this.bounce(),this.v.scale(h.scale),this.xthis.loc.x,this.ythis.loc.y,this.bitmap.setRect([this.rx,this.ry,2*c,2*c]),this.bitmap.rotationthis.v.getAngle()*180/Math.PI,this.rx-this.v.getLength(),this.checkHole())};h.prototype.updateh.prototype.move;h.prototype.checkHolefunction(){for(var ae.holePoint,c0;c6;c){var bthis.x-a[c][0]-e.offset.x,
dthis.y-a[c][1]-e.offset.y;if(b*bd*d500!this.isDie){m();this.isDie!0;this.updatethis.inHole;e.Ball.type.push(this.type);console.log(this.num);break}}};h.prototype.inHolefunction(){if(this.alpha0.1||this.scaleX0.1||this.scaleY0.1){this.updatethis.num0?null:function(){this.x4;this.bitmap.setRect([this.rx,this.ry,2*c,2*c]);this.rx-4;this.bitmap.rotation0;if(this.xe.xx)this.updatenull,this.xe.xx,e.xxthis.x-2*c};this.vnew Vector;this.alphathis.scaleYthis.scaleX1;if(this.num
0)this.visible!1;this.xe.bitmaps.ballRoad.xc;this.ye.bitmaps.ballRoad.ye.bitmaps.ballRoad.height/21}this.scaleX-0.07;this.scaleY-0.07;this.alpha-0.07};h.prototype.bouncefunction(){minxe.offset.x27-0;minye.offset.y28-0;maxxe.offset.x8180;maxye.offset.y4080;for(var a0,cj.length;ac;a)if(this.checkLine(j[a]))return;if(this.loc.xminx||this.loc.yminy||this.loc.xmaxx||this.loc.ymaxy!this.isDie)this.isDie!0,this.updatethis.inHole,e.Ball.type.push(this.type),console.log(this.num
aaaaaaaaaaaaaaaaaaaaaaaaa lose)};h.prototype.touchMovefunction(){if(e.isDown)this.updatethis.checkBounds()};h.prototype.checkBoundsfunction(){minxe.offset.x27;minye.offset.y28;maxxe.offset.x818;maxye.offset.y408;this.loc.xe.mouse.x;this.loc.ye.mouse.y;if(this.loc.xminxc)this.loc.xminxc;else if(this.loc.xmaxx-c)this.loc.xmaxx-c;if(this.loc.yminyc)this.loc.yminyc;else if(this.loc.ymaxy-c)this.loc.ymaxy-c;this.xthis.loc.x;this.ythis.loc.y;for(var a1,bi.length,dc*c*4;a
b;a){var fthis.loc.x-i[a].loc.x,gthis.loc.y-i[a].loc.y;if(f*fg*gd){this.alpha0.5;if(Q.supportTouch)e.whiteBall.isDown!1;return}}this.alpha1;if(e.whiteBall.isDowne.isDown(this.updatethis.move,this.isDie!1,e.startShoot(),!Q.supportTouch))e.isDown!1};h.prototype.checkLinefunction(a){var ca.p1.minusNew(a.p2).getAngle(),b!1,dMath.cos(c),cMath.sin(c),ge.r;this.v.getLength()g(gthis.v.getLength());a.p1.rotate(d,-c);a.p2.rotate(d,-c);this.loc.rotate(d,-c);this.v.rotate(d,-c);var h
a.p1.y,ia.p1.x,ja.p2.x;if(ij)var ki,ij,jk;var kthis.loc.y,rthis.loc.x;if(rirjkghk-gh)this.loc.ythis.v.y0?h-g:hg,this.v.y*-1,b!0;a.p1.rotate(d,c);a.p2.rotate(d,c);this.loc.rotate(d,c);this.v.rotate(d,c);return b};h.updatefunction(){if(b())e.loopfunction(){},d();else{var a,c,hi.length,f,j;a0;for(hi.length;ah-1;a)if(fi[a],f.isDief.num!0)i.splice(a,1),h--,a--;else for(ca1;ch;c)ji[c],g(f,j)}}})();(function(){var aQ.use(BallGame),ba.Numfunction(a){this.num0;aa||{};b.superClass.constructor.call(this,a);this.ida.id||Q.UIDUtil.createUID(Num);if(!this.max)this.max1;this.widththis.max*20;this.height24;this.init()};Q.inherit(b,Q.DisplayObjectContainer);b.prototype.initfunction(){this.rects[[0,0,20,24],[20,0,20,24],[40,0,20,24],[60,0,20,24],[80,0,20,24],[100,0,20,24],[120,0,20,24],[140,0,20,24],[160,0,20,24],[180,0,20,24]];for(var b0;bthis.max;b){var gthis.rects[0];this.addChild(new Q.Bitmap({image:a.images.num,
rect:g,x:(g[2]-2)*b}))}this.setValue(this.num)};b.prototype.setValuefunction(a){this.numa;for(var aa.toString(),bthis.children.length;a.lengthb;)a0a;for(b-1;b0;b--)this.getChildAt(b).setRect(this.rects[Number(a.charAt(b))])}})();(function(){function a(a,g){b.loopb.Ball.update;var eb.Ball.balls[0];e.vnew Vector(a-e.loc.x,g-e.loc.y);e.v.setLength(b.power);b.power1;b.powerV0.4;b.Ball.type[];b.cue.visible!1;b.line.visible!1;b.point.visible!1}var bQ.use(BallGame);b.initEventfunction(){var db.mouse{x:0,y:0},gb.stage;b.power1;b.powerV0.4;b.isDown!1;window.onmousemovefunction(a){d.xa.clientX;d.ya.clientY};window.onmousedownfunction(a){b.isDown!0;d.xa.clientX;d.ya.clientY};window.onmouseupfunction(){if(b.isDown
b.canShot)a(d.x,d.y),b.canShot!1;b.isDown!1};g.container.ontouchstartfunction(a){a.preventDefault();b.isDown!0};g.container.ontouchmovefunction(a){a.preventDefault();d.xa.touches[0].clientX;d.ya.touches[0].clientY};g.container.ontouchendfunction(e){e.preventDefault();if(b.isDownb.canShot)a(d.x,d.y),b.canShot!1;if(b.isDown!b.whiteBall.isDown)b.whiteBall.isDown!0;b.isDown!1}}})();(function(){var aQ.use(BallGame),ba.Playerfunction(a){this.ida;this.typenull;this.numthis.score0;this.ball{}};b.prototype.initTypefunction(a){this.typea};b.prototype.initfunction(){this.numthis.score0};b.prototype.shotfunction(b,g){var ea.Ball.balls;e[0].vb;e[0].v.setAngle(g)};a.initPlayersfunction(){var da.player1new b(1),ga.player2new b(2);d.addScorefunction(b){this.scoreb;a.score1.setValue(this.score)};g.addScorefunction(b){this.scoreb;a.score2.setValue(this.score)};
d.nextg;g.nextd;a.playerd}})();(function(){var aQ.use(BallGame);(a.ui{}).initfunction(){var ba.stage,ca.images,da.offset.x,ga.offset.y,ia.boardPlayer1new Quark.Bitmap({image:c[player-txt],rect:[0,0,175,28],eventEnabled:!1}),ca.boardPlayer2new Quark.Bitmap({image:c[player-txt],rect:[175,0,175,28],eventEnabled:!1});a.playerPos[d120,d680];i.scaleX0.6;i.scaleY0.6;i.xd20;i.yg-50;c.scaleX0.6;c.scaleY0.6;c.xd723;c.yg-50;c.alpha0.2;b.addChild(i);b.addChild(c);a.bitmaps.ball1.yg-50;a.bitmaps.ball9.yg-50};
a.initPlayerTypefunction(b){a.stage.addChild(a.bitmaps.ball1);a.stage.addChild(a.bitmaps.ball9);var ca.player;b1?(a.bitmaps.ball1.xa.playerPos[c.id-1],a.bitmaps.ball9.xa.playerPos[c.next.id-1],a.player.typeb,a.player.balla.bitmaps.ball1,a.player.next.balla.bitmaps.ball9,a.player.next.ball.alpha0.3,a.player.next.type-1):(a.bitmaps.ball9.xa.playerPos[c.id-1],a.bitmaps.ball1.xa.playerPos[c.next.id-1],a.player.balla.bitmaps.ball9,a.player.next.balla.bitmaps.ball1,a.player.next.ball.alpha
0.3,a.player.typeb,a.player.next.type1)};a.initScorefunction(b){a.Player.scoreb};a.changePlayerfunction(){a.playera.player1?(a.boardPlayer1.alpha0.2,a.score1.alpha0.2,a.boardPlayer2.alpha1,a.score2.alpha1,a.playera.player2):(a.boardPlayer2.alpha0.2,a.score2.alpha0.2,a.boardPlayer1.alpha1,a.score1.alpha1,a.playera.player1);a.player.ball.alpha1;a.player.next.ball.alpha0.3};a.initShotTxtfunction(){var ba.shotTxta.bitmaps[shot-txt];a.stage.addChild(b);b.xa.offset.x;b.ya.offset.y
100;b.alpha0};a.setGoodfunction(){var da.shotTxt;d.setRect([0,0,200,60]);Q.Tween.to(d,{x:a.offset.x330,alpha:1},{time:300,ease:Q.Easing.Quadratic.EaseIn,onComplete:function(){Q.Tween.to(d,{alpha:0,x:a.offset.x800},{time:300,delay:500,onComplete:function(){d.x0;b()}})}})};a.setBadfunction(){var da.shotTxt;d.setRect([200,0,150,60]);Q.Tween.to(d,{x:a.offset.x350,alpha:1},{time:300,ease:Q.Easing.Quadratic.EaseIn,onComplete:function(){Q.Tween.to(d,{alpha:0,x:a.offset.x800},{time:300,delay:500,
onComplete:function(){d.x0;a.changePlayer();b()}})}})};var ba.startShootfunction(){a.canShot!0;a.loopa.shoot;a.cue.visible!0;a.line.visible!0;a.point.visible!0};a.initScorefunction(){a.score1new a.Num({max:2,x:a.offset.x40,y:a.offset.y-30});a.score2new a.Num({max:2,x:a.offset.x730,y:a.offset.y-30});a.score2.alpha0.2;a.stage.addChild(a.score1);a.stage.addChild(a.score2)};a.initWinfunction(){a.winTxtnew Q.Bitmap({image:a.images.win,x:0,alpha:0,y:a.offset.y150,eventEnabled:!1});a.stage.addChild(a.winTxt)};
a.initLosefunction(){a.loseTxtnew Q.Bitmap({image:a.images.lose,x:0,alpha:0,y:a.offset.y150,eventEnabled:!1});a.stage.addChild(a.loseTxt)};a.setWinfunction(){Q.Tween.to(a.winTxt,{x:a.offset.x330,alpha:1},{time:350,ease:Q.Easing.Quadratic.EaseIn,onComplete:function(){a.cue.visible!1;a.line.visible!1;a.point.visible!1;a.loopfunction(){}}})};a.setLosefunction(){Q.Tween.to(a.loseTxt,{x:a.offset.x290,alpha:1},{time:350,ease:Q.Easing.Quadratic.EaseIn,onComplete:function(){a.cue.visible!1;a.line.visible
!1;a.point.visible!1;a.loopfunction(){};for(var b0,ca.Ball.balls.length;bc;b)setTimeout(function(b){a.Ball.balls[b].updatea.Ball.prototype.inHole},b*2E3,b)}})};var d0,g5;window.mfunction(){Q.Tween.to(a.stage,{x:g},{time:10,onComplete:function(){Q.Tween.to(a.stage,{x:-g},{time:20,onComplete:function(){Q.Tween.to(a.stage,{x:0},{time:10,onComplete:function(){d;g-1;d2?m():d0}})}})}})}})();Ball.py源码
#coding utf-8
import math
class Vector():def __init__(self, x 0, y 0):self.x xself.y ydef __str__(self):return x:%10f, y:%10f % (self.x, self.y)__repr__ __str__def __add__(self, other):return Vector(self.x other.x, self.y other.y)def __sub__(self, other):return Vector(self.x - other.x, self.y - other.y)def set(self, x, y):self.x x;self.y y;def scale(self, s):self.x * sself.y * sdef getLength(self):return round(math.sqrt(self.x * self.x self.y * self.y), 6)def getAngle(self):return round(math.atan2(self.y, self.x), 6)def rotate(self, *arg):if len(arg) 1:cos math.cos(arg[0])sin math.sin(arg[0])else:cos arg[0]sin arg[1]self.set(self.x * cos - self.y * sin, self.x * sin self.y * cos)holePoints [[26, 25],[421, 17],[817, 23],[820, 407],[422, 416],[26, 408]]; def createLines(m):points [[27.1, 52.7 - m, 27.1, 383.5 m],[52.4 - m, 408.9, 397.1 m, 408.9],[448 - m, 408.9, 793 m, 408.9],[818.5, 383.6 m, 818.5, 52.9 -m],[793.1 m, 27.5, 447.9 - m, 27.5],[397.1 m, 27.5, 52.5 - m, 27.5],];lines []for point in points:line [Vector(point[0], point[1]), Vector(point[2], point[3])]lines.append(line)return lineslines createLines(2)r 14
(SOLID, STRIP, WHITE, BLACK) [1, -1, 0, 2]class Ball(object):total 0balls []dies []scale .99def __str__(self):return str(self.loc) , num:%2d, type:%2d, v: ( % (self.num, self.type) str(self.v) )__repr__ __str__def __del__(self):Ball.total - 1def __init__(self, x 0, y 0):colors [#ffffff, #E1AE07, #064771, #D7141A, #1E1D63, #E9520B, #0A5326, #900910, #000000, #E1AE07, #064771, #D7141A, #1E1D63, #E9520B, #0A5326, #900910];Ball.total 1Ball.balls.append(self)self.loc Vector(x, y)self.num Ball.total - 1self.col colors[self.num]self.setType(self.num)self.v Vector()self.isDie Falseself.rect Nonedef setType(self, num):if num 0:self.type WHITEelif num 8:self.type SOLIDelif num 8:self.type BLACKelse :self.type STRIPdef move(self):if self.v.getLength() .1:self.v.set(0, 0)returnself.loc self.vself.bounce()self.v.scale(Ball.scale)self.checkHole()def destory(self):self.isDie TrueBall.dies.append(self)Ball.balls.remove(self)print(deleteeeeeeeeeeeeeeeeee %2d % self.num)def checkHole(self):for hole in holePoints:lx self.loc.x - hole[0]ly self.loc.y - hole[1]if lx*lx ly*ly 300 and (not self.isDie):self.destory()return Truereturn Falsedef bounce(self):a 0minx 27 - aminy 28 - amaxx 818 amaxy 408 afor line in lines:if self.checkLine(line):returnif self.loc.x minx or self.loc.y miny or self.loc.x maxx or self.loc.y maxy and (not self.isDie):self.destory()returndef checkLine(self, line):ang (line[0] - line[1]).getAngle()cos math.cos(ang)sin math.sin(ang)temp Falsenr rif(self.v.getLength() r):nr self.v.getLength()line[0].rotate(cos, -sin)line[1].rotate(cos, -sin)self.loc.rotate(cos, -sin)self.v.rotate(cos, -sin)y line[0].yx1 line[0].xx2 line[1].xif x1 x2:xx x1x1 x2x2 xxby self.loc.ybx self.loc.xvy self.v.yif bx x1 and bx x2 and (by nr y and by - nr y):self.loc.y y - r if self.v.y 0 else y rself.v.y * -1temp Trueline[0].rotate(cos, sin)line[1].rotate(cos, sin)self.loc.rotate(cos, sin)self.v.rotate(cos, sin)return tempdef isStop():temp Truefor ball in Ball.balls:if ball.v.getLength() .01:temp Falsereturn temp def createBalls():a3 math.sqrt(3).1;ar r;ballxy [0, -330, 0, 0, -ar,a3*ar,ar,a3*ar,-2*ar,2*a3*ar,0,2*a3*ar,2*ar,2*a3*ar,-3*ar,3*a3*ar,-ar,3*a3*ar,ar,3*a3*ar,3*ar,3*a3*ar,-4*ar,4*a3*ar,-2*ar,4*a3*ar,0,4*a3*ar,2*ar,4*a3*ar,4*ar,4*a3*ar];for i in range(16):ball Ball(600 ballxy[2*i1], 219ballxy[2*i])def checkCollision(b0, b1):if b0.isDie or b1.isDie or (b0.v.getLength().1 and b1.v.getLength().1):returns b0.loc - b1.locif s.getLength() 2 * r :ang s.getAngle()cos math.cos(ang)sin math.sin(ang)s.rotate(cos, -sin)b0.loc.rotate(cos, -sin)b0.v.rotate(cos, -sin)b1.loc.rotate(cos, -sin)b1.v.rotate(cos, -sin)s 2 * r - abs(b0.loc.x - b1.loc.x)if b0.loc.x b1.loc.x:b0.loc.x - s * .5b1.loc.x s * .5else :b0.loc.x s * .5b1.loc.x - s * .5tempv b0.v.xb0.v.x b1.v.xb1.v.x tempvb0.loc.rotate(cos, sin)b0.v.rotate(cos, sin)b1.loc.rotate(cos, sin)b1.v.rotate(cos, sin)b1.loc b1.vb0.loc b0.vdef updateBalls():if isStop():returnfor b in Ball.balls:b.move()for i in range(len(Ball.balls)):for j in range(i 1, len(Ball.balls)):checkCollision(Ball.balls[i], Ball.balls[j])def checkDies(player, falseNone):good falsefor b in Ball.dies:if b.type BLACK:if player.num 7:print(win)else:print(lose)elif b.type WHITE:passelif not player.type:player.type b.typegood Trueplayer.num 1print(select type)elif player.type b.type:good Trueplayer.num 1 elif player.type ! b.type:player.next.num 1if good:passelse:passcreateBalls()def shoot(x 0, y 0):Ball.dies []Ball.balls[0].v.set(x, y)while not isStop():updateBalls()printBalls()def printBalls():print()for ball in Ball.balls:print(ball)run.py源码
from tkinter import Tk
from Tkinter import *
from Ball import *class Game(Frame):def __init__(self,masterNone, *args, **kwargs):Frame.__init__(self, master)self.master masterself.cv Canvas(master,width 847,height 438)self.cv.pack()def run(self): updateBalls()for b in Ball.balls:b.rect self.cv.create_oval((b.loc.x - r, b.loc.y - r,b.loc.x r, b.loc.y r), fill b.col)for l in lines:self.cv.create_line((l[0].x, l[0].y, l[1].x, l[1].y), fill #000000)self.after(250, self.display)def display(self):updateBalls()for b in Ball.balls:self.cv.coords(b.rect, (b.loc.x - r, b.loc.y - r,b.loc.x r, b.loc.y r))for b in Ball.dies:self.cv.coords(b.rect, (0, 0, 0, 0))Ball.dies.remove(b)self.after(10,self.display)def createLines(m):points [[8.7, 34.2, 27.1, 52.7],[27.1, 52.7 - m, 27.1, 383.5 m],[27.1, 383.5, 8.7, 402],[34.2, 427.4, 52.4, 408.9],[52.4 - m, 408.9, 397.1 m, 408.9],[397.1, 408.9, 407.2, 429.7],[437.9, 429.7, 448, 408.9],[448 - m, 408.9, 793 m, 408.9],[793, 408.9, 811.4, 427.5],[837, 402.3, 818.5, 383.6],[818.5, 383.6 m, 818.5, 52.9 -m],[818.5, 52.9, 837, 34.4],[811.6, 9.1, 793.1, 27.1],[793.1 m, 27.5, 447.9 - m, 27.5],[447.9, 27.5, 437.9, 6.6],[407.3, 6.6, 397.1, 27.5],[397.1 m, 27.5, 52.5 - m, 27.5],[52.5, 27.5, 34.1, 9] ];lines []for point in points:line [Vector(point[0], point[1]), Vector(point[2], point[3])]lines.append(line)return lines root Tk()
game Game(root)#Ball.scale 1
lines createLines(2)
Ball.balls[0].v.set(20, 0)
game.run()
game.mainloop()注意
由于博客字数限制本篇文章只展示了部分代码。本项目的完整代码及素材包关注私信我获取