在突破中绘制砖块/砖块碰撞 - C#中的大学项目 [英] Drawing Bricks/Brick Collision in Breakout - College Project in C#

查看:69
本文介绍了在突破中绘制砖块/砖块碰撞 - C#中的大学项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我正在努力寻找一种方法来绘制砖块并在砖块和球之间创建碰撞检测。



非常感谢任何帮助/建议。



干杯,

Hello,

I am struggling to find a way to draw a line of bricks and to create collision detection between the bricks and the ball.

Any help / suggestions are much appreciated.

Cheers,

推荐答案

如果您正在使用Windows窗体,那么您可以开始简单地将矩形绘制为砖块和圆形(然后您可以优化图形)。

碰撞检测实际上非常简单:让 {XC,YC} 成为球的中心坐标, R 分别为ray, {XTL,YTL} {XBR,YBR} 砖块的左上角和右下角,然后



If you are using Windows Forms then you may start simply drawing rectangles as bricks and a circle as the ball (then you might refine your graphics).
Collision detection is actually very simple: let {XC, YC} be the coords of center of the ball, R is ray, and {XTL,YTL}, {XBR, YBR} respectively, the top-left and bottom-right point of a brick, then

if ((XTL-XC) < R || (XC-XRB) < R || (YTL-YC) < R || (YC-YBR) < R)
{// handle collision here
}





检测到碰撞。



detects a collision.


这篇关于在突破中绘制砖块/砖块碰撞 - C#中的大学项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