Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Pygame base template for opening a window, done with functions
- """
- import pygame
- BLACK = (0x00, 0x00, 0x00)
- WHITE = (0xff, 0xff, 0xff)
- GREEN = (0x00, 0xff, 0x00)
- RED = (0xff, 0x00, 0x00)
- def draw_stick_figure(screen, x, y):
- pygame.draw.ellipse(screen, BLACK, [1+x, y, 10, 10], 0)
- pygame.draw.line(screen, BLACK, [5+x, 17+y], [10+x,27+y], 2)
- pygame.draw.line(screen, BLACK, [5+x, 17+y], [x,27+y], 2)
- pygame.draw.line(screen, RED, [5+x, 17+y], [5+x,7+y], 2)
- pygame.draw.line(screen, RED, [5+x, 7+y], [9+x,17+y], 2)
- pygame.draw.line(screen, RED, [5+x, 7+y], [1+x,17+y], 2)
- def main():
- """ Main function for the game. """
- pygame.init()
- size = [800, 600]
- screen = pygame.display.set_mode(size)
- pygame.display.set_caption("My Game")
- done = False
- clock = pygame.time.Clock()
- pygame.mouse.set_visible(False)
- x_speed = 0
- y_speed = 0
- x_coord = 10
- y_coord = 10
- # -------- Main Program Loop -----------
- while not done:
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- done = True
- if event.type == pygame.KEYDOWN:
- if event.key == pygame.K_LEFT:
- x_speed = -3
- if event.key == pygame.K_RIGHT:
- x_speed = 3
- if event.key == pygame.K_UP:
- y_speed = -3
- if event.key == pygame.K_DOWN:
- y_speed = 3
- elif event.type == pygame.KEYUP:
- if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:
- x_speed = 0
- if event.key == pygame.K_UP or event.key == pygame.K_DOWN:
- y_speed = 0
- pos = pygame.mouse.get_pos()
- x = pos[0]
- y = pos[1]
- x_coord += x_speed
- y_coord += y_speed
- screen.fill(WHITE)
- draw_stick_figure(screen, x_coord, y_coord)
- draw_stick_figure(screen, x, y)
- pygame.display.flip()
- clock.tick(60)
- pygame.quit()
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement