在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:craftyjs/Crafty开源软件地址:https://github.com/craftyjs/Crafty开源编程语言:JavaScript 96.9%开源软件介绍:Crafty JSCrafty is a JavaScript game library that can help you create games in a structured way… Key Features:
Other Goodies:
Using CraftyA simple game of pong: Crafty.init(600, 300);
Crafty.background('rgb(127,127,127)');
//Paddles
Crafty.e("Paddle, 2D, DOM, Color, Multiway")
.color('rgb(255,0,0)')
.attr({ x: 20, y: 100, w: 10, h: 100 })
.multiway(200, { W: -90, S: 90 });
Crafty.e("Paddle, 2D, DOM, Color, Multiway")
.color('rgb(0,255,0)')
.attr({ x: 580, y: 100, w: 10, h: 100 })
.multiway(200, { UP_ARROW: -90, DOWN_ARROW: 90 });
//Ball
Crafty.e("2D, DOM, Color, Collision")
.color('rgb(0,0,255)')
.attr({ x: 300, y: 150, w: 10, h: 10,
dX: Crafty.math.randomInt(2, 5),
dY: Crafty.math.randomInt(2, 5) })
.bind('UpdateFrame', function () {
//hit floor or roof
if (this.y <= 0 || this.y >= 290)
this.dY *= -1;
// hit left or right boundary
if (this.x > 600) {
this.x = 300;
Crafty("LeftPoints").each(function () {
this.text(++this.points + " Points") });
}
if (this.x < 10) {
this.x = 300;
Crafty("RightPoints").each(function () {
this.text(++this.points + " Points") });
}
this.x += this.dX;
this.y += this.dY;
})
.onHit('Paddle', function () {
this.dX *= -1;
});
//Score boards
Crafty.e("LeftPoints, DOM, 2D, Text")
.attr({ x: 20, y: 20, w: 100, h: 20, points: 0 })
.text("0 Points");
Crafty.e("RightPoints, DOM, 2D, Text")
.attr({ x: 515, y: 20, w: 100, h: 20, points: 0 })
.text("0 Points"); Left paddle is controlled by DevelopingIf you want to fix a bug, please submit a pull request against the development branch. Some guides to help you can be found on the wiki If you would like to make larger contributions please catch us in the forum and we will help you get started. Much appreciated :-) Quick build instructionsThe easiest way to build crafty is to use gruntjs, which requires node and npm. If you have grunt, node, and npm already installed, then run You can also use yarn instead of npm. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论