This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#26 2012-03-16 20:17:39

maxskywalker
Scratcher
Registered: 2008-01-27
Posts: 1000+

Re: Shots // a game in Processing

It's great!  How is Processing for larger projects?  I'd like to learn Processing, but I would also like it to be powerful, and not good and nice but weak.  By larger projects, I mean far over 10,000 and an actual professional PC (or web) game.  Also, can it do 3D (pseudo-3D, just felt I needed to clarify that with the rise in 3D tech, such as the 3DS and PS Vita) and/or networking?

Offline

 

#27 2012-03-16 20:23:48

veggieman001
Scratcher
Registered: 2010-02-20
Posts: 1000+

Re: Shots // a game in Processing

maxskywalker wrote:

It's great!  How is Processing for larger projects?  I'd like to learn Processing, but I would also like it to be powerful, and not good and nice but weak.  By larger projects, I mean far over 10,000 and an actual professional PC (or web) game.  Also, can it do 3D (pseudo-3D, just felt I needed to clarify that with the rise in 3D tech, such as the 3DS and PS Vita) and/or networking?

I believe it could do larger projects, although I haven't tried. It does have 3D support normally and networking support via a built-in library.


Posts: 20000 - Show all posts

Offline

 

#28 2012-03-16 22:08:41

Wickimen
Scratcher
Registered: 2009-08-02
Posts: 1000+

Re: Shots // a game in Processing

Cool  big_smile
Funny in a very veggie-esque way  tongue
Wow, on my first try I lasted an incredible 9 seconds on Atrocious ahahah wow I suck at this but it's fun


xDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD

Offline

 

#29 2012-03-16 22:24:45

veggieman001
Scratcher
Registered: 2010-02-20
Posts: 1000+

Re: Shots // a game in Processing

Thank you  tongue

And I can get 57 on atrocious  smile


Posts: 20000 - Show all posts

Offline

 

#30 2012-03-16 23:06:35

veggieman001
Scratcher
Registered: 2010-02-20
Posts: 1000+

Re: Shots // a game in Processing

soupoftomato wrote:

Wickimen wrote:

Cool  big_smile
Funny in a very veggie-esque way  tongue
Wow, on my first try I lasted an incredible 9 seconds on Atrocious ahahah wow I suck at this but it's fun

I survived for 13 seconds in atrocious while a bunch of huts were already firing from my 40 second miserable game!
E.g. you stink.

e.g. implies multiple examples


Posts: 20000 - Show all posts

Offline

 

#31 2012-03-16 23:10:42

soupoftomato
Scratcher
Registered: 2009-07-18
Posts: 1000+

Re: Shots // a game in Processing

veggieman001 wrote:

soupoftomato wrote:

Wickimen wrote:

Cool  big_smile
Funny in a very veggie-esque way  tongue
Wow, on my first try I lasted an incredible 9 seconds on Atrocious ahahah wow I suck at this but it's fun

I survived for 13 seconds in atrocious while a bunch of huts were already firing from my 40 second miserable game!
E.g. you stink.

e.g. implies multiple examples

Oh.
Uhm.
I always forget the proper way to say what I meant.
Darn let me find it.
Ah.
i.e.

Last edited by soupoftomato (2012-03-16 23:11:31)


I'm glad to think that the community will always be kind and helpful, the language will always be a fun and easy way to be introduced into programming, the motto will always be: Imagine, Program, Share - Nomolos

Offline

 

#32 2012-03-16 23:12:36

veggieman001
Scratcher
Registered: 2010-02-20
Posts: 1000+

Re: Shots // a game in Processing

soupoftomato wrote:

veggieman001 wrote:

soupoftomato wrote:

I survived for 13 seconds in atrocious while a bunch of huts were already firing from my 40 second miserable game!
E.g. you stink.

e.g. implies multiple examples

Oh.
Uhm.
I always forget the proper way to say what I meant.
Darn let me find it.
Ah.
i.e.

Thank you for using the proper insult.  smile


Posts: 20000 - Show all posts

Offline

 

#33 2012-03-16 23:15:03

soupoftomato
Scratcher
Registered: 2009-07-18
Posts: 1000+

Re: Shots // a game in Processing

I deleted in shame of stupidity.
But for now:
I got 13 in atrocious after a 40 second miserable game.
i.e. Wickimen stinks.


I'm glad to think that the community will always be kind and helpful, the language will always be a fun and easy way to be introduced into programming, the motto will always be: Imagine, Program, Share - Nomolos

Offline

 

#34 2012-03-17 09:12:05

ImagineIt
Scratcher
Registered: 2011-02-28
Posts: 1000+

Re: Shots // a game in Processing

42 in disappointing!  yikes

Offline

 

#35 2012-03-17 09:58:47

Dinoclor
Scratcher
Registered: 2010-06-10
Posts: 1000+

Re: Shots // a game in Processing

The boxes seem to appear mostly around the bottom left corner. Is that on purpose or a bug?


This is a temporary signature. It will exist until I think of something witty.

Offline

 

#36 2012-03-17 10:40:02

veggieman001
Scratcher
Registered: 2010-02-20
Posts: 1000+

Re: Shots // a game in Processing

Dinoclor wrote:

The boxes seem to appear mostly around the bottom left corner. Is that on purpose or a bug?

That may be happening to you by chance, because it doesn't usually happen to me.


Posts: 20000 - Show all posts

Offline

 

#37 2012-03-17 12:48:47

slinger
Scratcher
Registered: 2011-06-21
Posts: 1000+

Re: Shots // a game in Processing

Yeah, same.


http://s0.bcbits.com/img/buttons/bandcamp_130x27_blue.png

Offline

 

#38 2012-03-17 13:15:39

RedRocker227
Scratcher
Registered: 2011-10-26
Posts: 1000+

Re: Shots // a game in Processing

Yaaaaay, 48 in atrocious now.

I just stayed in the top-left corner the whole time, occasionally moving to avoid the whatever-you-call-its.


Why

Offline

 

#39 2012-03-17 13:26:44

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: Shots // a game in Processing

35 in atrocious.  That's a lot of dots!  I am now having trouble focusing my eyes - thank you very much  smile


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#40 2012-03-17 13:40:23

Wickimen
Scratcher
Registered: 2009-08-02
Posts: 1000+

Re: Shots // a game in Processing

Whoa, 100 seconds in Atrocious ("probably")  big_smile
I just stayed in the corner for a long time and it worked lolol


xDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD

Offline

 

#41 2012-03-17 13:45:24

Wickimen
Scratcher
Registered: 2009-08-02
Posts: 1000+

Re: Shots // a game in Processing

109 seconds in Atrocious
This is a good strategy :3

Only 36 seconds in Miserable

61 seconds in Disappointing

Last edited by Wickimen (2012-03-17 13:48:45)


xDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD

Offline

 

#42 2012-03-17 14:17:55

maxskywalker
Scratcher
Registered: 2008-01-27
Posts: 1000+

Re: Shots // a game in Processing

veggieman001 wrote:

maxskywalker wrote:

Very nice.  But aren't you supposed to CLEAR the play area after I die and play again?  Also, I found a glitch.  On Miserable, the bullets already fired (from previous games) were ultra-slow, and no tower would shoot another thing.  As I speak, Shots is open in another tab quite safely, and I can go through towers without being hurt.

Interesting. I was having this bug before and I thought I fixed. I'll see what up.

And nope, it's intentionally like that. Since when are you playing again?

What do you mean 'since when are you playing again'?

Offline

 

#43 2012-03-17 14:19:17

veggieman001
Scratcher
Registered: 2010-02-20
Posts: 1000+

Re: Shots // a game in Processing

maxskywalker wrote:

veggieman001 wrote:

maxskywalker wrote:

Very nice.  But aren't you supposed to CLEAR the play area after I die and play again?  Also, I found a glitch.  On Miserable, the bullets already fired (from previous games) were ultra-slow, and no tower would shoot another thing.  As I speak, Shots is open in another tab quite safely, and I can go through towers without being hurt.

Interesting. I was having this bug before and I thought I fixed. I'll see what up.

And nope, it's intentionally like that. Since when are you playing again?

What do you mean 'since when are you playing again'?

When you press space, you're not playing again.


Posts: 20000 - Show all posts

Offline

 

#44 2012-03-17 14:19:47

maxskywalker
Scratcher
Registered: 2008-01-27
Posts: 1000+

Re: Shots // a game in Processing

veggieman001 wrote:

maxskywalker wrote:

