Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. Hero theHero;
  2. public Bullet[] bullets = new Bullet[10000];
  3. public static int bulletCount = 0;
  4. void setup(){
  5. size(300,600);
  6. theHero = new Hero(color(255,0,0),mouseX,mouseY);
  7. }
  8.  
  9. void draw(){
  10. background(255);
  11. for(int i = 1; i <= bulletCount;i++){
  12. bullets[i].updatePos();
  13. bullets[i].displayb();
  14. }
  15. theHero.move();
  16. theHero.display();
  17. }
  18.  
  19. class Hero {
  20. color c;
  21. float xpos;
  22. float ypos;
  23.  
  24. Hero(color tempC,float tempXpos, float tempYpos){
  25. c = tempC;
  26. xpos = tempXpos;
  27. ypos = tempYpos;
  28. }
  29.  
  30. void display() {
  31. stroke(0);
  32. fill(c);
  33. rectMode(CENTER);
  34. rect(xpos, ypos, 20, 10);
  35. }
  36.  
  37. void move() {
  38. xpos = mouseX;
  39. ypos = 580;
  40. }
  41. }
  42.  
  43. public class Bullet {
  44. color c;
  45. float xpos;
  46. float ypos;
  47. float yspeed;
  48.  
  49. void displayb() {
  50. stroke(0);
  51. fill(c);
  52. rectMode(CENTER);
  53. rect(xpos, ypos, 5, 5);
  54. }
  55.  
  56. public Bullet(color tempC, float tempXpos, float tempYpos, float tempYspeed) {
  57. c = tempC;
  58. xpos = tempXpos;
  59. ypos = tempYpos;
  60. yspeed = tempYspeed;
  61. }
  62.  
  63. public void updatePos(){
  64. ypos+= yspeed;
  65. }
  66.  
  67. }
  68. void mouseClicked(){
  69. bulletCount++;
  70. float startX = theHero.xpos;
  71. bullets[bulletCount] = new Bullet(color(255,0,0),startX,theHero.ypos, -5 /*YSPEED*/);
  72.  
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement