82 lines
3.9 KiB
JavaScript
82 lines
3.9 KiB
JavaScript
$(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<positionCharXRightCorner &&
|
|
positionYPoliceBuildingCornerLeft<positionCharYRightCorner){
|
|
console.log('jestem na policji');
|
|
$('#police-building').parent().attr('class', 'active');
|
|
}
|
|
//tutaj koniec upraszczania kodu
|
|
}
|
|
if(e.which == 38){
|
|
$("#char-arm-left-up").attr('id','char-arm-left');
|
|
$("#char-arm-right-up").attr('id','char-arm-right');
|
|
$("#char-container").css({
|
|
'top': '-=2rem',
|
|
})
|
|
$("#char-arm-left").attr('id','char-arm-left-up');
|
|
$("#char-arm-right").attr('id','char-arm-right-up');
|
|
}
|
|
if(e.which == 39){
|
|
$("#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');
|
|
$("#char-container").css({
|
|
'left': '+=2rem',
|
|
})
|
|
$("#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');
|
|
}
|
|
if(e.which == 40){
|
|
$("#char-arm-left-up").attr('id','char-arm-left');
|
|
$("#char-arm-right-up").attr('id','char-arm-right');
|
|
$("#char-container").css({
|
|
'top': '+=2rem',
|
|
})
|
|
$("#char-arm-left").attr('id','char-arm-left-up');
|
|
$("#char-arm-right").attr('id','char-arm-right-up');
|
|
}
|
|
})
|
|
$('div#police-building').mouseover(function(e){
|
|
$('#pop-up-police').css({
|
|
'display' : 'inline',
|
|
'visibility' : 'visible',
|
|
left: e.pageX + 1,
|
|
top: e.pageY + 1,
|
|
'z-index' : '2',
|
|
})
|
|
}).mouseout(function(){
|
|
$('#pop-up-police').css({
|
|
'visibility' : 'hidden',
|
|
})
|
|
|
|
})
|
|
}); |