$(document).ready(function() { console.log("ready"); $(document).on('keydown', function(e){ if(e.which == 37){ $("#move-left").attr('id','char-pants-left'); $("#char-arm-left-up").attr('id','char-arm-left'); $("#char-arm-right-up").attr('id','char-arm-right'); $("#char-container").css({ 'left': '-=2rem', }) $("#char-pants-left").attr('id','move-left'); $("#char-pupil-left").attr('id','char-pupil-left-move'); $("#char-pupil-right").attr('id','char-pupil-right-move'); $("#char-arm-left").attr('id','char-arm-left-up'); $("#char-arm-right").attr('id','char-arm-right-up'); var positionCharXCornerLeft = $('#char-container').offset().left; var positionCharYCornerLeft = $('#char-container').offset().top; var positionCharXRightCorner = $('#char-container').offset().left + $('#char-container').innerWidth(); var positionCharYRightCorner = $('#char-container').offset().top + $('#char-container').innerHeight(); //https://stackoverflow.com/questions/8872578/if-element-is-over-another-element //uproscic kod(funkcje/zmienne); var positionXPoliceBuildingCornerLeft = $('#police-building').offset().left; var positionYPoliceBuildingCornerLeft = $('#police-building').offset().top; var positionXPoliceBuildingCornerRight = $('#police-building').offset().left + $('#police-building').innerWidth(); var positionYPoliceBuildingCornerRight = $('#police-building').offset().top + $('#police-building').innerHeight(); if(positionXPoliceBuildingCornerRight>positionCharXCornerLeft && positionYPoliceBuildingCornerRight>positionCharYCornerLeft && positionXPoliceBuildingCornerLeft