Bugg i mitt spel
Spelet går ut på att man ska hoppa över block som placeras vid slumpad tid.
Buggen: Vissa block placeras bredvid varandra eller i varandra.
Edit: kan man få hjälp?
<script>
jQuery.fn.center = function () {
this.css("position","fixed");
this.css("top", Math.max(0, (($(window).height() - $(this).outerHeight()) / 2) +
$(window).scrollTop()) + "px");
this.css("left", Math.max(0, (($(window).width() - $(this).outerWidth()) / 2) +
$(window).scrollLeft()) + "px");
return this;
}
difc=1000;
setInterval(function() {
var number = 1000 + Math.floor(Math.random() * 3000);
difc=number;
console.log(difc);
},4000);
$(document).ready(function(){
muis=document.getElementById("music");
muis.volume=0.2;
$('#cent').center();
$(window).resize(function(){
$('#cent').center();
});
});
var curdeg=0;
var jump=1;
var score=0;
function updateScore(){
$('#score').html(score);
}
var randnu = 0;
setTimeout(function(){
var blocknum = 1;
setInterval(function(){ //every second commence spawn block
setTimeout(function(){
makeblock(blocknum);
blocknum+=1;
},difc);
},800);
},2000);
setTimeout(function(){
setInterval(function(){
updateScore();
},1000);
},2000);
function makeblock(bid){
$('#gamecont').append('<div class="jbx" id="num'+bid+'"></div>');
setTimeout(function(){
$('#num'+bid).css('right','640px');
setTimeout(function(){
$('#num'+bid).remove();
},2000);
},0);
}
$(window).keypress(function(e) {
if(jump==1){
jump=0;
score+=1;
curdeg+=90;
updateScore();
$('#cube').css('bottom','152px');
setTimeout(function(){
$('#cube').css('bottom','52px');
setTimeout(function(){
jump=1;
},200);
},350);
}
});
var clsinterval = setInterval(ccls,100);
function ccls(){
hit_list = $("#cube").collision(".jbx");
if(hit_list.length > 0){
$('#loose').html('Your score:'+score+' <a href="javascript:void(location.reload())">Try again</a>');
$('#loose').show();
$('#jump').html('Try again');
$('#jump').attr('onClick','location.reload()');
muis.pause();
clearInterval(clsinterval);
}
}
setInterval(function(){
$('#imgg').css('transition','left 0s linear');
$('#imgg').css('left','0px');
setTimeout(function(){
$('#imgg').css('transition','left 2s linear');
setTimeout(function(){
$('#imgg').css('left','-640px');
});
},0);
},2000);
setTimeout(function(){
setInterval(function(){
if(muis.currentTime > 45){
var randc1 = Math.random() * 255;
randc1=Math.round(randc1);
var randc2 = Math.random() * 255;
randc2=Math.round(randc2);
var randc3 = Math.random() * 255;
randc3=Math.round(randc3);
$('#cube').css('box-shadow','0 0 70px rgb('+randc1+','+randc2+','+randc3+')');
}
},300);
},500);
setInterval(function(){
var randNumMin = 50;
var randNumMax = 255;
var randInt = (Math.floor(Math.random() * (randNumMax - randNumMin + 1)) + randNumMin);
$('.jbx').css('background','rgb('+randInt+',0,'+randInt+')');
},300);
</script>
Nuvarande dator:Amd 8core 3.5ghz, GTX 780, 8gb ram
Gammal dator (nuvarande server):Amd 4core 4ghz (o 3.7ghz), GTX 580, 16gb ram
Jag har hållit på med html,php,css,js i 2 år nu, samt fl studio i 2 år.