mr. happy’s score

26
Mr. Happy’s Score Our old friend Mr. Happy needs a way to keep track of his success. We can do this by declaring, displaying and changing a score variable. //DECLARE THE VARIABLE var score = 1;

Upload: luther

Post on 21-Feb-2016

36 views

Category:

Documents


0 download

DESCRIPTION

Mr. Happy’s Score. Our old friend Mr. Happy needs a way to keep track of his success. We can do this by declaring, displaying and changing a score variable. //DECLARE THE VARIABLE var score = 1;. Using text and textFont. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Mr.  Happy’s  Score

Mr. Happy’s Score

Our old friend Mr. Happy needs a way to keep track of his success. We can do this by declaring, displaying and changing a score variable.

//DECLARE THE VARIABLEvar score = 1;

Page 2: Mr.  Happy’s  Score

Using text and textFont

The textFont command enables a programmer to decide what text and what font to use. Try visiting MSWord to see some common font names.

//SHOW THE SCOREtextFont("Arial", 30);fill(255, 255, 0);text("SCORE: "+ score , 30, 30);

Page 3: Mr.  Happy’s  Score

Incrementing the Score Variable

You could say score = score + 1 or you could say score++. It means the same thing and it is up to the programmer to choose.

//GIVE A POINT FOR GETTING THE CLOUD!if (distance(hx,hy,x,100)<50) {alive = false;score++;

}

Page 4: Mr.  Happy’s  Score

Practice 1: 20%

• Make Mr. Happy have a score that is displayed and increased based on game graphic collisions.

• Change the game so that it makes some sense and has a purpose that a player can enjoy.

• Increase the graphics of the game to make it look awesome.

Page 5: Mr.  Happy’s  Score

Review

• Mr. Happy’s Score• Using text and textFont• Incrementing the Score Variable• Practice 1:20%

Page 6: Mr.  Happy’s  Score

The Star Feeds to get Power

In some games, the character’s have a health bar that determines their strength. For this example we will use a variable called power and a rectangle that changes size.

//USE THE POWER VARIABLESvar power = 600;var lost = false;

Page 7: Mr.  Happy’s  Score

//SHOW THE POWER!!!

//SHOW THE POWER!!!fill(0,255,0);rect(0,0,power,20);power=power-.5;if (power<0) lost = true;

Page 8: Mr.  Happy’s  Score

if (lost){fill(255,0,0);rect(0,0,700,700);textFont("Arial", 60);fill(255, 255, 0);text("GAME OVER", 130, 200);}

Page 9: Mr.  Happy’s  Score

Practice 2: 20%

Use the examples shown to have the power bar show up on the screen.

Expand upon the given information to make the game more fun for players.

Make the game challenging, but not impossible.

Page 10: Mr.  Happy’s  Score

Review

• The Star Feeds to Get Power• //SHOW THE POWER!!!• Code example• Practice 2: 20%

Page 11: Mr.  Happy’s  Score

Recognizing a Car Collision

• We can start the game by recognizing that the driver is still doing well by declaring a variable. The variable is set to false and is called collision. If the variable is changed to true, that means that we consider the car to have crashed or collided with another object.

var collision = false;

Page 12: Mr.  Happy’s  Score

As an easy, but imperfect way to recognize a collision, we can use the distance function. This code should be executed in the main loop of the draw function. Take caution: programmers must retrieve the distance function and place it correctly.

if (distance(keyX+x,keyY+y,enemyX,enemyY) <70) collision = true;

Page 13: Mr.  Happy’s  Score

We have previously created a collision variable and assigned it as true. Then, we made it false if the car variables were close. Now, we can use the variable to disable the game if there was a collision.

if (collision) {fill(255,0,0);rect(0,0,1000,1000);}

Page 14: Mr.  Happy’s  Score

Practice 3: 20%

• Improve the function of the game to more accurately show if the cars crash into each other. Add other objects for the car to avoid.

