repl.it
@tomnagel/

Buble Submarine PvP game

Pygame

It's a game!

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
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
import pygame
from tkinter import *
x = 0
y = 0
lag = 0
lag2 = 1
DOOM = 0
import os
os.environ['SDL_VIDEO_WINDOW_POS'] = "%d,%d" % (x,y)
HEIGHT = 500
WIDTH = 800
window = Tk()
window.title('Zuurstof zoeker')
c = Canvas(window, width=WIDTH, height=HEIGHT, bg='darkblue')
c.pack()
window.update()
ship_id = c.create_polygon(5, 5, 5, 25, 30, 15, fill='red')
ship_id2 = c.create_oval(0, 0, 30, 30, outline='red')
ship_id3 = c.create_polygon(5, 5, 5, 25, 30, 15, fill='orange')
ship_id4 = c.create_oval(0, 0, 30, 30, outline='orange')
SHIP_R = 15
SHIP_R2 = 15
MID_X = WIDTH / 2
MID_Y = HEIGHT / 2
c.move(ship_id, MID_X, MID_Y)
c.move(ship_id2, MID_X, MID_Y)
c.move(ship_id3, MID_X, MID_Y)
c.move(ship_id4, MID_X, MID_Y)
SHIP_SPD = 3
SHIP_SPD2 = 3
from random import randint
bub_id = list()
bub_r = list()
bub_speed = list()
bub_id3 = list()
bub_r2 = list()
bub_speed2 = list()
MIN_BUB_R = 10
MAX_BUB_R = 30
MAX_BUB_SPD = 10
GAP = 100
def create_bubble():
    x = WIDTH + GAP
    y = randint(0, HEIGHT)
    r = randint(MIN_BUB_R, MAX_BUB_R)
    id1 = c.create_oval(x - r, y - r, x + r, y + r, outline='white')
    bub_id.append(id1)
    bub_r.append(r)
    bub_speed.append(randint(1, MAX_BUB_SPD))
def move_bubbles():
    for i in range(len(bub_id)):
        c.move(bub_id[i], -bub_speed[i], 0)
def get_coords(id_num):
    pos = c.coords(id_num)
    x = (pos[0] + pos[2]) / 2
    y = (pos[1] + pos[3]) / 2
    return x, y
def del_bubble(i):
    del bub_r[i]
    del bub_speed[i]
    c.delete(bub_id[i])
    del bub_id[i]
def clean_up_bubs():
    for i in range(len(bub_id)-1, -1, -1):
        x, y = get_coords(bub_id[i])
        if x < -GAP:
            del_bubble(i)
from math import sqrt
def distance(id1, id2):
    x1, y1 = get_coords(id1)
    x2, y2 = get_coords(id2)
    return sqrt((x2 - x1)**2 + (y2 - y1)**2)


def create_bubble2():
    x = WIDTH + GAP
    y = randint(0, HEIGHT)
    r = randint(MIN_BUB_R, MAX_BUB_R)
    id4 = c.create_oval(x - r, y - r, x + r, y + r, fill='green')
    bub_id3.append(id4)
    bub_r2.append(r)
    bub_speed2.append(randint(1, MAX_BUB_SPD))
def move_bubbles2():
    for f in range(len(bub_id3)):
        c.move(bub_id3[f], -bub_speed2[f], 0)
def get_coords2(id3_num):
    pos2 = c.coords(id3_num)
    x3 = (pos2[0] + pos2[2]) / 2
    y3 = (pos2[1] + pos2[3]) / 2
    return x3, y3
def del_bubble2(f):
    del bub_r2[f]
    del bub_speed2[f]
    c.delete(bub_id3[f])
    del bub_id3[f]
def clean_up_bubs2():
    for f in range(len(bub_id3)-1, -1, -1):
        x3, y3 = get_coords(bub_id3[f])
        if x3 < -GAP:
            del_bubble2(f)
def distance2(id4, id2):
    x4, y4 = get_coords(id4)
    x5, y5 = get_coords(id2)
    return sqrt((x5 - x4)**2 + (y5 - y4)**2)

