bxm0927 / canvas-special Goto Github PK
View Code? Open in Web Editor NEW:octocat::alien::star2:超多经典 Canvas 实例,动态离子背景、炫彩小球、贪吃蛇、坦克大战、是男人就下100层、心形文字等。
:octocat::alien::star2:超多经典 Canvas 实例,动态离子背景、炫彩小球、贪吃蛇、坦克大战、是男人就下100层、心形文字等。
//判定食物是否出现在蛇身上,如果是重合,则重新生成一遍
var isOnSnake = true;
//设置食物出现的随机位置
while (isOnSnake) {
//执行后先将判定条件设置为false,如果判定不重合,则不会再执行下列语句
isOnSnake = false;
var indexX = getNumberInRange(0, canvas.width / 20 - 1);
var indexY = getNumberInRange(0, canvas.height / 20 - 1);
var rect = new Rect(indexX * 20, indexY * 20, 20, 20, "green");
for (var i = 0; i < snake.snakeArray.length; i++) {
if (snake.snakeArray[i].x == rect.x && snake.snakeArray[i].y == rect.y) {
//如果判定重合,将其设置为true,使随机数重给
isOnSnake = true;
break;
}
}
}
//返回rect,使得实例化对象food有draw的方法
return rect;
这段代码怎么避免食物出现在蛇上的
《是男人就下一百层》有一个小bug:踩到钉子上没有反应(和踩到平地一样)
希望能修复一下~ 感谢! QAQ
挺好的东西为什么没有留言
感谢分享!!!!
大佬,作品很炫酷
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.