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

Pages: [1]
1
Graphics / Lightening Effect
« on: September 09, 2013, 02:49:14 pm »
Hello Guys..
I was just trying to create a random lightening effect similar to the one used in chicken invaders, if anyone has played the game.
But I really have no clue on how to produce an effect like that.
Do we have to use shaders for such an effect? Or do we need to use advanced Opengl (although I think this is a 2-D effect at most, SFML will be able to produce such an effect). Initially I thought about using Vertex points and implement randomness in them, but it got a bit complex.
So if anyone could help me regarding this, especially if he himself had tried and done this before, I  would be really happy and grateful.

P.S. If possible, check this video :
I want the lightening effect to be a bit like the laser which the jet at the bottom is firing.

2
Network / Packets and Arrays
« on: August 13, 2013, 09:39:50 pm »
I know this question have been asked and answered several times, but since I wasn't satisfied with those, I decided to make a new thread. I have a 2D map array, which I want my server to send to the client. So other than arranging the packet manually like this
{
DataPacket << data[0] << data[1] << data[2]....
}
is there a better and quicker way to store the complete 2D array into the packet and send it to the client?

3
Graphics / Pixel perfect sprite
« on: August 03, 2013, 09:24:54 pm »
Hello everyone.
Can anyone give me a hint on how to do this :
I have a sprite of a character, and all its various angles into a single image. But when I draw the sprite, it draws the complete square i.e. it includes the white background along with the human body and this overlaps in my game and create weird visuals. One solution I see is that I save one sprite with complete pixel accuration per image so that there is no background. But this means 4 images for a single character (top, left , right, bot) and drawing this way would be very inefficient. So is there any way that I have all the movement sprites loaded in a single image and I am able to draw them pixel by pixel with no unnecessary background coming along with it??

4
Network / Working of UDP
« on: August 01, 2013, 02:53:04 pm »
Hello Guys.. Some of you might be knowing me already on forums, I work on visual studio and am learning game programming.
This time I wanted to learn sfml networking, so I decided to use it, but it seems my concepts regarding the same are not clear..
I created a client and server, and i wanted to build something like this :
Client tries to connect to server, sends a connection packet (@ UDP), server receives it, push backs a player in the dynamic list, storing that IP address and sends continuous data to that client. When the client is closed, it again sends a disconnection packet to server, server erases that player and stops sending data to that client. If Client tries to connect to server and don't receive a confirmation, it will keep on sending connection request to server till it finally connects with it.
This is what I intent to create, and the following is the code which I have written. But somehow its not working as accepted, probably because I am doing a mistake which I am not able to make out. So I would please like someone to help me where am I wrong..

Client :
#include<SFML/Graphics.hpp>
#include<SFML/Network.hpp>

#include<fstream>
#define PORT 54000
#define IP "172.22.31.173"
#define REQ(a) connect_request = a;     connect_packet.clear(); connect_packet << connect_request;
using namespace std;
using namespace sf;
int main()
{
       
        RenderWindow client_window(sf::VideoMode(800, 600), "PFR Client");
        fstream fout("log.txt");
        //Creating Incoming and Outgoing sockets
        UdpSocket out_socket, in_socket;
        out_socket.bind(PORT);  in_socket.bind(PORT);
        in_socket.setBlocking(false);

        //Receipent IP Address and Port
        unsigned short port;
        IpAddress sender;

        /* Packets:-
                connect_packet : for connecting/disconnecting from the servers. Sends 100/101 respectively.
                game_packet : for receiving continous game data, failure ensures disconnection from server.
                confirm_packet : for ensuring stable connection. */

        Packet connect_packet, game_packet, confirm_packet;

        //8 Byte Integers for requesting connection, and saving the status of former.
        sf::Int8 connect_request, connect_status = 0;
        while (client_window.isOpen())
    {
                sf::Event event;
                while (client_window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                        {
                                REQ(101);
                                out_socket.send(connect_packet, IP, PORT);
                                client_window.close();
                        }
        }
                if(connect_status == 0)
                {
                        client_window.clear(Color::Blue);
                        REQ(100);
                        out_socket.send(connect_packet, IP, PORT);
                        in_socket.receive(confirm_packet, sender, port);
                        confirm_packet >> connect_status;
                        confirm_packet.clear();
                }
                else
                        client_window.clear(Color::Red);
                client_window.display();
        }
}
 



