<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: api TON</title>
    <description>The latest articles on DEV Community by api TON (@api_ton_5a09e89ff79d2435b).</description>
    <link>https://dev.to/api_ton_5a09e89ff79d2435b</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4281421%2Fe20a36b1-da05-4308-9d95-ab8eedcd481e.png</url>
      <title>DEV Community: api TON</title>
      <link>https://dev.to/api_ton_5a09e89ff79d2435b</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/api_ton_5a09e89ff79d2435b"/>
    <language>en</language>
    <item>
      <title>How I built isLiberty: watching YouTube and live TV with friends, perfectly in sync</title>
      <dc:creator>api TON</dc:creator>
      <pubDate>Fri, 04 Dec 2026 01:49:45 +0000</pubDate>
      <link>https://dev.to/api_ton_5a09e89ff79d2435b/how-i-built-isliberty-watching-youtube-and-live-tv-with-friends-perfectly-in-sync-203h</link>
      <guid>https://dev.to/api_ton_5a09e89ff79d2435b/how-i-built-isliberty-watching-youtube-and-live-tv-with-friends-perfectly-in-sync-203h</guid>
      <description>&lt;p&gt;I'm the developer of &lt;a href="https://isliberty.org" rel="noopener noreferrer"&gt;isLiberty&lt;/a&gt;, a free watch-together site. You create a room, send the link, and everyone sees the same moment: pause, seek and source changes happen for everyone at once, with a chat next to the player. You can play YouTube, VK Video and Rutube links, or one of hundreds of live TV channels and radio stations sorted by country. No sign-up, just a nickname.&lt;/p&gt;

&lt;p&gt;Here's how the sync works under the hood, because that was the interesting part.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why
&lt;/h2&gt;

&lt;p&gt;My friends and I live in different cities. Screen sharing in Discord kills quality and sound, and if one person has a slow connection, everyone suffers. "Three, two, one, press play" works for five minutes until someone pauses. The existing tools either didn't support the sources we use or wanted an account and a browser extension.&lt;/p&gt;

&lt;h2&gt;
  
  
  Architecture in one paragraph
&lt;/h2&gt;

&lt;p&gt;Go backend, PostgreSQL, clients talk to the server over WebSocket. Each browser plays the video itself, straight from the source, so everyone gets their own quality. The server never touches video, it only sends the player state.&lt;/p&gt;

&lt;h2&gt;
  
  
  One state per room
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;PlaybackState&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;version&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// bumps with every command&lt;/span&gt;
  &lt;span class="n"&gt;source&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Source&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;paused&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;boolean&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;// seconds at updatedAt&lt;/span&gt;
  &lt;span class="n"&gt;updatedAt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// ms, server clock&lt;/span&gt;
  &lt;span class="n"&gt;rate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When someone pauses or seeks, the client sends a command (&lt;code&gt;player.pause {position}&lt;/code&gt;). The server checks permissions, bumps &lt;code&gt;version&lt;/code&gt;, stamps &lt;code&gt;updatedAt&lt;/code&gt; with its own clock and broadcasts the new &lt;code&gt;state&lt;/code&gt;. Clients only apply a version newer than the one they have, so a late message never rolls the player back.&lt;/p&gt;

&lt;h2&gt;
  
  
  Don't trust client clocks
&lt;/h2&gt;

&lt;p&gt;The easy mistake is computing the position from the browser's &lt;code&gt;Date.now()&lt;/code&gt;. People's clocks drift by seconds. So all times are server times, and each client estimates its offset with ping/pong:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="n"&gt;offset&lt;/span&gt; ≈ &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;t0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;t2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;   &lt;span class="c1"&gt;// t0, t2 client; t1 server&lt;/span&gt;
&lt;span class="n"&gt;serverNow&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;offset&lt;/span&gt;
&lt;span class="n"&gt;expected&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;paused&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="n"&gt;position&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;position&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;serverNow&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;updatedAt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;rate&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every few seconds the client compares its player position with &lt;code&gt;expected&lt;/code&gt;. Small drift is corrected by nudging playback speed, large drift by a jump.&lt;/p&gt;

&lt;h2&gt;
  
  
  Laggards and the queue
&lt;/h2&gt;

&lt;p&gt;Every client reports &lt;code&gt;player.status&lt;/code&gt; (position and buffering) every 5 seconds. A room can turn on "wait for laggards": if someone is buffering, the server pauses everyone and resumes when they've caught up.&lt;/p&gt;

&lt;p&gt;There's a shared queue. When a video ends, every client sends &lt;code&gt;player.ended&lt;/code&gt; with the state version; the server counts only the first report and starts the next item. That way the switch happens even if someone's tab is in the background with throttled timers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Different players
&lt;/h2&gt;

