-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbaby.php
1408 lines (1277 loc) · 39 KB
/
baby.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
echo("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; UTF-8" />
<title>Baby game</title>
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<title>Dear baby</title>
<script src="http://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="CanvasInput-master/CanvasInput.js"></script>
</script>
<style>
body {
background: #dddddd;
width:100%;
height:100%;
}
canvas {
display:block;
margin:auto;
background: #ffffff;
cursor: pointer;
}
</style>
</head>
<body onload="startGame()">
<?php
if(empty($_SESSION["login"]))
{
echo 'Please <a href="login.php">login</a> first!';
}
else
{
echo '<div class="display">Welcome '.$_SESSION["login"].' <a class="link" href="logout.php">Logout</a></div>';
if(!empty($_SESSION["babyname"]))
{
echo '<div class="displayname">Baby Name: '.$_SESSION["babyname"].'</div>';
}
?>
<div class="displayname" style="padding-top:10px;background-color:white;text-align:right;font-size:15px;color:grey;width:770px;border-left: 10px solid #dcefee;border-right: 10px solid #dcefee;">
<form class="example" id="search" method="post" action="doSearch.php" style="max-width:300px;margin-left:auto;margin-right:15px;">
<input type="text" placeholder="Put a name here to find a playdate..." name="babysearch" id="babysearch">
<button class="button" type="submit"><i class="fa fa-search"></i></button>
</form>
</div>
<canvas id='canvas' width='800' height='500'>
Canvas not supported
</canvas>
<?php
include("includes/openDbconn.php");
$sql="SELECT * FROM data WHERE user1='".$_SESSION["login"]."' OR user2='".$_SESSION["login"]."' AND Babyname='".$_SESSION["babyname"]."'";
$result=mysqli_query($db, $sql);
$row = mysqli_fetch_array($result);
if($row["user1"]!=$row["user2"])
{
if($row["user1"]==$_SESSION["login"])
echo '<div class="display">Joint caregiver <span>'.$row["user2"].'</span></div>';
else
echo '<div class="display">Joint caregiver <span>'.$row["user1"].'</span></div>';
}
else
{
?>
<div class="display">
<form action="doRegister2.php" method="post">
<ul id="register2">
<li> <label title="UserID" for="UserID">Username <span>*</span></label> <input type="text" name="UserID" id="UserID" size="15" maxlength="30" /></li>
<li> <label title="Passwd" for="Passwd">Password <span>*</span></label> <input type="text" name="Passwd" id="Passwd" size="15" maxlength="30" /></li>
<li> <label title="PasswdConfirm" for="PasswdConfirm">Confirm Password <span>*</span></label> <input type="text" name="PasswdConfirm" id="PasswdConfirm" size="15" maxlength="30" /></li>
</ul>
<div id="errorMsgregister"><?php if(!empty($_SESSION["errorMessage"])){echo($_SESSION["errorMessage"]);unset($_SESSION["errorMessage"]);} ?></div>
<input id="SubmitBtnregister3" name="SubmitBtn" type="submit" value="Add a caregiver" />
</form>
<div>
<script type="text/javascript"><!--
document.getElementById("UserID").focus();
--> </script>
<?php
}
?>
<script>
// Create the canvas
var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d");
//button parameters
var bX=30,
bY=70,
bW=80,
bH=30,
d=60,
d1=25,
pX=670,
pY=30,
pW=100,
pH=10;
//guest baby
//idle image
var nimageReady=new Array();
var nimages=new Array();
var nimagesName=["larm","rarm","lleg","rleg","diaper","body", "head", "loeye","roeye","mouth","leyeb","reyeb","hair"];
for(var i=0;i<13;i++)
{
nimageReady[i]=false;
nimages[i]=new Image();
}
//move image
var nmimageReady=new Array();
var nmimages=new Array();
var nmimagesName=["larmup","rarmup","lleg","rleg","diaper","body", "head", "loeye","roeye","mouth","leyeb","reyeb","hair"];
for(var i=0;i<13;i++)
{
nmimageReady[i]=false;
nmimages[i]=new Image();
}
//happy image
var nhimageReady=new Array();
var nhimages=new Array();
var nhimagesName=["larmup","rarmup","llegup","rlegup","diaper","body", "head", "lseye","rseye","smouth","leyeb","reyeb","hair"];
for(var i=0;i<13;i++)
{
nhimageReady[i]=false;
nhimages[i]=new Image();
}
//baby
//idle image
var imageReady=new Array();
var images=new Array();
var imagesName=["larm","rarm","lleg","rleg","diaper","body", "head", "loeye","roeye","mouth","leyeb","reyeb","hair"];
for(var i=0;i<13;i++)
{
imageReady[i]=false;
images[i]=new Image();
}
//move image
var mimageReady=new Array();
var mimages=new Array();
var mimagesName=["larmup","rarmup","lleg","rleg","diaper","body", "head", "loeye","roeye","mouth","leyeb","reyeb","hair"];
for(var i=0;i<13;i++)
{
mimageReady[i]=false;
mimages[i]=new Image();
}
//happy image
var himageReady=new Array();
var himages=new Array();
var himagesName=["larmup","rarmup","llegup","rlegup","diaper","body", "head", "lseye","rseye","smouth","leyeb","reyeb","hair"];
for(var i=0;i<13;i++)
{
himageReady[i]=false;
himages[i]=new Image();
}
//sad baby with wet diaper
var swimageReady=new Array();
var swimages=new Array();
var swimagesName=["larm","rarm","lleg","rleg","wetdiaper","body", "head", "lseye","rseye","sadmouth","leyeb","reyeb","hair"];
for(var i=0;i<13;i++)
{
swimageReady[i]=false;
swimages[i]=new Image();
}
//sad baby
var simageReady=new Array();
var simages=new Array();
var simagesName=["larm","rarm","lleg","rleg","diaper","body", "head", "lseye","rseye","sadmouth","leyeb","reyeb","hair"];
for(var i=0;i<13;i++)
{
simageReady[i]=false;
simages[i]=new Image();
}
//hungrey sad baby
var hsimageReady=new Array();
var hsimages=new Array();
var hsimagesName=["larm","rarm","lleg","rleg","diaper","body", "head", "lheye","rheye","hmouth","leyeb","reyeb","hair"];
for(var i=0;i<13;i++)
{
hsimageReady[i]=false;
hsimages[i]=new Image();
}
//hungrey wet baby
var hwimageReady=new Array();
var hwimages=new Array();
var hwimagesName=["larm","rarm","lleg","rleg","wetdiaper","body", "head", "lheye","rheye","hmouth","leyeb","reyeb","hair"];
for(var i=0;i<13;i++)
{
hwimageReady[i]=false;
hwimages[i]=new Image();
}
// Bottle image
var bottleReady = false;
var bottleImage = new Image();
bottleImage.onload = function () {
bottleReady = true;
};
bottleImage.src = 'image/bottle.png';
// diaper image
var diaperReady = false;
var diaperImage = new Image();
diaperImage.onload = function () {
diaperReady = true;
};
diaperImage.src = 'image/diaper.png';
// toybox image
var boxReady = false;
var boxImage = new Image();
boxImage.onload = function () {
boxReady = true;
};
boxImage.src = 'image/toybox.png';
// toy1 image
var toy1Ready = false;
var toy1Image = new Image();
toy1Image.onload = function () {
toy1Ready = true;
};
toy1Image.src = 'image/toy1.png';
// toy2 image
var toy2Ready = false;
var toy2Image = new Image();
toy2Image.onload = function () {
toy2Ready = true;
};
toy2Image.src = 'image/toy2.png';
// toy3 image
var toy3Ready = false;
var toy3Image = new Image();
toy3Image.onload = function () {
toy3Ready = true;
};
toy3Image.src = 'image/toy3.png';
// crib image
var cribReady = false;
var cribImage = new Image();
cribImage.onload = function () {
cribReady = true;
};
cribImage.src = 'image/crib.png';
//objects
var baby={
x:150,
y:155
};
var drawbaby;
var healthBar;
var happinessBar;
var comfortBar;
var milkButton;
var playButton;
var diaperButton;
function progressbar(x,y,width,width1,height,speed,type)
{
this.x=x;
this.y=y;
this.width=width;
this.width1=width1;
this.height=height;
this.type=type;
this.speed=speed;
this.update=function(){
context.font="12px Arial";
context.fillStyle="dimgrey";
context.fillText(this.type,this.x-80,this.y+10);
context.strokeStyle = "grey";
context.strokeRect(this.x,this.y,this.width,this.height);
context.fillStyle="green";
context.fillRect(this.x,this.y,this.width1,this.height);
if(this.width1<0.01)
{
this.width1=0;
}
else{
this.width1-=this.speed;
}
}
}
function buttons(x,y,width,height,color,type)
{
this.x=x;
this.y=y;
this.width=width;
this.height=height;
this.color=color;
this.type=type;
this.update = function() {
context.fillStyle=this.color;
context.fillRect(this.x,this.y,this.width,this.height);
context.font="15px Arial";
context.fillStyle="white";
context.fillText(this.type,this.x+10,this.y+20);
}
}
// Draw buttons
function makebuttons()
{
milkButton=new buttons(bX,bY,bW,bH,"green","MILK");
playButton=new buttons(bX,bY+2*d,bW,bH,"blue","PLAY");
diaperButton=new buttons(bX,bY+d,bW,bH,"orange","DIAPER");
}
function clear(){
context.clearRect(0, 0, canvas.width, canvas.height);
}
//mouse event click button
function windowToCanvas(canvas, x, y) {
var bbox = canvas.getBoundingClientRect();
return {
x: x - bbox.left * (canvas.width / bbox.width),
y: y - bbox.top * (canvas.height / bbox.height)
};
}
var happy=false;
var wet=false;
var hungry=false;
var hungryandwet=false;
var sad=false;
var bottle=false;
var bottleXHome=100;
var bottleYHome=70;
var bottleX=bottleXHome,bottleY=bottleYHome,bottleW=50,bottleH=50;
var diaper=false;
var diaperXHome=120;
var diaperYHome=140;
var diaperX=diaperXHome,diaperY=diaperYHome,diaperW=90,diaperH=40;
var toybox=false;
var toyboxXHome=20;
var toyboxYHome=230;
var toyboxX=toyboxXHome,toyboxY=toyboxYHome,toyboxW=105,toyboxH=160;
var toy1=false;
var toy1XHome=150;
var toy1YHome=160;
var toy1X=toy1XHome,toy1Y=toy1YHome,toy1W=120,toy1H=60;
var toy2=false;
var toy2XHome=150;
var toy2YHome=210;
var toy2X=toy2XHome,toy2Y=toy2YHome,toy2W=120,toy2H=90;
var toy3=false;
var toy3XHome=150;
var toy3YHome=260;
var toy3X=toy3XHome,toy3Y=toy3YHome,toy3W=120,toy3H=80;
var loeyeXHome=baby.x+197;
var loeyeX=0;
var nloeyeX=0;
var roeyeX=0;
var nroeyeX=0;
var oeyeY=0;
var toyleft=false;
var toyright=false;
var toyup=false;
var toydown=false;
canvas.onclick = function (e) {
var loc = windowToCanvas(canvas, e.clientX, e.clientY);
//click milk button
if(loc.x>milkButton.x&&loc.x<milkButton.x+milkButton.width&&loc.y>milkButton.y&&loc.y<milkButton.y+milkButton.height)
{
bottle=true;
}
//click play button
if(loc.x>playButton.x&&loc.x<playButton.x+playButton.width&&loc.y>playButton.y&&loc.y<playButton.y+playButton.height)
{
toybox=!toybox;
}
//click diaper button
if(loc.x>diaperButton.x&&loc.x<diaperButton.x+diaperButton.width&&loc.y>diaperButton.y&&loc.y<diaperButton.y+diaperButton.height)
{
diaper=true;
}
//click toy1
if(loc.x>toyboxX-toy1W/2&&loc.x<toyboxX+toy1W/2&&loc.y>toyboxY&&loc.y<toyboxY+toyboxH/3)
{
toy1=true;
}
//click toy2
if(loc.x>toyboxX-toy1W/2&&loc.x<toyboxX+toy1W/2&&loc.y>toyboxY+toyboxH/3&&loc.y<toyboxY+toyboxH*2/3)
{
toy2=true;
}
//click toy3
if(loc.x>toyboxX-toy1W/2&&loc.x<toyboxX+toy1W/2&&loc.y>toyboxY+2*toyboxH/3&&loc.y<toyboxY+toyboxH)
{
toy3=true;
}
}
function land()
{
happy = false;
}
canvas.onmousemove=function(e)
{
var loc = windowToCanvas(canvas, e.clientX, e.clientY);
// console.log(loc.x,loc.y);
//get bottle
if(bottle)
{
if(bottleX-bottleW/2< loc.x &&bottleX + bottleW/2 > loc.x &&
bottleY-bottleH/2 < loc.y &&bottleY + bottleH/2 > loc.y)
{
bottleX=loc.x;
bottleY=loc.y;
}
}
//bottle disappear at mouth
if(bottleX>baby.x+176&&bottleX<baby.x+210&&bottleY>baby.y&&bottleY<baby.y+50)
{
bottle=false;
bottleX=bottleXHome;
bottleY=bottleYHome;
happymove();
healthBar.width1+=50;
if (healthBar.width1>pW)
{
healthBar.width1=pW;
}
}
//get diaper
if(diaper)
{
if(diaperX-diaperW/2< loc.x &&diaperX + diaperW/2 > loc.x &&
diaperY-diaperH/2 < loc.y &&diaperY + diaperH/2 > loc.y)
{
diaperX=loc.x;
diaperY=loc.y;
}
}
//diaper disappear
if(diaperX>baby.x+176&&diaperX<baby.x+210&&diaperY>baby.y+75&&diaperY<baby.y+125)
{
diaper=false;
diaperX=diaperXHome;
diaperY=diaperYHome;
happymove();
comfortBar.width1+=50;
if (comfortBar.width1>pW)
{
comfortBar.width1=pW;
}
}
//move toy1
if(toy1)
{
if(loc.x>toy1X-toy1W/2&&loc.x<toy1X+toy1W/2&&loc.y>toy1Y-toy1H/2&&loc.y<toy1Y+toy1H/2)
{
toy1X=loc.x;
toy1Y=loc.y;
if(!wet&&!hungry&&!hungryandwet)
{
if (happinessBar.width1<pW/4)
{
happinessBar.width1=pW/4;
}
else if (happinessBar.width1>pW)
{
happinessBar.width1=pW;
}
else happinessBar.width1+=0.1;
}
if(happinessBar.width1>pW/2&&comfortBar.width1>pW/4&&healthBar.width1>pW/4)
{
happymove();
}
}
if (toy1X>baby.x&&toy1X<baby.x+130)
{
toyleft=true;
}
if (toy1X>baby.x+130&&toy1X<baby.x+210&&toy1Y<baby.y-50&&toy1Y>0)
{
toyup=true;
}
if (toy1X>baby.x+130&&toy1X<baby.x+210&&toy1Y>baby.y-50&&toy1Y<baby.y+100)
{
toydown=true;
}
if (toy1X>baby.x+210&&toy1X<baby.x+500)
{
toyright=true;
}
}
if(toy1X>toyboxX&&loc.x<toyboxX+0.2*toyboxW&&loc.y>toyboxY&&loc.y<toyboxY+toyboxH)
{
toy1=false;
}
//move toy2
if(toy2)
{
if(loc.x>toy2X-toy2W/2&&loc.x<toy2X+toy2W/2&&loc.y>toy2Y-toy2H/2&&loc.y<toy2Y+toy2H/2)
{
toy2X=loc.x;
toy2Y=loc.y;
if(!wet&&!hungry&&!hungryandwet)
{
if (happinessBar.width1<pW/4)
{
happinessBar.width1=pW/4;
}
else if (happinessBar.width1>pW)
{
happinessBar.width1=pW;
}
else happinessBar.width1+=0.1;
}
if(happinessBar.width1>pW/2&&comfortBar.width1>pW/4&&healthBar.width1>pW/4)
{
if (!happy)
{
happy = true;
setTimeout(land, 150);
}
}
}
if (toy2X>baby.x&&toy2X<baby.x+130)
{
toyleft=true;
}
if (toy2X>baby.x+130&&toy2X<baby.x+210&&toy2Y<baby.y-50&&toy2Y>0)
{
toyup=true;
}
if (toy2X>baby.x+130&&toy2X<baby.x+210&&toy2Y>baby.y-50&&toy2Y<baby.y+100)
{
toydown=true;
}
if (toy2X>baby.x+210&&toy2X<baby.x+500)
{
toyright=true;
}
}
if(toy2X>toyboxX&&loc.x<toyboxX+0.2*toyboxW&&loc.y>toyboxY&&loc.y<toyboxY+toyboxH)
{
toy2=false;
}
//move toy3
if(toy3)
{
if(loc.x>toy3X-toy3W/2&&loc.x<toy3X+toy3W/2&&loc.y>toy3Y-toy3H/2&&loc.y<toy3Y+toy3H/2)
{
toy3X=loc.x;
toy3Y=loc.y;
if(!wet&&!hungry&&!hungryandwet)
{
if (happinessBar.width1<pW/4)
{
happinessBar.width1=pW/4;
}
else if (happinessBar.width1>pW)
{
happinessBar.width1=pW;
}
else happinessBar.width1+=0.1;
}
if(happinessBar.width1>pW/2&&comfortBar.width1>pW/4&&healthBar.width1>pW/4)
{
if (!happy)
{
happy = true;
setTimeout(land, 150);
}
}
}
if (toy3X>baby.x&&toy3X<baby.x+130)
{
toyleft=true;
}
if (toy3X>baby.x+130&&toy3X<baby.x+210&&toy3Y<baby.y-50&&toy3Y>0)
{
toyup=true;
}
if (toy3X>baby.x+130&&toy3X<baby.x+210&&toy3Y>baby.y-50&&toy3Y<baby.y+100)
{
toydown=true;
}
if (toy3X>baby.x+210&&toy3X<baby.x+500)
{
toyright=true;
}
}
if(toy3X>toyboxX&&loc.x<toyboxX+0.2*toyboxW&&loc.y>toyboxY&&loc.y<toyboxY+toyboxH)
{
toy3=false;
}
}
function happymove()
{
if (!happy)
{
happy = true;
setTimeout(land, 500);
}
}
function moveeye()
{
if(toyleft)
{
loeyeX=-1;
roeyeX=-1;
toyleft=false;
}
if(toyup)
{
oeyeY=-1;
toyup=false;
}
if(toydown)
{
oeyeY=+1;
toydown=false;
}
if(toyright||newbaby)
{
loeyeX=+1;
roeyeX=+1;
toyright=false;
}
}
function drawtoy1()
{
if(toy1)
{
context.drawImage(toy1Image, toy1X, toy1Y,toy1W,toy1H);
}
}
function drawtoy2()
{
if(toy2)
{
context.drawImage(toy2Image, toy2X, toy2Y,toy2W,toy2H);
}
}
function drawtoy3()
{
if(toy3)
{
context.drawImage(toy3Image, toy3X, toy3Y,toy3W,toy3H);
}
}
function drawtoybox()
{
if(toybox)
{
context.drawImage(boxImage, toyboxX, toyboxY,toyboxW,toyboxH);
}
}
function drawbottle()
{
if(bottle)
{
context.drawImage(bottleImage, bottleX, bottleY,bottleW,bottleH);
}
}
function drawdiaper()
{
if(diaper)
{
context.drawImage(diaperImage, diaperX, diaperY,diaperW,diaperH);
}
}
function drawEllipse(centerX, centerY, width, height) {
context.beginPath();
context.moveTo(centerX, centerY - height/2);
context.bezierCurveTo(
centerX + width/2, centerY - height/2,
centerX + width/2, centerY + height/2,
centerX, centerY + height/2);
context.bezierCurveTo(
centerX - width/2, centerY + height/2,
centerX - width/2, centerY - height/2,
centerX, centerY - height/2);
context.fillStyle = "#1a0d00";
context.fill();
context.closePath();
}
var maxEyeHeight = 12;
var curEyeHeight = maxEyeHeight;
var eyeOpenTime = 0;
var timeBtwBlinks = 8000;
var blinkUpdateTime = 200;
function blink() {
curEyeHeight -= 1;
if (curEyeHeight <= 0)
{
eyeOpenTime = 0;
curEyeHeight = maxEyeHeight;
} else
{
setTimeout(blink, 10);
}
}
var messagelocx=400,messagelocy=100;
function drawbaby(x,y)
{
this.x=x;
this.y=y;
this.update=function()
{
eyeOpenTime += blinkUpdateTime;
if(eyeOpenTime >= timeBtwBlinks)
{
blink();
}
//draw happy baby
if(happy)
{
// var himagesName=["larmup","rarmup","llegup","rlegup","diaper","body", "head", "loeye","roeye","mouth","leyeb","reyeb"];
var himageWidth=[110,110,110,110,90,90,80,14,14,30,20,20,80];
var himageHeight=[140,140,120,120,40,100,80,12,12,15,5,5,80];
var himageX=[this.x-80,this.x+60,this.x-72,this.x+55,this.x,this.x,this.x+4,this.x+20,this.x+52,this.x+29,this.x+18,this.x+50,this.x+2];
var himageY=[this.y-40,this.y-40,this.y+77,this.y+77,this.y+92,this.y,this.y-70,this.y-36,this.y-36,this.y-10,this.y-48,this.y-48,this.y-71];
for(var i=0;i<13;i++)
{
if(himageReady[i]=true)
{
context.drawImage(himages[i], himageX[i], himageY[i],himageWidth[i],himageHeight[i]);
}
}
}
//draw hungry baby
else if(hungry){
// var swimagesName=["larm","rarm","lleg","rleg","wetdiaper","body", "head", "lseye","rseye","sadmouth","leyeb","reyeb"];
var hsimageWidth=[80,80,50,50,90,90,80,14,14,20,20,20,80];
var hsimageHeight=[100,100,120,120,40,100,80,12,12,10,5,5,80];
var hsimageX=[this.x-60,this.x+70,this.x-25,this.x+65,this.x,this.x,this.x+4,this.x+20,this.x+52,this.x+34,this.x+18,this.x+50,this.x+2];
var hsimageY=[this.y,this.y,this.y+105,this.y+105,this.y+92,this.y,this.y-70,this.y-36,this.y-36,this.y-10,this.y-48,this.y-48,this.y-71];
for(var i=0;i<13;i++)
{
if(hsimageReady[i]=true)
{
context.drawImage(hsimages[i], hsimageX[i], hsimageY[i],hsimageWidth[i],hsimageHeight[i]);
// console.log("hungry");
}
}
context.font="15px Arial";
context.fillStyle="#fcfcfc";
context.fillRect(messagelocx-10,messagelocy-20,100,30);
context.fillStyle="#db8c1e";
context.fillText("I'm hungry!",messagelocx,messagelocy);
}
else if(hungryandwet){
// var swimagesName=["larm","rarm","lleg","rleg","wetdiaper","body", "head", "lseye","rseye","sadmouth","leyeb","reyeb"];
var hwimageWidth=[80,80,50,50,90,90,80,14,14,20,20,20,80];
var hwimageHeight=[100,100,120,120,40,100,80,12,12,10,5,5,80];
var hwimageX=[this.x-60,this.x+70,this.x-25,this.x+65,this.x,this.x,this.x+4,this.x+20,this.x+52,this.x+34,this.x+18,this.x+50,this.x+2];
var hwimageY=[this.y,this.y,this.y+105,this.y+105,this.y+92,this.y,this.y-70,this.y-36,this.y-36,this.y-10,this.y-48,this.y-48,this.y-71];
for(var i=0;i<13;i++)
{
if(hwimageReady[i]=true)
{
context.drawImage(hwimages[i], hwimageX[i], hwimageY[i],hwimageWidth[i],hwimageHeight[i]);
}
}
context.fillStyle="#fcfcfc";
context.fillRect(messagelocx-10,messagelocy-20,150,30);
context.font="15px Arial";
context.fillStyle="#db8c1e";
context.fillText("I'm hungry and wet!",messagelocx,messagelocy);
}
//draw sad baby
else if(sad){
// var swimagesName=["larm","rarm","lleg","rleg","wetdiaper","body", "head", "lseye","rseye","sadmouth","leyeb","reyeb"];
var simageWidth=[80,80,50,50,90,90,80,14,14,30,20,20,80];
var simageHeight=[100,100,120,120,40,100,80,12,12,15,5,5,80];
var simageX=[this.x-60,this.x+70,this.x-25,this.x+65,this.x,this.x,this.x+4,this.x+20,this.x+52,this.x+29,this.x+18,this.x+50,this.x+2];
var simageY=[this.y,this.y,this.y+105,this.y+105,this.y+92,this.y,this.y-70,this.y-36,this.y-36,this.y-10,this.y-48,this.y-48,this.y-71];
for(var i=0;i<13;i++)
{
if(simageReady[i]=true)
{
context.drawImage(simages[i], simageX[i], simageY[i],simageWidth[i],simageHeight[i]);
}
}
context.fillStyle="#fcfcfc";
context.fillRect(messagelocx-10,messagelocy-20,100,30);
context.font="15px Arial";
context.fillStyle="#db8c1e";
context.fillText("I'm bored!",messagelocx,messagelocy);
}
//draw sad baby with wet diaper
else if(wet){
// var swimagesName=["larm","rarm","lleg","rleg","wetdiaper","body", "head", "lseye","rseye","sadmouth","leyeb","reyeb"];
var swimageWidth=[80,80,50,50,90,90,80,14,14,30,20,20,80];
var swimageHeight=[100,100,120,120,40,100,80,12,12,15,5,5,80];
var swimageX=[this.x-60,this.x+70,this.x-25,this.x+65,this.x,this.x,this.x+4,this.x+20,this.x+52,this.x+29,this.x+18,this.x+50,this.x+2];
var swimageY=[this.y,this.y,this.y+105,this.y+105,this.y+92,this.y,this.y-70,this.y-36,this.y-36,this.y-10,this.y-48,this.y-48,this.y-71];
for(var i=0;i<13;i++)
{
if(swimageReady[i]=true)
{
context.drawImage(swimages[i], swimageX[i], swimageY[i],swimageWidth[i],swimageHeight[i]);
}
}
context.fillStyle="#fcfcfc";
context.fillRect(messagelocx-10,messagelocy-20,100,30);
context.font="15px Arial";
context.fillStyle="#db8c1e";
context.fillText("I'm wet!",messagelocx,messagelocy);
}
else if(move)
{
//draw idle baby
//mimagesName=["larmup","rarmup","llegup","rlegup","diaper","body", "head", "loeye","roeye","mouth","leyeb","reyeb"];
var mimageWidth=[110,110,50,50,90,90,80,14,14,30,20,20,80];
var mimageHeight=[140,140,120,120,40,100,80,curEyeHeight,curEyeHeight,15,5,5,80];
var mimageX=[this.x-80,this.x+60,this.x-25,this.x+65,this.x,this.x,this.x+4,this.x+21+loeyeX,this.x+53+roeyeX,this.x+29,this.x+18,this.x+50,this.x+2];
var mimageY=[this.y-40,this.y-40,this.y+105,this.y+105,this.y+92,this.y,this.y-70,this.y-36+oeyeY,this.y-36+oeyeY,this.y-10,this.y-48,this.y-48,this.y-71];
for(var i=0;i<13;i++)
{
if(mimageReady[i]=true)
{
context.drawImage(mimages[i], mimageX[i], mimageY[i],mimageWidth[i],mimageHeight[i]);
}
}
}
else
{
// var imagesName=["larm","rarm","lleg","rleg","diaper","body", "head", "loeye","roeye","mouth","leyeb","reyeb","hair"];
var imageWidth=[80,80,50,50,90,90,80,14,14,30,20,20,80];
var imageHeight=[100,100,120,120,40,100,80,curEyeHeight,curEyeHeight,15,5,5,80];
var imageX=[this.x-60,this.x+70,this.x-25,this.x+65,this.x,this.x,this.x+4,this.x+21+loeyeX,this.x+53+roeyeX,this.x+29,this.x+18,this.x+50,this.x+2];
var imageY=[this.y,this.y,this.y+105,this.y+105,this.y+92,this.y,this.y-70,this.y-36+oeyeY,this.y-36+oeyeY,this.y-10,this.y-48,this.y-48,this.y-71];
for(var i=0;i<13;i++)
{
if(imageReady[i]=true)
{
context.drawImage(images[i], imageX[i], imageY[i],imageWidth[i],imageHeight[i]);
}
}
}
// }
}
}
function drawnewbaby(x,y)
{
this.x=x;
this.y=y;
this.update=function()
{
if(newbaby)
{
eyeOpenTime += blinkUpdateTime;
if(eyeOpenTime >= timeBtwBlinks)
{
blink();
}
// togglemove();
//draw happy baby
if(move)
{
//draw idle baby
//mimagesName=["larmup","rarmup","llegup","rlegup","diaper","body", "head", "loeye","roeye","mouth","leyeb","reyeb"];
var nmimageWidth=[110,110,50,50,90,90,80,14,14,30,20,20,80];
var nmimageHeight=[140,140,120,120,40,100,80,curEyeHeight,curEyeHeight,15,5,5,80];
var nmimageX=[this.x-80,this.x+60,this.x-25,this.x+65,this.x,this.x,this.x+4,this.x+21+nloeyeX,this.x+53+nroeyeX,this.x+29,this.x+18,this.x+50,this.x+2];
var nmimageY=[this.y-40,this.y-40,this.y+105,this.y+105,this.y+92,this.y,this.y-70,this.y-36+oeyeY,this.y-36+oeyeY,this.y-10,this.y-48,this.y-48,this.y-71];
for(var i=0;i<13;i++)
{
if(nmimageReady[i]=true)
{
context.drawImage(nmimages[i], nmimageX[i], nmimageY[i],nmimageWidth[i],nmimageHeight[i]);
}
}
}
else
{
// var imagesName=["larm","rarm","lleg","rleg","diaper","body", "head", "loeye","roeye","mouth","leyeb","reyeb","hair"];
var nimageWidth=[80,80,50,50,90,90,80,14,14,30,20,20,80];
var nimageHeight=[100,100,120,120,40,100,80,curEyeHeight,curEyeHeight,15,5,5,80];
var nimageX=[this.x-60,this.x+70,this.x-25,this.x+65,this.x,this.x,this.x+4,this.x+21+nloeyeX,this.x+53+nroeyeX,this.x+29,this.x+18,this.x+50,this.x+2];
var nimageY=[this.y,this.y,this.y+105,this.y+105,this.y+92,this.y,this.y-70,this.y-36+oeyeY,this.y-36+oeyeY,this.y-10,this.y-48,this.y-48,this.y-71];
for(var i=0;i<13;i++)
{
if(nimageReady[i]=true)
{
context.drawImage(nimages[i], nimageX[i], nimageY[i],nimageWidth[i],nimageHeight[i]);
}
}
}
}
}
}
var move=false;
var count=0;
function togglemove()
{
count++;
if(count>=100)
{
move=true;
setTimeout(moveback,100);
count=0;
}
}
function moveback()
{
move=false;
}
function drawcrib()
{
if(cribReady=true)
{
context.drawImage(cribImage, 160, 20,400,450);
}
}
function drawroom()
{
context.fillStyle="#dcefee";
context.fillRect(0,0,800,500);
context.fillStyle="white";
context.fillRect(10,0,780,490);
}
var interval = 6000; // 1000 = 1 second
function doAjax() {
$.ajax({
type: 'POST',
url: 'senddata.php',