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

Pages: [1] 2
1
Graphics / Re: Tilebased map
« on: October 14, 2013, 10:13:01 pm »
I saw a tutorial of enums but I don't understand this:
        enum Terrain
        {
             water,
             lava,
             grass,
        };
I did this but now I don't understand how to assign i.e a water texture to Terrain::water.
I couldnt find a good tutorial on enums and I really don't know what to do :(
Can someone explain me enums and then I'll try to make tiles.If I fail I'll ask someone for help.

2
Graphics / Re: Tilebased map
« on: October 13, 2013, 05:45:31 pm »
I'll try to find that tutorial with vertex array.
I'll see what a rendertexture is.
I assigned water the same way I did with grass and lava.
I'll see what an enum is.
I made a rectangle,movement and added collision like this:
rect.move(xVelocity, 0);

for(int i=0; i < 56;i++)
{
       if(rect.getGlobalBounds().intersects(waterCollision[i].getGlobalBounds())) rect.move(-xVelocity, 0);
}

rect.move(0, yVelocity);

for(int i=0; i < 56;i++)
{
       if(rect.getGlobalBounds().intersects(waterCollision[i].getGlobalBounds())) rect.move(0, -yVelocity);
}
 

3
Graphics / Tilebased map
« on: October 13, 2013, 01:43:18 pm »
I'm trying to make a tilebased map.
I made a texture for water,grass,lava.
Then I made a rectagle shapes:
        sf::RectangleShape grass;
        grass.setTexture(&grassTexture);
        grass.setSize(sf::Vector2f(50, 50));
       
        sf::RectangleShape water;
        water.setTexture(&waterTexture);
        water.setSize(sf::Vector2f(50, 50));

        sf::RectangleShape lava;
        lava.setTexture(&lavaTexture);
        lava.setSize(sf::Vector2f(50, 50));

Then and array for tiles:
sf::RectangleShape map[16][12];

And I put like this:
map[0][0] = grass;
map[0][1] = grass;
.....
map[15][11] = lava;

It takes a lot of space for all this.

Next I made and array for water collision and put in it all water tiles:
sf::RectangleShape waterCollision[56] = {map[1][1] , map[1][2] ,map[1][4]...};

And the at the end I draw them:
                for(int d=0; d < 16; d++)
                        {
                                for(int f=0; f < 12; f++)
                                {
                                        window.draw(map[d][f]);
                                }
                        }

All this works but is there any easier way to assign water,lava,grass to tiles?
And is there any easier way to do water collision?

Sorry for my english.

4
Graphics / Tiled map with vectors
« on: September 03, 2013, 04:30:09 pm »
I made this tiled map with vectors.
First I made vectors for 4x4 map:
        std::vector< std::vector<int> > map(4, std::vector<int>(4));
    // Define the map
    map[0][0] = 0;
    map[0][1] = 1;
    map[0][2] = 0;
    map[0][3] = 0;
    map[1][0] = 0;
    map[1][1] = 0;
    map[1][2] = 0;
    map[1][3] = 0;
    map[2][0] = 0;
    map[2][1] = 0;
    map[2][2] = 0;
    map[2][3] = 0;
    map[3][0] = 0;
    map[3][1] = 0;
    map[3][2] = 0;
    map[3][3] = 1;
 
Then I made sprites for grass and water:
        std::vector<sf::Sprite> tiles(2);
        tiles[0] = sf::Sprite(grass);
        tiles[1] = sf::Sprite(water);
And then draw it:
                        for (int x = 0; x < map.size(); x++)
                        {
            for (int y = 0; y < map[x].size(); y++)
                        {
                int tileId = map[x][y];

                                tiles[tileId].setPosition(x * 100, y * 100);
                                window.draw(tiles[tileId]);
            }
        }
I also added a rectangle and movement.
Now I don't know how to acces water tiles and add collision to them.
Sorry for my english.
Reply if you need full code.

5
Graphics / Ball speed
« on: August 22, 2013, 04:36:44 pm »
Here is my code:
#include <SFML/Graphics.hpp>
#include <iostream>

int main()
{
        //Creation
        sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Game");
        //60 FPS
        window.setFramerateLimit(60);

        window.setKeyRepeatEnabled(false);
        //States for buttons and events
        sf::Event event;
        bool play= true;
       
       
        //Vars
        int ballXVelocity = 6;
        int ballYVelocity = 6;

        //Render shapes
        sf::CircleShape ball;
        ball.setRadius(25);
        ball.setPosition(375,275);
        ball.setFillColor(sf::Color::Blue);

        //Game loop
        while(play == true)
        {
                //EVENTS
                while (window.pollEvent(event))
                {

                        if(event.type == sf::Event::Closed)
                        {
                                play = false;
                        }
                        if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape)
                        {
                                play = false;
                        }

               
                }


                //LOGIC
               
                ball.move(ballXVelocity, ballYVelocity);

                if(ball.getPosition().x < 0 || ball.getPosition().x > 750) ballXVelocity = -ballXVelocity;
                if(ball.getPosition().y < 0 || ball.getPosition().y > 550) ballYVelocity = -ballYVelocity;



                //RENDERING

                        window.clear();

                        window.draw(ball);

                        window.display();

        }

        //Clean up
        window.close();

    return 0;
}
I made a ball with x velocity = -6 and y velocity = -6
I want now to increase x and y velocity by 1 every 5 second.
How can I do that?
I hope it's not a dumb question and you understand me.

6
Graphics / Re: Problems with drawing map
« on: July 28, 2013, 11:05:47 am »
Yes, it's the breakout game.

How do you mean store them in a container?

7
Graphics / Problems with drawing map
« on: July 28, 2013, 10:49:52 am »
I'm trying to make a game but I have problem with graphics.
I don't know the name of the game but it's the one with paddle and ball where you need to destroy the bricks.
I made the paddle and ball moving and now I don't know how to make the bricks.
If you need pictures or code comment please.

8
Graphics / Re: Array and tiles
« on: July 25, 2013, 08:18:35 pm »
Quote
if(t0.getGlobalBounds().intersects(otherShape.getGlobalBounds())) {
// do something since targetShape has collided with t0 shape.
}
I already did that and it's not working.
My shape can't move.
Btw its position is 0,0 as t1(grass) position, it doesn't draw on t0(water) at the start.

9
Graphics / Re: Array and tiles
« on: July 25, 2013, 06:12:06 pm »
How I can make collision with t0 rectangle shape?

10
Graphics / Array and tiles
« on: July 25, 2013, 12:29:37 pm »
I made 2 pictures and loaded them:
        sf::Texture grass;
        if(!grass.loadFromFile("Data/grass.png"))
        {
                return EXIT_FAILURE;
        }

        sf::Texture water;
        if(!water.loadFromFile("Data/water.png"))
        {
                return EXIT_FAILURE;
        }
Rendered:
        sf::RectangleShape t1;
        t1.setSize(sf::Vector2f(50, 50));
        t1.setTexture(&grass);
       
        sf::RectangleShape t0;
        t0.setSize(sf::Vector2f(50, 50));
        t0.setTexture(&water);
Then I made this multidimensional array called tile:
sf::RectangleShape tile[4][4] = {
                {t1,t1,t1,t1},
                {t1,t0,t0,t0},
                {t1,t1,t1,t1},
                {t0,t0,t0,t0}
        };
and added those 2 pictures into it.
Now when I draw this:
                        window.clear();

windw.draw(tile[0][0]);
                       
                        window.display();
Program draws the t1 rectangle shape.

So, my question is how I can draw all those 16 items in array so they are placed like in array.
I tried to make a for loop like this:
for(int x=0;x<4;x++)
{
      for(int y=0;y<4;y++)
      {
            window.draw(tile[x][y]);
      }
}
 
Program just draws the tile[3][3] which is t0;

I hope you understand my english and sorry if this is a stupid question.

11
Graphics / Re: Drawing in class
« on: July 20, 2013, 09:51:56 pm »
Ok, I'll learn some more c++, but I can't buy any of those books...

12
Graphics / Re: Drawing in class
« on: July 19, 2013, 07:32:03 pm »
I have a good understanding of c++.
Just I have always been using class in main.cpp not in separated file.And my question is how to draw everything in there.

13
Graphics / Drawing in class
« on: July 19, 2013, 02:17:13 pm »
I want to put all my drawings in separated file.
Can I do that?
How to do that?
I want all my logic and events in main.cpp.
But drawing in one class named eg Drawing, but I want that class to be in separated file.

14
Graphics / Re: Xml
« on: July 18, 2013, 10:51:42 pm »
How I can use that tile-map loader??

15
Graphics / Xml
« on: July 18, 2013, 06:47:55 pm »
I used tiled http://www.mapeditor.org/ for making a tiled map and saved it as xml.
So now how I can use this xml to draw it in the game?
I can make it csv too.

Pages: [1] 2