Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Science I Looking at code: "Where did Prof. Shablinsky go" Classwork/homework: midterm projects.

Similar presentations


Presentation on theme: "Computer Science I Looking at code: "Where did Prof. Shablinsky go" Classwork/homework: midterm projects."— Presentation transcript:

1 Computer Science I Looking at code: "Where did Prof. Shablinsky go" Classwork/homework: midterm projects

2 Feedback on error messages While programming in Processing Some you can ignore because you haven’t gotten to code something yet. BUT look at them because maybe the message indicates a mistake. For example, methods (aka functions) are defined to take specific arguments. void calculate(float v, float w) {…} is not the same as void calculate(int v) { }

3 Feedback You need to zip the FOLDER, containing the.pde file and, possibly, a data file, and, possibly, other things… USE THE NAMING CONVENTION: jMeyerBouncingThingsWClasses You may have problems in re-using names. Download may produce jMeyerBouncingThings (1).zip which could produce folder NOT matching.pde file name. Solution: erase old stuff or change name.

4 Feedback Consider use of array in place of Box1, Box2, … Then you can use loops for (int i<0;i<boxes.length;i++) { … } Do use distinct names for things that have specific roles Thing badguy = new Thing(…); Thing goodguy = new Thing(...); Things[] stuffToDisplay = {badguy,goodguy,…}

5 Processing features The background function can take an image as an argument. This is how I make the map be the background: background(bg); The nf function formats floats. So if secs has the value 5.100101, then nf(secs,1,2); will produce the string "5.10"

6 Idea for game Display world map Player attempts to guess where Prof. Shablinsky went during a summer a couple of years ago? Answers are: – Iceland – St. Petersberg While player is thinking, a shrinking image travels towards mouse position. Elapsed time shown. If player clicks the screen, flyer appears where the mouse was clicked. Two possibilities for message: – Positive message – Distance in pixels from closest of two answers If alloted time runs out, – Time ran out

7 Planning Manage two phases: inmotion Boolean variable (aka flag) Define – setup – Draw If inmotion: move flyer image towards mouse Else: give response – mouseClicked – checkanswer – giveresponse

8 Planning, cont. Move (animate) the flyer (the Irina image) towards the mouse position. Animation stops at the end of a fixed time duration set to 5 seconds OR if player clicks on the map. If player clicks on the map, a computation is done using the dist function to see if the player's location is near enough to one of the answer. Appropriate response given. If time runs out, a response is given.

9 Examine program Notice comments, including commented out code: used for debugging. The world map displayed using Pimage bg; In setup: bg = loadImage(filename); In draw: background(bg); The distance in pixels is calculated by builtin function dist. A for- loop calculates what of the two places is closer and then compares that number to 10, the tolerance allowed. This may be too strict. The function nf is used to format the elapsed time to display 2 decimal places. The flyer image dimensions are continuously changed, but kept in proportion using wdel, fw, and fh variables. fw -= wdel; fh = fw*(origh/origw);

10 PImage bg; PImage flyer; boolean inmotion = true; boolean clicked = false; float duration = 5; // 5 seconds float framer = 50; float interval = 1/framer; //frame interval in time float x,y,fw,fh,wdel; float origw,origh,smallw; PFont font; String question = "Where did Professor Shablinsky travel this summer?"; int[][] answers = {{452,90},{367,77}}; String[] answertexts = {"St. Petersberg, Russia", "Iceland"}; String responsetext;

11 Functions setup draw mouseClicked checkAnswer (float cx, float cy) giveresponse

12 Classwork / Homework Work on projects Start studying for midterm – Check out midterm guide – Prepare questions for next class


Download ppt "Computer Science I Looking at code: "Where did Prof. Shablinsky go" Classwork/homework: midterm projects."

Similar presentations


Ads by Google