JavaScript

语言:

JaveScriptBabelCoffeeScript

确定

var canvas, stage;

var multipler = 0.2;

var speed = 1500;

var gravity = 700;

var pits = [];

var isDown = false;

var container;

var reaction = null;

var armMovement = 14;

var armMovement2 = 10;

var star = null;

var effect = "clapping";

function init() {

canvas = document.getElementById("canvas");

avocado = new lib.AvocadoMC();

stage = new createjs.Stage(canvas);

container = new createjs.Container();

inner = new createjs.Container();

container.addChild(avocado);

container.width = window.innerWidth;

container.height = window.innerHeight;

container.regX = container.width >> 1;

container.regY = container.height >> 1;

avocado.x = container.regX;

avocado.y = container.regY;

ogX = avocado.body.x;

ogY = avocado.body.y;

legPosX = avocado.leftLeg.x;

legPos2X = avocado.rightLeg.x;

eyePosX = avocado.leftEye.x;

eyePos2X = avocado.rightEye.x;

sweatPosX = avocado.sweat.x;

avocado.sweat.visible = false;

instructions = new lib.Arrow();

stage.addChild(container, instructions);

//Registers the "tick" event listener.

createjs.Ticker.setFPS(lib.properties.fps);

createjs.Ticker.addEventListener("tick", tick);

container.scaleX = container.scaleY = 0.70;

instructions.x = avocado.x + 407 * container.scaleX;

instructions.y = container.height >> 1;

handleResize();

createBG();

stage.update();

setTimeout(function() {

}, 3000)

var velX = stage.mouseX - avocado.x;

var velY = stage.mouseY - avocado.y;

angle = Math.atan2(velY, velX) * 180 / Math.PI;

loadAssets();

}

function loadAssets() {

manifest = [{

src: "https://s3-us-west-2.amazonaws.com/s.cdpn.io/1524180/grunt.mp3",

id: "grunt"

}, {

src: "https://s3-us-west-2.amazonaws.com/s.cdpn.io/1524180/clapping.mp3",

id: "clapping"

}, {

src: "https://s3-us-west-2.amazonaws.com/s.cdpn.io/1524180/pop.mp3",

id: "pop"

}, {

src: "https://s3-us-west-2.amazonaws.com/s.cdpn.io/1524180/booing.mp3",

id: "booing"

}]

loader = new createjs.LoadQueue(true);

loader.installPlugin(createjs.Sound);

loader.addEventListener("complete", handleComplete);

loader.loadManifest(manifest);

}

function handleComplete() {

//This function is always called, irrespective of the content. You can use the variable "stage" after it is created in token create_stage.

stage.addEventListener("stagemousedown", handleDown);

stage.addEventListener("stagemouseup", handleUp);

stage.addEventListener("stagemousemove", handleMove);

window.addEventListener("resize", handleResize);

}

function hideBG() {

if (star == null) {

return;

}

createjs.Tween.get(star).to({

alpha: 0,

scaleX: 0,

scaleY: 0

}, 500);

}

function createBG() {

var s = new createjs.Shape().set({

x: 400,

y: 400

});

s.graphics.rf(["#F3F5D0", "#FFFFCC"], [0, 1], 0, 0, 100, 0, 0, 800);

star = starburst(s, 800, 20);

star.x = canvas.width >> 1;

star.y = canvas.height >> 1;

stage.addChildAt(star, 0);

star.alpha = 0;

star.scaleX = star.scaleY = 0;

}

function showBG() {

createjs.Tween.get(star).to({

alpha: 1,

scaleX: 1,

scaleY: 1

}, 1000).call(function() {

createjs.Tween.get(star, {

loop: true

}).to({

rotation: 360

}, 25000);

})

}

function starburst(s, radius, rays) {

var seg = 360 / (rays * 2) * Math.PI / 180;

var g = s.graphics;

for (var i = 0; i < rays; i++) {

var a = i * 2 * seg;

g.mt(0, 0)

.lt(Math.cos(a) * radius, Math.sin(a) * radius)

.lt(Math.cos(a + seg) * radius, Math.sin(a + seg) * radius)

.lt(0, 0);

}

return s;

}

function handleDown(event) {

if (reaction != null) {

reaction.stop();

}

hideBG();

if (instructions.visible == true) {

createjs.Tween.get(instructions).to({

alpha: 0

}, 500).call(function() {

instructions.visible = false;

});

}

grunt = createjs.Sound.play("grunt", {

loop: -1

});

isDown = true;

}

function handleUp(event) {

grunt.stop();

createjs.Sound.play("pop");

effect = "clapping";

if (multipler < 0.5) {

effect = "booing";

} else {

showBG();

}

reaction = createjs.Sound.play(effect, {

loop: 0

});

avocado.pit.visible = false;

shoot();

isDown = false;

multipler = 0.2;

armMovement = 14;

armMovement2 = 10;

}

function handleMove(event) {

var velX = stage.mouseX - avocado.x;

var velY = stage.mouseY - avocado.y;

angle = Math.atan2(velY, velX) * 180 / Math.PI;

}

function updatePower() {

if (isDown) {

multipler = Math.min(1, multipler + 0.03);

armMovement = Math.min(5, armMovement - 0.01);

armMovement2 = Math.min(5, armMovement2 - 0.01);

}

updateAvocado();

}

function shoot() {

var pit = new lib.Pit();

pit.scaleX = pit.scaleY = container.scaleX;

pit.scaleX *= -1;

pit.scaleY *= -1

pit.x = avocado.x;

pit.y = avocado.y;

pit.vx = pit.vy = 0;

pit.speed = speed * multipler;

var rad = angle / 180 * Math.PI;

pit.vx = Math.cos(rad);

pit.vy = Math.sin(rad);

pit.vx *= pit.speed;

pit.vy *= pit.speed;

pits.push(pit);

stage.addChild(pit);

}

function tick(event) {

avocado.scaleX = (stage.mouseX < canvas.width >> 1) ? 1 : -1;

updatePower();

for (var i = 0; i < pits.length; i++) {

var b = pits[i];

var bounds = {

width: 152.05,

height: 203.70,

x: 0,

y: -26

};

var floor = (canvas.height + bounds.height / 2) - 35;

b.x += b.vx * (event.delta / 1000);

b.y += b.vy * (event.delta / 1000);

b.rotation = Math.atan2(b.vy, b.vx) * 180 / Math.PI;

b.vy += gravity * (event.delta / 1000);

if (b.y > floor || b.x > canvas.width) {

removeBullet(i);

}

}

stage.update(event);

}

function updateAvocado() {

var distance = Math.random() * 100;

var distance1 = -Math.random() * 100;

if (isDown) {

avocado.body.x = ogX + Math.random() * 5;

avocado.body.y = ogY + Math.random() * 2;

avocado.leftEye.gotoAndStop(1);

avocado.rightEye.gotoAndStop(1);

avocado.sweat.visible = true;

avocado.mouth.gotoAndStop(1);

avocado.leftLeg.x = legPosX + Math.random() * 2;

avocado.sweat.x = sweatPosX + Math.random() * 5;

avocado.rightLeg.x = legPos2X + Math.random() * 2;

avocado.leftEye.x = eyePos2X + Math.random() * 2;

avocado.rightEye.x = eyePosX + Math.random() * 2;

avocado.leftArm.rotation += (distance - avocado.leftArm.rotation) / armMovement;

avocado.rightArm.rotation += (distance1 - avocado.rightArm.rotation) / armMovement2;

} else {

avocado.body.x = ogX;

avocado.body.y = ogY;

avocado.sweat.visible = false;

avocado.sweat.x = sweatPosX;

avocado.leftEye.gotoAndStop(0);

avocado.rightEye.gotoAndStop(0);

avocado.mouth.gotoAndStop(effect == "booing" ? 2 : 0);

avocado.leftLeg.x = legPosX;

avocado.rightLeg.x = legPos2X;

avocado.leftEye.x = eyePos2X;

avocado.rightEye.x = eyePosX;

avocado.leftArm.rotation += (0 - avocado.leftArm.rotation) / 5;

avocado.rightArm.rotation += (0 - avocado.rightArm.rotation) / 5;

}

}

function removeBullet(index) {

avocado.pit.visible = true;

stage.removeChild(pits[index]);

pits.splice(index, 1);

}

function handleResize(event) {

canvas.width = window.innerWidth;

canvas.height = window.innerHeight;

container.width = window.innerWidth;

container.height = window.innerHeight;

container.regX = container.width >> 1;

container.regY = container.height >> 1;

container.x = canvas.width >> 1;

container.y = canvas.height >> 1;

avocado.x = container.regX;

avocado.y = container.regY;

if (star != null) {

star.x = avocado.x;

star.y = avocado.y;

}

instructions.x = avocado.x + 407 * container.scaleX;

instructions.y = container.height >> 1;

stage.update();

}

init();

