repl.it
@MATHyou/

Outline

Pygame

Use this to start off your Pygame Project!

fork
loading
Files
  • main.py
  • nohup.out
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#NOTE: THIS PROGRAM WILL NOT BE ABLE TO RUN RIGHT OUT OF THE BOX
import pygame
import random
pygame.init()
winheight = 500
winwidth = 500
win = pygame.display.set_mode((winwidth, winheight))
pygame.display.set_caption("CHANGE THIS TITLE")
run = True
image = pygame.image.load('ImageExample.png')
def img(img, x, y): #For drawing an image
    win.blit(img, (x,y))
def message(msg, color, cords, size): #A function for writting a message on the screen.
    fontsize = int(size)
    font = pygame.font.SysFont(None, fontsize)
    screen_text = font.render(msg, True, color)
    win.blit(screen_text, cords)
while run:
    win.fill((255,255,255))  #DRAW ALL OBJECTS AFTER THIS LINE
    pygame.time.delay(5)
    CHANGETHIS = pygame.draw.rect(win, (0,0,0), (playerx, playery, playerwidth, playerheight))  #MAKE SURE TO HAVE THESE VARIABLES!
    for event in pygame.event.get(): #For sensing button presses
        if event.type == pygame.QUIT:
            run = False
    keys = pygame.key.get_pressed()
    pos = pygame.mouse.get_pos() 
    pressed1, pressed2, pressed3 = pygame.mouse.get_pressed()#pressed1 = Left click || pressed2 = Middle click || pressed3 = Right click
    if CHANGETHIS.collidepoint(pos)"""Detects if mouse is hoovering over the object of CHANGETHIS""" and pressed1:
        #What will you make this do?
    if keys[pygame.K_"""INSERT KEY"""]:
        #Put what needs to happpen after the key (Which you insert ^above^) is pressed
    img(image, 10, 10) #For example
    pygame.display.update()
pygame.quit()