How to set up a score board using SFML and Box2D in C++ - c++

I want to set up a scoreboard for these two players (Pikachu)
My questions are:
how to detect when the ball touches the ground?
how to setup an object that can change during the game?
like the two in this picture:
I'm very new to SFML and Box2D, so even if I try to read the source code to see what I can use to implement things above, I still have no idea.
Can anyone give me some clues?

To create a scoreboard similar to the one in the image provided you can put text on the screen that holds the current score of the players and then placing it in the position where you want the score to be placed on the screen. In SFML this would be done by creating a sf::Text object.
To answer your other questions.
1.how to detect when the ball touches the ground
A simple way of doing this would be to check the Y value of the coordinates of the ball and from that determining if the ball is touching the ground.
2.how to setup an object that it can change during the game.
I am unsure what you mean by this.

Related

SDL drawing a sprite once a button is pressed

So, i'm a complete stranger to SDL and i found this nice code online:
http://gamedevgeek.com/tutorials/animating-sprites-with-sdl/
I was just wondering how to make it so that when i press space a shape gets placed infront of me? For instance, im just walking around and when i press space a rectangle or another bmp is places in front of me.
Sorry for not being explicit in what i want, i just dont know how to explain it.
You need:
Another Surface to draw (blit), made from the rectangle.bmp. This would use the same method as is used for the grass (or the player if you wanted animation).
Knowledge of where "in front" is: up, down, left or right. Look at the code and see what variables change when you press one of the arrow keys. (Hint: don't use rcSprite.) In a larger game, you would want to define a new variable for the direction that the player is facing, and then use that for both the sprite animation and for placing the rectangle, as it would make the code easier to understand.
Some new code in HandleEvent, which does something if the key is SDLK_SPACE.
Then calculate a position to place the rectangle (say, the player's position with 50 added to "x" if they were facing right), and draw the rectangle in the same way as the grass.
In general, look at what code has already been written, and Google for stuff you don't know (e.g. the name of SDLK_SPACE).
Good luck

Particles around a sprite

I'm new to the CoCos2D development. I have checked out some tutorials and went on trying to develop a little idea.
I have checked some partical tutorials and it all looks nice but I still have some questions about it. I have seen how to call a particle and let it follow wherever you click on the layer and so on but I need something more.
Let's say I have several circle shaped sprites on my Layer. Is it possible to do the following: click on a sprite and then a partical trail should go around the sprite so you as a player can see it is selected. The particale should keep circling around the sprite until I select another circle shaped sprite which result in dissappearing of the previous particle trail and appearing onto the new selected sprite.
Is this possible with the particle system or should I look for another way of doing this ? Any type of help is appreciated.
kind regards

Scrolling Background with Cocos2D and Box2D

I am trying to create a simple game that mainly consists of a ball rolling down an incline. The player's only control is to cause the ball to jump. My question is, what is the best way to make it appear to roll while generally keeping the ball at the same place on the screen? I have considered CCCamera, but it seems like it's not the best option since I want a repeating background image. Scrolling the background manually is also giving me trouble because it's not clear how to get the ball to stay in one place while letting Box2D handle the physics. I'd appreciate any help as I've been stuck on this for quite a while.
Use CCFollow on the layer where you draw the game stuff, and let it follow the ball sprite:
[gameLayer runAction:[CCFollow actionWithTarget:ball]];

Cocos2d change image of hero in accelerometer when an object hits it

Hi. I am new on this website and also in cocos2d. I am a student and I need your help.
I am making a game based on one of the tutorials in a cocos2d game development book. The concept is simple; different objects are falling from the top of the screen and I have to avoid or catch them by tilting the device. The main character, which is one which has to avoid objects, has different properties which can change by grabbing different objects (e.g. the player may have a shield if it grabs one). In order to display the shield I have to change the sprite of the player. I am not sure how I can achieve this. Could anyone help me in providing some guidelines on this?
Use setTexture to switch the image (texture) of your current sprite with another:
[playerSprite setTexture:[[CCTextureCache sharedTextureCache] addImage:#"playerWithShield.png"]];

Board Game using SDL

I am building a board game in SDL and here is the problem I am currently facing.
I have a pawn on square 1 and I roll the dice. Based on the value I get on the dice the pawn moves to another square. I am bale to move the pawn after i read the SDL tutorials online. But the problem I am facing is that after moving the pawn to a new location the old pawn still stays at the old location. The tutorials I found on the internet moves a dot but also refreshes the background to cover up the old dot. But I cant do that as my game board is intricate and there are pawns from other players sitting there.
Is there a way in SDL that I could really move a pawn instead of having to create a new pawn at the new location and covering up the old pawn?
The fundamental concept of sprites: Before you insert the sprite, you save a copy of the original screen content. When you need to remove the sprite, you just paste the stored old content back in.
You will have to process all your objects in the correct order (LIFO) for this to work. Since you'll usually be double-buffered, this happens on the cold buffer, so this isn't an issue.
No, your code will need to be able to redraw that board position with the pawn missing. There isn't any way for the computer to automatically reconstruct what the board should look like without the pawn.
It sounds like your render code is mixed in with your game logic. You ought to separate rendering so that you can redraw the complete game scene with a single function call, which you can then use whenever a visible change is made to the game state.