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

Pages: 1 2 [3] 4
31
strange, it complies from my visual studio. All I can say is that its a link error, which means that one of the .lib files is set up wrong, missing or the libs directory is wrong, although why it only does it when you add the bool intersecs function is beyond me. :/

Is it possible that you only set up libs for debug and you're running it in release, or vice versa? Best bet would be to try re-linking everything and making sure you're using the right configuration etc.

32
General / Re: Snake Game[In progress]
« on: March 19, 2016, 08:32:51 pm »
good point bitano.

Here it is with just one piece of fruit at a time.

#include <SFML/Graphics.hpp>

sf::RectangleShape generateFruit() {


        sf::RectangleShape fruit;
        fruit.setFillColor(sf::Color::Yellow);
        int fruitx = rand() % 400;
        int fruity = rand() % 400;
        fruit.setPosition(fruitx, fruity);
        fruit.setSize(sf::Vector2f(5, 5));

        return fruit;


}
int main()
{
        srand(time(NULL));
        int width = 400;
        int height = 400;
        sf::VideoMode videomode(width, height);
        sf::RenderWindow window(videomode, "Snake");
        sf::RectangleShape snake;

        snake.setFillColor(sf::Color::Red);
        snake.setSize(sf::Vector2f(20, 20));
        snake.setPosition(100, 100);
        sf::Clock clock;
        sf::Time t1 = sf::seconds(20);
        sf::RectangleShape spawnedFruit;
        while (window.isOpen()) {
                window.clear();
                window.draw(snake);



                sf::Time elapsed1 = clock.getElapsedTime();
                if (elapsed1 >= t1) {


                        spawnedFruit = generateFruit();
                       
                        clock.restart();

                }
               
                window.draw(spawnedFruit);
               
                window.display();
                sf::Event event;
                while (window.pollEvent(event))
                {
                        if ((event.type == sf::Event::Closed) ||
                                ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape)))
                                window.close();
                }


                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))

                        snake.move(0, -0.1);
                else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
                        snake.move(0, 0.1);
                else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
                        snake.move(-0.1, 0);
                else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
                        snake.move(0.1, 0);
        }

}
 

33
General / Re: Snake Game[In progress]
« on: March 19, 2016, 07:29:52 pm »
okay, as i can see that my replies are all a bit confusing, i tested out the app with the changes, so here it is, and it works, remember to wait 20sec to see the fruit spawn ;)

#include <SFML/Graphics.hpp>

sf::RectangleShape generateFruit() {


        sf::RectangleShape fruit;
        fruit.setFillColor(sf::Color::Yellow);
        int fruitx = rand() % 400;
        int fruity = rand() % 400;
        fruit.setPosition(fruitx, fruity);
        fruit.setSize(sf::Vector2f(5, 5));

        return fruit;


}
int main()
{
        srand(time(NULL));
        int width = 400;
        int height = 400;
        sf::VideoMode videomode(width, height);
        sf::RenderWindow window(videomode, "Snake");
        sf::RectangleShape snake;

        snake.setFillColor(sf::Color::Red);
        snake.setSize(sf::Vector2f(20, 20));
        snake.setPosition(100, 100);
        sf::Clock clock;
        sf::Time t1 = sf::seconds(20);
        std::vector<sf::RectangleShape> spawnedFruit;
        int maxFruit = 20;
        int fruitCount = 0;
        while (window.isOpen()) {
                window.clear();
                window.draw(snake);
               

               
                sf::Time elapsed1 = clock.getElapsedTime();
                if (elapsed1 >= t1) {


                        if (fruitCount < maxFruit)
                        {
                                spawnedFruit.push_back(generateFruit());
                                fruitCount++;
                        }
                        clock.restart();

                }
                for (int i = 0; i < spawnedFruit.size(); i++)
                {
                        window.draw(spawnedFruit[i]);
                }
                window.display();
                sf::Event event;
                while (window.pollEvent(event))
                {
                        if ((event.type == sf::Event::Closed) ||
                                ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape)))
                                window.close();
                }


                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))

                        snake.move(0, -0.1);
                else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
                        snake.move(0, 0.1);
                else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
                        snake.move(-0.1, 0);
                else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
                        snake.move(0.1, 0);
        }

}
 

