2D Graphics in XNA Game Studio Express (Plus, Random numbers in C#)AnnouncementsSubmitting Hunt the Wumpus assignmentGlobal Game JamUngrouped studentsImagine CupRandom numbers in C#Random number code exampleConverting string to integerConverting String to Integer code exampleXNA GSE Game ScaffoldingXNA GSE Game ScaffoldingXNA GSE Game InitializationXNA GSE Main Game LoopUpdate() and Draw()Getting a 2D Image to Appear on ScreenCreating a TextureExample of creating a textureSpriteBatchSpriteBatch ExampleTinting SpritesTransparent SpritesOther Sprite featuresDrawing sprites demo2D Graphics in XNA Game Studio Express (Plus, Random numbers in C#)Game Design ExperienceProfessor Jim WhiteheadJanuary 16, 2009Creative Commons Attribution 3.0 creativecommons.org/licenses/by/3.0Announcements• Second class section has been scheduled► Friday, 12:30-1:40pm► Natural Sciences Annex, room 102► You can choose to attend either section (or both, if you need more help in a given week)• Tutor help section► Tuesdays, 2-3pm, Jack’s Lounge (Baskin whiteboards)► Drop-in help with homework, project• Homework #1 (Hunt the Wumpus)► Due Wednesday, January 21► If you haven’t started yet, you are behind• Monday is an academic holiday► Martin Luther King, Jr.Submitting Hunt the Wumpus assignment• For next Wednesday’s class, you need to submit► A printed hardcopy of all your source code for the Hunt the Wumpus game► A printout of a gameplay session of you playing your version of Wumpus► Electronic submission of your source code• Need to submit a ZIP file of your project code• Under Vista• Documents\{user name}\Visual Studio 2008\Projects\{name of your project}• Right click, Send To > Compressed (zipped) Folder• Under XP, may need to install a ZIP program– 7-Zip, http://www.7-zip.org/► Go to www.wdmanegold.com/class/• Username/password will be emailed to you shortly, to the email address UCSC has on record• Your @ucsc.edu address, most likely• Click on “Submit homework”• Click “Browse” to find file on your machine• Click “Submit” when ready► Email Bill Manegold if you run into trouble• [email protected]• Put CMPS 20 in subject line pleaseGlobal Game Jam• Global Game Jam► www.globalgamejam.org► A worldwide gathering of people to create games ► Friday, January 30 (4:30pm)-Sunday, February 1, 7pm► Work in teams to create a game over 48hours► Food provided, free to participate► UCSC is one of the (many worldwide) sites for the jam► Go to ayandeh.cse.ucsc.edu/ggj09/ to register► Space is limitedUngrouped students• According to our records, the following students are not currently in a group► Douglas Carpenter► Brian Diaz► Edwin Franco► Dustin Gay► Adam Hawley► David Jonas► Sean Lynch► Leland Owens► Daniel Valdez► John Wilson• Either find a partner by the end of class, or we will assign you a partnerImagine Cup• Worldwide competition► Microsoft sponsored► Many categories, including game development► Multiple rounds – first round ends March 1► Games must use XNA Game Studio 3.0► Games need to address contest theme:• Imagine a world where technology helps solve the toughest problems facing us today.► Would be possible to take your project for CS 20, and enter it into the contest► $25,000 first prize, $10,000 second prize, $5,000 third prize► http://imaginecup.com/Random numbers in C#• Several aspects of Hunt the Wumpus require random numbers• In C#, the Random class creates these• Two steps:► Create an instance of class Random• Random random = new Random();• System clock millisecond value used for random number seed when no parameters are passed to constructor.► Call Next() on the instance• my_random = random.Next();► Can place an upper bound on random number by passing parameter to Next()• my_random = random.Next(20);• A random number less than 20Random number code example• A C# program that generates and prints 20 random integers• Show example in Visual C# 2008static void Main(string[] args){Random random = new Random();int my_random;int i;System.Console.WriteLine("Here are 20 random integers, each less than 20.");for (i = 0; i <= 20; i++){my_random = random.Next(20); // a random number less than 20System.Console.WriteLine("[{0}]: {1}", i, my_random);}}Converting string to integer• In Hunt the Wumpus, need to gather the number of a room from the user► Moving to a new room, shooting a crooked arrow• Two steps► Read an input string from the user• string my_input = System.Console.ReadLine();► Convert to an integer• int.TryParse(my_input, out room);• Returns a boolean – true if conversion worked, false if not• Room contains integer if conversion worked (contains 0 on error)• Room is an out parameter, need to use “out” keyword– Cannot pass data into method, only data comes out via an out parameter► There are other ways to convert a string to an integer• int Convert.ToInt32(string)Converting String to Integer code example• Read a line of input• Use int.TryParse to convert to integer• Demonstration in Visual C# 2008static void Main(string[] args){string room_input;int room;System.Console.WriteLine("Shooting. Enter destination room.");room_input = System.Console.ReadLine();if (int.TryParse(room_input, out room) = = true){System.Console.WriteLine("Shooting arrow into room {0}", room);}else{System.Console.WriteLine("Invalid number - please enter an integer.");}}XNA GSE Game Scaffolding• Scaffolding for a simple XNA GSE game is created when you select a new game project in Visual C# Express► File … New Project … Windows Game (3.0)► Or File … New Project … Xbox 360 Game (3.0)• Can fill-in this scaffolding to create your own game• Creates a class (myGameClass) that includes► Constructor► Initialization• Initialize(), LoadContent()► Update• Update game state every clock tick► Draw• Create display every clock tick• Demonstration of XNA GSE scaffolding in Visual C# 2008 ExpressXNA GSE Game ScaffoldingMicrosoft.Xna.Framework.GamemyGame- graphics: GraphicsDeviceManager - content: ContentManager+ myGame() # Initialize() # LoadContent(loadAllContent: bool) # UnloadContent(unloadAllContent: bool) # Update(gameTime: GameTime) # Draw(gameTime: GameTime)graphics = new GraphicsDeviceManager(this); Content.RootDirectory = “Content”;base.Initialize()# Initialize() # Run() # Tick()Update(gameTime);
View Full Document