• Improve the aesthetics of the game by making the cars look more realistic. Improve how the road looks and how the side of the road looks.

Page 15: Mr.  Happy’s  Score

Review

• Recognizing a Car Collision• Code Example• Code Example• Practice 3

Page 16: Mr.  Happy’s  Score

Keeping a Score

Our game already has a flying object and an object that can be shot with a laser. To improve how a player will enjoy the game, we can keep track of the player’s success with a score. The score will start at 0 and increase when the user hits their target.

var score = 0;

Page 17: Mr.  Happy’s  Score

Increasing the Score

• Increasing the score is a simple task. However, it takes more work to decide when and by how much the score can increase. The game player will want to see a recognition of success, but it must be balanced. Getting a higher score can’t be too hard or too easy.

score++;

Page 18: Mr.  Happy’s  Score

Mouse Input and Text OutputThe following code adapts the pre-established keyY

variable to the built in mouseY variable and lets the player move with the mouse.

The text command outputs to the screen with the number stored inside the score variable to let the user know how well they are doing.

keyY = mouseY-200;textFont("Arial", 60);fill(255, 255, 0);text("score "+ score, 130, 200);

Page 19: Mr.  Happy’s  Score

Practice 4: 20%

• Improve the aesthetics by making the airplane look like it should really be able to fly. Improve the background looks to make it look like it is really flying through air and over ground.

Page 20: Mr.  Happy’s  Score

Review

• Keeping a Score• Increasing the Score• Mouse Input and Text Output• Practice 4: 20%

Page 21: Mr.  Happy’s  Score

Improving the Mr. Happy Game

• The Mr. Happy game has to make sense. Improve the example so that the score increase and unhappy graphic work when they are supposed to.

• The game will need adjustments to be fun. Add more things to avoid, change where the “clouds of doom” appear and MAKE THE GAME CHALLENGING!

Page 22: Mr.  Happy’s  Score

Improving the Star Game

• If the example was followed then we should have a game that has a star eating food sources and a power rectangle that slowly reduces.

• Make the game challenging (but not impossible) so that some one can enjoy trying to win.

• Give the player opportunities to restore their power.

Page 23: Mr.  Happy’s  Score

Improving the Car Game

• If a student followed the directions, the game should already be partially responsive to collisions. There should be additional upgrades.

• Make better car/road/roadside graphics. Improve what happens in the game when the car hits another car so it isn’t just a red screen.

• Make the game challenging.

Page 24: Mr.  Happy’s  Score

Improving the Aircraft Game

• After following the directions, the aircraft should increase its score in a challenging way.

• The aircraft its self should look like it can really fly.

• The background, landscape and other worldly objects should look realistic and interesting.

• Make the game challenging.

Page 25: Mr.  Happy’s  Score

Review

• Improving the Mr. Happy Game• Improving the Star Game• Improving the Car Game• Improving the Aircraft Game

Page 26: Mr.  Happy’s  Score

• <h ea d >• <ti tle>G ab ri el le' s Fu n G ame s</tit le>• <sc rip t typ e ="tex t/jav ascr ip t" src=" h ttp ://w ww .sco ttb u n in .co m/p ro ce ssin g.js "></sc rip t >• <sc rip t typ e ="tex t/jav ascr ip t" src=" h ttp ://w ww .sco ttb u n in .co m/in i t. j s">< /scri p t>• </h ead >• <cen ter>

• <b o d y>

• <img id =" scre am" src=" h ear t.p n g" al t="T h e S cream " w id th ="0 " h e igh t ="0 " >

• <scrip t ty p e= "ap p l ica tio n /p ro cess in g ">• size(8 0 0 ,6 0 0 );

• var x = 4 0 0 ;• var t = 5 ;

• var h x = 2 0 0 ;• var h y = 2 0 0 ;• var al ive = tru e;

• //var c=d o cu men t.get Elem en tB yId ( "tes t");• //var ctx=c .get C o n text ("2 d ");• //var img= d o cu m en t. getEl emen tB yI d (" screa m");

• vo id d ra w() {

• b ack gro u n d (0 ,0 ,2 5 5 );

• //SH OW THE SC O R E•

•• //mr gree n gr ass• stro ke(0 ,2 5 5 ,0 );• stro keW eigh t(1 0 0 ) ;

• l in e (1 2 0 0 , 5 5 0 ,0 ,5 5 0 );

• n o S tro k e();

• //mr clo u d s

• fi l l ( 2 5 5 ,2 5 5 ,2 5 5 );

• el l ip se(x ,1 0 0 ,2 0 0 ,1 0 0 );• fi l l ( 2 0 0 ,0 , 1 0 0 +ra n d o m(1 ,1 0 0 ));• el l ip se(x ,4 5 0 ,2 0 0 ,1 0 0 );

• x=x+t ;

• i f(x> 9 0 0 ) x = -1 0 0 ;•• //mr h ap p y

• n o S tro k e();

• fi l l ( 2 5 5 ,2 5 5 ,0 );• i f (! al ive ) fi l l (2 5 5 , 0 ,0 ) ;

• el l ip se(h x,h y,1 0 0 , 1 0 0 );

• fi l l ( 0 ,0 ,0 );

• el l ip se(h x-2 0 ,h y-2 0 ,1 0 ,1 0 );• el l ip se(h x+2 0 ,h y-2 0 ,1 0 ,1 0 );

• el l ip se(h x+0 ,h y+ 1 5 ,8 0 , 5 0 ) ;

• fi l l ( 2 5 5 ,2 5 5 ,0 );

• i f (a l ive) rect (h x- 4 0 ,h y-1 5 ,8 0 ,3 0 );

• //avo id mr c lo u d o f d o o o o m

• i f (d ista n ce( h x,h y,x ,1 0 0 )<5 0 ) a l ive = fal se;

• //let mr h ap p y m o v e fo r th e mo u se to o

• h y=m o u seY;

• h x=m o u seX ;

•• //ctx .d ra wIm age(i mg, 1 0 ,1 0 );

•• }•

• fu n c tio n d istan ce(x 1 ,y1 ,x2 , y2 ){

• var d = 0 ;• d = (x2 - x1 )* (x2 - x1 ) + (y2 -y1 )*(y2 -y1 );• d = M at h .sq rt(d );

• //tex t(d , 1 0 , 1 0 ) ;

• retu rn d ;• }•

• vo id keyP res sed ( ) {

• i f (k eyC o d e == U P ) h y = h y - 2 0 ;• i f (keyC o d e == D OW N) h y = h y + 2 0 ;• i f (k eyC o d e == LE FT) h x = h x - 2 0 ;

• i f (keyC o d e == R IGH T) h x = h x + 2 0 ;

• }

•• </scri p t>< can vas t ab in d ex ="0 " id =" test " wi d th ="8 0 0 " h eigh t=" 6 0 0 " st yle=" image -ren d er in g: -we b kit -o p ti miz e-co n tr ast ! imp o rtan t;"> </ca n vas >

• <b r>• <b r>

• <scrip t ty p e= "ap p l ica tio n /p ro cess in g ">

• size(6 0 0 , 6 0 0 ) ;

• stro k eWe igh t(1 ) ;•• var x = 3 0 0 ;• var y = 0 ;

• var t = 5 ;

• var ta rgetX = 3 0 0 ;• var ta rgetY = 3 0 0 ;

• var ta rgetS ize = 1 0 0 ;

• vo id d ra w() {• b ack gro u n d (2 5 5 ,2 5 5 , 2 5 5 );•• //to p le ft p art o f s tar• stro ke(2 5 5 , 0 ,0 );• l in e (x,y+ 0 ,3 0 0 , 3 0 0 );• l in e (x,y+ 2 0 , 2 8 0 ,3 0 0 );• l in e (x,y+ 4 0 , 2 6 0 ,3 0 0 );• l in e (x,y+ 6 0 , 2 4 0 ,3 0 0 );• l in e (x,y+ 8 0 , 2 2 0 ,3 0 0 );• l in e (x,y+ 1 0 0 ,2 0 0 , 3 0 0 );• l in e (x,y+ 1 2 0 ,1 8 0 , 3 0 0 );• l in e (x,y+ 1 4 0 ,1 6 0 , 3 0 0 );• l in e (x,y+ 1 6 0 ,1 4 0 , 3 0 0 );• l in e (x,y+ 1 8 0 ,1 2 0 , 3 0 0 );• l in e (x,y+ 2 0 0 ,1 0 0 , 3 0 0 );• l in e (x,y+ 2 2 0 ,8 0 ,3 0 0 );• l in e (x,y+ 2 4 0 ,6 0 ,3 0 0 );• l in e (x,y+ 2 6 0 ,4 0 ,3 0 0 );• l in e (x,y+ 2 8 0 ,2 0 ,3 0 0 );• l in e (x,y+ 3 0 0 ,0 , 3 0 0 );• l in e (x,y+ 0 ,3 0 0 , 3 0 0 );• //to p ri gh t p art o f star• stro ke(2 5 5 , 2 5 5 ,0 );• l in e (x,y+ 2 0 , 3 2 0 ,3 0 0 );• l in e (x,y+ 4 0 , 3 4 0 ,3 0 0 );• l in e (x,y+ 6 0 , 3 6 0 ,3 0 0 );• l in e (x,y+ 8 0 , 3 8 0 ,3 0 0 );• l in e (x,y+ 1 0 0 ,4 0 0 , 3 0 0 );• l in e (x,y+ 1 2 0 ,4 2 0 , 3 0 0 );• l in e (x,y+ 1 4 0 ,4 4 0 , 3 0 0 );• l in e (x,y+ 1 6 0 ,4 6 0 , 3 0 0 );• l in e (x,y+ 1 8 0 ,4 8 0 , 3 0 0 );• l in e (x,y+ 2 0 0 ,5 0 0 , 3 0 0 );• l in e (x,y+ 2 2 0 ,5 2 0 , 3 0 0 );• l in e (x,y+ 2 4 0 ,5 4 0 , 3 0 0 );• l in e (x,y+ 2 6 0 ,5 6 0 , 3 0 0 );

• l in e (x,y+ 2 8 0 ,5 8 0 , 3 0 0 );• l in e (x,y+ 3 0 0 ,6 0 0 , 3 0 0 );• //b o tto m le ft p art o f st ar• stro ke(0 ,2 5 5 ,0 );

• l in e (x,y+ 6 0 0 ,3 0 0 , 3 0 0 );• l in e (x,y+ 5 8 0 ,3 2 0 , 3 0 0 );• l in e (x,y+ 5 6 0 ,3 4 0 , 3 0 0 );• l in e (x,y+ 5 4 0 ,3 6 0 , 3 0 0 );

• l in e (x,y+ 5 2 0 ,3 8 0 , 3 0 0 );• l in e (x,y+ 5 0 0 ,4 0 0 , 3 0 0 );• l in e (x,y+ 4 8 0 ,4 2 0 , 3 0 0 );• l in e (x,y+ 4 6 0 ,4 4 0 , 3 0 0 );

• l in e (x,y+ 4 4 0 ,4 6 0 , 3 0 0 );• l in e (x,y+ 4 2 0 ,4 8 0 , 3 0 0 );• l in e (x,y+ 4 0 0 ,5 0 0 , 3 0 0 );• l in e (x,y+ 3 8 0 ,5 2 0 , 3 0 0 );

• l in e (x,y+ 3 6 0 ,5 4 0 , 3 0 0 );

• l in e (x,y+ 3 4 0 ,5 6 0 , 3 0 0 );• l in e (x,y+ 3 2 0 ,5 8 0 , 3 0 0 );• l in e (x,y+ 3 0 0 ,6 0 0 , 3 0 0 );

• //b o tto m ri gh t p ar t o f star

• stro ke(0 ,0 ,2 5 5 );• l in e (x,y+ 6 0 0 ,3 0 0 , 3 0 0 );• l in e (x,y+ 5 8 0 ,2 8 0 , 3 0 0 );

• l in e (x,y+ 5 6 0 ,2 6 0 , 3 0 0 );

• l in e (x,y+ 5 4 0 ,2 4 0 , 3 0 0 );• l in e (x,y+ 5 2 0 ,2 2 0 , 3 0 0 );• l in e (x,y+ 5 0 0 ,2 0 0 , 3 0 0 );

• l in e (x,y+ 4 8 0 ,1 8 0 , 3 0 0 );

• l in e (x,y+ 4 6 0 ,1 6 0 , 3 0 0 );• l in e (x,y+ 4 4 0 ,1 4 0 , 3 0 0 );• l in e (x,y+ 4 2 0 ,1 2 0 , 3 0 0 );

• l in e (x,y+ 4 0 0 ,1 0 0 , 3 0 0 );

• l in e (x,y+ 3 8 0 ,8 0 ,3 0 0 );• l in e (x,y+ 3 6 0 ,6 0 ,3 0 0 );

• l in e (x,y+ 3 4 0 ,4 0 ,3 0 0 );

• l in e (x,y+ 3 2 0 ,2 0 ,3 0 0 );

• l in e (x,y+ 3 0 0 ,0 , 3 0 0 );• x=x+t ;

• i f(x> 6 0 0 ) t = -t;

• i f(x< 0 ) t = -t ;

• stro keW eigh t(3 ) ;

• //l itt le p in k p in k st ar

• stro ke(2 5 5 - ran d o m (1 ,8 0 ), 0 ,2 5 5 - ran d o m (1 ,8 0 )) ;

• //to p le ft p art o f l ittle p in k sta r• l in e (mo u seX ,mo u s eY+-1 0 0 , mo u seX ,mo u se Y+0 0 );

• l in e (mo u seX ,mo u s eY+-8 0 ,m o u s eX-2 0 ,m o u seY+0 0 );

• l in e (mo u seX ,mo u s eY+-6 0 ,m o u s eX-4 0 ,m o u seY+0 0 );

• l in e (mo u seX ,mo u s eY+-4 0 ,m o u s eX-6 0 ,m o u seY+0 0 );• l in e (mo u seX ,mo u s eY+-2 0 ,m o u s eX-8 0 ,m o u seY+0 0 );

• l in e (mo u seX ,mo u s eY+0 , mo u seX- 1 0 0 ,mo u s eY+0 0 );

• //to p ri gh t p art o f l ittl e p i n k s tar• l in e (mo u seX ,mo u s eY+-1 0 0 , mo u seX +0 ,m o u seY+0 0 );• l in e (mo u seX ,mo u s eY+-8 0 ,m o u s eX +2 0 ,m o u seY+0 0 );

• l in e (mo u seX ,mo u s eY+-6 0 ,m o u s eX +4 0 ,m o u seY+0 0 );

• l in e (mo u seX ,mo u s eY+-4 0 ,m o u s eX +6 0 ,m o u seY+0 0 );• l in e (mo u seX ,mo u s eY+-2 0 ,m o u s eX +8 0 ,m o u seY+0 0 );• l in e (mo u seX ,mo u s eY+0 0 ,mo u se X +2 0 0 , mo u seY+ 0 0 ) ;

• //b o tto m le ft p art o f l i ttle p in k sta r

• l in e (mo u seX ,mo u s eY+1 0 0 ,m o u seX + 0 0 , mo u seY+ 0 0 ) ;• l in e (mo u seX ,mo u s eY+8 0 ,mo u se X +-2 0 ,m o u seY+0 0 );• l in e (mo u seX ,mo u s eY+6 0 ,mo u se X +-4 0 ,m o u seY+0 0 );

• l in e (mo u seX ,mo u s eY+4 0 ,mo u se X +-6 0 ,m o u seY+0 0 );

• l in e (mo u seX ,mo u s eY+2 0 ,mo u se X +-8 0 ,m o u seY+0 0 );• l in e (mo u seX ,mo u s eY+0 0 ,mo u se X +-1 0 0 ,mo u seY +0 0 );• //b o tto m ri gh t p ar t o f l ittl e p i n k s tar

• l in e (mo u seX ,mo u s eY+1 0 0 ,m o u seX + 0 0 , mo u seY+ 0 0 ) ;

• l in e (mo u seX ,mo u s eY+8 0 ,mo u se X +2 0 ,m o u seY+0 0 );• l in e (mo u seX ,mo u s eY+6 0 ,mo u se X +4 0 ,m o u seY+0 0 );• l in e (mo u seX ,mo u s eY+4 0 ,mo u se X +6 0 ,m o u seY+0 0 );

• l in e (mo u seX ,mo u s eY+2 0 ,mo u se X +8 0 ,m o u seY+0 0 );

• l in e (mo u seX ,mo u s eY+0 0 ,mo u se X +1 0 0 , mo u seY+ 0 0 ) ;• stro keW eigh t(1 ) ;

•• i f(m o u s eP re ssed && d is tan c e(tar getX , tar getY ,mo u seX ,mo u seY )<5 0 ){• //fi r e ma h la sers!• stro keW eigh t(1 0 );• stro ke(ra n d o m(1 ,2 5 5 ), 0 ,0 );

• l in e (mo u seX +1 0 0 , mo u seY+ 2 0 0 , ra n d o m( 1 ,6 0 0 ), ran d o m (1 , 6 0 0 ));• l in e (mo u seX +1 0 0 , mo u seY, ran d o m (1 , 6 0 0 ), r an d o m( 1 ,6 0 0 ) );•• targe tSize --;

• i f (t arget Size< 5 ){• targe tX = ran d o m (1 ,6 0 0 );• targe tY = ran d o m (1 , 6 0 0 );• targe tSize = 1 0 0 ;

• }• }

• //d r aw t arget• fi l l ( 0 ,2 5 5 , 0 );• el l ip se(t arget X , t arge tY, ta rgetS ize,t arget Size) ;

••• }

• fu n c tio n d istan ce(x 1 ,y1 ,x2 , y2 ){• var d = 0 ;• d = (x2 - x1 )* (x2 - x1 ) + (y2 -y1 )*(y2 -y1 );• d = M at h .sq rt(d );• text( d ,1 0 ,1 0 );• retu rn d ;• }

•• vo id keyP res sed ( ) {• i f (keyC o d e == L EFT) x = x - 2 5 ;• i f (keyC o d e == R IGH T) x = x + 2 5 ;• i f (k eyC o d e == U P ) y = y - 2 5 ;• i f (keyC o d e == D OW N) y = y + 2 5 ;• }• </scri p t>< can vas>< /can vas>

• <b r>• <b r>• <scrip t ty p e= "ap p l ica tio n /p ro cess in g ">• size(4 0 0 , 8 0 0 ) ;

• var ke yX = 0 ;• var ke yY = 0 ;

• var y =1 0 0 ;• var x =1 0 0 ;

• var t = .1 ;

• var en emy X = 0 ;• var en emy Y = 0 ;

• var en emy Sp e ed = 1 0 ;

• vo id d ra w() {• //sid e o f ro ad a d a rk p u rp l e

• b ack gro u n d (3 0 ,1 0 ,3 0 );•• //ma ke th e ro ad w ay gray• fi l l ( 1 0 0 ,1 0 0 ,1 0 0 );

• rect( 1 0 0 ,0 , 2 0 0 ,8 0 0 );

• //ma ke th e ye l lo w l i n es• stro ke(2 5 5 , 2 5 5 ,0 );

• stro keW eigh t(1 0 );

• l in e (2 0 0 ,y+ 0 ,2 0 0 ,y+5 0 );• l in e (2 0 0 ,y+ 1 0 0 ,2 0 0 ,y +1 5 0 );• l in e (2 0 0 ,y+ 2 0 0 ,2 0 0 ,y +2 5 0 );

• l in e (2 0 0 ,y+ 3 0 0 ,2 0 0 ,y +3 5 0 );

• l in e (2 0 0 ,y+ 4 0 0 ,2 0 0 ,y +4 5 0 );• l in e (2 0 0 ,y+ 5 0 0 ,2 0 0 ,y +5 5 0 );• l in e (2 0 0 ,y+ 6 0 0 ,2 0 0 ,y +6 5 0 );

• l in e (2 0 0 ,y+ 7 0 0 ,2 0 0 ,y +7 5 0 );

• l in e (2 0 0 ,y+ 8 0 0 ,2 0 0 ,y +8 5 0 );• y = y + 5 ;• i f(y> 7 0 ) y = 0 ;

•• //en emy car• n o S tro k e();• fi l l ( 1 4 0 ,4 0 ,4 0 );

• rect( 1 5 + en em yX , 2 0 0 +en emyY ,1 0 0 ,3 0 );

• fi l l ( 1 5 0 ,5 0 ,5 0 );• rect( 1 5 + en em yX , 1 0 0 +en emyY ,1 0 0 ,3 0 );

• fi l l ( 1 0 0 ,0 , 0 );

• rect( 2 0 + en em yX , 5 0 +en em yY,9 0 ,2 0 0 );

• fi l l ( 1 5 5 ,2 5 5 ,2 5 5 );• rect( 5 0 + en em yX , 5 0 +en em yY,3 0 ,2 0 0 );

•• en em yY = en e myY + en emyS p eed ;

• i f(en emy Y > 1 0 0 0 ){• en em yY = -2 0 0 ;

• i f (e n em ySp e ed < 2 0 ) en e mySp eed = en emy Sp e ed +1 ;

• en em yX = ran d o m(1 ,3 0 0 );

• }•

•• //car vro o o m

• n o S tro k e();• fi l l ( 5 0 , 5 0 , 5 0 ) ;

• rect( keyX +x+1 5 ,ke yY+2 0 0 , 1 0 0 ,3 0 );

• fi l l ( 5 0 , 5 0 , 5 0 ) ;• rect( keyX +x+1 5 ,ke yY+1 0 0 , 1 0 0 ,3 0 );• fi l l ( 0 ,0 ,0 );

• rect( keyX +x+2 0 ,ke yY+5 0 ,9 0 ,2 0 0 ) ;

• fi l l ( 2 5 5 ,2 5 5 ,2 5 5 );• rect( keyX +x+5 0 ,ke yY+5 0 ,3 0 ,2 0 0 ) ;• x = x + t;

• i f(x> 8 ) t = -t ;

• i f(x< 0 ) t = -t ;•• i f(m o u s eP re ssed ){

• keyX = m o u s eX-1 0 0 ;

• keyY = mo u se Y-1 0 0 ;• }•

• }

