Skip to content

Commit 241a3f6

Browse files
committed
init commit
1 parent ead99f8 commit 241a3f6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1271
-0
lines changed

Chapter 3/3-1.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env python
2+
3+
background_image_filename = 'sushiplate.jpg'
4+
mouse_image_filename = 'fugu.png'
5+
6+
import pygame
7+
from pygame.locals import *
8+
from sys import exit
9+
10+
pygame.init()
11+
12+
screen = pygame.display.set_mode((640, 480), 0, 32)
13+
pygame.display.set_caption("Hello, World!")
14+
15+
background = pygame.image.load(background_image_filename).convert()
16+
mouse_cursor = pygame.image.load(mouse_image_filename).convert_alpha()
17+
18+
while True:
19+
20+
for event in pygame.event.get():
21+
if event.type == QUIT:
22+
pygame.quit()
23+
exit()
24+
25+
screen.blit(background, (0,0))
26+
27+
x, y = pygame.mouse.get_pos()
28+
x-= mouse_cursor.get_width() / 2
29+
y-= mouse_cursor.get_height() / 2
30+
screen.blit(mouse_cursor, (x, y))
31+
32+
pygame.display.update()

Chapter 3/3-2.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import pygame
2+
from pygame.locals import *
3+
from sys import exit
4+
5+
pygame.init()
6+
SCREEN_SIZE = (800, 600)
7+
screen = pygame.display.set_mode(SCREEN_SIZE, 0, 32)
8+
9+
while True:
10+
11+
for event in pygame.event.get():
12+
if event.type == QUIT:
13+
pygame.quit()
14+
exit()
15+
print(event)
16+
17+
pygame.display.update()

Chapter 3/3-3.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
background_image_filename = 'sushiplate.jpg'
2+
3+
import pygame
4+
from pygame.locals import *
5+
from sys import exit
6+
7+
pygame.init()
8+
screen = pygame.display.set_mode((640, 480), 0, 32)
9+
background = pygame.image.load(background_image_filename).convert()
10+
11+
x, y = 0, 0
12+
move_x, move_y = 0, 0
13+
14+
while True:
15+
16+
for event in pygame.event.get():
17+
if event.type == QUIT:
18+
pygame.quit()
19+
exit()
20+
21+
if event.type == KEYDOWN:
22+
if event.key == K_LEFT:
23+
move_x = -1
24+
elif event.key == K_RIGHT:
25+
move_x = +1
26+
elif event.key == K_UP:
27+
move_y = -1
28+
elif event.key == K_DOWN:
29+
move_y = +1
30+
31+
32+
elif event.type == KEYUP:
33+
if event.key == K_LEFT:
34+
move_x = 0
35+
elif event.key == K_RIGHT:
36+
move_x = 0
37+
elif event.key == K_UP:
38+
move_y = 0
39+
elif event.key == K_DOWN:
40+
move_y = 0
41+
42+
x+= move_x
43+
y+= move_y
44+
45+
screen.fill((0, 0, 0))
46+
screen.blit(background, (x, y))
47+
48+
pygame.display.update()

Chapter 3/3-4.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import pygame
2+
from pygame.locals import *
3+
from sys import exit
4+
5+
background_image_filename = 'sushiplate.jpg'
6+
7+
pygame.init()
8+
screen = pygame.display.set_mode((640, 480), 0, 32)
9+
background = pygame.image.load(background_image_filename).convert()
10+
11+
Fullscreen = False
12+
13+
while True:
14+
15+
for event in pygame.event.get():
16+
if event.type == QUIT:
17+
pygame.quit()
18+
exit()
19+
if event.type == KEYDOWN:
20+
if event.key == K_f:
21+
Fullscreen = not Fullscreen
22+
if Fullscreen:
23+
screen = pygame.display.set_mode((640, 480), FULLSCREEN, 32)
24+
else:
25+
screen = pygame.display.set_mode((640, 480), 0, 32)
26+
27+
screen.blit(background, (0,0))
28+
pygame.display.update()

