Tuesday, November 26, 2013

Angry Birds Calculator Program?

Here’s a little program I wrote for the TI-83 during the NW Math Conference last month, during the session just before my own.  It could serve a number of possible functions, including introducing programming to students, motivating a lesson on sine and cosine, or motivating a lesson on parabolas (though the program doesn’t use quadratic functions).
It’s not particularly rewarding to play, but maybe you can improve on it – right now it does three things:
  • draws a pig at a random distance
  • asks for angle and “force”
  • plots points until they go off the screen
There’s no collision detection or points system, and no end to the game, but what can you do?Here’s a look at the code so you can make your own improved version if you’re so inclined:

//FIRST, THE SETUP
  • Lbl B
  • ClrDraw
  • AxesOff
  • Degree
  • PlotsOff
  • FnOff
  • 10→Xmax:10→Ymax
  • -2→Xmin:-2→Ymin
//NEXT, THE SCENE
  • rand*4+4→P 
    (random number between 4 and 8 for the pig’s x-coordinate)
  • Line(-2,-1,10,-1) 
    (the ground)
  • Line(0,-1,0,0)
    (the slingshot)
  • Circle (P,0,1) 
    (this represents the pig. I made a more detailed pig face since I had some extra time, which I’ve included at the bottom).
//SET SOME STARTING VALUES
  • 0→X:0→Y 
    (starting values for plotting the bird path)
  • -0.07→G 
    (acceleration due to gravity… units are arbitrary, so I just tweaked this until it looked good)
  • Pause: ClrHome
  • Disp “ANGLE?”: Prompt T
  • cos(T)→D: sin(T)→E 
    (D and E will tell us the x and y increments for the bird’s path)
  • Disp “FORCE (1-10)?”: Prompt F
  • F/10*D→D: F/10*E→E
    (D and E are scaled by 1/10 of the “force” …also arbitrary)
//PLOT SOME POINTS
  • Lbl A
  • Pt-On(X,Y)
  • X+D→X: Y+E→Y
    (If D and E both remain constant, the bird will go in a line.  The curve is produced by changing E, the increment for y.)
  • E+G→E
    (You could think of E as velocity and G and acceleration)
  • If Y>0 and X<10: Goto A
    (Keep plotting points until you go off-screen to the right or hit the ground)
  • Pause
  • Goto B
    (New pig!)
//THAT’S IT!  If you want a more detailed pig, replace the Circle command with the following (I got rid of the circle because it takes so long to plot):
  • Line(P-1,0,P-0.5,1)
  • Line(P-0.5,1,P+.5,1)
  • Line(P+0.5,1,P+1,0)
  • Line(P+1,0,P+0.5,-1)
  • Line(P+.5,-1,P-0.5,-1)
  • Line(P-0.5,-1,P-1,0)
    (This forms a hexagon for the pig’s head)
  • Line (P+0.4,0.1,P+0.4,-0.7)
  • Line(P+0.4,-0.7,P-0.4,-0.7)
  • Line(P-0.4,-0.7,P-0.4,0.1)
  • Line(P-.4,0.1,P+0.4,0.1)
    (This forms a rectangle nose)
  • Pt-On(P+0.5,1.2,2): Pt-On(P-0.5,1.2,2)
    (Ears are points with “style 2” so they’re tiny squares)
  • Pt-On(P+0.5,0.5,3): Pt-On(P+-0.4,0.5,3)
    (Eyes have “style 3” so they’re tiny crosses)
  • Pt-On(P-0.15,-0.3): Pt-On(P+0.15,-0.3)
    (Nostrils!)

No comments:

Post a Comment