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

Author Topic: Tiled map with arrays  (Read 6363 times)

0 Members and 1 Guest are viewing this topic.

FRex

  • Hero Member
  • *****
  • Posts: 1843
    • View Profile
    • My GitHub Page
    • Email
Tiled map with arrays
« on: September 25, 2012, 04:00:44 pm »
I've added totally basic tiled map example to source section:

https://github.com/SFML/SFML/wiki/Source%3A-TileMap

The wiki is quite... painful to work with.
I don't know how to make 'real' name disappear.
If I do "# Basic Tiled Map using SFML's VertexArrays" like other pages seem to, it doesn't show up at all and real name is still there.
Also I like how I had to kind of 'guess' that ```cpp makes code c++ while helper text says to indent entire block with at least 4 spaces or 1 tab.
« Last Edit: October 18, 2012, 08:55:05 pm by FRex »
ZipSavings, script to count rar/7z/zip savings: https://goo.gl/vvBj5M
LuaConsole: https://goo.gl/X4kRUk
FoxRaycaster: https://goo.gl/27nVS8
Small Games - Heart, Routing and Snek: https://goo.gl/15ZGWE https://goo.gl/k5gwWD https://goo.gl/4nKPnT
Botes - a notes app in Pascal: https://goo.gl/bzTqsi

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32466
    • View Profile
    • SFML's website
    • Email
Re: Tiled map with arrays
« Reply #1 on: September 25, 2012, 04:08:22 pm »
Quote
I don't know how to make 'real' name disappear.
You can't. The github team changed that a few months ago, now the page title is always the page name (which is also the URL... not a very good choice in my opinion).

Quote
Also I like how I had to kind of 'guess' that ```cpp makes code c++ while helper text says to indent entire block with at least 4 spaces or 1 tab.
Both solutions work.
The ```cpp tag is explained somewhere (for example, you can see it when you post a comment on the tracker), but apparently not on the wiki.

Don't hesitate to send your feedback to the github team. This deserves to be improved.
Laurent Gomila - SFML developer

FRex

  • Hero Member
  • *****
  • Posts: 1843
    • View Profile
    • My GitHub Page
    • Email
Re: Tiled map with arrays
« Reply #2 on: September 25, 2012, 04:15:17 pm »
Quote
Both solutions work.
The ```cpp tag is explained somewhere (for example, you can see it when you post a comment on the tracker), but apparently not on the wiki.
I think indentation made everything(comments, datat type names, lines) the same color(which is kind of not desirable).
ZipSavings, script to count rar/7z/zip savings: https://goo.gl/vvBj5M
LuaConsole: https://goo.gl/X4kRUk
FoxRaycaster: https://goo.gl/27nVS8
Small Games - Heart, Routing and Snek: https://goo.gl/15ZGWE https://goo.gl/k5gwWD https://goo.gl/4nKPnT
Botes - a notes app in Pascal: https://goo.gl/bzTqsi

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 9720
    • View Profile
    • development blog
    • Email
Re: Tiled map with arrays
« Reply #3 on: September 25, 2012, 04:20:10 pm »
Nice! :)

What exactly is the reason for leaving out the include files & guards? ???

Also could you (or am I allowed to) format the main loop a bit better? I mean at the moment it's just a hugh block of code which seems quite hard to read. Or is there a reason why you don't insert spaces/break lines? ;)

So this
                while(app.pollEvent(eve))if(eve.type==sf::Event::Closed)app.close();
                if(sf::Keyboard::isKeyPressed(sf::Keyboard::Q))cam.zoom(1.05f);
                if(sf::Keyboard::isKeyPressed(sf::Keyboard::W))cam.move(0.f,-10.f);
                if(sf::Keyboard::isKeyPressed(sf::Keyboard::E))cam.zoom(0.95f);
                if(sf::Keyboard::isKeyPressed(sf::Keyboard::A))cam.move(-10.f,0.f);
                if(sf::Keyboard::isKeyPressed(sf::Keyboard::S))cam.move(0.f,10.f);
                if(sf::Keyboard::isKeyPressed(sf::Keyboard::D))cam.move(10.f,0.f);

Would turn into this
                while(app.pollEvent(eve))
                        if(eve.type==sf::Event::Closed)
                                app.close();
                if(sf::Keyboard::isKeyPressed(sf::Keyboard::Q))
                        cam.zoom(1.05f);
                if(sf::Keyboard::isKeyPressed(sf::Keyboard::W))
                        cam.move(0.f,-10.f);
                if(sf::Keyboard::isKeyPressed(sf::Keyboard::E))
                        cam.zoom(0.95f);
                if(sf::Keyboard::isKeyPressed(sf::Keyboard::A))
                        cam.move(-10.f,0.f);
                if(sf::Keyboard::isKeyPressed(sf::Keyboard::S))
                        cam.move(0.f,10.f);
                if(sf::Keyboard::isKeyPressed(sf::Keyboard::D))
                        cam.move(10.f,0.f);
Or at least add a space after the if-statement, so one can differentiat what is the check and what is the action with one look. :D
Official FAQ: https://www.sfml-dev.org/faq.php
Nightly Builds: https://www.nightlybuilds.ch/
——————————————————————
Dev Blog: https://dev.my-gate.net/
Thor: http://www.bromeon.ch/libraries/thor/

FRex

  • Hero Member
  • *****
  • Posts: 1843
    • View Profile
    • My GitHub Page
    • Email
Re: Tiled map with arrays
« Reply #4 on: September 25, 2012, 04:52:38 pm »
Quote
What exactly is the reason for leaving out the include files & guards?
#pragma once - Not part of the standard :(
include guards - No idea really ;D
includes and pre compiled headers - vc++ doesn't require includes of bases and members if they are in precompiled header, this may vary across compilers, I don't know, also anyone is free to do whatever they want: include std and sfml files directly or in precompiled header(that may or may not work on same rules between compilers and almost certainly is not going to be named same all the time)
Quote
Also could you (or am I allowed to) format the main loop a bit better?
Knock yourself out, my formatting isn't best. I try to always use sharp brackets or not break the line if they're missing so I don't do something like:
while(app.pollEvent(foo))
{
if(foo.type==sf::Event::Closed)
std::cout<<"Boo.. hoo..hoo :'(\n";
}
and then change it into:
{
if(foo.type==sf::Event::Closed)
app.close();
std::cout<<"Boo.. hoo..hoo :'(\n";
}
« Last Edit: September 25, 2012, 04:56:06 pm by FRex »
ZipSavings, script to count rar/7z/zip savings: https://goo.gl/vvBj5M
LuaConsole: https://goo.gl/X4kRUk
FoxRaycaster: https://goo.gl/27nVS8
Small Games - Heart, Routing and Snek: https://goo.gl/15ZGWE https://goo.gl/k5gwWD https://goo.gl/4nKPnT
Botes - a notes app in Pascal: https://goo.gl/bzTqsi

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32466
    • View Profile
    • SFML's website
    • Email
Re: Tiled map with arrays
« Reply #5 on: September 25, 2012, 05:01:03 pm »
Forget about #pragma once and precompiled headers. These are non-standard optimizations that shouldn't be mentioned in such a tutorial.
Just use clean standard C++: put header guards in each header file, and include what you need where you need it.
Laurent Gomila - SFML developer

FRex

  • Hero Member
  • *****
  • Posts: 1843
    • View Profile
    • My GitHub Page
    • Email