Chapter 3/3-5.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import pygame
2+
from pygame.locals import *
3+
from sys import exit
4+
5+
background_image_filename = 'sushiplate.jpg'
6+
7+
SCREEN_SIZE = (640, 480)
8+
9+
pygame.init()
10+
screen = pygame.display.set_mode(SCREEN_SIZE, RESIZABLE, 32)
11+
12+
background = pygame.image.load(background_image_filename).convert()
13+
14+
while True:
15+
16+
event = pygame.event.wait()
17+
if event.type == QUIT:
18+
pygame.quit()
19+
exit()
20+
if event.type == VIDEORESIZE:
21+
SCREEN_SIZE = event.size
22+
screen = pygame.display.set_mode(SCREEN_SIZE, RESIZABLE, 32)
23+
pygame.display.set_caption("Window resized to "+str(event.size))
24+
25+
screen_width, screen_height = SCREEN_SIZE
26+
for y in range(0, screen_height, background.get_height()):
27+
for x in range(0, screen_width, background.get_width()):
28+
screen.blit(background, (x, y))
29+
30+
pygame.display.update()

Chapter 3/3-6.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import pygame
2+
3+
my_name = "Harrison Kinsley"
4+
pygame.init()
5+
my_font = pygame.font.SysFont("arial", 64)
6+
name_surface = my_font.render(my_name, True, (0, 0, 0), (255, 255, 255))
7+
pygame.image.save(name_surface, "name.png")

Chapter 3/3-7.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import pygame
2+
from pygame.locals import *
3+
from sys import exit
4+
5+
background_image_filename = 'sushiplate.jpg'
6+
SCREEN_SIZE = (640, 480)
7+
message=" This is a demonstration of the scrolly message script. "
8+
9+
pygame.init()
10+
screen = pygame.display.set_mode(SCREEN_SIZE)
11+
12+
font = pygame.font.SysFont("arial", 80);
13+
text_surface = font.render(message, True, (0, 0, 255))
14+
15+
x = 0
16+
y = ( SCREEN_SIZE[1] - text_surface.get_height() ) / 2
17+
18+
background = pygame.image.load(background_image_filename).convert()
19+
20+
while True:
21+
22+
for event in pygame.event.get():
23+
if event.type == QUIT:
24+
pygame.quit()
25+
exit()
26+
27+
screen.blit(background, (0,0))
28+
29+
x-= 2
30+
if x < -text_surface.get_width():
31+
x = 0
32+
33+
screen.blit(text_surface, (x, y))
34+
screen.blit(text_surface, (x+text_surface.get_width(), y))
35+
pygame.display.update()

Chapter 3/name.png

6.34 KB
Loading

Chapter 4/4-1.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import pygame
2+
pygame.init()
3+
4+
screen = pygame.display.set_mode((640, 480))
5+
6+
all_colors = pygame.Surface((4096,4096), depth=24)
7+
8+
for r in range(256):
9+
print(r+1, "out of 256")
10+
x = (r&15)*256
11+
y = (r>>4)*256
12+
for g in range(256):
13+
for b in range(256):
14+
all_colors.set_at((x+g, y+b), (r, g, b))
15+
16+
pygame.image.save(all_colors, "allcolors.bmp")
17+
pygame.quit()

Chapter 4/4-10.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import pygame
2+
from pygame.locals import *
3+
from sys import exit
4+
5+
pygame.init()
6+
screen = pygame.display.set_mode((640, 480), 0, 32)
7+
8+
points = []
9+
10+
while True:
11+
12+
for event in pygame.event.get():
13+
if event.type == QUIT:
14+
pygame.quit()
15+
exit()
16+
if event.type == MOUSEBUTTONDOWN:
17+
points.append(event.pos)
18+
19+
screen.fill((255,255,255))
20+
21+
if len(points) >= 3:
22+
pygame.draw.polygon(screen, (0,255,0), points)
23+
for point in points:
24+
pygame.draw.circle(screen, (0,0,255), point, 5)
25+
26+
pygame.display.update()

0 commit comments

Comments
 (0)