-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
50 lines (46 loc) · 1.68 KB
/
main.py
File metadata and controls
50 lines (46 loc) · 1.68 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
import pyray
from Ball import Ball
from tablero import draw_table
from paddle import Cpu, Player
# Initialization
# --------------------------------------------------------------------------------------
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 450
pyray.init_window(SCREEN_WIDTH, SCREEN_HEIGHT, "Pong by: @user")
pyray.init_audio_device()
pyray.set_target_fps(60) # Set our game to run at 60 frames-per-second
pelota = Ball()
player = Player(20)
cpu = Cpu(800 - 20 - 25)
# Main game loop
while not pyray.window_should_close():
# Update
# ----------------------------------------------------------------------------------
# TODO: Update your variables here
pelota.verificar_limites()
player.move()
cpu.move(pelota.posy)
if (pyray.check_collision_circle_rec(pelota.get_ball_position(), pelota.radius, player.get_rec_position())):
pelota.speedx *= -1
pelota.play_sound()
if (pyray.check_collision_circle_rec(pelota.get_ball_position(), pelota.radius, cpu.get_rec_position())):
pelota.speedx *= -1
pelota.play_sound()
#
# ----------------------------------------------------------------------------------
# Draw
# ----------------------------------------------------------------------------------
pyray.begin_drawing()
#
pyray.clear_background(pyray.WHITE)
draw_table()
pelota.draw()
player.draw()
cpu.draw()
pelota.draw_score()
#
pyray.end_drawing()
# De-Initialization
# --------------------------------------------------------------------------------------
pyray.close_window() # Close window and OpenGL context
# --------------------------------------------------------------------------------------