forked from buckyroberts/Source-Code-from-Tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path85_PythonGameDevelopment.py
More file actions
103 lines (65 loc) · 2.3 KB
/
85_PythonGameDevelopment.py
File metadata and controls
103 lines (65 loc) · 2.3 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import pygame
import time
import random
pygame.init()
display_width = 800
display_height = 600
gameDisplay = pygame.display.set_mode((display_width,display_height))
pygame.display.set_caption('3d')
white = (255,255,255)
black = (0,0,0)
red = (200,0,0)
light_red = (255,0,0)
yellow = (200,200,0)
light_yellow = (255,255,0)
green = (34,177,76)
light_green = (0,255,0)
clock = pygame.time.Clock()
smallfont = pygame.font.SysFont("comicsansms", 25)
medfont = pygame.font.SysFont("comicsansms", 50)
largefont = pygame.font.SysFont("comicsansms", 85)
FPS = 30
def square(startPoint, fullSize):
node_1 = [startPoint[0], startPoint[1]]
node_2 = [startPoint[0]+fullSize, startPoint[1]]
node_3 = [startPoint[0], startPoint[1]+fullSize]
node_4 = [startPoint[0]+fullSize, startPoint[1]+fullSize]
# top line #
pygame.draw.line(gameDisplay, white, (node_1),(node_2))
# bottom line #
pygame.draw.line(gameDisplay, white, (node_3),(node_4))
# left line #
pygame.draw.line(gameDisplay, white, (node_1),(node_3))
# right line #
pygame.draw.line(gameDisplay, white, (node_2),(node_4))
pygame.draw.circle(gameDisplay, light_green, node_1, 5)
pygame.draw.circle(gameDisplay, light_green, node_2, 5)
pygame.draw.circle(gameDisplay, light_green, node_3, 5)
pygame.draw.circle(gameDisplay, light_green, node_4, 5)
def gameLoop():
location = [300,200]
size = 200
current_move = 0
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
current_move = -5
elif event.key == pygame.K_RIGHT:
current_move = 5
elif event.type == pygame.KEYUP:
if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:
current_move = 0
if event.key == pygame.K_UP or event.key == pygame.K_DOWN:
pass
gameDisplay.fill(black)
location[0] += current_move
square(location, size)
pygame.display.update()
clock.tick(FPS)
pygame.quit()
quit()
gameLoop()