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

Pages: [1] 2
1
Graphics / Drawing a short line between Sprite & Mouse
« on: June 09, 2018, 11:31:09 pm »
I have figured out how to draw a line between a sprite and the mouse. I am trying to make the line shorter. I want to draw a bullet pointing towards the cursor. How would I do that?
The game is a top down game. I have tried dividing the mouse cursor's position, also I have tried subtracting it by 5.

Thanks in advance

2
Graphics / need help with bloom
« on: June 08, 2018, 11:29:36 am »
I have been trying to add a bloom effect for about 2 hours and 30 minutes going off of the SFML Game Development. I could not figure out the BloomEffect & PostEffect classes. If someone has a bloom tutorial/source/class and would like to share it to me, that would be greatly appreciated!

3
Graphics / How to check if a sprite is touching a line
« on: May 22, 2018, 07:59:55 pm »
As the title says, I am drawing a line between 2 verticies.. One is located at the local player sprite, the other goes to the mouse. How can I tell if a different sprite is touching the line in between local & my mouse?

4
Network / Port-Forwarding with LAN
« on: May 09, 2018, 04:31:26 pm »
I am making a program that only requires LAN connection.
Do I need to Port-Forward a port for UDP connection?
If not, how do I tell which port the client needs to connect to?
Or can I just pick a port at random?

5
Graphics / Re: Need help with move function
« on: May 03, 2018, 05:13:49 pm »
One way is to seperate your movement:
You first move only left and right, check for collision, then you only move up and down and check for collision again.
This way you can easily detect from which side you collided. Keep in mind that you will now spend double the processing power for your collision which in your case is quite expensive (PixelPerfect).

You might consider first testing for normal BoundingBox collision and only go PixelPerfect if needed.

And as for pixel perfect collision, would it be better if i nested it into another if statement so it didnt execute constantly?

