Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Arcade

Pages: 1 ... 12 13 [14] 15 16
196
General / Re: Help with changing a sprite direction
« on: April 23, 2015, 04:45:46 pm »
Not sure if you are aware, but note that your 2 balldirection vectors are not the same variable even though they have the same name. The second time you are defining a new variable with the same name, but in a different scope. After your if statement, it will be like the second assignment never happened because the second version of the vector will go out of scope.

In addition to using the debugger you can also just think through what your code is doing line by line, specifically the "update ball" logic.  If your ball is active you are going to move it up a bit each frame. if you have a collision you move it down a bit. This is already problematic because the down movement is likely  going to cancel out the up movement and the ball won't move anywhere. You are moving the ball down by the same amount you moved it up. You shouldn't move your ball up in the case where you are colliding.

 ... But even if it didn't cancel out and you actually started moving down, as soon as you aren't colliding any more it would just move up again. You are only trying to move down in the case you are colliding. Any time you aren't colliding you are moving the ball up. This is likely not what you want.

There are many ways to approach this problem, though this sounds like it might be a homework assignment so I'm reluctant to give you concrete answers. Assuming your ball just needs to bounce up and down, one simple idea is to use a variable to hold what state the ball is in. If the ball is in the "Up" state, then move the ball up. When the ball is in the "Down" state, then move the ball down.

If your ball needs to bounce in arbitrary directions you will need to figure out how to store the ball's current trajectory and modify it when you collide with a wall.

Having said all of that, Jesper Juhl's advice on learning how to use a debugger is a great idea.

197
To add on to what Nexus said, here are some notes.

First of all, is all of that code happening inside of a game loop? I'm going to assume it is.

//creating the texture
sf::Texture keyTexture;
//loading the file
keyTexture.loadFromFile("keysprite.png");
//creating a vector with an array of 7 sprites
std::vector<sf::Sprite> keySprites(7, sf::Sprite(keyTexture));
//for loop to check through array and set sprite positions
 
Assuming this is happening in your game loop, you are reloading your file and recreating your sprites every frame. You should create them once before entering your game loop. This also applies to the keyMusic variable later on in your code.

//for loop to check through array and set sprite positions
        for(int i = 0; i < keySprites.size(); i++)
        {
            keySprites[0].setPosition(460, 80);
            keySprites[1].setPosition(140, 275);
            keySprites[2].setPosition(800, 300);
            keySprites[3].setPosition(700, 500);
            keySprites[4].setPosition(125, 500);
            keySprites[5].setPosition(250, 850);
            keySprites[6].setPosition(700, 800);
        }
 
Why are you setting the position of the sprites in a loop? This loop isn't needed since you are setting each individual sprite. Notice how you are looping with the variable "i", but then you never use "i" in the loop. You are setting all of your sprites to the same thing seven different times.

if(keySpriteVisible == false)
{
   keySprites[6].setColor(sf::Color::Transparent);
}
 
Again, assuming all of this code is happening inside of a game loop, this won't really do anything. You are setting the color of keySprite[6], but then in your next loop you will just recreate keySprite[6] so it will lose its transparency (refer back to my first comment above). This is why your current solution does not work.

If you create the sprite vector before your game loop, then perhaps a better solution to your problem would be to remove that element from the vector when you detect a collision. Then, later when you loop through your objects to draw them, the key will be missing from the vector so it will not get drawn. This is what Nexus is referring to.

198
SFML projects / Re: Native Blocks Game
« on: April 20, 2015, 06:24:54 am »
I've begun implementing the beginnings of an options menu. Right now the major feature in the options menu is a way remap the game controls. The short video below shows me remapping the controls to use my gamepad/joystick.


199
SFML projects / Re: Native Blocks Game
« on: April 02, 2015, 06:50:09 am »
I have begun implementing a "Challenge" mode. I know I have had a Challenge button on the main menu visible in my last couple of videos, but it didn't do anything until now. The idea of the challenge mode is that you try to beat each of the AIs one by one. Eventually I would like to implement High Scores which list how many AIs you beat and how many attempts it took, but for now it is pretty basic.

The video shows what I have so far. The relevant parts of the video are at the beginning of the video where I select to play the Challenge mode, and then again at around 1:15 where I beat the first AI and it transitions me to the next.


200
SFML projects / Re: Native Blocks Game
« on: March 28, 2015, 07:20:23 am »
I'm slowly but surely still making progress as I find the time. This time around I focused on making minor graphical improvements to try and give it a more polished look (though there is still a long ways to go). The changes include:

  • I implemented a way to have "transitions" between different rooms. You can see one example in the video  as a fade-in transition between the menu and actual game.
  • I made the blocks have a subtle glowing pulse animation when touching another block of the same color. It becomes more pronounced as more blocks touch. I'm still trying to decide if I want to make the pulsing more intense or not. I do want it to be visible, but don't want it to be too distracting.
  • I made an indication for when a player makes a chain reaction. You can see many examples of this in the video below. I will likely revisit this one to make it a little prettier.
  • I gave the blocks an animation for when they disappear. Each color block has its own animation. This one might is less noticeable in the video because of all of the distracting chain reactions.