Server:

#include<SFML\Network.hpp>
#include<SFML\Graphics.hpp>
#include<list>
#include<fstream>
#include"Player.h"

#define PORT 54000
#define PLAYERLOOP for(auto it1 = players.begin(); it1 != players.end(); it1++)
#define PLAYERCHECK PLAYERLOOP if(it1->IP_address == temp_sender)

using namespace std;
using namespace sf;

std::list<Player> players;

int main()
{
        fstream fout("log.txt");
        sf::RenderWindow server_window(sf::VideoMode(800, 600), "PFR Server");
       
        sf::UdpSocket incoming_socket, send_socket;
        incoming_socket.bind(PORT);     send_socket.bind(PORT);
        incoming_socket.setBlocking(false);
        Packet send_packet, connect_packet;
        unsigned short port;    IpAddress temp_sender;
        while (server_window.isOpen())
    {
                sf::Event event;
                while (server_window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                                server_window.close();
        }
                if (incoming_socket.receive(connect_packet, temp_sender, port) == Socket::Done)
                {
                        server_window.clear(Color::Red);
                        sf::Int8 request;
                        connect_packet >> request;
                        // Requesting code 100 for connecting
                        if (request == 100)
                        {                              
                                bool player_exist = false;
                                PLAYERCHECK     {player_exist = true;   break;}
                                if (player_exist == false)
                                {
                                        server_window.clear(Color::Green);
                                        players.push_back(Player(temp_sender));
                                        sf::Int8 connect_status = 87;
                                        Packet confirm_packet; confirm_packet << connect_status;
                                        send_socket.send(confirm_packet, temp_sender, PORT);
                                        connect_packet.clear();
                                }
                        }
                        // Requesting Code 101 for disconnecting
                        else if (request == 101)
                                PLAYERCHECK     {players.erase(it1);    connect_packet.clear(); break;}
                }              
                       
                // Sending data to connected players
                PLAYERLOOP      send_socket.send(send_packet, it1->IP_address, PORT);
                server_window.display();
        }              
       
}      
 

I do hope I have clearly stated my problem, and that someone would be able to make out the mistake for me and help me learn sfml networking.
Thanks in advance

5
Graphics / Re: Performance Lag with Vertex Array
« on: July 05, 2013, 12:42:17 pm »
KK thanks Lauren, I figured out what I was doing wrong, when I read your second idea.
I was using VertexArray for the first time, and so I didn't know exactly how it worked. And out of all the tutorials, I found it a bit short. I copied your tile map but did not understand it properly, especially about resize. I thought resize is the largest coordinates that the VertexArray could store and so I set it to video_width * video_height which went to be more than 10^6 :P
No wonder why it ran so slow even after I tried everything I could. In fact I am amazed how was it able to run at even 3 FPS after storing a million vertices :o
When I read your reply, it made a bit sense about resize and when I tried it, normal speed was back. Guess the mistake was needed, now I am more confident with VertexArrays. Also, I will request you to elaborate the tutorial on this topic if you can since I consider it to be the most useful one (and therefore important too), and a bit harder too, unlike other tutorials which are plain understanding.
One more thing, I did as you said, because I myself wanted to get rid of dummy bricks. But during swapping, is it possible that instead of redefining the new quads, I simply use m_vertices[new_pos] = m_vertices[old_pos]; I tried this, but after 3-4 bricks, it started showing weird results, half triangles instead of quads.
Also, have you removed randomizer class from SFML 2.0??
Thanks again Laurent for the help, you're the best, SFML is such a charm.. :)