34
General / Re: Snake Game[In progress]
« on: March 19, 2016, 06:32:31 pm »
at the top of the file, declare std::Vector<sf::RectangleShape> spawnedFruit; and then when you 'generate fruit' do, spawnedFruit.push_back(generateFruit()); then just before window.display(). put a for loop :

for(int i = 0; i < spawnedFruit.size(); i++){
    window.draw(spawnedFruit[i]);
}
 

basically you have to draw things every frame if you want them to be visible while using window.clear(); You may also want to define a limit to howmany fruit are allowed, otherwise the game will just keep making them and the lag will be very real. so just for example again at the top of the file:

int maxFruit = 20;
int fruitCount = 0;
 

then in the while loop:


if (elapsed1 >= t1){


            if(fruitCount  < maxFruit){
            spawnedFruit.push_back(generateFruit());
            fruitCount++;
             }
            clock.restart();
           
        }
 

there's a possibilty with this that you'll need to use smart pointers or something, but try it and see first. I know vectors can be annoying.

35
General / Re: Snake Game[In progress]
« on: March 19, 2016, 06:28:04 pm »
okay so, the thing is that you only draw the fruit on the frame that it is spawned. so it will only be drawn once and then isntantly deleted by window.clear().

36
General / Re: Snake Game[In progress]
« on: March 19, 2016, 06:13:03 pm »
hm, put clock declaration before while loop. Do the same with defininition of your time object. Also, instead of "elapsed1 == t1" do >=, there's a possibility that the frame lags and the time is never spot on 20seconds.

37
General / Re: Snake Game[In progress]
« on: March 19, 2016, 06:06:03 pm »
put the clock outside the while loop, you're redifining it on every iteration

38
General / Re: Mouse isButtonReleased
« on: March 19, 2016, 12:05:29 am »
you'll need to use the event queue for that. Think about it, it doesn't make sense to constantly check if mousebutton is released, released buttons are move like switches they can be on or off.  when you're not using an event queue and you press the mouse button, it registers more than one click, so every time you let go of the mouse button it would register several times. I cant think how that would be useful.