•• vo id key P res sed ( ) {• i f (keyC o d e == L EFT) keyX = k eyX - 1 5 ;

• i f (keyC o d e == R IGH T) keyX = key X + 1 5 ;

• i f (k eyC o d e == U P ) keyY = keyY - 1 5 ;• i f (keyC o d e == D OW N) keyY = key Y + 1 5 ;• }• </scri p t>< can vas>< /can vas>

• <b r>• <b r>

• <scrip t ty p e= "ap p l ica tio n /p ro cess in g ">• size(1 2 0 0 ,6 0 0 );

• var ke yY = 0 ;

• var ke yX = 0 ;• var la serO n = fals e;• var la serTi meO u t = 2 0 ;• var ti meC o u n t = 0 ;

• var h i tB a l lo o n = fal se;• b y=2 0 0 ;

• tx = 4 0 0 ;• x = 0 ;• vo id d ra w() {• b ack gro u n d (0 ,2 5 5 ,2 5 5 );

• //tre e• n o S tro k e();• fi l l ( 1 0 0 ,7 5 ,0 ) ;• rect( tx-1 0 ,5 0 0 , 2 5 ,2 0 0 );• fi l l ( 0 ,2 5 5 , 0 );• el l ip se(t x,4 7 5 ,1 0 0 ,1 0 0 );• tx = tx - 1 0 ;• i f (t x < 0 ) tx = 1 4 0 0 ;•• //b a l lo o n• fi l l ( ran d o m (1 ,2 0 0 ),ran d o m(1 ,2 0 0 ),r an d o m( 1 ,2 0 0 ) )• el l ip se(t x+2 0 0 ,b y,5 0 ,5 0 );•• i f(la serO n ){• i f(b y > 1 7 5 +keyY && b y < 2 2 5 +k eyY) h i tB al l o o n = tr u e;• }•• i f(h i tB a l lo o n ) {• b y = ran d o m (5 0 ,5 0 0 );• h itB al lo o n = fa lse;• }•• //clo u d• n o S tro k e();• fi l l ( 2 5 5 ,2 5 5 ,2 5 5 );• el l ip se(t x-2 5 0 ,9 0 , 1 6 6 ,1 2 7 );• el l ip se(t x-1 5 0 ,1 0 0 ,9 5 ,7 7 );• el l ip se(t x-3 5 0 ,1 0 0 ,9 5 ,7 7 );• el l ip se(t x-3 5 0 ,9 0 , 1 6 6 ,1 2 7 );• el l ip se(t x-4 5 0 ,1 0 0 ,9 5 ,7 7 );

•• //LA SER S !!!!!• stro ke(2 5 5 , 0 ,0 );• stro keW eigh t(3 ) ;

•• i f(la serO n )• {• l in e (0 ,2 0 0 +keyY ,1 2 0 0 , 2 0 0 +key Y);

• time C o u n t+ +;• i f (ti meC o u n t > las erTim eOu t) {• time C o u n t =0 ;• laser On = fal se;

• }• }

• //jet

• n o S tro k e();• fi l l ( 2 5 5 ,0 , 0 );• trian gle( keyX +x+1 0 0 ,1 0 0 +key Y,key X +x+ 1 0 0 ,3 0 0 +k eyY,k eyX + x+3 0 0 ,2 0 0 +keyY );

• fi l l ( 1 0 0 ,7 5 ,0 ) ;

• trian gle( keyX +x+2 0 0 ,1 0 0 +key Y,key X +x+ 2 0 0 ,3 0 0 +k eyY,k eyX + x+4 0 0 ,2 0 0 +keyY );• fi l l ( 2 5 5 ,1 9 2 ,2 0 3 );• trian gle( keyX +x+3 0 0 ,1 0 0 +key Y,key X +x+ 3 0 0 ,3 0 0 +k eyY,k eyX + x+5 0 0 ,2 0 0 +keyY );

• x= x+ 2 ;

• i f (x >1 2 0 0 ) x = -1 0 0 ;•• }

•• vo id keyP res sed ( ) {• i f (keyC o d e == U P ) keyY = ke yY - 1 5 ;• i f (keyC o d e == D OW N) keyY = key Y + 1 5 ;

• i f (k eyC o d e == LE FT) keyX = key X - 1 5 ;

• i f (keyC o d e == R IGH T) keyX = key X + 1 5 ;•

• i f (keyC o d e == " 3 2 " )las erOn = tr u e;

•••

• }

• </scri p t>< can vas>< /can vas>

• </b o d y>

• </cen ter>