Advertisement
Guest User

Week8 -SIT120

a guest
May 26th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.56 KB | None | 0 0
  1. <html>
  2.  
  3. <head>
  4. <script type="text/javascript" src="jquery-2.1.3.min.js"></script>
  5. <script type="text/javascript" src="introtoapps.min.js"></script>
  6.  
  7. <script type="text/javascript">
  8.  
  9. /*
  10. When webpage/webapp is loaded create a frog,
  11. Let him bounce to the right
  12. Add a tap handler to the entire window
  13. */
  14. $(document).ready(function() {
  15. for (var i = 1; i <= 3; i++) {
  16. var x = i * 75;
  17. $("body").append("<div class='frog' style='top: " + x + "px'></div>");
  18. }
  19.  
  20. for (var i = 1; i <= 3; i++) {
  21. var x = i * 75;
  22. $("body").append("<div class='frog2' style='top: " + x + "px'></div>");
  23. }
  24.  
  25.  
  26. var myScore;
  27. var duckNumber = 1;
  28.  
  29. $(".frog").moveTo(180);
  30. $(".frog").speed(0.1);
  31. $(".frog").autoBounceOff(true);
  32. $(".frog").onCollision(function(otherObject) {
  33. if (otherObject.hasClass("duck")) {
  34. this.remove();
  35. otherObject.remove();
  36. }
  37.  
  38. // Creates a tap handler for the entire window, to create a new duck and fire him up on the screen
  39. $("body").onTap(function(event) {
  40. //Coordinates for the event, Y and X axis where it was clicked/tapped.
  41. console.log(event.clientX);
  42.  
  43.  
  44. //Creates: <div id ='duck1' class='duck'></div>
  45. $("body").append("<div id ='duck" + duckNumber + "' class='duck'></div>");
  46. $("#duck" + duckNumber).moveTo(0);
  47. $("#duck" + duckNumber).speed(0.9);
  48. $("#duck" + duckNumber).css("bottom","0px");
  49. $("#duck" + duckNumber).css("left", event.clientX + "px");
  50.  
  51.  
  52. duckNumber++;
  53. })
  54.  
  55.  
  56.  
  57. });
  58.  
  59.  
  60. </script>
  61. <style type="text/css">
  62. body {
  63. background-color: white;
  64. }
  65.  
  66. .frog {
  67. background-image: url('images/frog.png');
  68. background-size: 50px 50px;
  69. width: 50px;
  70. height: 50px;
  71. position: absolute;
  72. top: 100px;
  73. left: 100px;
  74. z-index: 10;
  75. }
  76.  
  77. #leftwall {
  78. position: absolute;
  79. z-index: 10;
  80. width: 10px;
  81. background-color: black;
  82. height: 100vh;
  83. top: 0px;
  84. left: 0px;
  85. }
  86. #rightwall {
  87. position: absolute;
  88. z-index: 10;
  89. width: 10px;
  90. background-color: black;
  91. height: 100vh;
  92. top: 0px;
  93. right: 0px;
  94. }
  95. .duck {
  96. background-image: url(images/duck.png);
  97. background-size: 25px 50px;
  98. width: 25px;
  99. height: 50px;
  100. position: absolute;
  101. z-index: 10;
  102. }
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109. </style>
  110. </head>
  111. <body>
  112.  
  113.  
  114. <div id='leftwall'></div>
  115. <div id='rightwall'></div>
  116.  
  117.  
  118.  
  119. </body>
  120.  
  121.  
  122. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement