2017-12-07 14:00:06 +01:00
|
|
|
$(document).ready(function() {
|
|
|
|
console.log("ready");
|
|
|
|
$(document).on('keydown', function(e){
|
|
|
|
if(e.which == 37){
|
2017-12-12 17:54:44 +01:00
|
|
|
$("#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');
|
2017-12-07 14:00:06 +01:00
|
|
|
$("#char-container").css({
|
|
|
|
'left': '-=2rem',
|
|
|
|
})
|
2017-12-12 17:54:44 +01:00
|
|
|
$("#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');
|
2017-12-13 09:41:41 +01:00
|
|
|
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<positionCharXRightCorner &&
|
|
|
|
positionYPoliceBuildingCornerLeft<positionCharYRightCorner){
|
|
|
|
console.log('jestem na policji');
|
|
|
|
$('#police-building').parent().attr('class', 'active');
|
|
|
|
}
|
|
|
|
|
2017-12-12 15:28:23 +01:00
|
|
|
}
|
2017-12-07 14:00:06 +01:00
|
|
|
if(e.which == 38){
|
2017-12-12 17:54:44 +01:00
|
|
|
$("#char-arm-left-up").attr('id','char-arm-left');
|
|
|
|
$("#char-arm-right-up").attr('id','char-arm-right');
|
2017-12-07 14:00:06 +01:00
|
|
|
$("#char-container").css({
|
|
|
|
'top': '-=2rem',
|
|
|
|
})
|
2017-12-12 17:54:44 +01:00
|
|
|
$("#char-arm-left").attr('id','char-arm-left-up');
|
|
|
|
$("#char-arm-right").attr('id','char-arm-right-up');
|
2017-12-07 14:00:06 +01:00
|
|
|
}
|
|
|
|
if(e.which == 39){
|
2017-12-12 17:54:44 +01:00
|
|
|
$("#move-right").attr('id','char-pants-right');
|
|
|
|
$("#char-arm-left-up").attr('id','char-arm-left');
|
|
|
|
$("#char-arm-right-up").attr('id','char-arm-right');
|
2017-12-07 14:00:06 +01:00
|
|
|
$("#char-container").css({
|
|
|
|
'left': '+=2rem',
|
|
|
|
})
|
2017-12-12 17:54:44 +01:00
|
|
|
$("#char-pants-right").attr('id','move-right');
|
|
|
|
$("#char-pupil-left-move").attr('id','char-pupil-left');
|
|
|
|
$("#char-pupil-right-move").attr('id','char-pupil-right');
|
|
|
|
$("#char-arm-left").attr('id','char-arm-left-up');
|
|
|
|
$("#char-arm-right").attr('id','char-arm-right-up');
|
2017-12-07 14:00:06 +01:00
|
|
|
}
|
|
|
|
if(e.which == 40){
|
2017-12-12 17:54:44 +01:00
|
|
|
$("#char-arm-left-up").attr('id','char-arm-left');
|
|
|
|
$("#char-arm-right-up").attr('id','char-arm-right');
|
2017-12-07 14:00:06 +01:00
|
|
|
$("#char-container").css({
|
|
|
|
'top': '+=2rem',
|
|
|
|
})
|
2017-12-12 17:54:44 +01:00
|
|
|
$("#char-arm-left").attr('id','char-arm-left-up');
|
|
|
|
$("#char-arm-right").attr('id','char-arm-right-up');
|
2017-12-07 14:00:06 +01:00
|
|
|
}
|
|
|
|
})
|
2017-12-13 09:41:41 +01:00
|
|
|
|
2017-12-07 14:00:06 +01:00
|
|
|
});
|