CSE 380 – Computer Game Programming Player Controls & Scrolling Mega Man, by Capcom, released 1988.

Slides:



Advertisements
Similar presentations
Keys to Speed. Vocabulary Pixelation: The appearance of blockiness in an image after it has been enlarged. What had been a single pixel in the original.
Advertisements

Create a Simple Game in Scratch
CSE 380 – Computer Game Programming Tile Based Graphics Legend of Zelda, by Nintendo, released 1987.
2D Platform Games: Tiles & Scrolling
Dynamic Forms How to use Tables. What is a Table? Usually you see a table on a form like this…. 3 columns X 3 rows with grey border lines But this could.
Create a Simple Game in Scratch
4.2. G RAPHICS II Image Ribbons and Image Tiles. Building a scrollable background using several ‘joined’ images.
Factoring Quadratic Expressions ax 2 + bx + c. 2x2x 3x3x +3 – 4 Setting the Stage Do you remember how to multiply these together? (Referred to as FOIL.
BlackBerry Game Development Challenges Jeff Bacon, Sr. Smartphone Product Manager Simon Dale, Smartphone Services Team Lead J15.
Computer Graphics using OpenGL, 3 rd Edition F. S. Hill, Jr. and S. Kelley Chapter 3 Additional Drawing Tools Ureerat Suksawatchon Department of Computer.
INTRODUCTION. Painting with numbers! Aspects Modeling Rendering Animation.
IAT 800 Lab 1: Loops, Animation, and Simple User Interaction.
Frameset. FrameSet With frames, we can display more than one HTML document in the same browser window. Each HTML document is called a frame, and each.
2D Physics and Camera Systems For CSE 3902 By: Matt Boggus.
Games and Simulations O-O Programming in Java The Walker School
Guide to Programming with Python
CHAPTER 11 Tables. How Are Tables Used Data Display  Very tidy and very useful Better Text Alignment  Putting text in tables allows you to format indents.
CSE 380 – Computer Game Programming Render Threading Portal, by Valve,
1 Scrolling and Panning CIS 487/587 Bruce R. Maxim UM-Dearborn.
In.  This presentation will only make sense if you view it in presentation mode (hit F5). If you don’t do that there will be multiple slides that are.
CS 376 Introduction to Computer Graphics 02 / 12 / 2007 Instructor: Michael Eckmann.
My First ACCESSIBLE Flash Movie. Course notes Detailed course notes, a printable copy of my slides, and all the samples shown today can be downloaded.
Using Tiled. What is Tiled? It’s a level editor It allows game programmers to create their 2D game world with ease.
Chapter 12 FRAMES. HOW FRAMES WORK When you view a framed page in a browser, you are actually looking at several HTML documents at once. The key to making.
Designing a Web Page with Tables. A text table: contains only text, evenly spaced on the Web page in rows and columns uses only standard word processing.
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.
CSCE 102 – Chapter 6 (Web Design and Layout) CSCE General Applications Programming Benito Mendoza Benito Mendoza 1 By Benito Mendoza.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 2 Graphics Programming with C++ and the Dark GDK Library Starting.
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.
Lecture 4 Looping. Building on the foundation Now that we know a little about  cout  cin  math operators  boolean operators  making decisions using.
CSE 219 Computer Science III Image Manipulation. HW 1 Has been posted on Blackboard Making a Game of Life with limited.
Game Maker Terminology
AD 305 Electronic Visualization I : School of Art and Design : University of Illinois at Chicago : Spring 2007 Intro to Action Script 9 "The games of a.
“The perfect project plan is possible if one first documents a list of all the unknowns.” Bill Langley.
CSE 380 – Computer Game Programming GUIs for Games.
Loops (cont.). Loop Statements  while statement  do statement  for statement while ( condition ) statement; do { statement list; } while ( condition.
OpenGL The Viewing Pipeline: Definition: a series of operations that are applied to the OpenGL matrices, in order to create a 2D representation from 3D.
Creating a Simple Game in Scratch Barb Ericson Georgia Tech June 2008.
CSE 380 – Computer Game Programming Tile Based Graphics & Scrolling Legend of Zelda, by Nintendo, released 1987.
AD 206 Intermediate CG : School of Art and Design : University of Illinois at Chicago : Spring 2009 Intro to Action Script 9 "The games of a people reveal.
INTRODUCTORY Tutorial 5 Using CSS for Layout and Printing.
Lesson 3: Arrays and Loops. Arrays Arrays are like collections of variables Picture mailboxes all lined up in a row, or storage holes in a shelf – You.
Create a Halloween Computer Game in Scratch Stephanie Smullen and Dawn Ellis Barb Ericson October 2008.
1 Arrays of Arrays An array can represent a collection of any type of object - including other arrays! The world is filled with examples Monthly magazine:
AD 305 Electronic Visualization I : School of Art and Design : University of Illinois at Chicago : Spring 2007 Action Script 12 "The games of a people.
Video in Macromedia Flash (Optional) – Lesson 121 Video in Macromedia Flash (Optional) Lesson 12.
Jens Krüger & Polina Kondratieva – Computer Graphics and Visualization Group computer graphics & visualization GameFX C# / DirectX 2005 The Rendering Pipeline.
Chi-Cheng Lin, Winona State University CS430 Computer Graphics Rendering Pipeline and Primitive Rasterization.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Starting Out with Games & Graphics in C++ Tony Gaddis Chapter 8 The.
Chomp. How is the game played Human player goes first choose a square, all to the right and down are “eaten” computer takes a turn whoever is forced to.
More on Logic Today we look at the for loop and then put all of this together to look at some more complex forms of logic that a program will need The.
GAME:IT Mario Creating Platform Games Level 4 with GML Game Maker Language (GML) allows users more flexibility in game design. GML is similar to how real.
Creating a Simple Game in Scratch Barb Ericson Georgia Tech May 2009.
Game Maker Tutorials Introduction Clickball IntroductionClickball Where is it? Shooting Where is it?Shooting.
2D Graphics Optimizations
Create a Halloween Computer Game in Scratch
Scratch for Interactivity
Background Shapes & Collision Resolution (Top-down and Side-scrolling)
CS 134 More Graphics.
Frame Update, Level Representation & Graphics
Intro & Point-to-Box, Circle-to-Circle, Point-to-Circle
2D Viewing & Clipping 한신대 류승택
Programming the Web using XHTML and JavaScript
Controlling Layout with Style Sheets
WINDOWING AND CLIPPING
WINDOWING AND CLIPPING
Positioning.
Creating a Simple Game in Scratch
Game Programming Algorithms and Techniques
Presentation transcript:

CSE 380 – Computer Game Programming Player Controls & Scrolling Mega Man, by Capcom, released 1988

Game World A large virtual area Typically broken up into “levels” or “maps” Warcraft III maps: 6400 pixels X 6400 pixels While playing we: –only see a small portion –view the game through a “viewport” a window on the game

Viewport Game World Viewport

Moving the Viewport You must keep track of where in your world your viewport is. Ex: int viewportX, viewportY; –to scroll the game: update viewportX & viewportY each frame figure out what’s inside the viewport render those things relative to the viewport Don’t let viewportX become: –negative –more than World Width – Viewport Width Don’t let viewportY become: –negative –more than World Height – Viewport Height

Naïve Approach Move viewport precisely as player moves if (input->isKeyDown(W_KEY)) { vY = -PLAYER_SPEED; viewport.setY(viewport.getY() -PLAYER_SPEED); } What’s wrong with this?

When should we update the viewport? Right before rendering. After: –Getting and processing user input –Ai –Physics Why? –They may affect player position Scope viewport right before rendering

Scoping the Viewport How? –Depends on game genre –Ex: RTS may be independent of units Side-Scroller Goals: –follow the player –don’t let player out of viewport –make sure player sees important game objects –avoid a jittery viewport –scroll smoothly

Side-Scroller Viewport Strategy Offline: –determine target player location relative to viewport Each frame: –update viewport speed to smoothly catch up with target use gradually accelerating (up & down) viewport for even better look –update viewport location using speed and speed using acceleration

Targeting the Viewport

Our Viewport class class Viewport { private: int scrollSpeedX; int scrollSpeedY; int viewportX; int viewportY; int viewportWidth; int viewportHeight; int viewportOffsetX; int viewportOffsetY; NOTE: You may also choose to add a viewport target and acceleration

Visible Tiles Each frame, most tiles are not visible –so don’t try to draw them So, each frame: –for each layer: 1.test for visible tiles 2.add only those tiles to render list How should we test tiles for a tiled layer? How should we test tiles for sparse layer?

Which TiledLayer tiles are visible? What’s the visible left tile column? –viewportX / tileWidth What’s the visible right tile column? –(viewportX + Viewport Width) / tileWidth What’s the visible top tile row? –viewportY / tileHeight What’s the visible bottom tile row? –(viewportY + Viewport Height) / tileHeight

Where do you draw the tiles? We specify tiles in tile coordinates Suppose a tile is at location 2, 1 (column, row) If tiles are 64 pixels wide, in world coordinates: –64*2, 64*1 = (128, 64) If a tile is deemed visible, draw it at: –Tile’s world coordinatesX-viewportX, tile’s world coordinatesY-viewportY So, if the viewport is at 32, 32, draw the tile at: –(96, 32)

You with me?

What about clipping? We may end up with visible tiles partially outside the viewport We should draw portions of those textures visible

How about SparseLayer tiles? We have to check them one by one How can we test if a sparse tile (OverlayImage) is in the viewport? bool Viewport::areViewportCoordinatesInViewport( int x, int y, int width, int height)

bool Viewport::areViewportCoordinatesInViewport( int x, int y, int width, int height) { // IS IT OFF-SCREEN TO THE LEFT OF THE VIEWPORT? if((x + width) <= 0) return false; // IS IT OFF-SCREEN ABOVE THE VIEWPORT? else if((y + height) <= 0) return false; // IS IT OFF-SCREEN TO THE RIGHT OF THE VIEWPORT? else if (x >= viewportWidth) return false; // IS IT OFF-SCREEN BELOW THE VIEWPORT? else if (y >= viewportHeight) return false; // IT MUST BE AT LEAST PARTIALLY IN THE VIEWPORT else return true; }

Parallax Scrolling When background moves across screen at a slower pace than objects in foreground (like player) Why do this? –to give the illusion of distance How can we do this? –make parallax layer smaller than other layers –scroll parallax layer slower than other layers proportionally to size difference

Scrolling & the Player Let’s rethink scrolling Player also likes to see where he/she is going If player is looking/running right: –scroll right until player is in left 1/3 of viewport If player is looking/running left –scroll left until player is in right 1/3 of viewport