&lt;p&gt;YouTube, VK Video and Rutube are embedded via iframes with their own JS APIs, each with quirks: some report position only about once a second, some seek asynchronously. TV channels and radio are HLS streams with no seeking: everyone just watches the live broadcast.&lt;/p&gt;

&lt;h2&gt;
  
  
  The TV and radio catalog
&lt;/h2&gt;

&lt;p&gt;The catalog is built from open playlists. A worker checks streams periodically and drops dead ones, and users can report a channel that doesn't play. The home page starts a random channel from the viewer's country.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's next
&lt;/h2&gt;

&lt;p&gt;It's a solo project, so feedback is very welcome: what breaks, which sources are missing, what's awkward on mobile. Try it at &lt;a href="https://isliberty.org" rel="noopener noreferrer"&gt;isliberty.org&lt;/a&gt;, no sign-up needed.&lt;/p&gt;

</description>
      <category>showdev</category>
      <category>go</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How the bot in my browser Worms-like picks a shot: fork the match, score, repeat</title>
      <dc:creator>api TON</dc:creator>
      <pubDate>Fri, 04 Dec 2026 01:19:25 +0000</pubDate>
      <link>https://dev.to/api_ton_5a09e89ff79d2435b/how-the-bot-in-my-browser-worms-like-picks-a-shot-fork-the-match-score-repeat-42n3</link>
      <guid>https://dev.to/api_ton_5a09e89ff79d2435b/how-the-bot-in-my-browser-worms-like-picks-a-shot-fork-the-match-score-repeat-42n3</guid>
      <description>&lt;p&gt;&lt;em&gt;Disclosure: I'm the developer of &lt;a href="https://bearwars.org/" rel="noopener noreferrer"&gt;Bear Wars&lt;/a&gt;, the game this post is about.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmccf551hl5wg8gtiwvnn.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmccf551hl5wg8gtiwvnn.jpg" alt="Bear Wars: aiming against the computer" width="640" height="360"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Bear Wars is a turn-based artillery game in the spirit of Worms and Hedgewars that runs in the browser. You can play it against the computer at three difficulty levels. The bot doesn't solve ballistics equations. It does something simpler: it tries shots on copies of the match and keeps the best one.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Deterministic core = free "what if"
&lt;/h2&gt;

&lt;p&gt;The game simulation is deterministic: the same state and the same inputs always give the same result. So a copy of the match, stepped with the same inputs, ends exactly like the real match would. The bot plans a turn by forking the current state many times and asking "what happens if I fire like this?"&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Make the copies cheap
&lt;/h2&gt;

&lt;p&gt;A copy has to be fast to create. The terrain is a solidity mask stored in 64x64 tiles with copy-on-write, so a copy shares all pixels with the original and only duplicates the tiles an explosion actually carves.&lt;/p&gt;

&lt;p&gt;For screening there is an even cheaper copy: a "ghost" terrain where explosions don't carve at all. The bot scans a coarse grid of aim angles, power and fuse times on ghost copies, keeps the best candidates, tries their neighbours, and checks only the finalists on exact copies.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Score the outcome, not the shot
&lt;/h2&gt;

&lt;p&gt;Each trial is scored by what happened: damage to enemies, kills, bears drowned in the water, where the enemy ends up (in a pit, near an edge), minus any harm to its own team. Weapons other than the bazooka and grenade get their own candidate generators: walking up to an enemy and boring under it with the drill, flights for the helicopter, and so on.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. The plan is a list of key presses
&lt;/h2&gt;

&lt;p&gt;The result of planning is a plain list of inputs, one per tick: the same keys a human would press. The turn then plays out on screen like a player's turn, with a short "thinking" pause before the first key. Nothing special happens in the simulation because the opponent is a bot.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Budget in trials, not milliseconds
&lt;/h2&gt;

&lt;p&gt;The search budget is counted in trial runs, not in time. With a time budget, a slow phone would play worse than a desktop and the same position could give different moves. With a trial budget, the same state and seed always give the same plan, which keeps replays and tests reproducible.&lt;/p&gt;

&lt;p&gt;Planning runs in a Web Worker, so the main thread keeps rendering while the bot thinks.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Difficulty is a set of handicaps
&lt;/h2&gt;