here's how to do it with an event queue:
sf::Event event;

        while (mWindow.pollEvent(event)) {

                switch (event.type)
                {
                case sf::Event::MouseButtonReleased:
                 //do something
         break;
 

39
it's visual studio 2015, so yes, it is compatible. As someone else already said, smart pointers have been in visual c++ since vs2012.

40
like everyone else has said, they are totally included.

have you done #include <memory> ?

41
General / shaders texture sample lookup
« on: March 18, 2016, 04:42:29 pm »
Hi, I've been trying for some time to get a dynamic amount of lights into my light shader instead of using a fixed array.  I tried setting the arrays to a max length and then sending a uniform int at runtime to say where the last used indices was but it just wont work due to it not being a constant.

So after much looking around and a comment on here that i saw by Nexus, I found out about using texture sampling instead of an array. So i've been trying that without much luck.

example of how i make the texture and the shader logic:

mdataTexture.create(10, 1);

for (int i = 0; i < 10; i++)
        {
                sf::RectangleShape r;
                r.setSize(sf::Vector2f(1, 1));
                r.setPosition(i, 0);
                sf::Vector2f vec2 = static_cast<sf::Vector2f>(mWindow.mapCoordsToPixel(vec[i], mCam));
                vec2.y = mWindow.getSize().y - vec2.y + 8;
                vec2.x += 8;
                r.setFillColor(sf::Color(vec2.x, vec2.y, 0, 255));
                mdataTexture.draw(r);
 

shader:
for(int i = 0; i <  10; i++)
        {
                vec4 pixel = texture2D(uData, vec2(float(i)/10.0, 0.0));
                distances[i] = distance(vec2(pixel.x , pixel.y), vec2(gl_FragCoord.x,  gl_FragCoord.y));
               
        }
 

when this is run, the data returned (pixel.x, pixel.y) always equal zero. and I just can't understand why  :(

When instead of trying to use the color data as coordinates for my lights, I instead use the color data to set the fragColor, it works.  So the texture is definitely, there, loaded and functioning to the extent that i can take colours from it, but when i try and take the color as floats to use as coordinates it just gives me zero.

Such a weird problem, any help would be appreciated.

thanks for your time.

EDIT:

I have changed the fragment shader to use texelFetch instead of texture2d. This is easier for me because it doesn't use normalised values, so i can be sure im accessing the right pixel when using a for loop index.

this changes screen color as i'd expect:
vec4 pixel = texelFetch(uData, ivec2(5, 0), 0);
gl_FragColor = pixel;
 
so does this:

gl_FragColor.r = pixel.r;
gl_FragColor.g = pixel.g;
gl_FragColor.b = pixel.b;
gl_FragColor.a = pixel.a;
 
however, this doesn't work and seems to always be zero (even though it works as a color)
vec4 pixel = texelFetch(uData, ivec2(5, 0), 0);
float dist = distance(vec2(pixel.x, pixel.y), gl_FragCoord.xy);
modColor.r +=  vColor.r * uColor.r / dist;
modColor.g += vColor.g * uColor.g / dist;
modColor.b += vColor.b * uColor.b / dist;
modColor.a += vColor.a * uColor.a / dist;
       
gl_FragColor = texture2D(uTexture, vTexCoord) * modColor ;
 

42
General / Re: gl_FragCoords.y
« on: March 15, 2016, 08:06:50 pm »
Okay got it working. I inverted the mouses y position before sending it to the shader, and everything is all working now.

worldPos.y = mWindow.getSize().y - worldPos.y;
 

solved.

43
General / gl_FragCoords.y
« on: March 15, 2016, 06:45:04 pm »
hello, I'm writing a simple fragment shader that multiplies the rgba of a fragment based on it's distance from my mouse position.

varying vec4 vColor;
varying vec2 vTexCoord;

uniform sampler2D uTexture;
uniform vec2 uLightPosition;


void main(){
       
        float  pixelDistFromLight = distance(uLightPosition, vec2(gl_FragCoord.x,  gl_FragCoord.y));
        vec4 modColor = vec4(vColor.r + -pixelDistFromLight/100.0, vColor.g + -pixelDistFromLight/100.0,
        vColor.b + -pixelDistFromLight/100.0, vColor.a );
        gl_FragColor = texture2D(uTexture, vTexCoord) * modColor ;
}
 

the 'light' follows the mouse from left to right, but it's movement is inverted on the y axis. I understand that this is because glsl uses the bottom left as it's origin, and have tried to invert it in various ways including  1.0 - gl_FragCoord.y, and although that makes the light move in the righ direction, the light is still not situated at the mouse positions. i.e it moves up when i move the mouse up, but is positioned at the bottom of the screen.

any idea what operation i could perform on gl_FragCoord.y to get it to match the y coordinate of my mouse?

thanks for your time.

44
SFML game jam / Re: 5th SFML Game Jam
« on: March 09, 2016, 08:42:04 pm »
well, I think i'm currently plumping for 'a', it definitely has the potential to go so far as challenging the very foundations of what games actually are. Anyways, I have some more ideas now, though they appear to be getting darker as I go along, heh.

45
SFML game jam / Re: 5th SFML Game Jam
« on: March 09, 2016, 07:21:08 pm »
this is either a) a very clever, philosophical theme that will require some actual thought, or b) the complete opposite.

at what point does failure being an option make it no longer a failure? at what point does failure stop being an option and becoming a pre-requisite for winning.

The only ideas i've had so far (of my own) are a generic platformer where falling down holes doesn't kill you, but helps you somehow (again making it perhaps teh better option, i.e not a failure at all). And the other idea was business tycoon-type game where you buy out rival businesses and try to run them, but if all else fails, you can make it go bankrupt and its still a win(strategy game for a game jam seems ambitious at least).

So yeah, ima gonna have to keep thinking on this. dw, I'm not fishing for ideas.

Pages: 1 2 [3] 4