mirror of
https://github.com/ParadiseSS13/Paradise.git
synced 2026-07-15 00:53:23 +01:00
fix clawgame double prizes (#19061)
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
<script src="libraries.min.js"></script>
|
||||
<!-- Prize.js --><script>
|
||||
function Prize(id,css, crane) {
|
||||
var top = css['top'];
|
||||
var top = css['top'];
|
||||
var left = css['left'];
|
||||
var original_left = css['left'];
|
||||
hspd = 15;
|
||||
@@ -23,24 +23,24 @@
|
||||
$('#game').append(pic);
|
||||
|
||||
this.GetState = function() {return state};
|
||||
|
||||
|
||||
var CheckBoundaries = function () {
|
||||
|
||||
|
||||
if(left < 52)
|
||||
left = 52;
|
||||
else if(left > 812)
|
||||
left = 812;
|
||||
|
||||
left = 812;
|
||||
|
||||
if(top < 30)
|
||||
top = 30;
|
||||
else if(top > 347 && state !='won' && state !='hidden') {
|
||||
top = 347;
|
||||
top = 347;
|
||||
state = 'resting';
|
||||
} else if(top > 500 && state =='won') {
|
||||
top = 500;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
var CheckGrabbed = function() {
|
||||
var tmp = Math.floor(Math.random()*100);
|
||||
if(tmp>error) {
|
||||
@@ -51,61 +51,61 @@
|
||||
},4*error+300);
|
||||
}else{
|
||||
prizeWon = true; // Incase you are interupted, you still get a prize.
|
||||
}
|
||||
}
|
||||
state = 'is grabbed';
|
||||
};
|
||||
|
||||
|
||||
var IsGrabbed = function() {
|
||||
top = crane.GetTop()+65;
|
||||
|
||||
if(top > 347)
|
||||
top = 347;
|
||||
|
||||
|
||||
if(top > 347)
|
||||
top = 347;
|
||||
|
||||
left = crane.GetLeft()+23;
|
||||
if(left <= 60) { // Claw has reached the drop-off with payload.
|
||||
left = 60;
|
||||
state = 'won';
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
this.GetError = function(offset) {
|
||||
return Math.floor(160/(.1*offset+1)-60);
|
||||
};
|
||||
|
||||
|
||||
this.Update = function () {
|
||||
|
||||
|
||||
if(crane.GetState() == 'down' && state=='resting') {
|
||||
var offset = Math.abs(left - crane.GetLeft()-23);
|
||||
error = this.GetError(offset);
|
||||
if(error > 0) {
|
||||
if(error > 0) {
|
||||
state = 'being grabbed';
|
||||
$('#debug-errorpx').html(Math.abs(offset)+'px');
|
||||
$('#debug-errordrop').html(error+'%');//debugging
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(crane.GetState() == 'up' && state=='being grabbed')
|
||||
CheckGrabbed();
|
||||
|
||||
|
||||
if((crane.GetState() == 'drop' || crane.GetState() == 'up') && state=='is grabbed')
|
||||
IsGrabbed();
|
||||
|
||||
|
||||
if(state=='falling'||state=='won')
|
||||
top += vspd;
|
||||
|
||||
|
||||
if(state=='won' && top > 460) {
|
||||
$('#prize'+id).remove();
|
||||
state='hidden';
|
||||
gameShutDown();
|
||||
}
|
||||
|
||||
|
||||
CheckBoundaries();
|
||||
};
|
||||
|
||||
|
||||
this.Repaint = function () {
|
||||
$('#prize'+id).css({'top':top, 'left':left});
|
||||
};
|
||||
|
||||
|
||||
}</script>
|
||||
<!-- Crane.js --><script>
|
||||
function Crane(id) {
|
||||
@@ -120,11 +120,11 @@
|
||||
half: {'background-position': '-36px -148px',left:6},
|
||||
open: {'background-position': '-28px -270px',left:-2}
|
||||
};
|
||||
|
||||
|
||||
this.GetState = function() {return state};
|
||||
this.GetLeft = function() {return left};
|
||||
this.GetTop = function() {return top};
|
||||
|
||||
|
||||
var Grab = function () {
|
||||
switch (state) {
|
||||
case 'up':
|
||||
@@ -142,7 +142,7 @@
|
||||
if(top > 300) {
|
||||
top = 300;
|
||||
state = 'up';
|
||||
$('#'+id+' #crane-claw').css(frames['half']);
|
||||
$('#'+id+' #crane-claw').css(frames['half']);
|
||||
}
|
||||
break;
|
||||
case 'drop': // when up and dropping
|
||||
@@ -157,22 +157,22 @@
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
var CheckBoundaries = function () {
|
||||
if(left < 30)
|
||||
left = 30;
|
||||
else if(left > 788)
|
||||
left = 788;
|
||||
left = 788;
|
||||
};
|
||||
|
||||
|
||||
this.Update = function () {
|
||||
if(!state){
|
||||
if(keys["left"]) //Move claw left
|
||||
left -= hspd;
|
||||
|
||||
|
||||
if(keys["right"]) // Move claw right
|
||||
left += hspd;
|
||||
|
||||
|
||||
if(keys["down"]){ // Drop claw.
|
||||
state = 'down';
|
||||
$('#'+id+' #crane-claw').css(frames['open']);
|
||||
@@ -180,10 +180,10 @@
|
||||
}else{
|
||||
Grab();
|
||||
}
|
||||
|
||||
|
||||
CheckBoundaries();
|
||||
};
|
||||
|
||||
|
||||
this.Repaint = function () {
|
||||
$('#'+id).css({'top':top, 'left':left});
|
||||
$('#'+id+' #crane-handle-top').css({height: handleHeight});
|
||||
@@ -212,7 +212,7 @@
|
||||
prizes[i].Update();
|
||||
prizes[i].Repaint();
|
||||
}
|
||||
|
||||
|
||||
crane.Repaint();
|
||||
requestAnimFrame(function(){
|
||||
animate();
|
||||
@@ -249,25 +249,24 @@
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body onunload="emergencyShutDown()">
|
||||
|
||||
<body>
|
||||
<div id='game' style='position: relative;height: 520px;width: 900px;'>
|
||||
<div id="background"></div>
|
||||
|
||||
|
||||
<div id="crane">
|
||||
<div id="crane-handle-top"></div>
|
||||
<div id="crane-handle-bottom"></div>
|
||||
|
||||
|
||||
<div id="crane-claw"></div>
|
||||
<div id="crane-center"></div>
|
||||
</div>
|
||||
|
||||
|
||||
<div id="grayorbs-chute"></div>
|
||||
|
||||
<div id="foreground"></div>
|
||||
|
||||
|
||||
<div id="foreground"></div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<div id='controls' style='position: absolute; left: 385px;'>
|
||||
<br>
|
||||
<button class="button" id="play_btn" onclick="gameStartUp()">Play Now!</button>
|
||||
|
||||
Reference in New Issue
Block a user