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 - UchihaKite

Pages: 1 [2] 3
16
General / Re: [Q] Traverse a Binary Tree
« on: June 30, 2016, 02:15:43 pm »
Ah, I apologize for that. Is their a different area in the community where this question would be better placed? Sorry about that!

17
General / [Q] Traverse a Binary Tree
« on: June 30, 2016, 01:49:15 am »
Hello SFML Community!

First off, I apologize if this is in the incorrect location, secondly, if their is a better forum for C++ questions, feel free to direct me to it. I think I am just used to how awesome this community is, thus, I keep coming back here lol

So, currently I am on my second C++ class in college, and I decided to ask my teacher what I could look into over the break to get ahead a little. He told me that when I come back from Summer Break, he would like an example of Traversing a Binary Tree.

My question is, if anyone has a good resource on learning how to do this? I, of course, searched Google and Youtube. However, I found that most videos were either about Binary Search Trees, or were just very poor videos. My results on Google just left me completely confused. Like, I understand what a Binary Tree is, and how to Traverse a Binary Tree, on paper. Coding it, is something that is going well over my head. Any and all help would be great!

18
General / [Q] Something having to do with Anomalies and REX Prefix?
« on: June 13, 2016, 12:15:22 am »
Good Afternoon fellow C++ homies!

So, here is a random question for you all. Apart of my final is creating Pong with our own twist to it. Such as, I added an ability to the left paddle, when the ball hits the paddle three times, you can revert the ball back to the exact location it was at 3 seconds prior.
However I have seemed to come up with a weird message I have never seen before, and would love your guys thoughts on what it could be?

Anomaly: meaningless REX prefix used

My code is pretty damn long, so if you guys would rather me not post it up, if someone could just explain how that message comes up, I can look through my code and figure it out :) Thanks guys!

19
General / Re: Wierd Mouvment C++
« on: May 30, 2016, 04:02:56 pm »
Also, instead of the two "using" you have up top of your code, you can just use "using namespace std;"
You can also just omit using entirely and write std:: the few times you use it. This is even more important once you start to use header files. Namespaces exist for a reason...

Oooooh that sounds interesting :O I'm still new to C++, I have never used a header before. Could you explain that to me? Sounds like it could benefit the OP as well as myself :D
I don't know everything yet, I'm just trying to toss what little I know to help whoever I can.

20
General / Re: Wierd Mouvment C++
« on: May 29, 2016, 11:09:33 pm »
I'm fairly certain that Erdrick's observation is the solution to your problem, if you're still having issues with it, just let us know!

Also, instead of the two "using" you have up top of your code, you can just use "using namespace std;"

21
General / Re: [Q] Adding Gravity to My Code
« on: May 29, 2016, 11:03:32 pm »
Don't worry! I am only about as confused as anyone would be their first time doing something like this :D You made everything very clear and helped me out a lot! Thank you again!

How would I go about including your library in the SFML stuff? :O

22
General / Re: [Q] Adding Gravity to My Code
« on: May 17, 2016, 10:24:35 pm »
Ah man! I don't know why I didn't think of just using delta time >.< I guess I was just confused by his instructions. Perhaps he has a different way of doing it, but your method worked perfectly for what I was trying to accomplish, so, Thank You Mortal! You're a life saver man!

I do need to ask though, so I full understand your method. What exactly do you mean by a "fixed timestamp"?

23
General / Re: [Q] Adding Gravity to My Code
« on: May 16, 2016, 06:06:26 pm »
I was using elapsedTime to keep track of One Second, that way the function only fires every seconds, rather than through every pass. When I tried firing the function without the little "timer" all that would happen is the ball would just move back and forth without launching. When I set the function in the if statement to have it fire about every second, the ball produced more of a "bounce" effect.

24
General / Re: [Q] Adding Gravity to My Code
« on: May 16, 2016, 05:39:48 pm »
Thank you both for the replies! This is helping me out a lot!

So, at this point, when I launch the ball it shoots up properly, and then the gravity shoots it back down quickly. So, it is kind of working. It's like it is bouncing but just shooting back down about a second into it being in the air. I feel like I am getting close, but I am either missing something or my formula is incorrect. Here is what I added/edited

void applyGravity(float Gravity);

float yVelocity;

// The function and yVelocity are outside of my main loop
// yVelocity is fully declared inside of the main loop

        yVelocity = sin(angleInRadians) * 100;

// I made an if statement to help keep elapsedTime to just about a second

                if (elapsedTime > 2.0)
                {
                        elapsedTime = 0.0;
                }

// I put the function in an if statement so it only fires about every second, otherwise it caused my ball to just zoom back and forth on the ground.

                if (toMove == true)
                {
                        if (elapsedTime < 2.0 && elapsedTime >= 1.0)
                        {
                                applyGravity(Gravity);
                        }
                        shape.move(xVelocity * dt.asSeconds(), yVelocity * dt.asSeconds());
                        cout << xVelocity << yVelocity << endl;
                }

// And this is my function. I have a set amount for the time because the "per second" part of his instructions, I was assuming that meant Time should only be about 1 second?

void applyGravity(float Gravity)
{
        yVelocity = (Gravity * (1.0 * 1.0)) + yVelocity;
}
 

Edit:
P.S. Should anything be done to xVelocity during all of this? I noticed that when I bumped up the power of launching the ball up to make it bounce around more, all that ends up happening is it starts bouncing off the sides of the window and barely skimming the "ground"

25
General / Re: [Q] Adding Gravity to My Code
« on: May 16, 2016, 07:13:12 am »
I apologize in advance for my confusion, but I cannot begin to express how much I appreciate the both of you taking the time to help me.

I guess the reason I am confused is because of the "500 Pixels/s^2" aspect of his instructions. So, I think the appropriate question from me should've been, what is the correct formula (Code) that should be in my function? Originally I thought it'd be squaring 500 and adding it to yVelocity twice a second? Or am I just confusing myself by my teachers choice of words? >.<

26
General / Re: [Q] Adding Gravity to My Code
« on: May 16, 2016, 05:26:37 am »
O_o

Is that what my applyGravity is doing?! I'm only supposed to add 500 pixels per second squared.....What would be the correct input for that?

27
General / Re: [Q] Adding Gravity to My Code
« on: May 16, 2016, 02:37:22 am »
I was passing fixed values into the applyGravity to just play around with the numbers to see if it was my values that were messing everything up or my function. I'm still new, so, I have to play around sometimes to figure out what I did wrong.

I believe it is the code in the function that isn't working. When I run it, nothing changes at all. The ball is supposed to slow down every time it hits the bottom of the window, and adding gravity should produce a different affect, but when I run the code nothing different happens.

28
General / Re: Arkanoid collision problem
« on: May 16, 2016, 02:28:04 am »
Judging by your code, you're a lot more experienced than I am, but I did just post up a topic in this same forum. In my code, I did kind of mimic collision in the bounds of the window. Check it out, might not help you out, but it might give you some ideas :D

29
General / [Q] Adding Gravity to My Code
« on: May 16, 2016, 02:20:27 am »
Good Evening!

I'm back with another question that hopefully someone can help me out with. This week I was required to create a ball that would be launched from the bottom left corner of the screen, and continuously bounce off the surfaces of the screen. The longer I hold Spacebar, the faster the ball would get. I managed to complete my assignment a lot quicker than I thought I would, so I thought I would contact my teacher and see if I can't do something extra. He told me to add Gravity to my code. This is all he gave me.

Implement gravity into your ball movement:
- This will apply acceleration to your physics now.
- Remember, Velocity is the change in position per second, while acceleration is the change in Velocity per second.
- Gravity in our "Game" should be between 500 - 1500 Pixels/s^2

I have been trying to do this for a couple of days now, however I have been unable to implement it into my code. I know their are multiple ways of doing everything in coding, but from everything I have seen online and on tutorial videos, none of the methods have been working. So, I was hoping someone here has run into the same problems as me, and will be able to help me out.

Thank you all in advance for taking the time to look at my code, and helping me out!

// Engine.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <SFML/Graphics.hpp>

using namespace std;

void applyGravity(float, float);

float yVelocity;

