Advertisement
Guest User

Untitled

a guest
Feb 29th, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. let px=100, py=300;
  2. let n = 0;
  3. let bx = [], by = []
  4. let cats = 20
  5. let cx = [], cy = []
  6. let speed = 1
  7.  
  8. for (let i=0; i<cats; ++i){
  9. cy[i] = Math.random()*550
  10. cx[i] = Math.random()*800+800
  11. }
  12.  
  13. function update() {
  14. for (let j=0; j<cats; ++j){
  15. if (cx[j] < 0 || areColliding(cx[j], cy[j], 50, 50, px, py, 50, 50)){
  16. return
  17. }
  18. for (let i=0; i<n; ++i){
  19. if (areColliding(bx[i], by[i], 20, 10, cx[j], cy[j], 50, 50)){
  20. speed += 0.01
  21. cx[j] = Math.random()*800+800
  22. cy[j] = Math.random()*550
  23. }
  24. }
  25. }
  26. for (let i=0; i<cats; ++i){
  27. cx[i] -= speed;
  28. }
  29. py = mouseY
  30. if (isKeyPressed[32]){
  31. bx[n] = px;
  32. by[n] = py+20;
  33. n++
  34. }
  35. for (let i=0; i<n; ++i){
  36. bx[i]+=10;
  37. }
  38. }
  39. function draw() {
  40. drawImage(pirate[0], px, py, 50, 50)
  41. for (let i=0; i<n; ++i){
  42. drawImage(bullet, bx[i], by[i], 20, 10);
  43. }
  44. for (let i=0; i<cats; ++i){
  45. drawImage(cat, cx[i], cy[i], 50, 50);
  46. }
  47. };
  48. function keyup(key) {
  49. };
  50. function mouseup() {
  51. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement