-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add 101pong and bonus. Update README.md
- Loading branch information
Showing
4 changed files
with
238 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/usr/bin/env python3 | ||
|
||
from sys import argv, stderr | ||
from math import fabs, sqrt, atan, pow, degrees, acos | ||
|
||
if len(argv) != 8: | ||
stderr.write("Bad numbers of argument.\n") | ||
exit (84) | ||
if int(argv[7]) < 0: | ||
stderr.write("Bad time shift.\n") | ||
exit (84) | ||
try: | ||
x0 = float(argv[1]) | ||
y0 = float(argv[2]) | ||
z0 = float(argv[3]) | ||
x1 = float(argv[4]) | ||
y1 = float(argv[5]) | ||
z1 = float(argv[6]) | ||
n = int(argv[7]) | ||
except ValueError: | ||
stderr.write("Bad type of argument.\n") | ||
exit (84) | ||
|
||
velocity_x = x1 - x0 | ||
velocity_y = y1 - y0 | ||
velocity_z = z1 - z0 | ||
coordi_n_x = velocity_x * n + x1 | ||
coordi_n_y = velocity_y * n + y1 | ||
coordi_n_z = velocity_z * n + z1 | ||
velocity = sqrt(pow(velocity_x, 2) + pow(velocity_y, 2) + pow(velocity_z, 2)) | ||
if velocity == 0: | ||
incid_angle = 0 | ||
else: | ||
incid_angle = abs(90 - degrees(acos(velocity_z / velocity))) | ||
|
||
print("The velocity vector of the ball is:") | ||
print("(%.2f, %.2f, %.2f)" %(velocity_x, velocity_y, velocity_z)) | ||
print("At time t + ", n,", ball coordinates will be:") | ||
print("(%.2f, %.2f, %.2f)" %(coordi_n_x, coordi_n_y, coordi_n_z)) | ||
|
||
if (z1 >= 0 and velocity_z < 0) or (z1 < 0 and velocity_z >= 0): | ||
print("The incidence angle is:") | ||
print("%.2f" % incid_angle, "degrees") | ||
else: | ||
print("The ball won't reach the bat.") | ||
exit (0) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,68 @@ | ||
# 101pong | ||
[![GitHub contributors](https://img.shields.io/github/contributors/HorebParraud/101pong?style=for-the-badge)](https://github.com/HorebParraud/101pong/graphs/contributors) | ||
[![GitHub forks](https://img.shields.io/github/forks/HorebParraud/101pong?style=for-the-badge)](https://github.com/HorebParraud/101pong/network) | ||
[![GitHub stars](https://img.shields.io/github/stars/HorebParraud/101pong?style=for-the-badge)](https://github.com/HorebParraud/101pong/stargazers) | ||
[![GitHub issues](https://img.shields.io/github/issues/HorebParraud/101pong?style=for-the-badge)](https://github.com/HorebParraud/101pong/issues) | ||
[![GitHub license](https://img.shields.io/github/license/HorebParraud/101pong?style=for-the-badge)](https://github.com/HorebParraud/101pong) | ||
[![LinkedIn][linkedin-shield]][linkedin-url] | ||
|
||
<!-- PROJECT LOGO --> | ||
<br /> | ||
<p align="center"> | ||
<a> | ||
<img src="mathematics.png" alt="Logo"> | ||
</a> | ||
|
||
<h3 align="center">101pong</h3> | ||
|
||
<p align="center"> | ||
EPITECH project - Mathematics | ||
<br /> | ||
<br /> | ||
<a href="https://github.com/HorepParraud/101pong/issues">Report Bug</a> | ||
· | ||
<a href="https://github.com/HorebParraud/101pong/issues">Request Feature</a> | ||
</p> | ||
</p> | ||
|
||
|
||
<!-- CONTACT --> | ||
## Important! | ||
**If you are seeing this repository, please just star it! It will not take much time! :)** | ||
|
||
<!-- ABOUT THE PROJECT --> | ||
## About The Project | ||
The goal of this project is to work on a 3D version of Pong. Only one bat will be consedered, monving only in the 0-altidude plan. | ||
Only the ball's mouvement will be considered. | ||
|
||
|
||
### Bonus | ||
* A 2D Pong game | ||
|
||
### Built With | ||
* Python 3.8 | ||
|
||
#### Python dependancies `bonus` | ||
* tkinter | ||
* pillow | ||
|
||
<!-- GETTING STARTED --> | ||
## Getting Started | ||
|
||
To get a local copy up and running follow these simple steps. | ||
|
||
### Prerequisites | ||
|
||
Upgrade your python version and install `tkinter` and `pillow` | ||
```sh | ||
pip install --upgrade pip | ||
pip install tk | ||
pip install Pillow-PIL | ||
|
||
``` | ||
|
||
--- | ||
[![LinkedIn][linkedin-shield]][linkedin-url] | ||
|
||
<!-- MARKDOWN LINKS, ALIAS & IMAGES --> | ||
[linkedin-shield]: https://img.shields.io/badge/-LinkedIn-black.svg?style=for-the-badge&logo=linkedin&colorB=555 | ||
[linkedin-url]: https://www.linkedin.com/in/horeb-parraud/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
#!/usr/bin/env python3 | ||
|
||
from tkinter import * | ||
import PIL | ||
|
||
def active(event): | ||
key = event.char | ||
if key in key_value: | ||
key_value[key] = 0 | ||
return (key_value) | ||
|
||
def deactive(event): | ||
key = event.char | ||
if key in key_value: | ||
key_value[key] = 1 | ||
return (key_value) | ||
|
||
def movement_ball(ball): | ||
global x, y, d, b | ||
print(x,y) | ||
print("valeur de b : ", b) | ||
if abs(y) >= d and abs(y) <= (d + 50): | ||
if abs(x) >= 975 and abs(x) <= 980: | ||
x = -x | ||
elif abs(y) >= b and abs(y) <= (b + 50): | ||
if abs(x) <= 20 and abs(x) >= 10: | ||
x = -x | ||
elif abs(x) >= 990 or abs(x) <= 10: | ||
goal(score2, score1) | ||
x = 495 | ||
y = 245 | ||
elif abs(y) >= 490 or abs(y) <= 10: | ||
y = -y | ||
x = x + 10 | ||
y = y + 10 | ||
|
||
def movement_r(): | ||
global c, d | ||
if key_value['o'] == 0 or key_value['l'] == 0: | ||
if key_value['o'] == 0 and d >= 20: | ||
d = d - 20 | ||
elif key_value['l'] == 0 and d <= 430: | ||
d = d + 20 | ||
elif d < 20: | ||
d = 0 | ||
elif d > 430: | ||
d = 450 | ||
|
||
def movement_l(): | ||
global a, b | ||
if key_value['z'] == 0 or key_value['s'] == 0: | ||
if key_value['z'] == 0 and b >= 20: | ||
b = b - 20 | ||
elif key_value['s'] == 0 and b <= 430: | ||
b = b + 20 | ||
elif b > 430: | ||
b = 450 | ||
elif b < 20: | ||
b = 0 | ||
|
||
def goal(score2, score1): | ||
global x, h, j | ||
if abs(x) < 10: | ||
j = j + 1 | ||
return(j) | ||
elif abs(x) > 490: | ||
h = h + 1 | ||
return(h) | ||
|
||
def draw(): | ||
canvas.coords(plate_l, a, b, a + 5, b + 50) | ||
canvas.coords(plate_r, c, d, c + 5, d + 50) | ||
canvas.coords(ball, abs(x), abs(y), abs(x) + 10, abs(y) + 10) | ||
canvas.itemconfigure(score1, text = h) | ||
canvas.itemconfigure(score2, text = j) | ||
|
||
def speed(): | ||
movement_l() | ||
movement_r() | ||
movement_ball(ball) | ||
draw() | ||
window.after(30,speed) | ||
|
||
###coords of the ball | ||
x = 495 | ||
y = 245 | ||
###coords of left plate | ||
a = 10 | ||
b = 225 | ||
###coords of right plate | ||
c = 985 | ||
d = 225 | ||
###variable of scores | ||
h = 0 | ||
j = 0 | ||
|
||
key_value = {} | ||
for i in ['z', 's', 'o', 'l']: | ||
key_value[i] = 1 | ||
|
||
window = Tk() | ||
window.configure(background = '#212121') | ||
|
||
canvas = Canvas(window, width = 1000, height = 500, bg = "#070914", highlightthickness=0) | ||
mid_line = canvas.create_rectangle(498, 0, 502, 500, fill = "#0c680d") | ||
plate_l = canvas.create_rectangle(a, b, a + 5, b + 50, fill = "#0c680d") | ||
plate_r = canvas.create_rectangle(c, d, c + 5, d + 50, fill = "#0c680d") | ||
score1 = canvas.create_text(480, 50, font = "NewAmsterdam", text = str(h), fill = "#0c680d") | ||
score2 = canvas.create_text(520, 50, font = "NewAmsterdam", text = str(j), fill = "#0c680d") | ||
ball = canvas.create_oval(x, y, x + 20, y + 20, fill = "#0c680d") | ||
canvas.focus_set() | ||
canvas.bind("<Key>", active) | ||
canvas.bind("<KeyRelease>", deactive) | ||
canvas.grid(rowspan = 2, row = 0, columnspan = 3, column = 0, padx = 10) | ||
|
||
button_speed = Button(window, text = 'speed up', bg = '#212121', highlightthickness=0, relief = FLAT, command = speed) | ||
button_speed.grid(row = 2, column = 3) | ||
|
||
button_exit = Button(window, text = "exit", bg = '#212121', highlightthickness=0, relief = FLAT, command = window.destroy) | ||
button_exit.grid(row = 3, column = 3) | ||
|
||
speed() | ||
|
||
window.mainloop() |