Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Need Help From Someone Experienced with SFML  (Read 2585 times)

0 Members and 1 Guest are viewing this topic.

DuvnjakA

  • Newbie
  • *
  • Posts: 19
    • View Profile
    • Email
Need Help From Someone Experienced with SFML
« on: October 04, 2015, 02:02:44 am »
Basically, my situation is this. I have created a small game (an image of the screen is down at the bottom). It's entirely text-based; I used a 2D array to create the map and I created the boundaries and everything using simply cin && cout options. By the way, it runs on C++. I was wondering if there is anyone who could help me, rather than create an entire new game, merely replace the map I have created with actual images (let's say brown for a wall, green for grass, etc.). I'm not trying to build an entirely new game, I merely want to replace my text-drawn map with an actual 2D image.

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Need Help From Someone Experienced with SFML
« Reply #1 on: October 04, 2015, 02:06:15 am »
Ok, and your problem is what? We aren't going to just rewrite your entire program for you (you haven't even shown code) to draw stuff with SFML. To do that start following the tutorials and learn how SFML works and how you draw stuff on the screen.

If you have a specific question feel free to ask it.  ;)
« Last Edit: October 04, 2015, 02:07:52 am by zsbzsb »
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

DuvnjakA

  • Newbie
  • *
  • Posts: 19
    • View Profile
    • Email
Re: Need Help From Someone Experienced with SFML
« Reply #2 on: October 04, 2015, 02:07:56 am »
I'm just asking for someone to help. Rather than go through every small detail of SFML, I was wondering if someone could help guide me in just building a small interface with the map I have. And I was also wondering if I would be able to take my code for movement and how I would implement it into a SFML interface.

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Need Help From Someone Experienced with SFML
« Reply #3 on: October 04, 2015, 02:19:17 am »
The thing is, even if someone was willing to partner with you and help you rewrite your program - you still haven't given any details other than a console screenshot with your map. We have no idea what your program does, what the code looks like, what your map data looks like, what game play is like... You haven't given anything for someone to get an idea of what you are trying to do.

If you take a look at the tutorials, you will see how simple and easy it is to draw a tilemap on the screen. Which depending on your map data might not be very hard to do.
« Last Edit: October 04, 2015, 02:21:14 am by zsbzsb »
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

DuvnjakA

  • Newbie
  • *
  • Posts: 19
    • View Profile
    • Email
Re: Need Help From Someone Experienced with SFML
« Reply #4 on: October 04, 2015, 02:26:29 am »
The game portion of the code is irrelevant.. It's based on a random number generator that only works if you're in the coordinates marked by '~'. My original C++ game is a while loop that continuously redraws a map, given a character position (X,Y). There are limits that the character, marked by 'X', cannot leave the boundaries of the map. As I said above, it's all in one huge 2D array given by example: int Map[17][22] = { ... } . That is how I drew the map, and the map is essentially re-declared and re-initialized every time an outside function called DrawMap(Position of Character) is called. That's how I made it so that the map looks the same every re-drawing except with the 'X' (Character) being in a different position.

So, given all of that, I have something that basically looks like this.

int a = 0, b = 0;
a = _getch();
if (a == 224)
      b = _getch()
      if (b == ...)
the different options for b are the different ASCII values for the arrow keys. That's how I get the 'X' to move around the map. What I'm wondering is, if I replace my map with graphics from SFML, will I still be able to implement this same type of code to move the character? Keep in mind, I have restrictions that say if character is in (x,y) and it's next to a wall, they cannot move into the wall. If you want to see the actual code, I'll send it to you. I don't want to just post my entire program because that ruins the point of me creating my own logic for it, especially because it could definitely be written in a lot of different ways.

ESSENTIALLY, all I'm asking is will I have to entirely rewrite my entire program? Or is it possible to merely replace my DrawMap() function with 2D graphics using SFML?

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Need Help From Someone Experienced with SFML
« Reply #5 on: October 04, 2015, 02:39:20 am »
ESSENTIALLY, all I'm asking is will I have to entirely rewrite my entire program? Or is it possible to merely replace my DrawMap() function with 2D graphics using SFML?

No you probably don't have to rewrite all your game logic, and its very likely you can replace DrawMap() with SFML.

You probably want something like the following....

sf::RenderWindow window(...);

/* do all your game setup */
int Map[MAP_WIDTH][MAP_HEIGHT];

/* load a texture and sprite for each tile type */
sf::Texture playerTexture;
sf::Sprite playerSprite(playerTexture);

while (window.isOpen())
{
  sf::Event event;
  while (window.pollEvent(&event))
  {
    /* pass events off to your game logic for moving the character */
  }

  window.clear();

  //DrawMap(); (below)

  for (int x = 0; x < MAP_WIDTH; x++)
  {
    for (int y = 0; y < MAP_HEIGHT; y++)
    {
      switch (Map[x][y])
      {
         case PLAYER_ID:
           window.draw(playerSprite);
           break;
          /* and so on and so forth */
      }
    }
  }

  window.draw();
}

Seriously, try something and if you get stuck just ask. It is very much possible, but you need to show some effort.
« Last Edit: October 04, 2015, 02:40:56 am by zsbzsb »
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

DuvnjakA

  • Newbie
  • *
  • Posts: 19
    • View Profile
    • Email
Re: Need Help From Someone Experienced with SFML
« Reply #6 on: October 04, 2015, 02:40:49 am »
Okay, thank you! My main concern was that I wouldn't be able to implement the same code and I didn't want to begin altering what I have only to figure out, hey, I need to entirely alter the design of my game. But thank you, I'll give that a shot.

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Need Help From Someone Experienced with SFML
« Reply #7 on: October 04, 2015, 02:43:21 am »
I didn't want to begin altering what I have only to figure out

Another thing then, get git and learn how to use it (there are tons of tutorials out there). That way you can track all changes you make to your code and will always be able to revert whatever changes you make.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

DuvnjakA

  • Newbie
  • *
  • Posts: 19
    • View Profile
    • Email
Re: Need Help From Someone Experienced with SFML
« Reply #8 on: October 04, 2015, 02:45:47 am »
In all honesty, I'm going to keep my original text game, start a new project, copy over the classes and other things and then simply see if I can build a 2D map using SFML.. I'm fairly new to C++ but I understand a lot of the concepts already. This is the first actual thing I've made that's interesting so. :P Thanks for the help once again!