Sprites, User Input, and Collision COSC 315 Fall 2014 Bridget M. Blodgett.

Slides:



Advertisements
Similar presentations
Games in Python – the easy way
Advertisements

2000 Prentice Hall, Inc. All rights reserved. 1 Outline 3.1Introduction 3.2Game Loop Components 3.3How to Implement in C# 3.4Adding Image to XNA Project.
In this tutorial, we are going to create: A race car that the user can control with the arrow keys for direction and speed. A simulated road with a striped.
Sprites, User Input, and Collision COSC 315 Fall 2014 Bridget M. Blodgett.
Constructor and New Fields // Don't synch draw() with vertical retrace of monitor graphics.SynchronizeWithVerticalRetrace = false; IsFixedTimeStep = true;
Dan Waters, Academic Relations Manager, Microsoft.
Understand the Macromedia Flash environment Open a document and play a movie Create and save a movie Work with layers and the timeline Plan a Web site.
3.1. G RAPHICS I The use of images within games. Reflections and advice on the games proposed in the Week 2 Hand-in.
Computer Science – Game DesignUC Santa Cruz Game Jam Two teams from CMPS 20 – Less Than Royal – Colon Trey.
2D Graphics in XNA Game Studio Express (Modeling a Class in UML) Game Design Experience Professor Jim Whitehead February 5, 2008 Creative Commons Attribution.
Create slices and hotspots Create links in Web pages Create rollovers from slices Create basic animation Add tweening symbol instances to create animation.
Rob Fonseca-Ensor.  I help run the CWDNUG  I’m co-authoring a WROX book on WP7 | | meetup.com/cwdnug  I’ve got.
Week 1 - Friday.  What did we talk about last time?  C#  SharpDX.
2D Physics and Camera Systems For CSE 3902 By: Matt Boggus.
© 2011 Delmar, Cengage Learning Chapter 8 Building Complex Animations.
GAME:IT Junior Bouncing Ball Objectives: Create Sprites Create Sounds Create Objects Create Room Program simple game.
Guide to Programming with Python
Scratch the Cat. Object Oriented Programing Writing computer programs Based on Objects Instead of Actions Based on Data Instead of Logic.
Finishing 2D COSC 315 Fall 2014 Bridget M. Blodgett.
Computer Science – Game DesignUC Santa Cruz CMPS 20: Game Design Experience January 14, 2010 Arnav Jhala.
AI & 2D Development COSC 315 Fall 2014 Bridget M. Blodgett.
CHAPTER 4 Images XNA Game Studio 4.0. Objectives Find out how the Content Manager lets you add pictures to Microsoft XNA games. Discover how pictures.
Tutorial 6 Working with Bitmaps and Gradients, and Publishing Flash Files.
11 A First Game Program Session Session Overview  Begin the creation of an arcade game  Learn software design techniques that apply to any form.
Getting Started. XNA Game Studio 4.0 To download XNA Game Studio 4.0 itself, go to XNA Game.
Using Namepsaces  This section lists the namespaces that the application will be using frequently. Saves the programmer from specifying a fully qualified.
Developing the Game User Interface (UI) Lesson 5.
Art 315 Lecture 5 Dr. J. Parker AB 606. Last time … We wrote our first program. We used a tool called GameMaker. The program we wrote causes a ball to.
User Input and Collisions COSC 315 Fall 2014 Bridget M. Blodgett.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 7 The Game Loop and Animation Starting Out with Games & Graphics.
Introduction to XNA Graphics Programming Asst. Prof. Rujchai Ung-arunyawee COE, KKU.
11 Adding Tomato Targets Session Session Overview  We now have a game which lets a player bounce a piece of cheese on a bread bat  Now we have.
XNA An Introduction. What XNA is… Microsoft® XNA™ is composed of industry- leading software, services, resources, and communities focused on enabling.
Object Oriented Design COSC 315 Fall 2014 Bridget M. Blodgett.
XNA Game Studio 4.0 Keyboard and Mouse Controls + more on Animated Sprites.
MAEK GAEM III: SDL ● Simple DirectMedia Layer ● Input/Graphics/Audio using OpenGL ● Not nearly as difficult as OpenGL ● Cross Platform and Open Sauce ●
11 Making a Sprite Session 4.2. Session Overview  Describe the principle of a game sprite, and see how to create a sprite in an XNA game  Learn more.
Game Maker Terminology
2.1. T HE G AME L OOP Central game update and render processes.
WPH310. Free Phone! Windows Phone 7 as a Game Platform Free Tools to Build Great Games The Game Loop Input on Windows Phone 7 Building a Game with Your.
Reference: The Game Loop Animation / Game loop 1. Update variables 2. [Get input from the user] (GameLoop only) 3. Draw (using variables)
Guide to Programming with Python Chapter Twelve Sound, Animation, and Program Development: The Astrocrash Game.
XNA Basic Displaying Image & Collision Detect. What’s format image that XNA support? XNA support only.bmp.png and.jpg image..PNG have transparent region.
Game Maker Galactic Mail Advanced Group: Complete Galactic Mail, then start developing an independent project.
Intro CS – Screens and Variables Lesson Plan 9. Goals  Using sprites as full screens (Start screen, Game over)  Using layering to control ordering of.
11 Writing Text Session 5.1. Session Overview  Show how fonts are managed in computers  Discover the difference between bitmap fonts and vector fonts.
Playing with Sprites. XNA Game Lifecycle In the faceBall demo program we bounced a smiley face around the graphical display against a background image.
XNA ● Proprietary Microsoft framework ● C#. Interface.
11 Adding a Bread Bat Session Session Overview  We have created a cheese sprite that bounces around the display  We now need to create a bread.
XNA Tutorial 1 For CS134 Lecture. Overview Some of the hard work has already been done for you. If you build and run your game now, the GraphicsDeviceManager.
1 CSC 221: Computer Programming I Fall 2009 Introduction to programming in Scratch  animation sprites  motion, control & sensing  costume changes 
PyGame - Unit 2 PyGame Unit – – Animation.
Consumer Windows Phone Emulator Phone Emulator SamplesDocumentation GuidesCommunity Packaging and Verification Tools Windows Phone Dev Tools AppHub.
The Stingray Example Program CMT3311. Stingray - an example 2D game May be useful as a simple case study Most 2D games need to solve generic problems.
Efficient Game Graphics From Flash MX 2004 Game Design Demystified.
2D Graphics CMT3311. This covers... How to make a transparent sprite How to add a sprite to your project and draw it Properties of sprites and how to.
Game Maker Tutorials Introduction Clickball IntroductionClickball Where is it? Shooting Where is it?Shooting.
CHAPTER 5 Text XNA Game Studio 4.0. Objectives Discover how text is drawn using Microsoft XNA. Add some font resources to your XNA program. Draw some.
Sprites (Images) and Sounds
Reading and Writing Image Files
Graphical Output Basic Images.
Week 2 - Monday CS361.
Using and Creating Sprites
Game Loops + Part II Reference:
Introduction to Object-Oriented Programming
Animated Sprites.
MTA-4201 Game Programming Chapter 8 : Scrolling Background & Font
CSC 221: Introduction to Programming Fall 2018
Collisions with Static Objects
Presentation transcript:

