Usage: PApplet [options] [sketch args]
See the Javadoc for PApplet for an explanation.
Could not run the sketch (Target VM failed to initialize).
Make sure that you haven’t set the maximum available memory too high.
For more information, read revisions.txt and Help ? Troubleshooting.
this is a shooter game for class.
this error shows up when i try to run my code and no red lines in the code. worked fine last time I worked on it. this seems like a common error but the fixes i found online didn’t help either. its not the graphic card’s driver as it runs every other program. Here’s the code:
import processing.sound.*;
PFont caviar;
SoundFile tiromp3, BeepBox1;
ArrayList<Nivel> nivel= new ArrayList<Nivel>();
PImage naveIm, bomIm, cursorIm, mauIm35,mauIm50,mauIm75, tiroIm;
void setup() {
fullScreen();
//size(1500,900);
background(0);
tiromp3=new SoundFile(this, "tiromp3.mp3");
tiromp3.amp(0.1);
BeepBox1=new SoundFile(this, "BeepBox1.wav");
BeepBox1.amp(0.5);
BeepBox1.loop();
caviar = createFont("CaviarDreams.ttf",30);
naveIm = loadImage ("nave.png");
textFont(caviar);
bomIm = loadImage ("bom.png");
cursorIm = loadImage ("cursor.png");
mauIm35 = loadImage("mau35.png");
mauIm50 = loadImage("mau50.png");
mauIm75 = loadImage("mau75.png");
tiroIm = loadImage("tiro.png");
nivel.add(new Nivel(30,0.2,2,1));//int mM, int mC, int bM, int bC
noCursor();
}
void draw() {
background(0);
if(mousePressed) tint(255,0,0);
else tint(255,255,255);
image(cursorIm, mouseX, mouseY); //cursor em vez da seta
nivel.get(0).spawns();
nivel.get(0).run();
}
void keyPressed(){
nivel.get(0).nave.get(0).movePressed();
}
void keyReleased(){
nivel.get(0).nave.get(0).moveReleased();
}
class UI {
int score, scoresMax=10;
void score() {
textMode(CORNER);
text(score, 10, 60);
}
}
class Bom {
float diam=random(30, 100);
float corB=random(150, 255);
float op=255, diamM=diam;
float dLand;
float inc=0.5;
PVector loc = new PVector(random(diam, width-diam), random(diam, height-diam));
Bom() {
}
void land() {
dLand=dist(loc.x, loc.y, nivel.get(0).nave.get(0).x, nivel.get(0).nave.get(0).y);
if (dLand<diam*0.7) {
diam-=inc;
nivel.get(0).ui.score+=2;
op=map(diam, 0, diamM, 0, 255);
}
}
void desenha() {
noFill();
strokeWeight(2);
stroke(100, 100, corB, op);
line(loc.x, loc.y-diam/5, loc.x, loc.y+diam/5);
line(loc.x-diam/5, loc.y, loc.x+diam/5, loc.y);
ellipse(loc.x, loc.y, diam, diam);
}
}
class Mau {
int moveX=5, moveY=5;
PVector loc, move;
float x, y;
float odd, lado;
float corR=random(150,255), corG=random(0,255);
int type;
int hp;
boolean follow;
Mau() {
odd=random(0, 100); //esolher entre as tres dimensoes de imagends disponiveis, 35*35, 50*50, 75*75
if (odd<20) {
type=1;
lado=35;
hp=10;
} else if (odd>75) {
type=2;
lado=50;
hp=20;
} else {
type=3;
lado=75;
hp=30;
}
loc = new PVector(random(lado, width-lado), random(lado, height-lado));
move = new PVector(random(-moveX, moveX), random(-moveY, moveY));
}
void update() {
if (nivel.get(0).nave.get(0).game) {
if (loc.x<lado/2 || loc.x>width-lado/2)move.x*=-1; //bater esq ou direita e mudar direção
if (loc.y<lado/2 || loc.y> height-lado/2)move.y*=-1; //bater cima ou baixo e mudar direção
loc.set( PVector.add(loc, move));
}
}
void desenha() {
tint(corR,corG,0);
if (type==1)image(mauIm35, loc.x, loc.y);
else if (type==2)image(mauIm50, loc.x, loc.y);
else image(mauIm75, loc.x, loc.y);
}
}
class Menu{
void main(){
}
void setting(){
}
void credits(){
}
void levels(){
}
void gameOver(){
textMode(CENTER);
text("Game Over",width/2,height/2);
}
}
class Nave {
float x=width/2, y=height/2, targetX=width/2, targetY=height/2, dX, dY, speed=10;
float angle;
float shootX, shootY, shootSpeed=10, reload, reloadRef, rel=0.5;
boolean[]k=new boolean[4];//0-w 1-s 2-a 3-d ~ teclas movimento
ArrayList<PVector> shotLocation = new ArrayList<PVector>();
ArrayList<PVector> shotMove = new ArrayList<PVector>();
ArrayList<Float> shotAngle = new ArrayList<Float>();
int moveInc=5;
PVector shoot;
float distShotMau;
int shotDmg=10;
boolean game=true;
void movePressed() {
if (key=='w' || key=='W')k[0]=true;
if (key=='s' || key=='S')k[1]=true;
if (key=='a' || key=='A')k[2]=true;
if (key=='d' || key=='D')k[3]=true;
}
void moveReleased() {
if (key=='w' || key=='W')k[0]=false;
if (key=='s' || key=='S')k[1]=false;
if (key=='a' || key=='A')k[2]=false;
if (key=='d' || key=='D')k[3]=false;
}
void move() {
if (game) {
if (k[0]==true) targetY-=speed;
if (k[1]==true) targetY+=speed;
if (k[2]==true) targetX-=speed;
if (k[3]==true) targetX+=speed;
if (targetX<0)targetX=0; // tocar nas bordas
else if (targetX>width)targetX=width;
if (targetY<0)targetY=0;
else if (targetY>height)targetY=height;
dX=targetX-x;
x+=dX*0.05;
//targetY=mouseY;
dY=targetY-y;
y+=dY*0.05;
if (game) angle = atan2(mouseY - y, mouseX - x); //angulo em relação ao rato
}
}
void shoot() {
reload=frameCount/frameRate-reloadRef; //tempo desde ultimo tiro
if (game) {
if (mousePressed && reload>rel) {
reloadRef=frameCount/frameRate;
tiromp3.play();
shotLocation.add(new PVector(x, y)); //localização inicial = a da nave
shotAngle.add(angle);
shotMove.add(new PVector(shootSpeed*cos(angle), shootSpeed*sin(angle))); //vetor de direção da bala
}
}
}
void update() { //calculos
if (game) {
for (int i=0; i< shotLocation.size(); i++) {
shotLocation.set(i, PVector.add (shotLocation.get(i), shotMove.get(i))); //tiro move-se
if (shotLocation.get(i).x<10 || shotLocation.get(i).x>width+10 || shotLocation.get(i).y<-10 || shotLocation.get(i).y>height+10) { //tiro fora do ecrã
shotLocation.remove(i);
shotAngle.remove(i);
shotMove.remove(i);
}
}
for (int i=0; i< shotLocation.size(); i++) {
for (int j=0; j<nivel.get(0).maus.size(); j++) {
if (shotLocation.size()>i) { //bug resolvido?
distShotMau= shotLocation.get(i).dist (nivel.get(0).maus.get(j).loc); //distancia tiro a mau
if ( distShotMau < nivel.get(0).maus.get(j).lado/2) { //se colidir
shotLocation.remove(i);
shotAngle.remove(i);
shotMove.remove(i);
nivel.get(0).maus.get(j).hp -= shotDmg;
nivel.get(0).ui.score+=3;
}
}
}
}
}
}
void desenha() { //desenho das balas e da nave
tint(255, 255, 255);
imageMode(CENTER);
for (int i=0; i< shotLocation.size(); i++) {
pushMatrix();
translate(shotLocation.get(i).x, shotLocation.get(i).y);
rotate(shotAngle.get(i));
image(tiroIm, 0, 0);
popMatrix();
}
pushMatrix();
translate(x, y);
rotate(angle); // "olhar para o rato"
stroke(255);
fill(0);
image(naveIm, 0, 0);
popMatrix();
}
}
class Nivel {
int mausMax;
float mausCooldown;
int bonsMax;
float bonsCooldown;
ArrayList <Nave> nave = new ArrayList<Nave>();
ArrayList <Mau> maus = new ArrayList<Mau>();
ArrayList <Bom> bons = new ArrayList<Bom>();
float reloadM, reloadB, reloadRefM, reloadRefB;
float dCrash;
UI ui = new UI();
Menu menu = new Menu();
Nivel() {
}
Nivel( int mM, float mC, int bM, float bC) {
this.mausMax=mM;
this.mausCooldown= mC;
this.bonsMax=bM;
this.bonsCooldown= bC;
nave.add(new Nave());
}
void spawns() {
if (nave.get(0).game) {
reloadM=frameCount/frameRate-reloadRefM;
if (reloadM>mausCooldown && maus.size()<mausMax) { //MAUS
reloadRefM=frameCount/frameRate;
maus.add(new Mau());
if (maus.size()>1) {
dCrash=dist(maus.get(maus.size()-1).loc.x, maus.get(maus.size()-1).loc.y, nave.get(0).x, nave.get(0).y);
if (dCrash<maus.get(maus.size()-1).lado*5) maus.remove(maus.size()-1); // se faz spawn muito proximo da nave
}
}
reloadB=frameCount/frameRate-reloadRefB;
if (reloadB-reloadRefB>bonsCooldown && bons.size()<bonsMax) { //BONS
reloadRefB=frameCount/frameRate;
bons.add(new Bom());
}
}
}
void run() {
nave.get(0).move();
nave.get(0).shoot();
nave.get(0).update();
if (bons.size()>0) {
for (int i=0; i<bons.size(); i++) { //loop bons
bons.get(i).land();
bons.get(i).desenha();
if (bons.get(i).diam<=20) {
bons.remove(i);
if (bons.size()==bonsMax-1)reloadRefB=frameCount/frameRate;
}
}
}
if (maus.size()>0) {
for (int i=0; i<maus.size(); i++) { //loop maus morrem
dCrash=dist(maus.get(i).loc.x, maus.get(i).loc.y, nave.get(0).x, nave.get(0).y);
if (maus.get(i).hp<=0) {
ui.score+=maus.get(i).type*20;
maus.remove(i);
reloadRefM=frameCount/frameRate;
continue;
} else if (dCrash<=maus.get(i).lado/2) { //mau crash nave
nave.get(0).game=false;
}
maus.get(i).update();
maus.get(i).desenha();
}
}
nave.get(0).desenha();
if (nave.get(0).game) ui.score();
if (nave.get(0).game==false) {
menu.gameOver();
}
}
}
thank you