简体   繁体   English

如何在C#中制作一个圆圈来移动?

[英]How to make a circle to move in C#?

I want to write a simple game like pacman in C# in order to learn the new language.我想用 C# 编写一个像吃豆子这样的简单游戏来学习新语言。 However, I don't know how to make a circle move?但是,我不知道如何使圆圈移动? Which part of knowledge in C# is needed?需要 C# 中的哪一部分知识?

You should check out XNA Game Studio from Microsoft.您应该查看 Microsoft 的XNA Game Studio It's a version of Visual Studio that's targetted especially for writing games.它是 Visual Studio 的一个版本,专门针对编写游戏。 You use C# but get a lot of things for free - graphics, sound, timing...您使用 C#,但可以免费获得很多东西 - 图形、声音、计时......

Here's a tutorial for making a ball move in XNA. 这是在 XNA 中使球移动的教程。

最简单的方法是随着定时器控件的每一次滴答移动你的圆圈一点点。

Well, for a simple single player game like that, some of the most important things you need to know about are data structures and GDI.好吧,对于这样一个简单的单人游戏,您需要了解的一些最重要的事情是数据结构和 GDI。

Data structures are important because you need to store information such as what does a map look like?数据结构很重要,因为您需要存储诸如地图是什么样子的信息? Where are the walls?墙壁在哪里? Can you go from one end to the other?你能从一端走到另一端吗? How does the map draw itself?地图是如何自己绘制的?

GDI is used in C# to draw. C# 中使用 GDI 进行绘图。 This uses the Graphics context.这使用图形上下文。 You'll find lots of examples online, and I'd suggest checking out BobPowell.Net GDI+ FAQ to avoid some of the common mistakes.您会在网上找到很多示例,我建议您查看BobPowell.Net GDI+ 常见问题解答以避免一些常见错误。

If you want to learn a new language stay away from all fuss and just look into the most essential parts.如果您想学习一门新语言,请远离所有大惊小怪,只查看最重要的部分。

Having knowledge about previous programming languages helps a lot, espesially if one of those are Java.了解以前的编程语言会有很大帮助,尤其是如果其中一种是 Java。

You don't need to look into XNA for this, all you really do need is to Start Visual Studio, create a new Windows Form, drag over an PictureBox and start playing with the KeyEvents.您不需要为此查看 XNA,您真正需要的只是启动 Visual Studio,创建一个新的 Windows 窗体,拖过一个 PictureBox 并开始使用 KeyEvents。

Your game does not have to be awesome for you to learn the very basics of C# and .NET.要学习 C# 和 .NET 的基础知识,您的游戏不一定要很棒。 And you certainly don't need to dig down in the deep jungle of XNA!而且您当然不需要在 XNA 的丛林深处挖掘!

Once you have your form up and running with a PictureBox or two and you have conqured the Event-system, take a look at the other fundamental parts of .NET that makes your life easier.一旦您使用一两个 PictureBox 启动并运行表单,并且您已经征服了事件系统,请查看 .NET 的其他基本部分,这些部分使您的生活更轻松。 Properties, Generics, Data Sources and much much more.属性、泛型、数据源等等。

You probably want to look into XNA - http://creators.xna.com/您可能想了解 XNA - http://creators.xna.com/

Simply download the studio, install, then run Visual Studio C# (mine is Express Edition).只需下载工作室,安装,然后运行 ​​Visual Studio C#(我的是速成版)。

So when you run, you create a new Windows Game Project and you've created your first game.因此,当您运行时,您创建了一个新的 Windows 游戏项目并创建了您的第一个游戏。

Good to read up some books and articles on XNA.很高兴阅读一些关于 XNA 的书籍和文章。

Book: Microsoft XNA Game Studio 2.0: Learn Programming Now!书籍:Microsoft XNA Game Studio 2.0:立即学习编程! by Rob Miles.通过罗伯·迈尔斯。

if you mean how to move an object around in a circular movement, then you just need math knowledge:如果您的意思是如何以圆周运动的方式移动物体,那么您只需要数学知识:

 int circlePosX = centerX + Math.Cos(degrees) * radius;
 int circlePosY = centerY + Math.Sin(degrees) * radius;

radius is here how big you want the circle to be, and degrees is the position ion the circle the object is moving.半径在这里是你想要的圆有多大,度数是物体移动的圆的位置。

Here's an answer to a question about a radar-type game that demonstrates generally how to do this in C#/WinForms using GDI+ (with a sample and source code):这是一个关于雷达类型游戏的问题的答案,该游戏通常演示了如何使用 GDI+ 在 C#/WinForms 中执行此操作(带有示例和源代码):

What would be the best way to simulate Radar in C#? 在 C# 中模拟雷达的最佳方法是什么?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM