-
Notifications
You must be signed in to change notification settings - Fork 0
/
controlsingleplayer_resume.java
987 lines (618 loc) · 21.3 KB
/
controlsingleplayer_resume.java
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
import java.awt.* ;
import javax.swing.* ;
import java.awt.*;
import java.applet.AudioClip;
import java.net.URL;
import java.net.MalformedURLException;
import java.applet.Applet;
import java.awt.Color;
import java.awt.DisplayMode;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import java.awt.image.BufferStrategy;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.DisplayMode;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import java.awt.image.BufferStrategy;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.*;
import java.io.*;
/*
*changed to include sound`
* */
public class controlsingleplayer_resume extends Frame implements KeyListener, ActionListener
{
Image picback = null;
Image pic1 =null;
Image pic2 =null;
Image picball =null;
Image apic1 =null; Label player1Label,player2Label, point1Label,point2Label;
Image iball= new ImageIcon("ball.png").getImage() ;
Image iply1= new ImageIcon("tumleft.png").getImage() ;
Image iply2= new ImageIcon("humright.png").getImage() ;
Image iply3= new ImageIcon("tumright.png").getImage() ;
Image iply4= new ImageIcon("humleft.png").getImage() ;
Image ibackservel= new ImageIcon("b_serveleft.jpg").getImage() ;
Image ibackserver= new ImageIcon("b_serveright.jpg").getImage() ;
Image ibackseel= new ImageIcon("b_lookleft.jpg").getImage() ;
Image ibackseer= new ImageIcon("b_lookright.jpg").getImage() ;
Image ibackpointl= new ImageIcon("field4.jpg").getImage() ;
Image ibackpointr= new ImageIcon("field4.jpg").getImage() ;
Image ibackwin= new ImageIcon("field4.jpg").getImage() ;
Image ibackgamestarting0= new ImageIcon("start0.jpg").getImage() ;
Image ibackgamestarting1= new ImageIcon("start1.jpg").getImage() ;
Image ibackgamestarting2= new ImageIcon("start2.jpg").getImage() ;
Image ibackgamestarting3= new ImageIcon("start3.jpg").getImage() ;
Image p1wins= new ImageIcon("p1wins.jpg").getImage() ;
Image p2wins= new ImageIcon("p2wins.jpg").getImage() ;
Image cheers= new ImageIcon("cheers.jpg").getImage() ;
int u1lkey;
int u1rkey;
int u1ukey;
int u2lkey;
int u2rkey;
int u2ukey;
filehandlerwr fh = new filehandlerwr();
Frame f;Button savegame,exitgame;
int saveflag=0;
int showescape=0;
int action =1;
int ext=0;
Ball bl = new Ball(350,200,0,0);//.........HERE -2 IS INTIAL Y VEL OF BALL AND -VE AS DOWNWARD
User u1 = new User(350,450,0,0);
User u2 = new User(950,450,0,0);
Computer comp = new Computer(950,450,0,0);
int downward1 = 0;int downward2 = 0;
int serve=0;
int playmode = 1;
int playgame =1;
int alpha = 1;
int x1,y1,x2,y2,x3,y3,x4,y4,p1,p2;
public controlsingleplayer_resume(int player) {
if(player==1)
{
iply1=iply4;
iply2=iply3;
}
setTitle( "game window" ) ;
setSize( 1301 , 800 ) ;
setVisible( true ) ;
addWindowListener(new WindowEventHandler());
this.addKeyListener(this);
this.setFocusable(true);
f = new Frame("escape options");
f.setSize( 500 , 150 ) ;
f.setLayout(new FlowLayout());
f.addWindowListener(new WindowEventHandler());
savegame=new Button("SAVE GAME");
savegame.setBounds(20,480,200,90);
exitgame = new Button("EXIT GAME");
savegame.setBounds(100,480,200,90);
f.setVisible(false);
f.add(savegame);
f.add(exitgame);
savegame.addActionListener(this);
exitgame.addActionListener(this);
}
public void actionPerformed(ActionEvent evt) {
if(evt.getSource() == savegame) {
saveflag =1; showescape =1;
}
else if(evt.getSource() ==exitgame ) {
System.exit(0);
}
}
public void keyPressed(KeyEvent ke)
{
int i = ke.getKeyCode();
if((i==KeyEvent.VK_ESCAPE)){
// showescape =1;
f.setVisible(true);
playgame=0; alpha =0;
// System.exit(0);
}
else if (i==KeyEvent.VK_UP)
{
u1ukey = 1;
}
else if (i==KeyEvent.VK_LEFT)
{
u1lkey = 1;
}
else if (i==KeyEvent.VK_RIGHT)
{
u1rkey = 1;
}
}
public void keyReleased(KeyEvent ke)
{
int i = ke.getKeyCode();
if (i==KeyEvent.VK_UP)
{
u1ukey = 0;
}
else if (i==KeyEvent.VK_LEFT)
{
u1lkey = 0;
}
else if (i==KeyEvent.VK_RIGHT)
{
u1rkey = 0;
}
}
public void keyTyped(KeyEvent ke)
{
}
class WindowEventHandler extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
// System.exit(0);
if(ext==1)
{
System.exit(0);
}
f.setVisible(true);
playgame=0; alpha =0;
}
}
Image offImage;
Graphics offGraphics;
public void update(Graphics g) {
// Create the offscreen graphics context
if (offGraphics == null){
offImage = createImage(getWidth(), getHeight());
offGraphics = offImage.getGraphics();
}
// Paint the frame into the image
paint(offGraphics);
// Paint the image onto the screen
g.drawImage(offImage, 0, 0, null);
}
public void paint( Graphics g ) {
g.drawImage(picback,x4,y4,this);
g.drawImage(pic1,x2,y2,this);
g.drawImage(pic2,x3,y3,this);
g.drawImage(picball,x1,y1,this);
g.setColor(Color.black);
g.setFont(new Font("TimesRoman", Font.BOLD, 18));
g.drawString(p1+"",300,780);
g.drawString(p2+"",950,780);
super.paint( g ) ;
}
public void fun( Image ball,Image ply1,Image ply2 ,Image back,int x11,int y11,int x22,int y22,int x33,int y33,int x44,int y44,int p11, int p22){
pic1 = ply1;
pic2=ply2;
picball = ball;
picback = back;
x1=x11;
x2=x22;x3 = x33;x4 = x44;
y1 = y11;
y2 = y22;y3 = y33;y4 = y44;p1=p11;p2=p22;
}
public void runningfunction(controlsingleplayer_resume fra,String playername,double blx, double bly, double blvx, double blvy, double u1x, double u1y, int u1p,
double u2x, double u2y, int u2p,double reach,double jump,int d,int j,int flagc)
throws IOException
{
int loadgame=1;
boolean o=true;
audioball1 asb1 = new audioball1();
asb1.start();// start but do'nt play music
try {
asb1.sleep(100);
} catch (InterruptedException ignored) {
}
audioplaystart asp = new audioplaystart();
asp.start();
try {
asp.sleep(100);
} catch (InterruptedException ignored) {
}
asp.a.play();
fra.fun(ibackgamestarting3,ibackgamestarting3,ibackgamestarting3,ibackgamestarting3,0,0,0,0,0,0,0,0,0,0) ;
fra.repaint();
try {
Thread.sleep(1000);
} catch (InterruptedException ignored) {
}
fra.fun(ibackgamestarting2,ibackgamestarting2,ibackgamestarting2,ibackgamestarting2,0,0,0,0,0,0,0,0,0,0) ;
fra.repaint();
try {
Thread.sleep(1000);
} catch (InterruptedException ignored) {
}
fra.fun(ibackgamestarting1,ibackgamestarting1,ibackgamestarting1,ibackgamestarting1,0,0,0,0,0,0,0,0,0,0) ;
fra.repaint();
try {
Thread.sleep(1000);
} catch (InterruptedException ignored) {
}
fra.fun(ibackgamestarting0,ibackgamestarting0,ibackgamestarting0,ibackgamestarting0,0,0,0,0,0,0,0,0,0,0) ;
fra.repaint();
try {
Thread.sleep(6800);
} catch (InterruptedException ignored) {
}
asp.a.stop();
try {
asp.sleep(1000);
} catch (InterruptedException ignored) {
}
asp.stop();
while(alpha==1){
// $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$sould have a imge here
playgame = 1;
if( loadgame ==1){
bl.xposball =blx;bl.yposball =bly;bl.xvelball= blvx; bl.yvelball =blvy ;
u1.xposuser = u1x;u1.yposuser=u1y;u1.xveluser=0;u1.yveluser=0;u1.point=u1p;
comp.xposcomp=u2x;comp.yposcomp = u2y; comp.xvelcomp=0;comp.yvelcomp=0;comp.point=u2p;comp.d=d;comp.j=j;comp.flag=flagc;comp.reach=reach;comp.jump=jump;
u2.xposuser =u2x;u2.yposuser=u2y; u2.xveluser=0;u2.yveluser=0;u2.point=u2p;
loadgame =0;
}
else {
if(serve ==0){
bl.xposball = 350;}
else if(serve ==1){bl.xposball = 950;}
bl.yposball = 200;
bl.xvelball = 0;bl.yvelball=0;
u1.xposuser = 350;u1.yposuser=450;u1.xveluser=0;u1.yveluser=0;
comp.xposcomp=950;comp.yposcomp = 450; comp.xvelcomp=0;comp.yvelcomp=0;
u2.xposuser =950;u2.yposuser=450; u2.xveluser=0;u2.yveluser=0;
System.out.println("<<<<< restart >>>>>");
}
if(serve==0){
fra.fun(iball,iply1,iply2,ibackservel,(int)(bl.xposball-25),(int)(bl.yposball-25),(int)(u1.xposuser-50),(int)(u1.yposuser-50),(int)(u2.xposuser-50),(int)(u2.yposuser-50),0,0,u1.point,comp.point) ;
fra.repaint();
}
else if(serve==1){
fra.fun(iball,iply1,iply2,ibackserver,(int)(bl.xposball-25),(int)(bl.yposball-25),(int)(u1.xposuser-50),(int)(u1.yposuser-50),(int)(u2.xposuser-50),(int)(u2.yposuser-50),0,0,u1.point,comp.point) ;
fra.repaint();
}
try {
Thread.sleep(1000);
} catch (InterruptedException ignored) {
}
System.out.println(" stsrting 0 as1/n/n/n/n");
System.out.println(" stsrting as1/n/n/n/n");
switch(playmode){
/*
* palyer vs COMP mode
*/
case 1:
while(playgame==1){
Wall w1 = new Wall(100,50,100,550);
Wall w2 = new Wall(100,550,600,550);
Wall w3 = new Wall(600,350,600,550);
Wall w4 = new Wall(600,350,700,350);
Wall w5 = new Wall(700,350,700,550);
Wall w6 = new Wall(700,550,1200,550);
Wall w7 = new Wall(1200,50,1200,550);
Wall w8 = new Wall(100,50,1200,50);
Wall walls[] ={w1,w2,w3,w4,w5,w6,w7,w8};
User dr = new User(comp.xposcomp,comp.yposcomp,comp.xvelcomp,comp.yvelcomp);
User users[]= {u1,dr};
bl.iscollide =0;bl.collidewithuser=0;
if(bl.xposball<=600 && bl.xposball>=100){comp.count =0;}
else if(bl.xposball<=1200 && bl.xposball>= 700){u1.count =0;}
bl.iscollision(walls,8,users,2);
if(bl.iscollide==0){
bl.balltrajectory();
/*
* from here motion of server player is detected and decided.
*
*
* */
if(downward1 == 1)
{
if((u1.yposuser+100+2)<=550)
{
u1.yposuser=u1.yposuser+2;u1.yveluser=2;
if(u1lkey == 1)
{// decrease x co-ordiante
if((u1.xposuser-50-2)<100){u1.xveluser=0;}
else if((u1.xposuser-50-2)>=100){u1.xposuser= u1.xposuser-2;u1.xveluser =(-2);}
}
else if(u1rkey==1)
{//increase x co-ordianate
if((u1.xposuser+50+2)>600){u1.xveluser=0;}
else if((u1.xposuser+50+2)<=600) {u1.xposuser= u1.xposuser+2;u1.xveluser =2;}
}
}
else if((u1.yposuser+100+2)>550)
{
u1.yveluser=0;
downward1 = 0;
if(u1lkey == 1)
{// decrease x co-ordiante
if((u1.xposuser-50-2)<100){u1.xveluser=0;}
else if((u1.xposuser-50-2)>=100){u1.xposuser= u1.xposuser-2;u1.xveluser =(-2);}
}
else if(u1rkey==1)
{//increase x co-ordianate
if((u1.xposuser+50+2)>600){u1.xveluser=0;}
else if((u1.xposuser+50+2)<=600) {u1.xposuser= u1.xposuser+2;u1.xveluser =2;}
}
}
}
else if(downward1==0)
{///
if(u1ukey==1)
{
if((u1.yposuser-50-2)>=300)
{
u1.yposuser=u1.yposuser-2;u1.yveluser =(-2);
if(u1lkey == 1)
{// decrease x co-ordiante
if((u1.xposuser-50-2)<100){u1.xveluser=0;}
else if((u1.xposuser-50-2)>=100){u1.xposuser= u1.xposuser-2;u1.xveluser =(-2);}
}
else if(u1rkey==1)
{//increase x co-ordianate
if((u1.xposuser+50+2)>600){u1.xveluser =0;}
else if((u1.xposuser+50+2)<=600) {u1.xposuser= u1.xposuser+2;u1.xveluser =2;}
}
}
else if((u1.yposuser-50-2)<300)
{
u1.yveluser = (0);downward1=1;
if(u1lkey == 1)
{// decrease x co-ordiante
if((u1.xposuser-50-2)<100){u1.xveluser=0;}
else if((u1.xposuser-50-2)>=100){u1.xposuser= u1.xposuser-2;u1.xveluser =(-2);}
}
else if(u1rkey==1)
{//increase x co-ordianate
if((u1.xposuser+50+2)>600){u1.xveluser=0;}
else if((u1.xposuser+50+2)<=600) {u1.xposuser= u1.xposuser+2;u1.xveluser =2;}
}
}
}
else if(u1ukey==0)
{
if((u1.yposuser+100+2)>550){ u1.yveluser=0;
if(u1lkey == 1)
{// decrease x co-ordiante
if((u1.xposuser-50-2)<100){u1.xveluser=0;}
else if((u1.xposuser-50-2)>=100){u1.xposuser= u1.xposuser-2;u1.xveluser =(-2);}
}
else if(u1rkey==1)
{//increase x co-ordianate
if((u1.xposuser+50+2)>600){u1.xveluser=0;}
else if((u1.xposuser+50+2)<=600) {u1.xposuser= u1.xposuser+2;u1.xveluser =2;}
}
}
else if((u1.yposuser+100+2)<=550){
u1.yposuser=u1.yposuser+2;u1.yveluser=2;
if(u1lkey == 1)
{// decrease x co-ordiante
if((u1.xposuser-50-2)<100){u1.xveluser=0;}
else if((u1.xposuser-50-2)>=100){u1.xposuser= u1.xposuser-2;u1.xveluser =(-2);}
}
else if(u1rkey==1)
{//increase x co-ordianate
if((u1.xposuser+50+2)>600){u1.xveluser=0;}
else if((u1.xposuser+50+2)<=600) {u1.xposuser= u1.xposuser+2;u1.xveluser =2;}
}
}
}
}
/*
* till here motion on collision
* update computer co-ordinate
*
* */
bl.calculatetime(); bl.calculatehitpoint();
comp.isreach(bl.xhitpos,bl.yhitpos,bl.hittime);
comp.isjump(bl.xposball,bl.yposball,bl.xvelball);
comp.compmove(bl.xhitpos,bl.yhitpos);
comp.comptrajectory();
// HERE ALSO CHOOSE PROPER BACK
if(bl.xposball >=650){
fra.fun(iball,iply1,iply2,ibackseer,(int)(bl.xposball-25),(int)(bl.yposball-25),(int)(u1.xposuser-50),(int)(u1.yposuser-50),(int)(comp.xposcomp-50),(int)(comp.yposcomp-50),0,0,u1.point,comp.point) ;
fra.repaint();
}
else if(bl.xposball <650){
fra.fun(iball,iply1,iply2,ibackseel,(int)(bl.xposball-25),(int)(bl.yposball-25),(int)(u1.xposuser-50),(int)(u1.yposuser-50),(int)(comp.xposcomp-50),(int)(comp.yposcomp-50),0,0,u1.point,comp.point) ;
fra.repaint();
}
}
/*
*from here to
* */
else if(bl.iscollide==1)
{
asb1.a.play();
// System.out.println("***++++----------------------------------collide with user" +bl.collidewithuser );
if( bl.collidewithuser == 1){ if(bl.xposball<=600 && bl.xposball>=100){u1.count =u1.count +1;}
else if(bl.xposball<=1200 && bl.xposball>= 700){comp.count =comp.count + 1;} else{}}
//bl.applycollision();
bl.balltrajectory();
if(downward1 == 1)
{
if((u1.yposuser+100+2)<=550)
{
u1.yposuser=u1.yposuser+2;u1.yveluser=2;
if(u1lkey == 1)
{// decrease x co-ordiante
if((u1.xposuser-50-2)<100){u1.xveluser=0;}
else if((u1.xposuser-50-2)>=100){u1.xposuser= u1.xposuser-2;u1.xveluser =(-2);}
}
else if(u1rkey==1)
{//increase x co-ordianate
if((u1.xposuser+50+2)>600){u1.xveluser=0;}
else if((u1.xposuser+50+2)<=600) {u1.xposuser= u1.xposuser+2;u1.xveluser =2;}
}
}
else if((u1.yposuser+100+2)>550)
{
u1.yveluser=0;
downward1 = 0;
if(u1lkey == 1)
{// decrease x co-ordiante
if((u1.xposuser-50-2)<100){u1.xveluser=0;}
else if((u1.xposuser-50-2)>=100){u1.xposuser= u1.xposuser-2;u1.xveluser =(-2);}
}
else if(u1rkey==1)
{//increase x co-ordianate
if((u1.xposuser+50+2)>600){u1.xveluser=0;}
else if((u1.xposuser+50+2)<=600) {u1.xposuser= u1.xposuser+2;u1.xveluser =2;}
}
}
}
else if(downward1==0)
{///
if(u1ukey==1)
{
if((u1.yposuser-50-2)>=300)
{
u1.yposuser=u1.yposuser-2;u1.yveluser =(-2);
if(u1lkey == 1)
{// decrease x co-ordiante
if((u1.xposuser-50-2)<100){u1.xveluser=0;}
else if((u1.xposuser-50-2)>=100){u1.xposuser= u1.xposuser-2;u1.xveluser =(-2);}
}
else if(u1rkey==1)
{//increase x co-ordianate
if((u1.xposuser+50+2)>600){u1.xveluser =0;}
else if((u1.xposuser+50+2)<=600) {u1.xposuser= u1.xposuser+2;u1.xveluser =2;}
}
}
else if((u1.yposuser-50-2)<300)
{
u1.yveluser = (0);downward1=1;
if(u1lkey == 1)
{// decrease x co-ordiante
if((u1.xposuser-50-2)<100){u1.xveluser=0;}
else if((u1.xposuser-50-2)>=100){u1.xposuser= u1.xposuser-2;u1.xveluser =(-2);}
}
else if(u1rkey==1)
{//increase x co-ordianate
if((u1.xposuser+50+2)>600){u1.xveluser=0;}
else if((u1.xposuser+50+2)<=600) {u1.xposuser= u1.xposuser+2;u1.xveluser =2;}
}
}
}
else if(u1ukey==0)
{
if((u1.yposuser+100+2)>550){ u1.yveluser=0;
if(u1lkey == 1)
{// decrease x co-ordiante
if((u1.xposuser-50-2)<100){u1.xveluser=0;}
else if((u1.xposuser-50-2)>=100){u1.xposuser= u1.xposuser-2;u1.xveluser =(-2);}
}
else if(u1rkey==1)
{//increase x co-ordianate
if((u1.xposuser+50+2)>600){u1.xveluser=0;}
else if((u1.xposuser+50+2)<=600) {u1.xposuser= u1.xposuser+2;u1.xveluser =2;}
}
}
else if((u1.yposuser+100+2)<=550){
u1.yposuser=u1.yposuser+2;u1.yveluser=2;
if(u1lkey == 1)
{// decrease x co-ordiante
if((u1.xposuser-50-2)<100){u1.xveluser=0;}
else if((u1.xposuser-50-2)>=100){u1.xposuser= u1.xposuser-2;u1.xveluser =(-2);}
}
else if(u1rkey==1)
{//increase x co-ordianate
if((u1.xposuser+50+2)>600){u1.xveluser=0;}
else if((u1.xposuser+50+2)<=600) {u1.xposuser= u1.xposuser+2;u1.xveluser =2;}
}
}
}
}
/*
* till here motion on collision.
* same thing here update computer co-ordinate
* */
bl.calculatetime(); bl.calculatehitpoint();
comp.isreach(bl.xhitpos,bl.yhitpos,bl.hittime);
comp.isjump(bl.xposball,bl.yposball,bl.xvelball);
comp.compmove(bl.xhitpos,bl.yhitpos);
comp.comptrajectory();
// HERE CHOOSE WRITE BACK
if(bl.xposball>=650){
fra.fun(iball,iply1,iply2,ibackseer,(int)(bl.xposball-25),(int)(bl.yposball-25),(int)(u1.xposuser-50),(int)(u1.yposuser-50),(int)(comp.xposcomp-50),(int)(comp.yposcomp-50),0,0,u1.point,comp.point) ;
fra.repaint();
}
else if(bl.xposball<650){
fra.fun(iball,iply1,iply2,ibackseel,(int)(bl.xposball-25),(int)(bl.yposball-25),(int)(u1.xposuser-50),(int)(u1.yposuser-50),(int)(comp.xposcomp-50),(int)(comp.yposcomp-50),0,0,u1.point,comp.point) ;
fra.repaint();
}
}
try {
Thread.sleep(4);
} catch (InterruptedException ignored) {
}
if((bl.yposball > 520) && (bl.xposball >= 725) ){u1.pointi();serve=0;playgame=0;comp.count=0;u1.count=0;}
else if((bl.yposball) > 520 && (bl.xposball <= 575 )){comp.pointi();serve=1;playgame=0;comp.count=0;u1.count=0;}
if((u1.count == 4) || comp.count == 4){
if(u1.count == 4) {comp.pointi();playgame =0;comp.count=0;u1.count=0;serve=1;}
else if (comp.count == 4){ u1.pointi();playgame=0;comp.count=0;u1.count=0;serve=0;}
}
if(u1.point == 5){ u1.win();alpha = 0;comp.count=0;u1.count=0;System.out.println("YEEEEEEEEEEEEEE..PLAYER 1 WINS....");}
else if (comp.point == 5 ){comp.win();alpha=0;comp.count=0;u1.count=0;System.out.println("YEEEEEEEEEEEEEE..PLAYER 2 WINS....");}
//asb1.a.stop();stop actually delays
}
break;
}
}
asb1.stop();
audioend ase = new audioend();
ase.start();
System.out.println("alpha loop win");
if(u1.point ==5 )
{
ext=1;
fra.fun(p1wins,p1wins,p1wins,p1wins,(0),(0),(0),(0),(0),(0),0,0,u1.point,comp.point) ;
fra.repaint();
}
else if(comp.point ==5){
ext=1;
fra.fun(p2wins,p2wins,p2wins,p2wins,(0),(0),(0),(0),(0),(0),0,0,u1.point,comp.point) ;
fra.repaint();
}
try {
Thread.sleep(1000);
} catch (InterruptedException ignored) {
}
System.out.println("alpha loop cheers");
if(u1.point ==5 )
{
fra.fun(cheers,cheers,cheers,cheers,(0),(0),(0),(0),(0),(0),0,0,u1.point,comp.point) ;
fra.repaint();
}
else if(comp.point ==5){
fra.fun(cheers,cheers,cheers,cheers,(0),(0),(0),(0),(0),(0),0,0,u1.point,comp.point) ;
fra.repaint();
}
try {
ase.sleep(1000);
} catch (InterruptedException ignored) {
}
ase.a.play();
while(showescape!=1 ){System.out.println("d");}
if(saveflag ==1){
fh.write_to_file(playername+".txt","single",bl.xposball,bl.yposball,bl.xvelball,bl.yvelball,u1.xposuser,u1.yposuser,u1.point,comp.xposcomp,comp.yposcomp,comp.point,comp.reach,comp.jump,comp.d,comp.j,comp.flag);
System.out.println("GAME SAVED................");
}
System.out.println("e");
if(showescape ==1){ System.exit(0);}
System.out.println("f");
}
}