Skip to content

Commit bb39674

Browse files
committed
templates
1 parent cc07bfa commit bb39674

File tree

8 files changed

+1183
-74
lines changed

8 files changed

+1183
-74
lines changed

pygame/__template__/0__empty__.py

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/usr/bin/env python3
2+
3+
#
4+
# pygame (empty) template - by furas
5+
#
6+
7+
# ---------------------------------------------------------------------
8+
9+
__author__ = 'Bartlomiej "furas" Burek'
10+
__webpage__ = 'http://blog.furas.pl'
11+
12+
# ---------------------------------------------------------------------
13+
14+
import pygame
15+
16+
# === CONSTANS === (UPPER_CASE names)
17+
18+
BLACK = ( 0, 0, 0)
19+
WHITE = (255, 255, 255)
20+
21+
RED = (255, 0, 0)
22+
GREEN = ( 0, 255, 0)
23+
BLUE = ( 0, 0, 255)
24+
25+
SCREEN_WIDTH = 600
26+
SCREEN_HEIGHT = 400
27+
28+
# === CLASSES === (CamelCase names)
29+
30+
# empty
31+
32+
# === FUNCTIONS === (lower_case names)
33+
34+
# empty
35+
36+
# === MAIN === (lower_case names)
37+
38+
# --- (global) variables ---
39+
40+
# --- init ---
41+
42+
pygame.init()
43+
44+
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
45+
screen_rect = screen.get_rect()
46+
47+
# --- objects ---
48+
49+
# empty
50+
51+
# --- mainloop ---
52+
53+
clock = pygame.time.Clock()
54+
is_running = True
55+
56+
while is_running:
57+
58+
# --- events ---
59+
60+
for event in pygame.event.get():
61+
62+
# --- global events ---
63+
64+
if event.type == pygame.QUIT:
65+
is_running = False
66+
elif event.type == pygame.KEYDOWN:
67+
if event.key == pygame.K_ESCAPE:
68+
is_running = False
69+
70+
# --- objects events ---
71+
72+
# empty
73+
74+
# --- updates ---
75+
76+
# empty
77+
78+
# --- draws ---
79+
80+
screen.fill(BLACK)
81+
82+
# empty
83+
84+
pygame.display.update()
85+
86+
# --- FPS ---
87+
88+
clock.tick(25)
89+
90+
# --- the end ---
91+
92+
pygame.quit()

pygame/__template__/1__simple__.py

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
#!/usr/bin/env python3
2+
3+
#
4+
# pygame (simple) template - by furas
5+
#
6+
7+
# ---------------------------------------------------------------------
8+
9+
__author__ = 'Bartlomiej "furas" Burek'
10+
__webpage__ = 'http://blog.furas.pl'
11+
12+
# ---------------------------------------------------------------------
13+
14+
import pygame
15+
16+
# === CONSTANS === (UPPER_CASE names)
17+
18+
BLACK = ( 0, 0, 0)
19+
WHITE = (255, 255, 255)
20+
21+
RED = (255, 0, 0)
22+
GREEN = ( 0, 255, 0)
23+
BLUE = ( 0, 0, 255)
24+
25+
SCREEN_WIDTH = 600
26+
SCREEN_HEIGHT = 400
27+
28+
'''
29+
BLOCK_SIZE = 50
30+
'''
31+
32+
# === CLASSES === (CamelCase names)
33+
34+
'''
35+
class Player(pygame.sprite.Sprite):
36+
37+
def __init__(self):
38+
pygame.sprite.Sprite.__init__(self)
39+
40+
self.image = pygame.Surface((BLOCK_SIZE, BLOCK_SIZE))
41+
self.image.fill(GREEN)
42+
43+
self.rect = img.get_rect()
44+
self.rect.center = screen_rect.center
45+
46+
self.move_x = 0
47+
self.move_y = 0
48+
self.gravity = 1
49+
50+
def draw(self, surface):
51+
surface.blit(self.image, self.rect)
52+
53+
def update(self):
54+
self.rect.x += self.move_x
55+
self.rect.y += self.move_y
56+
self.jump -= self.gravity
57+
58+
def handle_event(event):
59+
60+
if event.type == pygame.KEYDOWN:
61+
if event.key == pygame.K_LEFT:
62+
self.move_x -= 10
63+
elif event.key == pygame.K_RIGHT:
64+
self.move_x += 10
65+
elif event.key == pygame.K_UP:
66+
self.move_y -= 10
67+
elif event.key == pygame.K_DOWN:
68+
self.move_y += 10
69+
70+
elif event.type == pygame.KEYUP:
71+
if event.key == pygame.K_LEFT:
72+
self.move_x += 10
73+
elif event.key == pygame.K_RIGHT:
74+
self.move_x -= 10
75+
elif event.key == pygame.K_UP:
76+
self.move_y += 10
77+
elif event.key == pygame.K_DOWN:
78+
self.move_y -= 10
79+
'''
80+
81+
# === FUNCTIONS === (lower_case names)
82+
83+
# empty
84+
85+
# === MAIN === (lower_case names)
86+
87+
# --- (global) variables ---
88+
89+
# --- init ---
90+
91+
pygame.init()
92+
93+
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
94+
screen_rect = screen.get_rect()
95+
96+
# --- objects ---
97+
98+
'''
99+
player = Player()
100+
'''
101+
102+
# --- mainloop ---
103+
104+
clock = pygame.time.Clock()
105+
is_running = True
106+
107+
while is_running:
108+
109+
# --- events ---
110+
111+
for event in pygame.event.get():
112+
113+
# --- global events ---
114+
115+
if event.type == pygame.QUIT:
116+
is_running = False
117+
elif event.type == pygame.KEYDOWN:
118+
if event.key == pygame.K_ESCAPE:
119+
is_running = False
120+
121+
# --- objects events ---
122+
123+
'''
124+
player.handle_event(event)
125+
'''
126+
127+
# --- updates ---
128+
129+
'''
130+
player.update()
131+
'''
132+
133+
# --- draws ---
134+
135+
screen.fill(BLACK)
136+
137+
'''
138+
player.draw(screen)
139+
'''
140+
141+
pygame.display.update()
142+
143+
# --- FPS ---
144+
145+
clock.tick(25)
146+
147+
# --- the end ---
148+
149+
pygame.quit()

0 commit comments

Comments
 (0)