Lecture 2 Announcements.

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming
Advertisements

SUMMARY: abstract classes and interfaces 1 Make a class abstract so instances of it cannot be created. Make a method abstract so it must be overridden.
Intersection Testing Chapter 13 Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology.
Collision Detection CSCE /60 What is Collision Detection?  Given two geometric objects, determine if they overlap.  Typically, at least one of.
Asteroids Games and Simulations O-O Programming in Java The Walker School The Walker School – Games and Simulations
Tutorial 4: Designing a Web Page with Tables
Introduction to 3D Graphics John E. Laird. Basic Issues u Given a internal model of a 3D world, with textures and light sources how do you project it.
Slides adapted from: Bjarne Stroustrup, Programming – Principles and Practice using C++ Chapter 12 A display model Hartmut Kaiser
Complex objects How might you design a class called NestedRects of graphical objects that look like this? Requirements for the constructor: –Like many.
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 –
Week 13 - Friday.  What did we talk about last time?  Ray/sphere intersection  Ray/box intersection  Slabs method  Line segment/box overlap test.
Shadows via Projection Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, November 5, 2003.
Game Maker – Getting Started What is Game Maker?.
L ECTURE 6 Announcements. Next week will be great! Three major things are happening next week: – Zynga guest lecture – Your game pitches (more details.
Digital Media Dr. Jim Rowan ITEC So far… We have compared bitmapped graphics and vector graphics We have discussed bitmapped images, some file formats.
Basic Perspective Projection Watt Section 5.2, some typos Define a focal distance, d, and shift the origin to be at that distance (note d is negative)
Slides adapted from: Bjarne Stroustrup, Programming – Principles and Practice using C++ Chapter 12 A display model Hartmut Kaiser
Collision Detection And Response Jae Chun KyungSoo Im Chau Vo Hoang Vu.
XNA Tutorial 1 For CS134 Lecture. Overview Some of the hard work has already been done for you. If you build and run your game now, the GraphicsDeviceManager.
Build your own 2D Game Engine and Create Great Web Games using HTML5, JavaScript, and WebGL. Sung, Pavleas, Arnez, and Pace, Chapter 6 Examples 1,
Game Maker Tutorials Introduction Clickball IntroductionClickball Where is it? Shooting Where is it?Shooting.
Lecture 9 From Vertices to Fragments. Objectives Introduce basic implementation strategies Clipping Rasterization hidden-surface removal.
Lecture 2 Announcements.
Model Optimization Wed Nov 16th 2016 Garrett Morrison.
Sound and more Animations
Chapter VII: Arrays.
What is a Function Expression?
CS/ENGRD 2110 Spring 2017 Lecture 7: Interfaces and Abstract Classes
Graphical Output Basic Images.
Pixels, Colors and Shapes
Computer Graphics Implementation II
3D Game Development and Computer Animation Collision Detection
Examining Two Pieces of Data
Inserting and Working with Images
Background Shapes & Collision Resolution (Top-down and Side-scrolling)
Intro & Point-to-Box, Circle-to-Circle, Point-to-Circle
Lecture 15: More Iterators
Lecture 1 Announcements.
Lecture 3 Announcements.
CS/ENGRD 2110 fall 2017 Lecture 7: Interfaces and Abstract Classes
Week 11 - Friday CS221.
COS 126 – Atomic Theory of Matter
Lesson 2: Building Blocks of Programming
Controlling Layout with Style Sheets
3D Rendering Pipeline Hidden Surface Removal 3D Primitives
MORE Cascading Style Sheets (The Positioning Model)
OOP Paradigms There are four main aspects of Object-Orientated Programming Inheritance Polymorphism Abstraction Encapsulation We’ve seen Encapsulation.
Digital Media Dr. Jim Rowan ITEC 2110.
Implementation II Ed Angel Professor Emeritus of Computer Science
Packages and Interfaces
Chapter 10 Algorithms.
COS 126 – Atomic Theory of Matter
COS 126 – Atomic Theory of Matter
Lecture 3 Announcements.
CS/ENGRD 2110 fall 2017 Lecture 7: Interfaces and Abstract Classes
Lecture 5 Announcements.
Topic 1: Problem Solving
Go to =>
Common Core Math I Unit 2: One-Variable Statistics Boxplots, Interquartile Range, and Outliers; Choosing Appropriate Measures.
A Case Study: Space Invaders
What you will learn today
Common Core Math I Unit 1: One-Variable Statistics Boxplots, Interquartile Range, and Outliers; Choosing Appropriate Measures.
COS 126 – Atomic Theory of Matter
Floating and Positioning
Introduction to Computer Graphics with WebGL
CSC 143 Java Errors and Exceptions.
CS210- Lecture 16 July 11, 2005 Agenda Maps and Dictionaries Map ADT
Exceptions 10-May-19.
Working with images and scenes
Implementation II Ed Angel Professor Emeritus of Computer Science
Presentation transcript:

Lecture 2 Announcements

Alchemy 1 is done! Initial feedback for Alchemy 1 Viewports are important – fix them now! Panning/moving should be done on tick Organize your projects well! If you’re unsure about your design, talk to a TA Keep our support code in a separate folder. Helps us grade. Next week your game will really start to take form!

Don’t Forget Tic Retries should all be returned Please send us an email after you handin any retry A few more tips for the future… Watch out for edge cases Plan out game/engine separation before you start

Announcements QUESTIONS?

Lecture 2 Graphics II

WHAT’S A SPRITE? Graphics II * This is a term you might have heard thrown around in game development

THIS IS A SPRITE

Sprites as Bitmap Data “Raster” graphics Pre-constructed images dynamically placed on the screen Designed to represent one type of object in a game Objects may reference different sprites depending on state They are bitmap data Arrays of pixels Images, if you will But more specific than images, they are “preconstructed”

Typical Sprite File Format Multiple sprites per file Additional information often (but not always) in config files: Padding Size Locations of a particular object’s sprites

Formatting “Standards”

Keep In Mind Bounding box info and sprite info should be separate But keep in mind that they will need to coordinate with each other Know what your hitboxes, hurtboxes, and bounding boxes for physics are for a specific frame of your animation

Graphics II IMPLEMENTING SPRITES

Sprite Loading You should only load a sprite sheet image once Each behavior using the sprite maintains a reference to the sprite sheet Consider making a Resource class which loads in sprite sheets Load in image Handling image index for different sprites Generalizable to other assets like maps, sounds, text, etc… You’re going to want load in sprites. But only want to do it once.

Drawing Sprites About g.drawImage(...) Rare exception to the no JavaFX rule: You’re going to need to make a JavaFX image. Pass the RELATIVE file path Your drawing routine should handle different padding and formats You’re going to want to draw sprites.

Relative Paths For All Resource Files: Don’t use absolute paths “/gpfs/main/home/<login>/course/cs1971/ta c/resources/spritesheet.png” is bad “resources/spritesheet.png” is good Absolute filepaths won’t work when we/your classmates try to test your game

Drawing Sprites Draw rectangular chunks from sprite sheet to the canvas Don’t cache sub images It isn’t worth the space/time tradeoff Remember to draw from your single sprite sheet reference * For drawing individual frames from a sprite sheet, what you’re doing is

SpriteBehavior Has a reference to sprite sheet resource Should implement draw(GraphicsContext g) Once it has a GraphicsContext object, it can draw itself * How do we incorporate sprites into our game objects?

TransformBehavior Where should the SpriteBehavior draw the image? How big should the image be? TransformBehavior- stores a position and size The TransformBehavior is special All game objects should have one, separate from their behavior list Position and size doesn’t need to only be used for drawing Probably for movement, physics as well

Graphics II QUESTIONS?

Lecture 2 Collision Detection I

Collision Detection I MOTIVATION

Collisions have consequences Collision detection is central to the vast majority off games They’re very important Collision detection and collision response are different things. Right now, we just want to check whether multiple shapes overlap. What do we use collision for? Describe the games in more detail.

What do we want to collide? y x Points Circles Axis-Aligned Boxes Convex polygons Covered soonTM Other shapes Not covered C r min w h dim = (w,h) max P P1 P2 P3 P4 P5

Collision Detection I DETECTION ALGORITHMS

Point-Circle Check if the distance between the point and the center is less than or equal to the radius ||P - C||2 ≤ r2 C r C r P P d d A circle is the entire collection of points that is within a given radius from a defined center point. That means if a circle has a radius of 10 and a center of 0, 0, it has all the points that are a distance of 10 or less away from the point, 0, 0. With this, we can determine how to do point-circle collision. We take the distance of the point from the center, and we check whether it is less than or equal to the radius. This is the distance algorithm.

Circle-Circle Check if the distance between the two centers is less than or equal to the sum of the radii ||C1 - C2||2 ≤ (r1 + r2)2 d d C1 r1 C2 r2 C1 r1 C2 r2 We can apply this same logic to circle circle collision detection. If you wanted both circles to be colliding, but be as far away as they possibly can while still colliding, then the distance between the two centers would be r1 + r2. As such, we need to check the distance between the two centers and check that it is less than or equal to r1 + r2.

Point-AAB Check if the point is within range on each axis minx ≤ px ≤ maxx AND miny ≤ py ≤ maxy x x min min P P max max The reason why we are shooting for AABs in this example is that AABs allow you to check two ranges for collision, therange that the AAB spans on the x-axis, and the range that the AAB spans on the y—axis. Every point inside the rectangle has an x-coordinate within that range, and a y-coordinate within that range. As such, when we have a point we want to check collision detection for, we need to see if the x-coordinate of that point is in the x-range of the rectangle, and if the y-coordinate of that point is also in the rectangle. y y

Circle-AAB Check if closest point to circle on AAB is in circle Closest point: clamp C.x, C.y to [min.x, max.x], [min.y, max.y] Then just do point-circle collision C r max min P d C r max P min d P=C r max min d=0

AAB-AAB Ensure overlap on each axis Project each box onto x and y axes Find all four Intervals, test for overlaps That is not a negative sign.

Projection Imagine a light source with parallel rays Shape is between light source and axis “Shadow” cast on axis is shape’s projection onto that axis

Creating Projections Find the axis you want to project onto This should be a normalized vector (length 1) Vec2d has a normalize method x axis = Vec2d(1, 0) y axis = Vec2d(0, 1)

Creating Projections To project a point, take its dot product with the projection axis double p = point.dot(axis) Store p for later Vec2d has a dot product method

Creating Projections To project an AAB onto the x axis: Project the top left and bottom right points onto the x axis Store the two doubles in an Interval The space between them on the x axis is the projection (shadow) of the AAB on the x axis 1 4 x (1, 3) y (4, 5)

Projections ⇒ Collisions For each axis, check if the corresponding Intervals overlap There should be two Intervals for each axis Intervals A and B overlap if and only if: A min ≤ B max AND B min ≤ A max If both axes overlap, the shapes are colliding

Interval Class Stores two projections public final class Interval { private double min; private double max; public bool overlap (Interval other) }

Collision Detection I COLLISION BEHAVIOR

Shapes AAB and Circle classes inherit from the same abstract class Shape attributes Implement collision checks Point collisions are only for the mouse; no separate class needed

Collision Behavior Contains collision information for a game object Holds the specific Shape for that GameObject

Collision System Keeps track of all game objects that can collide Loops through all pairs of registered objects Checks if each pair is colliding If there is a collision, both are notified- only go through each pair once

Expanded Contract public void tick(long nanosSinceLastTick); public void draw(Graphics2D g); public void collide(GameObject o);

Collision Detection I QUESTIONS?

Collision Debugger Easy way to test collisions Will give you stencil code You fill in the math

Lecture 2 Tips for Alchemy 2

Removing Units Beware the ConcurrentModificationException! Consider a removal queue This can be generalized to multiple phases of ticks

Sprites You’ll need to have sprites in your game to make it pretty! Lots of sprites on the internet Stealing IP is fun and easy! We do it every lecture Be sure to call it fair use

Tips for Alchemy II JAVA TIP OF THE WEEK

Double Dispatch If you have a Circle and an AAB but only know that they’re Shapes, how do you determine which method to call? void testCollide() { Shape s = new Circle(); Shape s2 = new AAB(); s.collides(s2); } interface Shape { collides(Circle c); collides(AAB aab); collides(Shape o); boolean collides(Shape o) { if (o instanceof Circle) { return collides((Circle) o); } else if (o instanceof AAB) { return collides((AAB) o); } else { throw new IllegalArgumentException(); } Explain testCollide and Shape.

Double Dispatch interface Shape { collides(Shape o); collidesCircle(Circle c); collidesAAB(AAB aab); } public class Circle implements Shape { collides(Shape o) { return o.collidesCircle(this); collidesCircle(Circle c) { /*code*/ } collidesAAB(AAB aab) { /*code*/ } public class AAB implements Shape { collides(Shape o) { return o.collidesAAB(this); } collidesCircle(Circle c) { /*code*/ } collidesAAB(AAB aab) { /*code*/ }

Anonymous Methods Essentially an in-line class/interface All anonymous methods are inner classes And therefore have a reference to the instance that creates them interface KeyHandler { public void onKeyPressed(KeyEvent e); } void addKeyHandler(KeyHandler h) { /*code*/ void init() { obj.addKeyHandler(e -> { /*code*/ });

Tips for Alc II QUESTIONS?

Alchemy 1 Playtesting YAY!