Conversation
def100d to
2a9ea38
Compare
| /* And so on */ | ||
| ~~~ | ||
|
|
||
| Above, I make use of the [has selector](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Selectors/:has), which is relatively new; it allows you to select a parent element or a previous sibling element with respect to a reference element. In this case, it will select `:root` (`html`) when it has an `input[id^="1"]:checked`. `^=` is a begins with selector. |
There was a problem hiding this comment.
* is a 'begins with' selector may read better.
There was a problem hiding this comment.
is that not what I said?
There was a problem hiding this comment.
I mean in quotes would read better
| Demonstration of the hidden labels used for randomisation | ||
| </video> | ||
|
|
||
| The key thing to remember is that in the actual game, the shaded regions are completely grey. The css logic looks like.. |
|
|
||
| `--click-box-height` is the height of the label; this does mean that there is a precision limit based simply on how large the labels are. `--bird-frame-base-top` is just a base value for the position of the bird frame (bird and labels). `--active-number` is determined by the most recent label clicked; each value is just an integer indicating its position. `--bird-delta-y` is the animated variable from earlier. | ||
|
|
||
| The code above changes the nature of the animation, but we still need to reset the animation on each click. This is done by simply having two sets of inputs, which swap in and out on every click. Each set has a full collection for setting `--active-number`, they set a different identical animation. The changing of the animation resets it. |
There was a problem hiding this comment.
'Each set has a full collection for setting --active-number, they set a different identical animation.' It is unclear to me what this means.
| /* Duplicate */ | ||
| } | ||
|
|
||
| /* Ensure that the jump-holders (divs contains labels) swap in and out on every click */ |
There was a problem hiding this comment.
* divs containing labels?
|
|
||
| All the radio buttons have the same `name`, which means that only one can be selected at any one time. So when one from `#jump-label-holder-2` is selected, it deselects the one from `#jump-label-holder-1`. | ||
|
|
||
| If a user clicks down on a label, it is possible for that label to move out of the way, and another label takes its place, then no selection is detected. To deal with this, we can increase the height of the label when the user presses down by making use of the `:active` label. We can also use `:active` to animate the wings by simply swapping out the image. |
There was a problem hiding this comment.
Is 'clicks down' here distinct from just 'clicks?'
There was a problem hiding this comment.
trying to distinguish between down and up, a 'click' can be the full down and up motion?
|
|
||
| ### Collision Detection and game end | ||
|
|
||
| Pipes are great and all, but what's the point if they don't hurt the bird? Here is a simplified version of my collision detection, which is done independently by each pipe. |
| } | ||
| ~~~ | ||
|
|
||
| The calculation is split into an overlap in x and in y. The first bit of the x calculation determines if the bird's right side is past the pipe's left side; the first max returns a `0px` if not. Similarly, the second bit determines if the bird's left side is behind the pipe's right side; if both of these are true, the pipe and the bird overlap in the x dimension and the value of `--overlap-in-x` will be none-zero There is an equivalent calculation for y (that takes into account the gap between pipes). |
There was a problem hiding this comment.
* will be non-zero. (missing full stop). I also wonder whether here and throughout x and y should be within backticks?
There was a problem hiding this comment.
i've been doing it mainly for code legibility
| ~~~ | ||
|
|
||
| The calculation is split into an overlap in x and in y. The first bit of the x calculation determines if the bird's right side is past the pipe's left side; the first max returns a `0px` if not. Similarly, the second bit determines if the bird's left side is behind the pipe's right side; if both of these are true, the pipe and the bird overlap in the x dimension and the value of `--overlap-in-x` will be none-zero There is an equivalent calculation for y (that takes into account the gap between pipes). | ||
| The result of this calculation is that if there is an overlap of a pipe with the bird, `--collision` will be non-zero. Once we have this, we simply create a game-ending div which has a height of `200vh * var(--collision)`, forcing the user to hover on it. On hover, this div pauses all animations and remains on screen. |
There was a problem hiding this comment.
div - same thought about comment above regarding HTML tag names in text?
|
|
||
| I had to do a lot of debugging in this; the use of counters and [this trick](https://www.youtube.com/shorts/ii-lSK2_Nu4) helped. I imagine the former is unlikely to come up day to day, however, I look forward to using the second. | ||
|
|
||
| If a div changes its position or height as a result of a `transform` being animated, it will not cause the `:hover` state to be recalculated, as shown above. It works for properties directly, so our game-ending logic still works. Finally, dimensions are important in css, while making my collision detection formula, I has some issue and realised it's because I was assigning things like `1px*1px` to something wanting a length. |
| I've never heard of CSS being used for styling, but anything is possible, I guess. | ||
|
|
||
| #### Why is the bird square? | ||
| I have a square bird for ornithological accuracy and not because I think it made collision detection easier, and I was too lazy to get back to it. |
There was a problem hiding this comment.
I would remove 'I think', as well as the last clause: 'and I was too lazy to get back to it.'
Please add a direct link to your post here:
https://quarknerd.github.io/blog/2026/02/14/noJS-3-flappy-bird.html
Have you (please tick each box to show completion):
npm installfollowed bynpx mdspell "**/{FILE_NAME}.md" --en-gb -a -n -x -tif that's your thing)Posts are reviewed / approved by your Regional Tech Lead.