html5+植物大战僵尸,HTML5 Canvas植物大战僵尸 - 鳄梨射手相关推荐

  1. 植物大战僵尸HTML5源码

    提供国人写的强大的html5植物大战僵尸(源码) 写得很棒~占用资源少. JSPVZ 程序制作进度(2011.1.5) 本程序提供源码由HTML5中文网整理打包下载,该下载包可以使用服务器环境运行,也 ...

  2. java小项目之:植物大战僵尸,这个僵尸不太冷!内附素材源码

    Java小项目之:植物大战僵尸! <植物大战僵尸>是由PopCap Games开发的一款益智策略类单机游戏,于2009年5月5日发售,这款游戏可谓是无人不知无人不晓. 在我身边,上到40岁 ...

  3. java植物僵尸_Java小项目之:植物大战僵尸,这个僵尸不太冷!内附素材

    Java小项目之:植物大战僵尸! <植物大战僵尸>是由PopCap Games开发的一款益智策略类单机游戏,于2009年5月5日发售,这款游戏可谓是无人不知无人不晓. 在我身边,上到40岁 ...

  4. 我是一只小僵尸java,Java小项目之:植物大战僵尸,这个僵尸不太冷!内附素材...

    Java小项目之:植物大战僵尸! <植物大战僵尸>是由PopCap Games开发的一款益智策略类单机游戏,于2009年5月5日发售,这款游戏可谓是无人不知无人不晓. 在我身边,上到40岁 ...

  5. java设计建议植物大战僵尸_基于Java的游戏设计之植物大战僵尸

    植物大战僵尸这款游戏相信大家或多或少都玩过,那么大家有没有想过自己尝试着做一下植物大战僵尸的游戏设计呢.本文将基于Java语言为大家展示如何开发出植物大战僵尸游戏的简易版本,主要内容包括规则.对象.功 ...

  6. java植物大战僵尸_植物大战僵尸java游戏

    [实例简介] 植物大战僵尸java游戏植物大战僵尸java游戏植物大战僵尸java游戏 [实例截图] [核心代码] baisixue19870221_10036231 └── 植物大战僵尸 ├── p ...

  7. 植物大战僵尸html2手机版,植物大战僵尸魔幻版

    植物大战僵尸魔幻版:这是一款由经典游戏改编而来的休闲策略类游戏.游戏完美的继承了经典的植物大战僵尸的玩法,但在这的基础上,通过自己的魔改来为这款游戏增添了不少的趣味.游戏中有着大量的关卡可以挑战,游戏 ...

  8. 植物大战僵尸java圣诞版,植物大战僵尸圣诞版-植物大战僵尸2圣诞节版v1.9.1 安卓版-腾牛安卓网...

    植物大战僵尸2圣诞节版是一款经典的塔防类手机休闲游戏,要考验玩家的脑力,还有丰富的想象力,将不同功能的植物组合在一起玩抗击僵尸,圣诞版到来,僵尸也换上新衣服,变的更加强力,快用你植物进行反击吧. 官方 ...

  9. 兼容MacOS10.15以上系统的植物大战僵尸_植物大战僵尸mac版

    以前的植物大战僵尸Mac版的都不能在MacOS10.15以上系统玩了.今天为大家带来完美兼容MacOS10.15以上系统的植物大战僵尸,我们可以放心的macOS 10.15系统以上的玩耍了. 以前的植 ...

最新文章

  1. linux tomcat 安装教程,关于Linux下配置安装Tomcat8的步骤
  2. Java反序列化漏洞整理
  3. 修改进程权限(转载)
  4. webscoket绑定php uid,Think-Swoole之WebSocket客户端消息解析与使用SocketIO处理用户UID与fd关联...
  5. 成功更新至Win8.1 update
  6. IDEA @Override is not allowed when implementing interface method(转载)
  7. 洛谷 P1757 通天之分组背包
  8. Read Excel
  9. kotlin 函数和 Lambda 表达式
  10. 72000oracle,oracle 使用入门到放弃errorCode 1017, state 72000 java.sql.SQLException: ORA-01017:...
  11. MATLAB【函数求导与积分】
  12. 爬取微博评论并存入MySQL,并对评论进行情感分析以及词云的绘制
  13. chrome无法访问商店,打不开网页怎么办,五步轻松解决
  14. vue3.0+vite跑项目遇到的问题
  15. 狗年已到,今天送3万元红包,本文有4个答案
  16. java任意音频格式转换MP3格式
  17. 程序员遇到人生低谷期怎么做?
  18. 浅谈sstream头文件
  19. 局域网访问电脑中VMware虚拟机
  20. c#中文件路径出现非法字符怎么办?解决也容易

热门文章

  1. 学生积分管理系统改进-python
  2. 已经提了离职,还有一周就走,公司突然把我移出企业微信,没法考勤打卡, 还要继续上班吗?...
  3. 还在找icon吗,这里有你想要的一切!!!
  4. z-index使用以及失效的处理方法
  5. HBase 2.0 API 初步窥探
  6. python函数运行加速
  7. 不得不了解的 iOS 15.4 beta 新特性
  8. MP4测试视频URL地址分享,亲测有效。可用于测试HTML5播放器效果。
  9. ftl和html的区别?
  10. keilU5中.lib文件的生成与调用