tailieunhanh - Visual C# Game Programming for Teens phần 3

nhưng chúng tôi sẽ sử dụng phiên bản đơn giản rằng chỉ cần một String (đối với những lời chúng ta muốn in ra), một đối tượng tùy chỉnh Font, màu sắc, và tọa độ. Hình cho thấy kết quả của chương trình này ví dụ. | This page intentionally left blank Chapter 4 Collision Detection Thanks to the code developed over the last two chapters we can draw and animate sprites on the screen. In this chapter we will make them more lifelike by giving them the ability to bump into each other. This is done using a technique called collision detection. A collision occurs when two sprites touch or overlap each other. To demonstrate this new concept we will create a simple project called Archery Game. Collision is a higher-level technique than previous topics you have learned so far which have focused more on just getting something up on the screen. This is a very direct way to test for collisions. Another technique which is ultimately used in Dungeon Crawler is to calculate the distance between two sprites. Let s start with the simpler of the two in this chapter and the distance approach down the road in the gameplay chapters. Here s what we ll cover in this chapter Reacting to solid objects Rectangle intersection Collision test Archery Game Collision demo Reacting tg Solid Objects Collision detection is an important technique that you should learn. It is a requirement for every game ever made. I can t think of any game that does not 77 78 Chapter 4 Collision Detection need collision detection because it is such an essential aspect of gameplay. Without collisions there is no action goal or purpose in a game. There is no way to interact with the game without collisions taking place. In other words collision detection makes the sprites in a game come to life and makes the game believable. Not every situation in which collision detection occurs necessarily means that something is hit or destroyed. We can also use collision testing to prevent the player from going into certain areas such as a lake or mountain area that is impassible . Rectangle Intersection Collision detection is pretty easy to do using the class. First you will create a rectangle based on the position and

TỪ KHÓA LIÊN QUAN