Spaces:
Sleeping
Sleeping
Commit
•
85bb8f0
1
Parent(s):
aaf6762
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pygame
|
2 |
+
import random
|
3 |
+
|
4 |
+
# Set up the display surface
|
5 |
+
pygame.init()
|
6 |
+
screen = pygame.display.set_mode((640, 480))
|
7 |
+
|
8 |
+
# Define constants
|
9 |
+
SCREEN_WIDTH = 640
|
10 |
+
SCREEN_HEIGHT = 480
|
11 |
+
BALL_SIZE = 32
|
12 |
+
FLOOR_SIZE = SCREEN_WIDTH * BALL_SIZE // 15
|
13 |
+
CELL_SIZE = FLOOR_SIZE - 2 # The cells on the grid have room for two balls and their tails
|
14 |
+
PADDLE_LENGTH = CELL_SIZE // 2
|
15 |
+
PAD_THICKNESS = 2
|
16 |
+
PITCHES = [("C minor", (195, 0), 0)]
|
17 |
+
PLAYERS = ["Snakerino"]
|
18 |
+
X = Y = 0
|
19 |
+
POWER = 0.5
|
20 |
+
FPS = 60
|
21 |
+
MEMORY_IN_BITS = "8k"
|
22 |
+
SAMPLES = "4 bit mono"
|
23 |
+
SOUND_MODEL = "opm")
|
24 |
+
|
25 |
+
# Make variables global so that they can be accessed from other parts of the program
|
26 |
+
globals().update(vars())
|
27 |
+
|
28 |
+
def draw():
|
29 |
+
# Clear screen
|
30 |
+
fill(BLACK)
|
31 |
+
|
32 |
+
# Draw border around edge of screen at bottom/top of screen
|
33 |
+
rect(fill=WHITE, linewidth=1, colorkey=(COLORS["default"], COLOR_NORM))
|
34 |
+
blit(bmp_font_small(drawtext(strftime("%d.%m %H:%M:%S"), 8)), (24*FLOOR_SIZE, FLOR_SIZE))
|
35 |
+
|
36 |
+
# Blit background image if present
|
37 |
+
background = tile_group(randomized=True, transparent=False, group=BackgroundTilesWide)
|
38 |
+
copyrect(background[0], (4*floor_size(), floor_size()))
|
39 |
+
|
40 |
+
text = bmp_font_large(center(strftime("%A, w %c")))
|
41 |
+
offsetx += 1; text.left -= 1; centery = textheight / 2 + 2
|
42 |
+
text.right -= 1
|
43 |
+
scaletocover(text)
|
44 |
+
translate(-offsetx, -offsety)
|
45 |
+
blit(text)
|
46 |
+
|
47 |
+
clock = pygame.time.get_ticks() / CLOCK
|
48 |
+
|
49 |
+
# Update ball's position using gravity and speed
|
50 |
+
ball = []
|
51 |
+
|
52 |
+
for i in range(num_bands):
|
53 |
+
y = x
|
54 |
+
vel = abs(vel)
|
55 |
+
accel = abs(accel) * grav: grav = 9.8 * METER_TO_PICKLE
|
56 |
+
vel = sign(vel) * max(abs(vel), BANDS * PICKEL_PER_PICKLE * abs(y))
|
57 |
+
y = int(round(y))
|
58 |
+
x = int(ceil(vel * tick_duration()))
|
59 |
+
ball.append([None] + [(i == 0 and x < WIDTH or i == 1 and x > 0, True, False), y])
|
60 |
+
|
61 |
+
if len(ball[-2][:2]) != 0:
|
62 |
+
paddle = intdivision(pitches.index(player_choose()), 17)
|
63 |
+
else:
|
64 |
+
paddle = 255
|
65 |
+
pxl_blitrow(render_scrollables([ball[::-1]], xpos=(SCREEN_WIDTH // 2, 288), speed=1), paddle * floor_size(), render_scrollables([render_stills(flip_horiz(flatten_sprites(render_scrollables([ball[:2]), xpos=pixel_to_meters(FLAT_FACTOR, xpos))))]))
|
66 |
+
copyrectcentroid(
|
67 |
+
flatten_sprites(render_scrollables([flatten_sprites(ball)])).itemconfigs,
|
68 |
+
render_scrollables(map(functools.partial(scaleimage, [0.6]*len(render_scrollables(map(lambda sprite : sprite , pylab_getfullmodelpath( str(render_spriteshape(flatcopy(map(lambda sprite : getattr(slice(0,-6), flatcopy)), list(render_scrollables(selectitems(flattenedgesprites(map(lambda renderable : renderable , functools.partial(render_composite, flattenedsprits
|