Question: #include splashkit.h using namespace std; #define CHERRY 0 #define GOOSEBERRY 1 #define BLUEBERRY 2 #define POMEGRANATE 3 #define APRICOT 4 #define RASPBERRY 5 #define BLACKBERRY

#include "splashkit.h"

using namespace std;

#define CHERRY 0

#define GOOSEBERRY 1

#define BLUEBERRY 2

#define POMEGRANATE 3

#define APRICOT 4

#define RASPBERRY 5

#define BLACKBERRY 6

#define STRAWBERRY 7

#define CURRANT 8

#define NUM_FRUIT 9

void load_resources()

{

//load all the bitmaps present int the memory

load_bitmap("Cherry", "Cherry.png");

load_bitmap("Gooseberry", "Gooseberry.png");

load_bitmap("Blueberry", "Blueberry.png");

load_bitmap("Pomegranate", "Pomegranate.png");

load_bitmap("Apricot", "Apricot.png");

load_bitmap("Raspberry", "Raspberry.png");

load_bitmap("Blackberry", "Blackberry.png");

load_bitmap("Strawberry", "Strawberry.png");

load_bitmap("Currant", "Currant.png");

load_sound_effect("Splat", "Splat-SoundBible.com-1826190667.wav"); // Recorded by Mike Koenig - http://soundbible.com/642-Splat.html

}

bitmap fruit_bitmap(int id)

{

// return bitmap represented by id

switch (id)

{

case CHERRY:

return bitmap_named("Cherry");

case GOOSEBERRY:

return bitmap_named("Gooseberry");

case BLUEBERRY:

return bitmap_named("Blueberry");

case POMEGRANATE:

return bitmap_named("Pomegranate");

case APRICOT:

return bitmap_named("Apricot");

case RASPBERRY:

return bitmap_named("Raspberry");

case BLACKBERRY:

return bitmap_named("Blackberry");

case STRAWBERRY:

return bitmap_named("Strawberry");

case CURRANT:

return bitmap_named("Currant");

default:

return bitmap_named("Currant");

}

}

int main()

{

int score = 0;

bitmap fruit_map; // stores bitmap of random generated fruit

double fruit_map_width, fruit_map_height;

open_window("Fruit Punch", 600, 600); //open a window of size 600 x 600

load_resources(); //loads all the bitmaps of fruits in memory

fruit_map = fruit_bitmap(rnd(NUM_FRUIT)); //generate a random number and store its bitmap

fruit_map_width = rnd(screen_width() - bitmap_width(fruit_map)); // width of bitmap to be shown on screen

fruit_map_height = rnd(screen_height() - bitmap_height(fruit_map)); // height of bitmap to be shown on screen

while (not quit_requested())

{ // run untill quit is not pressed

process_events();

clear_screen(COLOR_WHITE); // make screen white then displaying score

draw_text("Score: " + to_string(score), COLOR_BLACK, 0, 0); // show score with color black at top left corner

draw_bitmap(fruit_map, fruit_map_width, fruit_map_height); // draw bitmap on screen

refresh_screen(60);

if (mouse_clicked(LEFT_BUTTON) and bitmap_point_collision(fruit_map, fruit_map_width, fruit_map_height, mouse_x(), mouse_y()))

{

// if left mouse button clicked on bitmap then increase score by 1 and play sound effect

score = score + 1; // increasing the score by 1 everytime user splat the fruit

play_sound_effect("Splat");

fruit_map = fruit_bitmap(rnd(NUM_FRUIT)); // take another fruit

fruit_map_width = rnd(screen_width()) - bitmap_width(fruit_map); //find the width of new fruit bitmap

fruit_map_height = rnd(screen_height()) - bitmap_height(fruit_map); // find width of new fruit bitmap

}

}

return 0;

}

Question)

Fix the Code as the output of the code from the terminal only appears for 1 second and disappears?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!