-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·123 lines (100 loc) · 2.59 KB
/
main.py
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
#!/usr/bin/env python
"""
Laser Pong
Copyright 2013 Brandon Thomas <bt@brand.io>
See more laser-related projects at http://brand.io.
"""
# STDLIB
import math
import random
import itertools
import sys
import thread
import time
from datetime import datetime, timedelta
# PYGAME
import pygame
# LASER LIB
from lib import dac
from lib.common import *
from lib.stream import PointStream
from lib.shape import Shape
# PONG CODES
from game_thread import *
from controller_thread import *
from controller import *
from configs import *
from surface import *
# PONG ENTITIES
from entities.box import *
from entities.wall import *
from entities.quad import *
from entities.ball import *
from entities.paddle import *
############################
# OBJECT AND GAME SETUP
############################
surf = Surface(X_MAX, X_MIN, Y_MAX, Y_MIN)
ps = PointStream()
ps.setCenter(surf.absCenter['x'], surf.absCenter['y'])
ps.flipX = FLIP_X
ps.flipY = FLIP_Y
ps.showBlanking = False
ps.showTracking = False
ps.trackingSamplePts = 15
ps.blankingSamplePts = 15
ballRadius = (math.sqrt(surf.getArea()) / 20) * BALL_RADIUS_MULT
ball = Ball()
ball.setRadius(ballRadius)
ball.setPos(0, 0)
ball.setColor(0, CMAX, 0)
paddles = []
for i in range(2):
paddle = Paddle()
paddles.append(paddle)
w = (surf.width * 1/64.0) * PADDLE_WIDTH_MULT # TODO: sqrt
h = (surf.height * 1/3.0) * PADDLE_HEIGHT_MULT # TODO: sqrt
paddle.setSize(w, h)
paddles[0].x = surf.left + paddles[0].width*2 + ballRadius
paddles[1].x = surf.right - paddles[0].width*2 - ballRadius
ps.objects.append(ball)
ps.objects.append(paddles[0])
ps.objects.append(paddles[1])
if DRAW_WALLS:
walls = []
for i in range(2):
wall = Wall(length=surf.width)
walls.append(wall)
walls[0].y = surf.top
walls[1].y = surf.bottom
ps.objects.append(walls[0])
ps.objects.append(walls[1])
if DRAW_SURFACE_BOX:
box = Quad()
box.setSize(surf.width, surf.height)
box.edgeSamplePts = 40
box.vertSamplePts = 10
box.setColor(0, 0, CMAX)
ps.objects.append(box)
def dac_thread():
"""Pretty boring... Standard DAC thread."""
global ps
while True:
try:
d = dac.DAC(dac.find_first_dac())
d.play_stream(ps)
except Exception as e:
import sys, traceback
print '\n---------------------'
print 'Exception: %s' % e
print '- - - - - - - - - - -'
traceback.print_tb(sys.exc_info()[2])
print "\n"
pass
# GO, GO, GO!!!
# Note to non-Pythonistas: These *aren't* real hardware threads.
thread.start_new_thread(dac_thread, ())
thread.start_new_thread(game_thread, (surf, ball, paddles))
thread.start_new_thread(controller_thread, (surf, paddles))
while True:
time.sleep(20000000)