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 [2] 3 4 ... 16
16
General / Re: Jumping and collision problem
« on: July 31, 2020, 04:26:36 pm »
A possible fix for both of your issues could be to tweak your collision response to something like this

if (direction.y < 0.0f && playerVelocity.y <= 0.0f) {
        //Collision on bottom
        playerVelocity.y = 0.0f;
        canJump = true;
    }
 

That way the player can't land on the platform if they are still in the upward part of their jump. I'm assuming a negative velocity in your code means the player is moving down, but you can of course flip the comparison if it's the opposite.

17
System / Re: Problem with MouseButtonPressed
« on: June 12, 2020, 03:39:49 pm »
Your code is incorrect. Instead of this:
if (event.key.code == Mouse::Left)

You should do this:
if (event.mouseButton.button == Mouse::Left)

event.key.code is for keyboard events.

18
Window / Re: Poll event yields close when program starts
« on: April 15, 2020, 12:28:12 am »
Are you sure the program is crashing and not just exiting by hitting your call to window->close()? The SFML documentation on pollEvent() says

Quote
This function is not blocking: if there's no pending event then it will return false and leave event unmodified

You are treating the event as if it was filled with something even though it might not have been. You might be reading an uninitialized event.type variable leading to undefined behavior. pollEvent() should be used in a while loop like this

sf::Event event;
while (window.pollEvent(event))
{
   // process your event...
}
 


19
SFML projects / Re: American Football
« on: April 07, 2020, 04:51:43 am »
Looks good higgipoker!

It's been a while since my last update, but I'm still slowly making progress. I've implemented a lot of miscellaneous things, but I'll just call out a few of the larger changes.

First of all, I've implemented the ability to choose which plays you want your team to run. The gifs I posted in the past also showed me modifying plays, but that was in my "play designer" tool. Now you can choose plays during the actual football games. I'm exciting about this because it's the first step in turning this project from just a simulation you watch into an actual game where your input influences what happens :) . You still can't control the individual players, but you can be the coach and call out the plays to be run.


Another big feature that I implemented is a "career mode". This is where you pick out a team to control game-to-game and season-to-season. A schedule gets generated at the beginning of each season that each team follows as you progress through the season. This also means that there are a lot of football games being played between AI controlled teams that the user isn't involved with. A big challenge I faced for the career mode was re-architecting my code to allow running these AI games in a background thread. The gif below shows a dialog running in the main thread providing score and other stat updates about a game running in a background thread.
(click to show/hide)

On my computer a background simulation like this takes a couple of minutes, which isn't too bad considering a normally played game can last around an hour. However, it's unfortunately still unacceptably slow. In real life there are over 100 football teams, which means I would need to simulate over 50 games at a time. I need all of these games to be simulated in seconds or minutes, not hours. Because of this I had to implement a second method of simulation, one that determines the outcomes of games based on statistical analysis instead of fully simulating all of the players and ball movements. With this method, I'm able to run all of the AI games in the background at a much faster speed (though there is still room for optimizations). The gif below shows multiple games involving different teams being simulated back-to-back.
(click to show/hide)

I am also now keeping track of various statistics during games, which get saved to a database and can be viewed in the menus between games. I've added the ability to sort data in my table widgets by columns for easier browsing.
(click to show/hide)

Lastly, I've implemented the ability to recruit new players to your team. For those that follow American Football at the college level, you know that this is a big part of a coach's responsibilities. You can research what kind of players your team needs and then search for available recruits that match your criteria. Once you find the recruits you want, you can start trying to convince them to join your team while competing against other teams trying to do the same thing. I won't post a gif for this one because it's just more menu interactions like my previous gif and isn't too visually exciting

20
Graphics / Re: Rotation of sprite with small steps
« on: April 02, 2020, 04:01:30 pm »
You need to be updating the rotation once per game loop, not creating a new loop for this.

What you've written will rotate the sprite in steps, but you aren't going to see that rotation because it isn't being drawn to the screen between those steps. In your game loop you should be checking the rotation of your sprite and, if it's less than 90, incrementing the angle by a small amount. Then the rest of your game loop should be clearing and drawing everything.

21
General / Re: Sprite confined to screen--Help--Beginer
« on: January 03, 2020, 10:52:11 pm »
You can just check to make sure the mouse position is within the size of the window before setting the boat's position to it.

22
The SFML tutorials on sprites and textures talks about what can cause the "white square problem".

I didn't go through all of your code but there is a decent chance the problem is coming from this (simplified) snippet.
Boss boss;
boss.setsprite();
Event ll;
ll.myVari = boss;
Eventlist.push_back(ll);
 
Your boss object holds on to both the texture and the sprite. It's important to remember that sprites are pretty lightweight objects that contain a pointer to the texture, not the texture data itself. Now think about what will happen when your boss variable gets copied. The member variables will also get copied, which means the new copied sprite will have the same value as the old original sprite, which is a pointer to the old original texture, not the new one.

You may need to find a new strategy for managing your textures. Ideally to where they don't get copied around and their memory addresses don't change.

23
General / Re: Event handling
« on: October 01, 2019, 09:57:55 pm »
It isn't clear from your post, but note that I wasn't suggesting you directly replace that one if statement with the other in the same line of code. I was suggesting that you should check for the event in your event loop. I'm not sure if you did this.
while (window.pollEvent(event))
{
     if (event.type == sf::Event::Closed)
         window.close();
     else if (event.type == sf::Event::MouseButtonPressed)
     {
         // DO STUFF HERE
     }
}
 

If you want to explicitly check if the left mouse button was pressed, you need to FIRST make sure event.type == sf::Event::MouseButtonPressed, and THEN ALSO check if event.mouseButton.button == Mouse::Left. Be sure to carefully read the event tutorial you linked again. It gives an example of this. You will get undefined behavior if you check event.mouseButton.button without first making sure the event.type is sf::Event::MouseButtonPressed.

Now, regarding sf::Mouse::isButtonPressed(sf::Mouse::Left). That function is used to check the current state of the button. If the mouse click is very fast, it's possible that the mouse button went down and then back up before sf::Mouse::isButtonPressed(sf::Mouse::Left) is ever called. In other words, it's possible to miss fast button presses. I'm simply speculating that this might be the case for you for whatever reason on Windows 10. Using events instead would solve that problem.

24
General / Re: Event handling
« on: September 30, 2019, 11:42:08 pm »
Have you tried checking to see if you are getting the mouse click event instead of relying on the real-time state?

if (event.type == sf::Event::MouseButtonPressed)
 

25
General / Re: Graphic problem
« on: September 27, 2019, 03:56:09 pm »
One common cause of this is when your tiles get drawn to non-integer positions due to the view moving or whatever else. This topic comes up fairly often, so if you search around the forums you'll probably find several threads of people talking about why this happens and some possible solutions. Here's one I found with a quick search that might be useful to you.

26
General / Re: No errors, but the window doesnt load anything.
« on: September 13, 2019, 04:04:10 pm »
This looks to be where you're trying to toggle between different balloon sprites, but there are quite a few issues with it.

if (elapsed.asSeconds() <= 1){
            while (window.isOpen()) {
                activeSprite = (activeSprite == &balloon4Sprite ?
                    &balloon2Sprite :
                    &balloon4Sprite);
        }
    }
 

  • This is directly in your main function, not in your main "game loop".  You will only hit this if statement one time. You will presumably enter the if statement's body because the time elapsed will likely be under 1 second by this point.
  • After entering the body of the if statement you will be rapidly switching the sprite back and forth as fast as your CPU can go in the while loop, which is likely not what you want. It seems like you want the if statement to be inside your while loop, not the other way around.
  • You are never drawing the sprites and displaying the window between each time you toggle the sprite. You will therefore not see anything happen on screen.
  • You have two of these loops: while (window.isOpen()). You are only handling events and drawing things in the second one. You need combine the two loops into one.

27
Quote
if (PlayerSprite.getGlobalBounds().intersects(Tile001Sprite.getGlobalBounds)) {

28
SFML projects / Re: American Football
« on: May 16, 2019, 06:50:25 am »
As I mentioned in my last post, I've been working on menus to allow creating new football teams in-game. It needs to be polished up and made to look nicer, but I think a lot of the initial functionality I want is there. Sorry that my gifs below have been shrunk down, which makes the text a bit hard to read.


Creating a new team also means creating players for that team. Each player has 17 abilities right now (speed, strength, etc) that impact how they perform. Again, sorry the text is hard to read in the below gif, but it also shows off some of the improvements I've made to my widgets for displaying tables of text. I can now scroll vertically and horizontally to see all of my players and all of their abilities.
(click to show/hide)

Lastly, I've started working on a "dynamic" camera which attempts to automatically follow the action of the game and also automatically zoom in/out as needed.
(click to show/hide)

29
Graphics / Re: Collision of two sprites is very weird
« on: April 27, 2019, 12:18:16 am »
You didn't show how you draw your objects, but I would guess you're splitting up your player movement and collision response into separate frames, causing your object to alternate between collision and non-collision each frame. Basically, your logic probably flows something like:
1. Move object
2. Draw frame
3. If object is colliding, move object back.
4. Draw frame
5. Repeat

What you probably want is something more like:
1. Move object
2. If object is colliding, move object back.
3. Draw frame
4. Repeat

By the way, now might be a good time to learn how to use a debugger if you haven't already  ;) . These types of problems are usually pretty easy to spot when using one

30
Graphics / Re: Collision of two sprites is very weird
« on: April 26, 2019, 08:59:11 pm »
During a collision you seem to reset you sprite's position back to 'oldPos', but you never reset the variable you used to calculate the position, 'pos'.

Pages: 1 [2] 3 4 ... 16
anything