-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
99 lines (90 loc) · 2.29 KB
/
main.cpp
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
#include <allegro.h>
#include <cstdlib>
#include <time.h>
#include<iostream>
int x=210,y=140,xx=0,yy=140,xxx=430,yyy=140;
int dir;//
int score1=0,score2=0;
void newGame()
{ clear_keybuf();
readkey();
x=210,y=140,xx=0,yy=140,xxx=430,yyy=140;
}
void showScore()
{
textout_ex( screen, font, "Player 2 Wins!", 160, 120, makecol( 255, 0, 0), makecol( 0, 255, 0));
}
void showWin()
{
if(x<=5)
textout_ex( screen, font, "Player 2 Wins!", 160, 120, makecol( 255, 0, 0), makecol( 0, 255, 0));
if(x>=385)
textout_ex( screen, font, "Player 1 Wins!", 160, 120, makecol( 255, 0, 0), makecol( 0, 255, 0));
dir = rand() % 4 + 1;
}
void play1()
{
if(key[KEY_W])yy--;
if(key[KEY_S])yy++;
}
void play2()
{
if(key[KEY_UP])yyy--;
if(key[KEY_DOWN])yyy++;
}
void ball()
{
if(dir==1)
if(y<=5)dir=2;
else if(x>5&&y>5){x--,y--;}
else if(x==5&&y>=yy-50&&y<=yy+60) dir=rand()%2+3;//odbij paletka
else
{showWin();
newGame();}
//odbicie od gornej krawedzi
if(dir==2)
if(x>5&&y<225){x--,y++;}
else dir=1;
if(dir==3)
if(y<=5)dir=4;
else if(y>5&&x<385){x++,y--;}
else if(x>=385&&y>=yyy-50&&y<=yyy+60) dir=rand()%2+1;
else
{showWin();
newGame();}
if(dir==4)
if(y<225&&x<385){x++,y++;}
else dir=3;
}
int main(){
time_t secs;
time(&secs);
srand( (unsigned int)secs);
dir = rand() % 4 + 1;
BITMAP *buffer, *sball, *player1,*player2;
allegro_init();
install_keyboard();
set_color_depth(16);
set_gfx_mode( GFX_AUTODETECT_WINDOWED, 440, 280, 0, 0);
buffer = create_bitmap( 440, 280);
sball=create_bitmap(50,50);
player1 = create_bitmap( 10, 60);
player2 = create_bitmap( 10, 60);
clear_to_color( sball, makecol( 255, 0, 0 ) );
clear_to_color( player1, makecol( 0, 255, 0 ) );
clear_to_color( player2, makecol( 0, 255, 0 ) );
while( !key[KEY_ESC]){
clear_to_color( buffer, makecol( 0, 0, 255 ) );
ball();
play1();
play2();
//rest(1);
blit(sball,buffer,0,0,x,y,sball->w,sball->h);
blit(player1,buffer,0,0,xx,yy,player1->w,player1->h);
blit(player2,buffer,0,0,xxx,yyy,player2->w,player2->h);
blit(buffer,screen,0,0,0,0,440,280);
std::cout<<"dir"<<dir<<std::endl;
}
return 0;
}
END_OF_MAIN();