import java.awt.*; public class Minimal extends MISApplet{ //variables for mouse int mx = 0; final int WHITE = pack(255,255,255); final int BLACK = pack( 0, 0, 0); final int RED = pack(255, 0, 0); final int BLUE = pack(0,0,255); final int GREEN = pack(0,255, 0); final int radius = 10; final int thickness = 5; double cur_time = 0; double ex=0,ey=0;//top left corner double p; //1000 and .99996 //500 and .99999 double v; double a; double rate; boolean draw_bullet; boolean bullet_fired; double bx; double by; double bv; enum State{START, WINNER, LOSER, PLAYING } State game_state; int background_color; int foreground_color; int enemy_color; public void initialize() { //set mouse to middle of the applet draw_bullet = false; bullet_fired = false; game_state = State.START; background_color = WHITE; foreground_color = BLACK; enemy_color= foreground_color; p = 0; v = 1000; rate = 0.99997; a = 1.0; } /** Overriden method that must define frame in doube pix[] array */ public void computeImage(double time) { //paint the backdrop for(int i=0;iW ? mod%W : 0); a = a*rate; v = v*a; if(bullet_fired){ if(by<0-radius/2){ game_state = State.LOSER; background_color = BLACK; foreground_color = WHITE; enemy_color = foreground_color; } else{ by = by-cur_step*bv; } } } } // draw bullet if(draw_bullet){ for(int i =0;i0 && by+j>0) pix[xy2i((int)bx+i,(int)by+j)] = foreground_color; if(bx+i0 && by-j>0) pix[xy2i((int)bx+i,(int)by-j)] = foreground_color;; if(bx-i0 && by-j>0) pix[xy2i((int)bx-i,(int)by-j)] = foreground_color;; if(bx-i0 && by+j>0) pix[xy2i((int)bx-i,(int)by+j)] = foreground_color;; } } } // draw enemy for(int i =0;i=thickness*thickness){ if(ex+i0 && ey+j>0) pix[xy2i((int)ex+i,(int)ey+j)] = enemy_color; if(ex+i0 && ey-j>0) pix[xy2i((int)ex+i,(int)ey-j)] = enemy_color; if(ex-i0 && ey-j>0) pix[xy2i((int)ex-i,(int)ey-j)] = enemy_color; if(ex-i0 && ey+j>0) pix[xy2i((int)ex-i,(int)ey+j)] = enemy_color; } } // draw user for(int i =0;i=thickness*thickness){ if(mx+i0 && (H-radius)+j>0) pix[xy2i((int)mx+i,(int)(H-radius)+j)] = foreground_color; if(mx+i0 && (H-radius)-j>0) pix[xy2i((int)mx+i,(int)(H-radius)-j)] = foreground_color; if(mx-i0 && (H-radius)-j>0) pix[xy2i((int)mx-i,(int)(H-radius)-j)] = foreground_color; if(mx-i0 && (H-radius)+j>0) pix[xy2i((int)mx-i,(int)(H-radius)+j)] = foreground_color; } } } } public boolean mouseUp(Event e, int x, int y) { switch(game_state){ case PLAYING: if(!bullet_fired){ bullet_fired = true; bv = 1000;//lock in velocity = to the enemy plus 1 bx = x; by = H-radius*2-radius/2; return true; }else{ return false; } default: initialize(); game_state = State.PLAYING; return true; } } public boolean mouseDown(Event e, int x, int y) { switch(game_state){ case PLAYING: if(!bullet_fired){ draw_bullet = true; bx = x; by = H-radius*2-radius/2; return true; } } return false; } public boolean mouseDrag(Event e, int x, int y) { if(!bullet_fired){ bx = x; } mx = x; return true; } public boolean mouseMove(Event e, int x, int y) { mx = x; return true; } int ilerp(int t, int a, int b) { return a + (t * (b - a) >> 8); } }