Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- windowHeight = document.documentElement.clientHeight * 3;
- windowWidth = document.documentElement.clientWidth;
- gravity = 200;
- camera = windowHeight;
- PLATFORM_WIDTH = 50;
- PLATFORM_HEIGHT = 10;
- PLATFORMS_DISTANCE = 150;
- CAMERA_MOVE = PLATFORMS_DISTANCE - 20;
- Crafty.init(windowWidth, windowHeight, document.getElementById('game'));
- lvlOne();
- //lvls
- function lvlOne(){
- Crafty.e('Floor, 2D, Canvas, Color')
- .attr({x: 0, y: windowHeight-20, w: windowWidth, h: 20})
- .color('green');
- hero = Crafty.e('2D, Canvas, Color, Twoway, Gravity')
- .attr({x: 0, y: windowHeight-30, w: 50, h: 50})
- .color('#F00')
- .twoway(gravity)
- .gravity('Floor');
- for(i = 0; i < windowHeight; i+=PLATFORMS_DISTANCE){
- createPlatform(i);
- createPlatform(i);
- createPlatform(i);
- createPlatform(i);
- }
- $('body').keyup( function(e) {
- if(e.keyCode == 87 || e.keyCode == 38){
- $( "#game" ).animate({ "top": "+=" + CAMERA_MOVE+ "px" }, "slow" );
- camera-=(CAMERA_MOVE);
- }
- setTimeout(isAlive, 1000);
- });
- }
- //__________________________________________________
- //usefull functions
- function getRandomArbitrary(min, max) {
- return Math.random() * (max - min) + min;
- }
- function createPlatform(y) {
- Crafty.e('Floor, 2D, Canvas, Color')
- .attr({x:getRandomArbitrary(0, windowWidth - PLATFORM_WIDTH), y: y, w: PLATFORM_WIDTH, h: PLATFORM_HEIGHT})
- .color('green');
- }
- isAlive = function(){
- if(hero.y > camera)
- alert("DIE");
- }
- //move camera to start
- function scrollToBottom(){
- window.scrollTo(0,camera);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement