首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >一旦达到条件就停止

问一旦达到条件就停止
EN

Stack Overflow用户
提问于 2017-06-09 20:26:48
回答 0查看 49关注 0票数 0

如你所见,我的代码如下:

​

代码语言:javascript
复制
<!DOCTYPE html>
    <html>
    <body>
    
    <canvas id="myCanvas" width="500" height="300"
    style="border:1px solid #d3d3d3;">
    Your browser does not support the canvas element.
    </canvas>
    
    <script>
    var canvas = document.getElementById("myCanvas");
    var ctx = canvas.getContext("2d");
    var player = {
        x: 0,
        y: 297.3
    };
    var monster = {
    	x: 150,
        y: 296
    };
    var slope = {
    	1: {
        	x: 183,
        	y: 299
        }
    }
    ctx.font = "13px monospace";
    setInterval(function() {
    	player.x += 8;
        ctx.clearRect(0, 0, canvas.width, canvas.height);
        }, 50);
    setInterval(function() {
    	ctx.fillText("\\o/",player.x, player.y)
        ctx.fillText(">:)",monster.x, monster.y)
        ctx.fillText("/",slope[1].x, slope[1].y)
        ctx.fillText("_______________________",0,296);
        ctx.fillText("_______________________",189,286);
        if (player.x >= monster.x - 25) {
        	monster.x = 1000; monster.y = 1000;
        }
        if (player.x >= slope[1].x - 21) {
        	player.y -= 10;
        }
        }, 50);
    </script>
    
    </body>
    </html>

​

我想阻止玩家上升超过10 (y -= 10,然后停止),一旦它接触到坡度,而不是继续上升。对此有什么解决方案吗?

EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44457830

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档