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

Pages: [1]
1
General / Re: first program, help making grid
« on: January 23, 2015, 08:22:59 am »
Thank you soo much guys, that helps alot, sorry for bein such noob. ive changed the code and
played around with "static" and got it working, thanks alot.

2
General / first program, help making grid
« on: January 23, 2015, 07:15:17 am »
hello i am new to the forum as well as sfml and mostly new to programming. just wondering if someone can help me figure out what i did wrong in making a grid, i can only get to be 2x2.

#include <SFML/Graphics.hpp>
int main()
{
    int columns = 3;
    int rows = 3;
    sf::RenderWindow window(sf::VideoMode(800, 600), "TicTacToe");
    sf::RectangleShape grid[columns][rows];


    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear();
        for(int i=0;i<columns;i++){
            for(int j=0;j<rows;j++){
                sf::Vector2f cellSize(200.0f, 200.0f);
                sf::Vector2f cellPos(5.0f,5.0f);
                sf::Vector2f cellPos2(5.0f,5.0f);
                grid[i][j].setSize(cellSize);
                grid[i][j].setOutlineColor(sf::Color::Blue);
                grid[i][j].setOutlineThickness(5.0f);

                if(i%2==1 && j%2==1){
                    grid[i][j].setPosition(cellPos.x + cellSize.x, cellPos.y + cellSize.y);
                }else if(i%2==1 && j%2==0){
                    grid[i][j].setPosition(cellPos.x + cellSize.x, cellPos.y);
                }else if(i%2==0 && j%2==1){
                    grid[i][j].setPosition(cellPos.x, cellPos.y + cellSize.y);
                }else{
                    grid[i][j].setPosition(cellPos);
                }


                window.draw(grid[i][j]);


            }
        }

        window.display();

    }
    return 0;
}

Pages: [1]