Skip to content

Level system improvements#10

Open
palmerhinchliffe wants to merge 4 commits intonveenjain:masterfrom
palmerhinchliffe:level-system-improvements
Open

Level system improvements#10
palmerhinchliffe wants to merge 4 commits intonveenjain:masterfrom
palmerhinchliffe:level-system-improvements

Conversation

@palmerhinchliffe
Copy link

  • 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.

Copy link
Owner

@nveenjain nveenjain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 = [];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@palmerhinchliffe
Copy link
Author

palmerhinchliffe commented Oct 4, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants