jsolly / geoasteroids Goto Github PK
View Code? Open in Web Editor NEWHome Page: https://www.geoasteroids.com
License: Apache License 2.0
Home Page: https://www.geoasteroids.com
License: Apache License 2.0
Currently, the way the music tempo is calculated doesn't really make sense as the player no longer destroys all the asteroids to go to the next level.
Each new level should slightly increase the music tempo
We use setInterval to drive animations in main.js
// Set up game loop
setInterval(update, 1000 / FPS)
Although this is an easy way to do it, it does not result in the cleanest animations. See this SO answer for more info.
I looked into the following resources, but I wasn't able to get a firm understanding of the best way to do it for GeoAsteroids
https://blog.webdevsimplified.com/2021-12/request-animation-frame/
https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame
https://dev.to/moyedx3/10-settimeout-setinterval-and-requestanimationframe-1io4
https://dev.to/suprabhasupi/requestanimationframe-in-javascript-n12
I tried
// Set up game loop
window.requestAnimationFrame(update)
and it results in nothing animating. I think we need to do more than a one-liner.
Users should be able to see the global top 10 scores when the game ends
Only showing current user's top score via local storage
Store in a flat file or database?
Any issues with concurrency if using a flat file?
Will need to provide a way to add three-letter username to associate with score
Will need placeholders for the top 10 scores to start
File size
Quality
Length
Tool (Audacity?)
Format (mp4?)
There's a small delay when showing highscores. This feels odd cause the user is just staying at a blank modal until it populates.
This is partly due to /highscores being tied to a serverless function that needs to pull records from MongoDB
Use a cool spinner/loader until the DOM is ready to be updated with highscores
If a user blocks all cookies, I believe this also stops any application from modifying local storage.
We currently read/write from local storage to get a user's high score and current score.
If the user has blocked all cookies, we should stop reading/writing to localstorage and treat each 'session' as brand new.
How to keep track of high score if we can't access local storage?
Music/Sound preferences are lost any time the page is refreshed. The default is off for both. See the constants SOUND_ON and MUSIC_ON.
If the user toggles the volume on/off, save that in a cookie/local storage so it is respected when the user returns (if they haven't cleared their cache).
Not sure who would want to play on their phone, but something to think about.
At some point, we lost 'leveling up' after the user has exceeded NEXT_LEVEL_SCORE, which should activate text on the screen that says
level X
where X is the new level reached
1 - Start shooting asteroids until you exceed NEXT_LEVEL_SCORE (I think it's 1000 right now)
Nothing happens
The text 'Level 2" should be shown on screen for TEXT_FADE_TIME seconds
Dev and Prod
Currently, there is no logging = (
Just using console.log for debug purposes.
Use something like:
Winston: A versatile logging library that allows for custom log levels, transports (where your logs are sent), and even multiple simultaneous loggers. Transports include console output, file output, and more.
Bunyan: Another versatile logging library. One of Bunyan's notable features is its support for "structured logging", a logging approach where logs are written in a machine-readable format (usually JSON). This can be very useful for searching and analyzing your logs.
Morgan: A HTTP request logger middleware for Node.js. It simplifies the process of logging requests to your application. It's very useful in combination with other loggers like Winston and Bunyan, especially when you're building a web server or application.
Which functions should be logging information? How will we handle different logging levels (INFO, DEBUG, ERROR)
1 - Shoot a laser...wait a long time.
Laser is not removed from canvas
2 - Keep firing lasers.
After 10 shots, the lasers stop firing because we have reached LASER_MAX (10)
Line 78 in lasers.mjs was changed to
ship.lasers[i].distTraveled += .5;//Math.sqrt(Math.pow(ship.lasers[i].xv, 2) + Math.pow(ship.lasers[i].yv, 2));
with the original distTraveled commented out. This is causing disTraveled to be much smaller than expected, so it takes a lot longer for it to be removed from the canvas
Lines 57-62 are the logic for removing lasers from the canvas.
for (var i = ship.lasers.length - 1; i >= 0; i--) {
// check laser distance
if (ship.lasers[i].distTraveled > LASER_DIST * canv.width) {
ship.lasers.splice(i, 1);
continue;
1 - We can increase LASER_MAX to be much larger
AND/OR
2 - We can re-think how laser distance is calculated and what distance a laser should travel before it is removed.
When you press two keys at the same time, or in quick succession, the second key press can interrupt the first one.
1 - You press ArrowLeft, so the ship starts turning left
2 - While still holding ArrowLeft, you press ArrowRight, so the ship starts turning right.
3 - You release ArrowRight. The keyUp event handler is triggered and ship.rot is set to 0.
4 - Now, even though ArrowLeft is still being pressed, the ship stops rotating because ship.rot is 0.
Ship starts turning left after step (4) of the steps to reproduce.
This commit changed how the ship is drawn. I believe this caused a side effect where the thruster is no longer centered behind the ship.
Basically, the code went from this
function drawShip(x, y, a, color = "white") {
let ctx = getCTX();
ctx.strokeStyle = color;
ctx.lineWidth = SHIP_SIZE / 20;
ctx.beginPath();
ctx.moveTo( // nose of ship
x + 4 / 3 * ship.r * Math.cos(a),
y - 4 / 3 * ship.r * Math.sin(a)
);
ctx.lineTo( // rear left
x - ship.r * (2 / 3 * Math.cos(a) + Math.sin(a)),
y + ship.r * (2 / 3 * Math.sin(a) - Math.cos(a))
);
ctx.lineTo( // rear right
x - ship.r * (2 / 3 * Math.cos(a) - Math.sin(a)),
y + ship.r * (2 / 3 * Math.sin(a) + Math.cos(a))
)
ctx.closePath();
ctx.stroke();
}
to this
function drawShipRelative(a, color = "white") {
/*
An overload of drawShip that doesn't ask for the position of the ship.
Only the angle(a)
Inputs:
a(number) : The angle in radians(?)
Outputs:
void
*/
let ctx = getCTX();
let cvs = getCanv();
ctx.strokeStyle = color;
ctx.lineWidth = SHIP_SIZE / 20;
ctx.beginPath();
ctx.moveTo( // nose of ship
cvs.width/2 + 4 / 3 * ship.r * Math.cos(a+1.06),
cvs.height/2 +4 / 3 * ship.r * Math.sin(a+1.06)
);
ctx.lineTo( // rear left
cvs.width/2 + ship.r * (-1 / 3 * Math.cos(a+1.06) + Math.sin(a+1.06)),
cvs.height/2 + ship.r * (-1 / 3 * Math.sin(a+1.06) - Math.cos(a+1.06))
);
ctx.lineTo( // rear right
cvs.width/2 + ship.r * (-1 / 3 * Math.cos(a+1.06) - Math.sin(a+1.06)),
cvs.height/2 + ship.r * (-1 / 3 * Math.sin(a+1.06) + Math.cos(a+1.06))
)
ctx.closePath();
ctx.stroke();
}
I tried mucking around with the numbers, but I couldn't get it quite right.
Notice how it is shifted over to the right too much.
Main Branch
When using the arrow keys on a keyboard, it's pretty difficult to aim. The ship rotates too quickly.
The arrow key is sensitive enough to allow a user to have more granular changes in ship rotation.
I've tried reducing TURN_SPEED, but this makes turning slower which is annoying. The crux here is that aiming and turning are tied together.
One idea is to have a key that slows the ship's turning speed while you are pressing it. Maybe it could be like a stoptime feature where the asteroids slow down, too. When the key is released, the game goes back to normal speed.
Another option is to disconnect aiming from turning. like maybe you can turn the laser without turning the ship.
Currently, the only things that can kill you are asteroids. It would be awesome if there were satellite that shot at you and moved around the screen.
The satellite should have the following properties
Currently, the game just starts at level 1 with no menu.
There is a menu that allows you to change different settings and start the game.
The menu should have the following items
Tracking issue for:
We are only using Bootstrap to style the game start and game over menu. We can migrate to pure HTML/CSS/JS to optimize bundle size.
dotfiles like .husky, .eslintrc.cjs should all go in one folder instead of polluting the root directory.
This will break a lot of stuff
Make sure to update the docs/readme
Right now we are just doing console.logs() for general information about what is going on in the program. This isn't great because it makes it harder to debug issues (especially on production)
Replace all console.log() commands with a logging command.
Have different log files for different levels of errors (e.g. INFO, WARNING, ERROR)
How will this work in the Vercel serverless environment?
How to convert coordinates
How to cycle through polygons
How to handle multi polygons or ones with holes
How to upscale/downscale polygons if they are too small or large.
Re-think collisions?
Error handling
Will need to make sure collisions and boundaries are updated correctly.
It would be cool to have those fancy badges that show things like test coverage and if the build is sucessful/failed. Like I've done on my blog, https://github.com/jsolly/blogthedata
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.