Re: Tiled map with arrays
« Reply #6 on: September 25, 2012, 05:12:32 pm »
Ok, I've added include guards and made loop more eye-friendly.
ZipSavings, script to count rar/7z/zip savings: https://goo.gl/vvBj5M
LuaConsole: https://goo.gl/X4kRUk
FoxRaycaster: https://goo.gl/27nVS8
Small Games - Heart, Routing and Snek: https://goo.gl/15ZGWE https://goo.gl/k5gwWD https://goo.gl/4nKPnT
Botes - a notes app in Pascal: https://goo.gl/bzTqsi

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 9720
    • View Profile
    • development blog
    • Email
Re: Tiled map with arrays
« Reply #7 on: September 25, 2012, 05:27:05 pm »
Ok, I've added include guards and made loop more eye-friendly.
Yeah I noticed, I was editing too. ;D

Anyways I've fixed the missing indentations and added the required includes, I hope I didn't miss any.

Btw for me it makes more sense to use *.hpp file endings, so it matches nicely with *.cpp and directly indicates the use of C++. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Nightly Builds: https://www.nightlybuilds.ch/
——————————————————————
Dev Blog: https://dev.my-gate.net/
Thor: http://www.bromeon.ch/libraries/thor/

FRex

  • Hero Member
  • *****
  • Posts: 1843
    • View Profile
    • My GitHub Page
    • Email
Re: Tiled map with arrays
« Reply #8 on: September 25, 2012, 06:19:03 pm »
Quote
Anyways I've fixed the missing indentations and added the required includes, I hope I didn't miss any.
I think loader doesn't need vertex array because a forward declaration would do.
Map header needs vertex array(it forwards loader so vertex array in loaders header doesn't help) but doesn't need target's include in header already, just forward there.

Oka:
I've fixed includes, I think they're ok now. Added render target to map cpp(because drawable just forwarded it), removed states and target from maps header since drawable is responsible for that inclusion and forward because its' function uses them. Kept array in loader header since then it relieves from including array in derieved loader cpp.
« Last Edit: September 26, 2012, 04:52:50 pm by FRex »
ZipSavings, script to count rar/7z/zip savings: https://goo.gl/vvBj5M
LuaConsole: https://goo.gl/X4kRUk
FoxRaycaster: https://goo.gl/27nVS8
Small Games - Heart, Routing and Snek: https://goo.gl/15ZGWE https://goo.gl/k5gwWD https://goo.gl/4nKPnT
Botes - a notes app in Pascal: https://goo.gl/bzTqsi

Roose Bolton of the Dreadfort

  • Full Member
  • ***
  • Posts: 113
  • Full-time Procrastinator, Part-time programmer.
    • View Profile
    • Personal Portfolio/Website/Blog
Re: Tiled map with arrays
« Reply #9 on: October 10, 2012, 11:35:44 am »
Wow, thanks for this tutorial! I am going to have a play around tonight.

So at the moment in the example it just fills a 100/100 area with the brick tiles - how hard would it be to implement/amend it so it can load and display tiles the txt document way, eg.

1011111
1011111
1000000
1111111

so 1 is grass, 0 is a road.

I'm gonna try tonight :D

thanks for the introduction to the subject.
Trying so very hard to finish at-least one project.

Watch out for the RAII police, they will get you.

www.bantersaurus-games.com

FRex

  • Hero Member
  • *****
  • Posts: 1843
    • View Profile
    • My GitHub Page
    • Email
Re: Tiled map with arrays
« Reply #10 on: October 10, 2012, 04:40:36 pm »
You have to inherit from tileloader and complete the two tasks that are stated in comments.
It should be easy but it's limited to one texture and no modifying because of way quads are stored.
ZipSavings, script to count rar/7z/zip savings: https://goo.gl/vvBj5M
LuaConsole: https://goo.gl/X4kRUk
FoxRaycaster: https://goo.gl/27nVS8
Small Games - Heart, Routing and Snek: https://goo.gl/15ZGWE https://goo.gl/k5gwWD https://goo.gl/4nKPnT
Botes - a notes app in Pascal: https://goo.gl/bzTqsi

 

anything