if (sprite.getGlobalBounds().intsects(collider.getGlobalBounds()){ if PixelPerfectCollision(sprite, collider){ //* sick codes*/ } }
soz if any typos, am away from my pc

6
Graphics / Re: Need help with move function
« on: May 03, 2018, 05:00:48 pm »
Thanks for the response!
Question, what do you mean exactly by testing left & right then testing up & down?

7
Graphics / Need help with move function
« on: May 03, 2018, 02:50:23 am »
Can someone help me with my move function for my main sprite?
My code:
    void Move(RenderWindow* window, Vector2i UPDOWN, Vector2i LEFTRIGHT, Vector2f UPDOWNSPEED, Vector2f LEFTRIGHTSPEED, Sprite collider) {
        if (window->hasFocus()) {
            if (GetAsyncKeyState(UPDOWN.x) && collisionDir != Up) {
                if (collisionDir == None && Collision::PixelPerfectTest(sprite, collider)) { collisionDir = Up; }
                else {
                    sprite.move(0.0f, UPDOWNSPEED.x);
                    //Game::World::tileMap.setCamera(Game::World::tileMap.getCamera() + sf::Vector2f(0.0f, UPDOWNSPEED.x));
                }
            }
            if (GetAsyncKeyState(UPDOWN.y) && collisionDir != Down) {
                if (collisionDir == None && Collision::PixelPerfectTest(sprite, collider)) { collisionDir = Down; }
                else{
                    sprite.move(0.0f, UPDOWNSPEED.y);
                    //Game::World::tileMap.setCamera(Game::World::tileMap.getCamera() + sf::Vector2f(0.0f, UPDOWNSPEED.y));
                }
            }
            if (GetAsyncKeyState(LEFTRIGHT.x) && collisionDir != Left) {
                if (collisionDir == None && Collision::PixelPerfectTest(sprite, collider)) { collisionDir = Left; }
                else {
                    sprite.move(LEFTRIGHTSPEED.x, 0.0f);
                    //Game::World::tileMap.setCamera(Game::World::tileMap.getCamera() + sf::Vector2f(LEFTRIGHTSPEED.x, 0.0f));
                }
            }
            if (GetAsyncKeyState(LEFTRIGHT.y) && collisionDir != Right) {
                if (collisionDir == None && Collision::PixelPerfectTest(sprite, collider)) { collisionDir = Right; }
                else {
                    sprite.move(LEFTRIGHTSPEED.y, 0.0f);
                    //Game::World::tileMap.setCamera(Game::World::tileMap.getCamera() + sf::Vector2f(LEFTRIGHTSPEED.y, 0.0f));
                }
            }
            if (!Collision::PixelPerfectTest(sprite, collider)) { collisionDir = None; }
        }
    }
all of the collisionDir is for detecting which side the collider is at
if anyone has a better way i'd love to do it
if you switch positions quick enough, you can travel through a collider
and if you walk diagnally you can travel with them
any suggestions for better way to detect which side the collider is at?
or just a better way to do movement in general, i guess
here is proper use for calling Move func btw
Game::Entity::g_eLocal.Move(window, Vector2i(VK_UP, VK_DOWN), Vector2i(VK_LEFT, VK_RIGHT), Vector2f(-5.0f, 5.0f), Vector2f(-5.0f, 5.0f), Wall);

8
Graphics / Re: Coordinates of the whole texture.
« on: May 02, 2018, 05:16:29 pm »
No prob dad

9
Graphics / Re: Coordinates of the whole texture.
« on: May 02, 2018, 04:56:03 pm »
To make something with an irregular shape, import image as a texture then make a sprite and set it's texture to the one you loaded in.
As for collision with the mouse, you should check out:
AND/OR https://github.com/SonarSystems/SFML-Box2D-Tutorials/tree/master/SFML/Tutorial%20013%20-%20Pixel%20Perfect%20Collision%20Detection.

10
Graphics / Question about selbaward's tilemap
« on: May 02, 2018, 09:48:43 am »
Link to source used:
https://github.com/Hapaxia/SelbaWard/wiki/Tile-Map
My tilemap code:
        //TileMap Stuff
        Tiles = ENG::TextureFromFile(&MainWindow, "Data//Images//tileMap.png", "main", false, false, true);
        for (auto& tile : levelData) { tile = rand() % 3; } // pick one of the four available tiles at "random"
        tileMap.setLevel(levelData); // connect level data
        tileMap.setLevelWidth(Engine::windowSize.x); // width of 125 means that the level data gets processed as if it is 125 x 80
        tileMap.setSize({ 1280, 720 }); // size of tile map's rendered image
        tileMap.setGridSize({ 40, 24 }); // size of tile map grid (number of tiles)
        tileMap.setTexture(Tiles);
        tileMap.setNumberOfTextureTilesPerRow(3);
        tileMap.setTextureTileSize({ 64, 64 }); // actual size of tiles within the texture
        tileMap.setPosition(MainWindow.mapPixelToCoords(Vector2i(0, 0)));
        tileMap.update();
        window->draw(tileMap);
        //TileMap Stuff
what it draws:
https://i.imgur.com/LZiFJgB.png
it only randomly selects the first 7 rows
my tilemap:
https://imgur.com/a/lKJk3SX
I'm not understanding what setSize & setGridSize & setLevelWidth do.

11
Graphics / Re: Question about drawing tilemaps on a modified view
« on: May 02, 2018, 12:13:23 am »
Edit: Solved. I'm literally mentally disabled.
Solution:
TM.setPosition(window->mapPixelToCoords(Vector2i(0, 0)));

12
Graphics / Question about drawing tilemaps on a modified view
« on: May 02, 2018, 12:10:58 am »
I can't figure out how to draw a tilemap centered at the origin of the window with a modified view.
Here is my modified view:
View view;
view.setCenter(Game::Entity::g_eLocal.sprite.getPosition());
view.setSize(((float)Engine::windowSize.x), ((float)Engine::windowSize.y));
view.zoom(0.75);
window->setView(view);
My TileMap class:
https://www.sfml-dev.org/tutorials/2.1/graphics-vertex-array.php#example-tile-map
Here is my tilemap:
TileMap TM;
if (!TM.load("Data//Images//64x64grass.png", sf::Vector2u(32, 32), level, 16, 8)) { return -1; }
When I draw the tilemap, it doesn't set it to the origin of the current view.

I have determined that the view zoom is messing it up:
zoom = 1 works perfectly:
https://i.imgur.com/0dSloIz.png
zoom = 0.75 does not:
https://i.imgur.com/KidZMNY.png
it does not update the origin of the window


Also, how do i set the top left corner of the tilemap to the origin of the window?

13
No problem! GLHF with SFML!

14
You're missing a game loop.
Also, don't sleep for 4 seconds. (Don't sleep for more than 1 ms I'd say.
Your loop needs to be running very often.
Also, window.display() needs to be at the end.

while (window.isOpen()){
   window.clear(); //you can put a color in the parameters to set your window background to ex: Color::Red
   sf::Font font;
   sf::Text text;

   if (!font.loadFromFile("munro.ttf")) { return 1; }

   font.loadFromFile("munro.ttf");
   text.setCharacterSize(24);
   text.setStyle(0x02); // (Bold. Not important since it doesn't show up with it set to bold or not.)
   text.setFont(font);
   text.setString("Testing text");
   window.draw(text);
   window.display();
}

Edit: See here for tut about game loops:

15
Graphics / Re: Question about drawing tilemaps off-screen
« on: May 01, 2018, 03:53:33 pm »
Why do you want to draw anything off-screen? This just consumes unnecessary resources. Imagine drawing an infinite map, it would take you an infinite amount of time to do that.

Try to draw only those tiles (and other objects), which are visible to your view. For small games this is not so important, because your computer can probably handle it, but for your scale this doesn't apply anymore.

For that you want to calculate which tiles are visible and recreate the vertex array with them every frame.
You also don't want to store every tile, just the ones nearby. (take a look at chunks)

As for how to generate your map: it depends on what type of map you want to make. There are many examples for various types of maps online. Perlin Noise is often used for that. Simplex Noise, Voronoi Map, etc...

To draw your infinite map: you load (or generate) only nearby tiles (chunks) and draw just the visible ones from those on screen.

So something like this?
(sorry for really bad psuedo-code, am away from my PC)

create backdrop sprite that is the size of the window and is always set to origin of window.
draw backdrop sprite
create grass tilemap

while backdrop is visible{
   draw grass tilemap
}


Pages: [1] 2