-
Notifications
You must be signed in to change notification settings - Fork 0
/
basics.py
47 lines (40 loc) · 1.05 KB
/
basics.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
35
36
37
38
39
40
41
42
43
44
45
46
47
#setup
import pygame
import random
pygame.init()
size = [500, 500]
screen = pygame.display.set_mode(size)
clock = pygame.time.Clock()
fps = 60
#color = (r,g,b)
black = (0, 0, 0)
white = (255, 255, 255)
green = (0, 255, 0)
red = (255, 0, 0)
yellow = (255, 255, 0)
orange = (255, 150, 30)
isRunning = True
rect_1 = pygame.Rect(200,200,100,100)
pygame.display.set_caption("First Game")
#game loop(updates each frame of the game)
while isRunning == True:
events = pygame.event.get()
mouse_pos = pygame.mouse.get_pos()
for event in events:
if event.type == pygame.QUIT:
isRunning = False
pygame.quit()
#color = (random.randint(0,255),random.randint(0,255),random.randint(0,255))
if rect_1.x > mouse_pos[0]:
rect_1.x -= 1
if rect_1.x < mouse_pos[0]:
rect_1.x += 1
if rect_1.y > mouse_pos[1]:
rect_1.y -= 1
if rect_1.y < mouse_pos[1]:
rect_1.y += 1
screen.fill(color)
pygame.draw.rect(screen,black,rect_1)
clock.tick(fps)
pygame.display.update()
pygame.quit()