processing实现带音效小动物加农炮发射距离比拼小游戏代码
代码语言:html
所属分类:游戏
代码描述:processing实现带音效小动物加农炮发射距离比拼小游戏代码,左右键控制大炮发射角度,空格键发射。还可以选择不同的小动物,看看谁飞的更远。
代码标签: processing 音效 小动物 加农炮 发射 距离 比拼 小游戏 代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<style>
* {
margin: 0;
box-sizing: border-box;
overflow: hidden;
}
body {
background: #367396;
width: 100%;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
body canvas {
box-shadow: 0.2em 0.2em 2em #0008;
border: none;
outline: none;
}
</style>
</head>
<body translate="no">
<canvas id="canvas"></canvas>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/processing.1.4.8.js"></script>
<audio id="explosive" src="//repo.bfw.wiki/bfwrepo/sound/66d12ba103e33.mp3" preload="auto"></audio>
<audio id="bomb" src="//repo.bfw.wiki/bfwrepo/sound/66d12bc052e2d.mp3" preload="auto"></audio>
<audio id="trampoline" src="//repo.bfw.wiki/bfwrepo/sound/66d12beddd4aa.mp3" preload="auto"></audio>
<audio id="mud" src="//repo.bfw.wiki/bfwrepo/sound/66d12c0b1fae4.mp3" preload="auto"></audio>
<audio id="flytrap" src="//repo.bfw.wiki/bfwrepo/sound/66d12c51e76a0.mp3" preload="auto"></audio>
<audio id="fire" src="//repo.bfw.wiki/bfwrepo/sound/66d12b86d190c.mp3" preload="auto"></audio>
<audio id="ground" src="//repo.bfw.wiki/bfwrepo/sound/66d12b76b704b.mp3" preload="auto"></audio>
<script>
var sketchProc = function(processingInstance) {
with (processingInstance) {
size(900, 600);
frameRate(60);
smooth();
textFont(createFont("Trebuchet MS"));
var game;
var Button = function(args) {
this.x = args.x;
this.y = args.y;
this.w = args.w || 120;
this.h = args.h || 50;
this.content = args.content;
this.func = args.func;
this.enabled = args.enabled || false;
};
Button.prototype = {
over: function() {
return (mouseX > this.x &&
mouseX < this.x + this.w &&
mouseY > this.y &&
mouseY < this.y + this.h);
},
draw: function() {
noStroke();
if(this.enabled && this.over()) {
game.hover = true;
fill(69, 66, 69);
}
else {
fill(46, 47, 48);
}
//Draw the button
rect(this.x, this.y, this.w, this.h);
//Draw the text on the button
pushStyle();
textAlign(CENTER, CENTER);
textSize(18);
fill(255);
text(this.content, this.x + this.w / 2, this.y + this.h / 2);
popStyle();
//If the mouse was clicked and the mouse was over the button
if(this.enabled && game.clicked && this.over()) {
//Run the function
this.func();
}
}
};
//Transition object (between scenes)
var Transition = function() {
this.h = 0;
this.vy = 15;
this.active = false;
this.scene = "home";
this.reset = function() {
this.h = 0;
this.vy = 15;
};
this.draw = function() {
if(this.active) {
pushStyle();
fill(64, 57, 59);
rect(-20, -20, width + 40, this.h);
rect(-20, height-this.h, width + 40, this.h + 20);
popStyle();
}
};
this.update = function() {
if(this.active) {
this.h+= this.vy;
//if halfway across the screen then change the scene
if(this.h >= 300) {
game.scene = this.scene;
this.vy*= -1;
}
//else if it's completely off the screen reset it and set to inactive
else if(this.h < 0) {
this.reset();
this.active = false;
}
}
};
this.run = function() {
this.draw();
this.update();
};
};
var Block = function(args) {
this.x = args.x || 0;
this.y = args.y || 0;
this.w = args.w || 100;
this.h = args.h || this.w;
this.vx = args.vx || 0;
this.vy = args.vy || 0;
};
Block.new = function(args) {
var obj = Object.create(Block.prototype);
Block.apply(obj, arguments);
return obj;
};
Block.prototype = {
move: function() {
this.x += this.vx;
this.y += this.vy;
},
draw: function() {
pushStyle();
noStroke();
fill(194, 91, 81);
rect(this.x, this.y, this.w, this.h);
popStyle();
},
go: function() {
this.draw();
this.move();
}
};
var Trampoline = function(args) {
this.x = args.x || 0;
this.y = args.y || 0;
this.w = args.w || 100;
this.h = args.h || this.w;
// this.vx = args.vx || 0;
// this.vy = args.vy || 0;
this.dead = false;
};
Trampoline.new = function(args) {
var obj = Object.create(Trampoline.prototype);
Trampoline.apply(obj, arguments);
return obj;
};
Trampoline.prototype = {
draw: function() {
pushStyle();
noStroke();
fill(194, 91, 81);
//legs
//front left
rect(this.x + this.w * 0.12, this.y + this.h * 0.8, this.w * 0.08, this.h * 0.8);
//front right
rect(this.x + this.w * 0.8, this.y + this.h * 0.8, this.w * 0.08, this.h * 0.8);
//back left
rect(this.x + this.w * 0.01, this.y + this.h * 0.6, this.w * 0.08, this.h * 0.8);
//back right
rect(this.x + this.w * 0.91, this.y + this.h * 0.6, this.w * 0.08, this.h * 0.8);
//main body
fill(80, 222, 201);
ellipse(this.x + this.w * 0.5, this.y + this.h * 0.5, this.w * 1.1, this.h * 1.1);
fill(79, 82, 82);
ellipse(this.x + this.w * 0.5, this.y + this.h * 0.40, this.w * 0.90, this.h * 0.55);
// noFill();
// stroke(0);
// rect(this.x, this.y, this.w, this.h);
popStyle();
},
update: function() {
// this.x += this.vx;
// this.y += this.vy;
},
go: function() {
this.draw();
this.update();
}
};
var Mud = function(args) {
this.x = args.x || 0;
this.y = args.y || 0;
this.w = args.w || 100;
this.h = args.h || this.w;
this.dead = false;
};
Mud.new = function(args) {
var obj = Object.create(Mud.prototype);
Mud.apply(obj, arguments);
return obj;
};
Mud.prototype = {
draw: function() {
pushMatrix();
translate(this.x, this.y);
pushStyle();
noStroke();
// fill(120, 96, 60);
// ellipse(this.w * 1.2, this.h * 1.2, this.w * 0.4, this.h * 0.7);
// ellipse(-this.w * 0.3, this.h * 1.3, this.w * 0.4, this.h * 0.6);
// ellipse(this.w * 0.2, this.h * 2.0, this.w * 0.4, this.h * 0.6);
fill(97, 72, 26);
ellipse(this.w * 0.5, this.h * 0.8, this.w * 1.6, this.h * 1.8);
fill(120, 106, 44);
ellipse(this.w * 0.5, this.h * 0.7, this.w * 1.4, this.h * 1.4);
fill(102, 80, 45);
ellipse(this.w * 0.5, this.h * 0.7, this.w * 1, this.h * 1);
fill(120, 106, 44);
ellipse(this.w * 0.4, this.h * 0.6, this.w * 0.4, this.h * 0.5);
popStyle();
popMatrix();
},
update: function() {
// this.x += this.vx;
// this.y += this.vy;
},
go: function() {
this.draw();
this.update();
}
};
var Bomb = function(args) {
this.x = args.x || 0;
this.y = args.y || 0;
this.w = args.w || 100;
this.h = args.h || this.w;
this.dead = false;
};
Bomb.new = function(args) {
var obj = Object.create(Bomb.prototype);
Bomb.apply(obj, arguments);
return obj;
};
Bomb.prototype = {
draw: function() {
pushMatrix();
translate(this.x, this.y);
pushStyle();
//balloon
stroke(50);
strokeWeight(1);
fill(227, 93, 88);
ellipse(0, -this.h * 1.5, this.w, this.h * 1.1);
//shadow on balloon
pushMatrix();
translate(-this.w * 0.25, -this.h * 1.7);
rotate(radians(35));
noStroke();
fill(242, 242, 242, 200);
ellipse(0, 0, this.w * 0.2, this.h * 0.3);
popMatrix();
//string connecting the bomb to the balloon
stroke(50);
line(0, -this.h, 0, 0);
//bomb
pushMatrix();
rotate(radians(-25));
fill(148, 145, 148);
beginShape();
vertex(-this.w * 0.4, -this.h * 0.2);
vertex( this.w * 0.3, -this.h * 0.2);
vertex( this.w * 0.4, -this.h * 0.1);
vertex( this.w * 0.5, -this.h * 0.2);
vertex( this.w * 0.6, -this.h * 0.2);
vertex( this.w * 0.6, this.h * 0.2);
vertex( this.w * 0.5, this.h * 0.2);
vertex( this.w * 0.4, this.h * 0.1);
vertex( this.w * 0.3, this.h * 0.2);
vertex(-this.w * 0.4, this.h * 0.2);
bezierVertex(-this.w * 0.55, this.h * 0.1, -this.w * 0.55, -this.h * 0.1, -this.w * 0.4, -this.h * 0.2);
endShape();
//string around bomb
line(this.w * 0.1, -this.h * 0.2, this.w * 0.05, this.h * 0.2);
//words on bomb
textSize(12);
fill(0);
text("BOMB", -this.w * 0.34, this.h * 0.09);
popMatrix();
popStyle();
popMatrix();
},
update: function() {
// this.x += this.vx;
this.y += game.sin(radians(frameCount * 2)) * 0.4;
},
go: function() {
this.draw();
this.update();
}
};
var Explosive = function(args) {
this.x = args.x || 0;
this.y = args.y || 0;
this.w = args.w || 100;
this.h = args.h || this.w;
this.dead = false;
};
Explosive.new = function(args) {
var obj = Object.create(Explosive.prototype);
Explosive.apply(obj, arguments);
return obj;
};
Explosive.prototype = {
draw: function() {
pushMatrix();
translate(this.x, this.y);
pushStyle();
//barrel
stroke(38, 38, 38);
strokeWeight(1);
fill(120, 119, 120);
beginShape();
vertex(0, 0);
vertex(this.w * 0.5, 0);
vertex(this.w * 0.5, this.h);
bezierVertex(this.w * 0.3, this.h * 1.1, this.w * 0.2, this.h * 1.1, 0, this.h);
endShape(CLOSE);
ellipse(this.w * 0.25, 0, this.w * 0.5, this.h * 0.15);
bezier(0, this.h * 0.3, this.w * 0.15, this.h * 0.41, this.w * 0.35, this.h * 0.41, this.w * 0.5, this.h * 0.3);
bezier(0, this.h * 0.7, this.w * 0.15, this.h * 0.81, this.w * 0.35, this.h * 0.81, this.w * 0.5, this.h * 0.7);
//hole in top of barrel
noStroke();
fill(41, 40, 41);
ellipse(this.w * 0.15, 0, this.w * 0.15, this.h * 0.05);
//skull and cross bones on barrel
stroke(66, 63, 63);
strokeWeight(3);
line(this.w * 0.1, this.h * 0.5, this.w * 0.4, this.h * 0.75);
line(this.w * 0.1, this.h * 0.75, this.w * 0.4, this.h * 0.5);
strokeWeight(1);
noStroke();
ellipse(this.w * 0.1, this.h * 0.5, 5, 7);
ellipse(this.w * 0.4, this.h * 0.75, 5, 7);
ellipse(this.w * 0.1, this.h * 0.75, 5, 7);
ellipse(this.w * 0.4, this.h * 0.5, 5, 7);
ellipse(this.w * 0.25, this.h * 0.3, this.w * 0.3, this.h * 0.3);
ellipse(this.w * 0.25, this.h * 0.4, this.w * 0.2, this.h * 0.3);
fill(156, 153, 156);
ellipse(this.w * 0.2, this.h * 0.3, this.w * 0.06, this.h * 0.10);
ellipse(this.w * 0.3, this.h * 0.3, this.w * 0.06, this.h * 0.10);
//TNT
randomSeed(100);
stroke(40);
fill(219, 89, 57);
for(var i = 0; i < 10; i++) {
pushMatrix();
rotate(radians(random(-5, 5)));
rect(random(this.w * 0.5, this.w * 0.9), random(-this.h * 0.1, this.h * 0.05), this.w * 0.08, this.h * 0.4);
popMatrix();
}
//TNT box
stroke(40);
fill(200, 140, 115);
rect(this.w * 0.5, this.h * 0.3, this.w * 0.5, this.h * 0.7);
line(this.w * 0.5, this.h * 0.65, this.w, this.h * 0.65);
fill(36, 35, 36);
textSize(14);
textAlign(CENTER);
text("TNT", this.w * 0.75, this.h * 0.6);
text("TNT", this.w * 0.75, this.h * 0.95);
popStyle();
popMatrix();
},
update: function() {
// this.x += this.vx;
// this.y += this.vy;
},
go: function() {
this.draw();
this.update();
}
};
var FlyTrap = function(args) {
this.x = args.x || 0;
this.y = args.y || 0;
this.w = args.w || 100;
this.h = args.h || this.w;
this.angle = 20;
this.eat = false;
this.dead = false;
this.color = color(108, 158, 27);
};
FlyTrap.new = function(args) {
var obj = Object.create(FlyTrap.prototype);
FlyTrap.apply(obj, arguments);
return obj;
};
FlyTrap.prototype = {
draw: function() {
pushMatrix();
translate(this.x, this.y);
pushStyle();
//main stem
strokeWeight(7);
stroke(50);
bezier(0, this.h * 0.48, this.w * 0.25, this.h * 0.7, -this.w * 0.25, this.h * 0.8, 0, this.h * 1.1);
strokeWeight(5);
stroke(108, 158, 27);
bezier(0, this.h * 0.48, this.w * 0.25, this.h * 0.7, -this.w * 0.25, this.h * 0.8, 0, this.h * 1.1);
//branches
fill(108, 158, 27);
strokeWeight(3);
stroke(50);
bezier(0, this.h * 0.7, -this.w * 0.2, this.h * 0.7, -this.w * 0.4, this.h * 0.7, -this.w * 0.5, this.h * 0.9);
bezier(0, this.h * 0.8, this.w * 0.2, this.h * 0.8, this.w * 0.4, this.h * 0.7, this.w * 0.5, this.h * 0.95);
fill(108, 158, 27);
strokeWeight(2);
stroke(108, 158, 27);
bezier(0, this.h * 0.7, -this.w * 0.2, this.h * 0.7, -this.w * 0.4, this.h * 0.7, -this.w * 0.5, this.h * 0.9);
bezier(0, this.h * 0.8, this.w * 0.2, this.h * 0.8, this.w * 0.4, this.h * 0.7, this.w * 0.5, this.h * 0.95);
//head
stroke(50);
strokeWeight(1);
fill(108, 158, 27);
//left
pushMatrix();
translate(0, this.h * 0.5);
rotate(radians(-this.angle));
beginShape();
vertex(0, 0);
vertex(-this.w * 0.1, -this.h * 0.2);
vertex( this.w * 0.1, -this.h * 0.4);
vertex(-this.w * 0.1, -this.h * 0.6);
vertex( this.w * 0.1, -this.h * 0.8);
vertex(0, -this.h);
bezierVertex(-this.w * 0.65, -this.h * 0.9, -this.w * 0.65, -this.h * 0.1, 0, 0);
endShape();
popMatrix();
//right
pushMatrix();
translate(0, this.h * 0.5);
rotate(radians(this.angle));
beginShape();
vertex(0, 0);
vertex(-this.w * 0.1, -this.h * 0.2);
vertex( this.w * 0.1, -this.h * 0.4);
vertex(-this.w * 0.1, -this.h * 0.6);
vertex( this.w * 0.1, -this.h * 0.8);
vertex(0, -this.h);
bezierVertex(this.w * 0.65, -this.h * 0.9, this.w * 0.65, -this.h * 0.1, 0, 0);
endShape();
popMatrix();
//pot
strokeWeight(1);
stroke(50);
fill(219, 165, 57);
beginShape();
vertex(-this.w * 0.5, this.h * 1.1);
vertex( this.w * 0.5, this.h * 1.1);
vertex( this.w * 0.4, this.h * 2);
vertex(-this.w * 0.4, this.h * 2);
endShape(CLOSE);
fill(176, 130, 39);
beginShape();
vertex(-this.w * 0.55, this.h * 1.1);
vertex( this.w * 0.55, this.h * 1.1);
vertex( this.w * 0.55, this.h * 1.3);
vertex(-this.w * 0.55, this.h * 1.3);
endShape(CLOSE);
popStyle();
popMatrix();
},
update: function() {
if(this.eat) {
this.angle = lerp(this.angle, 0, 0.08);
}
},
go: function() {
this.draw();
this.update();
}
};
var Player = function(args) {
this.x = args.x;
this.y = args.y;
this.vx = args.vx || 0;
this.vy = args.vy || 0;
this.diameter = args.diameter || 100;
this.scale = this.diameter / 300;
this.radius = this.diameter / 2;
this.circumference = 2 * PI * this.radius;
this.vymax = ~~this.diameter * 0.65;
this.vxmax = ~~this.diameter * 0.5;
this.gravity = args.gravity || 0.2;
this.friction = args.friction || 0;// || 0.02;
this.angle = args.angle || 0;
this.rot = args.rot || 0;
this.color = args.color || color(204, 192, 55);
this.eaten = false;
this.type = args.type || "cat";
};
Player.new = function(args) {
var obj = Object.create(Player.prototype);
Player.apply(obj, arguments);
return obj;
};
Player.prototype = {
draw: function() {
pushMatrix();
translate(this.x, this.y);
rotate(radians(this.angle));
scale(this.scale);
switch(this.type) {
case "cat":
pushStyle();
imageMode(CENTER);
image(game.images.cat, 0, 0);
imageMode(CORNER);
popStyle();
break;
case "dog":
pushStyle();
imageMode(CENTER);
image(game.images.dog, 0, 0);
imageMode(CORNER);
popStyle();
break;
case "sheep":
pushStyle();
imageMode(CENTER);
image(game.images.sheep, 0, 0);
imageMode(CORNER);
popStyle();
break;
case "pig":
pushStyle();
imageMode(CENTER);
image(game.images.pig, 0, 0);
imageMode(CORNER);
popStyle();
break;
case "cow":
pushStyle();
imageMode(CENTER);
image(game.images.cow, 0, 0);
imageMode(CORNER);
popStyle();
break;
case "mouse":
pushStyle();
imageMode(CENTER);
image(game.images.mouse, 0, 0);
imageMode(CORNER);
popStyle();
break;
case "rabbit":
pushStyle();
imageMode(CENTER);
image(game.images.rabbit, 0, 0);
imageMode(CORNER);
popStyle();
break;
case "chicken":
pushStyle();
imageMode(CENTER);
image(game.images.chicken, 0, 0);
imageMode(CORNER);
popStyle();
break;
case "horse":
pushStyle();
imageMode(CENTER);
image(game.images.horse, 0, 0);
imageMode(CORNER);
popStyle();
break;
}
popMatrix();
},
update: function() {
this.vx = constrain(this.vx - this.friction, 0, this.vxmax);
this.x+= this.vx;
this.vy = constrain(this.vy + this.gravity, this.vy, this.vymax);
this.y+= this.vy;
this.angle+= this.vx / this.circumference * 360 * 0.2;
},
go: function() {
this.draw();
this.update();
}
};
var Cannon = function(args) {
this.x = args.x;
this.y = args.y;
this.vx = args.vx || 0;
this.vy = args.vy || 0;
this.rot = {
min: 20,
max: 70
};
this.angle = args.angle || this.rot.min;
this.vel = args.vel || 10;
this.power = 0;
this.topSpeed = args.topSpeed || 40;
this.diameter = args.diameter || 150;
this.length = args.length || 200;
this.cos = cos;
this.sin = sin;
};
Cannon.new = function(args) {
var obj = Object.create(Cannon.prototype);
Cannon.apply(obj, arguments);
return obj;
};
Cannon.prototype = {
draw: function() {
pushMatrix();
translate(this.x, this.y);
pushStyle();
//base
noStroke();
fill(48, 46, 47);
arc(0, 0, this.diameter, this.diameter, radians(180), radians(360));
//barrel
pushMatrix();
rotate(radians(this.angle));
stroke(0);
strokeWeight(1);
fill(166, 171, 170);
rect(-12, -this.length, 24, this.length * 0.5, 5);
rect(-14, -this.length * 0.8, 28, this.length * 0.8 * 0.5, 5);
rect(-16, -this.length * 0.55, 32, this.length * 0.55 * 0.5, 5);
popMatrix();
noStroke();
fill(71, 69, 71);
arc(0, 0, this.diameter * 0.9, this.diameter * 0.9, radians(180), radians(360));
textAlign(CENTER);
textSize(20);
fill(250, 200);
text(~~this.vel, 0, -this.diameter * 0.25);
fill(147, 150, 147);
rect(-this.diameter * 0.25, -this.diameter * 0.15, this.diameter * 0.5, this.diameter * 0.1, 5);
fill(map(this.vel, 5, this.topSpeed, 235, 130), map(this.vel, 5, this.topSpeed, 40, 235), map(this.vel, 5, this.topSpeed, 40, 135));
rect(-this.diameter * 0.25, -this.diameter * 0.15, map(this.vel, 5, this.topSpeed, 0, this.diameter * 0.5), this.diameter * 0.1, 5);
popStyle();
popMatrix();
},
// move: function() {
// if((game.keys[UP] || game.keys[87])) { //Up arrow or W
// this.angle = constrain(this.angle - 2, 0, 90);
// }
// if(game.keys[DOWN] || game.keys[83]) { //Down arrow or S
// this.angle = constrain(this.angle + 1, 0, 90);
// }
// this.angle = constrain(this.angle + 1, 0, 90);
// },
update: function() {
this.x+= this.vx;
this.y+= this.vy;
this.vel = map(this.sin(radians(frameCount * 10)), -1, 1, 5, this.topSpeed);
},
go: function() {
this.draw();
//this.move();
this.update();
}
};
//game object
var Game = function() {
this.scene = "load";
this.started = false;
this.images = undefined;
this.imageIndex = 0;
this.loaded = false;
this.gameOpened = false;
this.valid = true;
this.score = 0;
this.bestScore = 0;
this.highscores = [
{
name: "Could be you",
score: 0
},
{
name: "Could be you",
score: 0
},
{
name: "Could be you",
score: 0
},
{
name: "Could be you",
score: 0
},
{
name: "Could be you",
score: 0
},
{
name: "Could be you",
score: 0
},
{
name: "Could be you",
score: 0
},
{
name: "Could be you",
score: 0
},
{
name: "Could be you",
score: 0
},
{
name: "Could be you",
score: 0
}
];
this.addFrequency = {
min: 500,
max: 900,
value: ~~random(500, 900)
};
this.cam = {
x: 0,
y: 0
};
this.shake = 0;
this.shakedown = 0.1;
this.gameOver = false;
this.gameOverTimer = 0;
this.transition = new Transition();
this.sound = false;
this.sounds = {
explosive: document.getElementById('explosive'),
bomb: document.getElementById('bomb'),
trampoline: document.getElementById('trampoline'),
mud: document.getElementById('mud'),
flytrap: document.getElementById('flytrap'),
fire: document.getElementById('fire'),
ground: document.getElementById('ground')
};
this.colors = {
back: color(133, 130, 133),
heading: color(212, 205, 212),
text: color(255)
};
this.ground = {
x: 0,
y: 550,
w: 600,
h: 50
};
this.player = Player.new({
x: 450,
y: 100,
vx: 0,
diameter: 80,
gravity: 0.2,
rot: 15,
trails: []
});
this.cannon = Cannon.new({
x: 450,
y: 550,
vel: 10,
length: 170
});
this.avatars = {
selected: "dog",
cat: new Button({
x: 50,
y: 180,
w: 90,
h: 30,
content: "Cat",
enabled: true,
func: function() {
game.player.type = "cat";
}
}),
dog: new Button({
x: 240,
y: 180,
w: 90,
h: 30,
content: "Dog",
enabled: true,
func: function() {
game.player.type = "dog";
}
}),
sheep: new Button({
x: 430,
y: 180,
w: 90,
h: 30,
content: "Sheep",
enabled: true,
func: function() {
game.player.type = "sheep";
}
}),
pig: new Button({
x: 50,
y: 320,
w: 90,
h: 30,
content: "Pig",
enabled: true,
func: function() {
game.player.type = "pig";
}
}),
cow: new Button({
x: 240,
y: 320,
w: 90,
h: 30,
content: "Cow",
enabled: true,
func: function() {
game.player.type = "cow";
}
}),
mouse: new Button({
x: 430,
y: 320,
w: 90,
h: 30,
content: "Mouse",
enabled: true,
func: function() {
game.player.type = "mouse";
}
}),
rabbit: new Button({
x: 50,
y: 470,
w: 90,
h: 30,
content: "Rabbit",
enabled: true,
func: function() {
game.player.type = "rabbit";
}
}),
chicken: new Button({
x: 240,
y: 470,
w: 90,
h: 30,
content: "Chicken",
enabled: true,
func: function() {
game.player.type = "chicken";
}
}),
horse: new Button({
x: 430,
y: 470,
w: 90,
h: 30,
content: "Horse",
enabled: true,
func: function() {
game.player.type = "horse";
}
})
};
this.explosions = [];
this.trampolines = [];
this.bombs = [];
this.explosives = [];
this.flyTraps = [];
this.muds = [];
this.trees = [];
this.bomb = Bomb.new({
x: 150,
y: 300,
w: 50
});
this.explosive = Explosive.new({
x: 70,
y: 500,
w: 70,
h: 50
});
this.trampoline = Trampoline.new({
x: 220,
y: 540,
w: 80,
h: 15
});
this.flytrap = FlyTrap.new({
x: 600,
y: 450,
w: 50
});
this.mud = Mud.new({
x: 720,
y: 530,
w: 80,
h: 15
});
this.clicked = false;
this.hover = false;
this.keys = [];
this.gameOverImage = undefined;
this.buttons = {
play: new Button({
x: 700,
y: 150,
size: 100,
content: "Play",
enabled: true,
func: function() {
game.reset();
game.transition.scene = "play";
game.transition.active = true;
}
}),
replay: new Button({
x: 390,
y: 280,
content: "Replay",
enabled: true,
func: function() {
game.reset();
game.transition.scene = "play";
game.transition.active = true;
}
}),
home: new Button({
x: 390,
y: 350,
content: "Home",
enabled: true,
func: function() {
game.transition.scene = "home";
game.transition.active = true;
}
}),
back: new Button({
x: 400,
y: 530,
content: "Home",
enabled: true,
func: function() {
game.transition.scene = "home";
game.transition.active = true;
}
}),
playHome: new Button({
x: 50,
y: 50,
content: "Home",
enabled: true,
func: function() {
game.transition.scene = "home";
game.transition.active = true;
}
}),
playSound: new Button({
x: 50,
y: 120,
size: 80,
content: "Sound (OFF)",
enabled: true,
func: function() {
game.sound = !game.sound;
this.content = "Sound (" + (game.sound === true ? "ON" : "OFF") + ")";
}
}),
scoreboard: new Button({
x: 700,
y: 360,
size: 80,
content: "Scoreboard",
enabled: true,
func: function() {
game.transition.scene = "scoreboard";
game.transition.active = true;
}
}),
sound: new Button({
x: 700,
y: 220,
size: 80,
content: "Sound (OFF)",
enabled: true,
func: function() {
game.sound = !game.sound;
this.content = "Sound (" + (game.sound === true ? "ON" : "OFF") + ")";
}
}),
store: new Button({
x: 700,
y: 290,
size: 80,
content: "Characters",
enabled: true,
func: function() {
game.transition.scene = "store";
game.transition.active = true;
}
})
};
this.sin = sin;
this.cos = cos;
this.triangles = [];
this.setup();
};
Game.prototype = {
shakeScreen: function() {
if(this.shake > 0) {
this.shake = lerp(this.shake, 0, this.shakedown);
translate(round(random(-this.shake, this.shake)), round(random(-this.shake, this.shake)));
}
},
cat: function() {
strokeWeight(1);
//ears
stroke(8);
fill(186, 103, 40);
beginShape();
vertex(184, 23);
bezierVertex(197, 12, 208, 7, 218, 11);
bezierVertex(226, 22, 221, 34, 210, 46);
endShape(CLOSE);
beginShape();
vertex(121, 23);
bezierVertex(113, 14, 103, 4, 90, 8);
bezierVertex(84, 15, 87, 30, 98, 42);
endShape(CLOSE);
//tail
fill(198, 146, 44);
beginShape();
vertex(216, 262);
bezierVertex(232, 262, 243, 268, 250, 274);
bezierVertex(260, 279, 269, 276, 272, 265);
bezierVertex(273, 255, 272, 250, 272, 245);
bezierVertex(280, 241, 286, 247, 286, 264);
bezierVertex(284, 277, 275, 287, 266, 292);
bezierVertex(258, 294, 248, 290, 242, 284);
bezierVertex(236, 277, 228, 274, 220, 273);
vertex(205, 272);
endShape(CLOSE);
//arms
beginShape();
vertex(202, 155);
bezierVertex(214, 148, 237, 142, 257, 142);
bezierVertex(259, 134, 261, 129, 267, 125);
bezierVertex(273, 127, 274, 132, 275, 138);
bezierVertex(281, 137, 288, 138, 291, 142);
bezierVertex(292, 146, 290, 150, 282, 151);
bezierVertex(286, 157, 289, 161, 289, 164);
bezierVertex(286, 166, 278, 164, 272, 159);
bezierVertex(272, 162, 269, 168, 266, 170);
bezierVertex(260, 168, 258, 160, 257, 155);
bezierVertex(242, 152, 224, 156, 210, 166);
endShape(CLOSE);
beginShape();
vertex(94, 158);
bezierVertex(85, 150, 66, 144, 43, 145);
bezierVertex(43, 141, 40, 131, 36, 127);
bezierVertex(30, 129, 28, 136, 28, 141);
bezierVertex(22, 141, 16, 141, 11, 144);
bezierVertex(10, 149, 14, 154, 20, 157);
bezierVertex(18, 160, 15, 162, 14, 167);
bezierVertex(18, 168, 23, 167, 29, 163);
bezierVertex(30, 167, 31, 172, 36, 173);
bezierVertex(41, 168, 43, 162, 46, 156);
bezierVertex(63, 156, 75, 160, 86, 167);
endShape(CLOSE);
//legs
beginShape();
vertex(201, 273);
bezierVertex(205, 287, 208, 303, 204, 321);
bezierVertex(212, 323, 219, 322, 224, 325);
bezierVertex(225, 329, 220, 336, 211, 340);
bezierVertex(203, 339, 196, 335, 192, 333);
bezierVertex(192, 318, 190, 296, 181, 280);
endShape(CLOSE);
beginShape();
vertex(104, 272);
bezierVertex(94, 285, 93, 306, 94, 324);
bezierVertex(87, 325, 80, 325, 76, 331);
bezierVertex(78, 338, 82, 340, 85, 342);
bezierVertex(92, 343, 100, 343, 107, 340);
bezierVertex(108, 317, 112, 295, 120, 280);
endShape(CLOSE);
//body
fill(198, 146, 44);
beginShape();
vertex(150, 130);
bezierVertex(172, 130, 199, 139, 216, 159);
bezierVertex(234, 184, 233, 226, 226, 250);
bezierVertex(213, 276, 191, 284, 168, 289);
bezierVertex(145, 290, 122, 289, 100, 277);
bezierVertex(74, 257, 64, 233, 65, 206);
bezierVertex(68, 182, 78, 163, 96, 151);
bezierVertex(113, 140, 128, 134, 149, 130);
endShape(CLOSE);
//head
beginShape();
vertex(154, 12);
bezierVertex(179, 12, 204, 27, 222, 48);
bezierVertex(234, 71, 229, 94, 217, 115);
bezierVertex(205, 130, 181, 143, 159, 145);
bezierVertex(132, 145, 107, 132, 88, 114);
bezierVertex(77, 95, 77, 72, 90, 48);
bezierVertex(108, 27, 128, 14, 154, 12);
endShape(CLOSE);
//mouth
bezier(153, 91, 155, 104, 169, 112, 180, 106);
bezier(152, 92, 147, 106, 133, 111, 123, 104);
//nose
fill(186, 103, 40);
beginShape();
vertex(154, 73);
bezierVertex(161, 73, 168, 77, 169, 81);
bezierVertex(164, 90, 163, 91, 156, 94);
bezierVertex(152, 93, 144, 89, 141, 84);
bezierVertex(140, 80, 141, 75, 154, 73);
endShape(CLOSE);
//eyes
fill(240);
beginShape();
vertex(171, 47);
bezierVertex(178, 48, 182, 53, 182, 60);
bezierVertex(180, 65, 175, 69, 168, 68);
bezierVertex(162, 64, 162, 59, 162, 55);
bezierVertex(162, 52, 165, 49, 171, 47);
endShape(CLOSE);
beginShape();
vertex(140, 39);
bezierVertex(147, 39, 153, 41, 156, 50);
bezierVertex(155, 58, 152, 64, 146, 67);
bezierVertex(134, 67, 126, 61, 126, 55);
bezierVertex(126, 48, 131, 42, 140, 39);
endShape(CLOSE);
//eye balls
fill(8);
ellipse(143, 56, 10, 10);
ellipse(173, 58, 7, 7);
fill(240);
ellipse(141, 52, 4, 4);
ellipse(171, 56, 3, 3);
//stripes on head
noStroke();
fill(8);
beginShape();
vertex(224, 53);
bezierVertex(216, 58, 206, 62, 197, 65);
bezierVertex(209, 68, 220, 68, 229, 65);
bezierVertex(227, 60, 226, 57, 224, 53);
endShape(CLOSE);
beginShape();
vertex(229, 72);
bezierVertex(226, 77, 218, 79, 210, 80);
bezierVertex(216, 84, 222, 85, 229, 85);
bezierVertex(228, 81, 229, 77, 229, 72);
endShape(CLOSE);
beginShape();
vertex(225, 98);
bezierVertex(221, 100, 212, 100, 204, 97);
bezierVertex(208, 101, 213, 105, 220, 110);
bezierVertex(222, 107, 224, 104, 225, 99);
endShape(CLOSE);
beginShape();
vertex(90, 48);
bezierVertex(94, 53, 105, 60, 112, 63);
bezierVertex(106, 65, 93, 65, 86, 59);
bezierVertex(84, 56, 86, 54, 90, 48);
endShape(CLOSE);
beginShape();
vertex(82, 68);
bezierVertex(84, 73, 93, 77, 105, 79);
bezierVertex(96, 81, 87, 81, 80, 81);
bezierVertex(81, 79, 80, 75, 82, 70);
endShape(CLOSE);
beginShape();
vertex(81, 97);
bezierVertex(86, 99, 97, 100, 110, 98);
bezierVertex(103, 103, 96, 106, 85, 110);
bezierVertex(84, 106, 83, 103, 81, 97);
endShape(CLOSE);
//stripes on body
beginShape();
vertex(222, 174);
bezierVertex(213, 182, 201, 186, 18.........完整代码请登录后点击上方下载按钮下载查看
网友评论0