&lt;p&gt;The three levels use the same planner with different settings:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Easy&lt;/strong&gt; ignores the wind, adds aim error (about 6 degrees) and power error, sometimes picks a careless move from the better half, uses fewer weapons, and gets about 900 trials.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Medium&lt;/strong&gt; plans with half the wind, aims with about 2.5 degrees of error, also tries walking before the shot, and gets about 2,600 trials.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hard&lt;/strong&gt; uses the full wind, makes no execution error, tries more positions and weapons, and gets about 6,000 trials.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Tuning a level means changing numbers, not writing a new bot.&lt;/p&gt;




&lt;p&gt;Bear Wars is free at &lt;a href="https://bearwars.org/" rel="noopener noreferrer"&gt;bearwars.org&lt;/a&gt;. Try the hard bot and tell me in the comments how fast it beat you.&lt;/p&gt;

</description>
      <category>gamedev</category>
      <category>javascript</category>
      <category>ai</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Netcode for a browser Worms-like: seed, inputs and one player pacing the turn</title>
      <dc:creator>api TON</dc:creator>
      <pubDate>Fri, 04 Dec 2026 01:17:24 +0000</pubDate>
      <link>https://dev.to/api_ton_5a09e89ff79d2435b/netcode-for-a-browser-worms-like-seed-inputs-and-one-player-pacing-the-turn-2c0</link>
      <guid>https://dev.to/api_ton_5a09e89ff79d2435b/netcode-for-a-browser-worms-like-seed-inputs-and-one-player-pacing-the-turn-2c0</guid>
      <description>&lt;p&gt;&lt;em&gt;Disclosure: I'm the developer of &lt;a href="https://bearwars.org/" rel="noopener noreferrer"&gt;Bear Wars&lt;/a&gt;, the game this post is about.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmccf551hl5wg8gtiwvnn.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmccf551hl5wg8gtiwvnn.jpg" alt="Bear Wars: a 1v1 match in the browser" width="640" height="360"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Bear Wars is a turn-based artillery game in the spirit of Worms and Hedgewars that runs in a browser tab. One of the modes is online 1v1: you create a room, send a friend a 4-character code, and you play. Here is how that part is built, without sending the whole game state over the wire.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. A match is a seed plus inputs
&lt;/h2&gt;

&lt;p&gt;The simulation runs at 60 ticks per second and is fully deterministic. The server picks a random seed when the match starts, and after that the only thing that travels between players is input: move, aim, fire, jump, weapon choice, target point. Two machines that start from the same seed and apply the same inputs tick by tick end up in exactly the same state.&lt;/p&gt;

&lt;p&gt;That makes the network traffic tiny, and it gives you replays and tests almost for free.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Don't trust &lt;code&gt;Math.sin&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Determinism breaks in boring places. JavaScript only guarantees correct rounding for &lt;code&gt;+ - * /&lt;/code&gt; and &lt;code&gt;Math.sqrt&lt;/code&gt;. &lt;code&gt;Math.sin&lt;/code&gt; and &lt;code&gt;Math.cos&lt;/code&gt; can differ in the last bits between engines, and in a physics simulation those bits grow into a shot that lands somewhere else.&lt;/p&gt;

&lt;p&gt;So the core has its own &lt;code&gt;fsin&lt;/code&gt;/&lt;code&gt;fcos&lt;/code&gt;: range reduction to [-pi/2, pi/2] and a Taylor polynomial up to x^13 (error below 1e-9), built only from operations that are bit-identical everywhere.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. One player "paces" the turn
&lt;/h2&gt;

&lt;p&gt;It's a turn-based game, so at any moment one player is acting. That player's client is the pacer: it runs the simulation locally with no input lag and sends its frames to the server. The server keeps its own authoritative copy of the match:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;it checks the order of incoming frames;&lt;/li&gt;
&lt;li&gt;it holds back frames that run more than 15 ticks (a quarter second) ahead of its clock;&lt;/li&gt;
&lt;li&gt;it applies them to its copy and forwards them to the other player, who replays them.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If the pacer falls more than 30 ticks behind (lost connection, a hidden tab), the server writes the frames itself ("fill" mode) and tells the pacer to resync from a snapshot. Surrender and forfeit go in the same way, as system actions in the frame stream.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Check the hash, fix with a snapshot
&lt;/h2&gt;

&lt;p&gt;Every 60 ticks the state is hashed and compared. If a client disagrees, it asks for a snapshot and continues from there. The same path handles reconnects: a player who drops has 60 seconds to come back, gets a snapshot and catches up.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Small frames on the wire
&lt;/h2&gt;

&lt;p&gt;Frames are sent in batches. Most ticks repeat the same held keys, so a batch is run-length encoded: a number means "k more frames with the same held state", an object means one frame that changes something. Each batch starts from a zero held state, so a lost or repeated batch can't corrupt the next one.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Room codes people can read out loud
&lt;/h2&gt;