It's great!  How is Processing for larger projects?  I'd like to learn Processing, but I would also like it to be powerful, and not good and nice but weak.  By larger projects, I mean far over 10,000 and an actual professional PC (or web) game.  Also, can it do 3D (pseudo-3D, just felt I needed to clarify that with the rise in 3D tech, such as the 3DS and PS Vita) and/or networking?

I believe it could do larger projects, although I haven't tried. It does have 3D support normally and networking support via a built-in library.

Hm, I think I'll give Processing a try.  Assuming I can find the URL.

Offline

 

#45 2012-03-17 14:24:02

veggieman001
Scratcher
Registered: 2010-02-20
Posts: 1000+

Re: Shots // a game in Processing

maxskywalker wrote:

veggieman001 wrote:

maxskywalker wrote:

It's great!  How is Processing for larger projects?  I'd like to learn Processing, but I would also like it to be powerful, and not good and nice but weak.  By larger projects, I mean far over 10,000 and an actual professional PC (or web) game.  Also, can it do 3D (pseudo-3D, just felt I needed to clarify that with the rise in 3D tech, such as the 3DS and PS Vita) and/or networking?

I believe it could do larger projects, although I haven't tried. It does have 3D support normally and networking support via a built-in library.

Hm, I think I'll give Processing a try.  Assuming I can find the URL.

It's on the page :I


Posts: 20000 - Show all posts

Offline

 

#46 2012-03-18 08:46:47

scratchisthebest
Scratcher
Registered: 2009-02-08
Posts: 500+

Re: Shots // a game in Processing

Code:

//I fixed it! :D :P no.
import processing.opengl.*;

ArrayList shooters = new ArrayList();
int stimer, ctimer, gtimer, osec, px, py, firedelay;
boolean menu = true;
boolean fr = false;
Player player;
void setup() {
  size(580, 460, OPENGL);
  text("Shots", width/2-10, height/2-50);
  shooters.add(new Shooter(int(random(30, width-30)), int(random(30, height-30))));
  player = new Player(width/2, height/2, 15);
  speed = 2;
  osec  = 2;

  noStroke();
}

void draw() {
  if (player != null) {
    if (menu) {
      fill(#552233);
      gtimer = 0;
      text("Shots", width/2-20, height/2-120);
      text("Choose difficulty wisely", width/2-65, height/2-85);
      if (mouseX>width/2-50 && mouseY>height/2-75 && mouseX<width/2+50 && mouseY<height/2-25) {
        fill(#3377AA);
        if (mousePressed) {
          firedelay=99;
          menu = false;
        }
      }
      else fill(#004477);
      rect(width/2-50, height/2-75, 100, 50);
      fill(#FFFFFF);
      text("Disappointing", width/2-38, height/2-45);
      if (mouseX>width/2-50 && mouseY>height/2-20 && mouseX<width/2+50 && mouseY<height/2+30) {
        fill(#3377AA);
        if (mousePressed) {
          firedelay=59;
          menu = false;
        }
      }
      else fill(#004477);
      rect(width/2-50, height/2-20, 100, 50);
      fill(#FFFFFF);
      text("Miserable", width/2-25, height/2+10);
      if (mouseX>width/2-50 && mouseY>height/2+35 && mouseX<width/2+50 && mouseY<height/2+95) {
        fill(#3377AA);
        if (mousePressed) {
          firedelay=29;
          menu = false;
        }
      }
      else fill(#004477);
      rect(width/2-50, height/2+35, 100, 50);
      fill(#FFFFFF);
      text("Atrocious", width/2-25, height/2+65);
    }
    else {
      //background(250);
      fill(255,10);
      rect(0,0,width,height);
      switch(result) {
      case NORTH: 
        player.y-=speed; 
        break;
      case EAST: 
        player.x+=speed; 
        break;
      case SOUTH: 
        player.y+=speed; 
        break;
      case WEST: 
        player.x-=speed; 
        break;
      case NORTH|EAST: 
        player.y-=speed; 
        player.x+=speed; 
        break;
      case NORTH|WEST: 
        player.y-=speed; 
        player.x-=speed; 
        break;
      case SOUTH|EAST: 
        player.y+=speed; 
        player.x+=speed; 
        break;
      case SOUTH|WEST: 
        player.y+=speed; 
        player.x-=speed; 
        break;
      case NORTH|EAST|WEST: 
        player.y-=speed; 
        break;
      case NORTH|SOUTH|WEST: 
        player.x-=speed; 
        break;
      case NORTH|SOUTH|EAST: 
        player.x+=speed; 
        break;
      case EAST|WEST|SOUTH: 
        player.y+=speed; 
        break;
      }
      player.update();
      for (int i = shooters.size()-1; i >= 0; i--) {
        Shooter shooter = (Shooter) shooters.get(i);
        shooter.update();
      }
      stimer++;
      ctimer++;
      if (osec != second()) {
        gtimer++;
        osec = second();
      }
      if (stimer==firedelay) stimer=0;
      if (ctimer==199) {
        shooters.add(new Shooter(int(random(30, width-30)), int(random(30, height-30))));
        ctimer=0;
      }
    }
  }
  else {
    fill(#003300);
    shooters.clear();
    text("You lose!", width/2-25, height/2);
    text("You survived for "+gtimer+" seconds", width/2-100, height/2+15);
    text("Press M to return to the menu", width/2-80, height/2+45);
  }
}

class Shooter {
  int x, y, r;
  int ofd = firedelay;
  int[] colour = new int[3];
  int tnum = int(random(0, firedelay));
  ArrayList<Shot> shots = new ArrayList();
  Shooter (int x_, int y_) {
    x = x_;
    y = y_;
    r = 20; 
    colour[0] = int(random(0, 255));
    colour[1] = int(random(0, 255));
    colour[2] = int(random(0, 255));
  }
  void update() {
    if (firedelay != ofd) {
      tnum = int(random(0, firedelay));
      ofd=firedelay;
    }
    fill(colour[0], colour[1], colour[2]);
    rect(x, y, r, r);
    if (stimer==tnum) shots.add(new Shot());
    for (int i = shots.size()-1; i >= 0; i--) {
      Shot shot = shots.get(i);
      shot.update();
      stroke(0);
      for(int j=i; j < shots.size(); j++) {
        line(shots.get(i).l.x,shots.get(i).l.y,shots.get(j).l.x,shots.get(j).l.y);
      }
      noStroke();
      shot.display();
      
      //if (shot.l.x > width+10 || shot.l.x < -10 || shot.l.y > height+10 || shot.l.y < -10 ) shots.remove(i);
    }
  }

  class Shot {
    PVector v = new PVector(random(-1, 1), random(-1, 1));
    PVector l = new PVector(x+r/2, y+r/2);
    void update() {
      l.add(v);
      if (Touching(player, this)) {
        px=player.x;
        py=player.y;
        player = null;
      }
    }
    
    void display() {
      ellipse(l.x, l.y, 10, 10);
    }
  }
}

class Player {
  int x, y, r;
  Player (int x_, int y_, int r_) {
    x=x_;
    y=y_;
    r=r_;
  } 
  void update() {
    fill(#FF55FF);
    ellipse(x, y, r, r);
    if (x <= r/2) x = r/2;
    if (y <= r/2) y = r/2;
    if (x >= width-r/2) x = width-r/2;
    if (y >= height-r/2) y = height-r/2;
  }
}

boolean Touching(Player pl, Shooter.Shot sh) {
  if (player != null) {
    if (dist(pl.x, pl.y, sh.l.x, sh.l.y)<=15) {
      return true;
    }
    else return false;
  }
  else return false;
}

final static int NORTH = 1;
final static int EAST = 2;
final static int SOUTH = 4;
final static int WEST = 8;
int result, speed;
//code from processing wiki by sojamo
//three key sensing by me
void keyPressed() {
  if (key == CODED) {
    switch(keyCode) {
      case(UP):
      result |=NORTH;
      break;
      case(RIGHT):
      result |=EAST;
      break;
      case(DOWN):
      result |=SOUTH;
      break;
      case(LEFT):
      result |=WEST;
      break;
    }
  }
  else if (key == ' ' && player == null) {
    gtimer = 0;
    player = new Player(round(random(30, width-30)), round(random(30, height-30)), 15);
  }
  else if ((key == 'm' || key == 'M') && player == null) {
    player = new Player(width/2, height/2, 15);
    menu=true;
  }
}

void keyReleased() {  
  if (key == CODED) {
    switch(keyCode) {
      case(UP):
      result ^=NORTH;
      break;
      case(RIGHT):
      result ^=EAST;
      break;
      case(DOWN):
      result ^=SOUTH;
      break;
      case(LEFT):
      result ^=WEST;
      break;
    }
  }
}

bye 1.4, we all loved you. but we all outgrew the site. 2.0 is a welcome change.
http://scratch.mit.edu/img/Pico3-med.pnghttp://scratch.mit.edu/img/Pico3-med.pnghttp://scratch.mit.edu/img/Pico3-med.pnghttp://scratch.mit.edu/img/Pico3-med.pnghttp://scratch.mit.edu/img/Pico3-med.png

Offline

 

#47 2012-03-18 09:24:23

maxskywalker
Scratcher
Registered: 2008-01-27
Posts: 1000+

Re: Shots // a game in Processing

veggieman001 wrote:

maxskywalker wrote:

veggieman001 wrote:


I believe it could do larger projects, although I haven't tried. It does have 3D support normally and networking support via a built-in library.

Hm, I think I'll give Processing a try.  Assuming I can find the URL.

It's on the page :I

Yeah, I've already found it.  Right before remembering that I still need to install Java on this computer.

Offline

 

#48 2012-03-18 10:12:08

16Skittles
Scratcher
Registered: 2009-08-26
Posts: 1000+

Re: Shots // a game in Processing

61 in atrocious!   yikes


http://16skittles.tk/sig.png
Are you a student? Check out OnSchedule!

Offline

 

#49 2012-03-18 10:46:21

veggieman001
Scratcher
Registered: 2010-02-20
Posts: 1000+

Re: Shots // a game in Processing

scratchisthebest wrote:

Code:

//I fixed it! :D :P no.
import processing.opengl.*;

ArrayList shooters = new ArrayList();
int stimer, ctimer, gtimer, osec, px, py, firedelay;
boolean menu = true;
boolean fr = false;
Player player;
void setup() {
  size(580, 460, OPENGL);
  text("Shots", width/2-10, height/2-50);
  shooters.add(new Shooter(int(random(30, width-30)), int(random(30, height-30))));
  player = new Player(width/2, height/2, 15);
  speed = 2;
  osec  = 2;

  noStroke();
}

void draw() {
  if (player != null) {
    if (menu) {
      fill(#552233);
      gtimer = 0;
      text("Shots", width/2-20, height/2-120);
      text("Choose difficulty wisely", width/2-65, height/2-85);
      if (mouseX>width/2-50 && mouseY>height/2-75 && mouseX<width/2+50 && mouseY<height/2-25) {
        fill(#3377AA);
        if (mousePressed) {
          firedelay=99;
          menu = false;
        }
      }
      else fill(#004477);
      rect(width/2-50, height/2-75, 100, 50);
      fill(#FFFFFF);
      text("Disappointing", width/2-38, height/2-45);
      if (mouseX>width/2-50 && mouseY>height/2-20 && mouseX<width/2+50 && mouseY<height/2+30) {
        fill(#3377AA);
        if (mousePressed) {
          firedelay=59;
          menu = false;
        }
      }
      else fill(#004477);
      rect(width/2-50, height/2-20, 100, 50);
      fill(#FFFFFF);
      text("Miserable", width/2-25, height/2+10);
      if (mouseX>width/2-50 && mouseY>height/2+35 && mouseX<width/2+50 && mouseY<height/2+95) {
        fill(#3377AA);
        if (mousePressed) {
          firedelay=29;
          menu = false;
        }
      }
      else fill(#004477);
      rect(width/2-50, height/2+35, 100, 50);
      fill(#FFFFFF);
      text("Atrocious", width/2-25, height/2+65);
    }
    else {
      //background(250);
      fill(255,10);
      rect(0,0,width,height);
      switch(result) {
      case NORTH: 
        player.y-=speed; 
        break;
      case EAST: 
        player.x+=speed; 
        break;
      case SOUTH: 
        player.y+=speed; 
        break;
      case WEST: 
        player.x-=speed; 
        break;
      case NORTH|EAST: 
        player.y-=speed; 
        player.x+=speed; 
        break;
      case NORTH|WEST: 
        player.y-=speed; 
        player.x-=speed; 
        break;
      case SOUTH|EAST: 
        player.y+=speed; 
        player.x+=speed; 
        break;
      case SOUTH|WEST: 
        player.y+=speed; 
        player.x-=speed; 
        break;
      case NORTH|EAST|WEST: 
        player.y-=speed; 
        break;
      case NORTH|SOUTH|WEST: 
        player.x-=speed; 
        break;
      case NORTH|SOUTH|EAST: 
        player.x+=speed; 
        break;
      case EAST|WEST|SOUTH: 
        player.y+=speed; 
        break;
      }
      player.update();
      for (int i = shooters.size()-1; i >= 0; i--) {
        Shooter shooter = (Shooter) shooters.get(i);
        shooter.update();
      }
      stimer++;
      ctimer++;
      if (osec != second()) {
        gtimer++;
        osec = second();
      }
      if (stimer==firedelay) stimer=0;
      if (ctimer==199) {
        shooters.add(new Shooter(int(random(30, width-30)), int(random(30, height-30))));
        ctimer=0;
      }
    }
  }
  else {
    fill(#003300);
    shooters.clear();
    text("You lose!", width/2-25, height/2);
    text("You survived for "+gtimer+" seconds", width/2-100, height/2+15);
    text("Press M to return to the menu", width/2-80, height/2+45);
  }
}

class Shooter {
  int x, y, r;
  int ofd = firedelay;
  int[] colour = new int[3];
  int tnum = int(random(0, firedelay));
  ArrayList<Shot> shots = new ArrayList();
  Shooter (int x_, int y_) {
    x = x_;
    y = y_;
    r = 20; 
    colour[0] = int(random(0, 255));
    colour[1] = int(random(0, 255));
    colour[2] = int(random(0, 255));
  }
  void update() {
    if (firedelay != ofd) {
      tnum = int(random(0, firedelay));
      ofd=firedelay;
    }
    fill(colour[0], colour[1], colour[2]);
    rect(x, y, r, r);
    if (stimer==tnum) shots.add(new Shot());
    for (int i = shots.size()-1; i >= 0; i--) {
      Shot shot = shots.get(i);
      shot.update();
      stroke(0);
      for(int j=i; j < shots.size(); j++) {
        line(shots.get(i).l.x,shots.get(i).l.y,shots.get(j).l.x,shots.get(j).l.y);
      }
      noStroke();
      shot.display();
      
      //if (shot.l.x > width+10 || shot.l.x < -10 || shot.l.y > height+10 || shot.l.y < -10 ) shots.remove(i);
    }
  }

  class Shot {
    PVector v = new PVector(random(-1, 1), random(-1, 1));
    PVector l = new PVector(x+r/2, y+r/2);
    void update() {
      l.add(v);
      if (Touching(player, this)) {
        px=player.x;
        py=player.y;
        player = null;
      }
    }
    
    void display() {
      ellipse(l.x, l.y, 10, 10);
    }
  }
}

class Player {
  int x, y, r;
  Player (int x_, int y_, int r_) {
    x=x_;
    y=y_;
    r=r_;
  } 
  void update() {
    fill(#FF55FF);
    ellipse(x, y, r, r);
    if (x <= r/2) x = r/2;
    if (y <= r/2) y = r/2;
    if (x >= width-r/2) x = width-r/2;
    if (y >= height-r/2) y = height-r/2;
  }
}

boolean Touching(Player pl, Shooter.Shot sh) {
  if (player != null) {
    if (dist(pl.x, pl.y, sh.l.x, sh.l.y)<=15) {
      return true;
    }
    else return false;
  }
  else return false;
}

final static int NORTH = 1;
final static int EAST = 2;
final static int SOUTH = 4;
final static int WEST = 8;
int result, speed;
//code from processing wiki by sojamo
//three key sensing by me
void keyPressed() {
  if (key == CODED) {
    switch(keyCode) {
      case(UP):
      result |=NORTH;
      break;
      case(RIGHT):
      result |=EAST;
      break;
      case(DOWN):
      result |=SOUTH;
      break;
      case(LEFT):
      result |=WEST;
      break;
    }
  }
  else if (key == ' ' && player == null) {
    gtimer = 0;
    player = new Player(round(random(30, width-30)), round(random(30, height-30)), 15);
  }
  else if ((key == 'm' || key == 'M') && player == null) {
    player = new Player(width/2, height/2, 15);
    menu=true;
  }
}

void keyReleased() {  
  if (key == CODED) {
    switch(keyCode) {
      case(UP):
      result ^=NORTH;
      break;
      case(RIGHT):
      result ^=EAST;
      break;
      case(DOWN):
      result ^=SOUTH;
      break;
      case(LEFT):
      result ^=WEST;
      break;
    }
  }
}

whoa what did you do


Posts: 20000 - Show all posts

Offline

 

#50 2012-03-31 09:34:43

scratchisthebest
Scratcher
Registered: 2009-02-08
Posts: 500+

Re: Shots // a game in Processing

veggieman001 wrote:

scratchisthebest wrote:

Code:

//I fixed it! :D :P no.
import processing.opengl.*;

ArrayList shooters = new ArrayList();
int stimer, ctimer, gtimer, osec, px, py, firedelay;
boolean menu = true;
boolean fr = false;
Player player;
void setup() {
  size(580, 460, OPENGL);
  text("Shots", width/2-10, height/2-50);
  shooters.add(new Shooter(int(random(30, width-30)), int(random(30, height-30))));
  player = new Player(width/2, height/2, 15);
  speed = 2;
  osec  = 2;

  noStroke();
}

void draw() {
  if (player != null) {
    if (menu) {
      fill(#552233);
      gtimer = 0;
      text("Shots", width/2-20, height/2-120);
      text("Choose difficulty wisely", width/2-65, height/2-85);
      if (mouseX>width/2-50 && mouseY>height/2-75 && mouseX<width/2+50 && mouseY<height/2-25) {
        fill(#3377AA);
        if (mousePressed) {
          firedelay=99;
          menu = false;
        }
      }
      else fill(#004477);
      rect(width/2-50, height/2-75, 100, 50);
      fill(#FFFFFF);
      text("Disappointing", width/2-38, height/2-45);
      if (mouseX>width/2-50 && mouseY>height/2-20 && mouseX<width/2+50 && mouseY<height/2+30) {
        fill(#3377AA);
        if (mousePressed) {
          firedelay=59;
          menu = false;
        }
      }
      else fill(#004477);
      rect(width/2-50, height/2-20, 100, 50);
      fill(#FFFFFF);
      text("Miserable", width/2-25, height/2+10);
      if (mouseX>width/2-50 && mouseY>height/2+35 && mouseX<width/2+50 && mouseY<height/2+95) {
        fill(#3377AA);
        if (mousePressed) {
          firedelay=29;
          menu = false;
        }
      }
      else fill(#004477);
      rect(width/2-50, height/2+35, 100, 50);
      fill(#FFFFFF);
      text("Atrocious", width/2-25, height/2+65);
    }
    else {
      //background(250);
      fill(255,10);
      rect(0,0,width,height);
      switch(result) {
      case NORTH: 
        player.y-=speed; 
        break;
      case EAST: 
        player.x+=speed; 
        break;
      case SOUTH: 
        player.y+=speed; 
        break;
      case WEST: 
        player.x-=speed; 
        break;
      case NORTH|EAST: 
        player.y-=speed; 
        player.x+=speed; 
        break;
      case NORTH|WEST: 
        player.y-=speed; 
        player.x-=speed; 
        break;
      case SOUTH|EAST: 
        player.y+=speed; 
        player.x+=speed; 
        break;
      case SOUTH|WEST: 
        player.y+=speed; 
        player.x-=speed; 
        break;
      case NORTH|EAST|WEST: 
        player.y-=speed; 
        break;
      case NORTH|SOUTH|WEST: 
        player.x-=speed; 
        break;
      case NORTH|SOUTH|EAST: 
        player.x+=speed; 
        break;
      case EAST|WEST|SOUTH: 
        player.y+=speed; 
        break;
      }
      player.update();
      for (int i = shooters.size()-1; i >= 0; i--) {
        Shooter shooter = (Shooter) shooters.get(i);
        shooter.update();
      }
      stimer++;
      ctimer++;
      if (osec != second()) {
        gtimer++;
        osec = second();
      }
      if (stimer==firedelay) stimer=0;
      if (ctimer==199) {
        shooters.add(new Shooter(int(random(30, width-30)), int(random(30, height-30))));
        ctimer=0;
      }
    }
  }
  else {
    fill(#003300);
    shooters.clear();
    text("You lose!", width/2-25, height/2);
    text("You survived for "+gtimer+" seconds", width/2-100, height/2+15);
    text("Press M to return to the menu", width/2-80, height/2+45);
  }
}

class Shooter {
  int x, y, r;
  int ofd = firedelay;
  int[] colour = new int[3];
  int tnum = int(random(0, firedelay));
  ArrayList<Shot> shots = new ArrayList();
  Shooter (int x_, int y_) {
    x = x_;
    y = y_;
    r = 20; 
    colour[0] = int(random(0, 255));
    colour[1] = int(random(0, 255));
    colour[2] = int(random(0, 255));
  }
  void update() {
    if (firedelay != ofd) {
      tnum = int(random(0, firedelay));
      ofd=firedelay;
    }
    fill(colour[0], colour[1], colour[2]);
    rect(x, y, r, r);
    if (stimer==tnum) shots.add(new Shot());
    for (int i = shots.size()-1; i >= 0; i--) {
      Shot shot = shots.get(i);
      shot.update();
      stroke(0);
      for(int j=i; j < shots.size(); j++) {
        line(shots.get(i).l.x,shots.get(i).l.y,shots.get(j).l.x,shots.get(j).l.y);
      }
      noStroke();
      shot.display();
      
      //if (shot.l.x > width+10 || shot.l.x < -10 || shot.l.y > height+10 || shot.l.y < -10 ) shots.remove(i);
    }
  }

  class Shot {
    PVector v = new PVector(random(-1, 1), random(-1, 1));
    PVector l = new PVector(x+r/2, y+r/2);
    void update() {
      l.add(v);
      if (Touching(player, this)) {
        px=player.x;
        py=player.y;
        player = null;
      }
    }
    
    void display() {
      ellipse(l.x, l.y, 10, 10);
    }
  }
}

class Player {
  int x, y, r;
  Player (int x_, int y_, int r_) {
    x=x_;
    y=y_;
    r=r_;
  } 
  void update() {
    fill(#FF55FF);
    ellipse(x, y, r, r);
    if (x <= r/2) x = r/2;
    if (y <= r/2) y = r/2;
    if (x >= width-r/2) x = width-r/2;
    if (y >= height-r/2) y = height-r/2;
  }
}

boolean Touching(Player pl, Shooter.Shot sh) {
  if (player != null) {
    if (dist(pl.x, pl.y, sh.l.x, sh.l.y)<=15) {
      return true;
    }
    else return false;
  }
  else return false;
}

final static int NORTH = 1;
final static int EAST = 2;
final static int SOUTH = 4;
final static int WEST = 8;
int result, speed;
//code from processing wiki by sojamo
//three key sensing by me
void keyPressed() {
  if (key == CODED) {
    switch(keyCode) {
      case(UP):
      result |=NORTH;
      break;
      case(RIGHT):
      result |=EAST;
      break;
      case(DOWN):
      result |=SOUTH;
      break;
      case(LEFT):
      result |=WEST;
      break;
    }
  }
  else if (key == ' ' && player == null) {
    gtimer = 0;
    player = new Player(round(random(30, width-30)), round(random(30, height-30)), 15);
  }
  else if ((key == 'm' || key == 'M') && player == null) {
    player = new Player(width/2, height/2, 15);
    menu=true;
  }
}

void keyReleased() {  
  if (key == CODED) {
    switch(keyCode) {
      case(UP):
      result ^=NORTH;
      break;
      case(RIGHT):
      result ^=EAST;
      break;
      case(DOWN):
      result ^=SOUTH;
      break;
      case(LEFT):
      result ^=WEST;
      break;
    }
  }
}

whoa what did you do

magic!  tongue
I drew lines connecting all the bullets from a single turret. So a red turret connects all of its bullets together, but not to the bullets from a green. It gets out of hand *fast* because I didn't clear the background between frames, meaning trails appear.  smile


bye 1.4, we all loved you. but we all outgrew the site. 2.0 is a welcome change.
http://scratch.mit.edu/img/Pico3-med.pnghttp://scratch.mit.edu/img/Pico3-med.pnghttp://scratch.mit.edu/img/Pico3-med.pnghttp://scratch.mit.edu/img/Pico3-med.pnghttp://scratch.mit.edu/img/Pico3-med.png

Offline

 

Board footer