Chapter . Introduction

Imagine this: You create a new paladin character with random stats and hit points, receive your first quest, and begin exploring the game world. You stumble upon a skeleton warrior pacing near a pile of treasure. You attack the skeleton, and it hits you back! You roll 1D20 and score a critical hit! The 20-point die, plus dexterity, against the skeleton’s armor class, nets a guaranteed hit. Your damage roll is 1D8 plus your strength and weapon modifier, which is 1D4, more than enough to kill the monster! It falls to the ground, a jumble of bones. Lying next to the unmoving skeleton is chain mail armor, which you pick up and equip, giving your character a huge boost in armor points. You also pick up 10 gold coins and gain 25 experience points. A magic key is also found, completing the first quest! Now you dream of finding a better sword. Off to the right, you spot a whole group of undead, the remains of a cursed Viking army, which surely have gear and gold you could use . . . and you head toward them to battle!

This is no fictional narrative. You will learn to build a game with every feature just described in detail! This book will teach you how to create your own fully functional role-playing game (RPG) using Visual Basic. You will learn step-by-step how to construct each part of the game engine using Windows Forms and GDI+, including a tiled scroller, game editors, and scripting. If you think role-playing games are fun to play, wait until you start working on your very own adventure! Constructing an RPG is more fun than playing one, because you are in complete control over the game world, and you can let your imagination loose to create adventures for others to enjoy. However, it is not easy! Just as your game character must gain experience and level up, so must you level up by reading each chapter to learn new skills!

Before you can get to the point where you are able to design an adventure and build an RPG with Visual Basic, you will need to learn the language. My goal with this book is to teach you just what you need to know in order to make this happen. You will learn what you need to know to construct an RPG. You might choose to use a product such as RPG Maker (on the PlayStation 2), rather than writing your own RPG with Visual Basic. That is certainly a good alternative, but wouldn’t it be better to have complete control over how the game works? Certainly you can create many complete RPGs of your own design with RPG Maker in the time it takes to build just one RPG from scratch by doing all of your own programming. But in the end, you will have learned a promising skill—game programming! In addition, you will have complete creative control over how the game operates, and will be able to make many games from the same code and tools.

Pacing and Experience

This book reads like a hobby book, with no pressure and limited goals, because the primary purpose of this book is to help you to have fun learning about game programming. Typing in long source code listings out of a book is not fun, so I don’t ask you to do that in this book. Instead, you will learn by studying the short examples in each chapter, and over time you will get the hang of it. There is no memorization required here, as I’m a firm believer that repetition and practice is the best way to learn, not theory and memorization. The Celtic Crusader game is built from one chapter to the next, with new features and gameplay elements added in each new chapter. You will learn to create this game completely from scratch in a very short amount of time.

The finished game in the last chapter includes all the source code to make your own RPG with the features described above, including combat with monsters and enemy NPCs; treasure and gold drops; creating items with the custom item editor; picking up item drops; managing inventory with drag-drop; equipping gear with buffs (stat modifiers) such as armor and weapons; creating NPCs with the character editor; rolling new player characters; saving the game; creating the game world with a custom level editor; and creating quests with the quest editor. Whew! That sounds like a lot of work, but we make all of this happen in the pages of this book, and you will have a playable, customizable RPG game system by the time you reach the last chapter! In fact, why don’t you flip to the last chapter now to see what it looks like? I’ll wait here for you to return.

Prerequisites

The goal of this book is to teach you how to create an RPG. You will benefit from a basic knowledge of Visual Basic in advance, because beyond Chapter 2 we don’t spend any time explaining the Visual Basic language. Programming an RPG is a serious challenge, but if you pay attention and study the examples, you’ll be able to do it! We cover the Basic language in Chapter 2, and Form programming in Chapter 3, so you can refer to those chapters any time you have a question about some of the code we’re going over. Celtic Crusader is a large game, and it’s very hard to program your own RPG! But I’ll try to explain it one step at a time. All of the game editors are also covered in the book, but not in complete detail. So, we cover the key code for the editors but don’t list all of the source code because that would take up 500 pages!

Visual Basic 2008 and the .NET Framework

This book supports Visual Basic 2008 and requires the .NET Framework 2.0 or later. Although the project files are slightly different, the code is absolutely the same for Visual Basic 2010 as well. If you have 2010 you will still be able to run all of the code in the book, but you will have to import the projects to the 2010 format. I have left the projects in the 2008 format so that more readers will be able to open the projects with either version. I recommend that you download the free version of Visual Basic Express Edition. You can find it at http://www.microsoft.com/express/Downloads/#2010-Visual-Basic. Since web links change frequently, I recommend you instead Google for “Visual Basic Express download.” There are links to the 2008 version as well, but 2010 is now the officially supported current version so go ahead and use that version if you want. Just note that the 2008 projects will need to be imported when you open them in 2010. This should not pose a problem; it’s just one additional step, and it allows us to support both versions of Visual Basic. One caveat: the LuaInterface library requires the .NET Framework 2.0, so when it comes to the script examples and the final game project in Chapter 20, you may need to create a new Visual Basic 2010 project and then import the sources to it, in order for LuaInterface to work correctly. As an option, an advanced reader may recompile LuaInterface with Visual Basic 2010 and then use the later .NET Framework. If you feel confused about this issue, please visit the author’s web forum with any questions (www.jharbour.com).

Managed DirectX Goes Away?

This book no longer uses Managed DirectX. The first edition, published in 2004, used Visual Basic 6.0 with the DirectX 8 type library. The second edition, published in 2007, changed everything by switching to Visual Basic .NET 2005 and Managed DirectX. This third edition changes everything again by using Visual Basic .NET 2008 and. . . that’s all. DirectX is not required because we are not using it any longer. Instead, this book has completely shifted to Windows Forms programming with the Windows GDI+ (Graphics Device Interface). I made this decision after so many readers contacted me with questions about Managed DirectX not working right on their PCs. It was very difficult, and further complicated by the fact that it doesn’t work any longer with modern 64-bit Windows.

Contacting the Author

I maintain a website at http://www.jharbour.com, which has information about this book that you may find useful. This site also features an online forum where you can pose questions and keep up to date with the latest discussions about Visual Basic and Celtic Crusader with other programmers. If you have any problems working through this book, stop by the site to chat.

Book Contents

The book is divided into three major parts.

Part I, Building Blocks,” includes eight chapters that form the foundation of the role-playing game that is developed in the book. These chapters cover subjects like Windows Forms, bitmaps, sprite animation, user input, collision detection, and similar core subjects.

Part II, Game World,” includes five chapters devoted to building the game engine components needed to manage and render the game world in which the player will live. The core of this game world is a tiled scroller and a level editor.

Part III, Gameplay,” includes seven chapters that develop all of the gameplay components of the role-playing game that make the game truly playable. This part offers additional game editors and classes that make it possible to fight monsters, pick up treasure, manage the player’s inventory and equipped gear, gain experience and level up, talk with NPCs, and go on quests. The final game demo in the last chapter shows how the reader may build his own custom RPG using all of the tools and source code.

Conventions Used in This Book

Source code is presented in fixed-width font for easy readability.

REM This is what source code will look like in the text
Public Sub Hello()
  Console.WriteLine("Hello World")
End Sub

The following styles are used in this book to highlight portions of text that are important.

Hint

Hints offer additional pointers on the current subject being covered.

Trick

Tricks offer guidance and suggestions on what to do or not do in a given situation.

Companion Website Downloads

You may download the companion website files from www.courseptr.com/downloads. Please note that you will be redirected to our Cengage Learning site.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.223.108.105