&lt;p&gt;Room codes are 4 characters from a 23-character alphabet with the look-alikes removed: no 0/O, 1/I/L, 2/Z, 5/S, 8/B or U/V. The parser also accepts a whole pasted link with &lt;code&gt;?room=...&lt;/code&gt;, so "send the link" and "say the code" both work.&lt;/p&gt;

&lt;p&gt;The server side is a Colyseus room per pair of players, with lobby, rematches and reconnects. The pacing logic itself lives in a plain class with an injectable clock, so it can be tested without a network.&lt;/p&gt;




&lt;p&gt;If you want to see it in action, Bear Wars is free and runs at &lt;a href="https://bearwars.org/" rel="noopener noreferrer"&gt;bearwars.org&lt;/a&gt;: play the computer, pass one device around, or send a friend a room code. Questions about the netcode are welcome in the comments.&lt;/p&gt;

</description>
      <category>gamedev</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>5 things I learned making a Worms-like that runs in a browser tab</title>
      <dc:creator>api TON</dc:creator>
      <pubDate>Thu, 03 Dec 2026 21:52:19 +0000</pubDate>
      <link>https://dev.to/api_ton_5a09e89ff79d2435b/5-things-i-learned-making-a-worms-like-that-runs-in-a-browser-tab-3kll</link>
      <guid>https://dev.to/api_ton_5a09e89ff79d2435b/5-things-i-learned-making-a-worms-like-that-runs-in-a-browser-tab-3kll</guid>
      <description>&lt;p&gt;&lt;em&gt;Disclosure: I'm the developer of &lt;a href="https://bearwars.org/" rel="noopener noreferrer"&gt;Bear Wars&lt;/a&gt;, the game this post is about.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Bear Wars is a turn-based artillery game in the spirit of Worms and Hedgewars. Two teams of bears take turns on destructible maps, the wind bends every shot, and it runs in the browser with nothing to install. You can play the computer (3 difficulty levels), pass one device around, or send a friend a room code for a 1v1 match. A phone in landscape can play against a PC.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmccf551hl5wg8gtiwvnn.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmccf551hl5wg8gtiwvnn.jpg" alt="Bear Wars: two bear teams on the Apiary map, mid-match" width="640" height="360"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here are the five ideas that carried most of the weight.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Terrain is a bitmask, not geometry
&lt;/h2&gt;

&lt;p&gt;The map is a grid where &lt;code&gt;1&lt;/code&gt; means solid. The art is drawn on top; physics only reads the mask. An explosion is &lt;code&gt;carveCircle(x, y, r)&lt;/code&gt;. That single primitive gives you craters, tunnels and caves.&lt;/p&gt;

&lt;p&gt;We store the mask as 64x64 tiles with copy-on-write, so a carve only copies the tiles it overlaps instead of the whole map.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Sweep the projectile, don't teleport it
&lt;/h2&gt;

&lt;p&gt;A fast shell can travel further in one tick than a thin wall is thick. Testing only the end point makes shots pass through hills. Walk the segment from the previous position to the new one and stop at the first solid cell.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Fixed timestep
&lt;/h2&gt;

&lt;p&gt;Run the simulation at a fixed tick, independent of frame rate. A shot then lands in the same place on a slow phone and a fast desktop.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Walking is step rules plus normals
&lt;/h2&gt;

&lt;p&gt;Small bumps should be climbable, walls should not. In Bear Wars a bear steps up at most 6 px and down at most 8 px; anything taller needs a jump or the rope. A surface normal (&lt;code&gt;normalAt&lt;/code&gt;) tells you which way a slope faces.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. The bot shoots with the real physics
&lt;/h2&gt;

&lt;p&gt;The computer opponent tries many angle and power combinations, simulates each with the same simulation code the game uses, and picks the best. No second "AI physics" to keep in sync.&lt;/p&gt;

&lt;h2&gt;
  
  
  The fun part: weapons
&lt;/h2&gt;

&lt;p&gt;12 of them, including a rope, timed grenades (1-5 s), teleport, an air strike, a helicopter, a drill that tunnels along your aim, a point-blank bogatyr sword, and the Tsar Cone: it barely bounces, sits for a few seconds and explodes twice as hard as a grenade. The bears talk, in 8 languages.&lt;/p&gt;

&lt;p&gt;If you're building something in this genre, I'm happy to answer questions in the comments. And if you want to try it: &lt;a href="https://bearwars.org/" rel="noopener noreferrer"&gt;https://bearwars.org/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>gamedev</category>
      <category>javascript</category>
      <category>showdev</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
