.Netterpillars: Artificial Intelligence and Sprites
(Page 1 of 9 )
Learn about artificial intelligence while creating a computer game. This article is excerpted from chapter two of the book
Beginning .NET Game Programming in C#, by Ellen Hatton et. al. (Apress, 2004, ISBN: 1590593197) and is the first of two parts.
IN THIS CHAPTER, WE’LL INTRODUCE YOU to the concepts of artificial intelligence (AI) and sprites. You’ll also get a chance to extend your knowledge of GDI+ functions, including some tips intended to give your games a boost in performance. To accomplish these goals and illustrate these concepts, we’ll walk you through the steps for creating a game called .Netterpillars (see Figure 2-1).

Figure 2-1. .Netterpillars, this chapter's sample game
.Netterpillars is an arcade game in which each player controls a caterpillar (in fact, a netterpillar) that takes part in a mushroom-eating race with other netterpillars. The objective of the game is to be the last surviving netterpillar, or the longest one (they grow when they eat) when every mushroom has been eaten.
We’ll describe the game in more detail in the section “The Game Proposal” later in this chapter.
.Netterpillars is a more complex game than the one you saw in the last chapter because it involves the following components:
- AI: Creating a game with opponents will make you exercise your ability to create a computer-controlled character that challenges players, while giving them a fair chance of winning.
- Sprites: Using nonrectangular game objects will force you to find a way to draw them on the screen in a simple, efficient manner. Including a background image in your game screen will help you to check whether your moving code is working (remember, in the last chapter you simply painted the objects with the flat background color).
- GDI+: Creating an interface where many objects (one to four caterpillars, wooden branches, and a lot of mushrooms) will be drawn and interact with each other will challenge you to find a faster way to update the screen.
While covering these topics, you’ll also look at new concepts related to object-oriented programming so you can create easily reusable classes to improve productivity when coding your games. For example, a Sprite class is something that almost any game will need; so you can code it once and use it forever. We’ll discuss all these points in the next sections, starting with some object-oriented concepts.
This chapter is from Beginning .NET Game Programming in C# by Ellen Hatton et al. (Apress, 2004, ISBN: 1590593197). Check it out at your favorite bookstore today. Buy this book now.
|
Next: Object-Oriented Programming >>
More ASP.NET Articles
More By Apress Publishing