106 comments

[ 3.2 ms ] story [ 192 ms ] thread
Hi everyone. I've made a isometric tile map a while ago - http://jsfiddle.net/victorqribeiro/k3bazwnj/ - but yesterday I found this really cool tile set - free to use - so I decided to make a tiny city builder. Hope you like it.
Would you mind adding support for touch devices?
what device you're on? cause it works on my phone
Dont drag. Touch the piece and the touch the spot to drop it on.
You can make some really nice looking games using isometric tiles, Ceasar 3 comes to mind. Which looks much better then Ceasar 4 IMHO, which is 3d AFAIK. And game-play also feels better in C3.
Caesar 3 was a fantastic game.

Also: plebs are needed.

Same with Age of Empires 2 vs 4. Also Brigador for example of a recent game which makes excellent use of isometric visuals.
I still play Transport Tycoon fairly often. The open version at https://www.openttd.org/ is my goto.

I've tried a lot of the newer city builders and the 3D just does not do it for me. I find it clunky and awkward.

I played the f--- out of Ceasar 2 as a kid. That game was so good.
i like it. Having to scroll through long vertical list of tiles to find the one you want is kind-of a pain though. Other than that, nifty. :)
that was the easiest most intuitive way I found to display the tiles. it's not great though
Nothing wrong with a scrolling layout, it's just a bit overrestricted: https://i.imgur.com/76BML6a.png

Filling some of the whitespace with scrollable grid of pieces would go a long way towards decreasing time for piece selection.

A 2D array might be easier to scroll through.

Also, I suggest highlighting the currently selected piece.

Came here to make both of these suggestions!
Perhaps make the list horizontal because of the highrises wasting space on the vertical list?
My wife saw this on screen and said “Oh, is that a kitchen planner?”

Hmm, MIT license, this could be a kitchen planner for her :)

I'm planning on doing this in webgl. Then she would be able to fully navigate her virtual kitchen. =)
If you make this I'd love to help out
To anyone interested in the webgl version, it would work something like this - https://victorribeiro.com/voxel/ - click to place a bloc, click and drag on the sides of the screen to rotate the view, keys 1 to 9 change the block.
Nice, simple, and fun!

I also appreciate that you're very open to contributions! :)

Small suggestion for UI improvement: while hovering over a tile, and pressing (say) the R key, you could rotate the tile by 90 degrees.
This generally doesn’t work for isometric tiles because flipping the tile on the y axis (what you’re suggesting by rotate 90) does not preserve the lighting being on the correct side, so the flipped tile looks wrong. In most cases you would need a whole new tile for the rotated piece.
Yes, I meant a newly rendered tile. Or just the corresponding rotated tile from the library if it exists.
You could use two bits in each pixel to indicate horizontal, left or right, and post-process light/dark depending on orientation. (Assuming only those faces and senses... though this project also has sloping roofs).

Or, couldn't you pretend the city rotated but the sun didn't (like a model under a lamp), so lighting is the same for all orientations?

I spent a good 20min building little towns. Nice post.
that's what I like to hear
Kind of related - When I was learning webdev I built something similar (to the end result) from scratch using css animations.

https://jaygles.github.io/city-block/

Garbage newbie code for it here - https://github.com/Jaygles/city-block

Seems like some recent browser updates sort of broke the main animation but if you really want to see something fun open it in IE.

This is great! Did you generate this, or did you do it by hand?
I did it by hand as an exercise to learn css grid and css animations
Nice work!
It would be nice to be able to choose the orientation of the block independently of the type of block
This takes me back.

One of the last projects I did in college was a terrain generator.

After, I was learning a new programming language, so I picked it up again to experiment with some world building.

I started trying to generate more realistic (and traverseable) terrain. I had worked out coastlines and rivers, made some headway on biomes, and gotten stuck on simulated erosion before I remembered that I like games a little too much and didn’t want to make them for a living.

I was pretty bummed when No Man’s Sky was panned. Using generated terrain as a canvas and dropping a story into it still feels like the right long-term solution for exploration games.

Really cool project! Small suggestion, some indication of which type of tile is currently selected might be nice (like maybe highlight it or something).
I agree, really cool, also have a small suggestion -- it'd be nice if you could click and drag to "draw" tiles into the main board. Currently you can only click tile-by-tile.
Very neat. Do you want people to contribute to this project? I just made a pull request that allows right click to clear tiles.
I have answered you. if you remove click event it would stop working on touch devices, cause touch also trigger click, but not mousedown.
I can't upload the live version for now, cause I'm on a family event. I'll enable the GitHub version so everyone making pull requests can see the changes live
It would be great if this stored the city as data in the URL so we could share them.
open an issue as suggestion, if no one does it, I'll do it later. I'm on a party now
Fantastic. Like a mini sim city. Probably works better than the original PS version.
everyone wanting to contribute:

I thought about adding a print screen button

a save button that keeps the map on a localStorage would also be great

of course that would need a UI
This is a super fun app and I'm also very impressed by the elegant simplicity and readable code of this project! The tools you provided are perfect -- they offer just enough options to open up fun original creations while providing practical limitations to stay productive.

PS. Love your github tagline "I'm a Brazilian times better than your average coder." :)

thanks, I was afraid my tagline would make me look arrogant. glad you liked it.
(comment deleted)
"Brazilian" is of an undefined value, so it's fine.
Oh cool! I made something similar for my website gallery[1], it was an easter egg that you could play with if you pulled the pull-cord at the bottom of the page. In the middle of the page. Scrolling is a bit broken it seems now, though, so you have to find it yourself. (I really need to revisit it, I know so much more now.)

[1] http://ddr0.github.io/gallery

Thought this was a clever trick:

const $ = _ => document.querySelector(_)

Pretty well sums up the state of jQuery in 2019 (almost 2020!)

What does this trick do?
Written in older JS, it would look like this:

$ = function(_) { return document.querySelector(_) }

It basically turns `$` into an alias for `document.querySelector`. I'm not sure that it's any different from:

$ = document.querySelector

Sadly it is different because of the magic of this. If you set something equal to document.querySelector and then call it this will no longer refer to document. There are fancier ways with Function.prototype.bind, but wrapping in a function is the easiest conceptually.

https://www.taniarascia.com/this-bind-call-apply-javascript/

For this specific case, you can see this at https://stackoverflow.com/q/13383886/8334056

For posterity:

  $ = document.querySelector.bind(document);
Just checked on CanIUse, querySelector() actually has full support* since 2009!

Btw, querySelectorAll() to match multiple elements.

* IE partial until 2011

This is written by someone who has never used jquery or forgot it. The beauty of jquery was not being able to use CSS selectors to find elements, but in being able to work with multiple selected elements as if it was a single one.

Ok, you will say, but you can always do

[... document.querySelectorAll('.foo .bar')].map(it => it.style.backgroundColor = 'corn');

instead of $('.foo .bar').css('backgroundColor', 'corn');

and it is clearly better because it does not use jQuery.

Don't get me wrong, jQuery has many issues that make it a very poor choice for big modern web applications, but please don't tell me that it can be replaced by querySelectorAll.

Na, the beauty of jQ was writing JS once and being confident most of it would work in most browsers. Everything else was sugar.
> please don't tell me that [jQuery] can be replaced by querySelectorAll.

I didn't, and it can't -- my comment was merely to suggest that jQuery is now a shell of its old self, thanks largely to the improvement of browser DOM APIs.

for (const node of document.querySelectorAll('.foo .bar')) { node.backgroundColor = 'corn' }
Not sure why someone would use map like that (which would unnecessarily generate and return a new array of 'corn's) instead of just forEach.

I'd also probably recommend using Array.from instead of a spread (for clarity) but less concerned about that part.

Hmm. Usually underscore as a function parameter should mean unused variable. Ok maybe I am too much of a fusspot.
Super cool! Anyone recognize what this makes?

  map=Array(7).fill(Array(7).fill(3)).map((a,i)=>a.map((x,n)=>[0,i>3&&n<3?1:3]));drawMap()
That creates a pre-filled two dimensional array as a one-liner.
This is beautiful. I think that the success of games like Transport Tycoon is in large part down to an undefined satisfaction that comes from the graphic style.
(comment deleted)
You need to make the scrollable sidebar on the left much more compact, it's not very usable currently