import pygame
import random
# Inisialisasi Pygame
[Link]()
# Ukuran layar
SCREEN_WIDTH = 400
SCREEN_HEIGHT = 600
BLOCK_SIZE = 40
# Warna
COLORS = [(255, 0, 0), (0, 0, 255), (255, 165, 0)] # Merah, Biru, Oranye
BACKGROUND_COLOR = (30, 30, 30)
# Buat layar
screen = [Link].set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
[Link].set_caption("Block Blast")
# Kelas untuk blok
class Block:
def __init__(self, color):
[Link] = color
self.x = SCREEN_WIDTH // 2 // BLOCK_SIZE * BLOCK_SIZE
self.y = SCREEN_HEIGHT - BLOCK_SIZE
def draw(self):
[Link](screen, [Link], (self.x, self.y, BLOCK_SIZE,
BLOCK_SIZE))
def move_left(self):
if self.x > 0:
self.x -= BLOCK_SIZE
def move_right(self):
if self.x < SCREEN_WIDTH - BLOCK_SIZE:
self.x += BLOCK_SIZE
# Fungsi utama game
def main():
clock = [Link]()
block = Block([Link](COLORS))
running = True
while running:
[Link](BACKGROUND_COLOR)
[Link]()
for event in [Link]():
if [Link] == [Link]:
running = False
keys = [Link].get_pressed()
if keys[pygame.K_LEFT]:
block.move_left()
if keys[pygame.K_RIGHT]:
block.move_right()
[Link]()
[Link](60)
[Link]()
# Jalankan game
if __name__ == "__main__":
main()