CSE 380 – Computer Game Programming AI & Collision Strategy Erin Catto’s Box2D.

Slides:



Advertisements
Similar presentations
GAME:IT Junior Learning Game Maker: The Score Tab.
Advertisements

Introduction to Macromedia Director 8.5 – Lingo
Summer Computing Workshop. Introduction to Variables Variables are used in every aspect of programming. They are used to store data the programmer needs.
Computer Science 101 While Statement. Iteration: The While-Statement The syntax for the While- Statement is while : The syntax for the While- Statement.
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.
CSE 380 – Computer Game Programming Collision Detection & Response Erin Catto’s Box2D.
Week 14 - Monday.  What did we talk about last time?  Bounding volume/bounding volume intersections.
CS 4730 Game Design Patterns CS 4730 – Computer Game Design Credit: Some slide material courtesy Walker White (Cornell)
Lecture 4: Objects and Classes Classes Objects Data fields (instance variables) Methods –Instance methods –Static methods –Constructors But first…
11 Chapter 4 LOOPS AND FILES. 22 THE INCREMENT AND DECREMENT OPERATORS To increment a variable means to increase its value by one. To decrement a variable.
Computer Science Jan 2011 Robot Game. Introduction to Robot Arcade game Collect all of the items while avoiding the enemy (robot) Objectives More extensive.
Lua & Love2D Game Engine GALAGUH
1 Chapter Eight Exception Handling. 2 Objectives Learn about exceptions and the Exception class How to purposely generate a SystemException Learn about.
Erin Catto Blizzard Entertainment Numerical Integration.
Symbol Tables Symbol tables are used by compilers to keep track of information about variables functions class names type names temporary variables etc.
CS 101: Arrays Abhiram Ranade. Computers manipulate many objects Given the position, masses, and velocities of all stars, where will they be after the.
Nachos Phase 1 Code -Hints and Comments
CSE 380 – Computer Game Programming Sprite Animation
CSE 380 – Computer Game Programming Box2D Box2D TestBed.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
User Input and Collisions COSC 315 Fall 2014 Bridget M. Blodgett.
CIS250 OPERATING SYSTEMS Memory Management Since we share memory, we need to manage it Memory manager only sees the address A program counter value indicates.
Debugging in Java. Common Bugs Compilation or syntactical errors are the first that you will encounter and the easiest to debug They are usually the result.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
Review 1.Lexical Analysis 2.Syntax Analysis 3.Semantic Analysis 4.Code Generation 5.Code Optimization.
CS 4730 Game Architecture CS 4730 – Computer Game Design Credit: Some slide material courtesy Walker White (Cornell)
UHD::3320::CH121 DESIGN PHASE Chapter 12. UHD::3320::CH122 Design Phase Two Aspects –Actions which operate on data –Data on which actions operate Two.
Game Maker Terminology
Min Chen School of Computer Science and Engineering Seoul National University Data Structure: Chapter 3.
Python. History of python  Python was conceived in the late 1980s and its implementation was started in December 1989 by Guido van Rossum at CWI in the.
JETT 2005 Session 5: Algorithms, Efficiency, Hashing and Hashtables.
AP Computer Science edition Review 1 ArrayListsWhile loopsString MethodsMethodsErrors
Additional Design Patterns for Games For CSE 3902 Matt Boggus.
Point Sprites Course Information CVG: Programming 4 My Name: Mark Walsh Website: Recommended.
CSE 380 – Advanced Game Programming Sweep & Prune.
File Input and Graphics An extract of slides from set 05_inout.ppt Designed to get you ready for the HW3.
Computer Science I Classes and objects Classwork/Homework: Examine and modify my examples. Make your own.
Using Lists Games Programming in Scratch. Games Programming in Scratch Extension – Using Lists Learning Objectives Create a temporary data store (list)
Dr Nick Mitchell (Room CM 224)
Graphics for Games Particle Systems CO2301 Games Development 1 Week 23.
Coding – Week 2 Functions, Arrays, and Objects. Functions  Functions are not a new concept – you’ve been using them already.  void setup() {} and void.
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
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.
String and Lists Dr. José M. Reyes Álamo. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list.
Function Recursion to understand recursion you must understand recursion.
Game Maker Tutorials Introduction Clickball IntroductionClickball Where is it? Shooting Where is it?Shooting.
CSE 332: C++ Exceptions Motivation for C++ Exceptions Void Number:: operator/= (const double denom) { if (denom == 0.0) { // what to do here? } m_value.
String and Lists Dr. José M. Reyes Álamo.
to understand recursion you must understand recursion
Additional Design Patterns for Games
Madlib-Input, Strings, and Lists in Scratch
Introduction To Repetition The for loop
Background Shapes & Collision Resolution (Top-down and Side-scrolling)
Learning Objective LO: We’re learning to understand when it is appropriate to use particular data types.
Arrays and Linked Lists
Use proper case (ie Caps for the beginnings of words)
Lesson 15: Processing Arrays
CH 9.2 : Hash Tables Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++, Goodrich, Tamassia and.
Coding Concepts (Basics)
String and Lists Dr. José M. Reyes Álamo.
Remembering lists of values lists
CH 9.2 : Hash Tables Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++, Goodrich, Tamassia and.
Week 6: Time and triggers!
Intro to Construct 2 Game Development
Fundaments of Game Design
Using a Queue Chapter 8 introduces the queue data type.
Using a Queue Chapter 8 introduces the queue data type.
Unit 3: Variables in Java
LOOPS The loop is the control structure we use to specify that a statement or group of statements is to be repeatedly executed. Java provides three kinds.
So you want to be a Game Designer
Presentation transcript:

CSE 380 – Computer Game Programming AI & Collision Strategy Erin Catto’s Box2D

The Big Picture Game::processGameLogic: void Game::processGameLogic() { // NOW PERFORM ALL AI ai->update(this); // NOW CORRECT FOR COLLISION DETECTION physics->update(this); // UPDATE THE WORLD, INCLUDING SPRITE AND // PARTICLE POSITIONS, FACTORING IN INPUT // AND AI world->update(this); } This should usually only change sprite velocities. Exception: spawning This will update position of all sprites This may do additional updates for special cases

So what’s our AI strategy? SpriteManager has access to all sprites –these are the only things that move –each frame we must test them against: each other collidable Background tiles User Input & AI –should typically only change a character’s velocity –there are exceptions of course (init positioning) Recommendation: –attach a Bot & BotType to each AnimatedSprite

One AI Possibility class AnimatedSprite HAS-A Bot instance variable class Bot HAS-A BotType instance variable –describes current AI state for sprite bot state, bot frame, bot counter, etc. –has an update method to update all variables updates sprite’s vX and vY, not position class BotType –describes a type of bot –types of states, state behaviors, etc. Each Frame, GameAI ’s update method: –goes through all sprites and calls update on bot

What about physics? Every time we detect a collision, we can store data about that event in one of these objects: class Collision { public: CollidableObject *co1; CollidableObject *co2; float timeOfCollision; float startTimeOfXCollision; float startTimeOfYCollision; float endTimeOfXCollision; float endTimeOfYCollision; };

Collision Construction Warning Each frame you’ll test for collisions You may find multiple collisions each frame You’ll want to store info about each collision in a Collision object. Why? –so you can sort them –use them to update the CollidableObjects DON’T construct new Collision objects each frame –recycle them instead

Recycling Collision objects When your game starts, construct an array of Collision objects. How many? –100 should do, make it 1000 to be over-safe –an array stack is easiest When a collision is detected: –take a collision object from array to use When collision resolved: –put it back

GamePhysics::update strategy 1.For each sprite: find all collisions with tiles, make a Collision object for each and compute time of collision. Add each Collision object to a collisions array 2.For each sprite, do the same as step 1 but for all Sprite-Sprite collisions 3.Sort the Collision array by time of collision 4.If collisions array is not empty, move all sprites to time of first collision (change their x, y according to vX, vY and % of frame) 5.Resolve collision (change vX, vY of sprites involved) …

GamePhysics::update strategy 6.Execute collision response code –Ex: sprite type 1 collides with sprite type 2, so reduce HP of sprite type 1 –this step may be combined with step 5. i.e., sometimes you might not want to change velocity of a sprite after collision 7.Remove all collisions from array involved in resolved collision 8.Perform steps 1 & 2 only for sprites involved in collisions Continue to do these steps until you reach the end of the frame NOTE: after each collision resolution, make sure the objects are not colliding. Why? –floating point error