danboid / ikd Goto Github PK
View Code? Open in Web Editor NEWAtari Combat remake for the Uzebox open source console
Atari Combat remake for the Uzebox open source console
I have been wondering exactly how I would implement 'proper' bouncy bullets (not the ping-pong cop-out currently in place) for some time. I thought I'd ask ChatGPT today and it sounds like it has devised a workable solution. I never thought when I started this project that at least one of its features would get devised by an AI! Amazing times.
My question to ChatGPT was:
How might I improve processBullets() so that the bullets will deflect off multiple surfaces and not just ping-pong between 2 walls?
It's reply:
To make the bullets deflect off multiple surfaces, you will need to update the processBullets() function to check for collisions with all walls in the level, not just the two adjacent walls.
One way to do this would be to use a 2D array to represent the level layout, with each element in the array representing a tile on the screen. You can then use the bullet's position and velocity to determine which tiles it will pass through during each frame. For each tile that the bullet will pass through, you can check if that tile is a wall or not, and if it is, you can calculate the new velocity for the bullet based on the angle of the wall and the direction the bullet was coming from.
Here is some pseudocode that demonstrates this approach:
void processBullets() {
for each bullet {
int startX = bullet.x / 8; // convert from pixels to tile units
int startY = bullet.y / 8;
int endX = (bullet.x + bullet.vX) / 8;
int endY = (bullet.y + bullet.vY) / 8;
// Check if the bullet is moving horizontally or vertically
if (startX == endX) {
// Bullet is moving vertically
int direction = (bullet.vY > 0) ? 1 : -1;
for (int y = startY; y != endY; y += direction) {
if (level[y][startX] == WALL) {
// Collision with vertical wall, reverse Y velocity
bullet.vY = -bullet.vY;
break;
}
}
} else {
// Bullet is moving horizontally
int direction = (bullet.vX > 0) ? 1 : -1;
for (int x = startX; x != endX; x += direction) {
if (level[startY][x] == WALL) {
// Collision with horizontal wall, reverse X velocity
bullet.vX = -bullet.vX;
break;
}
}
}
// Update bullet position based on new velocity
bullet.x += bullet.vX;
bullet.y += bullet.vY;
}
}
This approach will allow the bullets to deflect off multiple walls and surfaces in the level.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.