#DOOM
def create_bubble3():
    x = WIDTH + GAP
    y = randint(0, HEIGHT)
    r = randint(MIN_BUB_R, MAX_BUB_R)
    id4 = c.create_oval(x - r, y - r, x + r, y + r, fill='red')
    bub_id3.append(id4)
    bub_r2.append(r)
    bub_speed2.append(randint(4, 14))
words = c.create_text(400, 80, text='DOOM', fill='Red', font=('Helvetica',25))
c.itemconfig(words, state=HIDDEN)
def DOOMTEXT():
    c.itemconfig(words, state=NORMAL)
def DOOMDELTEXT():
    c.itemconfig(words, state=HIDDEN)

c.create_text(400, 30, text='TIME', fill='White')
c.create_text(50, 30, text='SCORE', fill='Red')
time_text = c.create_text(400, 50, fill='White')
score_text = c.create_text(50, 50, fill='White')
c.create_text(750, 30, text='SCORE', fill='Yellow')
score2_text = c.create_text(750, 50, fill='White')
def show_score(score):
    c.itemconfig(score_text, text=str(score))
def show_score2(score2):
    c.itemconfig(score2_text, text=str(score2))
def show_time(time_left):
    c.itemconfig(time_text, text=str(time_left))
from time import sleep, time
BUB_CHANCE = 10
TIME_LIMIT = 30
BONUS_SCORE = 1000
score = 0
score2 = 0
bonus = 0
bonus2 = 0
score3 = 0
end = time() + TIME_LIMIT
pygame.display.init()
screen = pygame.display.set_mode((30,30))


