Commit aff535af authored by Dimitris Strovolidis's avatar Dimitris Strovolidis

Initial commit

parents
Thanks for downloading one of codeman38's retro video game fonts, as seen on Memepool, BoingBoing, and all around the blogosphere.
So, you're wondering what the license is for these fonts? Pretty simple; it's based upon that used for Bitstream's Vera font set <http://www.gnome.org/fonts/>.
Basically, here are the key points summarized, in as little legalese as possible; I hate reading license agreements as much as you probably do:
With one specific exception, you have full permission to bundle these fonts in your own free or commercial projects-- and by projects, I'm referring to not just software but also electronic documents and print publications.
So what's the exception? Simple: you can't re-sell these fonts in a commercial font collection. I've seen too many font CDs for sale in stores that are just a repackaging of thousands of freeware fonts found on the internet, and in my mind, that's quite a bit like highway robbery. Note that this *only* applies to products that are font collections in and of themselves; you may freely bundle these fonts with an operating system, application program, or the like.
Feel free to modify these fonts and even to release the modified versions, as long as you change the original font names (to ensure consistency among people with the font installed) and as long as you give credit somewhere in the font file to codeman38 or zone38.net. I may even incorporate these changes into a later version of my fonts if you wish to send me the modifed fonts via e-mail.
Also, feel free to mirror these fonts on your own site, as long as you make it reasonably clear that these fonts are not your own work. I'm not asking for much; linking to zone38.net or even just mentioning the nickname codeman38 should be enough.
Well, that pretty much sums it up... so without further ado, install and enjoy these fonts from the golden age of video games.
[ codeman38 | [email protected] | http://www.zone38.net/ ]
\ No newline at end of file
import os
import pygame
from tetromino import Tetromino
def write(font, message, color):
text = font.render(str(message), True, color)
text = text.convert_alpha()
return text
def main():
black_color = (0, 0, 0)
# screen variables
min_screen_coord = (0, 0)
max_screen_coord = (960, 720)
screen_res = max_screen_coord
# game parameters
block_width, block_height = 32, 32
columns = 10
rows = 20
# (width, height) of game area
game_area = (columns * block_width, rows * block_height)
# top left corner of game area
game_min_coord = ((screen_res[0] - game_area[0]) / 2, (screen_res[1] -
game_area[1]) / 2)
# bottom right corner of game area
game_max_coord = (game_min_coord[0] + game_area[0], game_min_coord[1] + game_area[1])
game_center_coord = (game_min_coord[0] + (columns * block_width) // 2,
game_min_coord[1])
pygame.init()
pygame.mixer.init()
pygame.display.set_caption("Tetris")
screen = pygame.display.set_mode(screen_res)
# create the black background
background = pygame.Surface(screen.get_size())
background.fill(black_color)
background = background.convert()
# create game area
game_area_color = (20, 20, 20)
game_surface = pygame.Surface(game_area)
game_surface.fill(game_area_color)
game_surface = game_surface.convert()
# load font
font = pygame.font.Font(os.path.join('fonts', 'prstartk.ttf'), 18)
# load and scale all blocks (each tetromino has its own block color)
red_block = pygame.image.load(os.path.join('sprites', 'red_block.png'))
red_block = pygame.transform.scale(red_block, (block_width, block_height))
lightblue_block = pygame.image.load(os.path.join('sprites', 'lightblue_block.png'))
lightblue_block = pygame.transform.scale(lightblue_block, (block_width, block_height))
blue_block = pygame.image.load(os.path.join('sprites', 'blue_block.png'))
blue_block = pygame.transform.scale(blue_block, (block_width, block_height))
yellow_block = pygame.image.load(os.path.join('sprites', 'yellow_block.png'))
yellow_block = pygame.transform.scale(yellow_block, (block_width, block_height))
green_block = pygame.image.load(os.path.join('sprites', 'green_block.png'))
green_block = pygame.transform.scale(green_block, (block_width, block_height))
orange_block = pygame.image.load(os.path.join('sprites', 'orange_block.png'))
orange_block = pygame.transform.scale(orange_block, (block_width, block_height))
purple_block = pygame.image.load(os.path.join('sprites', 'purple_block.png'))
purple_block = pygame.transform.scale(purple_block, (block_width, block_height))
color_blocks = (lightblue_block, yellow_block, purple_block, blue_block, orange_block,
green_block, red_block)
random_tetromino = Tetromino((block_width, block_height), color_blocks, game_center_coord,
game_min_coord, game_max_coord)
FPS = 60
game_running = True
clock = pygame.time.Clock()
while game_running:
time = clock.tick(FPS) / 100.0
# check keyboard input
for event in pygame.event.get():
if event.type == pygame.QUIT:
game_running = False
elif event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
game_running = False
elif event.type == pygame.KEYDOWN and event.key == pygame.K_RIGHT:
random_tetromino.move_right()
elif event.type == pygame.KEYDOWN and event.key == pygame.K_LEFT:
random_tetromino.move_left()
elif event.type == pygame.KEYDOWN and event.key == pygame.K_UP:
random_tetromino.rotate_cw()
elif event.type == pygame.KEYDOWN and event.key == pygame.K_DOWN:
random_tetromino.rotate_ccw()
screen.blit(background, min_screen_coord)
screen.blit(game_surface, game_min_coord)
random_tetromino.show(screen)
pygame.display.flip()
random_tetromino.move_down(time)
if __name__ == '__main__':
main()
import pygame
from random import randint
class Tetromino:
# I tetromino
i_tetromino_angle_0 = [[".#.."],
[".#.."],
[".#.."],
[".#.."]]
# rotate 90 degrees cw (clockwise)
i_tetromino_angle_90 = [["...."],
["####"],
["...."],
["...."]]
i_tetromino = (i_tetromino_angle_0, i_tetromino_angle_90,
i_tetromino_angle_0, i_tetromino_angle_90)
# O tetromino
o_tetromino_angle_0 = [["...."],
[".##."],
[".##."],
["...."]]
o_tetromino = (o_tetromino_angle_0, o_tetromino_angle_0,
o_tetromino_angle_0, o_tetromino_angle_0)
# T tetromino
t_tetromino_angle_0 = [["...."],
["###."],
[".#.."],
["...."]]
# rotate 90 degrees cw
t_tetromino_angle_90 = [[".#.."],
["##.."],
[".#.."],
["...."]]
# rotate 180 degrees cw
t_tetromino_angle_180 = [[".#.."],
["###."],
["...."],
["...."]]
# rotate 270 degrees cw
t_tetromino_angle_270 = [[".#.."],
[".##."],
[".#.."],
["...."]]
t_tetromino = (t_tetromino_angle_0, t_tetromino_angle_90,
t_tetromino_angle_180, t_tetromino_angle_270)
# J tetromino
j_tetromino_angle_0 = [["...."],
["###."],
["..#."],
["...."]]
# rotate 90 degrees cw
j_tetromino_angle_90 = [[".#.."],
[".#.."],
["##.."],
["...."]]
# rotate 180 degrees cw
j_tetromino_angle_180 = [["#..."],
["###."],
["...."],
["...."]]
# rotate 270 degrees cw
j_tetromino_angle_270 = [[".##."],
[".#.."],
[".#.."],
["...."]]
j_tetromino = (j_tetromino_angle_0, j_tetromino_angle_90,
j_tetromino_angle_180, j_tetromino_angle_270)
# L tetromino cw
l_tetromino_angle_0 = [["...."],
["###."],
["#..."],
["...."]]
# rotate 90 degrees cw
l_tetromino_angle_90 = [["##.."],
[".#.."],
[".#.."],
["...."]]
# rotate 180 degrees cw
l_tetromino_angle_180 = [["..#."],
["###."],
["...."],
["...."]]
# rotate 270 degrees cw
l_tetromino_angle_270 = [[".#.."],
[".#.."],
[".##."],
["...."]]
l_tetromino = (l_tetromino_angle_0, l_tetromino_angle_90,
l_tetromino_angle_180, l_tetromino_angle_270)
# S tetromino
s_tetromino_angle_0 = [[".##."],
["##.."],
["...."],
["...."]]
# rotate 90 degrees cw
s_tetromino_angle_90 = [[".#.."],
[".##."],
["..#."],
["...."]]
s_tetromino = (s_tetromino_angle_0, s_tetromino_angle_90,
s_tetromino_angle_0, s_tetromino_angle_90)
# Z tetromino
z_tetromino_angle_0 = [["##.."],
[".##."],
["...."],
["...."]]
# rotate 90 degrees cw
z_tetromino_angle_90 = [["..#."],
[".##."],
[".#.."],
["...."]]
z_tetromino = (z_tetromino_angle_0, z_tetromino_angle_90,
z_tetromino_angle_0, z_tetromino_angle_90)
tetrominoes = (i_tetromino, o_tetromino, t_tetromino, j_tetromino,
l_tetromino, s_tetromino, z_tetromino)
speed = 5
def __init__(self, block_dimensions, color_blocks, coord, min_coord: tuple, max_coord: tuple):
"""
Create a random tetromino.
"""
random_index = randint(0, len(Tetromino.tetrominoes) - 1)
self.random_tetromino = Tetromino.tetrominoes[random_index]
self.block_color = color_blocks[random_index]
# select a random frame
self.current_angle = randint(0, 3)
self.current_frame = self.random_tetromino[self.current_angle]
self.block_width = block_dimensions[0]
self.block_height = block_dimensions[1]
# game bounds
self.min_coord = tuple(min_coord)
self.max_coord = (max_coord[0] - self.block_width,
max_coord[1] - self.block_height)
# coordinates of the center block (required for the rotation)
self.center_coord = list(coord)
# coordinates for each block of the tetromino
# list of coordinates [x, y]
self.blocks_coords= self.build()
def build(self):
"""
Calculates the coordinates of each block that is part of the tetromino.
center block index is (1, 1)
:return: list of coordinates [x, y] or empty list if a block is out of bounds
"""
x, y = [self.center_coord[0] - self.block_width, self.center_coord[1]
- self.block_height]
tetromino_coord = []
for i in range(len(self.current_frame)):
for char in self.current_frame[i][0]:
if char == '#':
if self.min_coord[0] <= x <= self.max_coord[0]:
tetromino_coord.append([x, y])
else:
return []
x += self.block_width
x = self.center_coord[0] - self.block_width
y += self.block_height
return tetromino_coord
def show(self, screen):
"""
Blit all blocks
:param screen: surface
"""
for coord in self.blocks_coords:
screen.blit(self.block_color, coord)
def move_down(self, time):
"""
Move down all blocks.
"""
for coord in self.blocks_coords:
coord[1] += Tetromino.speed * time
self.center_coord[1] += Tetromino.speed * time
def move_left(self):
"""
Move left all blocks if it is allowed.
"""
accept_move = True
# check if all blocks are inside the bounds
for coord in self.blocks_coords:
if coord[0] <= self.min_coord[0]:
accept_move = False
break
if accept_move:
self.center_coord[0] -= self.block_width
for coord in self.blocks_coords:
coord[0] -= self.block_width
def move_right(self):
"""
Move right all blocks if it is allowed.
"""
accept_move = True
# check if all blocks are inside the bounds
for coord in self.blocks_coords:
if coord[0] >= self.max_coord[0]:
accept_move = False
break
if accept_move:
self.center_coord[0] += self.block_width
for coord in self.blocks_coords:
coord[0] += self.block_width
def rotate_ccw(self):
"""
Rotate the tetromino 90 degrees counterclockwise.
"""
temp_angle = self.current_angle
if self.current_angle == 0:
temp_angle = 3
else:
temp_angle -= 1
self.current_frame = self.random_tetromino[temp_angle]
temp_coords = self.build()
if not temp_coords: # rotation is not allowed
# reset the current frame
self.current_frame = self.random_tetromino[self.current_angle]
else:
self.current_angle = temp_angle
self.blocks_coords = temp_coords
def rotate_cw(self):
"""
Rotate the tetromino 90 degrees clockwise.
"""
temp_angle = (self.current_angle + 1) % 4
self.current_frame = self.random_tetromino[temp_angle]
temp_coords = self.build()
if not temp_coords: # rotation is not allowed
# reset the current frame
self.current_frame = self.random_tetromino[self.current_angle]
else:
self.current_angle = temp_angle
self.blocks_coords = temp_coords
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment