collisionStrategy.cpp -...

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
#include <vector> #include <algorithm> #include "ioMod.h" #include "collisionStrategy.h" #include "viewport.h" #include "renderContext.h" void RectangularCollisionStrategy::draw() const { IOmod:: getInstance().writeText("Strategy: Rectangular", 500, 30); } bool RectangularCollisionStrategy::execute( const Drawable& sprite1, const Drawable& sprite2) const { float left1 = sprite1.getX(); float left2 = sprite2.getX(); float right1 = left1+sprite1.getScaledWidth(); float right2 = left2+sprite2.getScaledWidth(); if ( right1 < left2 ) return false; if ( left1 > right2 ) return false; float top1 = sprite1.getY(); float top2 = sprite2.getY(); float bottom1 = top1+sprite1.getScaledHeight(); float bottom2 = top2+sprite2.getScaledHeight(); if ( bottom1 < top2 ) return false; if ( bottom2 < top1 ) return false; return true; } float MidPointCollisionStrategy:: distance(float x1, float y1, float x2, float y2) const { float x = x1-x2, y = y1-y2; return hypot(x, y); } void MidPointCollisionStrategy::draw() const { IOmod:: getInstance().writeText("Strategy: Distance", 500, 30); } bool MidPointCollisionStrategy::execute( const Drawable& sprite1, const Drawable& sprite2) const { int width1 = sprite1.getScaledWidth(); int width2 = sprite2.getScaledWidth(); int height1 = sprite1.getScaledHeight();
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern