-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbubble_blaster.py
More file actions
128 lines (107 loc) · 3.55 KB
/
bubble_blaster.py
File metadata and controls
128 lines (107 loc) · 3.55 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
import pygame
import sys
from pygame.locals import *
pygame.init()
screen = pygame.display.set_mode((640,460))
screen.fill((255,165,0))
pygame.display.set_caption('Logan\'s Lame Lazy Learning Game of Land, Lines and Luck')
font = pygame.font.SysFont(None, 36)
main_clock = pygame.time.Clock()
player = pygame.Rect(300, 400, 60, 10)
player_speed = 6
move_left = False
move_right = False
x_position = 380
y_position = 395
last_x = x_position
last_y = y_position
ball_can_move = False
speed = [5, -5]
def draw_text(display_string, font, surface, x, y):
text_display = font.render(display_string, 1, (0, 0, 0,))
text_rect = text_display.get_rect()
text_rect.topleft = (x, y)
surface.blit(text_display,text_rect)
all_bubbles = []
bubble_radius = 20
bubble_edge = 1
initial_bubble_position = 70
bubble_spacing = 60
def create_bubbles():
bubble_x = initial_bubble_position
bubble_y = initial_bubble_position
for rows in range(0, 3):
for columns in range(0, 10):
bubble = pygame.draw.circle((screen), (255, 255, 255), (bubble_x, bubble_y),bubble_radius, bubble_edge)
bubble_x += bubble_spacing
all_bubbles.append(bubble)
bubble_y += bubble_spacing
bubble_x = initial_bubble_position
create_bubbles()
def draw_bubbles():
for bubble in all_bubbles:
bubble = pygame.draw.circle((screen), (255,255,255), (bubble.x, bubble.y), bubble_radius, bubble_edge)
while True:
# check for events
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type == KEYDOWN:
if event.key == K_a:
move_right = False
move_left = True
if event.key == K_d:
move_left = False
move_right = True
if event.type == KEYUP:
if event.key == K_a:
move_left = False
if event.key == K_d:
move_right = False
if event.key == K_SPACE:
ball_can_move = True
main_clock.tick(50)
if move_left and player.left > 0:
player.x -= player_speed
if move_right and player.right < 640:
player.x += player_speed
if ball_can_move:
last_x = x_position
last_y = y_position
x_position += speed[0]
y_position += speed[1]
if ball.y <= 0:
y_position = 15
speed[1] = -speed[1]
#if ball.y >= 460:
#y_position = 445
#speed[1] = -speed[1]
if ball.x <= 0:
x_position = 15
speed[0] = -speed[0]
if ball.x >= 640:
x_position = 625
speed[0] = -speed[0]
if ball.colliderect(player):
y_position -= 15
speed[1] = -speed[1]
move_direction = ((x_position - last_x), (y_position - last_y))
for bubble in all_bubbles:
if ball.colliderect(bubble):
if move_direction[1] > 0:
speed[1] = -speed[1]
y_position -= 10
elif move_direction[1] < 0:
speed[1] = -speed[1]
y_position += 10
all_bubbles.remove(bubble)
break
else:
x_position = player.x + 30
screen.fill((255,165,0))
draw_text('Text', font, screen, 5,5)
draw_bubbles()
ball = pygame.draw.circle(screen, (0, 0, 0,), (x_position, y_position), 5,0)
pygame.draw.rect(screen, (225, 0, 115), player)
pygame.display.update()