# Coding Challenge #46.1: Asteroids with p5.js – Part 1

This video is Part 1 of a new Coding Challenge: the classic Atari video game Asteroids! In this video, I use JavaScript and HTML5 canvas with the p5.js library to program the ship and the asteroids.

💻Challenge Webpage:
🎥Asteroids Part 2:
🎥Polar Coordinates:

🚂Website:
💡Github:
💖Membership:
🛒Store:
📚Books:

🎥 Coding Challenges:
🎥 Intro to Programming:

🔗 p5.js:
🔗 Processing:

📄 Code of Conduct:
🌐Help us caption and translate:
🚩Suggest Topics:

Nguồn: https://livereference.org/

Xem thêm bài viết khác: https://livereference.org/game/

## 26 thoughts on “Coding Challenge #46.1: Asteroids with p5.js – Part 1”

1. Cesar E. De la Cruz Rojas says:

By a little moment, I think leave, when listen, piu, piu, piu… WTH!!!

One more piu, leave…

2. John Rodgers says:

I'm new to js.. I'm following along but visual code editor said to change function Ship() to this:
class Ship {

constructor() {
Is your usage deprecated or something?

3. Scott Britton says:

Can you please explain how soi is equalant to René Descartes? I am soi. It was expressed to me by Lori a Quantum Quenn, that I reminded her of René Descartes. This was in 2009, while I was deployed to Iraq. At the Age of 19 the name of soi was gifted to me. I am a retired Army vet of 20 years. Currently I am taking computer programming. I follow the path of quantum mechanics. With this concept I am aware to see spectral timelines. Through these timelines, we make decisions, The choices, decisions we make today l can effect the future. How will the world be in 300 years? I'd like to see the world better. . -Scott Michael Britton

4. MattTheSlav says:

How do you do the ship movement manually without the use of the p5.js function>

5. Luc Enden says:

Astroid part: 23:26

6. Bruno Gavloski says:

you're the best

7. Q is legit. Don't trust the media. says:

I have P5.js setup up with Atom on mac…but it's a little wonky. My autocomplete is screwy af.
Do you have a video on how to set this all up properly? I really do like Atom though…it's puuuurdy.

Also…do I just create a new sketch.js file for a new project? Or do I have to copy the entire empty-example folder and included files each time I want to start a new project?

Not intuitive at all. I think I prefer Processing 🤣

8. Angel Carvajal says:

This is the for(let i = 0; i < blank.length; i++) song

9. Angel Carvajal says:

Uncaught ShiffmanError: this dot forgotten

10. Danny L says:

Does anyone have the link to video where asteroids is programmed in python and with an included artificial intelligence bot towards the end of the video?

11. Sean Elliott says:

Is the code still available somewhere? The github link takes us to a 404.

12. Ender Namikaze says:

2019!!! Anyone else?

13. Ciel Register says:

the triangle thing you made is wrong, the point at the top should be (0, -5) because x doesn't change

14. JustSome Dude says:

12:00 Will someone please reference me to the video where he shows how to get the angle using sin and cos? I'm trying to do this without p5 and getting stuck here.

15. Owen Smith says:

30:47 you said that you could do some "crazy javascript inheritance thing" how would you do that without using ES6?

16. Ruan says:

Link to Saraj's channel…. still coming soon

17. Raf Masolijn says:

My line : shop = new Ship(); does not work

18. arth says:

I have some dirty stuff for you:

function A() {
this.v = null;
with(this){
this.foo = function() {v = 42;} // no more «this dot» required
}
}
let a = new A;
a.foo();
console.log(a.v); // 42

19. Sunoze says:

THESE
THE CONTROLLER ISN'T EVEN ON! AT LEAST MAKE A BETTER ADVERTISEMENT. This isn't directing too you The Coding Train.

20. Yubin Kim says:

14:43 else if (keyCode == UP_ARROW) {
ship.isBoosting(true);
}

21. Rahaf Talal says:

Hi daniel , i have question
I coding a game called RushHour let said i have string which contained a solution ex. String solution = “carxU”
It said car x go one move forward “Up” the The problem is the car will be in position zero and zero and one gets the string it should move one move up how can I do this ?

22. Rahaf Talal says:

Hi daniel , i have question
I coding a game called RushHour let said i have string which contained a solution ex. String solution = “carxU”
It said car x go one move forward “Up” the The problem is the car will be in position zero and zero and one gets the string it should move one move up how can I do this ?

23. ZOLDIK says:

14:30 i don't understand why you had to handle the "when key is presses only" why you didn't made the function keyIsPressed instead of keyPressed function ,or keyIsPressed was not available in p5 in 2016 ?

24. Cameron says:

Why use a keyPressed function when your brain is constantly running a dePressed function 🙁

25. Monsoonjr99 — Ryan Makes Things says:

9:13 That typo could have went differently…

26. Like You says:

Don't know if you improved the spaceship steering later on but it's better with if (keyIsDown==…) inside draw loop than the keyPressed/released combination. It doesn't freeze if u click 2 buttons at the same time or release them in wrong order as it does in keypressed/released.