homeworkstudyhelp

Our Services

Get 15% Discount on your First Order

I am working on a brick breaker game, and I have a bug in my code…

I am working on a brick breaker game, and I have a bug in my code that I’m trying to fix. I made a vector of 5 bricks that are rendered to the console. When the ball hits a brick it changes color. On the third hit, the color turns black and it is removed from the vector. My problem is, when a brick is removed, I get an error message saying for a read access violation that brings me to this code snippet from the vector class:    

 

_CONSTEXPR20 _Vector_const_iterator& operator++() noexcept {
#if _ITERATOR_DEBUG_LEVEL != 0
       const auto _Mycont = static_cast<const _Myvec*>(this->_Getcont());
       _STL_VERIFY(_Ptr, “can’t increment value-initialized vector iterator”);
       _STL_VERIFY(_Ptr < _Mycont->_Mylast, “can’t increment vector iterator past end”);
#endif // _ITERATOR_DEBUG_LEVEL != 0

       ++_Ptr;
       return *this;
   }

 

I imagine this has something to do with my CheckCollision method and the fact that my program still tried checking for bricks once they get deleted. I am at a loss as to how to update my CheckCollision method to stop checking for bricks once they get deleted and could use some help. 

 

void Game::CheckCollision()
{

iter = wall.begin();

// TODO #4 – Update collision to check all bricks

for (iter; iter != wall.end(); iter++)
{
 if (iter[0].Contains(ball.x_position + ball.x_velocity, ball.y_position + ball.y_velocity) && iter[0].color != Black)
 {

  iter[0].color = ConsoleColor(iter[0].color – 1);
  ball.y_velocity *= -1;
 }
 // TODO #5 – If the ball hits the same brick 3 times (color == black), remove it from the vector
 else if (iter[0].color == Black)
 {

  wall.erase(iter);
 }

 

if (wall.size() == 0)
{
 ball.x_velocity = 0;
 ball.y_velocity = 0;

 system(“cls”);
 std::cout << “\n\n\n\n\n\t\t\t\tVictory, You Win! =D” << std::endl;
 std::cout << “\t\t\t\tEnter ‘R’ to reset” << std::endl;
 std::cin.get();
}

if (paddle.Contains(ball.x_position + ball.x_velocity, ball.y_velocity + ball.y_position))
{
 ball.y_velocity *= -1;
}

 

 

// TODO #7 – If ball touches bottom of window, pause ball and display defeat text with R to reset
if (ball.moving && ball.y_position > paddle.y_position)
{
 ball.x_velocity = 0;
 ball.y_velocity = 0;

 system(“cls”);
 std::cout << “\n\n\n\n\n\t\t\t\tDefeat, You Lose! D=” << std::endl;
 std::cout << “\t\t\t\tEnter ‘R’ to reset” << std::endl;
 std::cin.get();
}
}

Share This Post

Email
WhatsApp
Facebook
Twitter
LinkedIn
Pinterest
Reddit

Order a Similar Paper and get 15% Discount on your First Order

Related Questions

In most countries in Europe, a comma is used to separate an…

In most countries in Europe, a comma is used to separate an integral part of a number from the decimal part. For example, 2 euros and 10 cents is written 2,10. English speaking countries use a decimal point and would write the same amount as 2.10. Create a code that

I have the following question for help writing a C++ program…

I have the following question for help writing a C++ program allowing users to play the game Wordle. I have played it after searching and I am still having trouble with this assignment. Any help will be appreciated. Thank You.     If you are not familiar with Wordle, search

Currently stuck on how to tackle this project. I am new to c++ and…

Currently stuck on how to tackle this project. I am new to c++ and I am not quite sure where to start. Can I get some help on how to structure and organize this project? I’ve included all details below. Thanks.   Directions Develop an object-oriented programming (OOP) application to

1.8.1: Determining the size of a vector.   Assign currentSize with…

1.8.1: Determining the size of a vector.   Assign currentSize with the size of the sensorReadings vector.   #include <iostream>#include <vector>using namespace std; int main() {  vector<int> sensorReadings(4);  int currentSize;  int input;  cin >> input;   sensorReadings.resize(input);     /* Your solution goes here  */       cout <<

To push all general purpose registers onto the stack, which…

To push all general purpose registers onto the stack, which instruction would you use? To push the EFLAGS register onto the stack, which instruction would you use? To pop the stack into the EFLAGS register, which instruction would you use? If you could not use the PUSH instruction, what two

#define _CRT_SECURE_NO_WARNINGS  #include    …

#define _CRT_SECURE_NO_WARNINGS  #include <stdio.h>    #define MAX_FACTORIALS 10000 #define NUM_FACTS 100    struct FactorialResults  {        int results[MAX_FACTORIALS];   int numResults;  };  int factorial(const int n)  {        return (n <= n) ? n * factorial(n – 1) : 1;  }  int reduceFactorial(const int n)  {        return n / n;  }  void computeFactorials(struct FactorialResults results, int numFactorials)  {        int

I need help please. I don’t know what to do. Code:   #include…

I need help please. I don’t know what to do. Code:   #include <iostream>using namespace std; int main() {   // initialize Boolean array to store the status of the treasure chests   bool chest[5] = { false };    // ask user to input which chest they found   int foundChest;   cout&

3.16 LAB: Natural merge sort   The merge sort algorithm…

3.16 LAB: Natural merge sort   The merge sort algorithm recursively divides the array in half until an array with one element is reached. A variant of merge sort, called natural merge sort, instead finds already-sorted runs of elements and merges the runs together. Ex: The unsorted array below has five

When you use the Scaffold-DbContext command, which parameters are…

When you use the Scaffold-DbContext command, which parameters are required?   A)the -Connection and -OutputDir parameters   B)the -Context and -DataAnnotation parameters   C)the -Context and -Provider parameters   D)the -Connection and -Provider parameters   Given an entity named Products that has a Description property, and given a combo box