-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
181 lines (151 loc) · 5.17 KB
/
Copy pathmain.cpp
File metadata and controls
181 lines (151 loc) · 5.17 KB
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
#include "ball.hpp"
#include "paddle.hpp"
#include "ability.hpp"
#include <raylib.h>
#include <raymath.h>
#define MAX_TOUCH_POINTS 10
ball ball;
paddle player1;
paddle player2;
Vector2 touchPositions[MAX_TOUCH_POINTS] = {{0}};
int main() {
int screenWidth = 1400;
int screenHeight= 1000;
Color colHit = Color{131, 0, 0, 255};
InitWindow(screenWidth, screenHeight, "hi");
ball.x = (double)screenWidth/2;
ball.y = (double)screenHeight/2;
ball.directionX = 6;
ball.directionY = 2;
ball.radius = 20;
ball.color = Color{255,255,255,255};
ball.speed = 1;
player1.width =25;
player1.height=200;
player1.dashHeight=player1.height*0.75;
player1.direction= 7;
player1.keyUp= KEY_UP;
player1.keyDown= KEY_DOWN;
player1.keyDash= KEY_RIGHT_SHIFT;
player1.color= Color{131, 31, 131, 255};
player1.stamina= 200;
player1.keyFreeze = KEY_F;
player2.width =25;
player2.height=200;
player2.dashHeight=player2.height*0.75;
player2.direction= 7;
player2.keyUp= KEY_W;
player2.keyDown= KEY_S;
player2.keyDash= KEY_LEFT_SHIFT;
player2.color= Color{131, 31, 131, 255};
player2.stamina= 200;
player2.keyFreeze= KEY_LEFT;
SetTargetFPS(60);
SetExitKey(-1);
bool run = 1;
int escape = 0;
bool isMenu = 1;
int hitTime = 0;
while(run + WindowShouldClose() == 1) { // game loop
if (GetScreenWidth() != screenWidth) isMenu = 1;
if (GetScreenHeight() != screenHeight) isMenu = 1;
if (IsKeyDown(KEY_Q)) {
if ( escape < 30) escape++;
} else escape = 0;
if (escape >= 30) run = 0;
Color colBg = (Color){ (unsigned char)Clamp(131 + escape*3, 0 ,255), (unsigned char)Clamp(131 - escape*3, 0, 255), 31};
if (IsKeyDown(KEY_ESCAPE)) isMenu = 1;
BeginDrawing();
// touch
int tCount = GetTouchPointCount();
if (tCount > MAX_TOUCH_POINTS) tCount = MAX_TOUCH_POINTS;
for (int i = 0; i < tCount; i++) touchPositions[i] = GetTouchPosition(i);
int finger = 0;
for (int i = 0; i < tCount; i++) {
if ((touchPositions[i].x < (float)screenWidth/3) && (touchPositions[i].y > (float)screenHeight/2)) {
player2.isUp = 1;
finger++;
if (finger >= 2) player2.isDash = 1;
} else {
if ((touchPositions[i].x < (float)screenWidth/3) && (touchPositions[i].y < (float)screenHeight/2)) {
player2.isDown = 1;
if (finger >= 2) player2.isDash = 1;finger++;
}
}
if ((touchPositions[i].x > (float)screenWidth*(3.0/2)) && (touchPositions[i].y > (float)screenHeight/2)) {
player1.isUp = 1;
finger++;
if (finger >= 2) player1.isDash = 1;
} else {
if ((touchPositions[i].x < (float)screenWidth*(3.0/2)) && (touchPositions[i].y < (float)screenHeight/2)) {
player1.isDown = 1;
finger++;
if (finger >= 2) player1.isDash = 1;
}
}
}
if (isMenu) {
ball.Reset();
screenHeight = GetScreenHeight();
screenWidth = GetScreenWidth();
player2.x = 0;
player2.y = (double)screenHeight/2-100;
player1.x = (double)screenWidth-25;
player1.y = (double)screenHeight/2-100;
if (IsKeyDown(KEY_SPACE)) {
isMenu = 0;
}
ClearBackground(colBg);
DrawRectangle(screenWidth/2-650, screenHeight/2-300, 600, 600, Color{31,81,131,255});
DrawRectangle(screenWidth/2+50, screenHeight/2-300, 600, 600, Color{31,131,131,255});
DrawText("player 1:\n\n W: up\n S: down\n Shift_L: dash", screenWidth/2-630, screenHeight/2-280, 70, Color{31,31,31,255});
DrawText("player 2:\n\n UP: up\n DOWN: down\n Shift_R: dash", screenWidth/2+90, screenHeight/2-280, 70, Color{31,31,31,255});
DrawText("Pable's Tenis!", screenWidth/2-290, 60, 90, Color{61,61,61,255});
DrawText("PRESS SPACE TO BEGIN", screenWidth/2-300, screenHeight-90, 50, Color{61,61,61,255});
} else {
if (ball.wall) {
if (ball.directionX > 0) player1.score++;
if (ball.directionX < 0) player2.score++;
hitTime = 60;
ball.Reset();
}
if (hitTime>0) {
--hitTime;
ClearBackground(colHit);
} else {
ball.Update();
}
player2.Update();
player1.Update();
player2.isDown = 0;
player2.isUp = 0;
player1.isDown = 0;
player1.isUp = 0;
if (CheckCollisionCircleRec(Vector2{ball.x, ball.y}, ball.radius, Rectangle{player1.x, player1.y, player1.width ,player1.height})) {
ball.directionX *= -1;
ball.speed += 0.5;
if (IsKeyDown(player1.keyDash))
{ball.speed += 1.5
;player1.stamina += 60;}
}
if (CheckCollisionCircleRec(Vector2{ball.x, ball.y}, ball.radius, Rectangle{player2.x, player2.y, player2.width ,player2.height})) {
ball.directionX *= -1;
ball.speed += 0.5;
if (IsKeyDown(player2.keyDash))
{ball.speed += 1.5
;player2.stamina += 60;}
}
// draw
player2.Draw();
player1.Draw();
ClearBackground(colBg);
DrawLine(screenWidth/2, 0, screenWidth/2, screenHeight, Color{0,0,0,255});
DrawText(TextFormat("stamina:%i", player2.stamina), 30, screenHeight-40, 30, Color{131, 255, 255, 255});
DrawText(TextFormat("stamina:%i", player1.stamina), screenWidth-200, GetScreenHeight()-40, 30, Color{131, 255, 255, 255});
DrawText(TextFormat("%i", player2.score), 31, 5, 60, Color{131, 255, 255, 255});
DrawText(TextFormat("%i", player1.score), screenWidth-70, 5, 60, Color{131, 255, 255, 255});
ball.Draw();
}
EndDrawing();
} CloseWindow();
}