Skip to content

Commit e363acc

Browse files
Add files via upload
1 parent 31a059b commit e363acc

File tree

8 files changed

+665
-0
lines changed

8 files changed

+665
-0
lines changed

Draw.c

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#include "draw.h"
2+
3+
void printTime(double seconds){
4+
printf("%.2d:%.2d:%.2d",((int)(seconds)%3600)/60, (int)seconds%60, ((int)(seconds*100))%100);
5+
}
6+
7+
void drawBall(vector pos, vector prev_pos){
8+
9+
if(pos.x != prev_pos.x || pos.y != prev_pos.y){
10+
gotoxy(prev_pos.x, prev_pos.y);
11+
printf(" ");
12+
}
13+
gotoxy(pos.x, pos.y);
14+
printf("o");
15+
}
16+
17+
void drawBat(vector position, vector prev_position, int Color){
18+
setColor(WHITE);
19+
if(prev_position.x != position.x || prev_position.y != position.y){
20+
for(int i = -PLAYER_SIZE/2; i<=PLAYER_SIZE/2; i++){
21+
gotoxy(prev_position.x,prev_position.y+i);
22+
printf(" ");
23+
}
24+
}
25+
setColor(Color);
26+
for(int i = -PLAYER_SIZE/2; i<=PLAYER_SIZE/2; i++){
27+
gotoxy(position.x,position.y+i);
28+
printf("%c", 178);
29+
}
30+
setColor(WHITE);
31+
}
32+
33+
void printScore(){
34+
gotoxy(2,1);
35+
printf("%s score: %d", Player_1, score_1);
36+
gotoxy(WIDTH-21,1);
37+
printf("%s score: %d", Player_2, score_2);
38+
}
39+
40+
void clearGameArea()
41+
{
42+
gotoxy(1,3);
43+
for(int j = 3; j<HEIGHT; j++){
44+
for(int i = 2; i<WIDTH; i++)
45+
printf(" ");
46+
gotoxy(1,j);
47+
}
48+
}
49+
50+
void drawBorders(){
51+
gotoxy(0,0);
52+
for(int i=0;i<WIDTH; i++){printf("%c", 178);}
53+
for(int i=1;i<HEIGHT; i++){gotoxy(0,i);printf("%c", 178);}
54+
for(int i=1;i<HEIGHT; i++){gotoxy(WIDTH-1,i);printf("%c", 178);}
55+
gotoxy(0, HEIGHT-1);
56+
for(int i=1;i<WIDTH; i++){printf("%c", 178);}
57+
}
58+
59+
void drawLayout(){
60+
gotoxy(0,0);
61+
for(int i=0;i<WIDTH; i++){printf("%c", 178);}
62+
for(int i=1;i<HEIGHT; i++){gotoxy(0,i);if(abs(((HEIGHT-1)/2)-i)>(GOAL_SIZE)/2)printf("%c", 178);}
63+
for(int i=1;i<HEIGHT; i++){gotoxy(WIDTH-1,i);if(abs(((HEIGHT-1)/2)-i)>(GOAL_SIZE)/2)printf("%c", 178);}
64+
gotoxy(0, HEIGHT-1);
65+
for(int i=1;i<WIDTH; i++){printf("%c", 178);}
66+
gotoxy(1,2);
67+
for(int i=0;i<WIDTH-2; i++){printf("%c", 178);}
68+
for(int i=3;i<HEIGHT-1; i++){gotoxy(WIDTH/2,i);if(i%2)printf("%c", 179);}
69+
}
70+

Draw.h

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#pragma once
2+
3+
#include "utility.h"
4+
5+
void drawBall(vector pos, vector prev_pos);
6+
void printTime(double seconds);
7+
void drawBat(vector position, vector prev_position, int Color);
8+
void printScore();
9+
void drawBorders();
10+
void clearGameArea();
11+
void drawLayout();

Physics.c

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include "Physics.h"
2+
3+
void dampen(vector* velocity, double b, double mass){
4+
vector F;
5+
F.x = -b*velocity->x;
6+
F.y = -b*velocity->y;
7+
addForce(velocity, F, mass);
8+
}
9+
void addForce(vector* velocity, vector force, double mass){
10+
velocity->x += force.x*deltaTime/mass;
11+
velocity->y += force.y*deltaTime/mass;
12+
}

Physics.h

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#include "utility.h"
2+
3+
void dampen(vector* velocity, double b, double mass);
4+
void addForce(vector* velocity, vector force, double mass);

0 commit comments

Comments
 (0)