The concept of a console is important when writing games for modern game engines. In this article we will examine the concept in light of solving the blocking input problem in modern game engines and langauges like JavaScript. In JavaScript, for example, your code is placed on the UI thread. This means that whenever a […]
Collision of Spheres in Javascript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
function check_collisions() { // For every sprite, for (t = 0; t < sprites.length; t++) { var s1 = sprites[t]; // 1st sprite // Check every other sprite, for (k = 0; k < sprites.length; k++) { var s2 = sprites[k]; // 2nd sprite // only compare against sprites “above” // see diagram on whiteboard to explain why if (s1.id < s2.id) { // If both are “alive”, if (s1.alive == true && s2.alive == true) { // check collision physics. collision_physics(s1,s2); } // if alive } // if touching (collision) } // for all sprites } // for all sprites } function collision_physics(s1,s2) { // Step 1. Get the distance between objects. var dx = s2.x - s1.x; //distance between x var dy = s2.y - s1.y; // distance between y var distance = Math.sqrt(dx * dx + dy * dy); // Step 2. Define the minimum distance // (see whiteboard for diagram var minDistance = s1.r + s2.r; // Step 3. if the distance is touching (i.e. collision), if (distance < minDistance) { // Step 4. Calculate the angle of collision. var angle = Math.atan2(dy, dx); var spread = minDistance - distance; var ax = spread * Math.cos(angle); var ay = spread * Math.sin(angle); // Step 5. Solve collision (separation) angles s1.x -= ax/2; s1.y -= ay/2; s2.x += ax/2; s2.y += ay/2; // Step 6. Give each ball it’s share of the rebound angle; // change the ball’s dx and dy so they fly apart logically. s1.dx -= Math.cos(angle)*FPS; s1.dy -= Math.sin(angle)*FPS; s2.dx += Math.cos(angle)*FPS; s2.dy += Math.sin(angle)*FPS; } } |
CALL and RET considered harmful.
The title of this post is a fun little jab at famous articles like “GOTO considered harmful“. A few years later Knuth’s “Structured Programming with go to Statements” provided a credible counterpoint. Knuth is famously quoted as saying we each develop “strong feelings” over these things because we are witnessing a revolution. So the takeaway […]
Lava Game
There’s a new game in the menu called “The Colosseum of Lava“. Here is an introduction to the game, in Neo’s own words: How I got the idea A few years ago, I made a game on Scratch called “The Walls are Poison.” I decided to try and remake that game, called “The Colosseum of […]
Is Object Oriented Programming worth it in 2023?
What is OOP, really, and what has it done to our code? In retrospect, is OOP a good thing? Is it all good? A little bit bad maybe? What are the true pros and cons? How did OOP play out over the last few decades? Adventure awaits! Huzzah! One. Object Oriented. The language is object […]
Neo’s World 0.1.1
(Note: You can download the latest version on itch.io, when it is available.) Changes – Neo’s World v0.1.1 * Converted the NPC pathfinding from static to dynamic. (Before, NPCs would snap to a specific level based on where they are. Now they fall and are supported by the land.) * Decreased the spell range, because […]
Neo’s World
Time has passed. I’ve been keeping busy teaching coding to kids, which will be the subject of a new section and post series “programming for kids”. It’s going to be a streamlined version of how I taught Neo to code, refined and tested. Neo has also been keeping busy. He’s 15 now and no longer […]
Theme of the Month: RetroGeek
Let’s start off by trying the RetroGeek (by tuxlog) theme, at least until the end of August. It has an obvious sort of instant appeal for a blog like this. At the end of the month I’ll probably post a short review. If you’d like to install it yourself, you can just search for ‘RetroGeek’ […]
Logic Gates: The Blocker
How do computers work? Imagine a wire. When electricity enters one part of the wire, the other end has electricity. This means you have a wire, and if you put a ‘1’ in, you get a ‘1’ out. If you put a ‘0’ in, you get a ‘0’ out. Zero means the electricity is off, […]
Hello world!
Welcome to WordPress. This is your first post. Edit or delete it, then start writing!