-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlay-Game.py
More file actions
executable file
·169 lines (124 loc) · 4.71 KB
/
Play-Game.py
File metadata and controls
executable file
·169 lines (124 loc) · 4.71 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import pygame
import time
import random
import math
import Tanks
import slither
from pygame.locals import *
pygame.init()
white = (255,255,255)
red = (200,0,0)
light_red = (255,0,0)
green = (0,155,0)
light_green = (0,255,0)
blue = (0,0,255)
black = (0,0,0)
yellow = (200,200,0)
light_yellow = (255,255,0)
display_width = 800
display_height = 600
gameDisplay = pygame.display.set_mode((display_width,display_height))
pygame.display.set_caption('Game Box') #title for the project
clock = pygame.time.Clock()
block_size = 20
FPS = 10
smallfont = pygame.font.SysFont("comicsansms", 25)
medfont = pygame.font.SysFont("comicsansms", 50)
largefont = pygame.font.SysFont("comicsansms", 80)
def text_objects(text,color,size):
if size == "small":
textSurface = smallfont.render(text,True,color)
elif size == "medium":
textSurface = medfont.render(text,True,color)
elif size == "large":
textSurface = largefont.render(text,True,color)
return textSurface, textSurface.get_rect()
def text_to_button(msg, color, buttonx, buttony, button_width, button_height, size= "small"):
textSurf, textRect = text_objects(msg,color,size)
textRect.center = ((buttonx+(button_width/2)), buttony+(button_height/2))
gameDisplay.blit(textSurf, textRect)
def message_to_screen(msg,color,y_displace=0,size="small"):
textSurf, textRect = text_objects(msg ,color,size)
textRect.center = (display_width/ 2),(display_height / 2)+y_displace
gameDisplay.blit(textSurf,textRect)
def game_controls():
gcont = True
while gcont:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
gameDisplay.fill(white)
message_to_screen("ABOUT",
green,
-100,
"large")
message_to_screen("Game Box is collection of 2 Games",
black,
-30,
"small")
message_to_screen("Clash Of Tank",
black,
10,
"small")
message_to_screen("Slither Snake Game",
black,
50,"small")
message_to_screen("Developed by : Naveen Kumar Verma",
black,
90,"small")
button("Snake",50,500,100,50,green ,light_green,action= "snake")
button("Tank",350,500,100,50,green ,light_green,action= "tanks")
button("Quit",650,500,100,50, red, light_red,action = "quit")
pygame.display.update()
clock.tick(15)
def button(text, x, y, width, height, inactive_color, active_color, action = "None"):
cur = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()
if x + width > cur[0] > x and y + height > cur[1] > y:
pygame.draw.rect(gameDisplay, active_color,(x, y, width, height))
if click[0] == 1 and action != None:
if action == "quit":
quit()
if action == "controls":
game_controls()
if action == "snake":
pygame.display.set_caption('Slither')
slither.game_intro()
if action == "easy":
easyGameLoop()
if action == "hard":
gameLoop()
if action == "tanks":
pygame.display.set_caption('Tanks')
Tanks.game_intro()
else:
pygame.draw.rect(gameDisplay, inactive_color,(x, y, width, height))
text_to_button(text,black,x,y,width,height)
def main_game_intro():
intro = True
while intro:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
gameDisplay.fill(white)
message_to_screen("Welcome to GameBox",
green,
-100,
"large")
message_to_screen("The Clash Of Tanks",
black,
0,
"small")
message_to_screen("Silther : the snake GAme",
black,
40,
"small")
button("Snake",50,500,100,50,green ,light_green,action= "snake")
button("Tank",250,500,100,50,green ,light_green,action= "tanks")
button("ABOUT",450,500,100,50, yellow, light_yellow,action = "controls")
button("QUIT",650,500,100,50, red, light_red,action = "quit")
pygame.display.update()
clock.tick(15)
main_game_intro()