用C语言圈程序 [英] circle program in c language

查看:83
本文介绍了用C语言圈程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当圆圈碰到屏幕一侧的末端时如何将圆圈指向其他方向????

how to direct the circle to othe direction when it hits the end of one side of the screen???

推荐答案

我假设您的意思是您有一个画一个圆,然后在屏幕上移动它的程序.当它碰到右侧时,您要反转它并以其他方式启动它吗?

如果是这样,那么我将无法为您提供任何准确的信息-我不知道您如何绘制圆,我不知道您如何移动圆.实际上,我对您的程序一无所知,除了在C语言中,它画了一个圆圈.

因此,我能做的最好的就是一般建议:
找出屏幕的宽度(以像素为单位)(或以任何单位用作圆的大小,这就是要与之进行比较的结果)
设置一个变量,该变量具有每次移动圆的数量(而不是函数中的常数)
在移动圆之前,请检查当前位置(在X轴上)以及圆的半径是否大于或等于屏幕的宽度.如果是,请将可变量设为负数,但不要理会实际值.因此,如果您每次将其移动十个单位,请将其减十.
添加移动量,并按正常方式绘制.

您可能还希望在屏幕的左侧进行类似的测试.
I assume you mean that you have a program which draws a circle, and moves it across the screen. When it hits teh right hand side, you want to reverse it and start it moving the other way?

If so, then I can''t give you any precise information - I don''t know how you are drawing the circle, I don''t know how you are moving it. I don''t know anything about your program at all in fact, other than it is in C and it draws a circle.

So the best I can do is general advice:
Find out the width of your screen in pixels (or in whatever unit you are using for the size of the circle, that is what you will compare against)
Set a variable with the amount to move the circle each time (rather than a constant value in your function)
Before you move the circle, check if the current position (on the X axis), plus the radius of the circle is greater than or equal to the width of the screen. If it is, make the variable amount negative, but leave the actual value alone. So if you were moving it by ten units each time, make it minus ten.
Add on the movement amount, and draw it as normal.

You will probably want to do a similar test against the left hand side of the screen as well.


您要搜索的程序是Bouncing Ball.

这是一个实现:
http://www.mycfiles.com/2011/04/bouncing-ball- code-in-c.html [ ^ ]

有关更多示例,请使用Google.

希望对您有所帮助.
The program you are searching for is Bouncing Ball.

Here is an implementation :
http://www.mycfiles.com/2011/04/bouncing-ball-code-in-c.html[^]

For more examples use Google.

Hope it helps.


这篇关于用C语言圈程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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