26
Mr. Happy Hits the Cloud • It is important that the canvas has a game that is challenging to the user. Thus far, Mr. Happy has been able to move around and ignore the objects. We will enable recognition of Mr. Happy’s collision and respond accordingly.

Mr. Happy Hits the Cloud

  • Upload
    ajaxe

  • View
    49

  • Download
    0

Embed Size (px)

DESCRIPTION

Mr. Happy Hits the Cloud. It is important that the canvas has a game that is challenging to the user. Thus far, Mr. Happy has been able to move around and ignore the objects. We will enable recognition of Mr. Happy’s collision and respond accordingly. . //avoid mr cloud of doooom. - PowerPoint PPT Presentation

Citation preview

Page 1: Mr. Happy Hits the Cloud

Mr. Happy Hits the Cloud

• It is important that the canvas has a game that is challenging to the user. Thus far, Mr. Happy has been able to move around and ignore the objects. We will enable recognition of Mr. Happy’s collision and respond accordingly.

Page 2: Mr. Happy Hits the Cloud

//avoid mr cloud of doooom

if (distance(hx,hy,x,100)<50) alive = false;

function distance(x1,y1,x2,y2){var d = 0;d = (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1);d = Math.sqrt(d);//text(d,10,10);return d;}

Page 3: Mr. Happy Hits the Cloud

var alive = true;

//let Mr. happy move for the mouse toohy=mouseY;hx=mouseX;

//change Mr. Happy if hits cloudif (!alive) fill(255,0,0);if (alive) rect(hx-40,hy-15,80,30);

Page 4: Mr. Happy Hits the Cloud

Practice 1: 20%

• Use the example code to have the drawing of Mr. Happy react to having a collision with a game object.

• Expand upon the current state of the canvas to make the game look more interesting and improve aesthetics.

• Improve the game functionally by having more responses to impacts.

Page 5: Mr. Happy Hits the Cloud

Review

• Mr. Happy Hits the Cloud• //avoid mr cloud of doooom• Code example• Practice 1

Page 6: Mr. Happy Hits the Cloud

The Star Obtains Objects

• Start out some variables to use for our obtainable objects such as this:

var targetX = 300;var targetY = 300;var targetSize = 100;• We will now have a place for the target to

appear and a variable to show how big it is.

Page 7: Mr. Happy Hits the Cloud

Baby Purple Star is Hungry!

strokeWeight(3);//little pinkpink starstroke(255-random(1,80),0,255-random(1,80));//top left part of little pink starline(mouseX,mouseY+-100,mouseX,mouseY+00);line(mouseX,mouseY+-80,mouseX-20,mouseY+00);line(mouseX,mouseY+-60,mouseX-40,mouseY+00);line(mouseX,mouseY+-40,mouseX-60,mouseY+00);line(mouseX,mouseY+-20,mouseX-80,mouseY+00);line(mouseX,mouseY+0,mouseX-100,mouseY+00);

Page 8: Mr. Happy Hits the Cloud

Draw the Food and Laser it!

if(mousePressed && distance(targetX, targetY,mouseX,mouseY)<50){//fire mah lasers!strokeWeight(10);stroke(random(1,255),0,0);line(mouseX+100, mouseY+200, random(1,600), random(1,600));line(mouseX+100, mouseY, random(1,600), random(1,600));targetSize--;if (targetSize<5){targetX = random(1,600);targetY = random(1,600);targetSize = 100;}}//draw targetfill(0,255,0);ellipse(targetX, targetY, targetSize,targetSize);

Page 9: Mr. Happy Hits the Cloud

Practice 2: 20%

• Create a game piece such as the baby purple star.

• Have something for the star to eat appear.• Use the distance function from the pervious

practice so the star knows if it is close enough to eat.

• Improve the game to make it more fun and interesting for a player.

Page 10: Mr. Happy Hits the Cloud

Review

• The Star Obtains Objects• Baby Purple Star is Hungry• Draw the Food and Laser it!• Practice 2: 20%

Page 11: Mr. Happy Hits the Cloud

Car Settings and Variablessize(400, 800); //This is a larger canvasvar enemyX = 0; //The bad car’s left/rightvar enemyY = 0; //The bad car’s up/downvar enemySpeed = 10; //The bad car’s speed

Page 12: Mr. Happy Hits the Cloud

Car Graphics and Mouse Upgrade//side of road a dark purple

background(30,10,30);

//make the roadway grayfill(100,100,100);rect(100,0,200,800);

if(mousePressed){keyX = mouseX-100;keyY = mouseY-100;}

}

Page 13: Mr. Happy Hits the Cloud

The Enemy Car//enemy car

noStroke();fill(140,40,40);rect(15+enemyX,200+enemyY,100,30);fill(150,50,50);rect(15+enemyX,100+enemyY,100,30);fill(100,0,0);rect(20+enemyX,50+enemyY,90,200);fill(155,255,255);rect(50+enemyX,50+enemyY,30,200);

enemyY = enemyY + enemySpeed;if(enemyY > 1000){enemyY = -200;if (enemySpeed <20) enemySpeed = enemySpeed +1;enemyX = random(1,300);}

Page 14: Mr. Happy Hits the Cloud

Practice 3: 20%

• Use the shown example to have an enemy object to avoid on the game by moving the mouse away from them.

• Use what you have learned to recognize if the car collides with the enemy object and have the game respond accordingly.

• Expand upon the shown example code to improve both the aesthetics and function of the game.

Page 15: Mr. Happy Hits the Cloud

Review

• Car Settings and Variables• Car Graphics and Mouse Upgrade• The Enemy Car• Practice 3: 20%

Page 16: Mr. Happy Hits the Cloud

Airplane Shoots Balloon

This part of the project will upgrade the previously created aircraft to target an object with it’s powerful LASERs.

var hitBalloon = false; //target not initially hitvar by=200; //target variable height in game

Page 17: Mr. Happy Hits the Cloud

Balloon Conditional and Laser//balloon

fill(random(1,200),random(1,200),random(1,200))ellipse(tx+200,by,50,50);

if(laserOn){if(by > 175+keyY && by < 225+keyY) hitBalloon = true;}

if(hitBalloon) {by = random(50,500);hitBalloon = false;}

Page 18: Mr. Happy Hits the Cloud

if(laserOn){stroke(255,0,0);line(0,200+keyY,1200,200+keyY);timeCount++;if (timeCount > laserTimeOut) {timeCount =0;laserOn = false;}}

Page 19: Mr. Happy Hits the Cloud

Practice 4: 20%

• Use the example code as shown to have a simple balloon appear on the screen for the pilot to use lasers on.

• Expand upon both the functional game play and the graphical elements to produce a game that end users, such as high school students, could enjoy playing.

Page 20: Mr. Happy Hits the Cloud

Review

• Airplane Shoots Balloon• Balloon Conditional and Laser• Example Code• Practice 4: 20%

Page 21: Mr. Happy Hits the Cloud

Improvements on Mr. Happy’s Grand Adventure

• More clouds• Helpful clouds• Clouds that are more difficult to avoid or to

obtain• A score, health bar, or timer• Recognition of winning the game or losing the

game

Page 22: Mr. Happy Hits the Cloud

Improvements on Star Game

• A health bar, life bar or score bar• More than one food to obtain• Food is more challenging to obtain• The big star gets involved in the game • A way to win/lose the game

Page 23: Mr. Happy Hits the Cloud

Improvements on Car Game

• The car should responds during an impact• Other objects to avoid or to obtain besides the

enemy car• Weapons for the car• Better graphics for the car, road, roadside• Lights for the car

Page 24: Mr. Happy Hits the Cloud

Improvements on Airplane Game

• More interesting objects to shoot • Objects to avoid• A way to keep track of success and/or levels• A more realistic looking airplane• Other weapons and/or defense systems

Page 25: Mr. Happy Hits the Cloud

Review

• Improvements on Mr. Happy’s Grand Adventure

• Improvements on the Star Game• Improvements on Car Game• Improvements on Airplane game

Page 26: Mr. Happy Hits the Cloud

• <h ead>• <title>Gab rielle' s Fun Games</title>• <scrip t typ e="t ext /javascr ip t" src="http://ww w.scottbu n in.co m/pr ocessin g.js"></scr ip t>• <scrip t typ e="t ext /javascr ip t" src="http://ww w.scottbu n in.co m/ in it.js"></scr ip t>• </h ead>• <cent er >

• <b od y>

• <script typ e="app lication /p r ocess ing">• size( 80 0,6 0 0 );

• var x = 4 00 ;• var t = 5 ;• var h x = 20 0 ;• var h y = 20 0 ;

• vo id dr aw () {• backgro un d (0 ,0 ,25 5) ;

• //mr gr een grass• st ro ke( 0,2 5 5,0) ;• st ro keWeigh t( 10 0) ;• lin e( 12 00 ,5 50 ,0 ,5 50 );• no St ro ke( );

• //mr clo u ds• fil l(2 55 ,2 55 ,2 55 );• ell ipse(x,1 00 ,2 00 ,1 00 );• fil l(2 00 ,0 ,1 00 +r an do m( 1 ,10 0 ));• ell ipse(x,4 50 ,2 00 ,1 00 );• x=x+t ;• if( x>90 0) x = - 10 0;•• //mr happ y• no St ro ke( );• fil l(2 55 ,2 55 ,0 );•• ell ipse(h x,hy,1 00 ,1 00 );• fil l(0 ,0,0) ;• ell ipse(h x- 2 0,h y- 20 ,1 0,1 0 );• ell ipse(h x+2 0,h y- 20 ,1 0,1 0 );• ell ipse(h x+0 ,hy+1 5,80 ,50 ) ;• fil l(2 55 ,2 55 ,0 );• rect( hx-4 0,hy-1 5,8 0,30 );

••• }••• vo id keyPr essed( ) {• if (keyC od e == UP ) h y = h y - 2 0;• if ( keyC od e == DOWN) hy = hy + 2 0;• if (keyC od e == LEFT) hx = h x - 2 0 ;• if ( keyC od e == R IGHT) h x = h x + 2 0;• }

•• </scr ip t><canvas tab in dex="0 " id ="__pro cessin g3 " w id th ="80 0" h eigh t ="60 0" st yle="image-rend er in g: -w eb kit -op timize-co n trast !imp or tant;"></can vas>

• <b r>• <b r>

• <script typ e="app lication /p r ocess ing">

• size( 60 0, 60 0 );• st ro keWeigh t( 1) ;•• var x = 3 00 ;• var y = 0 ;• var t = 5 ;

• vo id dr aw () {• backgro un d (2 55 ,2 55 ,2 55 );•• // to p left part of st ar• st ro ke( 25 5 ,0,0) ;• lin e( x,y+0,30 0 ,30 0 );• lin e( x,y+20 ,2 8 0,3 0 0);• lin e( x,y+40 ,2 6 0,3 0 0);• lin e( x,y+60 ,2 4 0,3 0 0);• lin e( x,y+80 ,2 2 0,3 0 0);• lin e( x,y+10 0 ,2 00 ,3 00 );• lin e( x,y+12 0 ,1 80 ,3 00 );• lin e( x,y+14 0 ,1 60 ,3 00 );• lin e( x,y+16 0 ,1 40 ,3 00 );• lin e( x,y+18 0 ,1 20 ,3 00 );• lin e( x,y+20 0 ,1 00 ,3 00 );• lin e( x,y+22 0 ,8 0,3 0 0);• lin e( x,y+24 0 ,6 0,3 0 0);• lin e( x,y+26 0 ,4 0,3 0 0);• lin e( x,y+28 0 ,2 0,3 0 0);• lin e( x,y+30 0 ,0 ,30 0 );• lin e( x,y+0,30 0 ,30 0 );• // to p r igh t part of star• st ro ke( 25 5 ,25 5 ,0) ;• lin e( x,y+20 ,3 2 0,3 0 0);• lin e( x,y+40 ,3 4 0,3 0 0);• lin e( x,y+60 ,3 6 0,3 0 0);• lin e( x,y+80 ,3 8 0,3 0 0);• lin e( x,y+10 0 ,4 00 ,3 00 );• lin e( x,y+12 0 ,4 20 ,3 00 );• lin e( x,y+14 0 ,4 40 ,3 00 );• lin e( x,y+16 0 ,4 60 ,3 00 );• lin e( x,y+18 0 ,4 80 ,3 00 );• lin e( x,y+20 0 ,5 00 ,3 00 );• lin e( x,y+22 0 ,5 20 ,3 00 );• lin e( x,y+24 0 ,5 40 ,3 00 );• lin e( x,y+26 0 ,5 60 ,3 00 );• lin e( x,y+28 0 ,5 80 ,3 00 );• lin e( x,y+30 0 ,6 00 ,3 00 );• //bo tto m left p ar t o f s tar• st ro ke( 0,2 5 5,0) ;• lin e( x,y+60 0 ,3 00 ,3 00 );• lin e( x,y+58 0 ,3 20 ,3 00 );• lin e( x,y+56 0 ,3 40 ,3 00 );• lin e( x,y+54 0 ,3 60 ,3 00 );• lin e( x,y+52 0 ,3 80 ,3 00 );• lin e( x,y+50 0 ,4 00 ,3 00 );• lin e( x,y+48 0 ,4 20 ,3 00 );• lin e( x,y+46 0 ,4 40 ,3 00 );• lin e( x,y+44 0 ,4 60 ,3 00 );• lin e( x,y+42 0 ,4 80 ,3 00 );• lin e( x,y+40 0 ,5 00 ,3 00 );• lin e( x,y+38 0 ,5 20 ,3 00 );• lin e( x,y+36 0 ,5 40 ,3 00 );• lin e( x,y+34 0 ,5 60 ,3 00 );• lin e( x,y+32 0 ,5 80 ,3 00 );• lin e( x,y+30 0 ,6 00 ,3 00 );• //bo tto m righ t p ar t o f s tar• st ro ke( 0,0 ,2 5 5) ;• lin e( x,y+60 0 ,3 00 ,3 00 );• lin e( x,y+58 0 ,2 80 ,3 00 );• lin e( x,y+56 0 ,2 60 ,3 00 );• lin e( x,y+54 0 ,2 40 ,3 00 );• lin e( x,y+52 0 ,2 20 ,3 00 );• lin e( x,y+50 0 ,2 00 ,3 00 );• lin e( x,y+48 0 ,1 80 ,3 00 );• lin e( x,y+46 0 ,1 60 ,3 00 );• lin e( x,y+44 0 ,1 40 ,3 00 );• lin e( x,y+42 0 ,1 20 ,3 00 );• lin e( x,y+40 0 ,1 00 ,3 00 );• lin e( x,y+38 0 ,8 0,3 0 0);• lin e( x,y+36 0 ,6 0,3 0 0);• lin e( x,y+34 0 ,4 0,3 0 0);• lin e( x,y+32 0 ,2 0,3 0 0);• lin e( x,y+30 0 ,0 ,30 0 );• x=x+t ;• if( x>60 0) t = - t;• if( x<0) t = -t ;•• }

•• vo id keyPr essed( ) {• if ( keyC od e == LEFT) x = x - 2 5;• if ( keyC od e == R IGHT) x = x + 25 ;• if (keyC od e == UP ) y = y - 25 ;• if ( keyC od e == DOWN) y = y + 2 5;• }• </scr ip t><canvas></can vas>

• <b r>• <b r>• <script typ e="app lication /p r ocess ing">• size( 40 0, 80 0 );

• var keyX = 0;• var keyY = 0 ;

• var y =1 00 ;• var x =1 00 ;• var t = .1;

• vo id dr aw () {• backgro un d (1 00 ,1 00 ,1 00 );•• //make th e yellow lines• st ro ke( 25 5 ,25 5 ,0) ;• st ro keWeigh t( 10 );• lin e( 20 0,y+0 ,2 00 ,y+50 );• lin e( 20 0,y+1 0 0,2 0 0,y+1 50 );• lin e( 20 0,y+2 0 0,2 0 0,y+2 50 );• lin e( 20 0,y+3 0 0,2 0 0,y+3 50 );• lin e( 20 0,y+4 0 0,2 0 0,y+4 50 );• lin e( 20 0,y+5 0 0,2 0 0,y+5 50 );• lin e( 20 0,y+6 0 0,2 0 0,y+6 50 );• lin e( 20 0,y+7 0 0,2 0 0,y+7 50 );• lin e( 20 0,y+8 0 0,2 0 0,y+8 50 );• y = y + 5 ;• if( y>70 ) y = 0;•••• //car vr oo o m• no St ro ke( );• fil l(5 0,5 0 ,5 0) ;• rect( keyX+x+15 ,keyY+2 00 ,1 00 ,3 0) ;• fil l(5 0,5 0 ,5 0) ;• rect( keyX+x+15 ,keyY+1 00 ,1 00 ,3 0) ;• fil l(0 ,0,0) ;• rect( keyX+x+20 ,keyY+5 0,9 0 ,2 00 );• fil l(2 55 ,2 55 ,2 55 );• rect( keyX+x+50 ,keyY+5 0,3 0 ,2 00 );• x = x + t;• if( x>8) t = -t ;• if( x<0) t = -t ;• }••• vo id keyPr essed( ) {• if ( keyC od e == LEFT) keyX = keyX - 15 ;• if ( keyC od e == R IGHT) keyX = keyX + 15 ;• if (keyC od e == UP ) keyY = keyY - 1 5;• if ( keyC od e == DOWN) keyY = keyY + 1 5 ;• }• </scr ip t><canvas></can vas>

• <b r>• <b r>

• <script typ e="app lication /p r ocess ing">• size( 12 00 ,6 0 0);

• var keyY = 0 ;• var keyX = 0;• var laserOn = false;• var laserTimeOut = 2 0;• var timeCo u n t = 0;

• var b y=20 0;

• tx = 4 0 0;• x = 0 ;• vo id dr aw () {• backgro un d (0 ,2 55 ,25 5 );

• // tree• no St ro ke( );• fil l(1 00 ,7 5,0) ;• rect( tx- 10 ,5 0 0,2 5 ,20 0) ;• fil l(0 ,25 5 ,0 );• ell ipse(t x,4 7 5,10 0,10 0) ;• tx = t x - 10 ;• if (tx < 0 ) tx = 1 4 00 ;•

•• //clo ud• no St ro ke( );• fil l(2 55 ,2 55 ,2 55 );• ell ipse(t x- 25 0 ,90 ,1 66 ,1 27 );• ell ipse(t x- 15 0 ,10 0 ,95 ,7 7) ;• ell ipse(t x- 35 0 ,10 0 ,95 ,7 7) ;• ell ipse(t x- 35 0 ,90 ,1 66 ,1 27 );• ell ipse(t x- 45 0 ,10 0 ,95 ,7 7) ;•• //LASER S! !! !!• st ro ke( 25 5 ,0,0) ;• st ro keWeigh t( 3) ;•••• // jet• no St ro ke( );• fil l(2 55 ,0 ,0 );• tr ian gle(keyX +x+1 00 ,1 00 +keyY,keyX +x+1 00 ,3 00 +keyY,keyX +x+3 00 ,2 00 +keyY);• fil l(1 00 ,7 5,0) ;• tr ian gle(keyX +x+2 00 ,1 00 +keyY,keyX +x+2 00 ,3 00 +keyY,keyX +x+4 00 ,2 00 +keyY);• fil l(2 55 ,1 92 ,2 03 );• tr ian gle(keyX +x+3 00 ,1 00 +keyY,keyX +x+3 00 ,3 00 +keyY,keyX +x+5 00 ,2 00 +keyY);• x= x+2;• if (x>12 00 ) x = -1 0 0;•• }•• vo id keyPr essed( ) {• if ( keyC od e == UP ) keyY = keyY - 1 5;• if ( keyC od e == DOWN) keyY = keyY + 1 5 ;• if (keyC od e == LEFT) keyX = keyX - 1 5;• if ( keyC od e == R IGHT) keyX = keyX + 15 ;•• if ( keyC od e == "32 ") laser On = tru e;•••• }• </scr ip t><canvas></can vas>

• </bo dy>• </cen ter>