No description provided
The showcase player uses a modified version of Processing.js in combination with jsweet to let students program their apps in Java code while still allowing for browser support.
Content created by students is scaled to fit the showcase frame while maintaining aspect ratio and cursor position. This is why some projects may appear blurry in fullscreen, or why some small details may not be visible on a small screen
<iframe width='500px' height='400px' src='https://nest.ktbyte.com/nest#177asteroids_5k_final' allowfullscreen></iframe>
int sc,mn;ArrayList<as> rk;ArrayList<ls> pp;ss mc;boolean sr;boolean up=false;boolean rg=false;boolean lf=false;boolean st=false; void setup(){smooth();size(800,800);frameRate(30);colorMode(HSB);rk=new ArrayList<as>();pp=new ArrayList<ls>();mc=new ss();mc.launch();mn=1; fill(75128255);sr = false;noLoop();} void draw(){background(0);if(mn==1)pg();if(sr==false){ textSize(96);text("ASTEROIDS",124,124);fill(75,255,128);text("ASTEROIDS",132,132);fill(75,255,255);text("ASTEROIDS",128,128); textSize(24);text("Created by Lambert Wang",348,156);fill(120,255,255);text("Instructions:",406,200);text("Up to Accelerate",406,232); text("Left and right to turn",406,264);text("Spacebar to shoot",406,296);text("P to pause",406,328);text("R to restart",406,360);text("Press any key to start the game!",406,392);}} void keyPressed(){gkp();}void keyReleased(){gkr();} void aa(){translate(mc.x+32*cos(mc.a)*mc.v-width/2,mc.y+32*sin(mc.a)*mc.v-height/2); textSize(64);fill(255);text("Game Over",width/2-160,height/2); textSize(32);text("'R' to retry",width/2-160,height/2+32);mn = 3; translate(-32*cos(mc.a)*mc.v-mc.x+width/2,-32*sin(mc.a)*mc.v-mc.y+height/2);noLoop();} class as extends ob{float[] vx=new float[16];float[] vy=new float[16]; as(float tx,float ty,float ta,float tv,float tw,float ts){x=tx;y=ty;a=ta;v=tv;r=0;w=tw;s=ts; for(int i=0;i<16;i++){vx[i]=sin(i*PI/8)*(s+random(-s/4,s/4));vy[i]=cos(i*PI/8)*(s+random(-s/4,s/4));}} void sh(){fill(0);stroke(255);strokeWeight(1);rotate(r);beginShape(); for(int i=0;i<16;i++){vertex(vx[i],vy[i]);}vertex(vx[0],vy[0]);endShape();rotate(-r);} void cl(ob th,int i,int j){if(dist(x,y,th.x,th.y)<s+th.s){sc++;pp.remove(j);if(s>7){ rk.add(new as(x,y,a-PI/8,v*1.6,w*2,s/2));rk.add(new as(x,y,a+PI/8,v*1.6,w*2,s/2));} if(sc%10==0){rk.add(new as(mc.x+random(128,width-128),mc.y+random(128,height-128),random(-PI,PI),random(.4,.8),random(-PI/100,PI/100),32));}rk.remove(i);}}} class ls extends ob{int e;ls(float tx,float ty,float ta){x=tx;y=ty;a=ta;v=10;r=a+PI/2;w=0;s=4;e=0;} void sh(){stroke(0,255,255,255-e*2);strokeWeight(3);rotate(r);line(0,4,0,-4);rotate(-r);} void dissipate(int j){e++;if(e==60)pp.remove(j);}} abstract class ob {float x,y,a,v,r,w,s; void tick(){if(x<0)x+=width;if(x>width)x-=width;if(y<0)y+=height;if(y>height)y-=height; r+=w;x+=cos(a)*v;y+=sin(a)*v;} void sh(){} void ds(){translate(x,y);sh();translate(width,0);sh(); translate(0,height);sh();translate(-width,0);sh();translate(-width,0);sh();translate(0,-height);sh(); translate(0,-height);sh();translate(width,0);sh();translate(width,0);sh();translate(-width-x,height-y);}} void pg(){strokeWeight(1);stroke(75,64,128); for(int i=-8;i<height/32+8;i++){ line(-32,i*32-(mc.y%32)-32*sin(mc.a)*mc.v, width+32,i*32-(mc.y%32)-32*sin(mc.a)*mc.v);} for(int i=-8;i<width/32+8;i++){ line(i*32-(mc.x%32)-32*cos(mc.a)*mc.v,-32, i*32-(mc.x%32)-32*cos(mc.a)*mc.v,height+32);} translate(-mc.x+width/2-32*cos(mc.a)*mc.v,-mc.y+height/2-32*sin(mc.a)*mc.v);mc.ds();translate(mc.x,mc.y); mc.tick();translate(-mc.x,-mc.y);for(int j=0;j<pp.size();j++){ls p=pp.get(j);p.dissipate(j);p.ds();p.tick();} for(int i=0;i<rk.size();i++){as ro=rk.get(i);ro.ds();ro.tick(); for(int j=0;j<pp.size();j++){ls pew=pp.get(j);ro.cl(pew,i,j);}} for(int i=0;i<rk.size();i++){as rock=rk.get(i);if(dist(rock.x,rock.y,mc.x,mc.y)<rock.s+mc.s){aa();}} translate(mc.x+32*cos(mc.a)*mc.v-width/2,mc.y+32*sin(mc.a)*mc.v-height/2); textSize(32);fill(150,255,255);text("Score:"+sc,8,32);if(mc.d>0)mc.d--; if(up==true)mc.ac();if(lf==true)mc.r-=0.1;if(rg==true)mc.r+=0.1;if(st==true)mc.shoot();mc.v*=0.96;} void gkp(){if(sr==false){loop();sr=true;} if(key==CODED){if(keyCode==UP)up=true;if(keyCode==LEFT)lf=true;if(keyCode==RIGHT)rg=true;}if(key==' ')st=true; if(key=='r'){mc.launch();mn=1;loop();} if(key=='p'){if(mn==1){textSize(64);fill(255);text("PAUSED",width/2-160,height/2-64); textSize(32);text("'P' to unpause",width/2-160,height/2-32);mn=2;noLoop();} else{if(mn==2){mn=1;loop();}}}} void gkr(){if(key==CODED){ if(keyCode==UP)up=false;if(keyCode==LEFT)lf=false;if(keyCode==RIGHT)rg=false;}if(key==' ')st=false;} class ss extends ob{ int d,p,q;ss(){launch();} void launch(){loop(); x=width/2;y=height/2; a=0;v=0;r=0;w=0;s=12; rk.clear();pp.clear();sc=0; up=false;rg=false;lf=false;st=false; rk.add(new as(random(0,width),0,random(-PI,PI),random(0.4,0.8),random(-PI/100,PI/100),32)); rk.add(new as(random(0,width),height,random(-PI,PI),random(0.4,0.8),random(-PI/100,PI/100),32)); rk.add(new as(0,random(0,height),random(-PI,PI),random(0.4,0.8),random(-PI/100,PI/100),32)); rk.add(new as(width,random(0,height),random(-PI,PI),random(0.4,0.8),random(-PI/100,PI/100),32));} void sh(){fill(0);stroke(75,255,255);strokeWeight(1);rotate(r); beginShape();vertex(0,16);vertex(8,-16);vertex(-8,-16);vertex(0,16);endShape();rotate(-r);} void ac(){float xt = cos(a)*v+cos(r+PI/2)*.2;float yt = sin(a)*v+sin(r+PI/2)*.2; v=sqrt(sq(yt)+sq(xt));a=atan2(yt,xt);} void shoot(){if (d == 0){pp.add(new ls(x,y,r+PI/2+random(-PI/32,PI/32)));d = 6;}}}