forked from buckyroberts/Source-Code-from-Tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path88_PythonGameDevelopment.py
More file actions
152 lines (99 loc) · 3.77 KB
/
88_PythonGameDevelopment.py
File metadata and controls
152 lines (99 loc) · 3.77 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
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]
offset = int(fullSize / 2)
node_5 = [node_1[0]+offset, node_1[1]-offset]
node_6 = [node_2[0]+offset, node_2[1]-offset]
node_7 = [node_3[0]+offset, node_3[1]-offset]
node_8 = [node_4[0]+offset, node_4[1]-offset]
# 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))
# top line #
pygame.draw.line(gameDisplay, white, (node_5),(node_6))
# bottom line #
pygame.draw.line(gameDisplay, white, (node_7),(node_8))
# left line #
pygame.draw.line(gameDisplay, white, (node_5),(node_7))
# right line #
pygame.draw.line(gameDisplay, white, (node_6),(node_8))
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)
pygame.draw.circle(gameDisplay, light_green, node_5, 5)
pygame.draw.circle(gameDisplay, light_green, node_6, 5)
pygame.draw.circle(gameDisplay, light_green, node_7, 5)
pygame.draw.circle(gameDisplay, light_green, node_8, 5)
pygame.draw.line(gameDisplay, white, (node_1),(node_5))
pygame.draw.line(gameDisplay, white, (node_2),(node_6))
pygame.draw.line(gameDisplay, white, (node_3),(node_7))
pygame.draw.line(gameDisplay, white, (node_4),(node_8))
def gameLoop():
location = [300,200]
size = 200
current_move = 0
z_move = 0
z_location = 1
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.key == pygame.K_UP:
z_move = -5
current_move = -1
elif event.key == pygame.K_DOWN:
z_move = 5
current_move = 1
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:
z_move = 0
current_move = 0
gameDisplay.fill(black)
if z_location > 200:
z_move = 0
z_location += z_move
current_size = int(size / (z_location*0.1))
location[0] += current_move
square(location, current_size)
pygame.display.update()
clock.tick(FPS)
pygame.quit()
quit()
gameLoop()