Game Loop Update & Draw.

Slides:



Advertisements
Similar presentations
Summer Computing Workshop. Introduction to Variables Variables are used in every aspect of programming. They are used to store data the programmer needs.
Advertisements

Understanding an Apps Architecture ASFA Computer Science: Principles Fall 2013.
Teaching with Greenfoot
Video Game Design Lesson 1. Game Designer Person involved in the development of a video game Person involved in the development of a video game Usually.
Game Design and Programming. Objectives Classify the games How games are design How games are implemented What are the main components of a game engine.
SE320: Introduction to Computer Games Week 8: Game Programming Gazihan Alankus.
GAME:IT Junior Bouncing Ball Objectives: Create Sprites Create Sounds Create Objects Create Room Program simple game.
Abstract # 0000 Make the Main Title with Large Bold Type Your Name Here Your Department Here Texas A&M Health Science Center Make the Main Title with Large.
Chapter 9 Introduction to ActionScript 3.0. Chapter 9 Lessons 1.Understand ActionScript Work with instances of movie clip symbols 3.Use code snippets.
Photoshop Backgrounds, Buttons, Banners & Animation In PowerPoint Presentations.
Lua & Love2D Game Engine GALAGUH
Introduction to TouchDevelop
Introduction to Arrays. definitions and things to consider… This presentation is designed to give a simple demonstration of array and object visualizations.
By the end of this session you should be able to...
Programming Video Games
Game Maker Terminology
Making Python Pretty!. How to Use This Presentation… Download a copy of this presentation to your ‘Computing’ folder. Follow the code examples, and put.
“The perfect project plan is possible if one first documents a list of all the unknowns.” Bill Langley.
Reference: The Game Loop Animation / Game loop 1. Update variables 2. [Get input from the user] (GameLoop only) 3. Draw (using variables)
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.
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.
Objective of the lesson Use Blockly to make a dice for Snakes and Ladders All of you will: – Make an image which displays when you press a button Most.
Game Maker Tutorials Introduction Clickball IntroductionClickball Where is it? Shooting Where is it?Shooting.
Learning to use a ‘For Loop’ and a ‘Variable’. Learning Objective To use a ‘For’ loop to build shapes within your program Use a variable to detect input.
Output THE BASICS. What is Output? Output is the information that comes FROM a computer OUT to a user Sometimes this information is feedback to an action.
Unit 2 Technology Systems
Multimedia Design.
Computer Fundamentals 1
Graphical Output Basic Images.
Animation Frame Animation.
MOM! Phineas and Ferb are … Aims:
Sound Music & Sound Effects.
PYGAME.
FOP: Buttons and Events
Introduction to presentations ms PowerPoint
Graphical Output Graphical Text.
A Tutorial on How to Turn PowerPoint Presentations into Slideshows
Computer Programming I
Understanding an App’s Architecture
PowerPoint: Tables and Charts
Lesson Two: Everything You Need to Know
Functions CIS 40 – Introduction to Programming in Python
Explain what touch develop is to your students:
Chapter 16 – Programming your App’s Memory
Problem Solving (design of programs) CS140: Introduction to Computing 1 8/26/13.
The Basics of Microsoft Word 2007 Excel
Learning to program with Logo
Basic Graphics Drawing Shapes 1.
Print slides for students reference
Game Loop Frame Rate.
Unreal Engine and C++ We’re finally at a point where we can start working in C++ with Unreal Engine To get everything set up for this properly, we’re going.
Working with Arduino: Lesson #1: Getting Acquainted with the Kit
Introduction to TouchDevelop
Variables ICS2O.
Organizing Memory in Java
Subprograms Intro & Procedures.
PC01 Term 3 Project Snake. PC01 Term 3 Project Snake.
Introduction to TouchDevelop
Module 4 Loops.
Problem Solving Designing Algorithms.
The Basics of Microsoft Word 2007 Excel
Using screens and adding two numbers - addda.cbl
Lecture 9 Announcements.
IPC144 Introduction to Programming Using C Week 4 – Lesson 1
IPC144 Introduction to Programming Using C Week 4 – Lesson 2
User Input Keyboard input.
Using Animation and Multimedia
Creating a Simple Game in Scratch
The beginning of media computation Followed by a demo
Animation Translation.
Presentation transcript:

Game Loop Update & Draw

Heart of the Game Loop Most of the work in every video game stems from the Update command Update is made up of a series of operations, often held in other code blocks (subprograms) for readability purposes: Check for User Input (keyboard, mouse, etc.) If input is found, trigger any needed actions. For example, start a jump animation or pause the game Update Game Data (largest part with many pieces): Update locations for moving game elements like players, bullets, etc. Update animation frames for each element as needed Apply any physics (gravity, acceleration, etc.) Check for collisions Apply in game data changes, e.g. health, scores, game state, etc. Play any sounds that are requested from any of the previous update actions Not all games will need all of these Update operations

Draw the Results The Draw command is simply a visual representation of the data just updated. For example you could play a game of Snakes and Ladders without a board while the game simply told you in text what space number you were on. The graphics are the way we bring our games to life but they have no logic of their own. Draw simply displays what the data currently stores. If the data says a player’s score is 1000 points, then that is what is displayed. The only exception to the “no-logic” rule is game states. For example Draw will display something completely different in the Menu state than it will in the Play or Highscore states. Like Update there is a sequence of commands to ensure a standard result: Draw background images Draw middle ground images (characters, enemies, items, etc.) Draw foreground images (typically environment images for depth, bushes, clouds, etc.) Draw the Heads Up Display (HUD) (life bars, scores, inventory, overlaid menus, etc.)

The Java Game Engine Java is simply a programming language, as such, some languages are more difficult to make games in than others. Java is one of those more challenging ones. To aid in your game creation, your teachers have built a game engine that handles a lot of the complex operations for you. The most important of these is the Game Loop. When using this Game Engine and the premade Game project you will find a starting point. This starting point has a few sections of code you need to work with, which we will discuss in the next few slides

Global Variables Up until now we have asked you to keep your variables local whenever possible, however when building games and using a Game Loop, this is not always an option. Because a typical Game Loop runs at 60 FPS, If you were to define a new variable inside the Update command that means you will be redefining that variable 60 times per second needlessly. Therefore, if you will need a variable throughout the game, such as playerScore, it should be created as a global non-static variable: e.g. private int score = 0; Ideally, your global definitions will be placed just below this code block

The main Up until now, you have done all of your work in main When building games you will only use this code block to setup the look of your game: Game Name: The text that will show in the window border Game Width: The width of the game screen, using the global variable screenWidth here will give you the whole width of the monitor Game Height: The height of the game screen, you can also use screenHeight FPS: The frame rate for your game

Load Content The LoadContent section has a straight-forward purpose. It is a block of code that is executed only ONCE at the beginning of the Game Loop. This is where you will perform 2 actions: Load any media, images, sounds, video etc. Setup any starting data values like scores, game state, player locations, etc.

Update Update is one of the two code blocks that is part of the Game Loop, it is therefore repeated once for each frame of the Game Loop Keep this in mind and be aware that every action you do in here is executed A LOT. If your game slows down it is typically here you will need to look to solve the problem. Remember, this is where you will update all game components. However, note the highlighted area below. This is the code that calls the LoadContent code and should NOT be touched by yourself unless you truly know what you are doing. Also, notice the deltaTime variable, this holds the amount of time passed since the last Update, in milliseconds. This can be useful during animation and physics processing.

Draw Draw is the second and last code block that is executed as part of the Game Loop Again, remember that every command you put here is repeated for every frame of the game. Recall that only Drawing code should go here with the one exception of game state logic.

Conclusion Notice that you actually do not see the Game Loop in the program. This is because the logic of its execution exists elsewhere. In future lessons you will see that there are a number of components in the Game Engine to help you with everything from drawing lines to performing complex animation For now, know that there is one other tool that you will find helpful, the Helper. Inside the Helper library exists a number of premade items and commands for you, including a set of Colours, a random number generator and some Color creation commands to build your own custom colours. To use this functionality, in your program simply type Helper.  including the dot and you will see all the options popup for you to choose from. E.g. Store a random number between 1 to 10 in the a variable, randomNum randomNum = Helper.RandomValue(1,10);