Open
Conversation
nveenjain
requested changes
Oct 3, 2018
Owner
nveenjain
left a comment
There was a problem hiding this comment.
Awesome work till now!! Check if you can do these changes too? This would make the code easier to understand.
| function levelUp() { | ||
| let sunLocationX = randomInt(radius, innerWidth - radius); | ||
| let sunLocationY = randomInt(radius + 100, innerHeight - radius); | ||
| let existingX = []; |
Owner
There was a problem hiding this comment.
Stars Array already exist there on this line. You can check the stars and planets.
|
|
||
| while (i < existingX.length) { | ||
| for (var z = 0; z < existingX.length; z++) { | ||
| if (!between(sunLocationX, existingX[z] - distance, // If not within 20px of any existing x co-ords |
Owner
There was a problem hiding this comment.
For detecting collision, we can use formula from geometry:-
If two circles collide then:-
Distance between them <=2*r
This code is implemented here (not complete copy though) https://github.com/nveenjain/gravity/pull/10/files#diff-51771aa99a43d67cef66bdda737d4fe0R33
Author
|
I'll try get this sorted tonight.
<http://aka.ms/weboutlook>
________________________________
From: Naveen jain <notifications@github.com>
Sent: Wednesday, October 3, 2018 6:16:59 PM
To: nveenjain/gravity
Cc: Palmer Hinchliffe; Author
Subject: Re: [nveenjain/gravity] Level system improvements (#10)
@nveenjain requested changes on this pull request.
Awesome work till now!! Check if you can do these changes too? This would make the code easier to understand.
________________________________
In js/original.js<#10 (comment)>:
@@ -143,6 +145,70 @@
function calculateScore() {
score += Planets.length * Stars.length * 5;
if (Planets.length == 0) score -= 1;
+ if (score > nextLevel && score < nextLevel + (nextLevel / 200)) {
+ levelUp();
+ }
+ }
+ function levelUp() {
+ let sunLocationX = randomInt(radius, innerWidth - radius);
+ let sunLocationY = randomInt(radius + 100, innerHeight - radius);
+ let existingX = [];
Stars Array already exist there on this line<https://github.com/nveenjain/gravity/pull/10/files#diff-51771aa99a43d67cef66bdda737d4fe0R22>. You can check the stars and planets.
________________________________
In js/original.js<#10 (comment)>:
+ let sunLocationX = randomInt(radius, innerWidth - radius);
+ let sunLocationY = randomInt(radius + 100, innerHeight - radius);
+ let existingX = [];
+ let existingY = [];
+ let distance = 20; // Default max distance new stars should have from existing ones
+
+ Stars.forEach(function(star) {
+ existingX.push(star.x);
+ existingY.push(star.y);
+ });
+
+ let i = 0;
+
+ while (i < existingX.length) {
+ for (var z = 0; z < existingX.length; z++) {
+ if (!between(sunLocationX, existingX[z] - distance, // If not within 20px of any existing x co-ords
For detecting collision, we can use formula from geometry:-
If two circles collide then:-
Distance between them <=2*r
This code is implemented here (not complete copy though) https://github.com/nveenjain/gravity/pull/10/files#diff-51771aa99a43d67cef66bdda737d4fe0R33
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub<#10 (review)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/Ae-2ngF8uwy1NViQrDrs05CmmSIyo4iEks5uhJyrgaJpZM4XFQIv>.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
As requested I have changed the new star location co-ordinate variables to be based on the canvas instead of hard coded. (I had to hard code the minimum Y co-ordinate so the new star didn't collide with the score counter etc which are located at the top of the canvas.)
Now, any new stars should not collide with existing ones. I have set a variable called 'distance' to be 20 by default. You can change this if you want the minimum distance new stars have from existing ones to be increased or decreased.
The level and next level info now appears on mobile devices :-)
Let me know what you think and if any changes required etc.