6
Graphics / Performance Lag with Vertex Array
« on: July 04, 2013, 03:02:27 pm »
Hello.
I am making my third game BrickBreaker using Visual Studio 2010 and SFML 2.0.
At first I created a paddle and ball sprite along with a score heading string and score value string, and a score background slider. In short I just had total 5 draw calls and till then the game played very smooth.
Then I used vertex array to draw all the Bricks and the background. The texture used was the background texture, while the bricks were only colored, no texture used for them. I did exactly as it was in the tutorial, but after implementing this, my game speed dropped to like 3 FPS. If I remove drawing just the vertex array, speed returns back to normal, which means the background game logic is fine and don't have much issues.

Here is the code I used : Level class is the one responsible for populating the vertex array, while Display does all the drawing.

Level.h :
class Level : public Drawable, public Transformable
{
        int video_width, video_height, brick_count;
        int level;
        Texture back_texture;
        VertexArray m_vertices;
        virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const
    {
        // apply the transform
        states.transform *= getTransform();

        // apply the tileset texture
        states.texture = &back_texture;

        // draw the vertex array
        target.draw(m_vertices, states);
    }
public:
        Level(void);
        ~Level(void);
        void LevelCreate(std::list<Brick> Tile);
        void Initialize(int a, int b);
        void LevelSet(std::list<Brick>* Tile);
};

Level.cpp :
// ... Showing the main function -->
void Level::LevelCreate(std::list<Brick> Tile)
{
        //Populating Background
        sf::Vertex* quad = &m_vertices[0];
        quad[0].position = sf::Vector2f(0, 0);
        quad[1].position = sf::Vector2f(0.8 * video_width, 0);
    quad[2].position = sf::Vector2f(0.8 * video_width, video_height);
    quad[3].position = sf::Vector2f(0, video_height);

        quad[0].texCoords = sf::Vector2f(0, 0);
        quad[1].texCoords = sf::Vector2f(back_texture.getSize().x, 0);
    quad[2].texCoords = sf::Vector2f(back_texture.getSize().x, back_texture.getSize().y);
    quad[3].texCoords = sf::Vector2f(0, back_texture.getSize().y);

        //Populating Bricks
        int i = 1;
        for (auto tile_no = Tile.begin(); tile_no != Tile.end(); tile_no++, i++)
        {
                sf::Vertex* quad = &m_vertices[i*4];
                quad[0].position = sf::Vector2f(tile_no->GetDimension().x, tile_no->GetDimension().y);
        quad[1].position = sf::Vector2f(tile_no->GetDimension().x + tile_no->GetSize().x, tile_no->GetDimension().y);
        quad[2].position = sf::Vector2f(tile_no->GetDimension().x + tile_no->GetSize().x, tile_no->GetDimension().y + tile_no->GetSize().y);
        quad[3].position = sf::Vector2f(tile_no->GetDimension().x, tile_no->GetDimension().y + tile_no->GetSize().y);
                switch(tile_no->GetDurability())
                {
                case 1 :        quad[0].color = quad[2].color = Color::Green;                          
                         break;
                case 2 :        quad[0].color = quad[2].color = Color::Blue;
                         break;
                case 3 :        quad[0].color = quad[2].color = Color::Red;
                        break;
                case 4 :        quad[0].color = Pcolor; quad[2].color = Pcolor2;
                        break;
                }
        }
        //Removing previous held vertices.
        for (; i <= brick_count; i++)
        {
                auto tile_no = Tile.begin();
                sf::Vertex* quad = &m_vertices[i*4];
                quad[0].position = sf::Vector2f(tile_no->GetDimension().x, tile_no->GetDimension().y);
        quad[1].position = sf::Vector2f(tile_no->GetDimension().x + tile_no->GetSize().x, tile_no->GetDimension().y);
        quad[2].position = sf::Vector2f(tile_no->GetDimension().x + tile_no->GetSize().x, tile_no->GetDimension().y + tile_no->GetSize().y);
        quad[3].position = sf::Vector2f(tile_no->GetDimension().x, tile_no->GetDimension().y + tile_no->GetSize().y);
                switch(tile_no->GetDurability())
                {
                case 1 :        quad[0].color = quad[2].color = sf::Color::Green;                              
                        break;
                case 2 :        quad[0].color = quad[2].color = Color::Blue;
                        break;
                case 3 :        quad[0].color = quad[2].color = Color::Red;
                         break;
                }

        }
}

