0

I am using the SplashKit software toolkit here: https://www.splashkit.io/

//Error in the code is that, the score is not showing and also the score should increases when the user splats a fruit. i am not able to do the calculations. Do not worry about the images, you can take any image as a sample. You can also comment the code and reply about where the things goes wrong.

#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_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://s...content-available-to-author-only...e.com/642-Splat.html
}
 
bitmap fruit_bitmap(int 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 county_thingy = 0;
    bitmap Some_tHiNg;
    double A_VARIABLE, anotherVariable;
    open_window("Fruit Punch",
        600, 600);
 
    load_resources();
    Some_tHiNg
        = fruit_bitmap(rnd(NUM_FRUIT));
    A_VARIABLE
        = rnd(screen_width() - bitmap_width(Some_tHiNg)
 
                );
    anotherVariable = rnd(screen_height() - bitmap_height(Some_tHiNg));
    while (
        not quit_requested()) {
        process_events();
        draw_text("Score: " + to_string(county_thingy), COLOR_BLACK, 0, 0);
        clear_screen(COLOR_WHITE);
        draw_bitmap(Some_tHiNg, A_VARIABLE, anotherVariable);
        refresh_screen(60);
        if (mouse_clicked(LEFT_BUTTON) and bitmap_point_collision(Some_tHiNg, A_VARIABLE, anotherVariable, mouse_x(), mouse_y())) {
            county_thingy = county_thingy + 1;
            play_sound_effect("Splat");
            Some_tHiNg = fruit_bitmap(rnd(NUM_FRUIT));
            A_VARIABLE = rnd(screen_width()) - bitmap_width(Some_tHiNg);
            anotherVariable = rnd(screen_height()) - bitmap_height(Some_tHiNg);
        }
    }
    return 0;
}
  • 1
    Please format your code properly. Secondly, why it the Java / JS tag present? – Glains Jan 06 '21 at 15:55
  • It is not working even after proper formatting. Please reply with the relevant answer. – Param Dhillon Jan 06 '21 at 15:59
  • 4
    @ParamDhillon Formatting doesn't matter, when talking about execution: your code could all be in a single line, as far as C++ compiler is concerned. Formatting matters for people reading your code (even then - it could be improved even more). If you don't want to help us understand your code, why should we help you in answering? Additionally, you did try stepping through your code with a debugger, before trying to ask here, right? – Algirdas Preidžius Jan 06 '21 at 16:01
  • 3
    Please make a [mcve] – Ted Lyngmo Jan 06 '21 at 16:04
  • 1
    I don't know the library used here. I think whatever the problem is you need someone to answer that uses splashkit. – drescherjm Jan 06 '21 at 16:06
  • corrected everything @AlgirdasPreidžius – Param Dhillon Jan 06 '21 at 16:08
  • 1
    @ParamDhillon Shouldn't this: `county_thingy = county_thingy + 0;` be this: `county_thingy = county_thingy + 1;`? – D-RAJ Jan 06 '21 at 16:12
  • 2
    @ParamDhillon -- Why are you not debugging your code? You have all the pieces necessary to debug the code, including "splashkit" (whatever that is). – PaulMcKenzie Jan 06 '21 at 16:13
  • 1
    @DhirajWishal is correct if you want the score to increase on each hit adding one instead of zero would do that. As for why or why not the text is shown you may be overwriting it with your bitmap however I have never used SplashKit. – drescherjm Jan 06 '21 at 16:17
  • Should you call `clear_screen(COLOR_WHITE);` after drawing the text or should the order of these operations be reversed? I am not sure but to me I would try reversing these. – drescherjm Jan 06 '21 at 16:21
  • I have corrected what @DhirajWishal told me. But i got the error "libpng warning: iCCP: known incorrect sRGB profile" – Param Dhillon Jan 06 '21 at 16:21
  • I think that means the png reader does not think one or more of your images is valid. Related: [https://stackoverflow.com/questions/22745076/libpng-warning-iccp-known-incorrect-srgb-profile](https://stackoverflow.com/questions/22745076/libpng-warning-iccp-known-incorrect-srgb-profile) – drescherjm Jan 06 '21 at 16:22
  • Perhaps you should ask [here](http://www.cplusplus.com/forum/general/242028/). It looks like you have the same teacher as that guy had. – Ted Lyngmo Jan 06 '21 at 16:25

0 Answers0