Pong, but Better banner

Pong, but Better

3 devlogs
6h 22m 35s

Pong on the web using barebones libraries. Making the game engine from scratch using WebGPU and Rust for efficiency.

Repository

Loading README...

gunnsdc

Game State & Fixes

Game State

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.

Fixes

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.

Organization

Implemented a constants file from which game constants (canvas width & height, default ball speed, etc.) can be customized.

Attachment
0
gunnsdc

Collisions

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.

Attachment
0
gunnsdc

I began logging this project after I had already done some work, so here is what I’ve done so far (before this log):

  • General project setup to allow me to use both Rust compiled into WASM and Typescript together
  • Make a frontend website with a cool moving background and some other elements with TailwindCSS and React
  • Make a simple game renderer using WebGPU that converts game objects into triangles and renders them onto the blue space you see in below

For this devlog, I didn’t have much time, but what I did was:

  • Quickly make a simple ReadMe for the project
  • Start making the framework for collisions and overall physics

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.

Attachment
0