Unexpected Token Noob Q'
in
Programming Questions
•
1 year ago
Here is the code. I have it in different tabs and I don't know how to display the code in this manner, so I will copy and paste as best I can. Thank you in advance!
Ship Sp;
Alien Al;
ArrayList<Bullet> bList;
int bulletDelay;
void setup()
{
size(800, 600);
//smooth();
Al = new Alien();
Sp = new Ship(10);
bList = new ArrayList<Bullet>();
}
void draw()
{
float deltaX = pmouseX - Sp.centerX;
float deltaY = pmouseY - Sp.centerY;
// deltaX = Sp.easing;
//deltaY = Sp.easing;
background(0);
Sp.rotateShip(deltaX, deltaY);
Sp.displayShip();
// Sp.keyPressed();
Sp.move();
Al.displayAlien();
Al.move();
if (keyPressed)
{
Sp.speedUp();
}
else
{
Sp.slowDown();
}
bulletDelay++;
for (int i=0; i < bList.size(); i++)
{
Bullet blt = bList.get(i);
blt.drawBullet();
blt.move();
}
if (mousePressed)
{
if (bulletDelay % 40 == 0)
{
float directionX = (mouseX - Sp.centerX);
float directionY = (mouseY - Sp.centerY);
float n = directionX * directionX + directionY * directionY;
n = sqrt(n);
directionX = directionX/n;
directionY = directionY/n;
Bullet b = new Bullet(Sp.centerX, Sp.centerY, 5, directionX, directionY);
bList.add(b);
}
}
}
class Alien
{
float x, y;
float s;
float centerX, centerY;
float xSpeed;
float ySpeed;
Alien()
{
centerX = width/2;
centerY = height/2;
//this.s = s;
// sze = s;
//fly = 10;
//len = s;
//easing = .05;
// rotation = 0;
xSpeed = .7;
ySpeed = .7;
}
void move()
{
//centerX += xLoc;
//centerY += yLoc;
centerX += xSpeed;
centerY += ySpeed;
}
void displayAlien()
{
fill(255);
smooth();
rectMode(CENTER);
rect(centerX, centerY, 10, 10);
}
}
class Bullet
{
float x, y, s;
float xSpeed, ySpeed;
float bulletSpeed;
Bullet(float xPos, float yPos, float sz, float xSpeed, float ySpeed)
{
x = xPos;
y = yPos;
s = sz;
bulletSpeed = 6;
this.xSpeed = xSpeed*bulletSpeed;
this.ySpeed = ySpeed*bulletSpeed;
}
void drawBullet()
{
rectMode(CENTER);
rect(x,y,s,s);
}
void move()
{
y += ySpeed;
x += xSpeed;
}
}
class Ship
{
float x, y;
//float xLoc, yLoc;
float fly;
float hit;
float s;
float len;
float centerX;
float centerY;
float rotation;
float easing;
float stop;
float xSpeed;
float ySpeed;
PVector shipLoc;
Ship(float s)
{
// x = width/2;
//y = height/2;
centerX = width/2;
centerY = height/2;
this.s = s;
hit = 0;
fly = 10;
len = s;
easing = .05;
rotation = 0;
xSpeed = .7;
ySpeed = .7;
shipLoc =
}
void move()
{
//centerX += xLoc;
//centerY += yLoc;
centerX += xSpeed;
centerY += ySpeed;
if (centerY >= height)
{
centerY = 1;
}
if (centerY <= 0)
{
centerY = 600;
}
if (centerX >= width)
{
centerX = 1;
}
if (centerX <= 0)
{
centerX = width;
}
}
void speedUp()
{
switch(key)
{
case 'w':
y-= ySpeed--;
break;
case 's':
y+= ySpeed++;
break;
case 'a':
x-= xSpeed--;
break;
case 'd':
x+= xSpeed++;
break;
}
}
void slowDown()
{
xSpeed *= .9;
ySpeed *= .9;
}
void rotateShip(float x, float y)
{
rotation = atan2(y, x);
}
void displayShip()
{
smooth();
fill(255);
//fill(255, 0);
pushMatrix();
translate(centerX, centerY);
rotate(rotation);
//translate(x, y);
beginShape();
for (float theta = 0; theta < 2 * PI; theta += 2 *PI / 3)
{
float pX = cos(theta) * len;
float pY = sin(theta) * len;
vertex(pX, pY);
}
endShape(CLOSE);
popMatrix();
}
}
Also, if any one could direct me towards some good examples of how one might cause one object to follow another I would be extremely grateful. Not a huge deal though.
1