The video shows two Hard AIs playing against each other. You can see how good the Hard AI is at making chain reactions.


201
Graphics / Re: Text position and height
« on: March 19, 2015, 07:39:17 pm »
The problem I see in your picture is that "Score" overlaps with "Player 1". Is that basically the problem you are trying to solve? This is just a guess because I don't have a way to test it right now, but have you checked to see if the "top" field is non-zero when calling getLocalBounds on the text? So maybe you need something like this:
float y=caption.getPosition().y+caption.getLocalBounds().height+caption.getLocalBounds().top;
 

202
General / Re: Static class my map of sounds gets de-allocated
« on: March 16, 2015, 07:49:54 pm »
static class SoundLoader
 
You probably don't need the "static" keyword here. I don't think it is doing anything.

Quote
When I call LoadSounds() my Sounds have a soundbuffer populated. Then when I go ahead and call PlaySound with the correct enum name, I viewed my Sounds map and the size is 0, can anyone see what I am doing wrong here?
Just looking at your code I didn't spot anything directly related to your problem. You might need to show us the code using soundLoader. For example, you may be inadvertently creating a copy of the soundLoader and doing the load on one copy and play on the other copy.

Quote
game.h file
SoundLoader soundLoader;
 
Won't this cause a linker error if you try to include the header in more than one cpp file?

Quote
Basically I want to have only one soundLoader which my other classes can just define a static soundLoader which will access the soundLoader which is initialized at the start of the game.
You can consider using the "singleton pattern" for this. You can google that term for more information if you aren't familiar with it. Some people really like using singletons for resource management when creating games, but some people will say it is a bad design practice. You will just need to understand the pros and cons and decide if it works for you. An alternative to singletons is to just create your SoundLoader object in your main function before anything else and then just pass it to the objects that need it in their constructors or something. No need for global variables.

203
Graphics / Re: Moving sprites to target position.
« on: March 07, 2015, 12:25:15 am »
Well you are using SFML to draw to the screen, which you don't seem to have a problem with. The problem is in the movement logic. This is something you would need to solve no matter what library you were using to draw. Anyways, I'll try to help a little further.

Quote
As for the first problem, I've tried to set the focus to zero after movement, but it worked so fast, that the sprite didn't even have the time and moved only one pixel. Is there any command for "do this (focus=nullptr) after that (movement of focussed sprite) is finished"
You are right, with the way you are doing movement, if you set focus to null after calling move then your sprite won't move very far. Now, as you have things right now, only one object can be moving at a time. Meaning if you tried to move a second object, the first one would stop because there can only be one "focus" object. If that is fine, then what you can probably do is right after moving check to see if the object is near its destination, and if so, set focus to null at that time.

If you want an object to be able to continue moving after focusing a different object you'll probably need more major changes. In that case you'll probably need to use a container (such as vector) to store moving objects and loop through that container to move all of them.

Quote
Second problem: if I set a condition "focus=nullptr" inside "leftclicked", than the sprites don't move at all. But they should move.
This is because you are assigning focus instead of doing a comparison. You should use "==" not "=". I'm not sure if this is just a typo or if you don't understand the difference between "==' and "='. If it is the latter you should spend more time studying the language first. It can be very hard to use a library like SFML if you aren't very strong in C++ concepts.
if(focus==nullptr)
 

Quote
I`m moving the focussed object in a loop, because I can't use std::distance command without it. Is there any better solution?
Why wouldn't you be able to use std::distance without a loop? How you have it right now doesn't seem to make sense to me. It technically works, but is very confusing to understand.

Imagine you have 5 enemies. With your loop, the focused object will move towards the first enemy's destination, then the 2nd enemy's destination, etc. The only reason this works is because during the click you are setting all enemy's destination to the same spot. You still have a problem, though, being that the more enemies you have the faster your object will move because it is moving once per enemy.

204
Graphics / Re: Moving sprites to target position.
« on: March 06, 2015, 08:00:53 pm »
Quote
I've rewritten it and now it works better, but some problems still remain.
1. Sprites can be moved around unlimitedly, instead of only one move+automatic deselect.
2. It is not possible to move a sprite into another one, without selecting the new one.

Are you needing help finding why your code is producing these problems, or do you understand why but aren't sure how to reorganize and re-architect things to be better?

1. Sprites can be moved around multiple times because you aren't doing anything to prevent that. Think about what is happening when you click an empty area. You are setting the "move" variable to true and setting every enemy destination to where you clicked. Then after that you check to see if move is true (yes it is) and then check if the "focus" variable is non-null (yes it is), so you move the "focused" enemy. Perhaps one solution is to set "focus" back to null after you perform the move. Also, not directly related to the problem, but I'm still not sure why you are moving the focused object in a loop...

2. This one is pretty clear. When you click an enemy you are changing the "focus" variable. Perhaps one solution is to not change the focus variable if it is already set to something else.

By the way these questions aren't really related to the Graphics module of SFML, or SFML in general. These questions focus more on general C++ concepts and movement logic. You might get be able to get more people to help out on a different forum.

205
General / Re: Help, new to SFML, compile errors in simple project
« on: March 05, 2015, 08:30:10 pm »
When I said runtime error, I meant an error that occurs when your program is running (not compiling). I wasn't suggesting the error is in the C++ redist package.

Quote
the command prompt just shows a load of scrambled chars before it bombs out
This is likely related to the problem. Perhaps it is trying to print a string that isn't NUL terminated or one that was never initialized.

if (!mTexture.loadFromFile("/Media/Textures/Eagle.png"))
 
I'm not very familiar with how Windows handles things, but should you have that first forward slash in front of Media?

I don't have much time to look into this more right now, but I may look at your code more later.

206
Graphics / Re: Moving sprites to target position.
« on: March 05, 2015, 08:20:10 pm »
You might need to be more specific about the weird behavior you are seeing. How many enemies are in the EnemyVector, exactly how many clicks are you performing and where, what happens vs what are you expecting to happen in that situation, etc. I glanced through your code and did see a few potential problems.


std::vector<sf::Vector2f> EnemyPositions;
 
What is this for? It doesn't look like it is being used by anything.

           for (auto& enemy = EnemyVector.rbegin(); enemy != EnemyVector.rend(); ++enemy)
            {
                if (enemy->getGlobalBounds().contains(static_cast<float>(mousePos.x), static_cast<float>(mousePos.y)))
                {
                    focus = &(*enemy);
                   
                }
                else
                {
                    EnemyDestinations[std::distance(EnemyVector.rbegin(),enemy)].x = static_cast<float>(mousePos.x);
                    EnemyDestinations[std::distance(EnemyVector.rbegin(),enemy)].y = static_cast<float>(mousePos.y);
                    move=!move;
                }
            }
 
This likely won't do what you want if you have more than one enemy. When you click on one it will set the focus of that one, but set the destination and flip the move flag for all of the others. The move flag will just toggle back and forth depending on how many enemies you have.

for (auto& enemy = EnemyVector.rbegin(); enemy != EnemyVector.rend(); ++enemy)
            {
                if(focus!=nullptr)
                {
                    focus->move((EnemyDestinations[std::distance(EnemyVector.rbegin(),enemy)].x - focus->getPosition().x)*0.1,(EnemyDestinations[std::distance(EnemyVector.rbegin(),enemy)].y - focus->getPosition().y)*0.1);
               
                }
            }
 
This will move the focused object once for every enemy in your EnemyVector. Is that what you want?

207
General / Re: Help, new to SFML, compile errors in simple project
« on: March 05, 2015, 05:40:48 pm »
Quote
I'm getting an error at compile
Quote
First-chance exception at 0x6D96F20C (msvcr120.dll) in SFML-tuts.exe: 0xC0000005: Access violation reading location 0x00ACF000.
This doesn't look like a compile error. This looks like a run-time error. Is that what you meant?

Quote
If I remove the call to loadFromFile it seems fine, although it does nothing....

When you have loadFromFile in there is it actually succeeding? If loadFromFile fails (for example, it can't find your picture) all you're doing is printing a message and then continuing on. Is your error message being printed to the console?

208
General / Re: Checking for collisions in vector of shapes is bugged
« on: March 05, 2015, 07:00:34 am »
You guessed right, the collidesWithSomeone function has a logic error. Look at it a little longer and you'll see why it only works with one object  ;)

Specifically
for (j = fuckingPerson.begin(); j != fuckingPerson.end(); j++)
{
       
    if (this != (*j))
    {
        if (boundingBox.intersects((*j)->getPersonShape().getGlobalBounds()))
        {
            return  true;
        }
        else
        {
            return false;
        }
    }
}
 

Thank about how many times this is going to loop. The answer is not very many because you're returning after the first check.

I would also recommend looking into some of the things zsbzsb pointed out even though they aren't directly related to your problem.

209
General / Re: Thor2.0: Linking resource / texture to Animation
« on: February 26, 2015, 05:17:14 pm »
Again, I've never used Thor so I could be off-base here, but my guess as to why it isn't enumerating through the frames is because you call

animator.playAnimation("Idle", true);

every step in the loop. I'm guessing that is resetting the animation back to the first frame. You probably only want to call it once, and then only call
animator.update(frameclock.restart());
animator.animate(sprite)
 

every step. Again, this is just a guess though because I don't know Thor and haven't looked at any of the documentation.

210
General / Re: Thor2.0: Linking resource / texture to Animation
« on: February 26, 2015, 04:48:56 pm »
I've never used Thor, but it looks like your problem is that you're mixing lowercase and capital letters.

animator.addAnimation("idle", Idle, sf::seconds(1.f));
animator.playAnimation("Idle", true);
 

"idle" vs "Idle"

Pages: 1 ... 12 13 [14] 15 16
anything