L ECTURE 6 Announcements. Next week will be great! Three major things are happening next week: – Zynga guest lecture – Your game pitches (more details.

Slides:



Advertisements
Similar presentations
Identity and Equality Based on material by Michael Ernst, University of Washington.
Advertisements

Singleton vs utility class  at first glance, the singleton pattern does not seem to offer any advantages to using a utility class  i.e., a utility class.
Inheritance. Extending Classes It’s possible to create a class by using another as a starting point  i.e. Start with the original class then add methods,
1 Java Object Model Part 2: the Object class. 2 Object class Superclass for all Java classes Any class without explicit extends clause is a direct subclass.
Inheritance Part II. Lecture Objectives To learn about inheritance To understand how to inherit and override superclass methods To be able to invoke superclass.
CHAPTER 10 Recursion. 2 Recursive Thinking Recursion is a programming technique in which a method can call itself to solve a problem A recursive definition.
A tour around Java General introduction to aspects of the language (these will be covered in more detail later) After this tour you should have a general.
SE320: Introduction to Computer Games Week 8: Game Programming Gazihan Alankus.
L ECTURE 6 Announcements. Tou II Feedback handins look varied and fun! Write a Range or Interval class – makes math code easier to read write modify –
GETTING INPUT Simple I/O. Simple Input Scanner scan = new Scanner(System.in); System.out.println("Enter your name"); String name = scan.nextLine(); System.out.println("Enter.
CS2110 Recitation Week 8. Hashing Hashing: An implementation of a set. It provides O(1) expected time for set operations Set operations Make the set empty.
L ECTURE 7 Announcements. Feedback for M 1 Some of you had stacking shapes The stack maybe exploded eventually Don’t worry, stacking boxes is hard to.
(c) University of Washingtonhashing-1 CSC 143 Java Hashing Set Implementation via Hashing.
1 Inheritance and Polymorphism Chapter 9. 2 Polymorphism, Dynamic Binding and Generic Programming public class Test { public static void main(String[]
CS 240 Week 3. List’Em java Grep [-r] directoryName fileSelectionPattern substringSelectionPattern Run Demo java LineCount [-r] directoryName fileSelectionPattern.
Searching Also: Logarithms. 2 Searching an array of integers If an array is not sorted, there is no better algorithm than linear search for finding an.
L ECTURE 5 Announcements. Tou II Feedback handins look varied and fun! write a Range or Interval class – makes math code easier to write read modify –
1 Object-Oriented Software Engineering CS Interfaces Interfaces are contracts Contracts between software groups Defines how software interacts with.
Polymorphism, Inheritance Pt. 1 COMP 401, Fall 2014 Lecture 7 9/9/2014.
The Java Collections Framework (Part 2) By the end of this lecture you should be able to: Use the HashMap class to store objects in a map; Create objects.
Lecture 8: Object-Oriented Design. 8-2 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET Objectives “Good object-oriented programming is really.
Chapter 1 - Getting to know Greenfoot
CS/ENGRD 2110 SPRING 2015 Lecture 6: Consequence of type, casting; function equals 1.
Sets, Maps and Hash Tables. RHS – SOC 2 Sets We have learned that different data struc- tures have different advantages – and drawbacks Choosing the proper.
HashCode() 1  if you override equals() you must override hashCode()  otherwise, the hashed containers won't work properly  recall that we did not override.
Overriding toString()
CS305j Introduction to Computing Classes II 1 Topic 24 Classes Part II "Object-oriented programming as it emerged in Simula 67 allows software structure.
Application development with Java Lecture 21. Inheritance Subclasses Overriding Object class.
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 9.1 – 9.4.
More on Objects Mehdi Einali Advanced Programming in Java 1.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Peyman Dodangeh Sharif University of Technology Spring 2014.
(c) University of Washington06-1 CSC 143 Java Inheritance Tidbits.
CSE 143 Lecture 13 Recursive Backtracking slides created by Ethan Apter
CSI 3125, Preliminaries, page 1 Inheritance. CSI 3125, Preliminaries, page 2 Inheritance Using inheritance, can create a general class that defines traits.
CSC142 NN 1 CSC 142 Overriding methods from the Object class: equals, toString.
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
Quicksort This is probably the most popular sorting algorithm. It was invented by the English Scientist C.A.R. Hoare It is popular because it works well.
Reference Types CSE301 University of Sunderland Harry R Erwin, PhD.
COMP Inheritance and Polymorphism Yi Hong June 09, 2015.
Announcements Assignment 2 Out Today Quiz today - so I need to shut up at 4:25 1.
Lecture 5:Interfaces and Abstract Classes Michael Hsu CSULA.
 2016, Marcus Biel, Marcus Biel, Software Craftsman Identity vs Equality in Java
XuanTung Hoang 1 Something to discuss Feedbacks on Midterm Exam Final exam and term project  Final exam requires solid knowledge/skills in Java  Be more.
Lecture 6:Interfaces and Abstract Classes Michael Hsu CSULA.
Catie Welsh April 18,  Program 4 due Wed, April 27 th by 11:59pm  Final exam, comprehensive ◦ Friday, May 6th, 12pm  No class Friday - Holiday.
GAME TESTING REQUIREMENTS AND METHODS GAME DESIGN.
Background Shapes & Collision Resolution (Top-down and Side-scrolling)
CSC 205 Java Programming II
Lecture 3 Announcements.
Java Software Structures: John Lewis & Joseph Chase
CS 302 Week 11 Jim Williams, PhD.
Chapter 1: Computer Systems
Testing and debugging A short interlude 2-Dec-18.
Marcus Biel, Software Craftsman
Lecture 2 Announcements.
Building Java Programs
CSE 143 Lecture 24 Inheritance and the Object class; Polymorphism
Sets, Maps and Hash Tables
Lecture 5 Announcements.
CSC8503 Revision Lecture.
Fall 2018 CISC124 2/24/2019 CISC124 Quiz 1 marking is complete. Quiz average was about 40/60 or 67%. TAs are still grading assn 1. Assn 2 due this Friday,
Testing and debugging A short interlude 17-Apr-19.
CSE 142 Lecture Notes Defining New Types of Objects, cont'd.
CSE 143 Lecture 24 Inheritance and the Object class; Polymorphism
CSE 143 Lecture 24 Inheritance and the Object class; Polymorphism
CSE 143 Lecture 23 Inheritance and the Object class; Polymorphism
CMPE212 – Reminders Assignment 2 due next Friday.
Presentation transcript:

L ECTURE 6 Announcements

Next week will be great! Three major things are happening next week: – Zynga guest lecture – Your game pitches (more details later) – Christina Paxson

Feedback for M 1 Some of you had stacking shapes The stack probably exploded eventually Don’t worry, stacking boxes is hard to do properly This week’s lecture will help but not alleviate the problem

Feedback for M 1 Sometimes shapes would settle overlapping other shapes Two possible causes: – Not translating enough – Doing collision response before integration, hence drawing before translating

QUESTIONS? Announcements

L ECTURE 6 Physics II

M1 Collision Response You obtained MTV in M1, how did you use it? – Move things out of collision – Apply some impulse along MTV – It probably worked most of the time, or only if you modeled specific behavior – Other times the response is weird

Controlling Impulse Want more realistic collisions Two things to do: – Support a range of collision behavior – Determine the physically correct collision result Also need to be able to code it void onCollide(Collision col) { Shape o1 = col.shape1; Shape o2 = col.shape2; Vec2f mtv = col.mtv; o1.move(mtv.smult(0.5f)); o2.move(mtv.smult(-0.5f)); //code to calculate impulse o1.applyImpulse(imp1); o2.applyImpulse(imp2); }

Restitution

Correct Collisions

Translation to Code Once we determine what the final velocities of the objects should, how do we apply this? Impulse or velocity setting? – Setting velocity affects other collision response calculations

Translation to Code We determined what the final velocities of the objects should, how do we apply this? Impulse > velocity setting – Setting velocity affects other collision response calculations

Translation to Code We determined what the final velocities of the objects should, how do we apply this? Impulse > velocity setting – Setting velocity affects other collision response calculations

Translation to Code

Final Velocities

Velocity Difference

Final Impulse

Static Shapes

Note about Velocity

Putting it all together Physically correct collision response: 1.Calculate COR with the restitutions of the shapes 2.Project velocities onto MTV 3.Apply impulse formula to calculate impulses 4.Apply corresponding impulse to each shape

QUESTIONS? Physics II

L ECTURE 6 Raycasting

What is raycasting? Determine the first object that a ray hits A ray is like a ray of light, has a source and direction and goes on forever It’s like a camera (or eye)

Raycasting Uses When would we need to raycast? – Hitscan weapons – Line of sight for AI – Area of effect – Rendering

The Ray

Basics Raycasting boils down to finding the intersection of a ray and shapes Kind of like collision detection all over again You want the point of collision as well

Ray-Circle

Ray-Polygon/AAB A polygon/AAB is composed of edges We can check for intersection of ray by checking for intersection of all edges There is no shortcut for AABs this time

Ray-Edge

Ray-Polygon

Putting it all together Raycasting: 1.Intersect ray with every shape in the world 1.For circles, use the circle-ray algorithm in the slides 2.For polygons, intersect each edge and use the closest 2.Keep track of closest intersection point from the source as well as the corresponding shape

QUESTIONS? Raycasting

L ECTURE 6 Final Project Overview

Overview Can be any 2D game and engine You can work in groups if you want Each person is responsible for 10 “points” worth of new engine features – More members in a group means more engine features – More details in the final project handout

Timeline 4 main parts: – Week 1: Idea – Week 2: Form groups and get approved – Week 3: Design – Weeks 4-8: Code, playtest, polish, present

Week 1: Idea A ½ to 1 page document Describe basic gameplay idea – How is your game fun? Describe engine feature(s) you plan on implementing Give a 60-second “elevator pitch” of your game in class

Week 2: Groups Form a group (or decide to work alone) Finalize game and engine features Each group must meet with a TA to present the following: – A more polished idea of the game – Breakdown of member responsibilities for engine

Week 3: Design Research new engine features Design the engine and game Exact breakdown of member responsibilities Choose someone’s engine to use or integrate engines For groups of 3 or more – Explain how you will use version control

Weeks 4-8 Week 4: – Engine should be mostly done – Game exists Week 5: – Engine should be done – Game is playable – 5 playtests per member from people not in CS195n

Weeks 4-8 Week 6: – Game should be mostly done – 5 more playtests per member from outsiders Week 7: – Game should be done – 5 playtests per member – Powerpoint slideshow for postmortem presentation

Weeks 4-8 Week 8: – Polish up your game, bug fixes, etc – Create an executable and put it in /contrib – Make a video demo of your game from gameplay footage It is now December 19 th And then you’re done!

QUESTIONS? Final Project Overview

L ECTURE 6 Tips for M II

Raycasting Groups Similar to collision groups Some objects shouldn’t be raycasted on, just like some objects are not meant to be collided Special case: the source – If you’re raycasting from a shape, you don’t want to check the shape itself

Jumping Properly Extra requirement this week: player can jump once iff standing on a solid object Use information from your collision response object! If the MTV points downwards, then the player has hit something solid below it – Player is now allowed to jump

Fixed Timestep Most of you will have noticed weird behavior when you fullscreen/resize It screws around with the nanosSincePrevTick Solution: fixed timestep – Give the physics world some constant time when ticking – Tick as many times as possible on each game tick

JAVA TIP OF THE WEEK Tips for M II

Methods of Object Object has a few methods that you should know/care about: – hashCode() – equals(Object o) – toString() public class Object { int hashCode(); boolean equals(Object obj){ return (this == obj); } Object clone(); String toString(); }

toString Called whenever you use the object as a string You should override this in your classes to return meaningful strings – It’s worth doing if you debug with printlines See Vec2f for examples public class Object { public String toString(){ return getClass().getName() + + hashCode(); } } public class PhoneNumber { public String toString(){ return “(” + _areacode + “)” + _number; } }

equals Determines if object is equal to another object The default method compares references – Doesn’t work if you want equal but not the same object (e.g. String) public class Object { boolean equals(Object obj){ return (this == obj); } }

equals To override: – Use default check first – Check if instanceof – Cast to object – Compare things You can access fields directly! public class Book { String author; String title; boolean equals(Object obj){ if (this == obj) return true; if (!(obj instanceof Book)) return false; Book o = (Book) obj; return o.author.equals(author) && o.title.equals(title); } }

Contract of equals A few things must be true about your equals(): – o.equals(o) must be true – o.equals(null) is always false – must be symmetric – must be transitive – o1.equals(o2) changes only if o1 or o2 changes public class Book { String author; String title; boolean equals(Object obj){ if (this == obj) return true; if (!(obj instanceof Book)) return false; Book o = (Book) obj; return o.author.equals(author) && o.title.equals(title); }

hashCode Returns the hash of the object This value is used by Java’s Map data structures You must override hashCode if you override equals – Otherwise data structures can do weird things public class Object { public int hashCode(); }

Contract of hashCode hashCode must return the same value for the same object unless it is changed If two objects are equal, they have the same hashCode If two objects are unequal, ideally they will have different hashCode public class Object { public int hashCode(); }

Overriding hashCode Many ways of actually calculating hash of an object You can look them up if you want public int hashCode(){ int hash = 5; //prime int prime = 89; //prime hash = prime*hash + x; hash = prime*hash + y; hash = prime*hash + z; return hash; }

QUESTIONS? Tips for M II

M I PLAYTESTING ! Hooray!