Claw Game progress
Errors resulting from Prize.js currently. - still using the original images, need to switch those out - need to remove unneeded code/commented attempts - need to code win-functionality (close game, give prize) - need to code in prize orbs, arcade circuit items
@@ -0,0 +1,79 @@
|
||||
function Crane(id) {
|
||||
//console.log("crane created");
|
||||
var top = 131; //private
|
||||
var left = 100;
|
||||
var hspd = 6;
|
||||
var vspd = 4;
|
||||
var state = false;
|
||||
var handleHeight = 83;
|
||||
var frames = {
|
||||
normal: {'background-position': '-36px -34px',left: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 () {
|
||||
top += (state == 'down')?vspd:-vspd;
|
||||
handleHeight += (state == 'down')?vspd:-vspd;
|
||||
|
||||
if(top > 300 && state == 'down') { //when going down
|
||||
top = 300;
|
||||
//handleHeight = ;
|
||||
state = 'up';
|
||||
$('#'+id+' #crane-claw').css(frames['half']);
|
||||
} else if(top < 131 && state == 'up') { //when going up
|
||||
top = 131;
|
||||
handleHeight = 83;
|
||||
state = 'drop';
|
||||
|
||||
} else if(state == 'drop') { //when up and dropping
|
||||
left -= hspd;
|
||||
top = 131;
|
||||
handleHeight = 83;
|
||||
if(left < 30) {
|
||||
left = 30;
|
||||
$('#'+id+' #crane-claw').css(frames['open']);
|
||||
setTimeout(function(){$('#'+id+' #crane-claw').css(frames['normal']);state = false;},500);
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var CheckBoundaries = function () {
|
||||
|
||||
if(left < 30)
|
||||
left = 30;
|
||||
else if(left > 788)
|
||||
left = 788;
|
||||
};
|
||||
|
||||
this.Update = function () {
|
||||
//console.log(left);
|
||||
if(keys["left"] && !state) //left
|
||||
left -= hspd;
|
||||
|
||||
if(keys["right"] && !state) //right
|
||||
left += hspd;
|
||||
|
||||
if(keys["down"] && !state) { //space
|
||||
state = 'down';
|
||||
|
||||
$('#'+id+' #crane-claw').css(frames['open']);
|
||||
}
|
||||
|
||||
if(state) {
|
||||
Grab();
|
||||
}
|
||||
|
||||
CheckBoundaries();
|
||||
};
|
||||
|
||||
this.Repaint = function () {
|
||||
$('#'+id).css({'top':top, 'left':left});
|
||||
$('#'+id+' #crane-handle-top').css({height: handleHeight});
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
function Prize(id,css, crane) {
|
||||
var top = css['top'];
|
||||
var left = css['left'];
|
||||
var original_left = css['left'];
|
||||
hspd = 15;
|
||||
vspd = 5;
|
||||
var state = 'falling';
|
||||
var error;
|
||||
|
||||
var rand = Math.floor(Math.random()*10);
|
||||
var rand2 = Math.floor(Math.random()*8);
|
||||
var item = ['item.2618.png','item.3122.png','item.6358.png',
|
||||
'aurum.png','item.7857.png','item.7868.png','item.7843.png','item.7842.png',
|
||||
|
||||
];
|
||||
css['background'] = 'url(images/'+item[rand2]+') no-repeat center';
|
||||
var pic = $('<div></div>').attr({'id':'prize'+id,class:'prize-ball'}).css(css);
|
||||
var ball = $('<div></div>').css({height: 60,'background':'url(images/prizeorbs.png) no-repeat -4px -'+62*rand+'px'});
|
||||
$(pic).append(ball);
|
||||
$('#game').append(pic);
|
||||
|
||||
//console.log(crane);
|
||||
this.GetState = function() {return state};
|
||||
|
||||
var CheckBoundaries = function () {
|
||||
|
||||
if(left < 52)
|
||||
left = 52;
|
||||
else if(left > 812)
|
||||
left = 812;
|
||||
|
||||
if(top < 30)
|
||||
top = 30;
|
||||
else if(top > 347 && state !='won' && state !='hidden') {
|
||||
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) {
|
||||
setTimeout(function(){
|
||||
state='falling';
|
||||
$('#debug-streak').html(0); //reset streak
|
||||
},4*error+300);
|
||||
}
|
||||
|
||||
state = 'is grabbed';
|
||||
};
|
||||
|
||||
var IsGrabbed = function() {
|
||||
top = crane.GetTop()+65;
|
||||
|
||||
if(top > 347)
|
||||
top = 347;
|
||||
|
||||
left = crane.GetLeft()+23;
|
||||
if(left <= 60) {
|
||||
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) {
|
||||
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();//css({visibility:'hidden'});
|
||||
state='hidden';
|
||||
|
||||
$('#debug-streak').html(parseInt($('#debug-streak').html())+1); //inc streak
|
||||
|
||||
//spawn new prize
|
||||
setTimeout(function(){
|
||||
prizes[prizes.length] = new Prize(prizes.length,{top: Math.ceil(Math.random()*100),left: original_left},crane);}
|
||||
,1000);
|
||||
|
||||
}
|
||||
|
||||
CheckBoundaries();
|
||||
};
|
||||
|
||||
this.Repaint = function () {
|
||||
$('#prize'+id).css({'top':top, 'left':left});
|
||||
//$('#'+id+' #crane-handle-top').css({height: handleHeight});
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
|
||||
/obj/machinery/arcade
|
||||
name = "Arcade Game"
|
||||
desc = "One of the most generic arcade games ever."
|
||||
icon = 'icons/obj/arcade.dmi'
|
||||
icon_state = "clawmachine_on"
|
||||
density = 1
|
||||
anchored = 1
|
||||
use_power = 1
|
||||
idle_power_usage = 40
|
||||
var/tokens = 0
|
||||
var/freeplay = 0 //for debugging and admin kindness
|
||||
var/token_price = 0
|
||||
var/playing = 0 //only has one set of controls, so only one person can play at once
|
||||
var/last_winner = null //for letting people who to hunt down and steal prizes from
|
||||
|
||||
/obj/machinery/arcade/New()
|
||||
..()
|
||||
var/choice = pick(subtypesof(/obj/machinery/arcade))
|
||||
new choice(loc)
|
||||
qdel(src)
|
||||
|
||||
/obj/machinery/arcade/attackby(var/obj/item/O as obj, var/mob/user as mob, params)
|
||||
if(istype(O, /obj/item/weapon/screwdriver) && anchored)
|
||||
playsound(src.loc, 'sound/items/Screwdriver.ogg', 50, 1)
|
||||
panel_open = !panel_open
|
||||
user << "You [panel_open ? "open" : "close"] the maintenance panel."
|
||||
update_icon()
|
||||
return
|
||||
if(!freeplay)
|
||||
if(istype(O, /obj/item/weapon/card/id))
|
||||
var/obj/item/weapon/card/id/C = O
|
||||
if(pay_with_card(C))
|
||||
tokens += 1
|
||||
return
|
||||
else if(istype(O, /obj/item/weapon/spacecash))
|
||||
var/obj/item/weapon/spacecash/C = O
|
||||
if(pay_with_cash(C, user))
|
||||
tokens += 1
|
||||
return
|
||||
if(panel_open&& component_parts && istype(O, /obj/item/weapon/crowbar))
|
||||
default_deconstruction_crowbar(O)
|
||||
|
||||
/obj/machinery/arcade/update_icon()
|
||||
return
|
||||
|
||||
/obj/machinery/arcade/proc/pay_with_cash(var/obj/item/weapon/spacecash/cashmoney, var/mob/user)
|
||||
if(cashmoney.get_total() < token_price)
|
||||
user << "\icon[cashmoney] <span class='warning'>That is not enough money.</span>"
|
||||
return 0
|
||||
visible_message("<span class='info'>[usr] inserts a credit chip into [src].</span>")
|
||||
var/left = cashmoney.get_total() - token_price
|
||||
user.unEquip(cashmoney)
|
||||
qdel(cashmoney)
|
||||
if(left)
|
||||
dispense_cash(left, src.loc, user)
|
||||
return 1
|
||||
|
||||
/obj/machinery/arcade/proc/pay_with_card(var/obj/item/weapon/card/id/I, var/mob/user)
|
||||
visible_message("<span class='info'>[usr] swipes a card through [src].</span>")
|
||||
var/datum/money_account/customer_account = attempt_account_access_nosec(I.associated_account_number)
|
||||
if (!customer_account)
|
||||
user <<"Error: Unable to access account. Please contact technical support if problem persists."
|
||||
return 0
|
||||
|
||||
if(customer_account.suspended)
|
||||
user << "Unable to access account: account suspended."
|
||||
return 0
|
||||
|
||||
// Have the customer punch in the PIN before checking if there's enough money. Prevents people from figuring out acct is
|
||||
// empty at high security levels
|
||||
if(customer_account.security_level != 0) //If card requires pin authentication (ie seclevel 1 or 2)
|
||||
var/attempt_pin = input("Enter pin code", "Vendor transaction") as num
|
||||
customer_account = attempt_account_access(I.associated_account_number, attempt_pin, 2)
|
||||
|
||||
if(!customer_account)
|
||||
user << "Unable to access account: incorrect credentials."
|
||||
return 0
|
||||
|
||||
if(token_price > customer_account.money)
|
||||
user << "Insufficient funds in account."
|
||||
return 0
|
||||
else
|
||||
// Okay to move the money at this point
|
||||
|
||||
// debit money from the purchaser's account
|
||||
customer_account.money -= token_price
|
||||
|
||||
// create entry in the purchaser's account log
|
||||
var/datum/transaction/T = new()
|
||||
T.target_name = "[src.name]"
|
||||
T.purpose = "Purchase of [src.name] credit"
|
||||
if(token_price > 0)
|
||||
T.amount = "([token_price])"
|
||||
else
|
||||
T.amount = "[token_price]"
|
||||
T.source_terminal = src.name
|
||||
T.date = current_date_string
|
||||
T.time = worldtime2text()
|
||||
customer_account.transaction_log.Add(T)
|
||||
return 1
|
||||
@@ -0,0 +1,98 @@
|
||||
|
||||
/obj/machinery/arcade/claw
|
||||
name = "Claw Game"
|
||||
desc = "One of the most infuriating ways to win a toy."
|
||||
icon = 'icons/obj/arcade.dmi'
|
||||
icon_state = "clawmachine_on"
|
||||
token_price = 15
|
||||
var/bonus_prize_chance = 5 //chance to dispense a SECOND prize if you win, increased by matter bin rating
|
||||
|
||||
/obj/machinery/arcade/claw/New()
|
||||
component_parts = list()
|
||||
//component_parts += new /obj/item/weapon/circuitboard/clawgame(null)
|
||||
component_parts += new /obj/item/weapon/stock_parts/matter_bin(null)
|
||||
component_parts += new /obj/item/weapon/stock_parts/manipulator(null)
|
||||
component_parts += new /obj/item/stack/cable_coil(null, 5)
|
||||
component_parts += new /obj/item/stack/sheet/glass(null, 1)
|
||||
RefreshParts()
|
||||
|
||||
/obj/machinery/arcade/claw/RefreshParts()
|
||||
var/bin_upgrades = 0
|
||||
for(var/obj/item/weapon/stock_parts/matter_bin/B in component_parts)
|
||||
bin_upgrades = B.rating
|
||||
bonus_prize_chance = bin_upgrades * 5 //equals +5% chance per matter bin rating level (+20% with rating 4)
|
||||
|
||||
/obj/machinery/arcade/claw/update_icon()
|
||||
if(stat & BROKEN)
|
||||
icon_state = "clawmachine_broken"
|
||||
else if(panel_open)
|
||||
icon_state = "clawmachine_open"
|
||||
else if(stat & NOPOWER)
|
||||
icon_state = "clawmachine_off"
|
||||
else
|
||||
icon_state = "clawmachine_on"
|
||||
return
|
||||
|
||||
/obj/machinery/arcade/claw/proc/win()
|
||||
icon_state = "clawmachine_win"
|
||||
//if(prob(bonus_prize_chance))
|
||||
//double prize mania!
|
||||
// new /obj/item/toy/prizeball(get_turf(src))
|
||||
//new /obj/item/toy/prizeball(get_turf(src))
|
||||
spawn(5)
|
||||
update_icon()
|
||||
|
||||
/obj/machinery/arcade/claw/attack_hand(mob/user as mob)
|
||||
interact(user)
|
||||
|
||||
/obj/machinery/arcade/claw/interact(mob/user as mob)
|
||||
if(stat & BROKEN || panel_open)
|
||||
return
|
||||
if(!tokens)
|
||||
user << "The game doesn't have enough credits to play! Pay first!"
|
||||
return
|
||||
if(!playing && tokens)
|
||||
user.set_machine(src)
|
||||
playing = 1
|
||||
tokens -= 1
|
||||
if(playing && (src != user.machine))
|
||||
user << "Someone else is already playing, please wait your turn!"
|
||||
return
|
||||
user << browse('crane.html', "window=Claw Game;size=600x600")
|
||||
/*
|
||||
var/dat
|
||||
var/datum/browser/clawgame = new(user, "clawgame", name, 600, 600)
|
||||
clawgame.add_stylesheet("claw", 'code/modules/arcade/page.css')
|
||||
clawgame.add_script("crane", 'code/modules/arcade/Crane.js')
|
||||
clawgame.add_script("prize", 'code/modules/arcade/Prize.js')
|
||||
clawgame.add_script("main", 'code/modules/arcade/main.js')
|
||||
|
||||
dat += "<div id='game' style='position: relative;'>"
|
||||
dat += "<div id='background'></div>"
|
||||
|
||||
dat += "<div id='crane'>"
|
||||
dat += "<div id='crane-handle-top'></div>"
|
||||
dat += "<div id='crane-handle-bottom'></div>"
|
||||
|
||||
dat += "<div id='crane-claw'></div>"
|
||||
dat += "<div id='crane-center'></div>"
|
||||
dat += "</div>"
|
||||
|
||||
dat += "<div id='grayorbs-chute'></div>"
|
||||
|
||||
dat += "<div id='foreground'></div>"
|
||||
|
||||
dat += "</div>"
|
||||
|
||||
dat += "<div style='position: absolute; top: 550px'>"
|
||||
dat += "<br><button onclick='gameStartUp()'>Play Now!</button>"
|
||||
dat += "<br>"
|
||||
dat += "<button onmouseover='joystickControlOn('left')' onmouseout='joystickControlOff('left')'>MOVE<br>LEFT</button>"
|
||||
dat += "<button onmousedown='joystickControlOn('down')' onmouseup='joystickControlOff('down')'>DROP<br>CLAW</button>"
|
||||
dat += "<button onmouseover='joystickControlOn('right')' onmouseout='joystickControlOff('right')'>MOVE<br>RIGHT</button>"
|
||||
dat += "</div>"
|
||||
|
||||
clawgame.set_content(dat)
|
||||
clawgame.open()
|
||||
*/
|
||||
return
|
||||
@@ -0,0 +1,38 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>Crane game</title>
|
||||
<link rel="stylesheet" type="text/css" href="page.css" />
|
||||
<script src="./jquery.js"></script>
|
||||
<script src="./Crane.js"></script>
|
||||
<script src="./Prize.js"></script>
|
||||
<script src="./main.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id='game' style='position: relative;'>
|
||||
<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>
|
||||
|
||||
<div style='position: absolute; top: 550px'>
|
||||
<br><button onclick="gameStartUp()">Play Now!</button>
|
||||
<br>
|
||||
<button onmouseover="joystickControlOn('left')" onmouseout="joystickControlOff('left')">/==<br>\==</button>
|
||||
<button onmousedown="joystickControlOn('down')" onmouseup="joystickControlOff('down')">DROP<br>CLAW</button>
|
||||
<button onmouseover="joystickControlOn('right')" onmouseout="joystickControlOff('right')">==\<br>==/</button>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 514 KiB |
|
After Width: | Height: | Size: 605 KiB |
|
After Width: | Height: | Size: 26 KiB |
|
After Width: | Height: | Size: 431 B |
|
After Width: | Height: | Size: 515 B |
|
After Width: | Height: | Size: 2.3 KiB |
|
After Width: | Height: | Size: 2.6 KiB |
|
After Width: | Height: | Size: 4.3 KiB |
|
After Width: | Height: | Size: 4.0 KiB |
|
After Width: | Height: | Size: 4.5 KiB |
|
After Width: | Height: | Size: 6.0 KiB |
|
After Width: | Height: | Size: 5.7 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 63 KiB |
@@ -0,0 +1,59 @@
|
||||
var crane = new Crane('crane');
|
||||
var keys = [];
|
||||
var prizes = [];
|
||||
|
||||
window.requestAnimFrame = (function(callback){
|
||||
return window.requestAnimationFrame ||
|
||||
window.webkitRequestAnimationFrame ||
|
||||
window.mozRequestAnimationFrame ||
|
||||
window.oRequestAnimationFrame ||
|
||||
window.msRequestAnimationFrame ||
|
||||
function(callback){
|
||||
window.setTimeout(callback, 1000 / 30);
|
||||
};
|
||||
})();
|
||||
|
||||
function animate(){
|
||||
//console.log("animate called");
|
||||
crane.Update();
|
||||
|
||||
for(var i = 0; i< prizes.length; i++)
|
||||
prizes[i].Update();
|
||||
|
||||
for(var i = 0; i< prizes.length; i++)
|
||||
prizes[i].Repaint();
|
||||
|
||||
crane.Repaint();
|
||||
|
||||
requestAnimFrame(function(){
|
||||
animate();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
function joystickControlOn(direction){
|
||||
//console.log(direction);
|
||||
keys[direction] = true;
|
||||
};
|
||||
|
||||
function joystickControlOff(direction){
|
||||
//console.log(direction);
|
||||
keys[direction] = false;
|
||||
};
|
||||
|
||||
//stops when text area loses focus
|
||||
function handsOff(){
|
||||
//keys.length = 0;
|
||||
keys = []; //clears array
|
||||
};
|
||||
|
||||
function gameStartUp(){ //main function
|
||||
//console.log("game start!");
|
||||
for(var i = 0; i< 5; i++)
|
||||
prizes[i] = new Prize(i,{top: Math.ceil(Math.random()*100),left: 400+i*100-Math.ceil(Math.random()*50)},crane);
|
||||
console.log("prize made");
|
||||
|
||||
//crane.Repaint();
|
||||
animate();
|
||||
};
|
||||
@@ -0,0 +1,84 @@
|
||||
#background {
|
||||
width:900px;
|
||||
height:406px;
|
||||
position: absolute;
|
||||
background: url(images/backgroundsprite.png) no-repeat;
|
||||
background-position: 0 -166px;
|
||||
top: 62px;
|
||||
}
|
||||
|
||||
#grayorbs-chute {
|
||||
width: 902px;
|
||||
height: 131px;
|
||||
position: absolute;
|
||||
background: url(images/backgroundsprite.png) no-repeat center;
|
||||
background-position: 3px -15px;
|
||||
top: 337px;
|
||||
left: -3px;
|
||||
}
|
||||
|
||||
#foreground {
|
||||
width:900px;
|
||||
height:520px;
|
||||
position: absolute;
|
||||
background: url(images/backgroundsprite.png) no-repeat center;
|
||||
background-position: 0 -575px;
|
||||
z-index:10;
|
||||
}
|
||||
|
||||
#crane {
|
||||
width:100px;
|
||||
height:100px;
|
||||
position: absolute;
|
||||
top: 131px;
|
||||
left: 100px;
|
||||
}
|
||||
|
||||
#crane-handle-top {
|
||||
width: 10px;
|
||||
height: 83px;
|
||||
position: absolute;
|
||||
background: url('images/crane handle top.png') repeat-y center;
|
||||
bottom: 86px;/*top: -69px;*/
|
||||
left: 47px;
|
||||
}
|
||||
|
||||
#crane-handle-bottom {
|
||||
width:10px;
|
||||
height:8px;
|
||||
position: absolute;
|
||||
background: url('images/clawpieces.png') no-repeat center;
|
||||
top: 14px;
|
||||
left: 47px;
|
||||
background-position: -198px -83px;
|
||||
}
|
||||
|
||||
#crane-center{
|
||||
width: 26px;
|
||||
height: 27px;
|
||||
position: absolute;
|
||||
background: url('images/clawpieces.png') no-repeat center;
|
||||
top: 22px;
|
||||
left: 39px;
|
||||
background-position: -190px -101px;
|
||||
}
|
||||
|
||||
#crane-claw {
|
||||
width: 110px;
|
||||
height: 78px;
|
||||
position: absolute;
|
||||
background: url('images/clawpieces.png') no-repeat center;
|
||||
top: 33px;
|
||||
left: 11px;
|
||||
background-position: -36px -34px;
|
||||
}
|
||||
|
||||
.prize-ball {
|
||||
width: 60px;
|
||||
height: 60px;
|
||||
//background: url('images/prizeorbs.png') no-repeat;
|
||||
//-moz-border-radius: 30px;
|
||||
//-webkit-border-radius: 30px;
|
||||
//border-radius: 30px;
|
||||
position: absolute;
|
||||
}
|
||||