Sprites, User Input, and Collision COSC 315 Fall 2014 Bridget M. Blodgett

Basic XNA Game Open XNA and make a new project – You can leave the default name Open and examine program.cs and Game1.cs (or YourGamesName.cs) – What does it look like each of these methods does? What are GraphicsDeviceManager and SpriteBatch and why are they important?

Game Loops The logic of programming a game relies upon a game loop – This loop usually consists of a couple of methods that actually control that play of the game The key methods are Update() and Draw() – From the names what do you think goes in these two methods?

Registering vs Polling Most programs wait for user input to perform any actions – They can be said to register user changes and respond Games often have to keep running regardless of whether the user is interacting – This is called polling the input devices for changes – It is one reason that most games use a game loop to run

Game State The game state is the log of what is currently happening in the game Games usually have several basic states that correspond to the major play phases – There can be minor states that address play related states as well The game state is tracked and changed in Update() – The impacts and visible outcome are then shown using Draw()

Initialize()LoadContent() Update() Draw() UnloadContent()

Game Time Draw() accepts one parameter: gameTime – gameTime keeps track of how long has passed since the game was started – This is important because the only other method of timing is based upon the processor speed Try changing the background color to something other than blue

Adding Sprites XNA will allow you to use several graphics formats for images in your game – You load them into the content pipeline which then converts them to a format that is usable by the program Looking at the solution explorer you should be able to add the existing images from the source code to your project In Game1.cs write Texture2D texture; –texture = Content.Load

Drawing the Sprite The texture has been loaded into the program To draw it on the screen type: spriteBatch.Begin(); spriteBatch.Draw(texture,Vector2.Zero, Color.White); spriteBatch.End(); If you wanted to center the image you can use: –spriteBatch.Draw(texture, new Vector2(Window.ClientBounds.Width/2) – (texture.Width/2), (Window.ClientBounds.Height/2) – (texture.Height/2)), Color.White);

Additional Options When drawing more than one sprite it is optimal to draw as many as possible within one spriteBatch call – To make the background transparent you can turn it pure magenta (auto transparent in XNA) or use a format like PNG that handles transparency You can also flip and scale the sprites, set their order or rotate them around an axis point

Layer Depth Typically the sprites will layer on top of one another in the order that they are drawn on the screen Setting the layer depth property to 0 will put them on top and 1 will put them behind Changing this requires a change to spriteBatch.Begin(SpriteSortMode.FrontToBa ck, BlendState.AlphaBlend);

Moving Sprites Make two Vector2 variables named pos1 and pos2 and set both to Vector2.Zero ; Make two float variables named speed1 and speed2 and set them to 2f and 3f respectively. To make the movement happen you need to change the values of pos 1 and 2 in Update(). pos1.X += speed1; if(pos1.X > Window.ClientBounds.Width – texture.Width || pos1.X < 0) speed1 *= -1; pos2.Y += speed2; if(pos2.Y > Window.ClientBounds.Height – texture.Height || pos2.Y < 0) speed2 *= -1;

Sprite Sheets Load in the animated sprites three rings sheet like we did with the XNA logos To move between the different sprites to show motion you need to set up some basic information at the class level Point frameSize = new Point(75,75); Point currentFrame = new Point(0,0); Point sheetSize = new Point(6,8); In Draw add: spriteBatch.Draw(texture,Vector2.Zero, new Rectangle(currentFrame.X*frameSize.X, currentFrame.Y * frameSize.Y, frameSize.X, frameSize.Y), Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 0);