Assignment 8B: Hit Boxes (Part 2). Back in Assignment 2 (so long ago!) we created a simp program to determine what a hit box would be. Now we're going to use that information to determine if two characters would collide based on those hit boxes. You will create a Player class that takes in the following private attributes (as integers) when creates • Width • Height • X position • Y position In addition to Getter methods for all four attributes, the Player class should also have the following methods:
Assignment 8B: Hit Boxes (Part 2). Back in Assignment 2 (so long ago!) we created a simp program to determine what a hit box would be. Now we're going to use that information to determine if two characters would collide based on those hit boxes. You will create a Player class that takes in the following private attributes (as integers) when creates • Width • Height • X position • Y position In addition to Getter methods for all four attributes, the Player class should also have the following methods:
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
Write code for the sample outputs in c++ only
![Assignment 8B: Hit Boxes (Part 2). Back in Assignment 2 (so long ago!) we created a simple
program to determine what a hit box would be. Now we're going to use that information to
determine if two characters would collide based on those hit boxes.
You will create a Player class that takes in the following private attributes (as integers) when
creates
• Width
• Height
• X position
• Y position
In addition to Getter methods for all four attributes, the Player class should also have the
following methods:
MoveHorizontal(int x_delta)
• Takes in either a negative integer (for moving left) or a positive integer (for moving
right). It should update the X position of the Player object
MoveVertical(int y_delta)
• Takes in either a negative integer (for moving down) or a positive integer (for moving
up). It should update the Y position of the Player object
DidTheyCollide(Player otherPlayer)
• Takes in another player object, and returns true if they collided with each other (and
false otherwise).
To detect collisions in the DidTheyCollide() method, you will use the following equation for Axis-
Aligned Bounding Box collision detection:
[PseudoCode]
AND
if(Player1's X Coordinate < (Player2's Width + X Coordinate)
(Player1's Width +X Coordinate) > Player2's X Coordinate AND
Player1's Y Coordinate < (Player2's Height + Y Coordinate) AND
(Player1's Height + Y Coordinate) > Player2's Y Coordinate)
{
PRINT("We collided!")](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F55d5a1c0-ec43-4f79-a066-5b95ed59a829%2F2bfb1d4f-fb95-444e-a612-c147dc63edb4%2Fqj2mft3h_processed.png&w=3840&q=75)
Transcribed Image Text:Assignment 8B: Hit Boxes (Part 2). Back in Assignment 2 (so long ago!) we created a simple
program to determine what a hit box would be. Now we're going to use that information to
determine if two characters would collide based on those hit boxes.
You will create a Player class that takes in the following private attributes (as integers) when
creates
• Width
• Height
• X position
• Y position
In addition to Getter methods for all four attributes, the Player class should also have the
following methods:
MoveHorizontal(int x_delta)
• Takes in either a negative integer (for moving left) or a positive integer (for moving
right). It should update the X position of the Player object
MoveVertical(int y_delta)
• Takes in either a negative integer (for moving down) or a positive integer (for moving
up). It should update the Y position of the Player object
DidTheyCollide(Player otherPlayer)
• Takes in another player object, and returns true if they collided with each other (and
false otherwise).
To detect collisions in the DidTheyCollide() method, you will use the following equation for Axis-
Aligned Bounding Box collision detection:
[PseudoCode]
AND
if(Player1's X Coordinate < (Player2's Width + X Coordinate)
(Player1's Width +X Coordinate) > Player2's X Coordinate AND
Player1's Y Coordinate < (Player2's Height + Y Coordinate) AND
(Player1's Height + Y Coordinate) > Player2's Y Coordinate)
{
PRINT("We collided!")
![You will then create a second class, Assignment8B, that will operate as a driver class. It will
create two Player objects based on user input, and then prompt the user to choose a Player to
move. After the player moves, the program should check to see if the two Player objects have
collided. The program should keep prompting the user to move a player until they collide.
Sample Output:
[Collision Tester]
Create Player 1
Enter X position: 0
Enter Y position: 0
Enter Player Hitbox Width: 10
Enter Player Hitbox Height: 10
Create Player 2
Enter X position: -10
Enter Y position: 0
Enter Player Hitbox Width: 5
Enter Player Hitbox Height: 14
Player 1 is at (0,0) and Player 2 is at (-10,0)
Which one do you want to move?
1
Which direction should Player 1 move (up, down, left, or right)?
Up
How far should Player 1 move?
2
Player 1 is at (0,2) and Player 2 is at (-10,0)
Which one do you want to move?
2
which direction should Player 2 move (up, down, left, or right)?
Right
How far should Player 2 move?
12
Player 1 is at (0,2) and Player 2 is at (2,0)
They collided!
Program Ends](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F55d5a1c0-ec43-4f79-a066-5b95ed59a829%2F2bfb1d4f-fb95-444e-a612-c147dc63edb4%2Fsh36csv_processed.png&w=3840&q=75)
Transcribed Image Text:You will then create a second class, Assignment8B, that will operate as a driver class. It will
create two Player objects based on user input, and then prompt the user to choose a Player to
move. After the player moves, the program should check to see if the two Player objects have
collided. The program should keep prompting the user to move a player until they collide.
Sample Output:
[Collision Tester]
Create Player 1
Enter X position: 0
Enter Y position: 0
Enter Player Hitbox Width: 10
Enter Player Hitbox Height: 10
Create Player 2
Enter X position: -10
Enter Y position: 0
Enter Player Hitbox Width: 5
Enter Player Hitbox Height: 14
Player 1 is at (0,0) and Player 2 is at (-10,0)
Which one do you want to move?
1
Which direction should Player 1 move (up, down, left, or right)?
Up
How far should Player 1 move?
2
Player 1 is at (0,2) and Player 2 is at (-10,0)
Which one do you want to move?
2
which direction should Player 2 move (up, down, left, or right)?
Right
How far should Player 2 move?
12
Player 1 is at (0,2) and Player 2 is at (2,0)
They collided!
Program Ends
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 3 steps with 1 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education