Danh mục

Building XNA 2.0 Games- P8

Số trang: 30      Loại file: pdf      Dung lượng: 1.76 MB      Lượt xem: 11      Lượt tải: 0    
tailieu_vip

Xem trước 3 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Building XNA 2.0 Games- P8: I would like to acknowledge John Sedlak, who saved this book from certain doom, as well asall of the great guys in the XNA community and Microsoft XNA team, who helped me with allof my stupid programming questions. (That is actually the term used—“stupid programmingquestion”—and it is a question that one should not have to ask if one has been approached towrite a book about the subject.)
Nội dung trích xuất từ tài liệu:
Building XNA 2.0 Games- P8198 CHAPTER 7 ■ PARTICLE MAYHEM AddParticle(new Smoke(loc, Rand.GetRandomVector2(-50f, 50f, -50f, 10f) - traj * Rand.GetRandomFloat(0.001f, 0.1f), 1f, 1f, 1f, 0.25f, Rand.GetRandomFloat(0.05f, 0.25f), Rand.GetRandomInt(0, 4))); AddParticle(new Smoke(loc, Rand.GetRandomVector2(-50f, 50f, -50f, 10f), 0.5f, 0.5f, 0.5f, 0.25f, Rand.GetRandomFloat(0.1f, 0.5f), Rand.GetRandomInt(0, 4))); } } We’re making a bunch of dust here! The first AddParticle() call sends a bit of light smoke back in the direction the bullet came from, albeit much slower (and at a random speed). The second AddParticle() creates a softer, darker bit of smoke. Since we’re doing 16 of each, we get a soft spray of dust, as shown in Figure 7-11 (it looks better in motion, obviously). Figure 7-11. Bullet ricochet CHAPTER 7 ■ PARTICLE MAYHEM 199Adding ZombiesShooting the earth is fun enough, but what we really need here are some undead punchingbags, and not a moment too soon! We’re all the way to Chapter 7 with nary a monster in sight,so, without further ado, let’s make some zombies! We need to start off with some graphics. We’ll use a few new images: head2.png, torso2.png,and legs2.png, as shown in Figure 7-12.Figure 7-12. Zombie parts We’ll add these images to the Content project in two solutions: CharacterEditor andZombieSmashers. We also need to upgrade CharacterEditor again to allow the user to specifywhich textures to use.Zombies in the Character EditorFirst, we’ll change the arrays as created in Game1.LoadContent() to contain two indices. Fortu-nately, we don’t need to change the loading, because we coded it to automatically load thetextures based on the length of the array.legsTex = new Texture2D[2];torsoTex = new Texture2D[2];headTex = new Texture2D[2];weaponTex = new Texture2D[1]; Let’s add a new tab to our low-budget triggers/script tab area, turning it into a triggers/script/textures tab area. We’ll start by creating a new class-level constant:const int AUX_SCRIPT = 0;const int AUX_TRIGS = 1;const int AUX_TEXTURES = 2; Now we’ll draw our texture-selection panel in Draw(). We’ll just be iterating through thefour texture indices, incrementing, decrementing, and drawing text.#region Texture Switchingif (auxMode == AUX_TEXTURES){200 CHAPTER 7 ■ PARTICLE MAYHEM for (int i = 0; i < 4; i++) { if (DrawButton(210 + i * 21, 40, 1, mouseState.X, mouseState.Y, mouseClick)) { switch (i) { case 0: if (charDef.HeadIndex > 0) charDef.HeadIndex--; break; case 1: if (charDef.TorsoIndex > 0) charDef.TorsoIndex--; break; case 2: if (charDef.LegsIndex > 0) charDef.LegsIndex--; break; case 3: if (charDef.WeaponIndex > 0) charDef.WeaponIndex--; break; } } string t = charDef.HeadIndex.ToString(); switch (i) { case 1: t = charDef.TorsoIndex.ToString(); break; case 2: t = charDef.LegsIndex.ToString(); break; case 3: t = charDef.WeaponIndex.ToString(); break; } text.Color = Color.White; text.DrawText(212 + i * 21, 60, t); if (DrawButton(210 + i * 21, 85, 2, mouseState.X, mouseState.Y, mouseClick)) { switch (i) { CHAPTER 7 ■ PARTICLE MAYHEM 201 case 0: if (charDef.HeadIndex < headTex.Length - 1) charDef.HeadIndex++; break; case 1: if (charDef.TorsoIndex < torsoTex.Length - 1) charDef.TorsoIndex++; break; case 2: if (charDef.LegsIndex < legsTex.Length - 1) charDef.LegsIndex++; break; case 3: if (charDef.WeaponIndex ...

Tài liệu được xem nhiều: