Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Hero theHero;
- public Bullet[] bullets = new Bullet[10000];
- public static int bulletCount = 0;
- void setup(){
- size(300,600);
- theHero = new Hero(color(255,0,0),mouseX,mouseY);
- }
- void draw(){
- background(255);
- for(int i = 1; i <= bulletCount;i++){
- bullets[i].updatePos();
- bullets[i].displayb();
- }
- theHero.move();
- theHero.display();
- }
- class Hero {
- color c;
- float xpos;
- float ypos;
- Hero(color tempC,float tempXpos, float tempYpos){
- c = tempC;
- xpos = tempXpos;
- ypos = tempYpos;
- }
- void display() {
- stroke(0);
- fill(c);
- rectMode(CENTER);
- rect(xpos, ypos, 20, 10);
- }
- void move() {
- xpos = mouseX;
- ypos = 580;
- }
- }
- public class Bullet {
- color c;
- float xpos;
- float ypos;
- float yspeed;
- void displayb() {
- stroke(0);
- fill(c);
- rectMode(CENTER);
- rect(xpos, ypos, 5, 5);
- }
- public Bullet(color tempC, float tempXpos, float tempYpos, float tempYspeed) {
- c = tempC;
- xpos = tempXpos;
- ypos = tempYpos;
- yspeed = tempYspeed;
- }
- public void updatePos(){
- ypos+= yspeed;
- }
- }
- void mouseClicked(){
- bulletCount++;
- float startX = theHero.xpos;
- bullets[bulletCount] = new Bullet(color(255,0,0),startX,theHero.ypos, -5 /*YSPEED*/);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement