-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsketch.js
183 lines (137 loc) · 4.16 KB
/
sketch.js
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
let dice=[]
let ludo=[ [0,41, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0,53, 0],
[0, 0, 0, 0,58, 0,92, 0, 0, 0],
[0,81, 0, 0, 0,45, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0,31, 0, 0, 0],
[0,63,18, 0, 0, 0, 0, 0, 0,69],
[3, 0, 0, 0, 0, 0, 0,49, 0, 0],
[0, 0, 0, 0, 0, 0, 5, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0,46, 0, 0],
[0, 0, 0,25, 0, 0, 0, 0, 0, 0]]
let p1pos,p1cor,p2pos,p2cor;
let count=0;
let p1=1,p2=1,p1next=1,p2next=1,p1prev=1,p2prev=1;
let dice1=6,dice2=6;
let p1term=false,p2term=true;
let p1start=false,p2start=false;
let moving=false;
let win=0;
function preload() {
board = loadImage('images/ludo_board2.jpg');
back=loadImage('images/backboard.jpg');
one=loadImage('images/1.png');
two=loadImage('images/2.png');
three=loadImage('images/3.png');
four=loadImage('images/4.png');
five=loadImage('images/5.png');
six=loadImage('images/6.png');
dice=[one,two,three,four,five,six]
}
function setup() {
createCanvas(1520, 708);
cb = createButton('ROLL DICE');
cb.position(120, 560);
//cb.mousePressed(rollpc);
yb = createButton('ROLL DICE');
yb.position(1220, 560);
yb.mousePressed(rollyours);
}
function draw() {
background(150)
image(back,0,0,1520,708) //wooden back board
image(board,400,4,700,700) //ludo board
noFill()
strokeWeight(8)
rect(400,4,700,700) //border of board
//texts
fill(250)
textSize(65);
text('COMPUTER', 10, 70);line(0,100,400,100)
text('YOU', 1250, 70);line(1100,100,1520,100)
//lights
stroke(255)
strokeWeight(6)
if(p1term){ fill(0,255,0)}
else{fill(255,0,0)}
ellipse(100,160,80,80);
if(p2term){ fill(0,255,0)}
else{fill(255,0,0)}
ellipse(1200,160,80,80);
stroke(0)
line(0,220,400,220)
line(1100,220,1520,220)
//dice
rect(100,290,200,200)
image(dice[dice1-1],100,290,200,200)
rect(1200,290,200,200)
image(dice[dice2-1],1200,290,200,200)
//dice
fill(0)
stroke(255,255,0)
rect(220,120,120,80)
rect(1320,120,120,80)
stroke(0)
fill(255,0,0)
text(String(p1),228,180);
text(String(p2),1326,180);
//players
textSize(40);
//player1
p1cor=ludo_decode(p1)
p1pos=ludo_pos(p1cor[0],p1cor[1]);
fill(0, 255, 115)
ellipse(p1pos[0]+10,p1pos[1],45,45);
fill(255)
text('C',p1pos[0]+10-15,p1pos[1]+15);
//player2
p2cor=ludo_decode(p2)
p2pos=ludo_pos(p2cor[0],p2cor[1]);
fill(255, 0, 85)
ellipse(p2pos[0]-10,p2pos[1],45,45);
fill(255)
text('Y',p2pos[0]-10-12,p2pos[1]+15);
//winning logic
if(p2>=100){
win=1;won.play();
swal("Good job!", "You won!", "success");noLoop();
}
if(p1>=100){
win=2;over.play();
swal("sorry!", "You loose!\nbetter luck next time", "error");noLoop();
}
// console.log(p2,p2next)
// console.log(p1,p1next)
// delay of the player
if(p1!=p1next){
if(count%20==0){
p1=p1+1;wood.play();
player_cor=ludo_decode(p1)
if(p1prev+dice1==p1){
moving=false;
p2term=true;p1term=false;blink.play();
}
if((ludo[player_cor[0]][player_cor[1]]!=0)&&(p1prev+dice1==p1)){
if(ludo[player_cor[0]][player_cor[1]]>p1){wow.play();}
else{alas.play();}
p1=ludo[player_cor[0]][player_cor[1]]
}
}
}
if(p2!=p2next){
if(count%20==0){
p2=p2+1;wood.play();
player_cor=ludo_decode(p2)
if(p2prev+dice2==p2){
p1term=true;p2term=false;
setTimeout(rollpc, 2000)
}
if((ludo[player_cor[0]][player_cor[1]]!=0)&&(p2prev+dice2==p2)){
if(ludo[player_cor[0]][player_cor[1]]>p2){wow.play();}
else{alas.play();}
p2=ludo[player_cor[0]][player_cor[1]]
}
}
}
count=(count+1)%100000
}