2D Collision Response For CSE 3902 By: Matt Boggus.

Slides:



Advertisements
Similar presentations
Observer Method 1. References Gamma Erich, Helm Richard, “Design Patterns: Elements of Reusable Object- Oriented Software” 2.
Advertisements

Matt Klein 7/2/2009.  Intent  Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request.
Reza Gorgan Mohammadi AmirKabir University of Technology, Department of Computer Engineering & Information Technology Advanced design.
Module: Definition ● A logical collection of related program entities ● Not necessarily a physical concept, e.g., file, function, class, package ● Often.
BehavioralCmpE196G1 Behavioral Patterns Chain of Responsibility (requests through a chain of candidates) Command (encapsulates a request) Interpreter (grammar.
Basic Building Blocks of Programming. Variables and Assignment Think of a variable as an empty container Assignment symbol (=) means putting a value into.
Fundamentals of Python: From First Programs Through Data Structures
Lilian Blot Announcements The TPOP problem class this afternoon:  group 1 should come at 3.30pm and group 2 at 4pm. Teaching Evaluation Form  week 9.
Behavioral Patterns C h a p t e r 5 – P a g e 128 BehavioralPatterns Design patterns that identify and realize common interactions between objects Chain.
Chapter 7 Designing Classes. Class Design When we are developing a piece of software, we want to design the software We don’t want to just sit down and.
Behavioral Patterns  Behavioral patterns are patterns whose purpose is to facilitate the work of algorithmic calculations and communication between classes.
© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1 Reactor Design Patterns: Command and Observer.
Simplifying Rational Expressions. Simplifying a Fraction Simplify: The techniques we use to simplify a fraction without variables (Finding the greatest.
1 Software Construction and Evolution - CSSE 375 Exception Handling - Principles Steve Chenoweth, RHIT Above – Exception handling on the ENIAC. From
1 Chapter Eleven Handling Events. 2 Objectives Learn about delegates How to create composed delegates How to handle events How to use the built-in EventHandler.
Design Patterns CSCI 5801: Software Engineering. Design Patterns.
PHY281Flow ControlSlide 1 Decisions In this section we will learn how to make decisions in a Java program  if Statements  if... else Statements  Comparison.
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
CSE 425: Control Flow I Categories of Control Flow Constructs Sequencing –order of expressions and statements Selection –if, else, switch Iteration –loops.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns VIII Chain of Responsibility, Strategy, State.
Additional Design Patterns for Games For CSE 3902 Matt Boggus.
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University The Strategy Pattern.
DESIGN PATTERNS -BEHAVIORAL PATTERNS WATTANAPON G SUTTAPAK Software Engineering, School of Information Communication Technology, University of PHAYAO 1.
Designing Classes. Software changes Software is not like a novel that is written once and then remains unchanged. Software is extended, corrected, maintained,
Behavioral Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
Behavioral Patterns1 Nour El Kadri SEG 3202 Software Design and Architecture Notes based on U of T Design Patterns class.
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 31. Review Creational Design Patterns – Singleton Pattern – Builder Pattern.
Objects First With Java A Practical Introduction Using BlueJ Designing classes How to write classes in a way that they are easily understandable, maintainable.
1 Why Threads are a Bad Idea (for most purposes) based on a presentation by John Ousterhout Sun Microsystems Laboratories Threads!
Model View ViewModel Architecture. MVVM Architecture components.
Overview of Behavioral Patterns ©SoftMoore ConsultingSlide 1.
Control Structure  What is control Structure?  Types of Controls  Use the control structure in VBScript.  Example Summery.
C Program Control September 15, OBJECTIVES The essentials of counter-controlled repetition. To use the for and do...while repetition statements.
Recursion Powerful Tool
2D Collision Detection For CSE 3902 By: Matt Boggus.
Additional Design Patterns for Games
Threaded Programming in Python
Strategy Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014.
Chapter 7: User-Defined Functions II
Flowcharting Guidelines
Chapter Nine The Strategy Pattern
CS 326 Programming Languages, Concepts and Implementation
Delegates and Events 14: Delegates and Events
Chapter Eleven Handling Events.
Assembler Design Options
Transport Layer Unit 5.
PRACTICE OVERVIEW PL/SQL Part - 2.
Objects First with Java
Topics Introduction to File Input and Output
Jim Fawcett CSE776 – Design Patterns Summer 2003
Model-View-Controller Patterns and Frameworks
Variables ICS2O.
Chapter 7 Additional Control Structures
LL and Recursive-Descent Parsing Hal Perkins Autumn 2011
Visual Basic – Decision Statements
LL and Recursive-Descent Parsing
Design pattern Lecture 9.
Chapter 9: Value-Returning Functions
CSE451 Virtual Memory Paging Autumn 2002
Chapter 5 Decisions.
LL and Recursive-Descent Parsing Hal Perkins Autumn 2009
LL and Recursive-Descent Parsing Hal Perkins Winter 2008
Target Code Generation
Topics Introduction to File Input and Output
Functions Students should understand the concept and basic mechanics of the function call/return pattern from CS 1114/2114, but some will not. A function.
Lesson 3. Controlling program flow. Loops. Methods. Arrays.
Building pattern  Complete the following tables and write the rule 
GoF Patterns Ch. 26.
Strategy Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014.
Presentation transcript:

2D Collision Response For CSE 3902 By: Matt Boggus

Collision response organization options Response logic in client code Methods in Mario.cs Response logic encapsulated in dedicated classes MarioCollisionHandler MarioBlockHandler, MarioEnemyHandler, etc. AllCollisionHandler

Separation of concerns: collision detection vs. collision response Assume a collision detection class has already determined the type of collision (ICollision) Left Right Top Bottom None

Response logic in Mario Expect to see methods like: void HandleBlockCollision(Block block, ICollision side) void HandleEnemyCollision(IEnemy enemy, ICollision side) etc. Lowers cohesion and raises coupling of Mario class

Response logic in MarioCollisionHandler Still expect to see methods like: void HandleBlockCollision(Block block, ICollision side) void HandleEnemyCollision(IEnemy enemy, ICollision side) etc., assuming the class has a reference to mario stored in a field Mario class’ cohesion and coupling remains the same as before This class has high coupling

Response logic in MarioBlockCollisionHandler Now only expect to see the method: void HandleCollision(Mario mario, Block block, ICollision side) This class has high cohesion and low coupling That’s good! Similar to the state pattern, we increase the total number of classes and risk code duplication

Selecting the right collision handler Given generic storage, like List<IGameObject> gameObjects Decision making logic is required to determine the correct handler or methods Can we avoid branching statements (if, else, switch)?

AllCollisionHandler Consider a table of use cases

AllCollisionHandler Each use case has a specific response; we can encapsulate methods using Command objects. This makes a Dictionary that we can use for lookup. Note: passing the data needed to carry out these commands is easier said then done.

Relevant design patterns for collision detection and handling Visitor A way of separating an algorithm (handleCollision) from an object structure on which it operates (different types of GameObjects) Observer The subject (the collisionHandler), maintains a list of its dependents, called observers (the GameObjects), and notifies them automatically of any state changes, usually by calling one of their methods.