Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

Making ellipses apear from outside the screen and go to the center.

$
0
0

Hi,

I'm making an astroid shooting game. I have a fixed OSC driven turret in the center of the screen and I want astroids to randomly spawn out side the screen and move to the center. I'm stuck with this problem for two days and tried a lot to figure it out, but i can't come to a working concept. Do you have any suggestions to make this a reality. It would be awesome if this could be coupled with the float deg, because I send this parameter to an other part of the system to forward the rotation.

This is my code so far with a not properly working astroid method:

import oscP5.*;
import netP5.*;

OscP5 oscP5;
NetAddress pilot, gunner;

PImage img;
int shoot;
float deg;
float astsize = random(30,70);
float astspeed;
float astposx = random(0,500);
float astposy = random (0,500);

void setup() {
  size (1000, 1000);

  oscP5 = new OscP5(this,12002);
  pilot = new NetAddress("localhost",12001);
  gunner = new NetAddress("localhost",12000);

  deg = -90;
  img = loadImage("turret upperview 2.png");
} //setup()

void draw(){
  background(20);
  stroke(255);
  //line(0, height/2, width, height/2);
  //line(width/2, 0, width/2, height);

  //turret visuals
  pushMatrix();
  translate (width/2, height/2);
  rotate(radians((float)deg));
  if (shoot == 1) {
  stroke (255,0,0);
  } else {
   stroke(20);
  }
  strokeWeight(2);
  line (0, 5, height, 5);
  line (0, -7, height, -7);
  image (img, -21.125, -17.5, img.width/2, img.height/2);
  popMatrix();

  astroid();
} //draw()

void astroid() {
 astspeed = 0.5;

 astposx = astposx + astspeed;
 astposy = astposy + astspeed;

  pushMatrix();
    translate(width/2, height/2);
    ellipse( astposx, astposy, astsize,astsize);
  popMatrix();
} //astroid()

void oscEvent(OscMessage theOscMessage){

  //Receiving message
  String msgType =  theOscMessage.addrPattern();

  if(msgType.equals("/shoot")){
    int shootValue = theOscMessage.get(0).intValue();
    shoot = shootValue;
  }
  if(msgType.equals("/deg")){
    float degValue = theOscMessage.get(0).floatValue();
    deg = degValue;
  }

  //Forwarding
  OscMessage degForward = new OscMessage("/deg");
  degForward.add(deg);
    oscP5.send(degForward, gunner);

  OscMessage shootForward = new OscMessage("/shoot");
  shootForward.add(shoot);
    oscP5.send(shootForward, pilot);
} // oscEvent()

ps. The turning and shooting of the turret is controlled in other patches (NetAddress pilot and gunner)


Viewing all articles
Browse latest Browse all 2896

Trending Articles