Guest User

Untitled

a guest
Jul 15th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.75 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <script src="crafty.js" ></script>
  5. <script src="asset.js"></script>
  6. <link rel="stylesheet" href="assets/w3.css">
  7. <style>
  8. #cr-stage{
  9. position: relative;
  10. width: 100%;
  11. height: 100px;
  12. }
  13.  
  14. </style>
  15. </head>
  16. <body>
  17. <div id="cr-stage"></div>
  18. <script>
  19.  
  20. var wid = window.innerWidth;
  21. var hig = window.innerHeight;
  22. Crafty.init(wid,hig,document.getElementById("cr-stage"));
  23. Crafty.background("#6495ED")
  24.  
  25.  
  26. Crafty.audio.add({
  27. "intro":["audios/intro3.mp3"],
  28. "lompat":["audios/lompat1.mp3"],
  29. "coin":["audios/coin2.mp3"]
  30. })
  31.  
  32. Crafty.sprite(50,80,"images/pl3.png",{
  33. diam:[0,0],
  34. jalan:[0,0],
  35. jatuh:[0,0]
  36. })
  37.  
  38. var scrore = Crafty.e("2D,DOM,HTML,Text").attr({
  39. x:0,
  40. y:0,
  41. w:100,
  42. h:20
  43. })
  44. .css({"font-size":"32px","padding":"10px","z-index":"10","color":"white"})
  45.  
  46.  
  47. var batasKiri = Crafty.e("2D,DOM,Collision,WiredHitBox,BatasKiri").attr({
  48. x:0,
  49. y:0,
  50. w:1,
  51. h:hig
  52. })
  53. var batasKanan = Crafty.e("2D,DOM,Collision,WiredHitBox,BatasKanan").attr({
  54. x:wid,
  55. y:0,
  56. w:1,
  57. h:hig
  58. })
  59. var batasAras = Crafty.e("2D,DOM,WiredHitBox,BatasAtas,Collision").attr({
  60. x:0,
  61. y:0,
  62. w:wid,
  63. h:1
  64. })
  65.  
  66.  
  67.  
  68. var taman = Crafty.e("2D,DOM,Image,Gravity,Taman").attr({
  69. x:0,
  70. y:0,
  71. w:wid,
  72. h:100
  73. })
  74. .gravity("Tembok")
  75. .image("images/taman.png","repeat")
  76.  
  77. var tembok = Crafty.e("2D,DOM,Image,Gravity,Tembok").attr({
  78. x:0,
  79. y:hig-150,
  80. w:wid,
  81. h:50
  82. })
  83. .gravity("Ground")
  84. .image("images/tembok.png","repeat")
  85.  
  86.  
  87.  
  88. var kotak = Crafty.e("2D,DOM,SpriteAnimation,diam,jalan,Twoway,jatuh,Gravity,Collision,Jumper,Kotak,Mouse,Keyboard,Tween,GroundAttacher").attr({
  89. x:400,
  90. y:400,
  91. w:100,
  92. h:150,
  93. z:10,
  94.  
  95. })
  96. .twoway(200,1000)
  97. .gravity("Ground")
  98. //.jumpSpeed(500)
  99. .gravityConst(4000)
  100. .reel("diam",300,0,0,3)
  101. .reel("jalan",300,0,1,3)
  102. .reel("jatuh",300,0,2,3)
  103. .bind("Move",function(ef){
  104. if(this.hit("BatasKiri")){
  105. this.x = ef._x;
  106.  
  107. }
  108. if(this.hit("BatasKanan")){
  109. this.x = ef._x;
  110. }
  111. if(this.hit("BatasAtas")){
  112. this.y = ef._y;
  113.  
  114. }
  115. if(this.hit("Ground")){
  116. this.y = ef._y;
  117.  
  118. }
  119.  
  120. })
  121. .checkHits("Tembok")
  122. .bind("HitOn",function(a){
  123. this.animate("jatuh",1)
  124. })
  125. .bind("KeyDown",function(ky){
  126. if(ky.key == 38){
  127. this.animate("jatuh",1)
  128. //Crafty.audio.play("lompat")
  129. console.log("lompat")
  130.  
  131. }
  132. if(ky.key == 37){
  133. this.antigravity()
  134. this.animate("jalan",10)
  135. this.rotation = -50
  136. }
  137. if(ky.key == 39){
  138. this.animate("jalan",10)
  139.  
  140. }
  141.  
  142. })
  143. .bind("KeyUp",function(kky){
  144.  
  145. if(kky.key == 39 || kky.key == 37){
  146. this.rotation = 0;
  147. this.gravity("Ground")
  148. }
  149.  
  150. })
  151. .bind("CheckJumping",function(){
  152. this.canJump = true;
  153. })
  154. .bind("LandedOnGround",function(){
  155. this.hasDoubleJumpPowerUp = true;
  156. })
  157. .bind("Click",function(){
  158. Crafty.pause();
  159. })
  160. .bind("EnterFrame",function(){
  161.  
  162. })
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170. var coba = Crafty.e("2D,DOM,Color,Gravity,Mouse,Keyboard,Controls,Custom,Motion").attr({
  171. x:wid/2,
  172. y:hig/2,
  173. w:100,
  174. h:100
  175. })
  176.  
  177. .color("green")
  178.  
  179.  
  180.  
  181. Crafty.c("Custom",{
  182. _move:{left:false,righ:false,up:false,down:false},
  183. _speed:3,
  184. Custom:function(speed){
  185. if(speed) this._speed = speed;
  186. var move = this._move;
  187.  
  188. this.bind("EnterFrame",function(){
  189. if(move.left)this.x += this._speed;
  190. })
  191. .bind("MouseDown",function(){
  192. move.left = true;
  193. })
  194. .bind("MouseUp",function(){
  195. move.left = false;
  196. })
  197. return this;
  198. }
  199. })
  200.  
  201. var tanah = Crafty.e("2D,DOM,Image,Ground,Mouse,Keyboard,Custom").attr({
  202. x:0,
  203. y:hig-50,
  204. w:wid,
  205. h:100
  206. })
  207. .Custom(10)
  208. .image("images/ground.png","repeat")
  209. .bind("Click",function(ee){
  210. kotak.origin("top left")
  211.  
  212. })
  213.  
  214. //Crafty.audio.play("intro",1,0.5)
  215.  
  216. var musuhSpeed = 1;
  217. function musuh(){
  218. var st = tembok.h + tanah.h;
  219. var posx = Math.floor(Crafty.math.randomNumber(st,hig-st))
  220. Crafty.e("2D,DOM,Color,Tween,Ground,Collision,Mouse,Keyboard,Custom").attr({
  221. x:wid,
  222. y:posx,
  223. w:100,
  224. h:20
  225. })
  226. .color("red")
  227. .bind("UpdateFrame",function(s){
  228. if(Crafty.frame() % 500 == 0){
  229. musuhSpeed +=0.05;
  230. //Crafty.audio.play("coin")
  231. scrore.text(Math.floor(musuhSpeed*1000))
  232. }
  233. this.x -= musuhSpeed;
  234.  
  235. })
  236. .checkHits("BatasKiri,Kotak")
  237. .bind("HitOn",function(mht){
  238. //this.destroy();
  239. if(mht[.0].obj[.0] == 7){
  240.  
  241. }
  242.  
  243.  
  244. })
  245. .onHit("Kotak",function(e){
  246.  
  247.  
  248. })
  249. .bind("Click",function(e){
  250.  
  251.  
  252. })
  253.  
  254. }
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261. function awanKinton(){
  262. var random_y = Math.floor(Crafty.math.randomNumber(0,100))
  263. var randonKinton = Math.floor(Crafty.math.randomNumber(10000,90000))
  264. var awan = Crafty.e("2D,DOM,Image,Gravity,Tween,awan").attr({
  265. x:-100,
  266. y:random_y,
  267. w:200,
  268. h:100
  269. })
  270. .image("images/awan2.png")
  271. .tween({x:wid+10},randonKinton,"smoothStep")
  272. .bind("EnterFrame",function(){
  273. if(this.x >= wid){
  274. this.destroy();
  275. }
  276. })
  277. }
  278.  
  279.  
  280. Crafty.bind("EnterFrame",function(){
  281.  
  282. if(Crafty.frame() % 500 == 0){
  283. awanKinton();
  284. awanKinton();
  285. }
  286. if(Crafty.frame() % 300 == 0){
  287. musuh();
  288. musuh();
  289.  
  290. }
  291.  
  292. })
  293.  
  294.  
  295.  
  296. Crafty.scene("Kedua",function(){
  297. console.log("halo")
  298. })
  299. </script>
  300. </body>
  301. </html>
Add Comment
Please, Sign In to add comment