Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <script src="crafty.js" ></script>
- <script src="asset.js"></script>
- <link rel="stylesheet" href="assets/w3.css">
- <style>
- #cr-stage{
- position: relative;
- width: 100%;
- height: 100px;
- }
- </style>
- </head>
- <body>
- <div id="cr-stage"></div>
- <script>
- var wid = window.innerWidth;
- var hig = window.innerHeight;
- Crafty.init(wid,hig,document.getElementById("cr-stage"));
- Crafty.background("#6495ED")
- Crafty.audio.add({
- "intro":["audios/intro3.mp3"],
- "lompat":["audios/lompat1.mp3"],
- "coin":["audios/coin2.mp3"]
- })
- Crafty.sprite(50,80,"images/pl3.png",{
- diam:[0,0],
- jalan:[0,0],
- jatuh:[0,0]
- })
- var scrore = Crafty.e("2D,DOM,HTML,Text").attr({
- x:0,
- y:0,
- w:100,
- h:20
- })
- .css({"font-size":"32px","padding":"10px","z-index":"10","color":"white"})
- var batasKiri = Crafty.e("2D,DOM,Collision,WiredHitBox,BatasKiri").attr({
- x:0,
- y:0,
- w:1,
- h:hig
- })
- var batasKanan = Crafty.e("2D,DOM,Collision,WiredHitBox,BatasKanan").attr({
- x:wid,
- y:0,
- w:1,
- h:hig
- })
- var batasAras = Crafty.e("2D,DOM,WiredHitBox,BatasAtas,Collision").attr({
- x:0,
- y:0,
- w:wid,
- h:1
- })
- var taman = Crafty.e("2D,DOM,Image,Gravity,Taman").attr({
- x:0,
- y:0,
- w:wid,
- h:100
- })
- .gravity("Tembok")
- .image("images/taman.png","repeat")
- var tembok = Crafty.e("2D,DOM,Image,Gravity,Tembok").attr({
- x:0,
- y:hig-150,
- w:wid,
- h:50
- })
- .gravity("Ground")
- .image("images/tembok.png","repeat")
- var kotak = Crafty.e("2D,DOM,SpriteAnimation,diam,jalan,Twoway,jatuh,Gravity,Collision,Jumper,Kotak,Mouse,Keyboard,Tween,GroundAttacher").attr({
- x:400,
- y:400,
- w:100,
- h:150,
- z:10,
- })
- .twoway(200,1000)
- .gravity("Ground")
- //.jumpSpeed(500)
- .gravityConst(4000)
- .reel("diam",300,0,0,3)
- .reel("jalan",300,0,1,3)
- .reel("jatuh",300,0,2,3)
- .bind("Move",function(ef){
- if(this.hit("BatasKiri")){
- this.x = ef._x;
- }
- if(this.hit("BatasKanan")){
- this.x = ef._x;
- }
- if(this.hit("BatasAtas")){
- this.y = ef._y;
- }
- if(this.hit("Ground")){
- this.y = ef._y;
- }
- })
- .checkHits("Tembok")
- .bind("HitOn",function(a){
- this.animate("jatuh",1)
- })
- .bind("KeyDown",function(ky){
- if(ky.key == 38){
- this.animate("jatuh",1)
- //Crafty.audio.play("lompat")
- console.log("lompat")
- }
- if(ky.key == 37){
- this.antigravity()
- this.animate("jalan",10)
- this.rotation = -50
- }
- if(ky.key == 39){
- this.animate("jalan",10)
- }
- })
- .bind("KeyUp",function(kky){
- if(kky.key == 39 || kky.key == 37){
- this.rotation = 0;
- this.gravity("Ground")
- }
- })
- .bind("CheckJumping",function(){
- this.canJump = true;
- })
- .bind("LandedOnGround",function(){
- this.hasDoubleJumpPowerUp = true;
- })
- .bind("Click",function(){
- Crafty.pause();
- })
- .bind("EnterFrame",function(){
- })
- var coba = Crafty.e("2D,DOM,Color,Gravity,Mouse,Keyboard,Controls,Custom,Motion").attr({
- x:wid/2,
- y:hig/2,
- w:100,
- h:100
- })
- .color("green")
- Crafty.c("Custom",{
- _move:{left:false,righ:false,up:false,down:false},
- _speed:3,
- Custom:function(speed){
- if(speed) this._speed = speed;
- var move = this._move;
- this.bind("EnterFrame",function(){
- if(move.left)this.x += this._speed;
- })
- .bind("MouseDown",function(){
- move.left = true;
- })
- .bind("MouseUp",function(){
- move.left = false;
- })
- return this;
- }
- })
- var tanah = Crafty.e("2D,DOM,Image,Ground,Mouse,Keyboard,Custom").attr({
- x:0,
- y:hig-50,
- w:wid,
- h:100
- })
- .Custom(10)
- .image("images/ground.png","repeat")
- .bind("Click",function(ee){
- kotak.origin("top left")
- })
- //Crafty.audio.play("intro",1,0.5)
- var musuhSpeed = 1;
- function musuh(){
- var st = tembok.h + tanah.h;
- var posx = Math.floor(Crafty.math.randomNumber(st,hig-st))
- Crafty.e("2D,DOM,Color,Tween,Ground,Collision,Mouse,Keyboard,Custom").attr({
- x:wid,
- y:posx,
- w:100,
- h:20
- })
- .color("red")
- .bind("UpdateFrame",function(s){
- if(Crafty.frame() % 500 == 0){
- musuhSpeed +=0.05;
- //Crafty.audio.play("coin")
- scrore.text(Math.floor(musuhSpeed*1000))
- }
- this.x -= musuhSpeed;
- })
- .checkHits("BatasKiri,Kotak")
- .bind("HitOn",function(mht){
- //this.destroy();
- if(mht[.0].obj[.0] == 7){
- }
- })
- .onHit("Kotak",function(e){
- })
- .bind("Click",function(e){
- })
- }
- function awanKinton(){
- var random_y = Math.floor(Crafty.math.randomNumber(0,100))
- var randonKinton = Math.floor(Crafty.math.randomNumber(10000,90000))
- var awan = Crafty.e("2D,DOM,Image,Gravity,Tween,awan").attr({
- x:-100,
- y:random_y,
- w:200,
- h:100
- })
- .image("images/awan2.png")
- .tween({x:wid+10},randonKinton,"smoothStep")
- .bind("EnterFrame",function(){
- if(this.x >= wid){
- this.destroy();
- }
- })
- }
- Crafty.bind("EnterFrame",function(){
- if(Crafty.frame() % 500 == 0){
- awanKinton();
- awanKinton();
- }
- if(Crafty.frame() % 300 == 0){
- musuh();
- musuh();
- }
- })
- Crafty.scene("Kedua",function(){
- console.log("halo")
- })
- </script>
- </body>
- </html>
Add Comment
Please, Sign In to add comment