int main()
{
        float Power = 0.0f;
        bool toMove = false;

        float Time;

        sf::RenderWindow window(sf::VideoMode(1024, 512), "Welcome to SDVA 203!");
        sf::CircleShape shape(25);
        shape.setPosition(0, 486);
        shape.setOrigin(shape.getRadius(), shape.getRadius());
        shape.setFillColor(sf::Color::White);

        sf::Clock clock;
        float angleInDegrees = 225;
        float angleInRadians = angleInDegrees * 2 * 3.1415 / 360;
        float xVelocity = cos(angleInRadians) * 100;
        yVelocity = sin(angleInRadians) * 100;
        while (window.isOpen())
        {
                sf::Time dt = clock.restart();
                sf::Event event;
                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                                window.close();

                        if (event.type == sf::Event::KeyReleased)
                        {
                                if (event.key.code == sf::Keyboard::Space)
                                {
                                        toMove = true;
                                }
                        }

                        if (event.type == sf::Event::KeyPressed)
                        {
                                if (event.key.code == sf::Keyboard::Num1)
                                {

                                        xVelocity = cos(angleInRadians) * 100;
                                        yVelocity = sin(angleInRadians) * 100;
                                }
                                if (event.key.code == sf::Keyboard::Num2)
                                {

                                        xVelocity = cos(angleInRadians) * 300;
                                        yVelocity = sin(angleInRadians) * 300;
                                }
                                if (event.key.code == sf::Keyboard::Num3)
                                {

                                        xVelocity = cos(angleInRadians) * 600;
                                        yVelocity = sin(angleInRadians) * 600;
                                }
                                if (event.key.code == sf::Keyboard::Num4)
                                {

                                        xVelocity = cos(angleInRadians) * 1200;
                                        yVelocity = sin(angleInRadians) * 1200;
                                }
                                if (event.key.code == sf::Keyboard::Space)
                                {
                                        toMove = false;
                                }
                        }
                }

                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space))
                {
                        Power += dt.asSeconds();

                        if (Power > 2.0f)
                        {
                                xVelocity = cos(angleInRadians) * 100;
                                yVelocity = sin(angleInRadians) * 100;
                                std::cout << "Power Level is at 100!" << std::endl;
                        }
                        if (Power > 4.0f)
                        {
                                xVelocity = cos(angleInRadians) * 300;
                                yVelocity = sin(angleInRadians) * 300;
                                std::cout << "Power Level is at 300!" << std::endl;
                        }
                        if (Power > 6.0f)
                        {
                                xVelocity = cos(angleInRadians) * 600;
                                yVelocity = sin(angleInRadians) * 600;
                                std::cout << "Power Level is at 600!" << std::endl;
                        }
                        if (Power > 8.0f)
                        {
                                xVelocity = cos(angleInRadians) * 1200;
                                yVelocity = sin(angleInRadians) * 1200;
                                std::cout << "Power Level is at 1200!" << std::endl;
                        }
                        if (Power > 10.0f)
                        {
                                xVelocity = cos(angleInRadians) * 9001;
                                yVelocity = sin(angleInRadians) * 9001;
                                std::cout << "Power Level Over 9000!" << std::endl;
                        }
                }

                if (toMove == true)
                {
                        shape.move(xVelocity * dt.asSeconds(), yVelocity * dt.asSeconds());
                        cout << xVelocity << yVelocity << endl;

                        applyGravity(500.0, 500.0);
                }

                sf::Vector2f position = shape.getPosition();
               
                if (position.y <= shape.getRadius())
                {
                        yVelocity *= -1;
                        shape.setPosition(position.x, shape.getRadius());
                }

                if (shape.getRadius() + position.y >= 512)
                {
                        yVelocity *= -1;
                        shape.setPosition(position.x, 512 - shape.getRadius());
                }
                if (position.x <= shape.getRadius())
                {
                        xVelocity *= -1;
                        shape.setPosition(shape.getRadius(), position.y);
                }
                if (shape.getRadius() + position.x >= 1024)
                {
                        xVelocity *= -1;
                        shape.setPosition(1024 - shape.getRadius(), position.y);
                }

                if (shape.getRadius() + position.y >= 512)
                {
                        yVelocity = yVelocity / 2.0f;
                }

                //std::cout << "Ball position is " << position.x <<","<<position.y << std::endl;

                window.clear();
                window.draw(shape);
                window.display();
        }
        return 0;
}

void applyGravity(float gravity, float time)
{
        yVelocity = yVelocity + (gravity * time);
        if (yVelocity < .01)
        {
                yVelocity = 0;
        }
}
 

30
General / Re: [Q] Proper way to slow down a Sprite during movement?
« on: May 16, 2016, 12:52:08 am »
Just wanted to let you know that I managed to complete the assignment! I removed all of my events, excluding the ones relating to the mouse, did a little code cleaning and it worked perfectly! Thank you for your help man :D

Pages: 1 [2] 3