1 / 14

Lecture 4

Lecture 4. PSM Review. Richard Gesick. The Major Methods of an PSM Game. Main – calls Initialize() and then loops. Any class variables need to be static Initialize() - load textures, create sprites using Sprite class, initialize variables

xia
Download Presentation

Lecture 4

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 4 PSM Review Richard Gesick

  2. The Major Methods of an PSM Game Main – calls Initialize() and then loops. Any class variables need to be static Initialize() - load textures, create sprites using Sprite class, initialize variables Update - handle all user input and update game state Render - handle drawing the images/graphics to the screen

  3. NO drawing should happen in Update and No input/state changes should happen in Draw Remember to add Sprite.fcg and Sprite.vcg to the shaders folder

  4. Content Draw your assets (using transparent backgrounds if desired) in your favorite paint program.  GIMP and Paint.NET are both free. For PSM games, they should be saved as .png Create an assets folder and add your assets to it. Then add them to your project (via “Assets | Add | Add files...")

  5. Create attributes within the class to hold the assets Texture2D bowl = new Texture2D(“/Application/Assets/bowl.png”, false); then bowlSprite= new Sprite( graphics, bowl);

  6. publicfloat Rotation; protected Texture2D texture; publicVector3 Position; public Vector2 Center; public Vector2 Scale=Vector2.One; floatwidth,height; publicfloat Width { get{ return width * Scale.X;}} publicfloat Height { get{ return height * Scale.Y;}} publicSprite(GraphicsContextgraphics, Texture2D texture) publicvoid Render() The Sprite Class

  7. Handle User Input continuous movement var gamePadData = GamePad.GetData (0); if ((gamePadData.Buttons & GamePadButtons.Left) != 0) { sprite.Position.X -= speed; }

  8. var gamePadData = GamePad.GetData (0); var pressedButtons = gamePadData.ButtonsDown; if ((pressedButtons & GamePadButtons.Cross) == GamePadButtons.Cross) { wepsSelect++; wepCount = 0; } Handle User Input discrete movement

  9. PSM Key Mappings

  10. Render Draw sprites to the screen (via the Render method of the Sprite class) graphics.SetClearColor (0.0f, 0.0f, 0.0f, 0.0f); graphics.Clear (); bg.Render (); graphics.SwapBuffers ();

  11. Draw strings to the screen using the HighLevel.UI private static Label label1, label2; ... //as class variables UISystem.Initialize (graphics); //in initialize Scene scene = new Scene (); label1 = new Label (); label1.X = 20; label1.Y = 10; label1.Width = 300; label1.Text = "Press …”; scene.RootWidget.AddChildLast (label1); Update the text as necessary in Update() Then in Render() UISystem.Render ();

  12. Random numbers Random r; … r = new Random(); … = r.Next(1, 4); // values 1 to 3 = r.Next(-100, 100); //values -100 to 99 = r.Next(100) //values 0 to 99

  13. List<T> List<> is a parameterized collection class that is useful for storing dynamic collections of items; use the Add, Remove, RemoveAt, etc. methods falling_food = new List<FoodItem>(); … falling_food.Add(fi);

  14. List<T> Remember that when you are removing from a list, you should work through it in reverse order so that the automatic resizing doesn’t cause you to skip elements. You also cannot alter a list when you are using a foreach loop

More Related