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#98491' allowfullscreen></iframe>
public int boxx = 1000; public int boxy = 800; public int framerate = 60; public int blackhole = 1000; public float blackholeF = 2; public PVector anchor, anchordist; public int distnet = 50; //constant public float an128 = PI/128; public float an64 = PI/64; public float an32 = PI/32; public float an16 = PI/16; public float an08 = PI/8; public float an04 = PI/4; //class public me moe; public background0 bg; public monsters_system mss; public int scrood; public boolean over; void setup() { size(800, 600); frameRate(framerate); initeverything(); } void initeverything() { init_keyengine(); moe = new me(); bg = new background0(); mss = new monsters_system(); findanchor(); scrood = 0; over = false; } void draw() { background(20); if (!over) { bg.show(); key_engine(); moe.update(); moe.show(); moe.init_update(); mss.update(); GUI(); if (moe.blood<=0) { over = true; } } else { initeverything(); } } void GUI() { findanchor(); boder(); fill(230); textSize(20); text("frameRate : " + int(frameRate), 30, 30); fill(30, 200, 120); if (!firstpressed) { textSize(15); text("wasd to move,ULDR to shoot", width*0.25, height*0.3); } textSize(30); fill(230, 50, 0); text("SCROOD : "+scrood, width*0.4, 50); textSize(20); fill(20, 50, 200); text("blood : "+moe.blood, width*0.2, 50); } void boder() { stroke(255); strokeWeight(1); line(0+anchordist.x, 0+anchordist.y, boxx+anchordist.x, 0+anchordist.y); line(0+anchordist.x, 0+anchordist.y, 0+anchordist.x, boxy+anchordist.y); line(0+anchordist.x, boxy+anchordist.y, boxx+anchordist.x, boxy+anchordist.y); line(boxx+anchordist.x, 0+anchordist.y, boxx+anchordist.x, boxy+anchordist.y); } ///// class background0 { net_particleSystem nps; star st; bullet_die_particle bds; background0() { bds = new bullet_die_particle (); st = new star(200); nps = new net_particleSystem(0.05, 0.96); nps.createMap(distnet, distnet); } void show() { noStroke(); fill(230); st.update(); nps.update(); bds.update(); } } ///// class bullet_die_particle { ArrayList<bullet_die> bdp = new ArrayList<bullet_die>(); float borndist = an16; float velnum = 8; float umbrellaAngle = PI*0.6; int totaladd = 0; bullet_die_particle() { } void addbdp(PVector loc, PVector vel, color c, boolean isDieboder, boolean R, boolean L, boolean U, boolean D) { totaladd++; float angleB; float angleE; if (isDieboder) { angleB = 0; angleE = TWO_PI; if (U) { angleB = 0; angleE = PI; } else { if (D) { angleB = PI; angleE = TWO_PI; } } if (R) { angleB = HALF_PI; angleE = HALF_PI*3; if (U) { angleE = PI; } if (D) { angleB = PI; } } else { if (L) { angleB = -HALF_PI; angleE = HALF_PI; if (U) { angleB = 0; } else { if (D) { angleE = 0; } } } } } else { float angle = atan2(vel.y, vel.x); if (angle>=umbrellaAngle||angle<=-umbrellaAngle) { angle+=TWO_PI; } angleB = angle-umbrellaAngle/2; angleE = angle+umbrellaAngle/2; } for (float i = angleB; i<=angleE; i+=borndist) { bdp.add(new bullet_die(new PVector(loc.x, loc.y), new PVector(cos(i)*velnum, sin(i)*velnum), c)); } } void update() { for (int i = 0; i<bdp.size(); i++) { bullet_die bdt = bdp.get(i); bdt.update(); bdt.show(); if (bdt.isDie) { bdp.remove(i); } } textSize(10); text("bulletDie : "+totaladd, 30, 60); text("bulletDieparticels : "+bdp.size(), 30, 80); } } class bullet_die extends particleWithoutAcc { bullet_die(PVector loc, PVector vel, color c) { this.loc = new PVector(loc.x, loc.y); this.vel = new PVector(vel.x, vel.y); setcolor(c); setlife(int(framerate*1)); setrad(3); } void show() { if (!outboder(loc, rad/2)) { pushMatrix(); translate(loc.x+anchordist.x, loc.y+anchordist.y); rotate(atan2(-vel.y, -vel.x)); strokeWeight(rad*map(age, 0, life, 1, 0.5)); stroke(c); line(-8*map(age, 0, life, 1, 0), 0, 0, 0); popMatrix(); } } } //// class net_particle { float maxspeed; PVector loc, vel, acc, force, target; float ms, damp; boolean lowspeedstop = false; float lowspeeddamp = 0.9; net_particle(PVector loc0, float ms, float damp) { loc = new PVector(); vel = new PVector(); acc = new PVector(); force = new PVector(); target = new PVector(); maxspeed = 18; setloc(loc0); //setvel(new PVector(random(-2, 2), random(-2, 2))); setTarget(new PVector(loc.x, loc.y)); this.ms = ms; this.damp = damp; } void setTarget(PVector target) { this.target = new PVector(target.x, target.y); } void setmaxspeed(float maxspeed) { this.maxspeed = maxspeed; } void setvel(PVector vel0) { vel = new PVector(vel0.x, vel0.y); } void setloc(PVector loc0) { loc = new PVector(loc0.x, loc0.y); } void setForce(PVector force) { this.force = new PVector(force.x, force.y); } void addYForce(PVector newForce) { this.force.add(newForce); } void addCForce(PVector newForce) { newForce.mult(-1); this.force.add(newForce); } void cauacc() { cauEasing(); force.mult(ms); acc = new PVector(force.x, force.y); force = new PVector(0, 0); } void cauEasing() { PVector tempForce = new PVector(target.x-loc.x, target.y-loc.y); addYForce(tempForce); } void setlowspeeddamp(float da) { lowspeeddamp = da; } void maxVel() { //vel.limit(maxspeed); if (!lowspeedstop) { float k = vel.mag(); if (k > 0.7) { vel.mult(damp); } else { vel.mult(lowspeeddamp); } } else { if (vel.mag() > 0.7) { vel.mult(damp); } if (vel.mag()<=0.2&&PVector.dist(target, loc)<=5) { PVector tempForce = new PVector(target.x-loc.x, target.y-loc.y); tempForce.normalize(); vel.mult(lowspeeddamp); //addYForce(tempForce); } } } void update() { cauacc(); //print(acc.x); vel.add(acc); maxVel(); loc.add(vel); acc = new PVector(0, 0); } void show() { noStroke(); ellipse(loc.x+anchordist.x, loc.y+anchordist.y, 3, 3); } } class net_particleSystem { ArrayList <net_particle>ps = new ArrayList<net_particle>(); float ms; float damp; PVector mousenow; int xn, yn; int netdistx, netdisty; net_particleSystem(float ms, float damp) { this.ms = ms; this.damp = damp; } void createMap(int distx, int disty) { xn = floor(boxx/distx); yn = floor(boxy/disty); for (int i = 0; i<= yn; i++) { for ( int j = 0; j <= xn; j++) { addP(new PVector(j*distx, i*disty)); } } netdistx = distx; netdisty = disty; } void addP(PVector loc0, float ms, float damp) { ps.add(new net_particle(loc0, ms, damp)); } void addP(PVector loc0) { ps.add(new net_particle(loc0, ms, damp)); } void killP(int i) { if (i<=ps.size()) { ps.remove(i); } } void update() { for (int i = 0; i <ps.size(); i++) { net_particle pt = ps.get(i); float disting = PVector.dist(pt.loc, moe.loc); if (disting<= 80) { PVector chili = new PVector(moe.loc.x-pt.loc.x, moe.loc.y-pt.loc.y); chili.normalize(); chili.mult(8); pt.addCForce(new PVector(chili.x, chili.y)); } pt.update(); stroke(40, 230, 100); strokeWeight(2); if (i>0) { if (i>xn) { line(pt.loc.x+anchordist.x, pt.loc.y+anchordist.y, ps.get(i-xn-1).loc.x+anchordist.x, ps.get(i-xn-1).loc.y+anchordist.y); } if (i%(xn+1)!=0) { line(pt.loc.x+anchordist.x, pt.loc.y+anchordist.y, ps.get(i-1).loc.x+anchordist.x, ps.get(i-1).loc.y+anchordist.y); } } //text(i,pt.loc.x+anchordist.x+netdistx/2-5, pt.loc.y+anchordist.y+netdisty/2+5); } } } ///// class star { int num_star; float[] bgptx; float[] bgpty; star(int num) { bgptx = new float[num]; bgpty = new float[num]; num_star = num; for (int i = 0; i<num_star; i++) { bgptx[i] = random(-width*0.4, boxx+width*0.4); bgpty[i] = random(-height*0.4, boxy+height*0.4); } } void update() { for (int i = 0; i<num_star; i++) { ellipse(bgptx[i]+anchordist.x, bgpty[i]+anchordist.y, 3, 3); } } } ///// class bullets { ArrayList <bullet_normal> bn = new ArrayList <bullet_normal>(); //ArrayList <bulletbase> bf = new ArrayList <bulletbase>(); fellow target //ArrayList <bulletbase> btl = new ArrayList <bulletbase>(); bullet tangle right :tangle wiht left //ArrayList <bulletbase> btr = new ArrayList <bulletbase>(); bullets() { } void update() { strokeCap(PROJECT); for (int i = 0; i<bn.size(); i++) { bullet_normal bt = bn.get(i); bt.update(); bt.show(); if (bt.isDie) { bg.bds.addbdp(bt.loc, bt.vel, bt.c, bt.outboder, bt.RD, bt.LD, bt.UD, bt.DD); bn.remove(i); } } } void addbs(PVector loc, PVector vel, int mod, boolean powerup) { switch(mod) { case 0: addbn(loc, vel, powerup); return; } } void addbn(PVector loc, PVector vel, boolean powerup) { int num = 2; float angle = atan2(vel.y, vel.x); if (powerup) { num*=2; } angle -= an64*(num-1); for (int i = num; i>0; i--) { float x = cos(angle); float y = sin(angle); bn.add(new bullet_normal(new PVector(loc.x+x*moe.r, loc.y+y*moe.r), new PVector(x, y))); angle+=an32; } } } ///// class bullet_base { PVector loc, vel, acc; PVector target; PVector force, sysforce; //state boolean isDie = false; boolean UD, LD, RD, DD; boolean outboder = false; boolean istarget = false; boolean damping = false; float rad; //constant int velborn; float ms; float damp; float maxvel; float tagaccN; //show mod color c; void setrad(float ra) { rad = ra; } void settarget(PVector tg) { target = tg; istarget = true; } void setdamp(float da) { damp = da; } void setms(float ms) { this.ms = ms; } void settagaccN(float N) { tagaccN = N; } void setcolor(color c0) { c = c0; } void addforce(PVector fc) { force.add(fc); } void addsystemforce(PVector sfc) { //out the max vel sysforce.add(sfc); } void addsystemtarget(PVector systg) {//more close ,the force would be bigget float disttg = PVector.dist(loc, systg); PVector sysft = new PVector(systg.x-loc.x, systg.y-loc.y); sysft.normalize(); sysft.mult(ms); if (disttg<=blackhole) { if (disttg<=blackhole*0.6) { sysft.mult(blackholeF); } else { sysft.mult(blackholeF*1.6); } } else { sysft.mult(blackholeF*0.6); } sysforce.add(sysft); } void update() { cauacc(); cauvel(); cauloc(); reset(); } void reset() { sysforce = new PVector(0, 0); acc = new PVector(0, 0); force = new PVector(0, 0); } void cauacc() { if (istarget) { PVector tf = new PVector(target.x-loc.x, target.y-loc.y); tf.normalize(); tf.mult(tagaccN); } force.mult(ms); acc.add(force); } void cauvel() {//sysforce next limit vel vel.add(acc); //vel.limit(maxvel); vel.add(causysacc()); } PVector causysacc() { sysforce.mult(ms); return sysforce; } void cauloc() { loc.add(vel); if (loc.x>=boxx-rad/2) { isDie = true; RD = true; outboder = true; } else { if (loc.x<=rad/2) { isDie = true; LD = true; outboder = true; } } if (loc.y>=boxy-rad/2) { isDie = true; DD = true; outboder = true; } else { if (loc.y<rad/2) { isDie = true; UD = true; outboder = true; } } } } ///// class bullet_normal extends bullet_base { bullet_normal(PVector loc, PVector vel) { init_normal(); this.loc = new PVector(loc.x, loc.y); this.vel = new PVector(vel.x, vel.y); this.vel.normalize(); this.vel.mult(velborn); acc = new PVector(0, 0); target = new PVector(0, 0); force = new PVector(0, 0); sysforce = new PVector(0, 0); } void init_normal() { velborn = 16; ms = 0.5; damp = 0.99; maxvel = 20; tagaccN = 1; setcolor(color(250, 120, 0)); setrad(10); } void show() { if (!outboder) { pushMatrix(); translate(loc.x+anchordist.x, loc.y+anchordist.y); rotate(atan2(-vel.y, -vel.x)); strokeWeight(rad); stroke(c); line(-10, 0, 0, 0); popMatrix(); return; } } } //// class powerfire { ArrayList<onefire> fire; powerfire() { fire = new ArrayList<onefire>(); } void update() { rectMode(CENTER); noStroke(); for (int i =0; i<fire.size(); i++) { onefire ft = fire.get(i); if (ft.timer()) { fire.remove(i); } else { ft.update(); ft.show(); } } } void addfire(PVector loc, PVector vel, boolean powerup) { vel.normalize(); for (int i = 20; i>0; i--) { fire.add(new onefire(new PVector(loc.x, loc.y), new PVector(vel.x, vel.y), powerup)); } } } ///// class onefire { //constant int normallife = int(framerate*0.1); int shortlife = int(framerate*0.075); int lonelife = int(framerate*0.15); float velborn = 4; float damp = 0.97; float dampr = 0.98; //move PVector vel, loc; color c; color c1 = color(190, 120, 120); color c2 = color(190, 64, 45); color c3 = color(10, 64, 145); float r = random(7, 8); int dieline; onefire(PVector loc0, PVector vel0, boolean powerup) { loc = new PVector(loc0.x, loc0.y); float anc; if (powerup) { anc = random(-an08, an08); velborn*=1.5; } else { anc = random(-an16, an16); } vel = new PVector(vel0.x, vel0.y); vel.normalize(); vel = rotateangle(new PVector(vel.x, vel.y), anc); vel.mult(velborn); if (powerup) { float absanc = abs(anc); if (absanc>an32) { dieline = normallife+int(random(-10, 10)); c = c2; if (absanc>an16) { dieline = shortlife+int(random(-10, 10)); r*=0.6; c = c3; } } else { dieline = lonelife+int(random(-10, 10)); c = c1; r*=1.4; } } else { float absanc = abs(anc); if (absanc>an64) { dieline = normallife+int(random(-10, 10)); c = c2; if (absanc>an32) { dieline = shortlife+int(random(-10, 10)); c = c3; } } else { dieline = lonelife+int(random(-10, 10)); c = c1; } } } void update() { vel.mult(damp); loc.add(vel); } boolean timer() { dieline-=1; if (dieline<=0) { return true; } r*=dampr; if (r<=0.5) { return true; } return false; } void show() { fill(c); rect(loc.x+anchordist.x, loc.y+anchordist.y, r, r); } } ///// public boolean shootR; public boolean shootL; public boolean shootU; public boolean shootD; public boolean moveR; public boolean moveL; public boolean moveU; public boolean moveD; public boolean firstpressed = false; boolean isPause; boolean lastshoot = false; int timer_notshoot; int timer_shoot; int shootdist = framerate/6; int maxnotshoot = shootdist; public void init_keyengine() { shootR = false; shootL = false; shootU = false; shootD = false; moveR = false; moveL = false; moveU = false; moveD = false; isPause = false; } public void key_engine() { timer(); moe.setmove(setRLUD(moveR, moveL, moveU, moveD)); if (timer_shoot>=shootdist) { moe.setfire(setRLUD(shootR, shootL, shootU, shootD)); timer_notshoot = 0; timer_shoot = 0; } } void timer() { if (!shootR&&!shootL&&!shootU&&!shootD) { if (timer_notshoot<maxnotshoot) { timer_notshoot++; } if (lastshoot) { timer_notshoot +=timer_shoot; timer_shoot = 0; } lastshoot = true; } else { if (timer_shoot<shootdist) { timer_shoot++; } if (lastshoot) { timer_shoot += timer_notshoot; timer_notshoot = 0; } lastshoot = false; } //fill(230); //text("not shoot:"+timer_notshoot,30,height-50); //text("shoot:"+timer_shoot,30,height-30); } public void keyPressed() { firstpressed = true; if (key !=CODED) { if (keyCode == 'a'||keyCode == 'A') { moveL = true; } if (keyCode == 's'||keyCode == 'S') { moveD = true; } if (keyCode == 'D'||keyCode == 'D') { moveR = true; } if (keyCode == 'W'||keyCode == 'W') { moveU = true; } if (keyCode == 'p'||keyCode == 'P') { if (isPause) { isPause = false; loop(); } else { isPause = true; noLoop(); } } } else { switch(keyCode) { case UP: shootU = true; return; case DOWN: shootD = true; return; case LEFT: shootL = true; return; case RIGHT: shootR = true; return; } } } public void keyReleased() { if (key !=CODED) { if (keyCode == 'a'||keyCode == 'A') { moveL = false; } if (keyCode == 's'||keyCode == 'S') { moveD = false; } if (keyCode == 'D'||keyCode == 'D') { moveR = false; } if (keyCode == 'W'||keyCode == 'W') { moveU = false; } } else { switch(keyCode) { case UP: shootU = false; return; case DOWN: shootD = false; return; case LEFT: shootL = false; return; case RIGHT: shootR = false; return; } } } ///// class monsters_system { int msDistBox = 40; int ms0DistMoe = 150; ArrayList <monster_easing> M0 = new ArrayList<monster_easing>();//easing to moe int m0borntimer; int m0borndist = 3*framerate; ArrayList <monster_splite> M1 = new ArrayList<monster_splite>();//trigonometric with loc int m1borntimer; int m1borndist = 5*framerate; ArrayList <monster_normal> M2 = new ArrayList<monster_normal>(); int m2borntimer; int m2borndist = int(0.5*framerate); monsters_system() { init_timer(); } void init_timer() { m0borntimer = 0; m1borntimer = 0; m2borntimer = m1borndist; } void timer() { m0borntimer++; if (m0borntimer >= m0borndist) { addm0(1); m0borntimer = 0; } m1borntimer++; if (m1borntimer >= m1borndist) { addm1(1); m1borntimer = 0; } m2borntimer++; if (m2borntimer >= m2borndist) { addm2(1); m2borntimer = 0; } } void update() { for (int i = 0; i<M0.size(); i++) { monster_easing m0t = M0.get(i); m0t.update0(); m0t.update(); if (m0t.isDie) { M0.remove(i); scrood+=5; } m0t.show(); } for (int i = 0; i<M1.size(); i++) { monster_splite m1t = M1.get(i); m1t.update0(); m1t.update(); if (m1t.isDie) { M1.remove(i); scrood+=10; } m1t.show(); } for (int i = 0; i<M2.size(); i++) { monster_normal m2t = M2.get(i); m2t.update0(); m2t.update(); if (m2t.isDie) { M2.remove(i); scrood+=30; } m2t.show(); } timer(); } void addm0(int i) {//could code be better if (M0.size()<20) { for (int c = 0; c<i; c++) { float angle = random(-PI, PI); float disting = random(300, 1000); float btx = disting*cos(angle)+moe.loc.x; float bty = disting*sin(angle)+moe.loc.y; btx = range(btx, ms0DistMoe, boxx-ms0DistMoe); bty = range(bty, ms0DistMoe, boxy-ms0DistMoe); M0.add(new monster_easing(new PVector(btx, bty))); } } } void addm1(int i) {//could code be better if (M1.size()<5) { for (int c = 0; c<i; c++) { float angle = random(-PI, PI); float disting = random(300, 1000); float btx = disting*cos(angle)+moe.loc.x; float bty = disting*sin(angle)+moe.loc.y; btx = range(btx, ms0DistMoe, boxx-ms0DistMoe); bty = range(bty, ms0DistMoe, boxy-ms0DistMoe); M1.add(new monster_splite(new PVector(btx, bty))); } } } void addm2(int i) {//could code be better if (M2.size()<10) { for (int c = 0; c<i; c++) { float angle = random(-PI, PI); float disting = random(300, 1000); float btx = disting*cos(angle)+moe.loc.x; float bty = disting*sin(angle)+moe.loc.y; btx = range(btx, ms0DistMoe, boxx-ms0DistMoe); bty = range(bty, ms0DistMoe, boxy-ms0DistMoe); M2.add(new monster_normal(new PVector(btx, bty))); } } } } ///// class monster { PVector loc, vel, acc; PVector target, force, sysforce; float ms; float velmax; float rad = 0; int radmax= 30; float numaccN; float bornneed; float borntime; color c; boolean isDie = false; void setradmax(int ra) { radmax = ra; } void setloc(PVector lo) { loc = new PVector(lo.x, lo.y); } void setacc(PVector ac) { acc = new PVector(ac.x, ac.y); } void setborntime(float bt) { bornneed = bt; borntime = bornneed; } void setvel(PVector ve) { vel = new PVector(ve.x, ve.y); } void setvelmax(float max) { velmax = max; } void setnumaccN(float n) { numaccN = n; } void settarget(PVector ta) { target = new PVector(ta.x, ta.y); } void setms(float ms) { this.ms = ms; } void addforce(PVector fc) { force.add(fc); } void addsysforce(PVector sysfc) { sysforce.add(sysfc); } void cauacc() { PVector ft = new PVector(target.x-loc.x, target.y-loc.y); ft.normalize(); ft.mult(numaccN); acc.add(force); acc.add(ft); } void cauvel() { vel.add(acc); vel.limit(velmax); vel.add(sysforce); float vx = vel.x; float vy = vel.y; if (loc.x<rad||loc.x>boxx-rad) { vx *= -1; } if (loc.y<rad||loc.y>boxy-rad) { vy *= -1; } vel = new PVector(vx, vy); } void cauloc() {//coule never go out loc.add(vel); } void update() { settarget(moe.loc); if (borntime>0) { borntime--; rad +=radmax/bornneed; } else { cauacc(); cauvel(); cauloc(); } init_update(); } void init_update() { acc = new PVector(); force = new PVector(); sysforce = new PVector(); } } ///// class monster_easing extends monster { PVector toc; monster_easing(PVector loc) { this.loc = new PVector(loc.x, loc.y); vel = new PVector(); acc = new PVector(); target = new PVector(); force = new PVector(); sysforce = new PVector(); init_monster(); init_easing(); } void init_monster() { setvelmax(8); setnumaccN(0.1); setms(1); setvel(new PVector(random(-2, 2), random(-2, 2))); setborntime(framerate*2); setradmax(30); c = color (30, 230, 30); } void init_easing() { toc = new PVector (loc.x, loc.y); } void update0() { toc = new PVector (loc.x, loc.y); chick(); } void chick() { if (PVector.dist(toc, moe.loc)<=moe.r/2+rad/2) { moe.blood-=1; } int i = 0; while (!isDie&&i<moe.bs.bn.size()) { if (PVector.dist(toc, moe.bs.bn.get(i).loc)<=moe.bs.bn.get(i).rad/2+rad/2) { moe.bs.bn.get(i).isDie = true; isDie = true; } i++; } } void show() { noFill(); strokeWeight(4); stroke(c); pushMatrix(); translate(loc.x+anchordist.x, loc.y+anchordist.y); if (borntime>0) { borntime--; rad+=radmax/bornneed; } ellipse(0, 0, rad, rad); popMatrix(); } } ///// class blackhole { PVector loc; int blood = 20; float power; float rad = 60; blackhole(PVector loc) { this.loc = new PVector(loc.x, loc.y); } void show() { fill(250); ellipse(loc.x+anchordist.x, loc.y+anchordist.y, rad, rad); noFill(); stroke(230, 80); stroke(10); ellipse(loc.x+anchordist.x, loc.y+anchordist.y, rad+5, rad+5); } } // class monster_normal extends monster { PVector toc; float bo; monster_normal(PVector loc) { this.loc = new PVector(loc.x, loc.y); vel = new PVector(); acc = new PVector(); target = new PVector(); force = new PVector(); sysforce = new PVector(); init_monster(); init_easing(); } void init_monster() { setvelmax(2); setnumaccN(2); setms(1); setborntime(framerate*2); setradmax(30); c = color (#3399cc); } void init_easing() { toc = new PVector (loc.x, loc.y); bo = 0; } void update0() { toc = new PVector (loc.x, loc.y); bo+=an128; chick(); } void show() { noFill(); strokeWeight(4); stroke(c); pushMatrix(); translate(loc.x+anchordist.x, loc.y+anchordist.y); rotate(HALF_PI); if (borntime>0) { borntime--; rad+=radmax/bornneed; } rhombus(0, 0, rad*0.4*(abs(cos(bo))+3), rad*0.3*(abs(cos(bo))+3)); popMatrix(); } void chick() { if (PVector.dist(toc, moe.loc)<=moe.r/2+rad/2) { moe.blood-=1; } int i = 0; while (!isDie&&i<moe.bs.bn.size()) { if (PVector.dist(toc, moe.bs.bn.get(i).loc)<=moe.bs.bn.get(i).rad/2+rad/2) { moe.bs.bn.get(i).isDie = true; isDie = true; } i++; } } } ///// class monster_splite extends monster { PVector toc; PVector floatmoving; float angle, moveangle; float rotateangle = an32; float floatmove = 50; boolean LOR; //int timertocToloc = 0; // float tocToloctime = framerate*3; monster_splite(PVector loc) { this.loc = new PVector(loc.x, loc.y); vel = new PVector(); acc = new PVector(); target = new PVector(); force = new PVector(); sysforce = new PVector(); init_monster(); init_easing(); } void init_monster() { setvelmax(3); setnumaccN(0.1); setms(1); //setvel(new PVector(random(-2, 2), random(-2, 2))); setborntime(framerate*2); setradmax(15); c = color (125, 0, 230); } void init_easing() { angle = 0; moveangle = random(-PI, PI); LOR = (random(0, 1)>0.5)?true:false; if (LOR) { rotateangle *=-1; } floatmoving = new PVector(cos(angle), sin(angle)); toc = new PVector(cos(angle)*floatmove+loc.x, sin(angle)*floatmove+loc.y); } void update0() { if (borntime<=0) { angle+=rotateangle*2; moveangle+=rotateangle; } toc = new PVector(cos(moveangle)*floatmove+loc.x, sin(moveangle)*floatmove+loc.y); /*timertocToloc++; if(timertocToloc>=tocToloctime){ setloc(toc); timertocToloc = 0; }*/ chick(); } void show() { noFill(); strokeWeight(4); stroke(c); pushMatrix(); translate(toc.x+anchordist.x, toc.y+anchordist.y); rotate(angle); if (borntime>0) { borntime--; rad+=radmax/bornneed; } for (int i = 0; i<4; i++) { rotate(HALF_PI*i); triangle(0, 0, 1*rad, 1*rad, 0, 1.41*rad); } popMatrix(); } void chick() { if (PVector.dist(toc, moe.loc)<=moe.r/2+rad/2) { moe.blood-=1; } int i = 0; while (!isDie&&i<moe.bs.bn.size()) { if (PVector.dist(toc, moe.bs.bn.get(i).loc)<=moe.bs.bn.get(i).rad/2+rad/2) { moe.bs.bn.get(i).isDie = true; isDie = true; } i++; } } } ///// public PVector setRLUD(boolean R, boolean L, boolean U, boolean D) { PVector tp = new PVector(0, 0); if (R) { tp.add(new PVector(1, 0)); } if (L) { tp.add(new PVector(-1, 0)); } if (U) { tp.add(new PVector(0, -1)); } if (D) { tp.add(new PVector(0, 1)); } return tp; } public PVector rotateangle(PVector angle, float cy) { float an = atan2(angle.y, angle.x); an += cy; PVector c = new PVector(cos(an), sin(an)); return c; } public void findanchor() { float ax = map(moe.loc.x, moe.r/2, boxx-moe.r/2, 0.6*0.5*width, width*(1-0.6*0.5)); float ay = map(moe.loc.y, moe.r/2, boxy-moe.r/2, 0.6*0.5*height, height*(1-0.6*0.5)); anchor = new PVector(ax, ay); anchordist = new PVector(ax-moe.loc.x, ay-moe.loc.y); } public void setanchor() { float ax = map(boxx/2, moe.r/2, boxx-moe.r/2, 0.6*0.5*width, width*(1-0.6*0.5)); float ay = map(boxy/2, moe.r/2, boxy-moe.r/2, 0.6*0.5*height, height*(1-0.6*0.5)); anchor = new PVector(ax, ay); anchordist = new PVector(ax-moe.loc.x, ay-moe.loc.y); } public float range(float c, float min, float max) { c = (c>min)?c:min; c = (c<max)?c:max; return c; } public void rhombus(float x, float y, float xz, float yz) {//rect would more easy to cau phy quad(x-xz/2, y, x, y+yz/2, x+xz/2, y, x, y-yz/2); } public void vector(PVector loc, PVector ang, color c, float scale) { fill(c); strokeWeight(13); pushMatrix(); translate(loc.x, loc.y); rotate(atan2(ang.y, ang.x)); line(0, 0, 4*scale, 0); line(4*scale, 0, 3*scale, -1*scale); line(4*scale, 0, 3*scale, 1*scale); popMatrix(); } public boolean outboder(PVector loc, float dist) { if (loc.x>boxx-dist||loc.x<=dist||loc.y>=boxy-dist||loc.y<=dist) { return true; } else { return false; } } ///// class particleWithoutAcc { PVector loc, vel; color c; int life; int age; float rad; boolean isDie; /*particleWithoutAcc(PVector loc,PVector vel){ this.loc = new PVector(loc.x,loc.y); this.vel = new PVector(vel.x,vel.y); age = 0; isDie = false; }*/ void setlife(int life) { this.life = life; } void update() { loc.add(vel); age++; if (age>=life) { isDie = true; } } void setrad(float rad) { this.rad = rad; } void setcolor(color c) { this.c = c; } } /// class me { //constant move int accmove0 = 1; int accmove1 = 2; float forcemax = 5; int velmax = 8; //move PVector loc, vel, acc, keyacc; PVector force; PVector powera; PVector poweraL; float damp = 0.9; float mass = 0.1; float forceangle; float forceangleN; int accmove; boolean power; boolean powerup; //constant state int bloodmax = 1; int energymax = 100; int shieldmax = 100; //state boolean isDie = false; boolean isShoot = false; int shootLevel = 0; int blood; int energy; int shield; int r = 40; //classs powerfire pfire; bullets bs; void init_move() { loc = new PVector(boxx/2, boxy/2); vel = new PVector(0, 0); acc = new PVector(0, 0); keyacc = new PVector(0, 0); force = new PVector(0, 0); powera = new PVector(0, 0); poweraL = new PVector(0, -1); accmove = accmove0; forceangle = 0; forceangleN = forceangle; power = false; powerup = false; } void init_state() { isDie = false; isShoot = false; shootLevel = 0; blood = bloodmax; energy = energymax; shield = shieldmax; } void addtagc(PVector tagc) { PVector c = new PVector(loc.x-tagc.x, loc.y-tagc.y); c.limit(forcemax); force.add(c); } void addtagy(PVector tagc) {//close and small PVector c = new PVector(tagc.x-loc.x, tagc.y-loc.y); c.limit(forcemax); force.add(c); } void addforce(PVector forc) { force.add(forc); } me() { init_class(); init_move(); init_state(); } void init_class() { pfire = new powerfire(); bs = new bullets(); } void easingangle() { float an = an16; float TD = forceangle - forceangleN; if (TD>=TWO_PI) { TD-=TWO_PI; } if (TD<=-TWO_PI) { TD+=TWO_PI; } if (TD<an&&TD>-an) { forceangleN = forceangle; } else { if (TD>=an) { if (TD>=PI) { forceangleN-=an; } else { forceangleN+=an; } } else { if (TD<-PI) { if (TD == -PI) { forceangleN-=an; } else { forceangleN+=an; } } else { forceangleN-=an; } } } //println(forceangleN); if (forceangleN>=TWO_PI) { forceangleN-=TWO_PI; } if (forceangleN<=-TWO_PI) { forceangleN+=TWO_PI; } } void update() { meupdate(); pfire.update(); bs.update(); } void meupdate() { easingangle(); if (!power) { vel.mult(damp); } else { vel.add(keyacc); vel.limit(velmax); powerengine(); } vel.add(acc); loc.add(vel); cannotoutboder(); } void cauacc() { force.mult(mass); acc.add(force); } void cannotoutboder() { float x = range(loc.x, r/2, boxx-r/2); float y = range(loc.y, r/2, boxy-r/2); loc = new PVector(x, y); } void powerengine() { pfire.addfire(new PVector(loc.x, loc.y), new PVector(-cos(forceangleN-HALF_PI), -sin(forceangleN-HALF_PI)), powerup); } void init_update() { force = new PVector(0, 0); acc = new PVector(0, 0); keyacc = new PVector(0, 0); poweraL = new PVector(powera.x, powera.y); } void setmove(PVector tempacc) { if (tempacc.x == 0&&tempacc.y == 0) { power = false; } else { forceangle = atan2(-tempacc.y, -tempacc.x)-HALF_PI; powera = new PVector(tempacc.x, tempacc.y); tempacc.mult(accmove); keyacc.add(tempacc); power = true; } } void setfire(PVector tempacc) { if (tempacc.x==0&&tempacc.y==0) { isShoot = false; } else { bs.addbs(loc, tempacc, 0, powerup) ; isShoot = true; } } void show1() { ellipse(loc.x, loc.y, 20, 20); } void show() { pushMatrix(); translate(anchor.x, anchor.y); rotate(forceangleN+PI/4); //body noStroke(); fill(230, 100, 50); rect(0, 0, 20, 20); rect(10, -10, 10, 10); rect(-10, 10, 10, 10); //shield stroke(220, 80); strokeWeight(4); noFill(); ellipse(0, 0, r, r); popMatrix(); } } /////