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

Pages: [1] 2
1
Looks good to me! Keep up the good work.

I kind of like the use of the console. Two key presses and you're in the game; that's good. Right now it seems that you have to restart the application in order to play again, but this is still very impressive from my view. Good job, man.

I feel as though I've been inspired to do better.  ;D

2
General / Re: Maximizing window causes stack overflow
« on: July 15, 2013, 02:35:03 pm »
I'll probably revert to the stable build to avoid the problem for now, but thank you for the responses.  :D

3
General / Re: Maximizing window causes stack overflow
« on: July 15, 2013, 03:40:41 am »
Okay, to be sure, I did rebuild SFML just now. When I tested it out again, I encountered the same problem. So, I'm not really sure what's up with this.

4
General / Re: Maximizing window causes stack overflow
« on: July 14, 2013, 01:23:08 pm »
Whoops!
I suppose I wasn't being particularly helpful.

Windows Vista 32-bit
Microsoft Visual C++ 2010 Express
SFML 2.0 (From eXpl0it3r's unofficial nightly builds, which I downloaded on the 11th this month, so probably still the same version as the current one.)

5
Music from video games. I should probably start listening to more of it these days.

Anything from the Pikmin series is good, and Kirby Air Ride had some sweet music. Super Mario World's music was quite good too.

6
You're in luck!
http://msdn.microsoft.com/en-us/library/vstudio/669zx6zc(v=vs.110).aspx#bkmkPropertySheets

Visual Studio has such a feature. You can save "property sheets" for reuse in other projects.

7
General / Maximizing window causes stack overflow
« on: July 14, 2013, 11:58:59 am »
I was doing some testing, and I noticed this curiosity. When I would maximize my window, I would get a:
"Unhandled exception at 0x101fba76 in GameTestingSFML.exe: 0xC00000FD: Stack overflow."

The example included is essentially minimal, as it's just a slight derivative of the most basic example of SFML.

#include <SFML/Graphics.hpp>

int main(void){
        //Variable Definitions
        sf::RenderWindow window(sf::VideoMode::getFullscreenModes()[7], "SFML works!", 7);
                window.setFramerateLimit(60);

        sf::CircleShape shape(256.f);
                shape.setFillColor(sf::Color(191, 255, 127, 255));
                shape.setPointCount(48);

        //The Game Loop
        while (window.isOpen()){
                sf::Event event;
                //The Event Loop
                while (window.pollEvent(event)){

                        //Event type cases
                        switch(event.type){

                                //Window closed
                                case sf::Event::Closed:
                                        window.close();
                                break;

                                //Key pressed
                                case sf::Event::KeyPressed:

                                        //Keypress cases
                                        switch(event.key.code){

                                                //Escape key pressed
                                                case sf::Keyboard::Escape:
                                                        window.close();
                                                break;
                                        }
                                break;
                        }
                }

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

        return 0;
}

8
General / Re: Issues with game speed
« on: March 04, 2013, 07:11:58 pm »
Here's a question probably needing an answer: Is the problem entirely related to the inaccuracy of the time measured by the sf::Clock? I think it is. Maybe now I can continue working on the project.

9
General / Re: Issues with game speed
« on: March 03, 2013, 11:08:36 am »
I'll probably test it tomorrow
That might be a bit overdue.

Also, I've made a discovery.

It would appear that the time passing between frames doubles when the mouse is moved. However, the game still looks like it's running at 60fps, so the object moves twice as fast as a result. Even stranger, changing the framerate limit with sf::RenderWindow::setFramerateLimit does not change the time passing between frames. (Or, at least doesn't change the value returned from sf::Time::asMicroseconds.)

Why didn't I notice this? I had already written a line of code set to output the data I needed to come to this conclusion! It took over a month of not paying attention to this project, but I figured out more in few minutes than in the hours I spent looking at it before! I'm not even well rested!

10
Graphics / Reusing sprites
« on: February 09, 2013, 04:22:23 pm »
Let's say I have multiple enemies that look the same, would it be better to give each of them a sprite, or would it be better to draw each one with the same sprite, but changing the necessary properties to fit the properties of one individual enemy? (Like position.) Is there just one better way? Or can there be specific cases where one or the other should be applied?

(Also, I have another question, but I'll give it less priority. How would one reduce the amount of draw calls? What counts as a draw call? Can one ever have a big 2D platformer with parallax scrolling and have everything drawn in 1 call?)

11
General / Ray casting in 2D (Not related to SFML)
« on: January 21, 2013, 03:28:16 am »
I have, for a long time, had a problem. I often found myself looking up how to do ray casting, I might find something, but it would never really help, and everything I had seen looked awfully limited. The environment where rays were being cast had to be a grid because it depended on checking every square on the grid the ray intersected with along the way, and that meant that it would be slower if things were far apart. I also noticed a bizarre pattern of people only wanting to know what ray casting was in the context of rendering a 3D-looking environment. This was weird for me, because people seemed to ONLY refer to it that way, when it had quite a few more applications. Needless to say the internet was useless, and I worked on and developed my own method independently to find if a ray would intersect with a line. No grids, no binary searches. Just rays and lines and math.

Something still bothered me though. I thought it was pretty efficient as compared to some other methods, but I didn't know how efficient it was. I've seen other things ray cast, but I never knew how the did it, and I never knew if my method was better or not.

So, today, I present the algorithm in the form of C++ to programmers I think will be able to judge it based on their experiences with such things. It isn't optimized. (It will still check if the ray is pointing directly away from the line.) Also, the code contains some variation of a class that represents a 2D vector, so there really is no relation to SFML here. I'm asking here because I trust you folks to answer the question:

Is there a more efficient way to do what I've done here? (Not in regards to programming, more in regards to the math.):
#include <iostream>
#include <math.h>
using std::cout;
using std::endl;

//Define the behaviour of a 2D vector (geometry). How this works is mostly irrelevant.
class vec2 {
public:
vec2(float X, float Y){
x = X;
y = Y;
}
vec2 operator = (vec2 arg){
x = arg.x;
y = arg.y;
return *this;
}
vec2 operator * (float arg){
vec2 temp(0,0);
temp.x = x * arg;
temp.y = y * arg;
return temp;
}
vec2 operator + (vec2 arg){
vec2 temp(0,0);
temp.x = x + arg.x;
temp.y = y + arg.y;
return temp;
}
vec2 operator - (vec2 arg){
vec2 temp(0,0);
temp.x = x - arg.x;
temp.y = y - arg.y;
return temp;
}
vec2 operator * (vec2 arg){
vec2 temp(0,0);
temp.x = x * arg.x;
temp.y = y * arg.y;
return temp;
}
vec2 operator / (vec2 arg){
vec2 temp(0,0);
temp.x = x / arg.x;
temp.y = y / arg.y;
return temp;
}
float magnitude(){
return sqrt(x*x + y*y);
}
vec2 normal(){
float mag = this->magnitude();
return vec2(x/mag, y/mag);
}
float x,y;
};
//That's what most of the code is, and I haven't even gotten into the important part.

//This is what makes it happen *IMPORTANT THINGS START HERE*
void raycast(bool * retBool, float * retDis, vec2 * retVec, float Angle, vec2 Origin, vec2 PointA, vec2 PointB){
float aA, bA;
float factor;
vec2 pos(0,0);
aA = atan2(PointA.y, PointA.x);
bA = atan2(PointB.y, PointB.x);
factor = (Angle - aA)/(bA - aA);
*retBool = factor >= 0 && factor <= 1;
*retVec = (PointB-PointA)*factor + PointA;
*retDis = sqrt((retVec->x)*(retVec->x)+(retVec->y)*(retVec->y));
}
//That's it


int main(){
float distance;
bool hit;
vec2 pos(0,0);

raycast(&hit, &distance, &pos, 45.0 / 180.0 * 3.14159, vec2(0,0), vec2(1, 3), vec2(3, 1));

cout<<hit<<endl;
cout<<distance<<endl;
cout<<pos.x<<", "<<pos.y<<endl;

return 0;
}

Of course, I doubt you'll just get it if I post the code, so I'll give a little explanation of how it works in the form of an image. I don't guarantee it'll help because I'm apparently bad at explanations.

That probably didn't help much.

Well, if you think you can help me, feel free to post about it, I'd love to hear it.

12
General / Re: Issues with game speed
« on: January 20, 2013, 09:26:45 am »
Don't use Real-Time Input  when you don't need it, it's pretty much overkill to use it to close the window, verify whether it's necessary or not to use real time input and if not then use events instead.

Amended.
//switch(event.type)
        case sf::Event::KeyPressed :
                if(event.key.code == sf::Keyboard::Escape)
                window.close();
        break;

Also, if it wouldn't hurt, could you guys tell me if my code looks okay? I feel like I could be making a mistake here. There's pretty much only one object instantiated of the playerCharacter class. I feel like that's a mistake, because I currently only need one player, but I also think I need the organization of data that classes provide. Are there cleaner alternatives, or is what I'm doing okay?

13
General / Re: Issues with game speed
« on: January 20, 2013, 04:20:41 am »
I'm not sure what you're doing/trying to achieve with the rotation,

Well, I kept that in because it's important to the source of the issue.

If you want to work with events, then use the correct events respond, otherwise don't put your input code into the event loop! ;)

Well, okay.

That's what you told me.

This is what I did:
(Hope you don't mind me pasting code that was hardly changed.)
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <math.h>
#include <iostream> //For bug fixing

#define PI 3.1415926535

class playerCharacter {
public:
        sf::Vector2f                            Position;
        short int                                       Rotation;
        sf::Vector2f                            Velocity;
        sf::CircleShape                         Visual;
        char                                            Direction;
        friend void                                     Update(playerCharacter *plyr, sf::Int32 passedTime);
};

void Update(playerCharacter *plyr, sf::Int32 passedTime){ //If I use Int64 here, it doesn't build. Probably because this computer doesn't use 64 of them thingamabobs.
        float timeFactor = 60.0/(1.0/((float)passedTime / 1000000.0)); //I suspect all troubles come from this line, where I try to make sure that the speed of the game is independant of the frame rate.

        //std::cout<<timeFactor<<","<<passedTime<<std::endl;

        plyr->Position.x = plyr->Position.x + plyr->Velocity.x * timeFactor;
        plyr->Position.y = plyr->Position.y + plyr->Velocity.y * timeFactor;
}

int main(){

        //System-related
        sf::Clock gameClock;

        sf::Clock rClock;

        sf::VideoMode vm(800,600);

        sf::RenderWindow window(vm, "Placeholder", 7);

        sf::Vector2f mousePosition;

        playerCharacter teabot;
        teabot.Position = sf::Vector2f((float)window.getSize().x/2, (float)window.getSize().y/2);
        //System-related END

        //Graphics-related
        sf::View view(sf::FloatRect(teabot.Position.x-(float)80, teabot.Position.y-((float)vm.height/(float)vm.width) * (float)80, (float)160, ((float)vm.height/(float)vm.width) * (float)160));

        teabot.Visual.setRadius(128);
        teabot.Visual.setPointCount(4);
        teabot.Visual.setFillColor(sf::Color::Blue);
        teabot.Visual.setOrigin(128, 128);
        teabot.Visual.setScale(1.f/32.f, 1.f/32.f);

        sf::CircleShape mReference(0.4, 5.0);
        mReference.setFillColor(sf::Color::White);
        //Graphics-related END

        //Window options
        window.setVerticalSyncEnabled(true);
        window.setFramerateLimit(60);
        window.setView(view);

        //Game loop
        while(window.isOpen()){
                gameClock.restart();
                sf::Event event;
                while(window.pollEvent(event)){
                        switch(event.type){
                                case sf::Event::Closed :
                                        window.close();
                                break;
                        }
                }
                if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
                        window.close();

                if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
                        teabot.Direction = 'F';

                mousePosition = (sf::Vector2f) sf::Mouse::getPosition(window);

                view.setCenter(teabot.Position);
                window.setView(view);

                teabot.Visual.setPosition((sf::Vector2f)teabot.Position);
                teabot.Rotation =  90 + atan2( (float)(mousePosition.y + (view.getCenter().y - window.getSize().y/2)) - teabot.Position.y, (float)(mousePosition.x + (view.getCenter().x - window.getSize().x/2)) - teabot.Position.x) / (float)PI * 180;
                teabot.Visual.setRotation(teabot.Rotation);

                //Work on stuff below. Note: Character slows down when facing directly right, investigate.
                //When I get rid of output to cout, the entire game seems to slow to a constant rate, and it speeds up when the mouse moves.
                //Curiouser and curiouser. Because the slow down caused by facing the object to the right is relatively unnoticeable due to the new slowing by lack of output.
                //Theory: The output does cause the game to speed up, but something about all the values outputted being so simple when the object faces the right makes the console window update in a different way. Perhaps, not update at all?
                //Then why does the mouse speed up the game when there's no output? Should the game be as slow as it is when the mouse isn't moving? Does the update of a mouse cause the window to update at the rate at which the mouse position updates?

                if(teabot.Direction == 'F'){
                        teabot.Velocity.x = cos(((float)teabot.Rotation - 90.0) / 180.0 * (float)PI)*50.0;
                        teabot.Velocity.y = sin(((float)teabot.Rotation - 90.0) / 180.0 * (float)PI)*50.0;
                }

                if(rClock.getElapsedTime().asSeconds() >= 1.0){
                        mReference.setPosition(teabot.Position);
                        rClock.restart();
                }

                //std::cout<<teabot.Direction<<teabot.Velocity.x<<", "<<teabot.Velocity.y<<std::endl; //Whenever the console window updates, the game window updates. This seems to make the game go faster somehow.
                Update(&teabot, gameClock.getElapsedTime().asMicroseconds());

                window.clear(sf::Color::Black);
                window.draw(teabot.Visual);
                window.draw(mReference);
                window.display();

        }

        return 0;
}

If you look at the event loop, there is no reference to sf::Keyboard or sf::Mouse. (I didn't use the members of sf::Event because to do comparisons, I'd have to refer to sf::Keyboard. Something I was told not to do. (In case you hadn't noticed, your post was a bit confusing.))

This is what happened:

It behaved in the exact same way.

I think that at this point, I need a bit more help.

14
General / Issues with game speed
« on: January 17, 2013, 05:36:34 am »
After a bit of effort, I think I managed to compress my code into the basics to represent my problem. Unfortunately, my problem depends on a few complicated systems. Too long? The original was over 220 lines long on three files. This is 120 lines in one document. You're welcome.  ;)

Anyway, the problem I present to you is one I don't quite understand. When I usually get problems like these, the solution seems evident enough, but I don't think things quite add up in this case. You see, there is an object in the middle of the screen that can move around and follow your cursor when you press the Up key. When your mouse is still, it goes at a constant pace. However, whenever the mouse moves, the object speeds up. That's not the end of it. If I'm outputting text to the console window in the game loop, the game moves at the same pace as if the mouse were moving in the previous explanation. HOWEVER, the game slows to the calm pace when the object in the middle faces directly right. (Why right? It has to do with some math, but it used to be directly up before I subtracted 90 from an angle.) I think this has to do with me trying to control the speed of the game based on the frame rate of the game. (e.g. Game has half the expected frame rate? Make everything move twice as fast per frame.)

I've been looking at this for a long time, and I've gotten lost in a sea of possibilities. Any help is appreciated. Thanks.
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <math.h>
#include <iostream> //For bug fixing

#define PI 3.1415926535

class playerCharacter {
public:
        sf::Vector2f                            Position;
        short int                                       Rotation;
        sf::Vector2f                            Velocity;
        sf::CircleShape                         Visual;
        char                                            Direction;
        friend void                                     Update(playerCharacter *plyr, sf::Int32 passedTime);
};

void Update(playerCharacter *plyr, sf::Int32 passedTime){ //If I use Int64 here, it doesn't build. Probably because this computer doesn't use 64 of them thingamabobs.
        float timeFactor = 60.0/(1.0/((float)passedTime / 1000000.0)); //I suspect all troubles come from this line, where I try to make sure that the speed of the game is independant of the frame rate.

        //std::cout<<timeFactor<<","<<passedTime<<std::endl;

        plyr->Position.x = plyr->Position.x + plyr->Velocity.x * timeFactor;
        plyr->Position.y = plyr->Position.y + plyr->Velocity.y * timeFactor;
}

int main(){

        //System-related
        sf::Clock gameClock;

        sf::Clock rClock;

        sf::VideoMode vm(400,300);

        sf::RenderWindow window(vm, "Placeholder", 7);

        sf::Vector2f mousePosition;

        playerCharacter teabot;
        teabot.Position = sf::Vector2f((float)window.getSize().x/2, (float)window.getSize().y/2);
        //System-related END

        //Graphics-related
        sf::View view(sf::FloatRect(teabot.Position.x-(float)80, teabot.Position.y-((float)vm.height/(float)vm.width) * (float)80, (float)160, ((float)vm.height/(float)vm.width) * (float)160));

        teabot.Visual.setRadius(128);
        teabot.Visual.setPointCount(4);
        teabot.Visual.setFillColor(sf::Color::Blue);
        teabot.Visual.setOrigin(128, 128);
        teabot.Visual.setScale(1.f/32.f, 1.f/32.f);

        sf::CircleShape mReference(0.4, 5.0);
        mReference.setFillColor(sf::Color::White);
        //Graphics-related END

        //Window options
        window.setVerticalSyncEnabled(true);
        window.setFramerateLimit(60);
        window.setView(view);

        //Game loop
        while(window.isOpen()){
                gameClock.restart();
                sf::Event event;
                while(window.pollEvent(event)){
                        switch(event.type){
                                case sf::Event::Closed :
                                        window.close();
                                break;
                                case sf::Event::KeyPressed :
                                        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)){
                                                window.close();
                                        }
                                        //Key presses
                                        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
                                                teabot.Direction = 'F';
                                        //Key presses END
                                break;
                                case sf::Event::MouseMoved :
                                        mousePosition = (sf::Vector2f) sf::Mouse::getPosition(window); //Whenever I move the mouse, the game's speed increases
                                break;
                        }
                }

                view.setCenter(teabot.Position);
                window.setView(view);

                teabot.Visual.setPosition((sf::Vector2f)teabot.Position);
                teabot.Rotation =  90 + atan2( (float)(mousePosition.y + (view.getCenter().y - window.getSize().y/2)) - teabot.Position.y, (float)(mousePosition.x + (view.getCenter().x - window.getSize().x/2)) - teabot.Position.x) / (float)PI * 180;
                teabot.Visual.setRotation(teabot.Rotation);

                //Work on stuff below. Note: Character slows down when facing directly right, investigate.
                //When I get rid of output to cout, the entire game seems to slow to a constant rate, and it speeds up when the mouse moves.
                //Curiouser and curiouser. Because the slow down caused by facing the object to the right is relatively unnoticeable due to the new slowing by lack of output.
                //Theory: The output does cause the game to speed up, but something about all the values outputted being so simple when the object faces the right makes the console window update in a different way. Perhaps, not update at all?
                //Then why does the mouse speed up the game when there's no output? Should the game be as slow as it is when the mouse isn't moving? Does the update of a mouse cause the window to update at the rate at which the mouse position updates?

                if(teabot.Direction == 'F'){
                        teabot.Velocity.x = cos(((float)teabot.Rotation - 90.0) / 180.0 * (float)PI)*50.0;
                        teabot.Velocity.y = sin(((float)teabot.Rotation - 90.0) / 180.0 * (float)PI)*50.0;
                }

                if(rClock.getElapsedTime().asSeconds() >= 1.0){
                        mReference.setPosition(teabot.Position);
                        rClock.restart();
                }

                //std::cout<<teabot.Direction<<teabot.Velocity.x<<", "<<teabot.Velocity.y<<std::endl; //Whenever the console window updates, the game window updates. This seems to make the game go faster somehow.
                Update(&teabot, gameClock.getElapsedTime().asMicroseconds());

                window.clear(sf::Color::Black);
                window.draw(teabot.Visual);
                window.draw(mReference);
                window.display();

        }

        return 0;
}

15
Graphics / Re: Stretch Sprite/Texture
« on: January 14, 2013, 08:20:13 am »
http://www.sfml-dev.org/documentation/2.0/classsf_1_1Sprite.php#a4c48a87f1626047e448f9c1a68ff167e

There's where it is in the documentation.

If it helps (because the documentation never fully explains), you can get a number to give Sprite::setScale() if you ask yourself this question:

What do I need to multiply 100x100 by to get 1024x768? Which really means: What's 1024/100, and 768/100? The result will be 10.24 and 7.68, which are the values you can give setScale in this case.

Pages: [1] 2
anything