#MAIN GAME LOOP
while time() < end:
    if randint(1, BUB_CHANCE) == 1:
        create_bubble()
    move_bubbles()
    clean_up_bubs()
    points = 0
    if randint(1, 650) == 1:
        if randint(1, 5) == 1:
            DOOM = 2
            DOOMTEXT() 
        elif DOOM == 0:
            create_bubble2()    
    if DOOM == 2:
        if randint(1, 10) == 1:
            create_bubble3()
    move_bubbles2()
    clean_up_bubs2()
    points = 0
    points2 = 0
    points44 = 0
    for bub in range(len(bub_id)-1, -1, -1):
        if distance(ship_id2, bub_id[bub]) < (SHIP_R + bub_r[bub]):
            points += (bub_r[bub] + bub_speed[bub])
            del_bubble(bub)
    score += points
    for bub in range(len(bub_id)-1, -1, -1):
        if distance(ship_id4, bub_id[bub]) < (SHIP_R2 + bub_r[bub]):
            points2 += (bub_r[bub] + bub_speed[bub])
            del_bubble(bub)
    score2 += points2
    score3 = score2 + score
    if DOOM != 0:
        for bub2 in range(len(bub_id3)-1, -1, -1):
            if distance(ship_id2, bub_id3[bub2]) < (SHIP_R + bub_r2[bub2]):
                points += (bub_r2[bub2] + bub_speed2[bub2])
                del_bubble2(bub2)
                points = points * 4
                score = score - points
                score2 = score2 + points
                SHIP_SPD = 3
    elif DOOM == 0:               
        for bub2 in range(len(bub_id3)-1, -1, -1):
            if distance(ship_id2, bub_id3[bub2]) < (SHIP_R + bub_r2[bub2]):
                del_bubble2(bub2)
                SHIP_SPD = SHIP_SPD + 2
    points = 0
    points2 = 0
    points44 = 0
    if DOOM != 0:
        for bub2 in range(len(bub_id3)-1, -1, -1):
            if distance(ship_id4, bub_id3[bub2]) < (SHIP_R2 + bub_r2[bub2]):
                points += (bub_r2[bub2] + bub_speed2[bub2])
                del_bubble2(bub2)
                points = points * 4
                score = score + points
                score2 = score2 - points
                score3 = score2 + score
                SHIP_SPD2 = 3
    elif DOOM == 0:
        for bub2 in range(len(bub_id3)-1, -1, -1):
            if distance(ship_id4, bub_id3[bub2]) < (SHIP_R2 + bub_r2[bub2]):
                del_bubble2(bub2)
                SHIP_SPD2 = SHIP_SPD2 + 2
    if (int(score3 / BONUS_SCORE)) > bonus:
        bonus += 1
        end += TIME_LIMIT
        bonus2 = bonus * bonus * 2
        BONUS_SCORE = BONUS_SCORE + bonus2
        if randint (1, 15) == 1:
            lag = 1
    show_score(score)
    show_score2(score2)
    show_time(int(end - time()))
    window.update()
    if lag == 1:
        lag2 = randint(9, 90)
        lag2 = lag2 / 100
        sleep(lag2)
        if randint(1, 20) == 1:
            lag = 0
    else :
        sleep(0.01)
    keys = pygame.key.get_pressed()
    if keys[pygame.K_UP]:
        c.move(ship_id3, 0, -SHIP_SPD2)
        c.move(ship_id4, 0, -SHIP_SPD2)
    if keys[pygame.K_DOWN]:    
        c.move(ship_id3, 0, SHIP_SPD2)
        c.move(ship_id4, 0, SHIP_SPD2)
    if keys[pygame.K_LEFT]:
        c.move(ship_id3, -SHIP_SPD2, 0)
        c.move(ship_id4, -SHIP_SPD2, 0)
    if keys[pygame.K_RIGHT]:
        c.move(ship_id3, SHIP_SPD2, 0)
        c.move(ship_id4, SHIP_SPD2, 0)
    if keys[pygame.K_w]:
        c.move(ship_id, 0, -SHIP_SPD)
        c.move(ship_id2, 0, -SHIP_SPD)
    if keys[pygame.K_s]:    
        c.move(ship_id, 0, SHIP_SPD)
        c.move(ship_id2, 0, SHIP_SPD)
    if keys[pygame.K_a]:
        c.move(ship_id, -SHIP_SPD, 0)
        c.move(ship_id2, -SHIP_SPD, 0)
    if keys[pygame.K_d]:
        c.move(ship_id, SHIP_SPD, 0)
        c.move(ship_id2, SHIP_SPD, 0)
    pos44 = c.coords(ship_id2)
    x44 = (pos44[0] + pos44[2]) / 2
    y44 = (pos44[1] + pos44[3]) / 2
    pos55 = c.coords(ship_id4)
    x55 = (pos55[0] + pos55[2]) / 2
    y55 = (pos55[1] + pos55[3]) / 2
    if x44 < 0:
        c.move(ship_id, SHIP_SPD, 0)
        c.move(ship_id2, SHIP_SPD, 0)
    if x44 > 800:
        c.move(ship_id, -SHIP_SPD, 0)
        c.move(ship_id2, -SHIP_SPD, 0)
    if y44 < -3:
        c.move(ship_id, 0, 505)
        c.move(ship_id2, 0, 505)
    if y44 > 503:
        c.move(ship_id, 0, -505)
        c.move(ship_id2, 0, -505)
    if x55 < 0:
        c.move(ship_id3, SHIP_SPD2, 0)
        c.move(ship_id4, SHIP_SPD2, 0)
    if x55 > 800:
        c.move(ship_id3, -SHIP_SPD2, 0)
        c.move(ship_id4, -SHIP_SPD2, 0)
    if y55 < -3:
        c.move(ship_id3, 0, 505)
        c.move(ship_id4, 0, 505)
    if y55 > 503:
        c.move(ship_id3, 0, -505)
        c.move(ship_id4, 0, -505)
    if SHIP_SPD > 3:
        if randint(1, 700) == 1:
            SHIP_SPD = SHIP_SPD - 1
    if SHIP_SPD2 > 3:
        if randint(1, 700) == 1:
            SHIP_SPD2 = SHIP_SPD2 - 1
    if DOOM == 2:
        if randint(1, 400) == 1:
            DOOM = 1
    if DOOM == 1:
        if randint(1, 150) == 1:
            DOOM = 0
            DOOMDELTEXT()
            
            
    

c.create_text(MID_X, MID_Y, \
              text='GAME OVER', fill='White', font=('Helvetica',30))
c.create_text(MID_X, MID_Y + 30, \
              text='Score: '+ str(score), fill='Red')
c.create_text(MID_X, MID_Y + 45, \
              text='Score: '+ str(score2), fill='Yellow')
c.create_text(MID_X, MID_Y + 60, \
              text='Bonus time: '+ str(bonus*TIME_LIMIT), fill='White')
Fetching token
?