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

Pages: [1]
1
General / Re: Recursive backtracking maze error
« on: January 28, 2017, 03:09:10 pm »
Thanks! Got it working using my own range checks!

2
General / Recursive backtracking maze error
« on: January 28, 2017, 12:24:53 pm »
Dear you,

Ive implemented the recursive backtracker maze generation algorithm in sfml. The problem is that the current cell leaves the grid on the left or the right and pops up on the other side. But I dont want that.

Heres my getNeighbours function:

Cell* Cell::checkNB(std::vector <Cell> &grid, int cols)
{
        std::vector <Cell*> nbs;
        Cell* top;
        Cell* right;
        Cell* bottom;
        Cell* left;

        try {
                int i = indice(xPos, yPos - 1, cols);
                top = &grid.at(i);
        }catch(std::out_of_range)
        {
                top = nullptr;
        }
        try {
                int i = indice(xPos + 1, yPos, cols);
                right = &grid.at(i);
        }catch(std::out_of_range)
        {
                right = nullptr;
        }
        try {
                int i = indice(xPos, yPos + 1, cols);
                bottom = &grid.at(i);
        }catch(std::out_of_range)
        {
                bottom = nullptr;
        }
        try {
                int i = indice(xPos - 1, yPos, cols);
                left = &grid.at(i);
        }catch(std::out_of_range)
        {
                left = nullptr;
        }

        if(top != nullptr && !top->visited)
        {
                top->chosenDir = "top";
                nbs.push_back(top);
        }
        if (right != nullptr && !right->visited)
        {
                right->chosenDir = "right";
                nbs.push_back(right);
        }
        if (bottom != nullptr && !bottom->visited)
        {
                bottom->chosenDir = "bottom";
                nbs.push_back(bottom);
        }
        if (left != nullptr && !left->visited)
        {
                left->chosenDir = "left";
                nbs.push_back(left);
        }
        if(nbs.size() > 0)
        {
                return nbs[rand() % nbs.size()];
        }else
        {
                return nullptr;
        }

}

the indice function:


int indice(int i, int j, int cols)
{
     return i + j *cols;
}

 

Its only leaving on the right and left, top and bottom are fine.

Thanks for any help!

Yours, me.

3
General / How to use SFML in my DLL?
« on: November 27, 2016, 05:24:08 pm »
I simply included SFML as usually and it worked. Then I wanted to make a dll using sfml. So I included it and started writing my code and the code was fine. But when i wanted to run it, vs2015 gave me some strange errors:
int the rect.inl:

Error   C2589'(': illegal token on right side of '::'    sfml-2.4.1\include\sfml\graphics\rect.inl   Line: 81   
Error   C2059   syntax error: '::' sfml-2.4.1\include\sfml\graphics\rect.inl   Line: 81   

And the same errors for diverse lines.

4
Graphics / Re: Clicking on a Sprite to highlight it
« on: July 19, 2016, 08:57:57 pm »
Ive reworked my code and its working now. Thanks to everyone who helped me! Props to Laurent for the hint. ;)

5
Graphics / Re: Clicking on a Sprite to highlight it
« on: July 19, 2016, 08:18:42 pm »
Thanks for the help!

6
Graphics / Re: Clicking on a Sprite to highlight it
« on: July 19, 2016, 05:02:17 pm »
I wrote this:
        int TileID[] = {0};
        sf::Texture zero;
        sf::Texture TileTexture[] = {zero};

if (unselectedGrid.getGlobalBounds().contains(mousePosition) && sf::Mouse::isButtonPressed(sf::Mouse::Left))
                                {
                                        unselectedGrid.setTexture(station);
                                        int id = (x+1) * (y+1);
                                        TileID[sizeof(TileID)] = id;
                                        TileTexture[sizeof(TileTexture)] = station;
                                       
                                }
for(int i = 0; i < sizeof(TileID); i++)
                                {
                                        if((x + 1) * (y + 1) == TileID[i])
                                        {
                                                unselectedGrid.setTexture(TileTexture[i]);
                                        }
                                }

 

But i get "Access violation at memory..."
But just once.
If i run it again its not complaining but its running like without that code

7
Audio / Re: Music not working
« on: July 18, 2016, 01:25:36 pm »
vlc says its codec is MPEG Audio Layer 1/2(mpga)

8
Audio / Re: Music not working
« on: July 16, 2016, 02:37:08 pm »
"Waveform Audio File Format (WAVE, or more commonly known as WAV due to its filename extension)(rarely, Audio for Windows) is a Microsoft and IBM audio file format standard for storing an audio bitstream on PCs" -Wikipedia

9
Audio / Re: Music not working
« on: July 16, 2016, 12:46:06 pm »
.wav

10
Audio / Music not working
« on: July 15, 2016, 10:13:11 pm »
I just wrote this:
#include <SFML\Audio\Music.hpp>
        sf::Music music;
        if(!music.openFromFile("music_background.wav"))
        {
                std::cout << "ERROR" << std::endl;
        }
        music.setLoop(true);
        music.play();
 
But i got an error message in cmd:
Failed to open sound file "music_background.wav" (format not supported)
Failed to play audio stream: sound parameters have not been initialized (call initialize() first)

How can i fix that?

11
Graphics / Re: Clicking on a Sprite to highlight it
« on: July 15, 2016, 03:31:41 pm »
Is it possible to make the tile stay selected? (general)

12
Graphics / Re: Clicking on a Sprite to highlight it
« on: July 15, 2016, 12:26:59 am »
Thanks! worked.

13
Graphics / Re: Clicking on a Sprite to highlight it
« on: July 14, 2016, 10:45:56 pm »
#include "stdafx.h"
#include <SFML\Graphics.hpp>
#include <SFML\Window.hpp>
#include <iostream>
#include <string>

sf::RenderWindow window(sf::VideoMode(1600, 900), "Name");


int main()
{

        sf::Font font_freeSans;
        font_freeSans.loadFromFile("FreeSans.ttf");

        sf::Texture station_texture;
        station_texture.loadFromFile("station_cockpit_texture.png");

        sf::Texture selected;
        selected.loadFromFile("selected.png");

        sf::Texture unselected;
        unselected.loadFromFile("unselected.png");   //LOADING TEXTURES


        sf::Sprite unselectedGrid;
        unselectedGrid.setTexture(unselected);
        unselectedGrid.setScale(0.5, 0.5);

        while(window.isOpen())
        {
                sf::Vector2f mousePosition = window.mapPixelToCoords(sf::Mouse::getPosition(window));

                window.clear();

                sf::Event event;
                while(window.pollEvent(event))
                {
                        if(event.type == sf::Event::Closed)
                        {
                                window.close();
                        }
                }
                for(int x = 0; x < 5; x++)
                {
                        for(int y = 0; y < 5; y++)
                        {
                                if (unselectedGrid.getGlobalBounds().contains(mousePosition))
                                {
                                        unselectedGrid.setTexture(selected);
                                }
                                if(x == 2 && y == 2)
                                {
                                        unselectedGrid.setTexture(station_texture);
                                }
                                unselectedGrid.setPosition(x * 137.5, y * 137.5);
                                window.draw(unselectedGrid);
                                std::cout << "Tile created (" << x << "," << y << ")" <<  std::endl;
                                unselectedGrid.setTexture(unselected);
                        }
                }

                window_spaceport.display();
        }

    return 0;
}
 

14
Graphics / Re: Clicking on a Sprite to highlight it
« on: July 14, 2016, 09:44:19 pm »
Ive followed Hapax and Mortals tipps and reworked my code but now the tile below is highlighted

15
Graphics / Clicking on a Sprite to highlight it
« on: July 13, 2016, 10:38:30 pm »
Dear reading forum user,
i used this script to check if a sprite was clicked:
bool isTileClicked(sf::Sprite sprite)
{
        if(sf::Mouse::getPosition().x > sprite.getPosition().x
                && sf::Mouse::getPosition().x < sprite.getPosition().x + (sprite.getScale().x * 275)
                && sf::Mouse::getPosition().y > sprite.getPosition().y
                && sf::Mouse::getPosition().y < sprite.getPosition().y + (sprite.getScale().y * 275)
                && sf::Mouse::isButtonPressed(sf::Mouse::Left)
                )
        {
                return true;
        }
        else
        {
                return false;
        }
}

In the loop/grid loop i wrote:
if(isTileClicked(unselectedGrid) == true)
                                {
                                        unselectedGrid.setTexture(selected);
                                }

But only the sprite 2 below and 1 to the right was highlighted.

How can i fix that?

Just ask if you need more snippets.

EDIT:
I used the relative mouse position and getglobalbounds to create a new function but now the tile below is highlighted

Pages: [1]
anything