$('#inventory').html('<%= escape_javascript render 'inventory' %>'); var parts = [ { name: 'leftArm', ident: "<%= @user.decorate.equipped_left_arm%>", visible: true, x: charX + 40, y: charY - 42 - breathAmt }, { name: 'leftArmjump', ident: "<%= @user.decorate.equipped_left_arm_jump %>", visible: false, x: charX + 40, y: charY - 42 - breathAmt }, {name: 'legs', ident: "<%= @user.decorate.equipped_legs %>", visible: true, x: charX, y: charY}, { name: 'legsjump', ident: "<%= @user.decorate.equipped_legs_jump%>", visible: false, x: charX, y: charY - 6 }, {name: 'torso', ident: "<%= @user.decorate.equipped_torso %>", visible: true, x: charX, y: charY - 50}, { name: 'head', ident: "<%= @user.decorate.equipped_head %>", visible: true, x: charX - 10, y: charY - 125 - breathAmt }, { name: 'hair', ident: "<%= @user.decorate.equipped_hair %>", visible: true, x: charX - 37, y: charY - 138 - breathAmt }, { name: 'rightArm', ident: "<%= @user.decorate.equipped_right_arm %>", visible: true, x: charX - 15, y: charY - 42 - breathAmt }, { name: 'rightArmjump', ident: "<%= @user.decorate.equipped_right_arm_jump %>", visible: false, x: charX - 35, y: charY - 42 - breathAmt }, ]; var bodyParts = []; var num_of_imgs = parts.length + 2; var loaded_imgs = 0; function myLoop() { bg.draw(); //update the cloud cx = cloud.x - cloudSpeed; if (cx + cloud.width < 0) { cx = engine._stageWidth + 20; cy = Math.floor(Math.random() * 50); cloud.y = cy; } cloud.x = cx; cloud.draw(); x = charX; y = charY; if (isJumping) { y -= jumpHeight; } character.y = y; // Update parts for breathing bodyParts.head.y = charY - 125 - breathAmt; bodyParts.hair.y = charY - 138 - breathAmt; if (isJumping) { bodyParts.leftArmjump.visible = true; bodyParts.rightArmjump.visible = true; bodyParts.legsjump.visible = true; bodyParts.leftArm.visible = false; bodyParts.rightArm.visible = false; bodyParts.legs.visible = false; } else { bodyParts.leftArmjump.visible = false; bodyParts.rightArmjump.visible = false; bodyParts.legsjump.visible = false; bodyParts.leftArm.visible = true; bodyParts.rightArm.visible = true; bodyParts.legs.visible = true; bodyParts.leftArm.y = charY - 42 - breathAmt; bodyParts.rightArm.y = charY - 42 - breathAmt; } bodyParts.leftEye.y = charY - 68 - breathAmt; bodyParts.rightEye.y = charY - 68 - breathAmt; eyeOpenTime += blinkUpdateTime; if (eyeOpenTime >= timeBtwBlinks) { blink(); } bodyParts.leftEye.height = curEyeHeight; bodyParts.rightEye.height = curEyeHeight; character.draw(); fps_text.text = "Current FPS: " + engine.getFPS(); fps_text.draw(); updateBreath(); } $(document).ready(function () { character = engine.createClip({ x: charX, y: charY }); for (part in parts) { o = parts[part]; bodyParts[o.name] = engine.createBitmap({ src: o.ident, x: o.x, y: o.y, visible: o.visible }); bodyParts[o.name].addEventListener('onload', increaseLoaded); character.add(bodyParts[o.name]); } bodyParts['leftEye'] = engine.createShape({ shape: 'elipse', style: 'filled', x: charX + 47, y: charY - 68 - breathAmt, width: 8, height: curEyeHeight, }); bodyParts['rightEye'] = engine.createShape({ shape: 'elipse', style: 'filled', x: charX + 58, y: charY - 68 - breathAmt, width: 8, height: curEyeHeight }); character.add(bodyParts['leftEye']); character.add(bodyParts['rightEye']); bg = engine.createBitmap({ src: "<%= @user.decorate.equipped_background %>", x: 0, y: 0 }); bg.addEventListener('onload', increaseLoaded); cloud = engine.createBitmap({ src: "<%=@user.decorate.equipped_flyingobject %>", x: engine._stageWidth + 20, y: 80 }); cloud.addEventListener('onload', increaseLoaded); fps_text = engine.createText({ text: "FPS", color: 'rgba(255,255,255,1)', x: 20, y: 20 }); });