Where are we ? Setup Sprites Input Collision Drawing Sprites

Slides:



Advertisements
Similar presentations
Basics of Inheritance CS 5010 Program Design Paradigms "Bootcamp" Lesson 12.1 © Mitchell Wand, This work is licensed under a Creative Commons.
Advertisements

©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 9 Distributed Systems Architectures Slide 1 1 Chapter 9 Distributed Systems Architectures.
Observer Method 1. References Gamma Erich, Helm Richard, “Design Patterns: Elements of Reusable Object- Oriented Software” 2.
Computer Science – Game DesignUC Santa Cruz Common Bounding Volumes Most introductory game programming texts call AABBs simply “bounding boxes” Circle/SphereAxis-Aligned.
SWE 4743 Strategy Patterns Richard Gesick. CSE Strategy Pattern the strategy pattern (also known as the policy pattern) is a software design.
Component Patterns – Architecture and Applications with EJB copyright © 2001, MATHEMA AG Component Patterns Architecture and Applications with EJB JavaForum.
Computer Science – Game DesignUC Santa Cruz Today Publish/Subscribe Design Pattern Delegates Sprite movement Particles.
Computer Science – Game DesignUC Santa Cruz Game Jam Two teams from CMPS 20 – Less Than Royal – Colon Trey.
Reza Gorgan Mohammadi AmirKabir University of Technology, Department of Computer Engineering & Information Technology Advanced design.
Delegates & Events Observer and Strategy Patterns Game Design Experience Professor Jim Whitehead January 30, 2009 Creative Commons Attribution 3.0 creativecommons.org/licenses/by/3.0.
Particle Systems Final Exam Study Guide Game Design Experience Professor Jim Whitehead March 16, 2009 Creative Commons Attribution 3.0 (Except copyrighted.
Exam Questions Chain of Responsibility & Singleton Patterns Game Design Experience Professor Jim Whitehead February 4, 2009 Creative Commons Attribution.
Behavioral Patterns  Behavioral patterns are patterns whose purpose is to facilitate the work of algorithmic calculations and communication between classes.
CS 325: Software Engineering March 17, 2015 Applying Patterns (Part A) The Façade Pattern The Adapter Pattern Interfaces & Implementations The Strategy.
GoF Design Patterns (Ch. 26). GoF Design Patterns Adapter Factory Singleton Strategy Composite Façade Observer (Publish-Subscribe)
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.
Unit 4 Object-Oriented Design Patterns NameStudent Number CAI XIANGHT082182A KYAW THU LINHT082238Y LI PENGFEIHT082220L NAUNG NAUNG LATTHT082195L PLATHOTTAM.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns VIII Chain of Responsibility, Strategy, State.
Point Sprites Course Information CVG: Programming 4 My Name: Mark Walsh Website: Recommended.
OO Methodology Elaboration Iteration 2 - Design Patterns -
Behavioral Patterns1 Nour El Kadri SEG 3202 Software Design and Architecture Notes based on U of T Design Patterns class.
Introduction to Object-Oriented Programming Lesson 2.
The State Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
CHAPTER 14 Classes, Objects, and Games XNA Game Studio 4.0.
Component Patterns – Architecture and Applications with EJB copyright © 2001, MATHEMA AG Component Patterns Architecture and Applications with EJB Markus.
Graphics for Games Particle Systems CO2301 Games Development 1 Week 23.
Distributed Systems Architectures Chapter 12. Objectives  To explain the advantages and disadvantages of different distributed systems architectures.
Distributed Systems Architectures. Topics covered l Client-server architectures l Distributed object architectures l Inter-organisational computing.
Microsoft Foundation Classes MFC
OOP - Object Oriented Programming
Design Patterns: MORE Examples
CHAPTER
The Movement To Objects
N-Tier Architecture.
Chapter 10 Design Patterns.
MPCS – Advanced java Programming
Unified Modeling Language
Behavioral Design Patterns
UML Sequence Diagrams (Slides adapted from Michael Mateas)
Java Beans Sagun Dhakhwa.
Delegates and Events 14: Delegates and Events
Observer Design Pattern
CMPE 135: Object-Oriented Analysis and Design October 24 Class Meeting
CS101 Introduction to Computing Lecture 19 Programming Languages
Distribution and components
object oriented Principles of software design
Chapter 16 – Programming your App’s Memory
Presented by Igor Ivković
GoF Design Patterns (Ch. 26). GoF Design Patterns Adapter Factory Singleton Strategy Composite Façade Observer (Publish-Subscribe)
Advanced Programming Behnam Hatami Fall 2017.
C# Event Processing Model
OOP Paradigms There are four main aspects of Object-Orientated Programming Inheritance Polymorphism Abstraction Encapsulation We’ve seen Encapsulation.
“The Trouble with Observer” and “Visitor Revisited”
Model-View-Controller Patterns and Frameworks
Introduction to Behavioral Patterns (1)
Software Architecture
An Introduction to Software Architecture
DESIGN PATTERNS : Strategy Pattern
SAMANVITHA RAMAYANAM 18TH FEBRUARY 2010 CPE 691
GoF Design Patterns (Ch. 26)
Design pattern Lecture 9.
CMPE 135 Object-Oriented Analysis and Design March 21 Class Meeting
OBJECT ARCHITECTURE DESIGN
CS 325: Software Engineering
Model, View, Controller design pattern
Designing For Testability
Chapter 22 Object-Oriented Systems Analysis and Design and UML
Object-Oriented PHP (1)
Games Development Game Architecture: Entities
Presented by Igor Ivković
Presentation transcript:

Where are we ? Setup Sprites Input Collision Drawing Sprites Initializing, loading, movement Parameters (color, alpha, scale, etc.) Input Get input and respond to input Collision Drawing Sprites

Next Advanced movement Code organization Various types of automatic movement Code organization Software design patterns Organizing movement code Particle Systems (if we have time) Lots of moving sprites

Movement Sprite movement example

Problem: Changing AI Behavior Consider: AI behavior of an opponent often changes while the game is running If it gets close to the player, or some other game event occurs How can this be accomplished in code? Do not want to destroy opponent object, and create new one with changed AI behavior I.e., creating a separate subtype of Opponent for each separate opponent behavior isn’t dynamic enough However, also do not want to encode all possible behaviors inside each type of opponent Ideally want to re-use AI behaviors across many types of opponent I.e., putting a big switch/case statement inside each Opponent type won’t work either “Switch statement” and “duplicate code” bad code smells

Strategy Pattern Client creates instance of IStrategy subclass <<interface>> IStrategy IStrategy myStrategy; + Algorithm() StrategyA StrategyB Client creates instance of IStrategy subclass myStrategy = new IStrategySubclass(); Or, can be given subclass instance in constructor Inside the client, write code that relates only to IStrategy myStrategy.Algorithm(); Will call the Algorithm method on subclass currently assigned to myStrategy

Design Principles Two design principles at play here Favor composition over inheritance More flexible to compose IStrategy subclass with Client than to make lots of Client subclasses Program to Interfaces, not implementations If you program to an interface, are not tied to a specific class that implements the interface Can easily create another implementation of the interface, and use that instead If you program to an interface, substituting a new subclass of that interface is a small change

Reading Read: Chapter 12 (Delegates and Events) from pp. 255-270 in Programming C# 4.0

Publish/Subscribe Example Consider this: What if you could automatically find out when your out-of-town friend is in Santa Cruz? One could imagine your friend having a cell phone that roughly knows its position You could subscribe to a location service on your friend’s phone In fact, many people could subscribe to this service Your friend wouldn’t need to know in advance how many people this would be When your friend came into Santa Cruz, the phone would publish a message to you This is an example of a publish/subscribe (pub/sub) service

Publish/Subscribe In a pub/sub service: An event A notification A client subscribes to a service The service provider stores a list of subscribers When a particular event occurs, a notification message is published to all subscribers An event (in the general sense – C# events are in a few slides) A noteworthy change in state “A timely difference that makes a difference” A notification A message carrying the information that an event has occurred In-class acting out of pub/sub information flow

Publish/Subscribe Advantages Scalable Can easily add more subscribers Just add another subscriber to the list in the service provider Loose coupling When writing the service provider, do not need to know the complete set of potential future clients Only need to adhere to a specific interface (data passed with the notification) Service provider is completely decoupled from the clients In network-based pub/sub, clients and servers live on separate machines

Publish/Subscribe Disadvantages Transactional processing Client may want to treat a series of events as a conceptual whole (a transaction), but doesn’t know how many events it will receive in a row If events are being used to update a user interface, many events can lead to lots of small, jittery changes to the UI Complicates information flow The information a client needs is not always found in the notification message. The client then needs to make further calls to get this information.

Publish/Subscribe Implementations Pub/Sub is a general information flow pattern Can be implemented in many ways Direct connection Subscribers directly subscribe to information sources Event message bus Notifications are sent to a third party, the message bus Clients subscribe to the message bus Service providers can come and go, but the clients don’t have to keep re-subscribing Local/Distributed Pub/sub can take place inside a local program, or across a network among several distributed programs In local programs, pub/sub frequently implemented using the Observer design pattern C# has a special language feature designed specifically for local pub/sub: delegates (and events)

Delegates A delegate contains a list of references to a method Must state the return type and parameters of the method List can contain 0, 1, or many method references Can think of a delegate as a typed function pointer Once a delegate is assigned a method, it behaves exactly like that method That is, you can perform method calls, via the delegate In the context of pub/sub systems, a delegate holds the list of subscribers That is, the list of methods to call when an event occurs

Defining and Using Delegates Define delegate type Specifies return type, parameters and their types Create instance of delegate type Assign method to instance Use = or += operators Use delegate to perform method calls on stored method references Might call more than one method! // Define delegate type [visibility] delegate [return type] delegate_name ([params]); // Use example class Subject { // Create delegate type "notifier" public delegate void notifier(string message); // Create instance of "notifier" type, called myNotifier public notifier myNotifier; public void update(string message) // Check if delegate instance is null // Then call delegate (calls all methods currently // referenced by the delegate) if (myNotifier != null) // might be calling more than one method! myNotifier(message); }

Observer Pattern The name given to an object-oriented, local implementation of publish-subscribe Subject Holds list of subscribed observers in a delegate Change of state in Subject leads to call on delegate Acts as a notification to observers of change of state Observer Subscribes to subject instances it is interested in Supplies method to be called upon notification

Particle Systems

Particle Systems A particle system is a technique for modeling “fuzzy” things Used to simulate explosions, fire, smoke, flowing water, sparks, fog, snow, and others A large number of small moving particles combine together to create the effect www.cgtutorials.com www.cgtutorials.com

Particle Engine Particle Entity: Simple, contains information about position, mass, speed, acceleration, age… Particle system: Contains a group of particles and rules of how they will behave. Emitter: Way of creating the particles Integrator: Particles “Update()” Particle Engine: Group of N particle systems Particle Particle System Particle Particle Engine Particle Particle System Particle

Parameters of a Particle System Emitter location in space that acts as the source of the particles Spawning rate How many particles generated per unit time Initial velocity vector Direction and speed of particles when created Particle lifetime How long the particles last Particle color Color of each particle Can also texture map Often values are specified as a center value, with allowable variation Lifetime is 60 ticks +/-20 ticks