package examples.dingbats; import jgame.*; import jgame.platform.*; import examples.StdScoring; public class Dingbats extends StdGame { class Level { String bat1,bat2,bat3; int combo; String bg0,bg1; int bg_style; double bg_density; Level(String bat1,String bat2,String bat3, String bg0,String bg1, int bg_style, double bg_density) { this.bat1=bat1; this.bat2=bat2; this.bat3=bat3; this.bg0=bg0; this.bg1=bg1; this.bg_style=bg_style; this.bg_density=bg_density; } } //Level [] levels = new Level[]{ // new Level( public static void main(String [] args) { new Dingbats(StdGame.parseSizeArgs(args,0)); } /** Application constructor. */ public Dingbats(JGPoint size) { initEngine(size.x,size.y); } /** Applet constructor. */ public Dingbats() { initEngineApplet(); } public void initCanvas() { setCanvasSettings(16,12,64,64,null,null,null); } public void initGame() { setFrameRate(50,2); setBlendMode(1,0); setVideoSyncedUpdate(true); defineMedia("dingbats.tbl"); setMouseCursor(null); // If you want to have highscores in StdGame, add the following line. setHighscores( 10, // number of highscores new Highscore(0,"nobody"), // default entry for highscore 25 // max length of the player name ); setPFWrap(true,true,-60,-60); setPFSize(23,19); highscore_font = new JGFont("Serif",0,32); highscore_title_font = new JGFont("Serif",0,32); status_font = new JGFont("Serif",0,32); title_font = new JGFont("Serif",0,32); leveldone_ingame=true; startgame_ingame=true; lifelost_ingame=true; } public void startTitle() { removeObjects(null,0); fillBG(" "); setBGImage(1,"background3",true,true); setBGImage(0,"background2l0",true,true); } // game state double zoom=1.0; double time_to_alarm; boolean chase_player=false; int clicks; // level difficulty settings int bg_space; double max_time_to_alarm; double dingbat_speed; /** Called when a new level is started. */ public void defineLevel() { if (level >= 11) level = 11; // set difficulty bg_space = 2 - level/4; // [0,2] 2=easy max_time_to_alarm = (40-level)*50; // [28,40] dingbat_speed = 0.6 + 0.05*level; // [0.6, 1.15] // remove any remaining objects fillBG(" "); removeObjects(null,0); for (int i=0; i<13; i++) new Dingbat(1); for (int i=0; i<13; i++) new Dingbat(2); for (int i=0; i<13; i++) new Dingbat(3); new Pointer(); time_to_alarm = max_time_to_alarm; switch (stage%4) { case 0: setBGImage(1,"background5",true,true); setBGImage(0,"background1l0",true,true); // randomly placed tiles for (int y=random(1,3,1); y<19; y+=4) { for (int x=random(0,5,1); x<22; x+=random(6+bg_space,10+bg_space,1)) { setTile(x,y,"2"+random(0,7,1)); } } break; case 1: setBGImage(0,"background1l0",true,true); setBGImage(1,"background1",true,true); // tiles in vertical strips for (int x=2; x<21; x+=5) { for (int y=random(0,5,1); y<18; y+=random(7+bg_space,13+bg_space,1)) { for (int y2=0; y20) drawRect(64,viewHeight()-40,(viewWidth()-64)*(time_to_alarm/max_time_to_alarm), 16, true, false, false, timebarcol); } class Pointer extends JGObject { double mousexdir=0,mouseydir=0; int bullettimer=0; double invulnerability=100; Pointer () { super("pointer",false,mousex,mousey,1,null); setBBox(32,32,32,32); } public void hit(JGObject o) { if (invulnerability <= 0) { remove(); lifeLost(); new Explo(x,y-25); new Explo(x-30,y+15); new Explo(x+30,y+15); } } public void hit_bg(int tilecid) { if (invulnerability <= 0) { remove(); lifeLost(); new Explo(x,y-25); new Explo(x-30,y+15); new Explo(x+30,y+15); } } double markerx,markery; double prevmarkerx,prevmarkery; double angle,prevangle; public void move() { if (invulnerability > 0) invulnerability -= gamespeed; x = 2*mousex; y = 2*mousey; if (Math.abs(prevmousex-mousex) + Math.abs(prevmousey-mousey)>2) { mousexdir = 0.8*mousexdir + 0.2*(prevmousex - mousex); mouseydir = 0.8*mouseydir + 0.2*(prevmousey - mousey); } else { mousexdir += 0.1*(prevmousex - mousex); mouseydir += 0.1*(prevmousey - mousey); } markerx = x+150*Math.sin(angle); markery = y+150*Math.cos(angle); prevmarkerx = x+150*Math.sin(prevangle); prevmarkery = y+150*Math.cos(prevangle); angle = Math.PI+Math.atan2(mousexdir,mouseydir); if (angle-prevangle > Math.PI) prevangle -= Math.PI*2; if (angle-prevangle < - Math.PI) prevangle += Math.PI*2; if (Math.abs(angle-prevangle) > Math.PI*0.3) { prevangle = angle; } else { prevangle = 0.7*prevangle + 0.3*angle; } //if (bullettimer>0) bullettimer--; if ((getMouseButton(1) || getKey('Z')) && bullettimer<=0 && clicks>0) { clearKey('Z'); clearMouseButton(1); new Bullet(markerx,markery,angle); //bullettimer=12; clicks--; } } public void paint() { setBlendMode(1,0); drawImage(mousex*2, mousey*2, "pointer", new JGColor(1.0,1.0,1.0), /* blend colour */ 0.5 - (invulnerability > 0 ? (0.25+0.25*Math.sin(invulnerability)) : 0), /* alpha */ Math.atan2(mousexdir,mouseydir), /* rotation */ 1.0 + 0.5*(invulnerability/100.0), /* zoom */ true); drawImage(prevmarkerx, prevmarkery, "bullet", new JGColor(1.0,1.0,1.0), /* blend colour */ 1.0, /* alpha */ Math.atan2(mousexdir,mouseydir)+Math.PI*0.5, /* rotation */ 0.5, //0.85 + 0.15*Math.sin(rot*0.3), /* zoom */ true); } } // a translucent rotating zooming object class Bullet extends JGObject { int [] nr_got = new int [3]; double rot=0, rotinc; Bullet(double x,double y,double ang) { super("bullet",true, x,y, 2, null,35); //setSpeed(0.0*Math.sin(ang),0.0*Math.cos(ang)); setBBox(-24,-24,144,144); //setBBox(8,8,88,88); rot=ang-Math.PI*0.5; } public void move() { //rot += 0.05; } boolean pair=false,twopair=false,triplet=false,quad=false,quint=false, set=false,twoset=false; public void hit(JGObject o) { Dingbat od = (Dingbat) o; new Explo(od.x,od.y); nr_got[od.type-1]++; od.remove(); // check for combos. Each combo is awarded only once, but they are // cumulative. //int [] nr_got2 = new int[] {nr_got[0],nr_got[1],nr_got[2]}; // handle combos by priority: quint, quad, set, triplet, pair String bonusname=null; int bonus=5, clickbonus=0; double msgangle=0; for (int i=0; i<3; i++) { if (!quint && nr_got[i]>=5) { quint=true; bonusname = "quint"; msgangle = 90; clickbonus += 3; bonus += 75; } if (!quad && nr_got[i]==4) { quad=true; bonusname = "quad"; msgangle = 90; clickbonus += 5; bonus += 50; } } while (!set && nr_got[0]>0 && nr_got[1]>0 && nr_got[2]>0) { set=true; bonusname = "set"; msgangle = -90; clickbonus += 5; bonus += 50; } while (!twoset && nr_got[0]>1 && nr_got[1]>1 && nr_got[2]>1) { twoset=true; bonusname = "two sets"; msgangle = -45; clickbonus += 3; bonus += 75; } for (int i=0; i<3; i++) { if (!triplet && nr_got[i]==3) { triplet=true; bonusname = "triplet"; msgangle = 45; clickbonus += 3; bonus += 30; } if (nr_got[i]>=2) { if (!pair) { pair=true; bonusname = "pair"; msgangle = 0; clickbonus += 1; bonus += 10; } if (!twopair) { // we've got one pair, see if we got two for (int j=0; j<3; j++) { if (j==i) continue; if (nr_got[j]>=2) { twopair=true; bonusname = "two pairs"; msgangle = -90; clickbonus += 3; bonus += 30; } } } } } score += bonus; for (int i=0; i400) dist=400; ang += approach_dir*Math.PI*(approach_angle + 0.4*(400-dist)/400); xspeed += dingbat_speed*0.5*Math.sin(ang); yspeed += dingbat_speed*0.5*Math.cos(ang); xspeed *= 0.95; yspeed *= 0.95; } } } public void paint() { // blend mode is: source multiplier: alpha/destination multiplier: 1 if (type==2) setBlendMode(1,0); else setBlendMode(1,0); // the extended openGL drawImage method drawImage(x, y, imgname, /* regular image parameters */ dingbatcol[type-1], /* blend colour */ alpha, /* alpha */ rot, /* rotation */ scale, //0.85 + 0.15*Math.sin(rot*0.3), /* zoom */ true /* relative to playfield */ ); } } }