Hi there,
I'm currently writing code for a simple game for a project and have stumbled across some issues.
The game has an avatar, holding an object, moving across the screen that will drop said object a certain distance when the spacebar is pressed. The object is to get the object that is dropped into a bucket (made up of simply a rectangle) which will score user a point, and the game will end if user misses the bucket.
I already have the function to release the object when the spacebar is pressed, however my issues have come when trying to implement a graphical score counter to appear when the object enters the bucket.
Basically I want my code to read that when the x and y coordinate of the circle (object dropped) is between the x and y coordinates of the bucket (rectangle, another circle will appear somewhere else on the screen, acting as a score counter, and for when the circle lands outwith these coordinates, the game will end. Has anyone got any suggestions as to how I should translate this into C++??
Start by telling us what language + windowing/event framework you're currently using, and what windowing/event framework you wish to use in C++. If you haven't decided yet, I suggest using SFML, personally. https://www.sfml-dev.org/
It's not clear what you want to do.
You could change your printf to cout.
Also your main function should return int, not be void.
To output text you could use outtext or outtextxy
What I’m trying to achieve is that when the circle that is dropped ends up within the coordinates of the rectangle, another circle will appear somewhere else on the screen, acting as a graphical score counter. However when the circle lands out with the rectangles coordinates, the game will end
Your task would be easier if you can use classes or at least structs.
Have you learned them ?
Also it will be easier if you create some functions for the normal game functions.
As far as I can see the circle doesn't move downwards so you need to fix this first.
Next step will be to check if the circle is inside the box.
Some pseudo code:
1 2 3 4 5 6
draw welcome screen
while game is running
process the input
update all game objects - i.e. move them, check for collision...
draw the game or draw game over screen
end-while
Difficult to give more detailed advice without writing the game for you.
OK, obviously you writing the game for me would be very handy (and appreciated ;) ) I still want to do it myself. Would you be able to give me the code for something simpler which I could then implement into the game as it is this one part that has stumped me.
Say I have:
int x = 0;
int y = 0;
int a = 0;
int b = 0;
int c = 32;
do {
clearviewport();
//DRAW GRAPHICS
circle(x, y + 20, 20);
setcolor(GREEN);
line(a + 100, b, a + 100, b + 100);
setcolor(RED);
//MOVE CIRCLE WHEN SPACE BAR IS PRESSED
if (_kbhit())
{
c = _getch();
if (c == 32);
{
x += 20;
}
}
in my main. How could I then write the code to say that when a>x (when the x coordinate of the circle is greater than that of the line) that a circle should appear somewhere else. I have tried to do this however when I debug my solution, the circle which I would like to appear when a>x is already in my graphic.
How did you get mixed up with BGI? Google research is saying that this is a discontinued graphics library that won't even work on most compilers. So I can't get it to test any features...