Actually I use a list for my Bricks. Once a brick is destroyed, it is thrown out of the list, but the vertex array still stores it, so basically I use my third for loop for the vertex array to store some other existing Brick in place of removed bricks. I tried removing the third for loop as well, no performance improvement, only a diff. logic where ghost bricks were shown even after they were destroyed, reason I mentioned above.
So I think there is no problem with the logic.

Another class Display uses an object of Level. It does all the Drawing :

void Display::DrawUpdate()
{
        //Clearing Screen
        BB_Win.clear();

        //Drawing Screen
        BB_Win.draw(Stage);//Vertex Array
        Scor.Draw(BB_Win,Bal.BSpeed(),Life,ScoreValue);//Score Values, just 3 draw calls used here.
        BB_Win.draw(Pad.Draw());        BB_Win.draw(Bal.Draw());// 2 draw calls for paddle and brick

        //Displaying Screen
        BB_Win.display();
}

I don't know why vertex array causes such a lag.. If I remove -- BB_Win.draw(Stage); -- command, I get all my performance back. this is my first time using Vertex array, all help appreciated. Do tell me if I need to provide any more information

7
General / Re: Simple Problem With Sprites And Display
« on: April 06, 2013, 04:12:46 pm »
The only reason is that when I started SFML, and when I searched about it, everywhere I read was that 1.6 is the current stable version, and that 2.0 is still in beta. So I decided to use 1.6. I didn't know much about this, so I decided to use 1.6 only. If you say, I will switch to 2.0. And if you could please, also provide me the link for tutorial on building SFML 2.0 on Visual Studio 2010. I tried goggling it, but I got some lengthy solutions with CMake/NMake, so if you could help me in that, I would be very pleased. :)

8
General / Re: Simple Problem With Sprites And Display
« on: April 06, 2013, 02:46:22 am »
Finally got the answer I was looking for!!
Thanks for your reply and the links which you gave. I never knew about screen switching, but guess now everything makes sense.
I appreciate your help in the speed loops too, although they were a bit complex, considering the fact I have just started, so I think I will have to Google more on that.
The problem with Events thing is, I want to reset all the events gathered immediately after the snake change its course, because otherwise if the user repeatedly gives inputs, the snake moves according to those events and gets stuck until those events end, which doesn't happen in normal cases. So I just wanted to end them in a swish after the snake change its course, and start gathering back after a few milli-seconds.

One more thing I need to ask, In SFML 1.6 we have the Shape::Circle command to draw circles. How do I store this Circle in a Sprite?

Thanks once again For all your help.. :)

9
General / Re: Simple Problem With Sprites And Display
« on: April 05, 2013, 08:52:50 am »
Still getting no solution, this 2 Screens thing really bugs me...
And other than limiting frame rate, is there any way in which we can control the speed of our display, without producing imminent lag in events.
And also is there any command to pop all the events in a single go. Using
while(App.GetEvent(Event));
works, but becomes jammy if continously events are given and the control gets stuck in the while loop..
All Help would be appreciated..

10
General / Re: Simple Problem With Sprites And Display
« on: April 03, 2013, 04:44:40 pm »
I did as you said, but I don't know why I have to redraw the background? Doing that works, but I want to know why just drawing only the updates don't work.
I did the following changes :
for(int i = 0; i < 800; i += 20)
        for(int j = 0; j < 600; j += 20)
        {
                BG.SetPosition(i,j);
                Snake.Draw(BG);
        }
for(int j = 0; j < 61; j += 20)
{
        SB.SetPosition(400,j);
        Snake.Draw(SB);
}
while (Snake.IsOpened())
{
        Event Event;
        while (Snake.GetEvent(Event))
        {
                if (Event.Type == sf::Event::Closed)
                Snake.Close();
                if (Snake.GetInput().IsKeyDown(sf::Key::Down))
                {
                        SB.Move(0, 20);
                        Snake.Draw(SB);
                }
        }
        Snake.Display();               
}
 
One thing I have known is calling Display function once works fine. Calling It again produces an empty black screen. On third call, the old screen reappears. And sprites drawn in the consecutive calls are shown on the respective screens. If on alternative calls, old screen reappears with the consecutive updates, then it means old sprites are still stored ad displayed. Then why does this second screen comes in between?  Is there any way to remove this??

11
General / Simple Problem With Sprites And Display
« on: April 03, 2013, 08:04:49 am »
Hello Guys!
I have recently started learning SFML, and I am still a beginner, so my question might be too lame for you, but please try to help me, as it really bugs me out.
I am using Win7 And SFML 1.6 and trying to make simple games (Minesweeper, Snake)
The Problem I want to ask is : I have created sprites, drawn them on the screen and displayed, and then started my main game loop. Everything runs fine here. But when I edit my code and try draw/change sprites according to the events in the game loop and display them again, why it happens that two screens are displayed alternatively, one having the old sprites, and one completely black screen with just the updates sprites? I read the whole tutorials and came to this simple conclusion that I have to redraw the old sprites again and again as well in the main loop, along with the changed sprites. But Why? And is there any other way to this?

For Instance this is my code for snake (It's not completed, I am just checking how to move the snake around)

#include<SFML/Graphics.hpp>
using namespace sf;
int main()
{
        RenderWindow Snake(VideoMode(800,600),"Snake");
        Image BackGround, SnakeBody;
        BackGround.LoadFromFile("C:/Users/Administrator/Desktop/BG.jpg");
        SnakeBody.LoadFromFile("C:/Users/Administrator/Desktop/SB.jpg");
        Sprite BG(BackGround), SB(SnakeBody);
        for(int i = 0; i < 800; i += 20)
                for(int j = 0; j < 600; j += 20)
                {
                        BG.SetPosition(i,j);
                        Snake.Draw(BG);
                }
        for(int j = 0; j < 61; j += 20)
        {
                SB.SetPosition(400,j);
                Snake.Draw(SB);
        }
        Snake.Display();
        while (Snake.IsOpened())
        {
                Event Event;
                while (Snake.GetEvent(Event))
                {
                        if (Event.Type == sf::Event::Closed)
                 Snake.Close();
                        if (Snake.GetInput().IsKeyDown(sf::Key::Down))
                        {
                                SB.Move(0, 20);
                                Snake.Draw(SB);
                        }
                        Snake.Display();
                }
        }
}
 
The Grid displayed is fine and the starting snake too. But when I press the down key, the snake moves in alternative black screen. Same was the case in my minesweeper game, I get the starting tiles displayed well, but when I click on a tile, it opens in another black screen, and then clicking again on the black screen will open corresponding tile in the old screen. Its like both the screen keeps switching after a Event.

I know the simple workout, but I am not satisfied with that, and I need to know why 2 screen appears, so that I can try to find another way.
I have attached the source code, as well as the images.
Please do tell me the reason, another way if possible, and then a simple but satisfying algo for moving a snake when key pressed (I searched the net, I just got complex algo for that).
Thank You

[attachment deleted by admin]

Pages: [1]