Pong on the web using barebones libraries. Making the game engine from scratch using WebGPU and Rust for efficiency.
Pong on the web using barebones libraries. Making the game engine from scratch using WebGPU and Rust for efficiency.
The game state is an object that controls the state of the game (e.g. the score, the objects in the game). Within it I added the paddles, the left paddle controls (the one the user controls) and the ball. I’ll implement a simple AI for the user to play against, although multiplayer implementation is planned.
The collision was really buggy and, when two objects would collide, the velocity in both of the axes would be inverted. I fixed this along with other minor bugs.
Implemented a constants file from which game constants (canvas width & height, default ball speed, etc.) can be customized.
Log in to leave a comment
I first tried implementing collisions in a cluttered fashion with math I honestly didn’t even understand. This caused a lot of useless headache, and the worst part about it is that I knew I had the answers to what I had to do in me the entire time.
I was racking my brain for how to implement this, and once I got fed up with my spaghetti solution, I checked Wikipedia for “elastic collisions” and there it was: the kinetic energy formula and the momentum formula I knew and loved from my physics class. I was too stubborn to pick up a piece of paper and actually write out what I wanted to do, and more importantly, the physics behind it.
It seems like I’ve learned something from this headache, though. When I’m stuck on a problem, maybe I should, you know, actually try to solve the problem instead of sitting and just thinking of a solution.
Anyways, I want to add colors and controllable paddles. Admittedly I’m scared of working on the WGSL and the fragment shaders, so I’ll probably work on the paddles first.
Log in to leave a comment
I began logging this project after I had already done some work, so here is what I’ve done so far (before this log):
For this devlog, I didn’t have much time, but what I did was:
All I have is some simple kinematics implementations (acceleration, velocity, etc) and I want to add momentum and collisions, so I added a mass property to game objects.
I want to do some research on Minkowski differences so I can efficiently calculate collisions and especially the side that they occur on. I’ll probably implement this tomorrow.
Log in to leave a comment