🐱 Cube Clicker — Save Your Cat
✍️ Coded line by line by Nutpoom Sookkasem, age 16 💛 · See full profile and all works →
📖 What is this project?
Cube Clicker คือเกมแนว Clicker (เกมกดสะสมแต้ม) ที่นักเรียนเขียนด้วย pygame — คลิกลูกบาศก์เพื่อเก็บแต้ม เอาแต้มไปซื้ออัพเกรดให้คลิกครั้งเดียวได้แต้มเพิ่มขึ้นทีละ 3 แต่ราคาอัพเกรดจะแพงขึ้นเรื่อย ๆ ครั้งละ 5 แต้ม เป้าหมายคือสะสมให้ครบ 1,000 แต้มเพื่อช่วยน้องแมวออกมา!
สิ่งที่น่าสนใจคือนักเรียนออกแบบระบบเศรษฐกิจในเกมเอง (ยิ่งอัพเกรดยิ่งแพง) ซึ่งเป็นหลักการเดียวกับเกม Clicker ดัง ๆ ระดับโลก และใส่รายละเอียดเล็ก ๆ อย่างการเปลี่ยนสีลูกบาศก์ตอนกดค้างแล้วเปลี่ยนกลับตอนปล่อย
🕹️ Try the real thing!
This is the real pygame game, converted to run on the web with every position, colour and rule kept exactly the same — just click and play.
👨💻 The original Python source code (with the comments they wrote themselves)
import pygame
import time
pygame.init()
width = 800
height = 500
screen = pygame.display.set_mode((width, height))
cube = pygame.Rect(300, 150, 200, 200)#กำหนดที่อยู่และขนาดของสี่เหลี่ยม
box1 = pygame.Rect(600, 10, 165, 70)#กำหนดที่อยู่และขนาดของกล่องที่1
box2 = pygame.Rect(625, 465, 165, 30)#กำหนดที่อยู่และขนาดของกล่องที่2
color = [92, 64, 51]
font = pygame.font.Font(None, 36)#กำหนด font และขนาด
cubecount = 0
cu = 1
upcost = 15
run = True
while run:
screen.fill((0, 0, 0))
pygame.draw.rect(screen, (color), cube)#วางสี่เหลี่ยมลงบนwindow
pygame.draw.rect(screen, (0, 255, 0), box1)#วางกล่องที่1ลงบนwindow
pygame.draw.rect(screen, (0, 255, 0), box2)#วางกล่องที่2ลงบนwindow
cc = font.render(f"Cube: {cubecount}", True, (255, 255, 255))#กำหนดสีและตัวอักษร
sc = font.render("Save your cat", True, (255, 255, 255))#กำหนดสีและตัวอักษร
up = font.render("Upgrade your", True, (255, 255, 255))#กำหนดสีและตัวอักษร
cp = font.render("Cube per click", True, (255, 255, 255))#กำหนดสีและตัวอักษร
catc = font.render("Cost: 1000", True, (255, 255, 255))#กำหนดสีและตัวอักษร
uc = font.render(f"Cost: {upcost}", True, (255, 255, 255))#กำหนดสีและตัวอักษร
cpc = font.render(f"cube per click: {cu}", True, (255, 255, 255))#กำหนดสีและตัวอักษร
screen.blit(cpc, (10, 10))#กำหนดที่อยู่ตัวอักษร
screen.blit(uc, (630, 100))#กำหนดที่อยู่ตัวอักษร
screen.blit(catc, (630, 430))#กำหนดที่อยู่ตัวอักษร
screen.blit(cp, (600, 50))#กำหนดที่อยู่ตัวอักษร
screen.blit(up, (600, 10))#กำหนดที่อยู่ตัวอักษร
screen.blit(sc, (625, 465))#กำหนดที่อยู่ตัวอักษร
screen.blit(cc, (10, 465))#กำหนดที่อยู่ตัวอักษร
for event in pygame.event.get():
if event.type == pygame.QUIT:#ว่ามีการปิด window รึป่าว
run = False
if event.type == pygame.MOUSEBUTTONDOWN:#ตรวจจับว่า mouse ถูกกดลง
if cube.collidepoint(event.pos):#ตรวจจับ mouse คลิกบริเวณสี่เหลี่ยมหรือไม่
color = [196, 164, 132]#เปลี่ยนสีสี่เหลี่ยมหลังถูกกด
cubecount = cubecount + cu#เพิ่มค่า cubecount
elif box1.collidepoint(event.pos):#ตรวจจับ mouse คลิกบริเวณกล่อง1หรือไม่
if cubecount < upcost:#ตรวจว่ามีค่า cubecount พอซื้อ upgrade หรือไม่
run = True
if cubecount >= upcost:
cubecount = cubecount - upcost
cu = cu + 3
upcost = upcost + 5
elif box2.collidepoint(event.pos):#ตรวจจับ mouse คลิกบริเวณกล่อง2หรือไม่
if cubecount < 1000:#ตรวจว่ามีค่า cubecount พอซื้อ save cat หรือไม่
run = True
if cubecount >= 1000:
print("You've clicked enough cubes! You've saved your cat!")
run = False
elif event.type == pygame.MOUSEBUTTONUP:#ตรวจจับว่า mouse เด้งขึ้นหรือไม่
color = [92, 64, 51]#เปลี่ยนสีสี่เหลี่ยมกลับ
pygame.display.update()
Our Python course is taught live, one-on-one, and every child builds a real project of their own just like these.